A simple CUDA-MFC program

Well, it’s just a simple CUDA program written in MFC framework. You know, all CUDA examples in NVIDIA SDK were written by using GLUT library, so they only use glut-window. Here, I’m trying to combine CUDA+OpenGL+GLSL in an MFC program, and this is the result.cumfc

And the idea is simple, we can write CUDA kernel as a new class. Yeaa… then, you know how to work with a class, rite ?

#pragma once
// includes, system
// includes, project
// Required header to support CUDA vector types

__global__ void kernel( int* g_data );
__global__ void kernel2( int2* g_data );
__global__ void landKernel(float4* pos, unsigned int width, unsigned int height);

class CcudaKernel

void DoKernel(dim3 gridD, dim3 blockD, int* g_data);
void DoKernel2(dim3 gridD, dim3 blockD, int2* g_data);
void launchLandKernel(float4* pos, unsigned int mesh_width,
unsigned int mesh_height);
void computeGold(char* reference, char* idata, const unsigned int len);
void computeGold2(int2* reference, int2* idata, const unsigned int len);
void runTest(const int argc, const char** argv, char* data, int2* data_int2, unsigned int len);

void loadtotexture(cudaArray* cu_array, cudaChannelFormatDesc channelDesc);
void unbindTexture();
bool success;


You can download the complete code from the links below. But, please take a minute to drop email and comment/request for the password, I’ll reply directly to your email within 24 hours.

I have moved the source to bitbucket.org and open it. So, now you can clone or download it and NO password is needed. Please visit https://bitbucket.org/mteguhsat/cudamfc

Latest test: VS2010 and CUDA 6.5

Old versions (developed in VS 2008 on a 32-bit machine by myself):

Password for old versions: parasatria.tk

for CUDA 3.0 : cudaMFC.rar

for CUDA 3.1 : cudaMFC31.rar (thanks to Jun Wei for experience sharing in compiling this code using CUDA 3.1)

for CUDA 3.2 : use the same code with CUDA 3.1, but you need to make some changes in your project and it’s all about new build rules provided by CUDA toolkit. So, follow these steps (thanks to Manel for giving me idea on this) :

  1. Put your cursor on project root, then go to Project menu, then click Custom Build Rules.. (see image below)
  2. A Visual C++ Custom Build Rules Files window will appear..  select one of CUDA Runtime API Build Rule (v3.2) and click OK then.
  3.  Go to the Project’s Properties, find Configuration Properties > Linker > General, and in Additional Library Directories row, add $(CUDA_PATH)/lib/$(PlatformName).
  4. Still in Project’s Properties, find the CUDA Runtime API in the sidebar, click General, then in Additional Include Directories row fill with $(NVSDKCOMPUTE_ROOT)/C/common/inc, then click OK.
  5. Compile it now.

using CUDA 4.2 on VS 2010 : cudaMFC2010.rar or mirror. (thanks to Lho). Note: I don’t have chance to test this version currently, so any question regarding this version please address it directly to: lhoffart@free.fr

If you get more problem in compiling the codes, please let me know. 🙂



Great! Your project’s work, even with NVidia Ion (16 cores), the picture rotate is instant.
I use an ASUS Eee PC Seashell series, Windows 7 32bit & CUDA 3.2 (3.1 don’t recognize Ion).

With CUDA 4.0 & 4.2, I have got a lot of redéfinitions between glfreeglut_std.h and GL/glut.h.
But, fortunately, even most recent Geforces are compatible CUDA 3.0.

Thank you! Except your blog, CUDA & MFC is strangely untraceable on web and the books.
Now, I can work correctly.

I put a short agree message among the comments of your blog. There are almost exclusively comments with ‘send me the password’.
I wish my english is not too bad.

Eric (Paris, France).

using CUDA 5 on VS2010 : cuda5MFC10.zip

219 thoughts on “A simple CUDA-MFC program

  1. Glad to you demo, that is what I need.
    Thanks for your work.
    Can you send me the password?
    Also I use cuda 4.0 do I need to do some modification ?



  2. Could you send me the password, I have a movie editor project on CUDA+MFC, but some reason I need to use cuda-opengl… if can plz, send me the passwords.


  3. very good example. i was trying to the similar thing, but got constant linking errors. can you give me pass code to the file cudaMFC31.rar? thank you very much.


  4. Hello,
    This is a new version of the cudaMFC project build with Visual studio 2010 (x86 and x64).
    The project use the last cuda sdk release 4.2.

    You can download the project with the link bellow and the password is the same as the original project.


  5. Hi, Good job. I am learning how to write a kernel class. please send a password to me! Thank you! I appreciate it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.