Cuda-2.3 and Cmake

Hi,

I am trying to compile the deviceQuery example using CMake. I have compiled this example successfully using the makefile from SDK, however would like to use CMake for my builds.

I am on CMake-2.8 (which ships with the FindCUDA.cmake) module. My CMakeLists.txt shows the following

cmake_minimum_required(VERSION 2.6.2)
project(Cuda-project)
find_package(CUDA)

INCLUDE_DIRECTORIES(
${CUDA_INCLUDE_DIRS}
(/home/sv650/libs/cuda/cuda-2.3/cuda/C/common/inc)
)

cuda_add_executable(test
deviceQuery.cpp
)

target_link_libraries(
/home/sv650/libs/cuda/cuda-2.3/cuda/C/common/lib
)

When I build using the above CMakeLists.txt file, I get the following link error
CMakeFiles/test.dir/deviceQuery.cpp.o: In function main': deviceQuery.cpp:(.text+0x54f): undefined reference to cutCheckCmdLineFlag’
collect2: ld returned 1 exit status

Can some one please tell me, what extra library I need to add and how would I include that into my CMakeLists.txt file?

Thanks,
SV650

I think you’d need libcutil and libshrutil; both of these are available only if after intalling GPU/CUDA SDK, you ran make there in order to build examples. Furthermore, if you look into FindCUDA.cmake, you could find, commented out and below “Example of how to find an include file from the CUDA_SDK_ROOT_DIR” and “Example of how to find a library in the CUDA_SDK_ROOT_DIR” comments, respectively, examples of how to utilize a library from CUDA SDK. So you should try to copy these blocks into your CMake file, and adapt for above two libraries.

Hi,

Thanks for your suggestion, tried as suggested - see CMakeLists.txt below

cmake_minimum_required(VERSION 2.6.2)
project(Cuda-project)

find_package(CUDA)

find_path(CUDA_CUT_INCLUDE_DIR
cutil.h
#PATHS ${CUDA_SDK_SEARCH_PATH}
PATHS (/home/sv650/libs/cuda/cuda-2.3/cuda/C/)
PATH_SUFFIXES “common/inc”
DOC “Location of cutil.h”
NO_DEFAULT_PATH
)

# Now search system paths

find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC “Location of cutil.h”)

mark_as_advanced(CUDA_CUT_INCLUDE_DIR)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(cuda_cutil_name cutil64)
else(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(cuda_cutil_name cutil32)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)

find_library(CUDA_CUT_LIBRARY
NAMES cutil {cuda_cutil_name} PATHS {CUDA_SDK_SEARCH_PATH}
PATHS(/home/sv650/libs/cuda/cuda-2.3/cuda/C/)
# The new version of the sdk shows up in common/lib, but the old one is in lib
PATH_SUFFIXES “common/lib” “lib”
DOC “Location of cutil library”
NO_DEFAULT_PATH
)

# Now search system paths

find_library(CUDA_CUT_LIBRARY NAMES cutil {cuda_cutil_name} DOC "Location of cutil library") mark_as_advanced(CUDA_CUT_LIBRARY) set(CUDA_CUT_LIBRARIES {CUDA_CUT_LIBRARY})

cuda_add_executable(test
deviceQuery.cpp
)

After running configure with the above file, it finds the necessary libcutil.a and cutil.h - I can see it in the CMakeCache.txt, however when I compile, I get the following
/home/sv650/myDevelopment/cuda/example2/deviceQuery.cpp:23:19: error: cutil.h: No such file or directory
/home/sv650/myDevelopment/cuda/example2/deviceQuery.cpp: In function ‘int main(int, char**)’:
/home/sv650/myDevelopment/cuda/example2/deviceQuery.cpp:105: error: ‘CUT_EXIT’ was not declared in this scope
make[2]: *** [CMakeFiles/test.dir/deviceQuery.cpp.o] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2

This seems to suggest, although it finds the files during configure, they are not correctly included - I am probably doing some thing very stupid here, can some one give me some pointers please?

sv650

It is not enough just to paste these snippets from FindCUDA.cmake to your CMakeLists.txt - you need to put some use of them too. For example, regarding libcutil include directory, you need to add something like:

include_directories(${CUDA_CUT_INCLUDE_DIR})

to your CMakeLists.txt. Ditto for CUDA_CUT_LIBRARY:

target_link_libraries(

  # name of the executable here

  # other libraries to link with here

  ${CUDA_CUT_LIBRARY}

  )

Hi

Thanks - as you may have figured out already, I am no expert in CMake , it all works now. For those, who want to use the above, one more line for libshrutil.a needs to be added, the quick and dirty way is

target_link_libraries(test
(/home/sv650/libs/cuda/cuda-2.3/cuda/shared/lib/libshrutil.a)
{CUDA_LIBRARY} {CUDA_CUT_LIBRARY}
)

sv650