Skip to content
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
12 changes: 3 additions & 9 deletions sycl/include/sycl/ext/intel/experimental/usm_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ext::oneapi::property::usm::device_read_only>
: std::true_type {};

template <>
struct is_property<ext::intel::experimental::property::usm::buffer_location>
: std::true_type {};

} // namespace _V1
} // namespace sycl
19 changes: 16 additions & 3 deletions sycl/source/detail/usm/usm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion sycl/test-e2e/Adapters/level_zero/usm_device_read_only.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <sycl/ext/oneapi/experimental/annotated_usm/alloc_shared.hpp>

#include <sycl/usm/usm_allocator.hpp>

using namespace std;
using namespace sycl;

Expand All @@ -24,7 +26,22 @@ int main(int argc, char *argv[]) {
// CHECK: ---> urUSMSharedAlloc
// CHECK-NOT: zeMemAllocShared

free(ptr1, Q);
sycl::usm_allocator<int, sycl::usm::alloc::shared> allocator_no_prop{Q};

auto ptr3 = allocator_no_prop.allocate(1);
// CHECK: ---> urUSMSharedAlloc
// CHECK: zeMemAllocShared

sycl::usm_allocator<int, sycl::usm::alloc::shared> 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;
}
15 changes: 15 additions & 0 deletions sycl/test-e2e/USM/properties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out

#include <sycl/ext/intel/experimental/usm_properties.hpp>
#include <sycl/usm/usm_allocator.hpp>

int main() {
sycl::queue q;

// Ensure properties are supported when constructing the allocator:
sycl::usm_allocator<int, sycl::usm::alloc::shared> allocator{
q,
{sycl::ext::oneapi::property::usm::device_read_only{},
sycl::ext::intel::experimental::property::usm::buffer_location{1}}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some E2E tests for these properties (see for example Adapters/level_zero/usm_device_read_only.cpp and USM/buffer_location.cpp). Could these get some test cases with the allocator as well? Primarily I want to make sure the properties are being passed correctly to the allocations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the device_read_only part, but the buffer_location test doesn't verify anything (and is poorly written) and that is an FPGA extension, and we've deprecated whole FPGA support anyway.

}