wstring in OpenCl!

Hello,
I was wondering if there is anyway that I could write a kernel function that deals with strings of type wstring… I need to write a program that would run on GPU that will deal with arabic language… I wrote a kernel function and defined inside it a variable of type wstring but it always fails to build!
also wanted to ask about the datatype cl_uchar… is this type for unicode languages???
Thanks!

Hello,
I was wondering if there is anyway that I could write a kernel function that deals with strings of type wstring… I need to write a program that would run on GPU that will deal with arabic language… I wrote a kernel function and defined inside it a variable of type wstring but it always fails to build!
also wanted to ask about the datatype cl_uchar… is this type for unicode languages???
Thanks!

There is no wstring in OpenCL as it is quite low level language, rather for speeding up programs. cl_uchar stands for unsigned char. You can make your own struct to hold several chars which will stand for wchar or use vector type like char2.

There is no wstring in OpenCL as it is quite low level language, rather for speeding up programs. cl_uchar stands for unsigned char. You can make your own struct to hold several chars which will stand for wchar or use vector type like char2.

Thanks very much for the answer!

I used char2 type and the program built correctly

but the problem is in the calling from the host… I created a kernel object and I want to set its arguments whose type is char2* (unicode string) but in the host I can’t deal with cl_char2 variables! I can’t assign a value to cl_char2* variable and I can’t put unicode string in the normal char* datatype!

I need to end a unicode string to my cl function, what shall I do? sorry for my many questions as I am an OpenCL beginner.

Thanks very much for the answer!

I used char2 type and the program built correctly

but the problem is in the calling from the host… I created a kernel object and I want to set its arguments whose type is char2* (unicode string) but in the host I can’t deal with cl_char2 variables! I can’t assign a value to cl_char2* variable and I can’t put unicode string in the normal char* datatype!

I need to end a unicode string to my cl function, what shall I do? sorry for my many questions as I am an OpenCL beginner.

I must say I’m not a best adviser with different types of strings and chars. Nevertheless, wstring comes like an array of wchar_t (what I understand wchar_t is not a best type as it has different size on different platforms). Find out what lengths has your wchar_t and convert to multiple chars with bit masking.

cout << "size of wchar_t " << sizeof(wchar_t) << " sizeof char " << sizeof(char) << endl;
my output:
size of wchar_t 4 sizeof char 1

So I need 4 chars to represent single wchar_t:
wchar_t a = wchar_t(“a”);
char* array = new char[4];
array[0] = a&0xFF000000;
array[1] = a&0x00FF0000;
array[2] = a&0x0000FF00;
array[3] = a&0x000000FF;

In OpenCL I would load it as char4. After that it depends what you are going to do with those chars in kernel, to modify the strings you should be aware what endianness it has and so on and your application most probably won’t be portable:-(

I must say I’m not a best adviser with different types of strings and chars. Nevertheless, wstring comes like an array of wchar_t (what I understand wchar_t is not a best type as it has different size on different platforms). Find out what lengths has your wchar_t and convert to multiple chars with bit masking.

cout << "size of wchar_t " << sizeof(wchar_t) << " sizeof char " << sizeof(char) << endl;
my output:
size of wchar_t 4 sizeof char 1

So I need 4 chars to represent single wchar_t:
wchar_t a = wchar_t(“a”);
char* array = new char[4];
array[0] = a&0xFF000000;
array[1] = a&0x00FF0000;
array[2] = a&0x0000FF00;
array[3] = a&0x000000FF;

In OpenCL I would load it as char4. After that it depends what you are going to do with those chars in kernel, to modify the strings you should be aware what endianness it has and so on and your application most probably won’t be portable:-(

I don’t know how to thank you! I’ll try this

I don’t know how to thank you! I’ll try this