How do I get PyCuda to pull in the array of strings rather than one char string? If you uncomment the line within the C code, you'll see that its iterating through each character and not through each string.
For now i'm just trying to calculate the length of each string, but will eventually make this into a word frequency counter. First step: pass in an array... Right now the desired output should be 25,27,44
import pycuda.driver as drv
import pycuda.tools
import pycuda.autoinit
import numpy
from pycuda.compiler import SourceModule
# create an array of 1s
lines = numpy.array(['ok this is the first line','number two line is this one','alright last line is in the third place here'])
lines = numpy.array(lines)
blocks = len(lines)
block_size = 1
nbr_values = blocks * block_size
# create a destination array that will receive the result
a = numpy.zeros(nbr_values).astype(numpy.float32)
dest = numpy.zeros_like(a)
######################
# SourceModele SECTION
mod = SourceModule("""
__global__ void gpusin(float *dest, char *lines)
{
const int i = blockDim.x*blockIdx.x + threadIdx.x;
dest[i] = sizeof (lines[i]);
//dest[i] = lines[i]; //uncomment this line to see that its iterating through individual chars not strings
}
""")
#Run the sourc model
gpusin = mod.get_function("gpusin")
gpusin(drv.Out(dest), drv.In(lines), grid=(blocks,1), block=(block_size,1,1) )
print str(dest)
print lines