Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configuring CMake to setup CUDA on Windows

I am trying to use CMake for compiling CUDA based application on Windows (Visual Studio 2005). Here is an example stripped down CMake file:

cmake_minimum_required (VERSION 2.6)
project (HELLO)

#Support for CUDA Integration
FIND_PACKAGE(CUDA)
if(CUDA_FOUND)
    SET(CUDA_NVCC_FLAGS "-arch;sm_13")
CUDA_ADD_EXECUTABLE(Hello hello.cu)
else(CUDA_FOUND)
    message("CUDA is not installed on this system.")
endif()

There are a few issues I wish to understand with this.

When I open the solution file (Hello.sln), I don't see any custom build rule setup for the project (Right click on Project -> Custom build rules)

I do see a "Hello_generated_hello.cu.obj" added to my project in Visual Studio. What is this file and why is it added to the project?

By default CUDA Runtime API section doesn't come in Project properties.

If I enable an appropriate custom build rule (NvCudaRuntimeApi.rules), I can now see CUDA runtime API section. If I now go to GPU subsection, I see the GPU architecture still set to be sm_10.

Even if I use CUDA_INCLUDE_DIRECTORIES() Macro to add some directories for CUDA compilation, I won't see these settings in Project Properties -> CUDA Runtime API -> General -> Additional Include Directories.

I wish to know if FindCUDA() package is very able to properly configure VS 2005 project for CUDA based compilation. May be I need to specify additional options to properly configure the project. I would certainly wish to know that. I wish to make sure that whatever options I have specified through CMakeLists file, I should be able to review them easily in my generated VS 2005 project.

What is appropriate way to configure this?

like image 728
Shailesh Kumar Avatar asked Oct 11 '22 04:10

Shailesh Kumar


1 Answers

CMake does not support custom build rules (like the CUDA runtime API .rules file), and therefore you cannot edit the CUDA property sheets that the .rules files provide if you use CMake to configure your project. However you can set any CUDA settings directly in the CMakeLists.txt that generates the project, and rebuilding your project will detect these changes and regenerate and reload the project files automatically.

The additional benefit of FindCUDA (besides being cross-platform) is proper dependency analysis so that you never end up with stale builds like you normally do when using CUDA .cu files in Visual Studio (with or without .rules files).

You can find an examples of using CMake with CUDA in the CUDPP project in the following files:

  • Top-level CMakeLists for the whole library and sample apps: http://code.google.com/p/cudpp/source/browse/trunk/CMakeLists.txt
  • Project-specific CMakeLists file for a library: http://code.google.com/p/cudpp/source/browse/trunk/src/cudpp/CMakeLists.txt
  • Project-specific CMakeLists file for an executable: http://code.google.com/p/cudpp/source/browse/trunk/apps/simpleCUDPP/CMakeLists.txt

Hope that helps.

like image 170
harrism Avatar answered Oct 14 '22 09:10

harrism