passing an array of char* to kernel function

hello,

I’m an OpenCL beginner and not a C++ professional, I’ve read the oclVectorAdd example in the OpenCL samples… I found that the arguments of the kernel function were float * (float pointers representing 3 arrays of floats)… I’ve got an idea of a GPU program in which I want to create a simple kernel function but this time I want to deal with an array of strings… since there are no strings the cl program I’m trying to send 2 arrays of char* as an argument to the kernel function… Just for testing the idea, I wrote this code:

__kernel void normalizer(__global char * documentStrings[], __global char * documentStringsOut[])

{ int i = get_global_id(0);

 int strLen=sizeof(documentStrings[i])/sizeof(char);

for(int j=0;j<strLen;j++){

	char ch = documentStrings[i][j]; documentStrings[i][j]=ch++;}

 documentStringsOut[i]=documentStrings[i];

}

But when I try to call the clBuildProgram I get this error: “invalid address space for array argument to __kernel function”

can anybody help me?!

hello,

I’m an OpenCL beginner and not a C++ professional, I’ve read the oclVectorAdd example in the OpenCL samples… I found that the arguments of the kernel function were float * (float pointers representing 3 arrays of floats)… I’ve got an idea of a GPU program in which I want to create a simple kernel function but this time I want to deal with an array of strings… since there are no strings the cl program I’m trying to send 2 arrays of char* as an argument to the kernel function… Just for testing the idea, I wrote this code:

__kernel void normalizer(__global char * documentStrings[], __global char * documentStringsOut[])

{ int i = get_global_id(0);

 int strLen=sizeof(documentStrings[i])/sizeof(char);

for(int j=0;j<strLen;j++){

	char ch = documentStrings[i][j]; documentStrings[i][j]=ch++;}

 documentStringsOut[i]=documentStrings[i];

}

But when I try to call the clBuildProgram I get this error: “invalid address space for array argument to __kernel function”

can anybody help me?!

OpenCL doesn’t support pointers. I don’t think char* is a valid type for an argument.

OpenCL doesn’t support pointers. I don’t think char* is a valid type for an argument.

I don’t think anything like this would work in general. If you’re familiar with the OpenCL API then you know you have to call clCreateBuffer() and clEnqueueRead/WriteBuffer() for any pointer arguments passed into kernel functions. This suggests that nested pointer redirection is pretty much impossible for kernel arguments because the pointers would still be global and the kernel doesn’t know how to deal with global pointers unless they’ve been processed by the above function calls (so no lists of pointers, no linked lists, etc). If you really wanted to pass in a list of strings, the easiest way I could think of would be to put them all in one giant string, with each substring separated by ‘\0’. You could then pass your giant string in as a char* and extract the substrings within the kernel (you’d also need to pass in the number of substrings, or the size of your giant string, as a parameter).

I don’t think anything like this would work in general. If you’re familiar with the OpenCL API then you know you have to call clCreateBuffer() and clEnqueueRead/WriteBuffer() for any pointer arguments passed into kernel functions. This suggests that nested pointer redirection is pretty much impossible for kernel arguments because the pointers would still be global and the kernel doesn’t know how to deal with global pointers unless they’ve been processed by the above function calls (so no lists of pointers, no linked lists, etc). If you really wanted to pass in a list of strings, the easiest way I could think of would be to put them all in one giant string, with each substring separated by ‘\0’. You could then pass your giant string in as a char* and extract the substrings within the kernel (you’d also need to pass in the number of substrings, or the size of your giant string, as a parameter).