From bee45c380d0c603809a4813ec1c4cac6967a8fca Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Thu, 18 Jan 2024 16:15:54 -0800 Subject: [PATCH 01/13] Throw when USM not supported by Device --- sycl/source/detail/usm/usm_impl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 396750acf3044..4260bb8569b07 100644 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -252,6 +252,11 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, PrepareNotify.scopedNotify( (uint16_t)xpti::trace_point_type_t::mem_alloc_begin); #endif + if (Kind == alloc::device && + !Dev.has(sycl::aspect::usm_device_allocations)) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support Unified Shared Memory!"); + } void *RetVal = alignedAllocInternal(Alignment, Size, getSyclObjImpl(Ctxt).get(), getSyclObjImpl(Dev).get(), Kind, PropList); From 88e2c31a4ee16a2ba8988a8f44a93e7e8d9bf4ae Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Thu, 18 Jan 2024 16:44:04 -0800 Subject: [PATCH 02/13] Throw when USM not supported! --- sycl/source/detail/usm/usm_impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 4260bb8569b07..801443cfec5b1 100644 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -253,9 +253,9 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, (uint16_t)xpti::trace_point_type_t::mem_alloc_begin); #endif if (Kind == alloc::device && - !Dev.has(sycl::aspect::usm_device_allocations)) { - throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support Unified Shared Memory!"); + !Dev.has(sycl::aspect::usm_device_allocations)) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support Unified Shared Memory!"); } void *RetVal = alignedAllocInternal(Alignment, Size, getSyclObjImpl(Ctxt).get(), From 57f4ae52748d15f70918f691b4cabdbff10557f6 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Fri, 19 Jan 2024 09:21:58 -0800 Subject: [PATCH 03/13] Throw when USM not supported by device! --- sycl/source/detail/usm/usm_impl.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) mode change 100644 => 100755 sycl/source/detail/usm/usm_impl.cpp diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp old mode 100644 new mode 100755 index 801443cfec5b1..7abe2fe3f72b9 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -131,6 +131,12 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList) { + const bool isDevice + if (Kind == alloc::device && + !Dev.has(sycl::aspect::usm_device_allocations)) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support Unified Shared Memory!"); + } void *RetVal = nullptr; if (Size == 0) return nullptr; @@ -160,6 +166,11 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, switch (Kind) { case alloc::device: { + if (Kind == alloc::device && + !DevImpl->has(sycl::aspect::usm_device_allocations)) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support Unified Shared Memory!"); + } Id = DevImpl->getHandleRef(); std::array Props; @@ -252,11 +263,6 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, PrepareNotify.scopedNotify( (uint16_t)xpti::trace_point_type_t::mem_alloc_begin); #endif - if (Kind == alloc::device && - !Dev.has(sycl::aspect::usm_device_allocations)) { - throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support Unified Shared Memory!"); - } void *RetVal = alignedAllocInternal(Alignment, Size, getSyclObjImpl(Ctxt).get(), getSyclObjImpl(Dev).get(), Kind, PropList); From 2a1536927118a0adfa54ba98d368083a261962f9 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Fri, 19 Jan 2024 09:24:33 -0800 Subject: [PATCH 04/13] Throw when USM not supported by device! --- sycl/source/detail/usm/usm_impl.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 7abe2fe3f72b9..14ae57b6d544f 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -131,12 +131,6 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList) { - const bool isDevice - if (Kind == alloc::device && - !Dev.has(sycl::aspect::usm_device_allocations)) { - throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support Unified Shared Memory!"); - } void *RetVal = nullptr; if (Size == 0) return nullptr; From bfaf51b6af5eb0a0aa2f97a4b98eb3a98f4ee54a Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Fri, 19 Jan 2024 10:47:28 -0800 Subject: [PATCH 05/13] revert --- sycl/source/detail/usm/usm_impl.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 14ae57b6d544f..515dd131fc3a2 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -160,11 +160,11 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, switch (Kind) { case alloc::device: { - if (Kind == alloc::device && - !DevImpl->has(sycl::aspect::usm_device_allocations)) { - throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support Unified Shared Memory!"); - } + //if (Kind == alloc::device && + //!DevImpl->has(sycl::aspect::usm_device_allocations)) { + // throw sycl::exception(sycl::errc::feature_not_supported, + // "Device does not support Unified Shared Memory!"); + //} Id = DevImpl->getHandleRef(); std::array Props; From 32f4c0250e4752edefd7dca544957126d2f64d40 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Mon, 22 Jan 2024 14:30:57 -0800 Subject: [PATCH 06/13] Throw exception when USM not supported! --- sycl/source/detail/usm/usm_impl.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 515dd131fc3a2..7509b5f7ca01c 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -59,6 +59,13 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, PrepareNotify.scopedNotify( (uint16_t)xpti::trace_point_type_t::mem_alloc_begin); #endif + const auto &devices = Ctxt.get_devices(); + if (!std::any_of(devices.begin(), devices.end(), [&](const auto &device) { + return device.has(sycl::aspect::usm_device_allocations); + })) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support Unified Shared Memory!"); + } void *RetVal = nullptr; if (Size == 0) return nullptr; @@ -131,6 +138,11 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList) { + if (Kind == alloc::device && + !DevImpl->has(sycl::aspect::usm_device_allocations)) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support Unified Shared Memory!"); + } void *RetVal = nullptr; if (Size == 0) return nullptr; @@ -160,11 +172,6 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, switch (Kind) { case alloc::device: { - //if (Kind == alloc::device && - //!DevImpl->has(sycl::aspect::usm_device_allocations)) { - // throw sycl::exception(sycl::errc::feature_not_supported, - // "Device does not support Unified Shared Memory!"); - //} Id = DevImpl->getHandleRef(); std::array Props; From 3e1cf74efcfeecaf437159d2a7def2a480cd4c29 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Mon, 22 Jan 2024 18:01:50 -0800 Subject: [PATCH 07/13] Add check for malloc_shared --- sycl/source/detail/usm/usm_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 7509b5f7ca01c..f0136f0565451 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -138,7 +138,7 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList) { - if (Kind == alloc::device && + if ((Kind == alloc::device || Kind == alloc::shared) && !DevImpl->has(sycl::aspect::usm_device_allocations)) { throw sycl::exception(sycl::errc::feature_not_supported, "Device does not support Unified Shared Memory!"); From 7321a9f01cabdd856af4b726c3a54f2a44fa9d23 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Tue, 23 Jan 2024 07:28:45 -0800 Subject: [PATCH 08/13] Fix errors --- sycl/source/detail/usm/usm_impl.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index f0136f0565451..1dc5b6c8390c2 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -61,10 +61,11 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, #endif const auto &devices = Ctxt.get_devices(); if (!std::any_of(devices.begin(), devices.end(), [&](const auto &device) { - return device.has(sycl::aspect::usm_device_allocations); + return device.has(sycl::aspect::usm_host_allocations); })) { - throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support Unified Shared Memory!"); + throw sycl::exception( + sycl::errc::feature_not_supported, + "No device in this context supports host allocations!"); } void *RetVal = nullptr; if (Size == 0) @@ -138,8 +139,10 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList) { - if ((Kind == alloc::device || Kind == alloc::shared) && - !DevImpl->has(sycl::aspect::usm_device_allocations)) { + if ((Kind == alloc::device && + !DevImpl->has(sycl::aspect::usm_device_allocations)) || + (Kind == alloc::shared && + !DevImpl->has(sycl::aspect::usm_shared_allocations))) { throw sycl::exception(sycl::errc::feature_not_supported, "Device does not support Unified Shared Memory!"); } From 7b0752a6f1c31be26b358e4b41ba512975f43481 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Tue, 23 Jan 2024 08:06:42 -0800 Subject: [PATCH 09/13] Separate malloc_shared and malloc_device --- sycl/source/detail/usm/usm_impl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 1dc5b6c8390c2..efe080e6269e5 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -139,10 +139,8 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, const context_impl *CtxImpl, const device_impl *DevImpl, alloc Kind, const property_list &PropList) { - if ((Kind == alloc::device && - !DevImpl->has(sycl::aspect::usm_device_allocations)) || - (Kind == alloc::shared && - !DevImpl->has(sycl::aspect::usm_shared_allocations))) { + if (Kind == alloc::device && + !DevImpl->has(sycl::aspect::usm_device_allocations)) { throw sycl::exception(sycl::errc::feature_not_supported, "Device does not support Unified Shared Memory!"); } @@ -267,6 +265,10 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, PrepareNotify.scopedNotify( (uint16_t)xpti::trace_point_type_t::mem_alloc_begin); #endif + if (Kind == alloc::shared && !Dev.has(sycl::aspect::usm_shared_allocations)) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support USM shared allocations!"); + } void *RetVal = alignedAllocInternal(Alignment, Size, getSyclObjImpl(Ctxt).get(), getSyclObjImpl(Dev).get(), Kind, PropList); From 8e73003ec8d5e6ff36f05836e2f2baefdc0cef15 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Tue, 23 Jan 2024 10:29:30 -0800 Subject: [PATCH 10/13] Refactoring --- sycl/source/detail/usm/usm_impl.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index efe080e6269e5..d14d039d32ae9 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -65,7 +65,7 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, })) { throw sycl::exception( sycl::errc::feature_not_supported, - "No device in this context supports host allocations!"); + "No device in this context supports USM host allocations!"); } void *RetVal = nullptr; if (Size == 0) @@ -142,7 +142,12 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, if (Kind == alloc::device && !DevImpl->has(sycl::aspect::usm_device_allocations)) { throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support Unified Shared Memory!"); + "Device does not support USM device allocations!"); + } + if (Kind == alloc::shared && + !DevImpl->has(sycl::aspect::usm_shared_allocations)) { + throw sycl::exception(sycl::errc::feature_not_supported, + "Device does not support USM shared allocations!"); } void *RetVal = nullptr; if (Size == 0) @@ -265,10 +270,6 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, PrepareNotify.scopedNotify( (uint16_t)xpti::trace_point_type_t::mem_alloc_begin); #endif - if (Kind == alloc::shared && !Dev.has(sycl::aspect::usm_shared_allocations)) { - throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support USM shared allocations!"); - } void *RetVal = alignedAllocInternal(Alignment, Size, getSyclObjImpl(Ctxt).get(), getSyclObjImpl(Dev).get(), Kind, PropList); From 7f82478b880636da6efeadc0a461e5de2199b145 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Tue, 23 Jan 2024 22:07:47 -0800 Subject: [PATCH 11/13] Remove code for malloc_shared --- sycl/source/detail/usm/usm_impl.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index d14d039d32ae9..6b06ce80c930c 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -144,11 +144,6 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, throw sycl::exception(sycl::errc::feature_not_supported, "Device does not support USM device allocations!"); } - if (Kind == alloc::shared && - !DevImpl->has(sycl::aspect::usm_shared_allocations)) { - throw sycl::exception(sycl::errc::feature_not_supported, - "Device does not support USM shared allocations!"); - } void *RetVal = nullptr; if (Size == 0) return nullptr; From 82f93cfccf879b5f123605bbcd1c33d249d76776 Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Wed, 24 Jan 2024 11:33:51 -0800 Subject: [PATCH 12/13] Add memory querying ZE call to malloc test --- sycl/test-e2e/USM/usm_pooling.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sycl/test-e2e/USM/usm_pooling.cpp b/sycl/test-e2e/USM/usm_pooling.cpp index ecb5a5eab7200..4a9d16ec5a34e 100644 --- a/sycl/test-e2e/USM/usm_pooling.cpp +++ b/sycl/test-e2e/USM/usm_pooling.cpp @@ -102,6 +102,7 @@ int main(int argc, char *argv[]) { } // CHECK-NOPOOL: Test [[API:zeMemAllocHost|zeMemAllocDevice|zeMemAllocShared]] +// CHECK-NOPOOL-NEXT: ZE ---> zeDeviceGetMemoryAccessProperties // CHECK-NOPOOL-NEXT: ZE ---> [[API]]( // CHECK-NOPOOL-NEXT: ZE ---> [[API]]( // CHECK-NOPOOL-NEXT: ZE ---> zeMemFree @@ -111,6 +112,7 @@ int main(int argc, char *argv[]) { // CHECK-NOPOOL-NEXT: ZE ---> [[API]]( // CHECK-12345: Test [[API:zeMemAllocHost|zeMemAllocDevice|zeMemAllocShared]] +// CHECK-12345-NEXT: ZE ---> zeDeviceGetMemoryAccessProperties // CHECK-12345-NEXT: ZE ---> [[API]]( // CHECK-12345-NEXT: ZE ---> [[API]]( // CHECK-12345-NEXT: ZE ---> zeMemFree @@ -120,6 +122,7 @@ int main(int argc, char *argv[]) { // CHECK-12345-NEXT: ZE ---> [[API]]( // CHECK-1245: Test [[API:zeMemAllocHost|zeMemAllocDevice|zeMemAllocShared]] +// CHECK-1245-NEXT: ZE ---> zeDeviceGetMemoryAccessProperties // CHECK-1245-NEXT: ZE ---> [[API]]( // CHECK-1245-NEXT: ZE ---> [[API]]( // CHECK-1245-NEXT: ZE ---> zeMemFree @@ -127,6 +130,7 @@ int main(int argc, char *argv[]) { // CHECK-1245-NEXT: ZE ---> [[API]]( // CHECK-15: Test [[API:zeMemAllocHost|zeMemAllocDevice|zeMemAllocShared]] +// CHECK-15-NEXT: ZE ---> zeDeviceGetMemoryAccessProperties // CHECK-15-NEXT: ZE ---> [[API]]( // CHECK-15-NEXT: ZE ---> [[API]]( // CHECK-15-NEXT: ZE ---> zeMemFree From b47a15bf823d867520c226f90de54f864a6f66bb Mon Sep 17 00:00:00 2001 From: Lorenc Bushi Date: Wed, 24 Jan 2024 12:21:37 -0800 Subject: [PATCH 13/13] Add TODO for malloc_shared --- sycl/source/detail/usm/usm_impl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 6b06ce80c930c..3db9df8b52337 100755 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -144,6 +144,14 @@ void *alignedAllocInternal(size_t Alignment, size_t Size, throw sycl::exception(sycl::errc::feature_not_supported, "Device does not support USM device allocations!"); } + if (Kind == alloc::shared && + !DevImpl->has(sycl::aspect::usm_shared_allocations)) { + // TODO:: Throw an exception to conform with the specification. + // Note that many tests will have to be changed to conform with the spec + // before completing this. That is, the tests will now have to expect + // exceptions as a result of failed allocations in addition to nullptr + // being returned depending on the reason why allocation failed. + } void *RetVal = nullptr; if (Size == 0) return nullptr;