Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@zed /

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
how to define an elementwise function in pycuda
#!/usr/bin/env python
import pycuda.gpuarray as gpuarray
import pycuda.autoinit
from pycuda.elementwise import ElementwiseKernel
# define elementwise `add()` function
add = ElementwiseKernel(
"float *a, float *b, float *c",
"c[i] = a[i] + b[i]",
# create a couple of random matrices with a given shape
from pycuda.curandom import rand as curand
shape = 128, 1024
a_gpu = curand(shape)
b_gpu = curand(shape)
# compute sum on a gpu
c_gpu = gpuarray.empty_like(a_gpu)
add(a_gpu, b_gpu, c_gpu)
# check the result
import numpy.linalg as la
print (c_gpu - (a_gpu + b_gpu))
assert la.norm((c_gpu - (a_gpu + b_gpu)).get()) < 1e-5

Can you provide some further details ?? I am on Ubuntu 12.04 with CUDA 5.5 on a GEFORCE GT 630M card, any particular version of pycuda will suit me ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.