-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Change SseUtils call sites to call CpuMathUtils instead #672
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
Conversation
|
All 5 checks have passed for this new PR submitted today. After all active SSE intrinsics have been implemented and tested for correctness and speed, this PR asks to make all external This PR is now ready for review. |
|
It seems like you missed 2 instances:
|
|
@safern Seems that those two |
| { | ||
| public static partial class CpuMathUtils | ||
| { | ||
| public const int CbAlign = 16; |
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.
This shouldn’t be here. This is Sse specific, but CpuMathUtils should be agnostic of the ISA.
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.
Maybe if you name it ‘SseCbAlign’, that would work.
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.
Agree and thanks! The only current call site of CbAlign is in this file:
machinelearning/src/Microsoft.ML.Transforms/RffTransform.cs
Lines 24 to 29 in b51d9f9
| namespace Microsoft.ML.Runtime.Data | |
| { | |
| using CpuUtils = SseUtils; | |
| public sealed class RffTransform : OneToOneTransformBase | |
| { |
where Line 26 should be changed to
using CpuMathUtils;, and the bunch of CpuUtils.CbAlign in subsequent lines should be changed to CpuMathUtils.SseCbAlign for the moment. While this change may expose the ISA-specific element (the Sse prefix of SseCbAlign) out of CpuMathUtils, I think it's good for now.
In the future when we also support AVX, should I change public const int CbAlign = 16; to something like the code below?
public const int CbAlign = Avx.IsSupported ? 32 : 16;
**OR**
public int GetCbAlign() => Avx.IsSupported ? 32 : 16;
|
test VSTS: public-CI please |
|
test VSTS: public-CI |
| { | ||
| public static partial class CpuMathUtils | ||
| { | ||
| public const int SseCbAlign = 16; |
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 does CbAlign stand for (count of bytes alignment)?
Following .NET Naming Conventions might be desirable...
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 also want to know what CbAlign stands for. I was following the existing code:
machinelearning/src/Microsoft.ML.CpuMath/Sse.cs
Lines 11 to 14 in b51d9f9
| public static class SseUtils | |
| { | |
| public const int CbAlign = 16; | |
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.
After some detective work, the convention seems to stem from AlignedArray.cs:
machinelearning/src/Microsoft.ML.CpuMath/AlignedArray.cs
Lines 19 to 28 in b51d9f9
| public sealed class AlignedArray | |
| { | |
| // Items includes "head" items filled with NaN, followed by _size entries, followed by "tail" | |
| // items, also filled with NaN. Note that _size * sizeof(Float) is divisible by _cbAlign. | |
| // It is illegal to access any slot outsize [_base, _base + _size). This is internal so clients | |
| // can easily pin it. | |
| internal Float[] Items; | |
| private readonly int _size; // Must be divisible by (_cbAlign / sizeof(Float)). | |
| private readonly int _cbAlign; // The alignment in bytes, a power of two, divisible by sizeof(Float). |
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.
Cb normally stands for something like count of bytes.
I would probably rename this to something like Vector128Alignment, or something similar. That makes it clear that it is the alignment for the Vector128<T> type, and follows a "normal" .NET Naming Convention.
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.
Changed the naming of SseCbAlign to Vector128Alignment in the latest commit. Thanks for your suggestion!
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.
Overall LGTM.
I would still consider renaming SseCbAlign before merging.
|
Incorporated naming suggestions in the latest commits. All 5 checks have passed with two reviewers' approvals. |
|
Merging since naming has been fixed and if @eerhardt has another suggestion, since he is out, could be done in a follow up. |
After all active SSE intrinsics have been implemented and tested for correctness and speed, this PR asks to make all external
SseUtilscall sites callCpuMathUtilsinstead. This would allow us to obtain a baseline performance of C# hardware intrinsics APIs in a future PR.cc: @safern @danmosemsft @eerhardt @tannergooding