Created
November 13, 2021 20:29
-
-
Save 4OH4/d8c34db0a2326b5d9a84a38ef722fdbf to your computer and use it in GitHub Desktop.
Creating a CUDA function with PyCUDA (pt. 1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pycuda.driver as cuda | |
import pycuda.autoinit | |
from pycuda.compiler import SourceModule | |
# Define our function using CUDA code | |
cuda_func_def = """ | |
__global__ void multiply(float *result, float *a, float *b) | |
{ | |
const int i = threadIdx.x; | |
result[i] = a[i] * b[i]; | |
} | |
""" | |
# Create CUDA module and import into Python | |
mod = SourceModule(cuda_func_def) | |
multiply_func = mod.get_function("multiply") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment