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

[SYCL] Make ONEAPI_DEVICE_SELECTOR reject an empty string #12851

Merged
merged 4 commits into from
Mar 4, 2024

Conversation

uditagarwal97
Copy link
Contributor

@uditagarwal97 uditagarwal97 commented Feb 28, 2024

ONEAPI_DEVICE_SELECTOR="" causes SYCL runtime to silently not select/initialize any device at all. This PR makes SYCL runtime to throw an error when input to ONEAPI_DEVICE_SELECTOR is null.

@uditagarwal97 uditagarwal97 marked this pull request as ready for review February 28, 2024 19:04
@uditagarwal97 uditagarwal97 requested a review from a team as a code owner February 28, 2024 19:04
Comment on lines 2 to 3
// ONEAPI_DEVICE_SELECTOR, when called with an empty string, should be
// treated in the same manner when ONEAPI_DEVICE_SELECTOR is not set.
Copy link
Contributor

Choose a reason for hiding this comment

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

What does documentation say? Should we update it as well? I think raising an exception would be fine too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also wonder if this is the right behavior. I think a strict reading of the BNF grammar in the documentation says that this should be an error. I think the grammar requires at least one term in the expression string.

I think you could also make an argument that the current behavior is correct. It does sort of make sense that setting ONEAPI_DEVICE_SELECTOR to an empty string would cause no devices to be selected. (I.e. calling device::get_devices would return an empty vector.)

I think both of these choices (error or select no devices) would make more sense than treating this the same as having ONEAPI_DEVICE_SELECTOR unset.

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently OpenMP ignore ONEAPI_DEVICE_SELECTOR if it is set to null

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 now think it would be better to throw a meaningful exception instead of not selecting any device at all.

@RaviNarayanaswamy if not a major change, could we update OpenMP to also throw an error on ONEAPI_DEVICE_SELECTOR=""? I could do the same in SYCL runtime.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does DPC++ throw an error for other env variables if they are set to NULL?

Choose a reason for hiding this comment

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

The behavior of OpenMP and SYCL in this case should be identical to avoid many problems.

Currently OpenMP ignore ONEAPI_DEVICE_SELECTOR if it is set to null

And what about space?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zettai-reido Both OpenMP and DPC++ throws a parsing error on ONEAPI_DEVICE_SELECTOR=" " (space)

Target LEVEL_ZERO RTL --> Loaded library 'libomptarget.sycl.wrap.so':
terminate called after throwing an instance of 'sycl::_V1::exception'
  what():  ONEAPI_DEVICE_SELECTOR parsing error. Backend is required but missing from " "
Aborted (core dumped)

Copy link
Contributor

Choose a reason for hiding this comment

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

Openmp error is not during parsing. It is abort due to sycl not providing device list when asked for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RaviNarayanaswamy You are right. I looked at OpenMP's parsing of ONEAPI_DEVICE_SELECTOR and it does not throw when the value of ONEAPI_DEVICE_SELECTOR is illegal (like "", " ", "a:a", "a:a;a:a", etc), instead it just ignores it. This is different from how it's done in DPC++. OpenMP's parsing of ONEAPI_DEVICE_SELECTOR also doesn't take into account negated filters (like !opencl). Although, I'm not very familiar with the interactions between OpenMP plugins and SYCL runtime, IMO, we should align OpenMP's ONEAPI_DEVICE_SELECTOR parsing with that of DPC++, to prevent issues like this in future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes OpenMP and DPC++ should have used the same code. Unfortunately OpenMP could not use DPC++ implementation as it was integrated into sycl. I will change OpenMP to report error if the ONEAPI_DEVICE_SELECTOR is not valid instead of silently ignoring it. Can you open a JIRA for this.
Hopefully the parsing of ONEAPI_DEVICE_SELECTOR will be done in UR when we switch to using it.

@uditagarwal97
Copy link
Contributor Author

@intel/llvm-gatekeepers The PR is ready!

@againull againull merged commit 4b4ab14 into intel:sycl Mar 4, 2024
12 checks passed
@uditagarwal97 uditagarwal97 deleted the fix_ods_empty_input branch March 21, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants