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 396750acf3044..3db9df8b52337 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -59,6 +59,14 @@ 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_host_allocations); + })) { + throw sycl::exception( + sycl::errc::feature_not_supported, + "No device in this context supports USM host allocations!"); + } void *RetVal = nullptr; if (Size == 0) return nullptr; @@ -131,6 +139,19 @@ 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 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; 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