英特尔oneAPI dpcpp编译器与谷歌测试



我对英特尔的HPC工具链有点陌生,当gtest被用作测试框架时,我面临着一些麻烦,即使是简单的dpc++应用程序也可以工作

这是CMakeLists的结构。我在

cmake_minimum_required(VERSION 3.14)
project(foo)
set(CMAKE_CXX_COMPILER "dpcpp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3 -fsycl")
# add executables 
# target linked libraries 
# ...
option(ENABLE_TESTS ON)
if(ENABLE_TESTS)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_subdirectory(tests)
endif()

如果我删除最后一个块,它将按预期编译并运行,否则我会得到以下错误:

CMake Error at build/_deps/googletest-src/CMakeLists.txt:10 (project):
The CMAKE_CXX_COMPILER:
dpcpp
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.

-- Configuring incomplete, errors occurred!
See also "/home/u141905/foo/build/CMakeFiles/CMakeOutput.log".
See also "/home/u141905/foo/build/CMakeFiles/CMakeError.log".
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= /usr/bin/c++
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
make: *** [Makefile:2: all] Error 1

请注意dpcpp是正确设置的,实际上我使用的是英特尔的devcloud平台。将CXX设置为whereis dpcpp的输出,也会产生同样的错误。唯一的"变通办法"(我怀疑它是一个)我发现是使用clang++代替(从英特尔的llvm版本)。任何帮助或建议是非常感激,谢谢提前!

编辑:经过更多的尝试,我注意到,如果我在抓取gtest后设置CMAKE_CXX_COMPILER,一切都很好。无论如何,我不明白为什么会发生这种情况,以及如何才能适当地修复。

使用dpcpp二进制文件的路径来设置CMAKE_CXX_COMPILER,而不是使用"set(CMAKE_CXX_COMPILER "dpcpp")"。在"CMAKE_CXX_COMPILER"文件中添加路径"/opt/intel/oneapi/compiler/2022.0.1/linux/bin/dpcpp"后,可以成功运行程序。

请找到下面的CMakeLists.txt设置CMAKE_CXX_COMPILER:

project(foo)
set(CMAKE_CXX_COMPILER "/opt/intel/oneapi/compiler/2022.0.1/linux/bin/dpcpp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3 -fsycl")
# add executables
# target linked libraries
# ...
set(ENABLE_TESTS ON)
include(FetchContent)
if(ENABLE_TESTS)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_subdirectory(tests)
endif()

谢谢,问候,Hemanth

运行source /opt/intel/oneapi/setvars.sh intel64脚本了吗?在运行cmake之前,dpcpp是否在您的路径上?

最新更新