-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Public API for remaining learners #1901
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,6 @@ | |
|
||
namespace Microsoft.ML.Runtime.Internal.CpuMath | ||
{ | ||
using Float = System.Single; | ||
|
||
/// <summary> | ||
/// This implements a logical array of Floats that is automatically aligned for SSE/AVX operations. | ||
/// To pin and force alignment, call the GetPin method, typically wrapped in a using (since it | ||
|
@@ -24,7 +22,7 @@ internal sealed class AlignedArray | |
// 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. | ||
public Float[] Items; | ||
public 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). | ||
|
@@ -40,12 +38,12 @@ public AlignedArray(int size, int cbAlign) | |
{ | ||
Contracts.Assert(0 < size); | ||
// cbAlign should be a power of two. | ||
Contracts.Assert(sizeof(Float) <= cbAlign); | ||
Contracts.Assert(sizeof(float) <= cbAlign); | ||
Contracts.Assert((cbAlign & (cbAlign - 1)) == 0); | ||
// cbAlign / sizeof(Float) should divide size. | ||
Contracts.Assert((size * sizeof(Float)) % cbAlign == 0); | ||
Contracts.Assert((size * sizeof(float)) % cbAlign == 0); | ||
|
||
Items = new Float[size + cbAlign / sizeof(Float)]; | ||
Items = new float[size + cbAlign / sizeof(float)]; | ||
_size = size; | ||
_cbAlign = cbAlign; | ||
_lock = new object(); | ||
|
@@ -54,15 +52,15 @@ public AlignedArray(int size, int cbAlign) | |
public unsafe int GetBase(long addr) | ||
{ | ||
#if DEBUG | ||
fixed (Float* pv = Items) | ||
Contracts.Assert((Float*)addr == pv); | ||
fixed (float* pv = Items) | ||
Contracts.Assert((float*)addr == pv); | ||
#endif | ||
|
||
int cbLow = (int)(addr & (_cbAlign - 1)); | ||
int ibMin = cbLow == 0 ? 0 : _cbAlign - cbLow; | ||
Contracts.Assert(ibMin % sizeof(Float) == 0); | ||
Contracts.Assert(ibMin % sizeof(float) == 0); | ||
|
||
int ifltMin = ibMin / sizeof(Float); | ||
int ifltMin = ibMin / sizeof(float); | ||
if (ifltMin == _base) | ||
return _base; | ||
|
||
|
@@ -71,9 +69,9 @@ public unsafe int GetBase(long addr) | |
// Anything outsize [_base, _base + _size) should not be accessed, so | ||
// set them to NaN, for debug validation. | ||
for (int i = 0; i < _base; i++) | ||
Items[i] = Float.NaN; | ||
Items[i] = float.NaN; | ||
for (int i = _base + _size; i < Items.Length; i++) | ||
Items[i] = Float.NaN; | ||
Items[i] = float.NaN; | ||
#endif | ||
return _base; | ||
} | ||
|
@@ -96,7 +94,7 @@ private void MoveData(int newBase) | |
|
||
public int CbAlign { get { return _cbAlign; } } | ||
|
||
public Float this[int index] | ||
public float this[int index] | ||
{ | ||
get | ||
{ | ||
|
@@ -110,15 +108,21 @@ public Float this[int index] | |
} | ||
} | ||
|
||
public void CopyTo(Span<Float> dst, int index, int count) | ||
public void CopyTo(Span<float> dst) | ||
{ | ||
Contracts.Assert(dst != null); | ||
Items.AsSpan().CopyTo(dst); | ||
} | ||
|
||
public void CopyTo(Span<float> dst, int index, int count) | ||
{ | ||
Contracts.Assert(0 <= count && count <= _size); | ||
Contracts.Assert(dst != null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double-checking that this is intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must be. I did not touch this code, except Float -> float! In reply to: 243714825 [](ancestors = 243714825) |
||
Contracts.Assert(0 <= index && index <= dst.Length - count); | ||
Items.AsSpan(_base, count).CopyTo(dst.Slice(index)); | ||
} | ||
|
||
public void CopyTo(int start, Span<Float> dst, int index, int count) | ||
public void CopyTo(int start, Span<float> dst, int index, int count) | ||
{ | ||
Contracts.Assert(0 <= count); | ||
Contracts.Assert(0 <= start && start <= _size - count); | ||
|
@@ -127,13 +131,13 @@ public void CopyTo(int start, Span<Float> dst, int index, int count) | |
Items.AsSpan(start + _base, count).CopyTo(dst.Slice(index)); | ||
} | ||
|
||
public void CopyFrom(ReadOnlySpan<Float> src) | ||
public void CopyFrom(ReadOnlySpan<float> src) | ||
{ | ||
Contracts.Assert(src.Length <= _size); | ||
src.CopyTo(Items.AsSpan(_base)); | ||
} | ||
|
||
public void CopyFrom(int start, ReadOnlySpan<Float> src) | ||
public void CopyFrom(int start, ReadOnlySpan<float> src) | ||
{ | ||
Contracts.Assert(0 <= start && start <= _size - src.Length); | ||
src.CopyTo(Items.AsSpan(start + _base)); | ||
|
@@ -143,7 +147,7 @@ public void CopyFrom(int start, ReadOnlySpan<Float> src) | |
// valuesSrc contains only the non-zero entries. Those are copied into their logical positions in the dense array. | ||
// rgposSrc contains the logical positions + offset of the non-zero entries in the dense array. | ||
// rgposSrc runs parallel to the valuesSrc array. | ||
public void CopyFrom(ReadOnlySpan<int> rgposSrc, ReadOnlySpan<Float> valuesSrc, int posMin, int iposMin, int iposLim, bool zeroItems) | ||
public void CopyFrom(ReadOnlySpan<int> rgposSrc, ReadOnlySpan<float> valuesSrc, int posMin, int iposMin, int iposLim, bool zeroItems) | ||
{ | ||
Contracts.Assert(rgposSrc != null); | ||
Contracts.Assert(valuesSrc != null); | ||
|
@@ -202,7 +206,7 @@ public void ZeroItems(int[] rgposSrc, int posMin, int iposMin, int iposLim) | |
// REVIEW: This is hackish and slightly dangerous. Perhaps we should wrap this in an | ||
// IDisposable that "locks" this, prohibiting GetBase from being called, while the buffer | ||
// is "checked out". | ||
public void GetRawBuffer(out Float[] items, out int offset) | ||
public void GetRawBuffer(out float[] items, out int offset) | ||
{ | ||
items = Items; | ||
offset = _base; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.