-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Update input arguments in CpuMath files #1021
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
@@ -24,757 +24,757 @@ public static partial class CpuMathUtils | |||
public static int GetVectorAlignment() | |||
=> Avx.IsSupported ? Vector256Alignment : (Sse.IsSupported ? Vector128Alignment : FloatAlignment); | |||
|
|||
public static void MatTimesSrc(bool tran, bool add, AlignedArray mat, AlignedArray src, AlignedArray dst, int crun) | |||
public static void MatTimesSource(bool transpose, bool add, AlignedArray mat, AlignedArray source, AlignedArray destination, int crun) |
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.
mat
here stands for matrix
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.
Oh, thanks! I'll update that.
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.
crun
is also attempting to indicate how many columns are in each row of the matrix. We could probably have a better name here.... stride
is the term I'm more generally familiar with.
} | ||
|
||
private static void Scale(float a, Span<float> dst) | ||
private static void Scale(float source, Span<float> destination) |
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.
These names aren't really correct. The source
parameter isn't really the source of the information. It is the amount to scale the dst
values.
Maybe a
should just be renamed to scale
?
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.
Or possibly value
?
Similar comment for the Add
method above.
In reply to: 220239713 [](ancestors = 220239713)
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 think value
sounds good. I'll update that.
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void MatTimesSrc(bool tran, bool add, AlignedArray mat, int[] rgposSrc, AlignedArray srcValues, | ||
int posMin, int iposMin, int iposLim, AlignedArray dst, int crun) | ||
public static void MatrixTimesSource(bool transpose, bool add, AlignedArray mat, int[] rgpossource, AlignedArray sourceValues, |
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.
We shouldn't need the rg
prefix, we can just use posSource
.
This mat
(and most of the others in the file) also stands for matrix
public static void MatTimesSrc(bool tran, bool add, AlignedArray mat, int[] rgposSrc, AlignedArray srcValues, | ||
int posMin, int iposMin, int iposLim, AlignedArray dst, int crun) | ||
public static void MatrixTimesSource(bool transpose, bool add, AlignedArray mat, int[] rgpossource, AlignedArray sourceValues, | ||
int posMin, int iposMin, int iposLim, AlignedArray destination, int stride) |
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 believe the Lim
here stands for Limit
} | ||
|
||
private static void Scale(float a, Span<float> src, Span<float> dst) | ||
private static void Scale(float a, Span<float> source, Span<float> destination) |
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.
a
can be value
// dst[i] = a * (dst[i] + b) | ||
public static void ScaleAdd(float a, float b, float[] dst, int count) | ||
// destination[i] = a * (destination[i] + b) | ||
public static void ScaleAdd(float a, float b, float[] destination, int count) |
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:
a
=>scale
b
=>addend
?
} | ||
} | ||
} | ||
|
||
public static void MulElementWise(float[] src1, float[] src2, float[] dst, int count) | ||
public static void MulElementWise(float[] source1, float[] source2, float[] destination, int count) |
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.
left
and right
are probably better names here
This is a great improvement and helps increase readability immensely. Thanks for the work @jwood803 |
Glad to help @tannergooding! I hope to do more in the future 😄 |
@jwood803 - are there more updates coming? Or can the |
@eerhardt Good question. I can go ahead and remove the WIP and if you or @tannergooding has any more feedback, I can just make changes then. |
@@ -24,757 +24,757 @@ public static partial class CpuMathUtils | |||
public static int GetVectorAlignment() | |||
=> Avx.IsSupported ? Vector256Alignment : (Sse.IsSupported ? Vector128Alignment : FloatAlignment); | |||
|
|||
public static void MatTimesSrc(bool tran, bool add, AlignedArray mat, AlignedArray src, AlignedArray dst, int crun) | |||
public static void MatrixTimesSource(bool transpose, bool add, AlignedArray matrix, AlignedArray source, AlignedArray destination, int stride) |
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 is a partial class, and the .netstandard.cs
side of the partial class needs to be updated as well.
BTW - are you compiling for .NET Core 3.0? I assume there are callers of this function that need to be updated. I have 3.0
building instructions in this soon to be merged PR: #1032
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.
Thanks, @eerhardt! I totally didn't realize it was a partial class. The netstandard
class has been updated as well as the callers of the functions that were changed.
I'll mess with the .NET Core 3.0 part to make sure all that looks good.
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.
@eerhardt Tried to compile for .NET Core 3.0 and, with the VS route, it seemed that everything in the CpuMath
library fails to compile.
I also tried through the command line and would get this error:
I'm sure I probably did a step wrong so I'll continue to mess with it, but I figured I'd give an update.
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.
Something is eating your /
in /p:Configuration=Release-Intrinsics
on the command line. What shell are you using? CMD? Powershell?
try specifying it with a -
instead: -p:Configuration=Release-Intrinsics
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.
That worked better! I use bash on Cmder for my terminal.
It looks like it builds for the most part, but I do get the error below. Even after running dotnet restore
it still comes up. I wouldn't think it has anything to do with these changes, though.
C:\Users\jwood\Documents\Code\GitHub\machinelearning\Tools\dotnetcli\sdk\3.0.100-alpha1-009632\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(202,5):
error NETSDK1004: Assets file 'C:\Users\jwood\Documents\Code\GitHub\machinelearning\bin\obj\AnyCPU.Release-Intrinsics\Microsoft.ML.CpuMath\project.assets.json' not found.
Run a NuGet package restore to generate this file. [C:\Users\jwood\Documents\Code\GitHub\machinelearning\src\Microsoft.ML.CpuMath\Microsoft.ML.CpuMath.csproj]
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.
Do you have my latest code: #1032? That should solve that problem.
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.
Great catch, @eerhardt! Turns out I did miss some updates from a previous change. Thanks!
@@ -240,7 +240,7 @@ private string GetBuildPrefix() | |||
#endif | |||
} | |||
|
|||
[Fact(Skip = "Execute this test if you want to regenerate ep-list and _manifest.json")] | |||
[Fact] |
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 checked in.
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.
Whoops! I'll revert that.
|
||
public static float L2DistSquared(float[] a, float[] b, int count) => SseUtils.L2DistSquared(a, b, count); | ||
public static float L2DistSquared(float[] value, float[] b, int count) => SseUtils.L2DistSquared(value, b, count); |
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.
b
should be updated as well. Similar comment throughout this code file.
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.
Actually, I don't think value
makes sense for the first parameter either.
In reply to: 221718385 [](ancestors = 221718385)
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.
Would source
and destination
make sense there?
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.
Not for the specific method, no. This is computing the distance between two arrays and returning a float
. So there isn't a destination
array.
left
and right
would make sense. Or a
and b
... but I think you are changing it to use left
and right
elsewhere, so let's be consistent.
@jwood803 do you have time to rebase and resolve conflicts? |
@jwood803 depending, it might be easier to repeat the search and replace in some cases. |
@tannergooding can you help @jwood803 this PR get closed out one way or another? |
Apologies for the long delay everyone. I did the merge and hopefully, all will turn out ok, but I'll update any issues that may arise from it. Thanks for the patience, everyone! |
@jwood803 - it looks like your merge wasn't successful -
Can you fix the build errors? |
} | ||
|
||
private ValueGetter<VBuffer<float>> GetterFromFloatType(IRow input, int iinfo) | ||
{ | ||
|
||
var getSrc = input.GetGetter<float>(_srcCols[iinfo]); |
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.
Can you revert the unnecessary blank lines being added here?
src/Microsoft.ML.CpuMath/Thunk.cs
Outdated
@@ -92,6 +92,7 @@ internal static unsafe class Thunk | |||
public static extern void ZeroMatrixItemsCore(float* pd, int c, int ccol, int cfltRow, /*const*/ int* pindices, int cindices); | |||
|
|||
[DllImport(NativePath), SuppressUnmanagedCodeSecurity] | |||
|
|||
public static extern void SdcaL1UpdateU(float primalUpdate, /*const*/ float* ps, float threshold, float* pd1, float* pd2, int c); |
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.
Can you revert the unnecessary blank line added?
@eerhardt Sorry about that. I'll get those updated. |
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.
@tannergooding can you also review the PR? |
@@ -401,10 +401,10 @@ public static void SdcaL1UpdateDense(float primalUpdate, int count, ReadOnlySpan | |||
} | |||
} | |||
|
|||
public static void SdcaL1UpdateSparse(float primalUpdate, int count, ReadOnlySpan<float> src, ReadOnlySpan<int> indices, float threshold, Span<float> v, Span<float> w) | |||
public static void SdcaL1UpdateSparse(float primalUpdate, int count, ReadOnlySpan<float> source, ReadOnlySpan<int> indices, float threshold, Span<float> v, Span<float> w) |
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 don't know what v
and w
stand for throughout, but in some future PR someone might want to make them more descriptive...
|
||
public static void Add(float a, Span<float> dst) => SseUtils.Add(a, dst); | ||
public static void Add(float value, Span<float> destination) => SseUtils.Add(value, destination); |
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.
When something is being added it seems like sometimes we call it value
and sometimes addend
. And if we want to make them consistently addend
maybe value
should be more specific in other cases, such as scale
. Eg.,
Add(float addend, Span<float> destination)
ScaleAdd(float scale, float addend, Span<float> destination)
AddScale(float scale, ReadOnlySpan<float> addends, Span<float> destination, int count)
But I defer to @tannergooding as I haven't given this previous thought and I don't know what the convention is. Just as long as we're consistent.
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 don't think that should stop merging this PR though.
Seems fine but I'll let @tannergooding sign off. |
ping @tannergooding for review. |
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.
LGTM
Much thanks to @eerhardt and @tannergooding for all the help on this PR! 😄 |
Fix for #824
Marked as WIP since this may have more updates to come.
@briancylui @eerhardt @tannergooding Feel free to let me know if anything already done should be changed.