Created
May 21, 2014 05:11
-
-
Save fjarri/15383a1ae367bfc6efe8 to your computer and use it in GitHub Desktop.
This file contains 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 | |
import pycuda.autoinit | |
import pycuda.driver as drv | |
from pycuda.compiler import SourceModule | |
from pycuda.gpuarray import to_gpu | |
mod = SourceModule(""" | |
typedef struct _pair | |
{ | |
int first; | |
int second; | |
} pair; | |
__global__ void get_second(int *dest, pair src) | |
{ | |
const int i = threadIdx.x; | |
dest[i] = src.second; | |
} | |
""") | |
get_second = mod.get_function("get_second") | |
dtype = numpy.dtype([('first', numpy.int32), ('second', numpy.int32)]) | |
pair_arr = numpy.empty(1, dtype) | |
pair_arr['first'][0] = 1 | |
pair_arr['second'][0] = 2 | |
pair = pair_arr[0] | |
dest = to_gpu(numpy.empty(400, numpy.int32)) | |
get_second(dest, pair, block=(400,1,1), grid=(1,1)) | |
assert dest.get() == 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment