Skip to content

Conversation

@briancylui
Copy link
Contributor

@briancylui briancylui commented Aug 10, 2018

After all active SSE intrinsics have been implemented and tested for correctness and speed, this PR asks to make all external SseUtils call sites call CpuMathUtils instead. This would allow us to obtain a baseline performance of C# hardware intrinsics APIs in a future PR.

cc: @safern @danmosemsft @eerhardt @tannergooding

@briancylui briancylui changed the title Changed SseUtils call sites to call CpuMathUtils instead Change SseUtils call sites to call CpuMathUtils instead Aug 10, 2018
@briancylui
Copy link
Contributor Author

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 SseUtils call sites call CpuMathUtils instead. This would allow us to obtain a baseline performance of C# hardware intrinsics APIs in a future PR.

This PR is now ready for review.

@safern
Copy link
Member

safern commented Aug 10, 2018

It seems like you missed 2 instances:

Contracts.Assert(mat.Items.CbAlign == SseUtils.CbAlign);

Contracts.Assert(vec.Items.CbAlign == SseUtils.CbAlign);

@briancylui
Copy link
Contributor Author

@safern Seems that those two SseUtils references are wrapped around by #if and #endif that are only used in Debug. Thank you for the nice catch - now fixed!

{
public static partial class CpuMathUtils
{
public const int CbAlign = 16;
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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:

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;

@briancylui
Copy link
Contributor Author

test VSTS: public-CI please

@briancylui
Copy link
Contributor Author

test VSTS: public-CI

{
public static partial class CpuMathUtils
{
public const int SseCbAlign = 16;
Copy link
Member

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

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 also want to know what CbAlign stands for. I was following the existing code:

public static class SseUtils
{
public const int CbAlign = 16;

Copy link
Contributor Author

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:

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

Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Member

@tannergooding tannergooding left a 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.

@briancylui
Copy link
Contributor Author

Incorporated naming suggestions in the latest commits. All 5 checks have passed with two reviewers' approvals.

@safern
Copy link
Member

safern commented Aug 13, 2018

Merging since naming has been fixed and if @eerhardt has another suggestion, since he is out, could be done in a follow up.

@safern safern merged commit e77f24e into dotnet:master Aug 13, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants