Skip to content

[SYCL][ESIMD] Add more compile time checks to rdregion and wrregion API #13158

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
merged 10 commits into from
Apr 25, 2024

Conversation

fineg74
Copy link
Contributor

@fineg74 fineg74 commented Mar 26, 2024

No description provided.

@fineg74 fineg74 marked this pull request as ready for review March 26, 2024 16:23
@fineg74 fineg74 requested a review from a team as a code owner March 26, 2024 16:23
@fineg74
Copy link
Contributor Author

fineg74 commented Mar 28, 2024

AMD/HIP test failures are not related to the change

@fineg74 fineg74 closed this Mar 28, 2024
@fineg74 fineg74 reopened this Mar 28, 2024
@v-klochkov
Copy link
Contributor

I understand this change as ESIMD developer and it is correct, but...
It is a very user-unfriendly fix. It adds extra constraints to the code that could function without harm to the program execution (GPU driver promised to handle correctly (skip) the reads/writes out of esimd register scope).
If there are programs with such bad reads/writes they would fail at compilation with very odd error not giving information about what needs to be fixed.

If add such constraints, then they should be added in a user friendly manner. I.e. at the user's functions calling __esimd_rdregion/wrregion or at the places where the simd_view objects are created to prohibit potential reads/writes beyond simd object scope.

@fineg74
Copy link
Contributor Author

fineg74 commented Apr 15, 2024

I understand this change as ESIMD developer and it is correct, but... It is a very user-unfriendly fix. It adds extra constraints to the code that could function without harm to the program execution (GPU driver promised to handle correctly (skip) the reads/writes out of esimd register scope). If there are programs with such bad reads/writes they would fail at compilation with very odd error not giving information about what needs to be fixed.

If add such constraints, then they should be added in a user friendly manner. I.e. at the user's functions calling __esimd_rdregion/wrregion or at the places where the simd_view objects are created to prohibit potential reads/writes beyond simd object scope.

Yes, originally, these constraints were introduced for emulator that used to crash when read/write out of bounds was performed, but I believe it still has some value as it would allow to uncover some hidden bugs that would be impossible to detect otherwise. I don' have strong opinion about that though.

@@ -209,6 +209,23 @@ auto accessorToPointer(AccessorTy Acc, OffsetTy Offset = 0) {
}
#endif // __ESIMD_FORCE_STATELESS_MEM

template <int N, int M, int VStride, int Width, int Stride>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please write a detailed comment to these 2 functions and their params. Otherwise, it is really difficult (or impossible) to understand what they verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. It is still difficult to understand why the constraint is such: Width == M || ((M / Width) - 1) * VStride + (Width - 1) * Stride < N. It would help a lot if the pseudo-code would be copied from __esimd_rdregion/wrregion to the commend of these check functions, e.g.;
// This intrinsic computes a vector Result:
//
// \code{.cpp}
// uint16_t EltOffset = Offset / sizeof(T);
// assert(Offset % sizeof(T) == 0);
//
// int NumRows = M / Width;
// assert(M % Width == 0);
//
// int Index = 0;
// for (int i = 0; i < NumRows; ++i) {
// for (int j = 0; j < Width; ++j) {
// Result[Index++] = Input[i * VStride + j * Stride +
// EltOffset];
// }
// }
// \endcode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do the same for __esimd_wrregion please?
Perhaps, fix the comment in both places too - comment does not say that the write is skipped if mask is 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, for confusion. the pseudo-code for __esimd_wrregion is correct. Please just copy it to check function here.
The __esimd_rdregion does not have a mask operand, thus is is all right in the pseudo-code for rdregion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@v-klochkov v-klochkov merged commit e1119d9 into intel:sycl Apr 25, 2024
@fineg74 fineg74 deleted the regionChecks branch April 26, 2024 02:10
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.

2 participants