-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Implement accessor iterator #6815
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] Implement accessor iterator #6815
Conversation
Added base type for implementing accessor iterators. Implemented `accessor::begin()` and `accessor::end()` methods.
_MLinearCurrent = _MLinearEnd; | ||
else | ||
_MLinearCurrent += _N; | ||
_MCurrent = __delinearizeIndex(_MLinearCurrent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a test checking the generated LLVM IR and/or target assembly to ensure the compiler toolchain can generate it efficiently (i.e. without doing division).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure that we can add a test which checks for optimized LLVM IR, because some optimizations are done by low-level runtimes and I doubt that such test would be reliable.
We also synced offline and there is a generic comment that we shouldn't pay the price of handling ranged accessors with we are dealing with non-ranged accessors. The latter should be as much as possible close to a plain pointer. I have an idea how it can be done, I will post an update to the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rewritten the implementation, so it is now should be as cheap as possible for non-ranged accessors, see ba45577
Now iterators for non-ranged accessors should be almost equal to plain pointers and only iterator dereference for a ranged accessor is a costly operation which requires various calculations including division.
This is a prepartion commit for when the iterator won't hold a pointer to an accessor at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks solid, well documented, and thoroughly tested. However, I am a little on the fence about the use of reserved identifiers before we conclude on it in #2981. Granted the SYCL subproject regrettably isn't very consistent in naming, having some parts using reserved names just adds to it.
: _MDataPtr(_DataPtr) { | ||
constexpr int _XIndex = _Dimensions - 1; | ||
constexpr int _YIndex = _Dimensions - 2; | ||
(void)_YIndex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very much a nit, but I would prefer we lean into using std::ignore
for these situations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, looking at cppreference I don't quite understand how exactly should I use it in here.
From what I understand std::ignore
simply defines a custom operator=
, which allows to silence the warning, but those values here are not always ignored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should just be something like
(void)_YIndex; | |
std::ignore = _YIndex; |
} | ||
|
||
__accessor_iterator &operator++() { | ||
if (_MLinearId < _MEnd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for having all these tests?
I guess that it will diminish the performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for having all these tests?
See my reply to your other comment. Basically, the reasoning is quite weak and we should probably indeed remove those checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the implementation in 8e2db4e
} | ||
{ | ||
auto It = accessor.end(); | ||
// Check that It can't be incremented past end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it in the SYCL specification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is neither a part of SYCL specification nor it is a part of C++ specification. This is a test for an implementation detail. Essentially, C++ says that decrementing past .begin()
or incrementing past .end()
is a UB. By some reason, I decided to make this UB more user-friendly.
I agree that it is not strictly necessary and it makes sense to remove associated checks from the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the test and related parts of the implementation in 8e2db4e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your motivation.
But UB in C/C++ are not there to annoy the user but to allow bare-metal speed when needed. At the end the goal is not to have UB anyway and less speed. :-)
Safe users or coding rules can avoid the use of pointers and iterators and use std::span
, std::ranges
, etc.
Ok, unless that discussion is concluded I reverted back to using regular non-reserved identifiers in a6effbb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Added base type for implementing accessor iterators.
Implemented
accessor::begin()
andaccessor::end()
methods.