不同版本sycl编译器测试
1.测试程序
cat > sycl_test.cpp <<-'EOF'
#include <sycl/sycl.hpp>
#include <chrono>
#include <iostream>
#include <vector>
#include <sys/time.h>
#include <nvtx3/nvToolsExt.h>
class ReluKernel {
public:
ReluKernel(sycl::buffer<float, 1>& input, sycl::buffer<float, 1>& output)
: input_(input), output_(output) {}
void operator()(sycl::handler& h) {
auto in_acc = input_.get_access<sycl::access::mode::read>(h);
auto out_acc = output_.get_access<sycl::access::mode::write>(h);
h.parallel_for(sycl::range<1>{in_acc.size()}, [=](sycl::id<1> idx) {
float x = in_acc[idx];
out_acc[idx] = x > 0 ? x : 0;
});
}
private:
sycl::buffer<float, 1>& input_;
sycl::buffer<float, 1>& output_;
};
int main() {
bool flag = true;
auto data_size = 200*1024;
std::vector<float> input_data(data_size, 1.0f);
std::vector<float> output_data(data_size, 0.0f);
for (int j = 0; j < input_data.size(); j++) {
input_data[j] = j % 2 == 0 ? 1.0f : -1.0f;
}
sycl::gpu_selector selector;
sycl::queue queue(selector,sycl::property::queue::enable_profiling());
sycl::buffer<float, 1> input_buf(input_data.data(),
sycl::range<1>(input_data.size()));
sycl::buffer<float, 1> output_buf(output_data.data(),
sycl::range<1>(output_data.size()));
for (int times = 0; times < 10; times++)
{
nvtxRangePush("kernel in");
struct timeval start_time, end_time;
gettimeofday(&start_time, nullptr);
sycl::event kernel_event = queue.submit([&](sycl::handler& h) {
ReluKernel kernel(input_buf, output_buf);
kernel(h);
});
queue.wait_and_throw();
gettimeofday(&end_time, nullptr);
double e2e_time = ((end_time.tv_sec - start_time.tv_sec) * 1e6 \
+ (end_time.tv_usec - start_time.tv_usec)) / 1000.0;
auto submit_ns =
kernel_event
.get_profiling_info<sycl::info::event_profiling::command_submit>();
auto start_ns =
kernel_event
.get_profiling_info<sycl::info::event_profiling::command_start>();
auto end_ns =
kernel_event
.get_profiling_info<sycl::info::event_profiling::command_end>();
double duration_ms = (end_ns - start_ns)/1e6;
double submit_ms = (start_ns-submit_ns)/1e6 ;
nvtxRangePop();
printf("%8.4f %8.4f %8.4f\n",submit_ms,duration_ms,e2e_time);
}
return 0;
}
EOF
2.分别编译二个版本的开源sycl编译器
git clone https://github.com/intel/llvm -b sycl
cd llvm
git checkout 1c35af3dc19be511ddeb0d984f1fddc737d24592
git submodule update --recursive
python buildbot/configure.py --cuda -t Release
python buildbot/compile.py
mv build ../build_2025
git checkout 123705190ed5f971750a77da9e69ae7ff35ad243
git submodule update --recursive
# 修改点参考:https://github.com/KhronosGroup/OpenCL-Headers/issues/266
python buildbot/configure.py --cuda -t Release
python buildbot/compile.py
mv build ../build_2024
3.用2025年的开源sycl测试
export PATH=$PWD/build_2025/bin:$PATH
export LD_LIBRARY_PATH=$PWD/build_2025/lib:$LD_LIBRARY_PATH
clang++ -std=c++17 -O3 -fsycl -fsycl-targets=nvptx64-nvidia-cuda sycl_test.cpp -o sycl_test
export SYCL_CACHE_IN_MEM=1
./sycl_test
export SYCL_CACHE_IN_MEM=0
./sycl_test
export SYCL_CACHE_IN_MEM=1
nsys profile --stats=true -o sycl_test_open_2025.nsys-rep -f true -t cuda,nvtx ./sycl_test
输出
# SYCL_CACHE_IN_MEM=1
0.9001 0.0215 1.0780
0.0249 0.0082 0.0470
0.0229 0.0072 0.0420
0.0394 0.0072 0.0600
0.0249 0.0072 0.0410
0.0204 0.0072 0.0400
0.1497 0.0082 0.1730
0.0258 0.0080 0.0480
0.0248 0.0082 0.0450
0.0222 0.0072 0.0470
# SYCL_CACHE_IN_MEM=0
0.8991 0.0174 1.0920
0.1843 0.0594 0.2770
0.1866 0.0082 0.2250
0.1793 0.0082 0.2160
0.1795 0.0083 0.2160
0.1794 0.0082 0.2150
0.2979 0.0092 0.3380
0.2065 0.0082 0.2440
0.1698 0.0082 0.2100
0.1626 0.0082 0.2040
4.用2024年的开源sycl测试
export PATH=$PWD/build_2024/bin:$PATH
export LD_LIBRARY_PATH=$PWD/build_2024/lib:$LD_LIBRARY_PATH
clang++ -std=c++17 -O3 -fsycl -fsycl-targets=nvptx64-nvidia-cuda sycl_test.cpp -o sycl_test
export SYCL_CACHE_IN_MEM=1
./sycl_test
export SYCL_CACHE_IN_MEM=0
./sycl_test
输出
# SYCL_CACHE_IN_MEM=1
0.8847 0.0215 1.0580
0.0250 0.0092 0.0480
0.0381 0.0072 0.0540
0.0408 0.0072 0.0600
0.0249 0.0061 0.0390
0.0206 0.0071 0.0410
0.0204 0.0072 0.0390
0.1498 0.0082 0.1690
0.0274 0.0072 0.0540
0.0294 0.0072 0.0490
# SYCL_CACHE_IN_MEM=0
0.8602 0.0215 1.0680
0.2120 0.0092 0.2510
0.1731 0.0082 0.2100
0.1667 0.0082 0.2020
0.1664 0.0082 0.2010
0.1871 0.0082 0.2220
0.1554 0.0082 0.1900
0.2707 0.0082 0.3080
0.1689 0.0082 0.2070
0.1523 0.0092 0.1920
5.intel-dpcpp-cpp-compiler-2025.0.4.20
rm /opt/intel -rf
bash intel-dpcpp-cpp-compiler-2025.0.4.20_offline.sh
bash oneapi-for-nvidia-gpus-2025.0.0-cuda-12.0-linux.sh
source /opt/intel/oneapi/setvars.sh --force
icpx --version
icpx sycl_test.cpp -o sycl_test -fsycl -fPIC -fsycl-targets=nvptx64-nvidia-cuda -O3
export SYCL_CACHE_IN_MEM=1
./sycl_test
export SYCL_CACHE_IN_MEM=0
./sycl_test
输出
# SYCL_CACHE_IN_MEM=1
1.3005 0.0215 1.4700
0.0242 0.0080 0.0450
0.0227 0.0071 0.0580
0.0212 0.0072 0.0480
0.0241 0.0215 0.0560
0.0253 0.0072 0.0390
0.1562 0.0082 0.1760
0.0247 0.0072 0.0450
0.0260 0.0072 0.0470
0.0222 0.0072 0.0420
# SYCL_CACHE_IN_MEM=0
0.8253 0.0174 0.9950
0.2120 0.0246 0.2670
0.1794 0.0081 0.2150
0.1763 0.0082 0.2110
0.1755 0.0091 0.2110
0.1653 0.0082 0.1990
0.3252 0.0236 0.3760
0.2154 0.0083 0.2660
0.1617 0.0092 0.2000
0.1623 0.0082 0.2010
6.intel-dpcpp-cpp-compiler-2024.1.0.468
rm /opt/intel -rf
bash intel_dpcpp-cpp-compiler_p_2024.1.0.468_offline.sh
bash oneapi-for-nvidia-gpus-2024.1.0-cuda-12.0-linux.sh
source /opt/intel/oneapi/compiler/latest/env/vars.sh
icpx --version
icpx sycl_test.cpp -o sycl_test -fsycl -fPIC -fsycl-targets=nvptx64-nvidia-cuda -O3
export SYCL_CACHE_IN_MEM=1
./sycl_test
export SYCL_CACHE_IN_MEM=0
./sycl_test
export SYCL_CACHE_IN_MEM=1
nsys profile --stats=true -o sycl_test_open_dpcpp2024.nsys-rep -f true -t cuda,nvtx ./sycl_test
输出
# SYCL_CACHE_IN_MEM=1
0.8530 0.0225 1.0080
0.0157 0.0081 0.0440
0.0138 0.0063 0.0360
0.0128 0.0072 0.0390
0.0124 0.0072 0.0380
0.0158 0.0072 0.0400
0.0151 0.0061 0.0350
0.1356 0.0092 0.1630
0.0139 0.0082 0.0560
0.0150 0.0072 0.0410
# SYCL_CACHE_IN_MEM=0
0.8305 0.0215 0.9970
0.1721 0.0092 0.2170
0.1605 0.0082 0.2020
0.1524 0.0092 0.1930
0.1467 0.0082 0.1870
0.1416 0.0082 0.1820
0.1334 0.0082 0.1720
0.2445 0.0092 0.2870
0.1525 0.0092 0.1970
0.1378 0.0092 0.1830