I have solved the problem
:
As far as I understand, if the dll contains the obj files that created by nvcc, C# side does not recognize this dll. So I splitted my dll project into two projects:
i) Cuda_Kernel
ii) Cuda_API
First one is including the kernel files and does the real job and the other is to call the first dll.
Cuda_Kernel project has one entry function and defined as:
“extern “C” __declspec( dllexport ) void runTest(Parameters *params)”.
This project outputs “cuda_Kernel.dll”
Cuda_API project also has one entry function and defined as:
“extern “C” __declspec( dllexport ) int CUDA_main(Parameters *params”.
Here is the code of CUDA_main function:
extern "C" __declspec( dllexport ) int CUDA_main(Parameters *params)
{
// get handle to dll
HINSTANCE hGetProcIDDLL = LoadLibrary("cuda_Kernel.dll");
// get pointer to the function in the dll
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "runTest");
//Define the Function in the DLL for reuse. This is just prototyping
//the dll's function. A mock of it. Use "stdcall" for maximum
//compatibility.
typedef void (* pICFUNC)(Parameters*);
pICFUNC runTest;
runTest = pICFUNC(lpfnGetProcessID);
// The actual call to the function contained in the dll
runTest(params);
// Release the Dll
FreeLibrary(hGetProcIDDLL);
return 0;
}
This project outputs “cuda_API.dll”.
And from C# side “CUDA_main” is called like this:
class CUDAMAIN_class
{
[DllImport("cuda_API.dll")]
public static extern int CUDA_main(ref Parameters p);
public void CUDA_main_call(ref Parameters p)
{
CUDA_main(ref p);
}
}
...
CUDAMAIN_class my_cuda = new CUDAMAIN_class();
my_cuda.CUDA_main_call(ref params_struct);
I hope this helps 