JOCL Hello World program

I tried writing a hello world program on JOCL …
though the program runs fine I dont see the actual output. It shows sum unreadable characters…
I have attached the program

and here is my kernel source

#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
__constant char hw[] = “Hw”;
__kernel void hello(__global char * out)
{
size_t tid = get_global_id(0);
out[tid] = hw[tid];
}

Help would be appreciated as there is hardly any online reference

Hello Soyeed,

Note that there is a difference between a ‘char’ in C/OpenCL, and a ‘char’ in Java. In C/OpenCL a ‘char’ has exactly 1 byte. In Java, a ‘char’ has 2 bytes, because it can also store Unicode characters and all that… In Java, the variable type which has 1 byte is called ‘byte’.

Thus, to receive the desired output, you have to change your variable declarations to

byte[] hw={'h','w'};
byte[] dst=new byte[hw.length+1];

and the result may be printed with something like

System.out.println(new String(dst, 0, dst.length-1));

(the last byte is ‘0’, which is required for C/OpenCL strings, but not for Java Strings)

bye

EDIT: By the way, you could probably leave out the additional ‘+1’ extra byte throughout the program, and finally print the result with
System.out.println(new String(dst));

Thanks a lot Marco…that explains everything. and the solution works too