Sunday, March 18, 2012

Integrate CUDA into SteerSuite

SteerSuite is a pure C++ project. I need to do something in CUDA in this project. So first thing to do is making CUDA code run with this project.

By referring this post: http://www.ademiller.com/blogs/tech/2011/05/visual-studio-2010-and-cuda-easier-with-rc2/, I successfully make CUDA run with SteerSuite, more accurate, with steerlib. Because I am planning first to optimize data retrieve in GridDatabase.

The way of integrating CUDA code into existing VS project is fairly easy, and it can be done in following steps:

1) Select the project in the solution explorer (here I choose steerlib), and then select  Project--Build Customization menu. In the dialog, check CUDA 4.0 targets.













2) Then right click on the .cu file and select Properties. Make sure that in Configuration Properties--General, "Item type" is CUDA C/C++


3) You should make sure that NVCC CUDA compiler targets your original platform, either Win32 or x64.
In project's Properties, open Configuration Properties--CUDA C/C++. The "Target Machine Platform" is correct. Here my target is Win32.

4) Open Configuration Properties--Linker--Input, and add cudart.lib to the list in the "Additional Dependencies", and do not forget use semicolon(;) to separate each item.


Now, you are all done. Just rebuild your project. But wait, how to use CUDA code in the source code.
You just need to use extern "C" to decorate your functions in .cu file, and use it in your original project code, but do not pre-declare your function in at the head of the file in which you use it, in the same form as extern "C".

I followed the steps mentioned above, and run a simple function in .cu file. Hopefully more complicated ones will work as well.

1 comment:

  1. Nice tutorial. Glad you got this setup early in your project schedule.

    ReplyDelete