0

How do I use CUDA function in a cpp file?

I must use a CUDA function declared in "cuda.h" (or other cuda libraries), for example cudaMalloc. I know it is simple to do in .cu files but my project is extended, we decide call some CUDA functions in .cpp files.

I saw in the SDK some CUDA functions are called from main.cpp, so why is it not working for me? How do I configure CUDA with Visual Studio 2010?

The error is:

cudaMalloc identifier not found

and

undeclared identifier for size_t types

talonmies
  • 70,661
  • 34
  • 192
  • 269
Abdullah
  • 43
  • 8

2 Answers2

1

You can call CUDA API calls from C/C++ compiled with cl.exe, just make sure you include the cuda.h header and link with cudart.lib.

For more detailed instructions on setting up Visual Studio 2010, see this answer.

Community
  • 1
  • 1
Tom
  • 20,852
  • 4
  • 42
  • 54
1

I created my first cuda project following this link. Also, you need to include not only #include <cuda.h> but also #include<cuda_runtime.h>.

Fr34K
  • 534
  • 6
  • 19