Skip to content

Instantly share code, notes, and snippets.

View leofang's full-sized avatar

Leo Fang leofang

View GitHub Profile
@leofang
leofang / test_cupy_to_pycuda.py
Created October 10, 2020 02:59
Convert CuPy array to PyCUDA array
import cupy as cp
from pycuda import gpuarray
import pycuda.autoinit # this import creates a CUDA context!
def from_cupy(arr):
shape = arr.shape
dtype = arr.dtype
# a dummy object always returns the underlying pointer address

Keybase proof

I hereby claim:

  • I am leofang on github.
  • I am leofang (https://keybase.io/leofang) on keybase.
  • I have a public key ASCZZ6NP9Kjx8B_n1wSCGFk3VCeEqKI2g7CAiIrhaAKcsAo

To claim this, I am signing this object:

import sys
import warnings
warnings.filterwarnings("ignore", category=FutureWarning)
import numpy as np
import cupy as cp
from cupyx.time import repeat
shape = (256, 512, 512)
@leofang
leofang / stream_cupy_to_numba.py
Last active September 14, 2023 22:49
Convert CuPy stream to Numba stream
# Many Python libraries provide low-level CUDA support, but when it comes to interoperability
# things get complicated. This script shows a simple example on converting a CUDA stream
# created from CuPy's API to one that is compatible with Numba.
from numba import cuda
import cupy as cp
def stream_cupy_to_numba(cp_stream):
@leofang
leofang / Dockerfile
Last active September 11, 2017 04:06
# build locally at the root of cthyb-ohmic:
# docker build --build-arg arg_build_time="$(date +"%b. %d, %T %Z, %Y")" --squash -t leofang/cthyb-ohmic .
FROM centos:latest
# get cthyb-ohmic; this layer will expose the source, so remember to squash when building!
ADD . /opt/cthyb-ohmic/
# get alps; note the pipe slot after tar
RUN curl -s http://alps.comp-phys.org/static/software/releases/alps-2.2.b3-r7462-src-with-boost.tar.gz | \
tar -xzf - -C /opt/