call a device function from a c++ file

Dear all,

I found a solution where a global cuda file is called from a c or c++ file.
It is done with a wrapper.

However, I need to have a return values and, moreover, I need two different cuda functions. As far as I know we can’t declare two global functions.

I have a header file, cuda file (main function is there) and a c++ file.

main function calls an “A” function in a c++ file,
then “A” function calls a “B” wrapper function in a cuda file
“B” wrapper function needs to call a “C” device function in cuda - here I have an error.

In further I need to return data and then call another cuda device function and return data.

You haven’t said in which file the “C” function is defined. Nor do you make it clear when you say “device function” whether you mean a function marked with global or a function marked with device

With a bit of effort on your part, you could probably create a complete minimal example in only about 20 or so lines, that demonstrates your problem.

Using typical compile settings, it’s not possible to call a function marked with

device

or

global

directly from a file with an extension of .cpp, or .c

Use wrapper functions instead (and a device function cannot be called directly from host code anyway).

If you want to call a global function from another global function, that will require the use of CUDA Dynamic Parallelism, which is covered in its own section in the programming guide:

https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#cuda-dynamic-parallelism

Thank you, txbob.

I called a global function from a wrapper and it worked.