Can not pass char* in OpenCL

Hi Macro,

I am implementing Smith waterman and I need to pass character array into kernel, however it does not work correctly.

My CL sample code:

  __global char *s1,
  __global char *s2)
{
    // try to print s1 or elements in s1
    for (int k = 0 ; k < 6; k++) {
        printf("%c", s1[k]);
    }
}```

My Java code:

```String s1 = "ANANAS";
String s2 = "BANANE";

cl_mem s1Mem = clCreateBuffer(context, CL_MEM_READ_ONLY | CL.CL_MEM_COPY_HOST_PTR,  
				  Sizeof.cl_char * (s1.length()), Pointer.to(s1.toCharArray()), null);

cl_mem s2Mem = clCreateBuffer(context, CL_MEM_READ_ONLY | CL.CL_MEM_COPY_HOST_PTR,  
				  Sizeof.cl_char * (s2.length()), Pointer.to(s2.toCharArray()), null);

.....```

But When I ran jocl java code to do parellel computing, the output of of s1 in OpenCL is not "ANANAS", it printed "ANA" or A or ANANAN sometime. Is there something wrong in my code ?

Thanks,
Duy

Caution: a cl_char and a Java char do NOT have the same size. In C and OpenCL the type char or cl_char always refers to a single byte - that is, an ASCII character - and has 8 bits. In Java, a char is a Unicode character, and has 16 bits.

In general, you can assume: OpenCL-char = Java-byte

So your should not use Pointer.to(string.toCharArray())
But you should use Pointer.to(string.getBytes())

It worked. Thanks Marco !