Hello everyone,
I am currently looking for examples of creating a DLL using CUDA and using it in a C# project in Visual Studios 2010.
I thought I did it correctly but I’m not having any good luck.
What I did was copy out the template project from the example and gotten cuda to do what I needed in it.
Right now is just trying to get my c# class to use the dll even as a test.
=------
//CudaWrapper.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CudaDllTest
{
class CudaWrapper{
[DllImport("CudaCodes.dll")]
public static extern int _DllTest();
int nTester = 5;
//strctres
public void dllRun()
{
//crash here
//Unable to find an entry point named '_DllTest' in DLL CudaCodes.dll'.
int nTestResult = _DllTest();
}
}
}
//template.cu output → CudaCodes.dll at C# application folder
extern "C" int _DllTest(int nInput)
{
return nInput +10;
}
I’m getting a “Unable to find an entry point named ‘_DllTest’ in DLL CudaCodes.dll’”
any suggestings, thank you
The following link does not have anything CUDA related, but may server as a starting point to getting something connected to C#
[url=“How to create a DLL library in C and then use it with C# - CodeProject”]How to create a DLL library in C and then use it with C# - CodeProject
Please respond back if you find anything CUDA related that causes any difficulty, or if you have success and want to share what you discover.
Thanks for the link. It gave me a good direction on what to do.
Here are some other note I’ve found out:
function declaration in the .cu must be inside extern “C” brackets
example
extern “C”{
__declspec(dllexport) void Cuda_InitVariables();
__declspec(dllexport) int Cuda_ActivateDevice();
__declspec(dllexport) bool Cuda_Action(int nDeviceNumber);
__declspec(dllexport) bool Cuda_FreeMem();
}
and in the c# source code if you are passing a variable “CallingConvention = CallingConvention.Cdecl” must be in the DllImport.
[DllImport("CudaCodes.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool Cuda_Action(int nDeviceNumber);
Im using CUDA via dll in C# but via an alternative method and it seems reasonably simple to me. I have created a managed wrapper in C++/CLI around my C++ classes with all my CUDA stuff in and then just added this managed wrapper as a reference in my c# project.
linky