Update input arguments in CpuMath files#1021
Conversation
| => 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.
mat here stands for matrix
There was a problem hiding this comment.
Oh, thanks! I'll update that.
There was a problem hiding this comment.
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.
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.
Or possibly value?
Similar comment for the Add method above.
In reply to: 220239713 [](ancestors = 220239713)
There was a problem hiding this comment.
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.
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.
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) |
| // 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.
Maybe:
a=>scaleb=>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.
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. |
| => 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.
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.
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.
@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.
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.
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.
Do you have my latest code: #1032? That should solve that problem.
There was a problem hiding this comment.
Great catch, @eerhardt! Turns out I did miss some updates from a previous change. Thanks!
| } | ||
|
|
||
| [Fact(Skip = "Execute this test if you want to regenerate ep-list and _manifest.json")] | ||
| [Fact] |
There was a problem hiding this comment.
Whoops! I'll revert that.
| public static float DotProductSparse(float[] value, int offset, float[] b, int[] indices, int count) => SseUtils.DotProductSparse(value, offset, b, indices, count); | ||
|
|
||
| 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.
b should be updated as well. Similar comment throughout this code file.
There was a problem hiding this comment.
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.
Would source and destination make sense there?
There was a problem hiding this comment.
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.
Can you revert the unnecessary blank lines being added here?
|
|
||
| [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.
Can you revert the unnecessary blank line added?
|
@eerhardt Sorry about that. I'll get those updated. |
|
@tannergooding can you also review the PR? |
| } | ||
|
|
||
| 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.
I don't know what v and w stand for throughout, but in some future PR someone might want to make them more descriptive...
| int posMin, int iposMin, int iposLimit, AlignedArray destination, int stride) => SseUtils.MatTimesSrc(matrix, rgposSrc, sourceValues, posMin, iposMin, iposLimit, destination, stride); | ||
|
|
||
| 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.
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.
I don't think that should stop merging this PR though.
|
Seems fine but I'll let @tannergooding sign off. |
|
ping @tannergooding for review. |
|
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.