Skip to content

Commit

Permalink
Throw when device does not support USM allocation (intel#12446)
Browse files Browse the repository at this point in the history
The USM allocation functions are changed to conform with the spec and
throw when certain usm allocation modes are not supported.
malloc_shared is left incomplete because it breaks a lot of tests and
its more reasonable to handle that in a later PR. In the meantime,
malloc_device and malloc_host have been changed to conform with the spec
and throw an exception when the corresponding USM aspect is not
supported. The test usm_pooling.cpp has also been updated to reflect
this query about the memory access properties in the L0 API so that it
knows to expect it in the output.
  • Loading branch information
lbushi25 authored Jan 25, 2024
1 parent 2e4916a commit 4dfde5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sycl/source/detail/usm/usm_impl.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions sycl/test-e2e/USM/usm_pooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -120,13 +122,15 @@ 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
// CHECK-1245-NEXT: ZE ---> [[API]](
// 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

0 comments on commit 4dfde5f

Please sign in to comment.