在 Cmake 项目中指定 openmp CUDA 标志

发布于 2025-01-06 01:32:48 字数 806 浏览 1 评论 0原文

在 cmake 项目中如何将 openmp 标志传递给 NVCC? 我的这个项目的 CMakeLists.txt 看起来像这样,但编译失败,并显示“未定义对‘omp_get_wtime’的引用”消息。

cmake_minimum_required (VERSION 2.8.2)

set (CMAKE_MODULE_PATH 
  "${CMAKE_SOURCE_DIR}/cmake" 
  ${CMAKE_MODULE_PATH}
)

find_package (CUDA 4.0 REQUIRED)

if(OPENMP_FOUND)
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
${OpenMP_EXE_LINKER_FLAGS}") endif()

set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

if(UNIX)
  add_definitions(-DUNIX)
endif(UNIX)

add_subdirectory(xor)

CUDA_BUILD_CLEAN_TARGET()

How can I pass openmp flag to NVCC when in a cmake project?
My CMakeLists.txt for this project looks like this, but compilation fails with "undefined reference to `omp_get_wtime'" message.

cmake_minimum_required (VERSION 2.8.2)

set (CMAKE_MODULE_PATH 
  "${CMAKE_SOURCE_DIR}/cmake" 
  ${CMAKE_MODULE_PATH}
)

find_package (CUDA 4.0 REQUIRED)

if(OPENMP_FOUND)
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
${OpenMP_EXE_LINKER_FLAGS}") endif()

set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

if(UNIX)
  add_definitions(-DUNIX)
endif(UNIX)

add_subdirectory(xor)

CUDA_BUILD_CLEAN_TARGET()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2025-01-13 01:32:48

我刚刚发现将 find_package (OpenMP) 添加到前面的脚本中可以解决问题。

I just found out that adding find_package (OpenMP) to the previous script did the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文