Skip to content

Instantly share code, notes, and snippets.

View mkolod's full-sized avatar

Marek Kolodziej mkolod

  • San Francisco Bay Area, CA
View GitHub Profile
import torch.cuda
import torch.cuda.memory as cumem
import sys
import ctypes as C
GB = 1 << 30
def get_cuda_memory():
handle = C.cdll.LoadLibrary("libcudart.so")
free, total = C.c_long(), C.c_long()
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" TODO: this may not be in the correct place. It is intended to allow overriding <Leader>.
" source ~/.vimrc.before if it exists.
if filereadable(expand("~/.vimrc.before"))
source ~/.vimrc.before
endif
@mkolod
mkolod / fake_gpu_utilization.cu
Created August 6, 2020 16:05
fake_gpu_utilization
#include <string>
#include <unistd.h>
#include <iostream>
#include <nvml.h>
#define cudaSafeCall(call) \
do { \
cudaError_t err = call; \
if (cudaSuccess != err) { \
fprintf (stderr, "Cuda error in file '%s' in line %i : %s.", \
import onnx
import sys
name = sys.argv[1]
model = onnx.load(name)
onnx.checker.check_model(model)
print(onnx.helper.printable_graph(model.graph))
RUN wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
RUN chmod +x cuda_10.2.89_440.33.01_linux.run && \
./cuda_10.2.89_440.33.01_linux.run --silent --toolkit
# After installing CUDA, you need to add the env vars below, otherwise you'll get CUDA runtime version/driver
# version issue, even if you're using nvidia-docker.
ENV LIBRARY_PATH=/usr/local/cuda/lib64/stubs
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
# precondition: d is power of 2
def mod_pow2(n, d):
return ( n & (d-1) )
print(n, "mod" , d , "is", mod_pow2(6, 4))
import torch
from time import time
# initialize CUDA, to not count startup later
foo = torch.ones(1).cuda()
MB = 1 << 20
# 27 MB tensor
NUM_MB = 27
@mkolod
mkolod / ipc_demo.py
Created April 16, 2020 18:45 — forked from lebedov/ipc_demo.py
Demonstrate how to pass IPC handles to GPU data between processes in Python
#!/usr/bin/env python
"""
Demonstrate how to pass IPC handles to GPU data between processes in Python.
"""
import ctypes
import numpy as np
import multiprocessing as mp
import zmq
#!/usr/bin/env python
import numpy as np
import sqlite3 as lite
import sys
from contextlib import ContextDecorator
class DbContext(ContextDecorator):
def __init__(self, file_path):
self.file_path = file_path
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.