Skip to content

Conversation

gmlueck
Copy link
Contributor

@gmlueck gmlueck commented Sep 8, 2025

Add a proposed extension specification that allows applications to easily get the index of a device object and to get a device object from its index.

Add a proposed extension specification that allows applications to
easily get the index of a `device` object and to get a `device` object
from its index.
@gmlueck gmlueck requested a review from a team as a code owner September 8, 2025 18:04
class device {
// ...
int ext_oneapi_to_index() const;
static device ext_oneapi_from_index(int index);
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I think ext_oneapi_from_index(i) is a little unnecessary. It is effectively just a "shorthand" for device::get_devices()[i], but not currently actually shorter:

device::ext_oneapi_from_index(i)
device::get_devices()[i]

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 this, but it seemed better to add a pair of APIs to convert back and forth between index and device, rather than just adding a single API to do a one-way conversion. In addition, it is a bit wasteful to construct a std::vector if the user just wants a single element from that vector.

Copy link
Contributor

@steffenlarsen steffenlarsen Sep 11, 2025

Choose a reason for hiding this comment

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

I agree with this, but it seemed better to add a pair of APIs to convert back and forth between index and device, rather than just adding a single API to do a one-way conversion.

Since the API is already talking about the return value being an index into the vector of devices, I am not personally too much against just having the one-way API added here. It is a minor thing, but it is also an additional API to maintain. I suppose we could maybe just reword it to say "Same as calling device::get_devices()[i]" or something along those lines.

In addition, it is a bit wasteful to construct a std::vector if the user just wants a single element from that vector.

That is a good point. I would be tempted to say we would want to do that internally as well, simply to make sure the sets of devices don't suddenly change due to the adapters not making any ordering guarantees, but maybe some implementations could avoid that.

That said, even if we did keep an internal version for book-keeping, the API for get_devices() would return a copy of it, so you are right that it would be wasteful.

Copy link
Contributor

@intel/llvm-gatekeepers please consider merging

Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

LGTM!

@gmlueck
Copy link
Contributor Author

gmlueck commented Sep 12, 2025

@intel/llvm-gatekeepers please consider merging

Yes. @intel/llvm-gatekeepers, I think this is ready to mege.

@aelovikov-intel aelovikov-intel merged commit fe8a292 into intel:sycl Sep 12, 2025
4 checks passed
@gmlueck gmlueck deleted the gmlueck/device-index branch September 12, 2025 15:08
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.

5 participants