Undefined device functions

Hello,

I am new to Cuda development and have run into a problem in which I cannot call some device functions before they are defined. I tried moving some of the functions around but 4 of them are recursive type functions and they call each other at different times. I tried to think of a way to fix this by creating some duplicate functions but the problem just arises again. Is it possible to call a function like this?:

__device__ void A()
{   int a = B();
}

__device__ int B()
{   return 1;
}

This is the only thing holding me back from finishing up a month long project to create my first Cuda app. Any help would be greatly appreciated.

Thanks

I think this is a basic C programming question. Don’t flush your C/C++ programming knowledge when you are doing CUDA programming.

__device__ int B(); // function prototype or "forward declaration"

__device__ void A()
{   int a = B();
}

__device__ int B()
{   return 1;
}

https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c

Hey.

I have virtually no C skills at all and have winged it for the last month. I used Visual Studio to recode some Python into C so I could use it on the gpu using PyCuda. I didn’t get any errors in VS so I assumed it would work ok. Thanks for the info on forward declaration. That sounds like that will solve everything. Thanks!