Skip to content

Commit 5b3ba9f

Browse files
[SYCL] Treat "ar" image format as PI_DEVICE_BINARY_TYPE_NATIVE (#12587)
That's what AOT for Intel GPUs produces when targeting multiple devices at once. This PR is built on top of #12586.
1 parent f7bdae8 commit 5b3ba9f

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

sycl/source/detail/pi.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,14 @@ getBinaryImageFormat(const unsigned char *ImgData, size_t ImgSize) {
718718
return PI_DEVICE_BINARY_TYPE_NATIVE;
719719
}
720720

721+
if (MatchMagicNumber(std::array{'!', '<', 'a', 'r', 'c', 'h', '>', '\n'}))
722+
// "ar" format is used to pack binaries for multiple devices, e.g. via
723+
//
724+
// -Xsycl-target-backend=spir64_gen "-device acm-g10,acm-g11"
725+
//
726+
// option.
727+
return PI_DEVICE_BINARY_TYPE_NATIVE;
728+
721729
return PI_DEVICE_BINARY_TYPE_NONE;
722730
}
723731

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Don't use normal %{run} as we need to control cache directory removal and
2+
// cannot do that reliably when number of devices is unknown.
3+
//
4+
// REQUIRES: level_zero, ocloc
5+
//
6+
// DEFINE: %{cache_vars} = env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_TRACE=1 SYCL_CACHE_DIR=%t/cache_dir
7+
// DEFINE: %{build_cmd} = %{build}
8+
// RUN: mkdir -p %t/cache_dir
9+
//
10+
// The following block of code should be copy-pasted as-is to verify different
11+
// JIT/AOT options. Don't know how to avoid code duplication.
12+
// ******************************
13+
// Check the logs first.
14+
// RUN: %{build_cmd} -DVALUE=1 -o %t.out
15+
// RUN: rm -rf %t/cache_dir/*
16+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s %if windows %{ --check-prefixes=CHECK,CHECK-WIN %}
17+
//
18+
// Now try to substitute the cached image and verify it is actually taken and
19+
// the code/binary there is executed.
20+
// RUN: mv %t/cache_dir/*/*/*/*/*.bin %t.value1.bin
21+
// RUN: rm -rf %t/cache_dir/*
22+
// RUN: %{build_cmd} -DVALUE=2 -o %t.out
23+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s --check-prefixes RESULT2
24+
// RUN: mv %t.value1.bin %t/cache_dir/*/*/*/*/*.bin
25+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s --check-prefixes RESULT1
26+
// ******************************
27+
//
28+
// REDEFINE: %{build_cmd} = %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device acm-g10" %s
29+
// ******************************
30+
// Check the logs first.
31+
// RUN: %{build_cmd} -DVALUE=1 -o %t.out
32+
// RUN: rm -rf %t/cache_dir/*
33+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s %if windows %{ --check-prefixes=CHECK,CHECK-WIN %}
34+
//
35+
// Now try to substitute the cached image and verify it is actually taken and
36+
// the code/binary there is executed.
37+
// RUN: mv %t/cache_dir/*/*/*/*/*.bin %t.value1.bin
38+
// RUN: rm -rf %t/cache_dir/*
39+
// RUN: %{build_cmd} -DVALUE=2 -o %t.out
40+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s --check-prefixes RESULT2
41+
// RUN: mv %t.value1.bin %t/cache_dir/*/*/*/*/*.bin
42+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s --check-prefixes RESULT1
43+
// ******************************
44+
//
45+
// REDEFINE: %{build_cmd} = %clangxx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device acm-g10,acm-g11" %s
46+
// ******************************
47+
// Check the logs first.
48+
// RUN: %{build_cmd} -DVALUE=1 -o %t.out
49+
// RUN: rm -rf %t/cache_dir/*
50+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s %if windows %{ --check-prefixes=CHECK,CHECK-WIN %}
51+
//
52+
// Now try to substitute the cached image and verify it is actually taken and
53+
// the code/binary there is executed.
54+
// RUN: mv %t/cache_dir/*/*/*/*/*.bin %t.value1.bin
55+
// RUN: rm -rf %t/cache_dir/*
56+
// RUN: %{build_cmd} -DVALUE=2 -o %t.out
57+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s --check-prefixes RESULT2
58+
// RUN: mv %t.value1.bin %t/cache_dir/*/*/*/*/*.bin
59+
// RUN: %{cache_vars} %{run-unfiltered-devices} %t.out 2>&1 | FileCheck %s --check-prefixes RESULT1
60+
// ******************************
61+
62+
// CHECK: Code caching: device binary has been cached: [[BIN_FILE:.*]]
63+
// CHECK-WIN: Code caching: using cached device binary: [[BIN_FILE]]
64+
// CHECK-WIN: Code caching: using cached device binary: [[BIN_FILE]]
65+
66+
// RESULT1: Result (0): 1
67+
// RESULT1: Result (1): 1
68+
// RESULT1: Result (2): 1
69+
70+
// RESULT2: Result (0): 2
71+
// RESULT2: Result (1): 2
72+
// RESULT2: Result (2): 2
73+
74+
#include <sycl/sycl.hpp>
75+
76+
int main() {
77+
for (int i = 0; i < 3; ++i) {
78+
sycl::buffer<int, 1> b{1};
79+
sycl::queue{}
80+
.submit([&](sycl::handler &cgh) {
81+
sycl::accessor acc{b, cgh};
82+
cgh.single_task([=]() { acc[0] = VALUE; });
83+
})
84+
.wait();
85+
std::cout << "Result (" << i << "): " << sycl::host_accessor{b}[0]
86+
<< std::endl;
87+
}
88+
return 0;
89+
}

0 commit comments

Comments
 (0)