BRabbit27
BRabbit27

Reputation: 6623

More than one instance overloaded function has C linkage

Following the sample code in CUDA samples about C++ integration I was writing the wrapper functions that call CUDA code in a .cu file.

In that file I have a function that initializes CUDA context and allocates global memory and puts some data in constant memory.

extern "C" void initEngine(int *d_data, int *d_coefA, int *d_coefB)
{
   //Allocations
   //Copy to constant memory
}

Now what I want to do is overload that initEngine function to receive to more parameters but I think there's no way to overload that function as it has C linkage am I right?

extern "C" void initEngine(int *d_data, int *d_coefA, int *d_coefB, int *d_coefC, 
                           int *d_random)
{
   //Allocations
   //Copy to constant memory
}

Could you give me some advise to have only one initEngine function? or is not possible and I have to have 2 functions or probably have only one function with all the parameters and just pass NULL references or something like that.

Upvotes: 4

Views: 12399

Answers (2)

NoseKnowsAll
NoseKnowsAll

Reputation: 4624

This probably doesn't address OP's concern, but I ran into this same issue myself when trying to link with cublas in C++ code. Instead of including cublas.h, I solved the problem with

#include <cublas_v2.h>

Upvotes: 0

Robert Crovella
Robert Crovella

Reputation: 152123

Yes, overloading is a C++ feature.

If you want to have overloaded functions that are callable from other modules, use C++ throughout (i.e. don't use extern "C", and keep all your files as .cpp or .cu).

If you don't wish to do that, you could try resorting to macros or some other magic.

Upvotes: 4

Related Questions