Skip to content

[SYCL] Small patch on annotated USM allocation #11801

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 2 commits into from
Nov 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ aligned_alloc_annotated(size_t alignment, size_t count,
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
"Unknown USM allocation kind was specified.");

void *rawPtr = sycl::aligned_alloc(
combine_align(alignment, alignFromPropList), count * sizeof(T),
syclDevice, syclContext, kind, usmPropList);
return annotated_ptr<T, propertyListB>(static_cast<T *>(rawPtr));
size_t combinedAlign = combine_align(alignment, alignFromPropList);
T *rawPtr = sycl::aligned_alloc<T>(combinedAlign, count, syclDevice,
syclContext, kind, usmPropList);
return annotated_ptr<T, propertyListB>(rawPtr);
}

template <typename propertyListA = detail::empty_properties_t,
Expand Down
25 changes: 15 additions & 10 deletions sycl/test-e2e/Annotated_usm/annotated_usm_align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ template <typename T> void testAlign(sycl::queue &q, unsigned align) {
// 2),
// nullptr is returned
,
[&]() { return TDevice(q, properties{alignment<5>}); },
[&]() { return TDevice(dev, Ctx, properties{alignment<10>}); },
[&]() { return THost(q, properties{alignment<25>}); },
[&]() { return THost(Ctx, properties{alignment<50>}); },
[&]() { return TDevice(q, properties{alignment<75>}); },
[&]() { return TDevice(dev, Ctx, properties{alignment<100>}); },
[&]() { return THost(q, properties{alignment<205>}); },
[&]() { return THost(Ctx, properties{alignment<500>}); },
[&]() {
return TAnnotated(q, alloc::device, properties{alignment<127>});
},
Expand All @@ -405,18 +405,23 @@ template <typename T> void testAlign(sycl::queue &q, unsigned align) {
// alignment
// argument is not a power of 2, the result is nullptr
,
[&]() { return ATDevice(3, q); },
[&]() { return ATDevice(7, dev, Ctx); },
[&]() { return ATHost(7, q); },
[&]() { return ATHost(9, Ctx); },
[&]() { return ATAnnotated(15, q, alloc::device); },
[&]() { return ATAnnotated(17, dev, Ctx, alloc::host); }});
[&]() { return ATDevice(65, q); },
[&]() { return ATDevice(70, dev, Ctx); },
[&]() { return ATHost(174, q); },
[&]() { return ATHost(299, Ctx); },
[&]() { return ATAnnotated(550, q, alloc::device); },
[&]() { return ATAnnotated(1700, dev, Ctx, alloc::host); }});
}

struct alignas(64) MyStruct {
int x;
};

int main() {
sycl::queue q;
testAlign<char>(q, 4);
testAlign<int>(q, 128);
testAlign<std::complex<double>>(q, 4);
testAlign<MyStruct>(q, 4);
return 0;
}