Skip to content

[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

Merged

Conversation

AlexeySachkov
Copy link
Contributor

Added base type for implementing accessor iterators.
Implemented accessor::begin() and accessor::end() methods.

Added base type for implementing accessor iterators.
Implemented `accessor::begin()` and `accessor::end()` methods.
_MLinearCurrent = _MLinearEnd;
else
_MLinearCurrent += _N;
_MCurrent = __delinearizeIndex(_MLinearCurrent);
Copy link
Contributor

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).

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'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.

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'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.
@AlexeySachkov AlexeySachkov changed the title [WIP] [SYCL] Implement accessor iterator [SYCL] Implement accessor iterator Oct 4, 2022
@AlexeySachkov AlexeySachkov marked this pull request as ready for review October 4, 2022 13:38
@AlexeySachkov AlexeySachkov requested a review from a team as a code owner October 4, 2022 13:38
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.

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

Suggested change
(void)_YIndex;
std::ignore = _YIndex;

}

__accessor_iterator &operator++() {
if (_MLinearId < _MEnd)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@AlexeySachkov
Copy link
Contributor Author

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.

Ok, unless that discussion is concluded I reverted back to using regular non-reserved identifiers in a6effbb

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!

@AlexeySachkov AlexeySachkov merged commit c7b1a00 into intel:sycl Oct 7, 2022
@AlexeySachkov AlexeySachkov deleted the private/asachkov/accessor-iterator branch May 22, 2024 09:51
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