How to convert lowercase to uppercase in OpenCL or vise-versa

332 Views Asked by At

Hi i have a vector of char16 containing some special characters and lowercase alphabets, is is possible to check each char if :

1.) is an alphabet? if it is then i would convert it to lowercase letter or vice versa

2.) if its a special characters or spaces (eg. ' ' or ' " ' aka apos or ',' or '-' etc. then i would leave it as it is

Below is my unfinished kernel, i before moving my character by 'n' amount, i would like to check each character if its a char and convert it to upper/lower case

__kernel void A2_T2_B(      
                        __global int n,
                        __global char16* char_vec,
                        __global char* encrypted,
                        __global char* decrypted        ) {



int i = get_global_id(0);



if (n>0)
{
     if(any(char_vec[i]=='z')==1))
     {

     }
     char_vec[i]+=n;

}

else if(n<0)
{
     char_vec[i]-=n;

 }

}
2

There are 2 best solutions below

3
pmdj On

OpenCL doesn't have any built-in string handling functions if that's what you're asking. You will need to implement them yourself, or find a 3rd party library.

There isn't a general answer we can give, because the implementation will depend heavily on the encoding. For plain ASCII, you can use something like:

bool isupper(char c)
{
    return (c >= 'a' && c <= 'z');
}
1
Mehroz Mustafa On

Just add this simple condition for conversion

for (int i = 0; arr[i] != '\n'; i++) {
    if (arr[i] <= 'a' && arr[i] >= 'z') {
        arr[i] = (int)arr[i] - 32;     // A: 65, a: 97 ;  a - A = 32
        // or   arr[i] = arr[i] - ' ';
   }
}