Skip to content

Commit a5862bc

Browse files
[SYCL] Fixes for usm_allocator properties
* Fix `verifyUSMAllocatorProperties` to allow supported properties * No need to specialize `is_property<...>` for USM properties - `std::base_of_v<>`-based implementation covers that.
1 parent d6eb331 commit a5862bc

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

sycl/include/sycl/ext/intel/experimental/usm_properties.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,10 @@ class buffer_location
3939
uint64_t MLocation;
4040
};
4141

42+
// If new properties are added here, update `verifyUSMAllocatorProperties` to
43+
// include them!
44+
4245
} // namespace intel::experimental::property::usm
4346
} // namespace ext
44-
45-
template <>
46-
struct is_property<ext::oneapi::property::usm::device_read_only>
47-
: std::true_type {};
48-
49-
template <>
50-
struct is_property<ext::intel::experimental::property::usm::buffer_location>
51-
: std::true_type {};
52-
5347
} // namespace _V1
5448
} // namespace sycl

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,22 @@ void release_from_device_copy(const void *Ptr, const queue &Queue) {
644644
} // namespace ext::oneapi::experimental
645645

646646
__SYCL_EXPORT void verifyUSMAllocatorProperties(const property_list &PropList) {
647-
auto NoAllowedPropertiesCheck = [](int) { return false; };
648-
detail::PropertyValidator::checkPropsAndThrow(
649-
PropList, NoAllowedPropertiesCheck, NoAllowedPropertiesCheck);
647+
auto DataLessCheck = [](int Kind) {
648+
switch (Kind) {
649+
case detail::DeviceReadOnly:
650+
return true;
651+
}
652+
return false;
653+
};
654+
auto WithDataCheck = [](int Kind) {
655+
switch (Kind) {
656+
case detail::PropWithDataKind::AccPropBufferLocation:
657+
return true;
658+
}
659+
return false;
660+
};
661+
detail::PropertyValidator::checkPropsAndThrow(PropList, DataLessCheck,
662+
WithDataCheck);
650663
}
651664

652665
} // namespace _V1

sycl/test-e2e/USM/properties.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
3+
4+
#include <sycl/ext/intel/experimental/usm_properties.hpp>
5+
#include <sycl/usm/usm_allocator.hpp>
6+
7+
int main() {
8+
sycl::queue q;
9+
10+
// Ensure properties are supported when construction the allocator:
11+
sycl::usm_allocator<int, sycl::usm::alloc::shared> allocator{
12+
q,
13+
{sycl::ext::oneapi::property::usm::device_read_only{},
14+
sycl::ext::intel::experimental::property::usm::buffer_location{1}}};
15+
}

0 commit comments

Comments
 (0)