Reputation: 577
As I know, CUDA supports C and C++. But I can't' use C++ in my kernel.
I try a simple example like this
__global__ void simple(){
cout<<"abc";
}
That is error. But if I change to printf("abc");
it is right.
Can you explain for me? Thank you very much!
Upvotes: 2
Views: 1588
Reputation: 905
From CUDA 7.5 nvidia slides:
C++11 Supported features:
C++ Not supported features
std::cout
is defined in the C++ standard library which is not supported by CUDA. Use C printf
From CUDA 6.5, the ‘compute_11′, ‘compute_12′, ‘compute_13′, ‘sm_11′, ‘sm_12′, and ‘sm_13′ architectures are deprecated. So nvcc
will compile by default to CC 2.0 enabling printf
support.
Upvotes: 5
Reputation: 313
CUDA doesn't link the libraries & header files that are required to use the cout
function. However, you can enable the use of printf()
This answer explains the process which enables this feature: printing from cuda kernels quoted here for easier access:
To enable use of plain printf() on devices of Compute Capability >= 2.0, it's important to compile for CC of at least CC 2.0 and disable the default, which includes a build for CC 1.0.
Right-click the .cu file in your project, select Properties, select Configuration Properties | CUDA C/C++ | Device. Click on the Code Generation line, click the triangle, select Edit. In the Code Generation dialog box, uncheck Inherit from parent or project defaults, type compute_20,sm_20 in the top window, click OK.
Upvotes: 0