简体   繁体   中英

How to use cmake to compile both C++ file and CUDA file

I know how to use cmake to compile C++ file with cuda function like cublas. However, in my project, there is a kernel function that I write by myself. I see the g++ compiler do not know how to deal with the kernel<<<,>>>. Could you please help me fix this problem? The following is the CMakeLists that I used to compile the C++ files with cublas.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
cmake_minimum_required(VERSION 3.0)

project(GPU_LMM)
find_package(GSL REQUIRED)
find_package(BLAS REQUIRED)
find_package(CUDA)
if (CUDA_FOUND)
    message("CUDA found")
else()
    message("CUDA not found, doing something alternatively")
endif()

include_directories(test_cuda PRIVARE
                ${GSL_INCLUDE_DIRS}
                ${BLAS_INCLUDE_DIRS}
                ${CUDA_INCLUDE_DIRS}
                ${CUDA_CUBLAS_DIRS}
                                    ${PROJECT_SOURCE_DIR})

add_executable(GPU_LMM main.cpp aux.cpp)
target_link_libraries( GPU_LMM  PRIVATE
                    ${GSL_LIBRARY}
                    ${BLAS_LIBRARIES}
                    ${CUDA_LIBRARIES}
                    ${CUDA_CUBLAS_LIBRARIES})

I have three files to compile as the following.

main.cpp aux.cpp aux.hpp

The aux.cpp contains the cuda kernel function. Thank your everybody!

If you have cuda kernels that have to be compiled with nvcc , their extension should be .cu , no .cpp (so that should be aux.cu ). Then cmake will use the proper compiler for the proper file.

Since cmake 3.10.0, CUDA support is even native, you just need to activate the language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM