在 cuda 中添加 char 数组 [英] Add char arrays in cuda

查看:22
本文介绍了在 cuda 中添加 char 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 cuda 中添加 2 个字符数组,但没有任何效果.我尝试使用:

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);

当我在内核中使用它时 - 我收到 error : Calling a __host__ function("strcpy") from a __global__ function("Process") is not allowed

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 ĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶĶ.

那么,如何在 CUDA 中添加两个(或更多)字符数组?

So, how I can add two ( or more ) char arrays in CUDA ?

推荐答案

那么,如何在 CUDA 中添加两个(或更多)字符数组?

So, how I can add two ( or more ) char arrays in CUDA ?

编写你自己的函数:

__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;
}

当我们这样做时,这里strcmp

这篇关于在 cuda 中添加 char 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆