加入CUDA字符数组 [英] Add char arrays in cuda
问题描述
我想在CUDA加2字符数组,但没有什么工作。
我试图用
字符临时[32];
的strcpy(温度,my_array);
strcat的(温度,my_array_2);
当我用这个内核 - 我得到错误:调用从__global__函数(过程)一__host__功能(strcpy的)是不允许
在此之后,我试着在主机使用这些功能,而不是内核 - 没有错误,但加入后我收到奇怪的符号,比如ĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶ
所以,我怎么能在 CUDA
?
所以,我怎么能在CUDA添加两个(或更多)字符数组?
块引用>编写自己的函数:
__ device__的char * my_strcpy(字符* DEST,为const char * SRC){
INT I = 0;
做{
DEST [I] = SRC [i];}
而(SRC [我++]!= 0);
返回DEST;
}__device__的char * my_strcat(字符* DEST,为const char * SRC){
INT I = 0;
而(DEST [I]!= 0)我++;
my_strcpy(DEST + I,SRC);
返回DEST;
}虽然我们在这,<一个href=\"http://stackoverflow.com/questions/19600879/how-to-compare-arrays-of-char-in-cuda-c/19602075#19602075\">here为
STRCMP
I am trying to add 2 char arrays in cuda, but nothing is working. I tried to use:
char temp[32]; strcpy(temp, my_array); strcat(temp, my_array_2);
When I used this in kernel - I am getting
error : calling a __host__ function("strcpy") from a __global__ function("Process") is not allowed
After this, I tried to use these functions in host, not in kernel - no error,but after addition I am getting strange symbols like
ĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶ
.So, how I can add two ( or more ) char arrays in
CUDA
?解决方案So, how I can add two ( or more ) char arrays in CUDA ?
write your own functions:
__device__ char * my_strcpy(char *dest, const char *src){ int i = 0; do { dest[i] = src[i];} while (src[i++] != 0); return dest; } __device__ char * my_strcat(char *dest, const char *src){ int i = 0; while (dest[i] != 0) i++; my_strcpy(dest+i, src); return dest; }
And while we're at it, here is
strcmp
这篇关于加入CUDA字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!