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 ?

[sourcecode language=”cpp”]
#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

221 thoughts on “A simple CUDA-MFC program”

  1. After some steps has been taken, it works fine. :=)

    1. copy cuda.rules to C:Program FilesMicrosoft Visual Studio 9.0VCVCProjectDefaults

    2. remove rendercheck_gl.h from project

    3. remove codes below in file redercheck_gl.cpp
    CFrameBufferObject::CFrameBufferObject(unsigned int width, unsigned int height,
    unsigned int Bpp, fboData &data, fboConfig &config,
    bool bUseFloat) :
    #if !NEW_FBO_CODE
    initialize(width, height, m_fboConfig, m_fboData);


    CFrameBufferObject::CFrameBufferObject(unsigned int width, unsigned int height,
    unsigned int Bpp, fboData &data, fboConfig &config,
    bool bUseFloat, GLenum eTarget) :
    #if !NEW_FBO_CODE
    initialize(width, height, m_fboConfig, m_fboData);


    testing platform: windows 7 + vs 2008 sp1 + cuda 3.1

  2. Hi, This is great, exactly what I was looking for. But unfortunately the download link doesn’t seem to work. Could you please send me the password and the code. Thanks a lot in advance.

  3. Hi, could you pls send me the password? I’m trying to add a MFC activeX into a CUDA program but run into some trouble. Cheers.

  4. Windows 7 (64bit) + cuda 3.2

    if use project->properties-> configuration->linker-> advanced->target machine-> select X64. There is a link error.
    1>.ReleasecudaMFC.obj : fatal error LNK1112: module machine type ‘X86’ conflicts with target machine type ‘x64’

    However, if use project->properties-> configuration->linker-> advanced->target machine-> select X86. There is a link error.
    1>.ReleasecudaMFC.obj : fatal error LNK1112: module machine type ‘x64’ conflicts with target machine type ‘X86’.

    Appreciate for any suggestion.

  5. Thank you so much for that. That’s the thing that I was looking for my research. I’d also be glad if you could send me the password.

    Thank you again,
    Best Regards.

  6. thanks for your kind. I think it’s amazing program!!!

    But it is locked… Can I receive the password?

    I hope your lucky fortune 🙂


  7. Great MFC + CUDA startup project.
    If you had cuda.rules error try the following:

    In order to compile with VS 9.0 (and Windows 7, 64b) and CUDA 3.2 I did the following changes in the project:

    1) Edit the cudaMFC.vcproj with the Notepad and change the following line



    2) delete remove rendercheck_gl.h and .cpp from project

    3) Change the Additional Library Directories for the correct ones. In my case: $(CUDA_PATH)/lib/$(PlatformName);

  8. Can you please send me the password. I’m doing the same thing but I’m running into linking errors.


  9. Very interesting, can I please get the password?
    Do you think the same procedure applies for CUDA 4.0?

  10. Hi,
    i am working on CUDA for Data Normalisation for that i require to emerge MFC code in cuda, I found ur code might be helpful, so please send me the password on my mail id.

    waiting for ur reply

    1. @Kaj: I’m not working in Win recently, so I’ve no idea for cuda 4.0. But, you can try.. and then please share your experience here.. 😀

      @Vishal: it’s in your inbox now.. 😀

  11. Vishal,
    I successfully interfaced my CUDA 4.0 code from MFC. However, I didn’t use your code, so I cannot say if the procedure is exactly the same. I wrote a class for my CUDA klernel and wrapped into a DLL which I use from the MFC application.

  12. Hi, i’m a newbie in programming and it’s so sad to use cuda with MFC. Please send me the password. It might be a great help.

  13. Hi! I am trying to use MFC with CUDA and would like to look at your sample code. Could you please send me the password. Thanks!

  14. Hi, I’m also interested in your sourcecode. Just try to use CUDA with MFC and stuck in my progress, so can you please send me the needed password? Thanks a lot.

  15. I can’t convert project to VS2010.
    My error in VS2010 conversion is this:
    The following error has occurred during XML parsing: File: C:TempcudaMFCcudaMFCcudaMFC.vcproj Line: 32 Column: 5 Error Message: Error del sistema: -2146233088. The file ‘C:TempcudaMFCcudaMFCcudaMFC.vcproj’ has failed to load.

  16. 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 ?


  17. 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.

  18. 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.

  19. 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.

  20. Hi
    I just start to learn cuda, very thanks for your experience sharing, I had download file cuda5MFC10.zip. Please send me the password. many thanks.

  21. Hi

    I just start to learn cuda programming. Thanks for your experience sharing. i had download the file cuda5MFC10.zip. please send me the password. many thanks.

    1. Jun Wei,

      I don’t have chance to test it in all machines, in all platforms, in all CUDA versions. As you can see comments below, people share their experiences and give me feedbacks how to make it works in different machines.

      Let me know what kind of errors you got. Maybe I could give some directions about what you need to do. Thanks.

  22. can u help me to change this code to CUDA

    float h_max(float *h_surf)
    int i,totpoints;
    float hmax =-1.0e6;
    for ( i=0; i hmax)
    return hmax;

    I just start to learn cuda programming

  23. Hi

    I downloaded your last version of VS2010 and CUDA 6.5, but I compiled them in VS2013. The compiling and linking processes were OK, but I failed in run time. It seemed that my glew32.dll (1.11.0[08-11-14]) did not match your program (No entry point …). Therefore, I’d like to know what version of glew32 you had used with them. Or, did I miss anything? Thank you very much!

    I am running an Acer NB with Win. 8.1 X64 and Nvidia 750M.


Leave a Reply

Your email address will not be published. Required fields are marked *