I am hesistant to call this one a bug because the OpenCL spec is not very explicit when it comes to literal strings. But in any case, the following code doesn’t seem to compile.
int stringLen(const char *s)
{
int len = 0;
while(*s != 0)
{
s++;
len++;
}
return len;
}
__kernel void test_calc_kernel(__global void *heap, __global unsigned int *printbuf)
{
int len;
const char *s = “Hello World”;
len = stringLen(s);
printbuf[0] = 0;
}
clBuildProgram (CUDA 2.3) returns an error that says:
ptxas ptx input, line 53; fatal : Parsing error near ‘;’: syntax error
: Retrieving binary for ‘anonymous_jit_identity’, for gpu=‘sm_13’, usage mode=’
However, if I put the string on the __private char buffer, then it seems to compile and run. For example, if I change the second function to:
__kernel void test_calc_kernel(__global void *heap, __global unsigned int *printbuf)
{
int len;
const char s = {‘H’,‘e’,‘l’,‘l’,‘o’,’ ',‘W’,‘o’,‘r’,‘l’,‘d’};
len = stringLen(s);
printbuf[0] = 0;
}
For now, I made a workaround utility that converts all the literal strings in the code to char buffer. That’s not good since I suppose every invocation will involve a construction of the array.
Therefore, I’d like to know if the literal string problem is an expected behavior or something that will hopefully be fixed in a future release. If it is expected, i.e. literal string is for all intents and purposes not a supported feature in Nvidia’s implementation of OpenCL, I’d just resort to a different strategy, say pre-build a string table and put it on either __global or __constant. But if literal string is something that will be fixed, I’ll live with the workaround for now.
Thanks.