Hi Folks:
I am just getting started with all these. I am think about calling CUDA code/kernel from my C# code. I want my CUDA code to do some image processing stuff, then my main program in C# handles the logic. I am using VS2008 C#, CUDA 5.0. (I am not even sure if they’re compatible) Here is what I found.
Use a third party wrapper above CUDA driver, options are :
CUDA.NET: it is kinda old, little support document, no example found yet
CUDAfy.NET: looks promising, with examples and ducument supporting, but it seems only compatible wtih .NET 4.0 or above.
Writing a wrapper myself: I am not confident, unless there is an example; Unfornately, I have not found much relevant material talking about CUDA with VS2008 C#
Any other options?
As far as I know CUDA.NET is a commercial library (one need to pay to use it, but trial is available). Indeed CUDAfy is a promising one but, to my knowledge, it lacks some of CUDA features (e.g. textures management, but dunno exactly). Writing a wrapper Yourself is a hard, time-consuming task which I not recommend.
You can try MC# (www.mcsharp.net).
A simple vector addition program in MC# looks like as
using System;
using GpuDotNet.Cuda;
public static class VectorAddition {
public static void Main ( String[] args )
{
int N = Convert.ToInt32 ( args [ 0 ] );
Console.WriteLine ( "N = " + N );
int[] A = new int [ N ];
int[] B = new int [ N ];
int[] C = new int [ N ];
for ( int i = 0; i < N; i++ ) {
A [ i ] = i;
B [ i ] = i + 1;
}
GpuConfig gpuconfig = new GpuConfig();
gpuconfig.SetBlockSize ( N );
gpuconfig.vecadd ( A, B, C );
for ( int i = 0; i < N; i++ )
Console.WriteLine ( C [ i ] );
}
public static gpu vecadd ( int[] A, int[] B, int[] C ) {
int i = ThreadIndex.X;
C [ i ] = A [ i ] + B [ i ];
}
}
The reason why I am sticking with vs2008 is that the project has been developed by vs2008 for a long time, and I am not the person who can decide whether to move to 2010/2012 or not.
So I came here to see if someone knows how to integrate a CUDA dll in to vs2008 C#, if there actually is a way to do so.
I think that you go to the problem from the wrong end, because a GPU programming is
a very specific thing.
First of all, you need to decide is it possible to do your stuff on GPU at all.
So it’s better to implement a simple part of your stuff within any VS
or without it at all and then to decide questions concerning VS.
I think what you’re looking for is [url]http://managedcuda.codeplex.com/[/url] : it is a complete CUDA wrapper written in C#. The binaries are .net 4.0 but you can compile it yourself to .net 2.0.
Here is a gudie page that provides sample code and detailed steps for image processing (such as image drawing, annotating, converting and compressing). You may refer to it.