C++ Integration

Hello all!

I know this has probably been asked a thousand times, but I can’t find good support on this…

What I’m trying to do is to have a normal c++ that works as the main class of my program, which basically controls the program flow. From here I want to call a .cu file containing a kernel.

I’ve seen some examples but none of them are working, even the cppIntegration example that comes with the sdk which, for some reason, I’m not able to compile…

How can this be done in a simple way?

Do you mean that the main() function in the *.cpp, the kernel function is in *.cu?

[b]//header.h

extern “C” {

void CudaFunction(parametter);

};[/b]

[b]//main function

include “header.h”

main()

{

//calling a cuda function

CudaFunction(parametters);

}[/b]

[b]//cuda.cu

include “header.h”

global void Kernel(someParametter)

{

}

void CudaFucntion(parametter)

{

/////

Kernel<<<>>>();

}[/b]

Am I understand correctly?

Yea, that’s exactly what I want! My main problem is compiling this two files…which is not working…

The SDK examples should compile…that may indicate something is wrong with your setup if they don’t. I would suggest looking into that further and possibly giving more information…

  • Do you get errors when trying to compile cppIntegration example? What are they?

  • What driver version are you using?

  • What Toolkit version are you using?

  • What OS?

  • Visual Studio? Makefiles?

  • etc…

Apparently it lacks cutil_inline.h…

But still, the Makefile requires a common.mk, which has as a bunch of stuff that makes it non-portable.

I was thinking if how do you compiling the .cpp and .cu files with a simple Makefile?

Ok, I finally got it to work!

Now, is it possible to use c++ as a basis, I mean, given it’s support for data structures like vectors and that kind of stuff, and then call cuda kernels?

For instance, I have my main function in c++, where I go through a vector and, depending on the current element, I want to call some kernel. The problem I’m facing is about how to allocate device memory from c++…

Is this even possible? Or is there some workaround?

Ok, found my problem!

It seems that I cannot call a kernel from an external function…how come? I changed the cppIntegration example to print something inside the kernel and it’s not printing either…

Ok, finnaly!

To be honest, I have no idea what was my problem, but I just got it to work by compiling it “manually”, so it probably was something to do with the Makefile.