Is it possible that give all the SYCL runtime object partial order operators?
There are cases that we need to know partial order of SYCL object to make it into certain container. So is it possible to define operator < for sycl::queue, sycl::event, etc.
What's the use case for storing them in containers? Why is that solution better than alternatives and therefore important to support?
We are dealing with DL frameworks and they integrated equivalent objects (device, event, etc.) in C handlers hence integers. They actually do sorting them in containers, as example, for deciding which device allocation cache to be used or to be evicted.
If we want to do a code transform with minimum changes, it'll be convenient to have a partial order defined on SYCL objects since handlers have it naturally. Alternatively, we do another round of wrapping, add another level of indirection, given SYCL runtime already has an indirection, it'll be a little slower. And it hard to do right, like sycl::queue pointer can be different but the underlining queue_impl could be the same.
I don't know how to define 'importance' on this matter since I don't know how important does it take to add the interfaces. So I ask is it possible to add it and why haven't done it in the original ones.
why haven't done it in the original ones.
I think that the main answers to that are:
- requested operators are not required by the spec and we had no need to implement them (neither as an extension nor as an implementation detail)
- it is unclear how to define ordering rules for those objects. For example, for
queue: what would define whether or not one queue is<than another: amount of devices in an associated context? amount of commands previously submitted? an in-memory address of an underlying backend handler?
Alternatively, we do another round of wrapping, add another level of indirection, given SYCL runtime already has an indirection, it'll be a little slower.
Perhaps you could define an operator< as a free function without introducing an extra level of indirection? godbolt example
class context {
};
bool operator<(const context &a, const context &b) {
return &a < &b;
}
int main() {
context a, b;
return a < b;
}
We have internally at Khronos https://gitlab.khronos.org/sycl/Specification/-/issues/306 to track this. It should land in SYCL Next at some point in the future.
@CaoZhongZ, it looks like the question was answered and I don't think that we can do anything on the implementation side for now. Therefore, I suggest that we close this issue and wait until the spec is updated to implement the requested functionality - do you have any objections?
😯Sure.