From 319aeb6b7fb636e9533def758a6dc66cc980ef02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Ciglari=C4=8D?= Date: Mon, 23 May 2022 07:48:04 +0100 Subject: [PATCH 1/8] added mutlti device context test --- SYCL/Basic/multi_device_context.cpp | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 SYCL/Basic/multi_device_context.cpp diff --git a/SYCL/Basic/multi_device_context.cpp b/SYCL/Basic/multi_device_context.cpp new file mode 100755 index 0000000000..f9f8371979 --- /dev/null +++ b/SYCL/Basic/multi_device_context.cpp @@ -0,0 +1,67 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: %HOST_RUN_PLACEHOLDER %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out + +// REQUIRES: cuda + +#include +#include + +sycl::event add(sycl::queue q, sycl::buffer buff, int *usm, + sycl::event e) { + return q.submit([&](sycl::handler &cgh) { + auto acc = buff.get_access(cgh); + cgh.depends_on(e); + cgh.single_task([=]() { acc[0] += *usm; }); + }); +} + +int main() { + sycl::platform plat = sycl::platform::get_platforms()[0]; + auto devices = plat.get_devices(); + if (devices.size() < 2) { + std::cout << "Need two devices for the test!" << std::endl; + return 0; + } + + sycl::device dev1 = devices[0]; + sycl::device dev2 = devices[1]; + + sycl::context ctx{{dev1, dev2}}; + + sycl::queue q1{ctx, dev1}; + sycl::queue q2{ctx, dev2}; + + int a = 1; + int b = 2; + int c = 4; + int d = 5; + { + sycl::buffer buff1(&a, 1); + sycl::buffer buff2(&b, 1); + + // test copying usm + int *usm1 = sycl::malloc_device(1, q1); + int *usm2 = sycl::malloc_device(1, q2); + sycl::event e1 = q1.memcpy(usm1, &c, 1); + sycl::event e2 = q2.memcpy(usm2, &d, 1); + + // test combination of usm and buffers in a kernel + sycl::event e3 = add(q1, buff1, usm1, e1); + sycl::event e4 = add(q2, buff2, usm2, e2); + + // change values in usm to ensure results are distinct + sycl::event e5 = q1.memcpy(usm1, &d, 1, e3); + sycl::event e6 = q2.memcpy(usm2, &c, 1, e4); + + // use each buffer on the other device than before - tests that copying + // between devices works + add(q1, buff2, usm1, e5); + add(q2, buff1, usm2, e6); + } + assert(a == 1 + 2 * 4); + assert(b == 2 + 2 * 5); + + return 0; +} From a0409fc93a97eeea27d4f79332f690ab88e48237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Ciglari=C4=8D?= Date: Wed, 6 Jul 2022 08:17:41 +0100 Subject: [PATCH 2/8] fix tracing test --- SYCL/Tracing/pi_tracing_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SYCL/Tracing/pi_tracing_test.cpp b/SYCL/Tracing/pi_tracing_test.cpp index 66270f427a..7a4caf2810 100644 --- a/SYCL/Tracing/pi_tracing_test.cpp +++ b/SYCL/Tracing/pi_tracing_test.cpp @@ -13,6 +13,7 @@ // CHECK: // CHECK: ---> piMemBufferCreate( // CHECK-NEXT: : {{0[xX]?[0-9a-fA-F]*}} +// CHECK-NEXT: : {{0[xX]?[0-9a-fA-F]*}} // CHECK-NEXT: : 1 // CHECK-NEXT: : 40 // CHECK-NEXT: : 0 From daad593df55ff62c61bd0d5c4c9ba198ec3f4061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Ciglari=C4=8D?= Date: Tue, 19 Jul 2022 15:44:59 +0100 Subject: [PATCH 3/8] fix tests for other backends --- SYCL/Basic/alloc_pinned_host_memory.cpp | 1 + SYCL/Basic/buffer/native_buffer_creation_flags.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/SYCL/Basic/alloc_pinned_host_memory.cpp b/SYCL/Basic/alloc_pinned_host_memory.cpp index 6320715364..b741e54afc 100644 --- a/SYCL/Basic/alloc_pinned_host_memory.cpp +++ b/SYCL/Basic/alloc_pinned_host_memory.cpp @@ -40,4 +40,5 @@ int main() { // CHECK:---> piMemBufferCreate // CHECK:---> piMemBufferCreate // CHECK-NEXT: {{.*}} : {{.*}} +// CHECK-NEXT: {{.*}} : {{.*}} // CHECK-NEXT: {{.*}} : 17 diff --git a/SYCL/Basic/buffer/native_buffer_creation_flags.cpp b/SYCL/Basic/buffer/native_buffer_creation_flags.cpp index 68e912e3e4..4bd022010b 100644 --- a/SYCL/Basic/buffer/native_buffer_creation_flags.cpp +++ b/SYCL/Basic/buffer/native_buffer_creation_flags.cpp @@ -21,6 +21,7 @@ int main() { // buffer is created with the PI_MEM_FLAGS_HOST_PTR_USE flag. // CHECK: piMemBufferCreate // CHECK-NEXT: {{.*}} : {{.*}} + // CHECK-NEXT: {{.*}} : {{.*}} // CHECK-NEXT: {{.*}} : 9 auto BufAcc = Buf.get_access(Cgh); Cgh.single_task([=]() { int A = BufAcc[0]; }); From 11a9a73f32ad2b0ceea4972646ac85d8f871168b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Ciglari=C4=8D?= Date: Tue, 19 Jul 2022 16:45:55 +0200 Subject: [PATCH 4/8] Apply suggestions from code review Co-authored-by: aelovikov-intel --- SYCL/Basic/multi_device_context.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SYCL/Basic/multi_device_context.cpp b/SYCL/Basic/multi_device_context.cpp index f9f8371979..6d03efa9d1 100755 --- a/SYCL/Basic/multi_device_context.cpp +++ b/SYCL/Basic/multi_device_context.cpp @@ -6,7 +6,7 @@ // REQUIRES: cuda #include -#include +#include sycl::event add(sycl::queue q, sycl::buffer buff, int *usm, sycl::event e) { @@ -41,22 +41,22 @@ int main() { sycl::buffer buff1(&a, 1); sycl::buffer buff2(&b, 1); - // test copying usm + // Test copying usm. int *usm1 = sycl::malloc_device(1, q1); int *usm2 = sycl::malloc_device(1, q2); sycl::event e1 = q1.memcpy(usm1, &c, 1); sycl::event e2 = q2.memcpy(usm2, &d, 1); - // test combination of usm and buffers in a kernel + // Test combination of usm and buffers in a kernel. sycl::event e3 = add(q1, buff1, usm1, e1); sycl::event e4 = add(q2, buff2, usm2, e2); - // change values in usm to ensure results are distinct + // Change values in usm to ensure results are distinct. sycl::event e5 = q1.memcpy(usm1, &d, 1, e3); sycl::event e6 = q2.memcpy(usm2, &c, 1, e4); - // use each buffer on the other device than before - tests that copying - // between devices works + // Use each buffer on the other device than before - tests that copying + // between devices works. add(q1, buff2, usm1, e5); add(q2, buff1, usm2, e6); } From 50a968bc333b8fdec8c718340ef0296b36b940ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Ciglari=C4=8D?= Date: Tue, 19 Jul 2022 16:34:44 +0100 Subject: [PATCH 5/8] addressed review comments --- SYCL/Basic/multi_device_context.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/SYCL/Basic/multi_device_context.cpp b/SYCL/Basic/multi_device_context.cpp index 6d03efa9d1..d19dc02ee1 100755 --- a/SYCL/Basic/multi_device_context.cpp +++ b/SYCL/Basic/multi_device_context.cpp @@ -8,8 +8,8 @@ #include #include -sycl::event add(sycl::queue q, sycl::buffer buff, int *usm, - sycl::event e) { +sycl::event add(sycl::queue& q, sycl::buffer& buff, int *usm, + sycl::event& e) { return q.submit([&](sycl::handler &cgh) { auto acc = buff.get_access(cgh); cgh.depends_on(e); @@ -35,8 +35,6 @@ int main() { int a = 1; int b = 2; - int c = 4; - int d = 5; { sycl::buffer buff1(&a, 1); sycl::buffer buff2(&b, 1); @@ -44,16 +42,16 @@ int main() { // Test copying usm. int *usm1 = sycl::malloc_device(1, q1); int *usm2 = sycl::malloc_device(1, q2); - sycl::event e1 = q1.memcpy(usm1, &c, 1); - sycl::event e2 = q2.memcpy(usm2, &d, 1); + sycl::event e1 = q1.fill(usm1, 4, 1); + sycl::event e2 = q2.fill(usm2, 5, 1); // Test combination of usm and buffers in a kernel. sycl::event e3 = add(q1, buff1, usm1, e1); sycl::event e4 = add(q2, buff2, usm2, e2); // Change values in usm to ensure results are distinct. - sycl::event e5 = q1.memcpy(usm1, &d, 1, e3); - sycl::event e6 = q2.memcpy(usm2, &c, 1, e4); + sycl::event e5 = q1.fill(usm1, 5, 1, e3); + sycl::event e6 = q2.fill(usm2, 4, 1, e4); // Use each buffer on the other device than before - tests that copying // between devices works. From c163f83181a35923673d3db3abf689c3eac40e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Ciglari=C4=8D?= Date: Tue, 19 Jul 2022 16:42:59 +0100 Subject: [PATCH 6/8] format --- SYCL/Basic/multi_device_context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SYCL/Basic/multi_device_context.cpp b/SYCL/Basic/multi_device_context.cpp index d19dc02ee1..03c5c35c88 100755 --- a/SYCL/Basic/multi_device_context.cpp +++ b/SYCL/Basic/multi_device_context.cpp @@ -8,8 +8,8 @@ #include #include -sycl::event add(sycl::queue& q, sycl::buffer& buff, int *usm, - sycl::event& e) { +sycl::event add(sycl::queue &q, sycl::buffer &buff, int *usm, + sycl::event &e) { return q.submit([&](sycl::handler &cgh) { auto acc = buff.get_access(cgh); cgh.depends_on(e); From eec9e921ce07037df5533655c915d6293a1052d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Ciglari=C4=8D?= Date: Wed, 20 Jul 2022 07:37:02 +0100 Subject: [PATCH 7/8] fixed another test --- SYCL/Basic/use_pinned_host_memory.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SYCL/Basic/use_pinned_host_memory.cpp b/SYCL/Basic/use_pinned_host_memory.cpp index a596093313..cd84aed6c1 100644 --- a/SYCL/Basic/use_pinned_host_memory.cpp +++ b/SYCL/Basic/use_pinned_host_memory.cpp @@ -42,4 +42,5 @@ int main() { // CHECK:---> piMemBufferCreate // CHECK-NEXT: {{.*}} : {{.*}} +// CHECK-NEXT: {{.*}} : {{.*}} // CHECK-NEXT: {{.*}} : 17 From 684afdd80882a221beda9e0e333854be57df04ba Mon Sep 17 00:00:00 2001 From: Nicolas Miller Date: Mon, 30 Jan 2023 10:59:00 +0000 Subject: [PATCH 8/8] Remove deprecated host placeholder --- SYCL/Basic/multi_device_context.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/SYCL/Basic/multi_device_context.cpp b/SYCL/Basic/multi_device_context.cpp index 03c5c35c88..351b87dcfd 100755 --- a/SYCL/Basic/multi_device_context.cpp +++ b/SYCL/Basic/multi_device_context.cpp @@ -1,5 +1,4 @@ // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -// RUN: %HOST_RUN_PLACEHOLDER %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out // RUN: %GPU_RUN_PLACEHOLDER %t.out