Skip to content

Throw when device does not support USM allocation #12446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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