Can string data types be used in C++ CUDA kernels?

為{幸葍}努か 提交于 2019-12-17 20:41:12

问题


I am writing a CUDA kernel in which I'm using the string data type in C++. However, the compiler is throwing the following error :

error: calling a host function("std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator =") from a __device__/__global__ function("doDecompression") is not allowed

Are strings not allowed within a kernel? if not, what is the workaround to allocate space for a char array within a kernel?


回答1:


You cannot use the C++ string type in a kernel because CUDA does not include a device version of the C++ String library that would be able run on the GPU. Even if it was possible to use string in a kernel, it's not something you would want to do because string handles memory dynamically, which would be likely to be slow.

Instead, create an array of fixed length strings and copy the strings to it. Then copy the array to the GPU. Pass the base address of the array of strings to your kernel and have each thread calculate the address to a given string by adding an offset based on its index to the base address.



来源:https://stackoverflow.com/questions/9910739/can-string-data-types-be-used-in-c-cuda-kernels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!