CUDA + C# .Net problem DLL importing problem in different machines

My application consists of a main C# Windows Forms project, and the CUDA project, which is built into a DLL and loaded by the main app.
If I build this solution it works just fine, but when I build it in one machine and run in another, same operating system and latest drivers/toolkit, the methods imported from the DLL don’t work. When I build the solution in this machine, the software works well.
I’m using Visual Studio 2008, latest dev drivers, CUDA Toolkit 3.1 and both Windows 7 x86 and x64 versions.

Can you give any specifics on the error that’s occurring? In any case, you’ll need to build both 32-bit and 64-bit versions of the native DLL; if you give them the same name (e.g. “native.dll”), then you can use a single P/Invoke signature in your C# project for both of them (well, a single signature for each method you call in the native DLL). You only need one version of the C# project though.

Can you give any specifics on the error that’s occurring? In any case, you’ll need to build both 32-bit and 64-bit versions of the native DLL; if you give them the same name (e.g. “native.dll”), then you can use a single P/Invoke signature in your C# project for both of them (well, a single signature for each method you call in the native DLL). You only need one version of the C# project though.

I have set different build paths for x86 and x64. The problem appears in different machines using the same operating system. For example, I build the software at work, and the methods from de DLL don’t work at home (both 32 bits machines). I don’t know what the error is. The methods are being imported with the [DLLIMPORT] attribute, and these methods are simple not being imported.

Edit: I want to build a release version of the software, that works in any machine that have proper GPU and driver version installed (x86 Release for x86 machines and x64 for a 64 bits Windows).

I have set different build paths for x86 and x64. The problem appears in different machines using the same operating system. For example, I build the software at work, and the methods from de DLL don’t work at home (both 32 bits machines). I don’t know what the error is. The methods are being imported with the [DLLIMPORT] attribute, and these methods are simple not being imported.

Edit: I want to build a release version of the software, that works in any machine that have proper GPU and driver version installed (x86 Release for x86 machines and x64 for a 64 bits Windows).

How are you specifying the name of the DLL in [DllImport]? You should only be using the name of the dll (no path, no extension), e.g., [DllImport(“nvcuda”)]. If the .NET code is breaking (throwing an exception) the FIRST time you call one of the DllImport’ed methods, then it’s probably that .NET can’t find the DLL for some reason.

You could try wrapping the calling code in a try/catch block, and check for a DllNotFoundException:

try

{

...

}

catch (DllNotFoundException dnfe)

{

//

int blah = 0;

}

Put a breakpoint on the “int blah = 0;” line…if it hits, then you’ll know that’s the problem.

Otherwise, maybe you’re linking some other code dynamically in your native (CUDA) DLL and it can’t be found when you run it on your home system.

How are you specifying the name of the DLL in [DllImport]? You should only be using the name of the dll (no path, no extension), e.g., [DllImport(“nvcuda”)]. If the .NET code is breaking (throwing an exception) the FIRST time you call one of the DllImport’ed methods, then it’s probably that .NET can’t find the DLL for some reason.

You could try wrapping the calling code in a try/catch block, and check for a DllNotFoundException:

try

{

...

}

catch (DllNotFoundException dnfe)

{

//

int blah = 0;

}

Put a breakpoint on the “int blah = 0;” line…if it hits, then you’ll know that’s the problem.

Otherwise, maybe you’re linking some other code dynamically in your native (CUDA) DLL and it can’t be found when you run it on your home system.

When I catch the exception, it gives me the following message:

External Media

When I catch the exception, it gives me the following message:

That error probably has to do with your native DLL, not .NET. I don’t use Visual Studio C++ a whole lot (I do nearly all of my programming in C# or F#), but here’s the steps I’d take (in order):

EDIT: 0) Try adding the /MT or /MTd compiler flag, which should remove your runtime dependency. If that fixes it, you’ll know it’s a VC++ runtime issue (see #3 below).

  1. Check event viewer for more information (Control Panel → Administrative Tools → Event Viewer → “Windows Logs” → Application). Look at the timestamps of the entries to make it easier to find which one you need.
  2. Make sure your home machine has all updates installed.
  3. If you don’t have Visual Studio installed on your home machine (the one getting the error), or you have a different version, make sure you’ve got the correct Visual C++ runtime installed (you can download it for free).
  4. Install SP1 for Visual Studio 2008. I think the original version of Visual Studio 2008 had some issues with Vista / Windows 7.

If all of that doesn’t work…I suppose try the sxstrace tool (which I never used, so I can’t give you any advice on).

That error probably has to do with your native DLL, not .NET. I don’t use Visual Studio C++ a whole lot (I do nearly all of my programming in C# or F#), but here’s the steps I’d take (in order):

EDIT: 0) Try adding the /MT or /MTd compiler flag, which should remove your runtime dependency. If that fixes it, you’ll know it’s a VC++ runtime issue (see #3 below).

  1. Check event viewer for more information (Control Panel → Administrative Tools → Event Viewer → “Windows Logs” → Application). Look at the timestamps of the entries to make it easier to find which one you need.
  2. Make sure your home machine has all updates installed.
  3. If you don’t have Visual Studio installed on your home machine (the one getting the error), or you have a different version, make sure you’ve got the correct Visual C++ runtime installed (you can download it for free).
  4. Install SP1 for Visual Studio 2008. I think the original version of Visual Studio 2008 had some issues with Vista / Windows 7.

If all of that doesn’t work…I suppose try the sxstrace tool (which I never used, so I can’t give you any advice on).

The Dll is being compiled with the /MT and /MTd already, and I have Visual Studio 2008 and the last updates installed in my home machine. I will search for more info about the sxstrace tool.
By the way, do you have any other sugestions to work with C# + CUDA, besides the native DLL alternative?

The Dll is being compiled with the /MT and /MTd already, and I have Visual Studio 2008 and the last updates installed in my home machine. I will search for more info about the sxstrace tool.
By the way, do you have any other sugestions to work with C# + CUDA, besides the native DLL alternative?