diff --git a/sycl/include/sycl/ext/intel/experimental/usm_properties.hpp b/sycl/include/sycl/ext/intel/experimental/usm_properties.hpp index 3c31b5d80278a..5cf3fdc1695ca 100644 --- a/sycl/include/sycl/ext/intel/experimental/usm_properties.hpp +++ b/sycl/include/sycl/ext/intel/experimental/usm_properties.hpp @@ -39,16 +39,10 @@ class buffer_location uint64_t MLocation; }; +// If new properties are added here, update `verifyUSMAllocatorProperties` to +// include them! + } // namespace intel::experimental::property::usm } // namespace ext - -template <> -struct is_property - : std::true_type {}; - -template <> -struct is_property - : std::true_type {}; - } // namespace _V1 } // namespace sycl diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 2f6d6fd5688f8..9cf6fee0ecf3c 100644 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -644,9 +644,22 @@ void release_from_device_copy(const void *Ptr, const queue &Queue) { } // namespace ext::oneapi::experimental __SYCL_EXPORT void verifyUSMAllocatorProperties(const property_list &PropList) { - auto NoAllowedPropertiesCheck = [](int) { return false; }; - detail::PropertyValidator::checkPropsAndThrow( - PropList, NoAllowedPropertiesCheck, NoAllowedPropertiesCheck); + auto DataLessCheck = [](int Kind) { + switch (Kind) { + case detail::DeviceReadOnly: + return true; + } + return false; + }; + auto WithDataCheck = [](int Kind) { + switch (Kind) { + case detail::PropWithDataKind::AccPropBufferLocation: + return true; + } + return false; + }; + detail::PropertyValidator::checkPropsAndThrow(PropList, DataLessCheck, + WithDataCheck); } } // namespace _V1 diff --git a/sycl/test-e2e/Adapters/level_zero/usm_device_read_only.cpp b/sycl/test-e2e/Adapters/level_zero/usm_device_read_only.cpp index d848d68e95af9..99f5d4e5c8740 100644 --- a/sycl/test-e2e/Adapters/level_zero/usm_device_read_only.cpp +++ b/sycl/test-e2e/Adapters/level_zero/usm_device_read_only.cpp @@ -8,6 +8,8 @@ #include +#include + using namespace std; using namespace sycl; @@ -24,7 +26,22 @@ int main(int argc, char *argv[]) { // CHECK: ---> urUSMSharedAlloc // CHECK-NOT: zeMemAllocShared - free(ptr1, Q); + sycl::usm_allocator allocator_no_prop{Q}; + + auto ptr3 = allocator_no_prop.allocate(1); + // CHECK: ---> urUSMSharedAlloc + // CHECK: zeMemAllocShared + + sycl::usm_allocator allocator_prop{ + Q, {sycl::ext::oneapi::property::usm::device_read_only{}}}; + + auto ptr4 = allocator_prop.allocate(1); + // CHECK: ---> urUSMSharedAlloc + // CHECK-NOT: zeMemAllocShared + + allocator_prop.deallocate(ptr4, 1); + allocator_no_prop.deallocate(ptr3, 1); free(ptr2, Q); + free(ptr1, Q); return 0; } diff --git a/sycl/test-e2e/USM/properties.cpp b/sycl/test-e2e/USM/properties.cpp new file mode 100644 index 0000000000000..746a33cfc8d0a --- /dev/null +++ b/sycl/test-e2e/USM/properties.cpp @@ -0,0 +1,15 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out + +#include +#include + +int main() { + sycl::queue q; + + // Ensure properties are supported when constructing the allocator: + sycl::usm_allocator allocator{ + q, + {sycl::ext::oneapi::property::usm::device_read_only{}, + sycl::ext::intel::experimental::property::usm::buffer_location{1}}}; +}