Skip to content
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

Update input arguments in CpuMath files #1021

Merged
merged 27 commits into from
Nov 7, 2018

Conversation

jwood803
Copy link
Contributor

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.

@@ -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)
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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)
Copy link
Member

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?

Copy link
Member

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)

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 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,
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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

@tannergooding
Copy link
Member

This is a great improvement and helps increase readability immensely. Thanks for the work @jwood803

@jwood803
Copy link
Contributor Author

Glad to help @tannergooding! I hope to do more in the future 😄

@eerhardt
Copy link
Member

@jwood803 - are there more updates coming? Or can the WIP be removed and make this an official PR?

@jwood803
Copy link
Contributor Author

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

@jwood803 jwood803 changed the title WIP: Update input arguments in CpuMath files Update input arguments in CpuMath files Sep 26, 2018
@@ -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)
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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:
image

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.

Copy link
Member

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

Copy link
Contributor Author

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]

Copy link
Member

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.

Copy link
Contributor Author

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]
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 checked in.

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

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.

@danmoseley
Copy link
Member

@jwood803 do you have time to rebase and resolve conflicts?

@danmoseley
Copy link
Member

@jwood803 depending, it might be easier to repeat the search and replace in some cases.

@danmoseley
Copy link
Member

@tannergooding can you help @jwood803 this PR get closed out one way or another?

@jwood803
Copy link
Contributor Author

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!

@eerhardt
Copy link
Member

@jwood803 - it looks like your merge wasn't successful -

2018-10-28T20:35:35.4153390Z CpuMathUtils.netstandard.cs(22,133): error CS0103: The name 'srcValues' does not exist in the current context [/__w/1/s/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj]
2018-10-28T20:35:35.4154682Z CpuAligenedMathUtils.cs(88,26): error CS0117: 'CpuMathUtils' does not contain a definition for 'MatrixTimesSource' [/__w/1/s/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj]
2018-10-28T20:35:35.4155112Z CpuAligenedMathUtils.cs(103,26): error CS0117: 'CpuMathUtils' does not contain a definition for 'MatrixTimesSource' [/__w/1/s/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj]
2018-10-28T20:35:35.4155218Z /__w/1/s/dir.traversal.targets(25,5): error : Build failed. See earlier errors. [/__w/1/s/build.proj]

Can you fix the build errors?

}

private ValueGetter<VBuffer<float>> GetterFromFloatType(IRow input, int iinfo)
{

var getSrc = input.GetGetter<float>(_srcCols[iinfo]);
Copy link
Member

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?

@@ -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);
Copy link
Member

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?

@jwood803
Copy link
Contributor Author

@eerhardt Sorry about that. I'll get those updated.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shauheen
Copy link
Contributor

@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)
Copy link
Member

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);
Copy link
Member

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.

Copy link
Member

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.

@danmoseley
Copy link
Member

Seems fine but I'll let @tannergooding sign off.

@shauheen
Copy link
Contributor

shauheen commented Nov 6, 2018

ping @tannergooding for review.

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.

LGTM

@shauheen shauheen merged commit a3b09bf into dotnet:master Nov 7, 2018
@jwood803 jwood803 deleted the cpu-rename-arguments branch November 7, 2018 14:42
@jwood803
Copy link
Contributor Author

jwood803 commented Nov 7, 2018

Much thanks to @eerhardt and @tannergooding for all the help on this PR! 😄

@ghost ghost locked as resolved and limited conversation to collaborators Mar 28, 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.

5 participants