cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

String manipulation

Hi,

I'm trying to work with string (array of char) with OpenCL.

Do you think it is possible to do ?

Something like :

1 - Pass a char buffer to a kernel
2 - Put string into the char array (strcat, strcpy)
3 - Convert integer and float to string

etc ...

Thanks 

0 Likes
4 Replies
Sheeep
Journeyman III

1 - you have to use cl_char instead of char in Hostcode

2-  in host code:

           cl_char host_char[stringname.length()];

           const *char pointer = stringname.c_str();

           for(int i=0;i<stringname.length();i++){

                 host_char=   pointer ;    

           }

3 - to convert int and float you string s=""+int/float or use sstream. Note: strings are only availible in hostcode:

#include <sstream>

stringstream converter;

int i=100;

std::string s;

converter<<i;

converter>>s;

converter.clear();

you can do the same with floats

 

 

 

 

 

 

0 Likes
spectral
Adept II

Thanks but,

I don't need the 'host' code I need the 'kernel' code ... can you help me wth this ?

0 Likes

you can't use strings in the kernel...

string is a additional class in c++, which is not supported in opencl.

you have to use char array. but be carefull, you cannot use arrays with dynamic length in opencl.

so you have to know, how long you char array wil be, before you start the kernel.

psydocode:

__kernel void example(__global char* in, __global char *out, __global int *length_in, __global int* length_out){

          for(int i=0;i< length_out[0];i+=2){

                out[ i]=in[ i];

                out[i+1]=in[ i];

          }

}

in this case length_out =2* length_in

note that worksize 1. so it don't work parallen and may be slow.

example:

in =hello; length_in=5;

out_length=10;

run kernel

--> out=hheelloo;

 

0 Likes
genaganna
Journeyman III

Originally posted by: viewon01 Hi,

 

I'm trying to work with string (array of char) with OpenCL.

 

Do you think it is possible to do ?

 

Something like :

 

1 - Pass a char buffer to a kernel 2 - Put string into the char array (strcat, strcpy) 3 - Convert integer and float to string

 

etc ...

 

 

 

  You can write kernels to implement such fuction.

0 Likes