Created
May 27, 2014 04:21
-
-
Save inducer/88ac86874112b0e126ce 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:1] | |
dest = to_gpu(numpy.empty(400, numpy.int32)) | |
get_second(dest, pair, block=(400,1,1), grid=(1,1)) | |
assert dest.get()[0] == 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment