Hi,
I need to use strings in kernel functions but whenever I use it I get the error that host function cannot be called in device code.
I searched about it and found out that as std::string is not primitive data type in c++ it is not allowed to be processed in kernels.
I need to use strings and their functions.
Can anyone please guide me about it ?
any sample code and suggestion would be appreciated.
I have heard about thrust but could not figure out how to use strings in thrust.
That’s correct, std::string is not usable in CUDA device code.
Typical advice would be to handle things as C-style arrays of char
There are various examples on the internet, here are a few:
https://stackoverflow.com/questions/34700999/cuda-passing-char-to-kernel/34712905#34712905
https://stackoverflow.com/questions/20201335/add-char-arrays-in-cuda/20201511#20201511
The last one gives examples of how you could do strcpy, strcat, and strcmp
With perhaps a bit more time spent on integration, you could investigate use of the custrings library: