What programming language should I use?

Hi,

I need to develop a software package with quite a lot of GUI involved, which will incorporate some CUDA code as well.
My first inclination was to use Visual C#, as I have always found it to be the best language to program GUI with in terms of ease of programming and flexibility.
My experiments in incorporating CUDA C++ code with C# have been unsuccessful till now. I’m starting to think maybe I should just program everything in C++.

What’s your opinion? A case where a lot of GUI is involved, would you program everything in C++ just to ease the incorporation of CUDA or will you go for a different programming language for dealing with the GUI?

Interested to hear your opinions…

Thanks!
Y.

First, CUDA (as in what nvcc is processing) is neither really C nor C++, which might explain some of your problems.

I do not really program GUIs if I have any way to avoid it, but if it is (and probably will remain) something you can click together I’d stay with that (I guess that Qt is not an option for you - while not quite as comfortable IMO it has quite powerful GUI editors).

Depending on what exactly you intend to do, you might also have the option of creating two programs: one for the GUI and one to do the calculation, communicating with one of the many facilities for that (shared memory, pipes, DCOM, …).

I hardly ever program Windows programs anymore, so I do not know how well that stuff works (nowadays).

Search the forums: I believe there are some posts where someone successfully integrated with C#.

I’m fond of python for quick and dirty GUIs. Python and C++ can be fully integrated easily with boost.python.

The last time I did a professional GUI was with wxWidgets (similar to Qt) and C++. It can be used from python too, but I haven’t done any professional GUIs since I learned python.

Ive integrated a cuda/c++ dll in a C# application.

Nothing much to it if you know how the DllImport works in C#.

You compile the C/C++ code as a dll (project->properties->general->Configuration type)

C++:

extern "C" __declspec(dllexport) int doCuda( unsigned int threshold, int width,  int height, unsigned char *pixels,  unsigned char* oldPixels,unsigned  char *moved)

{	

... stuff

somewhere in here you call the kernel

...

}

In C#:

[DllImport("motionDetectCuda.dll")]

 �  �  �   public unsafe static extern int doCuda(uint threshold, int width, int height, byte[] pixels, byte[] oldpixels, IntPtr moved);

doCuda(threshold, streamSize.Width, streamSize.Height, bytes, oldbytes, pData.AddrOfPinnedObject());

Obviously the function signatures will vary, i just didnt modify mine to post this snipped.

So calling functions is easy, but marshalling the data between the 2 is a real pain in the ass. So depending on what kind of data you want to move around C# and C++, youll have a lot of fun looking for how to do that. Plenty of answers on the web.

This might help somebody… to move a an unsigned char* between C++ and C#:

moved = new byte[numBlocksH * numblocksV];

GCHandle pData = GCHandle.Alloc(moved, GCHandleType.Pinned);

doCuda(threshold, streamSize.Width, streamSize.Height, bytes, oldbytes, pData.AddrOfPinnedObject());

I have not tested the speed of calling a dll from C#. It was “fast enough” for a baby project i spent two days on and had no intention of really working through.

You could use Java and JNI, I think, although you might need a one-line zlib patch to get around Sun’s hilariously old version of zlib statically linked into the JVM.

I :heart: Qt

Totally forgot about that–if you’re willing to pay for Qt or are writing a GPL app, Qt is the absolute best C++ GUI library (and it’s still useful for other stuff, like networking).

Wrote a pretty enormous robotics app using Qt when I was still in school–very friendly to work with.

thanks everyone… I ended up using C#, I managed to compile cuda code into a dll and call it from C# and performance seem satisfactory. I’m not familiar with Qt, I will look into that as well…

Thanks!

Y.