c++ - 如何使用 cmake 编译 C++ 文件和 CUDA 文件
问题描述
我知道如何使用 cmake 编译具有 cuda 函数(如 cublas)的 C++ 文件。但是,在我的项目中,有一个我自己编写的内核函数。我看g++编译器不知道怎么处理内核<<<,>>>。你能帮我解决这个问题吗?以下是我用来用 cublas 编译 C++ 文件的 CMakeLists。
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})
我有三个文件要编译如下。
main.cpp aux.cpp aux.hpp
aux.cpp 包含 cuda 内核函数。谢谢大家!
解决方案
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.
推荐阅读
- node.js - 通过 id API getway AWS 获取项目
- mysql - 如何访问数据库列的单个值?
- sql-server - 选择特定的存在但仍包含不需要的结果
- c# - 使用循环概念从字符串中拆分运算符
- google-apps-script - 谷歌电子表格脚本 - 将值移动到特定单元格
- bash - 在 shell 脚本中使用“睡眠”功能时出现问题
- azure - “云端点创建失败”的一些问题
- python - ValueError:在系统中找不到外部 ID:todo_report.report_todo_task_template
- reactjs - 我们可以将sectionList(或滚动视图)的粘性标题粘贴到滚动视图顶部的相对位置吗?
- hyperledger-fabric - 超级账本的 fabcar.go 链码不接受更改和修改,始终运行以前的链码