Skip to content

Instantly share code, notes, and snippets.

@4OH4
4OH4 / pycuda_exampple_pt3.py
Last active November 13, 2021 20:50
Executing a CUDA function with PyCUDA (pt. 3)
# run multiply function on GPU
multiply_func(
result_gpu, a_gpu, b_gpu,
block=(100, 1, 1),
grid=(1, 1, 1)
)
# Get data back from GPU
cuda.memcpy_dtoh(result, result_gpu)
@4OH4
4OH4 / check_pycuda.py
Created November 16, 2021 21:14
Checking if PyCUDA is available
# Check if PyCuda is installed
package_name = 'pycuda'
use_cuda = importlib.util.find_spec(package_name) is not None
if use_cuda:
import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule
@4OH4
4OH4 / median_func.cc
Created November 16, 2021 21:22
Inline configuration parameters
#define IMW __IMW_keyword__ // image width (px)
#define IMH __IMH_keyword__ // image height (px)
#define BX __BX_keyword__ // block index x
#define BY __BY_keyword__ // block index y
#define nTPB (BX*BY) // threads per block
#define IMN 21 // buffer length