tags:

views:

97

answers:

2

Hi, heres sumthin ive been battling for 4 days now. I have an array of character pointers which i want to send to device. Can somebody tell me how... Heres what ive tried so far:

char **a;
char **b;
*a[0]="Foo1";
*a[1]=="Foo2";

cudaMalloc(void**)?,sizeof(?);
cudamemcpy(b,a,sizeof(?),cudaMemcpyHostToDevice);

How do i pass in the parameters to the above two functions...someone plz help! And finally how should the kernel be called? (do i just pass b or *b or something?)

A: 

to assign, use array[0] = "string literal" No need for stars.

To get length, use strlen(). siezeof is irrelevant.

Never copy into this string matrix, or pass it as out parameter. You have to allocate memory for that.

Pavel Radzivilovsky
ok..thanks...but my main two questions are how you call cudaMemcpy and cudaMalloc...and how do you call the kernel?
ananth
A: 

If you send the character pointers to the device, you will have an array of CPU memory addresses on the device, which is probably not what you want.

If you want to send the whole data structure there, allocate sizeof(char) * string_length bytes for each string, and then store the resulting device pointers in a CPU array of char*s. Then, once it's complete, send the array of device pointers to the device, allocating sizeof(char*) * number_of_strings bytes for it.

When you call the kernel, give it the device-side array of device pointers.

interfect