Is there a .NET-usable .dll example? Making CUDA available to .NET applications

Hi!

I have had some success building a .dll in ‘native’ C++ that exposes routines that call CUDA, and in using that .dll in a ‘native’ C++ test program (I am using Visual Studio 2008). But when I try to use this .dll in a .NET-enabled application, using either C++ with ‘common language runtime’ support or using C#, the code crashes inside the .dll, on a not-particularly conspicuous instruction, with the exception “An unhandled exception of type ‘System.AccessViolationException’ occurred in Example_Use_PInvoke.exe” (Example_Use_PInvoke.exe is the name of my test routine.) This is not a problem with data marshaling – the function I am calling has no arguments. I believe I have scrupulously used all the advice that Microsoft provides for calling unmanaged-code .dlls from managed code, and other routines I have written work OK.

Has anyone succeeded at this? I am very fond of C# as a development environment, and I thought I could just develop my class library in C++ and use it from C#, but so far, no luck.

// AllenC

I have succeeded at making a DLL and interfacing it with C#. This should help:

[url=“The Official NVIDIA Forums | NVIDIA”]The Official NVIDIA Forums | NVIDIA .

Also, make sure to include the:

using System.Runtime.InteropServices;

From there it is pretty straightforward.

ALLENC, was my link useful?

Hi!

Sorry for not responding sooner. I eventually did succeed in making a .dll that can be called from C#. I think I made every mistake possible along the way. The most confusing thing was to get the options in the CUDA build rule correct. There were notes about this in the ‘CUDA project wizard’ that was posted in these pages some time ago; but, being a beginner, I didn’t realize that every detail has to be just right. Anyway, now a little wiser, I will re-read the entries that you posted and maybe they will make better sense to me now. Thanks!

ALLENC