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.

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
#include
#include
#include
#include 
// includes, project
#include
// Required header to support CUDA vector types
#include

__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
{
public:
	CcudaKernel(void);
	~CcudaKernel(void);

	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();
public:
	bool success;

};

You can download the complete code from the links below. But, please drop a comment or email for the password, I’ll reply within 24 hours.

Note: It was developed in VS 2008 on a 32-bit machine

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.

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

:)

Advertisement

155 comments on “A simple CUDA-MFC program

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

    1. copy cuda.rules to C:\Program Files\Microsoft Visual Studio 9.0\VC\VCProjectDefaults

    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) :
    m_fboData(data),
    m_fboConfig(config),
    m_bUseFloat(bUseFloat),
    m_eGLTarget(GL_TEXTURE_2D)
    {
    #if !NEW_FBO_CODE
    initialize(width, height, m_fboConfig, m_fboData);

    CHECK_FBO;
    #endif
    }

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

    CHECK_FBO;
    #endif
    }
    */

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

  2. Oups.. miss my email.. sorry..this is the good one..
    Can you send me the password ..
    Thank’s

  3. It is an interesting mfc project and, I want to know if there is or not a c++ compiler for cuda

    thanks in advance
    Mr. Pedro

  4. hi sizdah, sorry your email didn’t work. post it again..
    “Remote host said: 554 delivery error: dd This user doesn’t have a yahoo.com account(sozdahdreizehn@yahoo.com)”

  5. Pingback: 2010 in review « notes

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

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

  8. Windows 7 (64bit) + cuda 3.2

    if use project->properties-> configuration->linker-> advanced->target machine-> select X64. There is a link error.
    1>.\Release\cudaMFC.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>.\Release\cudaMFC.obj : fatal error LNK1112: module machine type ‘x64′ conflicts with target machine type ‘X86′.

    Appreciate for any suggestion.

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

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

    But it is locked… Can I receive the password?

    I hope your lucky fortune :)

    감사합니다.

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

    <DefaultToolFile
    FileName="cuda.rules"

    <DefaultToolFile
    FileName="NvCudaRuntimeApi.rules"

    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);

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

    Thanks

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

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

  15. @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.. :D

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

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

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

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

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

  20. Pingback: California WebDesign

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

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

    Best,
    Lei.

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 )

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