Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 6ce8f20

Browse files
[SYCl][L0] Buffer for multi-device context is using device allocation now (#976)
1 parent 8acf00e commit 6ce8f20

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

SYCL/Basic/buffer/buffer_create.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@ int main() {
1515
buffer<::cl_int, 1> Buffer(Size);
1616
Queue.submit([&](handler &cgh) {
1717
accessor Accessor{Buffer, cgh, read_write};
18-
if (NumOfDevices > 1)
19-
// Currently the Level Zero plugin uses host allocations for multi-device
20-
// contexts because such allocations are accessible by all devices.
21-
std::cerr << "Multi GPU should use zeMemAllocHost\n";
22-
else if (D.get_info<info::device::host_unified_memory>())
18+
if (D.get_info<info::device::host_unified_memory>())
2319
std::cerr << "Integrated GPU should use zeMemAllocHost\n";
2420
else
2521
std::cerr << "Discrete GPU should use zeMemAllocDevice\n";
26-
cgh.parallel_for<class CreateBuffer>(range<1>(Size), [=](id<1> ID) {});
22+
cgh.parallel_for<class CreateBuffer>(range<1>(Size),
23+
[=](id<1> ID) { Accessor[ID] = 0; });
2724
});
2825
Queue.wait();
2926

3027
return 0;
3128
}
3229

33-
// CHECK: {{Integrated|Multi|Discrete}} GPU should use [[API:zeMemAllocHost|zeMemAllocHost|zeMemAllocDevice]]
30+
// CHECK: {{Integrated|Discrete}} GPU should use [[API:zeMemAllocHost|zeMemAllocDevice]]
3431
// CHECK: ZE ---> [[API]](

SYCL/Basic/buffer/buffer_migrate.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// REQUIRES: gpu
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: env NEOReadDebugKeys=1 CreateMultipleRootDevices=2 %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: env NEOReadDebugKeys=1 CreateMultipleRootDevices=3 %GPU_RUN_PLACEHOLDER %t.out
6+
//
7+
// Test for buffer use in a context with multiple devices (all found
8+
// root-devices)
9+
//
10+
11+
#include <CL/sycl.hpp>
12+
using namespace cl::sycl;
13+
14+
int main() {
15+
16+
int Data = 0;
17+
int Result = 0;
18+
buffer<int, 1> Buffer(&Data, range<1>(1));
19+
20+
const auto &Devices =
21+
platform(gpu_selector{}).get_devices(info::device_type::gpu);
22+
std::cout << Devices.size() << " devices found" << std::endl;
23+
context C(Devices);
24+
25+
int Index = 0;
26+
for (auto D : Devices) {
27+
std::cout << "Using on device " << Index << ": "
28+
<< D.get_info<info::device::name>() << std::endl;
29+
Result |= (1 << Index);
30+
31+
queue Q(C, D);
32+
Q.submit([&](handler &cgh) {
33+
accessor Accessor{Buffer, cgh, read_write};
34+
cgh.parallel_for<class MigrateBuffer>(
35+
range<1>(1), [=](id<1> ID) { Accessor[ID] |= (1 << Index); });
36+
});
37+
Q.wait();
38+
++Index;
39+
}
40+
41+
auto HostAcc = Buffer.get_host_access();
42+
auto Passed = (HostAcc[0] == Result);
43+
std::cout << "Checking result on host: " << (Passed ? "passed" : "FAILED")
44+
<< std::endl;
45+
std::cout << HostAcc[0] << " ?= " << Result << std::endl;
46+
return !Passed;
47+
}

SYCL/Plugin/interop-level-zero-buffer-ownership.cpp

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// 2. User-provided memory allocation is freed by DPCPP RT if
1010
// "transfer" ownership is specified.
1111

12+
// NOTE: SYCL RT will see unbalanced count of alloc/free,
13+
// so this test will fail with ZE_DEBUG=4.
14+
1215
// Keep ownership
1316
// CHECK: zeMemFree
1417

SYCL/Plugin/interop-level-zero-buffer.cpp

100644100755
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ int main() {
9090
Queue.wait();
9191

9292
{
93-
char *Ptr = (char *)HostBuffer1;
94-
for (int i = 0; i < 10; i++) {
95-
assert(Ptr[i] == 'a');
96-
}
97-
9893
auto HostAcc1 = HostBufferInterop1.get_host_access();
9994
for (int i = 0; i < 10; i++) {
10095
assert(HostAcc1[i] == 'a');

0 commit comments

Comments
 (0)