はじめに
2021年12月28日に Intel oneAPI 2022をWSL2にインストールしてみました。
今回は、既にインストールしてある oneAPI 2022 を 2023.2 にアップデートしました。
アップデート
sudo apt upgrade intel-basekit
にて、アップデートしました。途中エラーになっているところがありました。メッセージにしたがって、
sudo apt --fix-broken install sudo apt install intel-oneapi-runtime-dpcpp-sycl-cpu-rt
で更新できました。下記の環境設定ファイルを source で読み込むことで oneAPI のツールを使えるようにします。
source /opt/intel/oneapi/setvars.sh
サンプルコード
git clone https://github.com/oneapi-src/oneAPI-samples.git
にて、サンプルコードを clone して、
cd oneAPI-samples cd DirectProgramming/C++SYCL/DenseLinearAlgebra/simple-add/
にて、simple-add を動かしてみました。
mkdir build cd build cmake .. -- The CXX compiler identification is IntelLLVM 2023.2.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/intel/oneapi/compiler/2023.2.0/linux/bin/icpx - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- FPGA_DEVICE was not specified. Configuring the design to target the default FPGA family (Intel Agilex® 7). Please refer to the README for information on board selection. -- Configuring done (1.2s) -- Generating done (0.5s) -- Build files have been written to: /XXX/oneAPI-samples/DirectProgramming/C++SYCL/DenseLinearAlgebra/simple-add/build make [ 50%] Building CXX object src/CMakeFiles/simple-add-buffers.dir/simple-add-buffers.cpp.o [100%] Linking CXX executable ../simple-add-buffers [100%] Built target simple-add-buffers
生成された simple-add-buffers を実行します。Running on device: Intel(R) Graphics と出て、プログラムが正しく動いたようです。
./simple-add-buffers Running on device: Intel(R) Graphics [0x9a49] Array size: 10000 [0]: 0 + 100000 = 100000 [1]: 1 + 100000 = 100001 [2]: 2 + 100000 = 100002 ... [9999]: 9999 + 100000 = 109999 Successfully completed on device.
OpenCL のサンプルコード
cd /DirectProgramming/C++SYCL/OpenCLInterop mkdir build cd build cmake .. -- Default CMAKE_BUILD_TYPE not set using Release with Debug Info -- The C compiler identification is GNU 10.3.0 -- The CXX compiler identification is IntelLLVM 2023.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /opt/intel/oneapi/compiler/2023.2.0/linux/bin/icpx - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (1.8s) -- Generating done (0.2s) -- Build files have been written to: /XXX/oneAPI-samples/DirectProgramming/C++SYCL/OpenCLInterop/build make [ 50%] Building CXX object src/CMakeFiles/prog.dir/sycl_with_opencl_objects.dp.cpp.o [100%] Linking CXX executable prog [100%] Built target prog
生成されたプログラムを実行します。
make run Kernel Loading Done Platforms Found: 4 Using Platform: Intel(R) OpenCL HD Graphics Devices Found: 1 Device: Intel(R) Graphics [0x9a49] Passed! Built target run
OpenCL対応の環境は4つあり、プログラムは、Intel(R) OpenCL HD Graphics で動いています。
ソースコード ( src/sycl_with_opencl_objects.dp.cpp) に以下のコードを追加し、どんな環境があるかを表示させてみた。
cl_platform_id *ocl_platforms = (cl_platform_id *)malloc(ret_num_platforms); ret = clGetPlatformIDs(ret_num_platforms, ocl_platforms, NULL); + for(int i=0 ; i<ret_num_platforms ; i++){ + platform sycl_platform = make_platform<backend::opencl>(ocl_platforms[i]); + std::cout << "Using Platform: " + << i << " " << sycl_platform.get_info<info::platform::name>() << std::endl; + } +
追加後、プログラムを実行したら、次のような4つの環境を表示した。0番目と3番目が同じなのは理由がわかりません。
Using Platform: 0 Intel(R) FPGA Emulation Platform for OpenCL(TM) Using Platform: 1 Intel(R) OpenCL Using Platform: 2 Intel(R) OpenCL HD Graphics Using Platform: 3 Intel(R) FPGA Emulation Platform for OpenCL(TM)
の3つがあるようです。
おわりに
Intel oneAPI、Windows WSL2 + Ubuntu 環境で動くのでとっても便利です。
でも動きますからね。