Skip to content
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

raise exception in malloc when device does not supports usm #10348

Conversation

pwisniewskimobica
Copy link
Contributor

Due to issue #9513
I made changes where alignedAlloc method throws exception when device does not supports usm

@al42and
Copy link
Contributor

al42and commented Jul 13, 2023

Ideally, should also check malloc_host:

Throws a synchronous exception with the errc::feature_not_supported error code if no device in syclContext has aspect::usm_host_allocations.

@@ -232,6 +232,11 @@ void *alignedAllocInternal(size_t Alignment, size_t Size,
void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
const device &Dev, alloc Kind, const property_list &PropList,
const detail::code_location &CodeLoc) {
if (Dev.has(sycl::aspect::usm_device_allocations) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on Kind, we should check either usm_device_allocations or usm_shared_allocations. I doubt there are relevant devices with one but not the other, but the spec says what the spec says.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@al42and Thanks for that!
All your remarks I just applied in newest commit.
Please take a look

@pwisniewskimobica pwisniewskimobica temporarily deployed to aws July 14, 2023 10:53 — with GitHub Actions Inactive
@pwisniewskimobica pwisniewskimobica temporarily deployed to aws July 14, 2023 11:33 — with GitHub Actions Inactive
// feature_not_supported exception
bool raiseUsmException = true;
for (auto device : Ctxt.get_devices()) {
if (device.has(sycl::aspect::usm_device_allocations)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (device.has(sycl::aspect::usm_device_allocations)) {
if (device.has(sycl::aspect::usm_host_allocations)) {

Also, I think it might be slightly more concise if std::any_of / std::none_of is used, but that's a matter of taste?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for std::none_of; it gets rid of the extra auxiliary variable

// if no device in context has spect::usm_host_allocations then raise
// feature_not_supported exception
bool raiseUsmException = true;
for (auto device : Ctxt.get_devices()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
for (auto device : Ctxt.get_devices()) {
for (const auto& device : Ctxt.get_devices()) {

sycl::make_error_code(sycl::errc::feature_not_supported),
"usm not supported");
} else if (Kind == alloc::host &&
Dev.has(sycl::aspect::usm_host_allocations) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Dev.has(sycl::aspect::usm_host_allocations) == false) {
!Dev.has(sycl::aspect::usm_host_allocations)) {

sycl::make_error_code(sycl::errc::feature_not_supported),
"usm not supported");
} else if (Kind == alloc::shared &&
Dev.has(sycl::aspect::usm_shared_allocations) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Dev.has(sycl::aspect::usm_shared_allocations) == false) {
!Dev.has(sycl::aspect::usm_shared_allocations)) {

@@ -232,6 +246,23 @@ void *alignedAllocInternal(size_t Alignment, size_t Size,
void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
const device &Dev, alloc Kind, const property_list &PropList,
const detail::code_location &CodeLoc) {
if (Kind == alloc::device &&
Dev.has(sycl::aspect::usm_device_allocations) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Dev.has(sycl::aspect::usm_device_allocations) == false) {
!Dev.has(sycl::aspect::usm_device_allocations)) {

raiseUsmException = false;
}
}
if (raiseUsmException == true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (raiseUsmException == true) {
if (raiseUsmException) {

@@ -41,6 +41,20 @@ namespace usm {
void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
alloc Kind, const property_list &PropList,
const detail::code_location &CodeLoc) {
// if no device in context has spect::usm_host_allocations then raise
// feature_not_supported exception
bool raiseUsmException = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable names introduced are not consistent with the surrounding convention

// feature_not_supported exception
bool raiseUsmException = true;
for (auto device : Ctxt.get_devices()) {
if (device.has(sycl::aspect::usm_device_allocations)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for std::none_of; it gets rid of the extra auxiliary variable

Copy link
Contributor

This pull request is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be automatically closed in 30 days.

@github-actions github-actions bot added the Stale label Sep 15, 2024
Copy link
Contributor

This pull request was closed because it has been stalled for 30 days with no activity.

@github-actions github-actions bot closed this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants