From de7379010e3279bccec2a726bc817bc7323d3537 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Thu, 16 Apr 2020 15:10:04 -0400 Subject: [PATCH 1/2] Improve USM allocator test and fix improper behavior. Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 3 +- sycl/test/usm/allocator_vector.cpp | 107 +++++++++++++++++---- 2 files changed, 90 insertions(+), 20 deletions(-) diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index 2967f1fe0195d..1ee4d6ae44e66 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -87,8 +87,7 @@ class usm_allocator { usm::alloc AllocT = AllocKind, typename std::enable_if::type = 0> void destroy(pointer Ptr) { - throw feature_not_supported( - "Device pointers do not support destroy on host", PI_INVALID_OPERATION); + // This method must be a NOP for device pointers. } /// Note:: AllocKind == alloc::device is not allowed. diff --git a/sycl/test/usm/allocator_vector.cpp b/sycl/test/usm/allocator_vector.cpp index 2a87695c2f2ff..550ebae22642f 100644 --- a/sycl/test/usm/allocator_vector.cpp +++ b/sycl/test/usm/allocator_vector.cpp @@ -30,35 +30,106 @@ int main() { auto dev = q.get_device(); auto ctxt = q.get_context(); - if (!dev.get_info()) + if (!(dev.get_info() && + dev.get_info() && + dev.get_info())) return 0; - usm_allocator alloc(ctxt, dev); + { + usm_allocator alloc(ctxt, dev); - std::vector vec(alloc); - vec.resize(N); + std::vector vec(alloc); + vec.resize(N); - for (int i = 0; i < N; i++) { - vec[i] = i; + for (int i = 0; i < N; i++) { + vec[i] = i; + } + + int *res = &vec[0]; + int *vals = &vec[0]; + + auto e1 = q.submit([=](handler &h) { + h.single_task([=]() { + for (int i = 1; i < N; i++) { + res[0] += vals[i]; + } + }); + }); + + e1.wait(); + + int answer = (N * (N - 1)) / 2; + + if (vec[0] != answer) + return -1; } - int *res = &vec[0]; - int *vals = &vec[0]; + { + usm_allocator alloc(ctxt, dev); - auto e1 = q.submit([=](handler &cgh) { - cgh.single_task([=]() { - for (int i = 1; i < N; i++) { - res[0] += vals[i]; - } + std::vector vec(alloc); + vec.resize(N); + + for (int i = 0; i < N; i++) { + vec[i] = i; + } + + int *res = &vec[0]; + int *vals = &vec[0]; + + auto e1 = q.submit([=](handler &h) { + h.single_task([=]() { + for (int i = 1; i < N; i++) { + res[0] += vals[i]; + } + }); }); - }); - e1.wait(); + e1.wait(); - int answer = (N * (N - 1)) / 2; + int answer = (N * (N - 1)) / 2; + + if (vec[0] != answer) + return -1; + } - if (vec[0] != answer) - return -1; + { + usm_allocator alloc(ctxt, dev); + + std::vector vec(alloc); + vec.resize(N); + + int *res = &vec[0]; + int *vals = &vec[0]; + + auto e0 = q.submit([=](handler &h) { + h.single_task([=]() { + res[0] = 0; + for (int i = 0; i < N; i++) { + vals[i] = i; + } + }); + }); + + auto e1 = q.submit([=](handler &h) { + h.depends_on(e0); + h.single_task([=]() { + for (int i = 1; i < N; i++) { + res[0] += vals[i]; + } + }); + }); + + e1.wait(); + + int answer = (N * (N - 1)) / 2; + int result; + q.memcpy(&result, res, sizeof(int)); + q.wait(); + + if (result != answer) + return -1; + } return 0; } From 6475531a5aec6e57ee7e2cb30792ff7f7363cbfc Mon Sep 17 00:00:00 2001 From: James Brodman Date: Tue, 28 Apr 2020 18:31:53 -0400 Subject: [PATCH 2/2] Gate different parts of test appropriately Signed-off-by: James Brodman --- sycl/test/usm/allocator_vector.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sycl/test/usm/allocator_vector.cpp b/sycl/test/usm/allocator_vector.cpp index 550ebae22642f..2f1b8c3ff3eef 100644 --- a/sycl/test/usm/allocator_vector.cpp +++ b/sycl/test/usm/allocator_vector.cpp @@ -30,12 +30,7 @@ int main() { auto dev = q.get_device(); auto ctxt = q.get_context(); - if (!(dev.get_info() && - dev.get_info() && - dev.get_info())) - return 0; - - { + if (dev.get_info()) { usm_allocator alloc(ctxt, dev); std::vector vec(alloc); @@ -64,7 +59,7 @@ int main() { return -1; } - { + if (dev.get_info()) { usm_allocator alloc(ctxt, dev); std::vector vec(alloc); @@ -93,7 +88,7 @@ int main() { return -1; } - { + if (dev.get_info()) { usm_allocator alloc(ctxt, dev); std::vector vec(alloc);