4 Replies Latest reply on Feb 4, 2010 5:42 AM by genaganna

    String manipulation

    spectral

      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 

        • String manipulation
          Sheeep

          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

           

           

           

           

           

           

          • String manipulation
            spectral

            Thanks but,

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

              • String manipulation
                Sheeep

                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;

                 

              • String manipulation
                genaganna

                 

                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.