我是从OneAPI SYCL开始学习的,但我通常使用QtCreator作为我的IDE。我用CMake做了一个HelloSYCL项目,在终端和带有OneAPI扩展的VSCode中工作得很好,但在QtCreator中不工作。
每次我想使用SYCL时,我都需要用. /opt/intel/oneapi/ www.example.com启动ONEAPIsetvars.sh环境,但我不知道如何使用QtCreator
下面是我的编译方法
mkdir build; cd build
cmake -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -G Ninja -S .. -DCMAKE_PREFIX_PATH="/opt/intel/oneapi/compiler/latest/linux/cmake/SYCL/" -DSYCL_INCLUDE_DIR=/opt/intel/oneapi/compiler/latest/linux/include/sycl -DSYCL_LIBRARY_DIR=/opt/intel/oneapi/compiler/latest/linux/lib
cmake_minimum_required(VERSION 3.22)
project(testSYCL LANGUAGES CXX)
if(UNIX)
set(CMAKE_C_COMPILER icx)
set(CMAKE_CXX_COMPILER dpcpp)
endif(UNIX)
list(APPEND CMAKE_MODULE_PATH "/opt/intel/oneapi/compiler/2021.4.0/linux/")
list(APPEND CMAKE_MODULE_PATH "/opt/intel/oneapi/compiler/2021.4.0/linux/cmake/SYCL/")
find_package(IntelDPCPP REQUIRED)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE PATH "Build Type" FORCE)
endif()
add_executable(testSYCL main.cpp)
#include <iostream>
#include <iomanip>
#include <CL/sycl.hpp>
int main()
{
for ( const auto& plataform : sycl::platform::get_platforms() ) {
std::cout << "=========================================================\n";
std::cout << std::setw(25);
std::cout << plataform.get_info<sycl::info::platform::name>() << "\n";
std::cout << plataform.get_info<sycl::info::platform::vendor>() << "\n";
std::cout << "Plataform: " << plataform.get_info<sycl::info::platform::version>() << "\n";
for ( const auto& device : plataform.get_devices() ) {
std::cout << "Devices\n";
std::cout << "Name: " << device.get_info<sycl::info::device::name>() << "\n";
std::cout << "Max Compute Units: " << device.get_info<sycl::info::device::max_compute_units>() << "\n";
std::cout << "Max Work Group Size: " << device.get_info<sycl::info::device::max_work_group_size>() << "\n";
std::cout << "Max Clock Frequency: " << device.get_info<sycl::info::device::max_clock_frequency>() << " MHz \n";
}
}
}
1条答案
按热度按时间kx5bkwkv1#
答案取决于
setvars.sh
的内容,我假设这是一个设置环境变量的简单脚本。在QtCreator中模仿它的一种方法是定义一个自定义工具包。进入Tools/Options/Kits。高亮显示任何你使用的工具包并按下“clone”。然后,在“Environment”字段中手动添加必要的环境变量。将此工具包用于你的SYCL项目。如果你的问题是由编译器错误引起的,这将起作用。
如果在QtCreator中运行程序时出现问题,请查看
build/running options
:在那里,您可以很容易地找到更改运行时或编译时环境的选项