From 9efaeeecfeba6c87dd15889a51c58d577a3edc9e Mon Sep 17 00:00:00 2001 From: James Brodman Date: Fri, 5 Jun 2020 11:44:51 -0400 Subject: [PATCH 01/15] Enable allocate_shared Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index f821175205c03..820902e644e46 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -47,6 +47,9 @@ class usm_allocator { : MContext(Q.get_context()), MDevice(Q.get_device()) {} usm_allocator(const usm_allocator &Other) : MContext(Other.MContext), MDevice(Other.MDevice) {} + template + usm_allocator(const usm_allocator &Other) noexcept + : MContext(Other.MContext), MDevice(Other.MDevice) {} /// Constructs an object on memory pointed by Ptr. /// @@ -66,9 +69,7 @@ class usm_allocator { usm::alloc AllocT = AllocKind, typename std::enable_if::type = 0> void construct(pointer, const_reference) { - throw feature_not_supported( - "Device pointers do not support construct on host", - PI_INVALID_OPERATION); + // This method must be a NOP for device pointers. } /// Destroys an object. @@ -159,6 +160,9 @@ class usm_allocator { */ return Alignment; } + + template + friend class usm_allocator; const context MContext; const device MDevice; From 186cf79e9cc13208d2ff16eef231cb81c20085bb Mon Sep 17 00:00:00 2001 From: James Brodman Date: Wed, 1 Jul 2020 11:34:29 -0400 Subject: [PATCH 02/15] Improve USM Allocator. Add equality operators. Enable allocate_shared. Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 16 +++++- sycl/test/usm/allocator_equal.cpp | 60 ++++++++++++++++++++++ sycl/test/usm/allocator_shared.cpp | 59 +++++++++++++++++++++ 3 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 sycl/test/usm/allocator_equal.cpp create mode 100644 sycl/test/usm/allocator_shared.cpp diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index 820902e644e46..162d8f9bbcfa7 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -149,6 +149,20 @@ class usm_allocator { } } + template + friend bool operator==(const usm_allocator &One, + const usm_allocator &Two) { + return ((AllocKind == AllocKindU) && (One.MContext == Two.MContext) && + (One.MDevice == Two.MDevice)); + } + + template + friend bool operator!=(const usm_allocator &One, + const usm_allocator &Two) { + return !((AllocKind == AllocKindU) && (One.MContext == Two.MContext) && + (One.MDevice == Two.MDevice)); + } + private: constexpr size_t getAlignment() const { /* @@ -160,7 +174,7 @@ class usm_allocator { */ return Alignment; } - + template friend class usm_allocator; diff --git a/sycl/test/usm/allocator_equal.cpp b/sycl/test/usm/allocator_equal.cpp new file mode 100644 index 0000000000000..d06ed7da577f5 --- /dev/null +++ b/sycl/test/usm/allocator_equal.cpp @@ -0,0 +1,60 @@ +// XFAIL: cuda +// piextUSM*Alloc functions for CUDA are not behaving as described in +// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc +// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc +// +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out +// RUN: %CPU_RUN_PLACEHOLDER %t1.out +// RUN: %GPU_RUN_PLACEHOLDER %t1.out + +//==---- allocator_equal.cpp - Allocator Equality test -------------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +using namespace cl::sycl; + +int main() { + queue q; + auto dev = q.get_device(); + auto ctxt = q.get_context(); + + queue q2; + auto dev2 = q2.get_device(); + auto ctxt2 = q2.get_context(); + + // Test allocator equality + if (dev.get_info()) { + usm_allocator alloc1(ctxt, dev); + usm_allocator alloc2(q); + + assert((alloc1 == alloc2) && "Allocators should be equal."); + + usm_allocator alloc3(ctxt, dev); + usm_allocator alloc4(q); + + assert((alloc1 == alloc2) && "Allocators should be equal."); + } + + if (dev.get_info()) { + usm_allocator alloc1(ctxt, dev); + usm_allocator alloc2(ctxt, dev); + + assert((alloc1 != alloc2) && "Allocators should NOT be equal."); + } + + if (dev.get_info()) { + usm_allocator alloc1(ctxt, dev); + usm_allocator alloc2(ctxt2, dev2); + + assert((alloc1 != alloc2) && "Allocators should NOT be equal."); + } + + return 0; +} diff --git a/sycl/test/usm/allocator_shared.cpp b/sycl/test/usm/allocator_shared.cpp new file mode 100644 index 0000000000000..136b8b416841e --- /dev/null +++ b/sycl/test/usm/allocator_shared.cpp @@ -0,0 +1,59 @@ +// XFAIL: cuda +// piextUSM*Alloc functions for CUDA are not behaving as described in +// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc +// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc +// +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out +// RUN: %CPU_RUN_PLACEHOLDER %t1.out +// RUN: %GPU_RUN_PLACEHOLDER %t1.out + +//==---- allocator_shared.cpp - Allocate Shared test -------------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +#include + +using namespace cl::sycl; + +int main() { + queue q; + auto dev = q.get_device(); + auto ctxt = q.get_context(); + + // Test ability to create a shared pointer. + if (dev.get_info()) { + usm_allocator alloc(ctxt, dev); + auto ptr1 = std::allocate_shared(alloc); + + // Test construction + auto ptr2 = std::allocate_shared(alloc, 42); + assert(*ptr2 == 42); + } + + if (dev.get_info()) { + usm_allocator alloc(ctxt, dev); + auto ptr1 = std::allocate_shared(alloc); + + // Test construction + auto ptr2 = std::allocate_shared(alloc, 42); + assert(*ptr2 == 42); + } + + if (dev.get_info()) { + usm_allocator alloc(ctxt, dev); + auto ptr1 = std::allocate_shared(alloc); + + // Test construction + auto ptr2 = std::allocate_shared(alloc, 42); + // Cannot actually construct value for device pointers, but should not die. + } + + return 0; +} From 836d9b2e56839dd668e58d8711f052ec54feb304 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Wed, 1 Jul 2020 11:40:26 -0400 Subject: [PATCH 03/15] Remove test as behavior has changed. Construct is a NOP for device allocations. Signed-off-by: James Brodman --- sycl/test/usm/allocator_vector_fail.cpp | 48 ------------------------- 1 file changed, 48 deletions(-) delete mode 100644 sycl/test/usm/allocator_vector_fail.cpp diff --git a/sycl/test/usm/allocator_vector_fail.cpp b/sycl/test/usm/allocator_vector_fail.cpp deleted file mode 100644 index 8c0e176eaa411..0000000000000 --- a/sycl/test/usm/allocator_vector_fail.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// XFAIL: cuda -// piextUSM*Alloc functions for CUDA are not behaving as described in -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc -// -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out -// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out -// RUN: %CPU_RUN_PLACEHOLDER %t1.out -// RUN: %GPU_RUN_PLACEHOLDER %t1.out - -//==-- allocator_vector_fail.cpp - Device Memory Allocator fail test -------==// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include - -#include - -using namespace cl::sycl; - -const int N = 8; - -class foo; -int main() { - queue q; - auto dev = q.get_device(); - auto ctxt = q.get_context(); - - if (dev.get_info()) { - try { - usm_allocator alloc(ctxt, dev); - std::vector vec(alloc); - - // This statement should throw an exception since - // device pointers may not be accessed on the host. - vec.assign(N, 42); - } catch (feature_not_supported) { - return 0; - } - - return -1; - } - return 0; -} From 78bd8761a83fb6727d2fe389280f5a6e11379785 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Wed, 1 Jul 2020 12:00:41 -0400 Subject: [PATCH 04/15] Clang-format fix. Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index 162d8f9bbcfa7..901d149830b5d 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -160,7 +160,7 @@ class usm_allocator { friend bool operator!=(const usm_allocator &One, const usm_allocator &Two) { return !((AllocKind == AllocKindU) && (One.MContext == Two.MContext) && - (One.MDevice == Two.MDevice)); + (One.MDevice == Two.MDevice)); } private: From 6c6309ebb519255d91a1c0b67042de4ad1b8b3a1 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Wed, 1 Jul 2020 13:08:19 -0400 Subject: [PATCH 05/15] Make assert more verbose in test. Signed-off-by: James Brodman --- sycl/test/usm/allocator_shared.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/test/usm/allocator_shared.cpp b/sycl/test/usm/allocator_shared.cpp index 136b8b416841e..2fd55d97619b4 100644 --- a/sycl/test/usm/allocator_shared.cpp +++ b/sycl/test/usm/allocator_shared.cpp @@ -34,7 +34,7 @@ int main() { // Test construction auto ptr2 = std::allocate_shared(alloc, 42); - assert(*ptr2 == 42); + assert((*ptr2 == 42) && "Host construct passed."); } if (dev.get_info()) { @@ -43,7 +43,7 @@ int main() { // Test construction auto ptr2 = std::allocate_shared(alloc, 42); - assert(*ptr2 == 42); + assert((*ptr2 == 42) && "Shared construct passed."); } if (dev.get_info()) { From 9f24380d2629c7cb055a3fe7f626969c0ae5382b Mon Sep 17 00:00:00 2001 From: James Brodman Date: Thu, 9 Jul 2020 13:00:57 -0400 Subject: [PATCH 06/15] Remove test for device allocations as they cannot work. Fix formatting. Signed-off-by: James Brodman --- sycl/test/usm/allocator_equal.cpp | 4 +++- sycl/test/usm/allocator_shared.cpp | 12 +++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/sycl/test/usm/allocator_equal.cpp b/sycl/test/usm/allocator_equal.cpp index d06ed7da577f5..69b9ba65efd5b 100644 --- a/sycl/test/usm/allocator_equal.cpp +++ b/sycl/test/usm/allocator_equal.cpp @@ -8,7 +8,7 @@ // RUN: %CPU_RUN_PLACEHOLDER %t1.out // RUN: %GPU_RUN_PLACEHOLDER %t1.out -//==---- allocator_equal.cpp - Allocator Equality test -------------------==// +//==---------- allocator_equal.cpp - Allocator Equality test ---------------==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -18,6 +18,8 @@ #include +#include + using namespace cl::sycl; int main() { diff --git a/sycl/test/usm/allocator_shared.cpp b/sycl/test/usm/allocator_shared.cpp index 2fd55d97619b4..110cb22214ab8 100644 --- a/sycl/test/usm/allocator_shared.cpp +++ b/sycl/test/usm/allocator_shared.cpp @@ -8,7 +8,7 @@ // RUN: %CPU_RUN_PLACEHOLDER %t1.out // RUN: %GPU_RUN_PLACEHOLDER %t1.out -//==---- allocator_shared.cpp - Allocate Shared test -------------------==// +//==-------- allocator_shared.cpp - Allocate Shared test -------------------==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -18,6 +18,7 @@ #include +#include #include using namespace cl::sycl; @@ -46,14 +47,7 @@ int main() { assert((*ptr2 == 42) && "Shared construct passed."); } - if (dev.get_info()) { - usm_allocator alloc(ctxt, dev); - auto ptr1 = std::allocate_shared(alloc); - - // Test construction - auto ptr2 = std::allocate_shared(alloc, 42); - // Cannot actually construct value for device pointers, but should not die. - } + // Device allocations are not supported due to how allocated_shared is written. return 0; } From ce67702b598f13afb6ba36306b8f8f7dfaae2345 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Mon, 13 Jul 2020 10:12:19 -0400 Subject: [PATCH 07/15] Remove cuda XFAIL Signed-off-by: James Brodman --- sycl/test/usm/allocator_equal.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sycl/test/usm/allocator_equal.cpp b/sycl/test/usm/allocator_equal.cpp index d06ed7da577f5..8f930392cfc42 100644 --- a/sycl/test/usm/allocator_equal.cpp +++ b/sycl/test/usm/allocator_equal.cpp @@ -1,4 +1,3 @@ -// XFAIL: cuda // piextUSM*Alloc functions for CUDA are not behaving as described in // https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc // https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc From 0e776b5617dece8e5d03e469c41e57777f659f6f Mon Sep 17 00:00:00 2001 From: James Brodman Date: Wed, 15 Jul 2020 16:15:37 -0400 Subject: [PATCH 08/15] Modernize allocator. Disallow device allocations due to too many complications. Update tests Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 119 ++++----------------- sycl/test/usm/allocator_equal.cpp | 12 +-- sycl/test/usm/allocator_vector.cpp | 38 ------- sycl/test/usm/allocatorll.cpp | 88 --------------- 4 files changed, 26 insertions(+), 231 deletions(-) delete mode 100644 sycl/test/usm/allocatorll.cpp diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index 901d149830b5d..8f34d464eaede 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -30,109 +30,43 @@ template class usm_allocator { public: using value_type = T; - using pointer = T *; - using const_pointer = const T *; - using reference = T &; - using const_reference = const T &; + using propagate_on_container_copy_assignment = std::true_type; + using propagate_on_container_move_assignment = std::true_type; + using propagate_on_container_swap = std::true_type; public: template struct rebind { typedef usm_allocator other; }; - usm_allocator() = delete; - usm_allocator(const context &Ctxt, const device &Dev) - : MContext(Ctxt), MDevice(Dev) {} - usm_allocator(const queue &Q) - : MContext(Q.get_context()), MDevice(Q.get_device()) {} - usm_allocator(const usm_allocator &Other) - : MContext(Other.MContext), MDevice(Other.MDevice) {} - template - usm_allocator(const usm_allocator &Other) noexcept - : MContext(Other.MContext), MDevice(Other.MDevice) {} - - /// Constructs an object on memory pointed by Ptr. - /// - /// Note: AllocKind == alloc::device is not allowed. - /// - /// \param Ptr is a pointer to memory that will be used to construct the - /// object. - /// \param Val is a value to initialize the newly constructed object. - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - void construct(pointer Ptr, const_reference Val) { - new (Ptr) value_type(Val); + usm_allocator() noexcept = delete; + usm_allocator(const context &Ctxt, const device &Dev) noexcept + : MContext(Ctxt), MDevice(Dev) { + static_assert(AllocKind != usm::alloc::device, + "Allocators do not work with device allocations."); } - - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - void construct(pointer, const_reference) { - // This method must be a NOP for device pointers. - } - - /// Destroys an object. - /// - /// Note:: AllocKind == alloc::device is not allowed - /// - /// \param Ptr is a pointer to memory where the object resides. - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - void destroy(pointer Ptr) { - Ptr->~value_type(); + usm_allocator(const queue &Q) noexcept + : MContext(Q.get_context()), MDevice(Q.get_device()) { + static_assert(AllocKind != usm::alloc::device, + "Allocators do not work with device allocations."); } + usm_allocator(const usm_allocator &) noexcept = default; + usm_allocator(usm_allocator&&) noexcept = default; + usm_allocator& operator=(const usm_allocator&) = delete; + usm_allocator& operator=(usm_allocator&&) = default; - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - void destroy(pointer) { - // This method must be a NOP for device pointers. - } - - /// Note:: AllocKind == alloc::device is not allowed. - /// - /// \param Val is a reference to object. - /// \return an address of the object referenced by Val. - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - pointer address(reference Val) const { - return &Val; - } - - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - pointer address(reference) const { - throw feature_not_supported( - "Device pointers do not support address on host", PI_INVALID_OPERATION); - } - - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - const_pointer address(const_reference Val) const { - return &Val; - } - - template < - usm::alloc AllocT = AllocKind, - typename std::enable_if::type = 0> - const_pointer address(const_reference) const { - throw feature_not_supported( - "Device pointers do not support address on host", PI_INVALID_OPERATION); - } + template + usm_allocator(const usm_allocator &Other) noexcept + : MContext(Other.MContext), MDevice(Other.MDevice) {} /// Allocates memory. /// /// \param NumberOfElements is a count of elements to allocate memory for. - pointer allocate(size_t NumberOfElements) { + T *allocate(size_t NumberOfElements) { - auto Result = reinterpret_cast( + auto Result = reinterpret_cast( aligned_alloc(getAlignment(), NumberOfElements * sizeof(value_type), - MDevice, MContext, AllocKind)); + MDevice, MContext, AllocKind)); if (!Result) { throw memory_allocation_error(); } @@ -143,7 +77,7 @@ class usm_allocator { /// /// \param Ptr is a pointer to memory being deallocated. /// \param Size is a number of elements previously passed to allocate. - void deallocate(pointer Ptr, size_t) { + void deallocate(T *Ptr, size_t) { if (Ptr) { free(Ptr, MContext); } @@ -165,13 +99,6 @@ class usm_allocator { private: constexpr size_t getAlignment() const { - /* - // This form might be preferable if the underlying implementation - // doesn't do the right thing when given 0 for alignment - return ((Alignment == 0) - ? alignof(value_type) - : Alignment); - */ return Alignment; } diff --git a/sycl/test/usm/allocator_equal.cpp b/sycl/test/usm/allocator_equal.cpp index 119c33df57aaf..e02040fe16c28 100644 --- a/sycl/test/usm/allocator_equal.cpp +++ b/sycl/test/usm/allocator_equal.cpp @@ -43,16 +43,10 @@ int main() { assert((alloc1 == alloc2) && "Allocators should be equal."); } - if (dev.get_info()) { + if (dev.get_info() && + dev.get_info()) { usm_allocator alloc1(ctxt, dev); - usm_allocator alloc2(ctxt, dev); - - assert((alloc1 != alloc2) && "Allocators should NOT be equal."); - } - - if (dev.get_info()) { - usm_allocator alloc1(ctxt, dev); - usm_allocator alloc2(ctxt2, dev2); + usm_allocator alloc2(ctxt, dev); assert((alloc1 != alloc2) && "Allocators should NOT be equal."); } diff --git a/sycl/test/usm/allocator_vector.cpp b/sycl/test/usm/allocator_vector.cpp index 265c071e1cf0e..135484c1d4e8f 100644 --- a/sycl/test/usm/allocator_vector.cpp +++ b/sycl/test/usm/allocator_vector.cpp @@ -88,43 +88,5 @@ int main() { return -1; } - if (dev.get_info()) { - 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; } diff --git a/sycl/test/usm/allocatorll.cpp b/sycl/test/usm/allocatorll.cpp deleted file mode 100644 index 323dc0d75a1c1..0000000000000 --- a/sycl/test/usm/allocatorll.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// XFAIL: cuda -// piextUSM*Alloc functions for CUDA are not behaving as described in -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc -// -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out -// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out -// RUN: %CPU_RUN_PLACEHOLDER %t1.out -// RUN: %GPU_RUN_PLACEHOLDER %t1.out - -//==---- allocatorll.cpp - Device Memory Linked List Allocator test --------==// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include - -using namespace cl::sycl; - -int numNodes = 4; - -struct Node { - Node() : pNext(nullptr), Num(0xDEADBEEF) {} - - Node *pNext; - uint32_t Num; -}; - -class foo; -int main() { - queue q; - auto dev = q.get_device(); - auto ctxt = q.get_context(); - - if (!dev.get_info()) - return 0; - - usm_allocator alloc(ctxt, dev); - Node h_cur; - - Node *d_head = alloc.allocate(1); - Node *d_cur = d_head; - - for (int i = 0; i < numNodes; i++) { - h_cur.Num = i * 2; - - if (i != (numNodes - 1)) { - h_cur.pNext = alloc.allocate(1); - } else { - h_cur.pNext = nullptr; - } - - event e0 = q.memcpy(d_cur, &h_cur, sizeof(Node)); - e0.wait(); - - d_cur = h_cur.pNext; - } - - auto e1 = q.submit([=](handler &cgh) { - cgh.single_task([=]() { - Node *pHead = d_head; - while (pHead) { - pHead->Num = pHead->Num * 2 + 1; - pHead = pHead->pNext; - } - }); - }); - - e1.wait(); - - d_cur = d_head; - for (int i = 0; i < numNodes; i++) { - event c = q.memcpy(&h_cur, d_cur, sizeof(Node)); - c.wait(); - alloc.deallocate(d_cur, 1); - - const int want = i * 4 + 1; - if (h_cur.Num != want) { - return -2; - } - d_cur = h_cur.pNext; - } - - return 0; -} From df1a5a4b601e54260bb129dfeac68b6eedfce329 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Wed, 15 Jul 2020 16:18:50 -0400 Subject: [PATCH 09/15] clang format Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index 8f34d464eaede..c32b4756d0099 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -51,9 +51,9 @@ class usm_allocator { "Allocators do not work with device allocations."); } usm_allocator(const usm_allocator &) noexcept = default; - usm_allocator(usm_allocator&&) noexcept = default; - usm_allocator& operator=(const usm_allocator&) = delete; - usm_allocator& operator=(usm_allocator&&) = default; + usm_allocator(usm_allocator &&) noexcept = default; + usm_allocator &operator=(const usm_allocator &) = delete; + usm_allocator &operator=(usm_allocator &&) = default; template usm_allocator(const usm_allocator &Other) noexcept From b175024a6a98359f77b5ed8d820d759c2f17f15f Mon Sep 17 00:00:00 2001 From: James Brodman Date: Wed, 15 Jul 2020 17:04:06 -0400 Subject: [PATCH 10/15] Remove level0 xfail Signed-off-by: James Brodman --- sycl/test/usm/allocator_vector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/usm/allocator_vector.cpp b/sycl/test/usm/allocator_vector.cpp index 135484c1d4e8f..0609d2134e1b5 100644 --- a/sycl/test/usm/allocator_vector.cpp +++ b/sycl/test/usm/allocator_vector.cpp @@ -1,4 +1,4 @@ -// XFAIL: cuda || level0 +// XFAIL: cuda // piextUSM*Alloc functions for CUDA are not behaving as described in // https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc // https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc From 18a20feac0615474642ac889d494be3682302994 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Fri, 17 Jul 2020 15:36:32 -0400 Subject: [PATCH 11/15] Move static_assert to class body. Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index c32b4756d0099..d9ba5ad029e11 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -39,17 +39,15 @@ class usm_allocator { typedef usm_allocator other; }; + static_assert( + AllocKind != usm::alloc::device, + "usm_allocator does not support AllocKind == usm::alloc::device"); + usm_allocator() noexcept = delete; usm_allocator(const context &Ctxt, const device &Dev) noexcept - : MContext(Ctxt), MDevice(Dev) { - static_assert(AllocKind != usm::alloc::device, - "Allocators do not work with device allocations."); - } + : MContext(Ctxt), MDevice(Dev) {} usm_allocator(const queue &Q) noexcept - : MContext(Q.get_context()), MDevice(Q.get_device()) { - static_assert(AllocKind != usm::alloc::device, - "Allocators do not work with device allocations."); - } + : MContext(Q.get_context()), MDevice(Q.get_device()) {} usm_allocator(const usm_allocator &) noexcept = default; usm_allocator(usm_allocator &&) noexcept = default; usm_allocator &operator=(const usm_allocator &) = delete; From 40fbf4913d0eb42da5c494ba56b3c2efa03abd58 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Tue, 28 Jul 2020 11:01:31 -0400 Subject: [PATCH 12/15] Change default align to alignof(T) Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index d9ba5ad029e11..64b2f52db21e5 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -26,7 +26,7 @@ __SYCL_EXPORT void *aligned_alloc(size_t alignment, size_t size, usm::alloc kind); __SYCL_EXPORT void free(void *ptr, const context &ctxt); -template +template class usm_allocator { public: using value_type = T; From 29649c439e522c9bfcd1aca012b0613bd2642112 Mon Sep 17 00:00:00 2001 From: James Brodman Date: Tue, 28 Jul 2020 11:09:02 -0400 Subject: [PATCH 13/15] clang-format Signed-off-by: James Brodman --- sycl/include/CL/sycl/usm/usm_allocator.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/usm/usm_allocator.hpp b/sycl/include/CL/sycl/usm/usm_allocator.hpp index 64b2f52db21e5..3270fa1d6d67e 100644 --- a/sycl/include/CL/sycl/usm/usm_allocator.hpp +++ b/sycl/include/CL/sycl/usm/usm_allocator.hpp @@ -96,9 +96,7 @@ class usm_allocator { } private: - constexpr size_t getAlignment() const { - return Alignment; - } + constexpr size_t getAlignment() const { return Alignment; } template friend class usm_allocator; From 101dee6111f49930c6d543cc44ba5d015359409e Mon Sep 17 00:00:00 2001 From: James Brodman Date: Tue, 28 Jul 2020 11:13:52 -0400 Subject: [PATCH 14/15] clang-format Signed-off-by: James Brodman --- sycl/test/usm/allocator_shared.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sycl/test/usm/allocator_shared.cpp b/sycl/test/usm/allocator_shared.cpp index 110cb22214ab8..d00ee60c08148 100644 --- a/sycl/test/usm/allocator_shared.cpp +++ b/sycl/test/usm/allocator_shared.cpp @@ -47,7 +47,8 @@ int main() { assert((*ptr2 == 42) && "Shared construct passed."); } - // Device allocations are not supported due to how allocated_shared is written. + // Device allocations are not supported due to how allocated_shared is + // written. return 0; } From 50307bdad2b4feea046a4a02543df14061a8902e Mon Sep 17 00:00:00 2001 From: James Brodman Date: Tue, 28 Jul 2020 15:18:33 -0400 Subject: [PATCH 15/15] Remove XFAIL cuda on tests Signed-off-by: James Brodman --- sycl/test/usm/allocator_shared.cpp | 5 ----- sycl/test/usm/allocator_vector.cpp | 5 ----- 2 files changed, 10 deletions(-) diff --git a/sycl/test/usm/allocator_shared.cpp b/sycl/test/usm/allocator_shared.cpp index d00ee60c08148..2dbc0fe57bd6f 100644 --- a/sycl/test/usm/allocator_shared.cpp +++ b/sycl/test/usm/allocator_shared.cpp @@ -1,8 +1,3 @@ -// XFAIL: cuda -// piextUSM*Alloc functions for CUDA are not behaving as described in -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc -// // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out // RUN: env SYCL_DEVICE_TYPE=HOST %t1.out // RUN: %CPU_RUN_PLACEHOLDER %t1.out diff --git a/sycl/test/usm/allocator_vector.cpp b/sycl/test/usm/allocator_vector.cpp index 0609d2134e1b5..8f0dcaa62055a 100644 --- a/sycl/test/usm/allocator_vector.cpp +++ b/sycl/test/usm/allocator_vector.cpp @@ -1,8 +1,3 @@ -// XFAIL: cuda -// piextUSM*Alloc functions for CUDA are not behaving as described in -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc -// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc -// // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out // RUN: env SYCL_DEVICE_TYPE=HOST %t1.out // RUN: %CPU_RUN_PLACEHOLDER %t1.out