QTCreator与Intel oneapi sycl

发布于 2025-01-18 11:32:19 字数 2906 浏览 1 评论 0原文

我开始使用Oneapi Sycl学习,但通常我将QTCreator作为我的IDE。我使用Cmake进行了一个HelloSycl项目,并且在终端和vScode中也可以使用Oneapi扩展程序工作,但在QTCreator中没有工作。

Every time I want to use SYCL I need to start ONEAPI environment with ". /opt/intel/oneapi/setvars.sh", but I don't know how to do it with QtCreator

Here is the way I'm compile

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";
        }
    }
}

qtCreator cmake cmake error qtcreator自定义编译器添加了

I started my study with OneAPI SYCL but I normally use QtCreator as my IDE. I did a HelloSYCL project with CMake and works fine in the terminal and in the VSCode with OneAPI Extension as well, but didn't work in the QtCreator.

Every time I want to use SYCL I need to start ONEAPI environment with ". /opt/intel/oneapi/setvars.sh", but I don't know how to do it with QtCreator

Here is the way I'm compile

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";
        }
    }
}

QtCreator CMake Error
QtCreator Custom Compiler added

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

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

发布评论

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

评论(1

不气馁 2025-01-25 11:32:19

答案取决于 setvars.sh 的内容。我认为这是一个设置环境变量的简单脚本。

在 QtCreator 中模仿它的一种方法是定义一个自定义套件。
转至工具/选项/套件。突出显示您使用的任何套件并按“克隆”。然后,在“环境”字段中手动添加必要的环境变量。将此套件用于您的 SYCL 项目。如果您的问题是由编译器错误引起的,这将起作用。

设置QtCreator 中的套件

如果在 QtCreator 中运行程序时出现问题,请查看构建/运行选项

构建/运行选项

在那里您可以轻松找到更改运行时或编译时环境的选项

在此处输入图像描述

The answer depends on the contents of setvars.sh. I assume this is a simple script setting environment variables.

One way to mimic it in QtCreator is to define a custom kit.
Go to Tools/Options/Kits. Highlight any kit you use and press "clone". Then, add to it manually the necessary environment variables in the field "Environment". Use this kit for your SYCL projects. This will work if your problem is caused by a compiler error.

setting a kit in QtCreator

If the problem occurs while running a program inside QtCreator, look at build/running options:

build/run options

There you'll easily find options for changing the runtime or compile-time environment

enter image description here

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