diff --git a/docs/building/netcoreapp3.0-instructions.md b/docs/building/netcoreapp3.0-instructions.md index 338e06ef83..d65bcba34b 100644 --- a/docs/building/netcoreapp3.0-instructions.md +++ b/docs/building/netcoreapp3.0-instructions.md @@ -1,10 +1,8 @@ In order to build ML.NET for .NET Core 3.0, you need to do a few manual steps. -1. Pick a version of the .NET Core 3.0 SDK you want to use. As of this writing, I'm using `3.0.100-alpha1-009622`. You can get the latest available version from the [dotnet/core-sdk README](https://github.com/dotnet/core-sdk#installers-and-binaries) page. -2. Change the [DotnetCLIVersion.txt](https://github.com/dotnet/machinelearning/blob/master/DotnetCLIVersion.txt) file to use that version number. -3. Delete the local `.\Tools\` folder from the root of the repo, to ensure you download the new version. -4. Run `.\build.cmd -- /p:Configuration=Release-Intrinsics` from the root of the repo. -5. If you want to build the NuGet packages, `.\build.cmd -buildPackages` after step 4. +1. Delete the local `.\Tools\` folder from the root of the repo, to ensure you download the new version of the .NET Core SDK. +2. Run `.\build.cmd -- /p:Configuration=Release-Intrinsics` or `.\build.cmd -Release-Intrinsics` from the root of the repo. +3. If you want to build the NuGet packages, `.\build.cmd -buildPackages` after step 2. If you are using Visual Studio, you will need to do the following: diff --git a/src/Microsoft.ML.CpuMath/AvxIntrinsics.cs b/src/Microsoft.ML.CpuMath/AvxIntrinsics.cs index 5b402c6ba1..2156ddf5fa 100644 --- a/src/Microsoft.ML.CpuMath/AvxIntrinsics.cs +++ b/src/Microsoft.ML.CpuMath/AvxIntrinsics.cs @@ -943,6 +943,8 @@ public static unsafe void Scale(float scale, Span dst) public static unsafe void ScaleSrcU(float scale, ReadOnlySpan src, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -1036,6 +1038,8 @@ public static unsafe void ScaleAddU(float a, float b, Span dst) public static unsafe void AddScaleU(float scale, ReadOnlySpan src, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -1088,6 +1092,9 @@ public static unsafe void AddScaleU(float scale, ReadOnlySpan src, Span src, ReadOnlySpan dst, Span result, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= result.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) fixed (float* pres = &MemoryMarshal.GetReference(result)) @@ -1142,6 +1149,9 @@ public static unsafe void AddScaleCopyU(float scale, ReadOnlySpan src, Re public static unsafe void AddScaleSU(float scale, ReadOnlySpan src, ReadOnlySpan idx, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= idx.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (int* pidx = &MemoryMarshal.GetReference(idx)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) @@ -1190,6 +1200,8 @@ public static unsafe void AddScaleSU(float scale, ReadOnlySpan src, ReadO public static unsafe void AddU(ReadOnlySpan src, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -1237,6 +1249,9 @@ public static unsafe void AddU(ReadOnlySpan src, Span dst, int cou public static unsafe void AddSU(ReadOnlySpan src, ReadOnlySpan idx, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= idx.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (int* pidx = &MemoryMarshal.GetReference(idx)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) @@ -1282,6 +1297,9 @@ public static unsafe void AddSU(ReadOnlySpan src, ReadOnlySpan idx, public static unsafe void MulElementWiseU(ReadOnlySpan src1, ReadOnlySpan src2, Span dst, int count) { + Contracts.Assert(count <= src1.Length); + Contracts.Assert(count <= src2.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc1 = &MemoryMarshal.GetReference(src1)) fixed (float* psrc2 = &MemoryMarshal.GetReference(src2)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) @@ -1718,6 +1736,8 @@ public static unsafe float MaxAbsDiffU(float mean, ReadOnlySpan src) public static unsafe float DotU(ReadOnlySpan src, ReadOnlySpan dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -1770,6 +1790,9 @@ public static unsafe float DotU(ReadOnlySpan src, ReadOnlySpan dst public static unsafe float DotSU(ReadOnlySpan src, ReadOnlySpan dst, ReadOnlySpan idx, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= idx.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) fixed (int* pidx = &MemoryMarshal.GetReference(idx)) @@ -1824,6 +1847,8 @@ public static unsafe float DotSU(ReadOnlySpan src, ReadOnlySpan ds public static unsafe float Dist2(ReadOnlySpan src, ReadOnlySpan dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { diff --git a/src/Microsoft.ML.CpuMath/SseIntrinsics.cs b/src/Microsoft.ML.CpuMath/SseIntrinsics.cs index 9583fbe652..b83fd6bbc6 100644 --- a/src/Microsoft.ML.CpuMath/SseIntrinsics.cs +++ b/src/Microsoft.ML.CpuMath/SseIntrinsics.cs @@ -13,6 +13,7 @@ // * D suffix means convolution matrix, with implicit source padding. // * Tran means the matrix is transposed. +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -884,6 +885,8 @@ public static unsafe void Scale(float scale, Span dst) public static unsafe void ScaleSrcU(float scale, ReadOnlySpan src, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -952,6 +955,8 @@ public static unsafe void ScaleAddU(float a, float b, Span dst) public static unsafe void AddScaleU(float scale, ReadOnlySpan src, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -991,6 +996,9 @@ public static unsafe void AddScaleU(float scale, ReadOnlySpan src, Span src, ReadOnlySpan dst, Span result, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= result.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) fixed (float* pres = &MemoryMarshal.GetReference(result)) @@ -1032,6 +1040,9 @@ public static unsafe void AddScaleCopyU(float scale, ReadOnlySpan src, Re public static unsafe void AddScaleSU(float scale, ReadOnlySpan src, ReadOnlySpan idx, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= idx.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (int* pidx = &MemoryMarshal.GetReference(idx)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) @@ -1068,6 +1079,8 @@ public static unsafe void AddScaleSU(float scale, ReadOnlySpan src, ReadO public static unsafe void AddU(ReadOnlySpan src, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -1103,6 +1116,9 @@ public static unsafe void AddU(ReadOnlySpan src, Span dst, int cou public static unsafe void AddSU(ReadOnlySpan src, ReadOnlySpan idx, Span dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= idx.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (int* pidx = &MemoryMarshal.GetReference(idx)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) @@ -1136,6 +1152,9 @@ public static unsafe void AddSU(ReadOnlySpan src, ReadOnlySpan idx, public static unsafe void MulElementWiseU(ReadOnlySpan src1, ReadOnlySpan src2, Span dst, int count) { + Contracts.Assert(count <= src1.Length); + Contracts.Assert(count <= src2.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc1 = &MemoryMarshal.GetReference(src1)) fixed (float* psrc2 = &MemoryMarshal.GetReference(src2)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) @@ -1470,6 +1489,8 @@ public static unsafe float MaxAbsDiffU(float mean, ReadOnlySpan src) public static unsafe float DotU(ReadOnlySpan src, ReadOnlySpan dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { @@ -1509,6 +1530,9 @@ public static unsafe float DotU(ReadOnlySpan src, ReadOnlySpan dst public static unsafe float DotSU(ReadOnlySpan src, ReadOnlySpan dst, ReadOnlySpan idx, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); + Contracts.Assert(count <= idx.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) fixed (int* pidx = &MemoryMarshal.GetReference(idx)) @@ -1550,6 +1574,8 @@ public static unsafe float DotSU(ReadOnlySpan src, ReadOnlySpan ds public static unsafe float Dist2(ReadOnlySpan src, ReadOnlySpan dst, int count) { + Contracts.Assert(count <= src.Length); + Contracts.Assert(count <= dst.Length); fixed (float* psrc = &MemoryMarshal.GetReference(src)) fixed (float* pdst = &MemoryMarshal.GetReference(dst)) { diff --git a/test/Microsoft.ML.Core.Tests/UnitTests/TestEntryPoints.cs b/test/Microsoft.ML.Core.Tests/UnitTests/TestEntryPoints.cs index 5e6b541acb..107c83eb7d 100644 --- a/test/Microsoft.ML.Core.Tests/UnitTests/TestEntryPoints.cs +++ b/test/Microsoft.ML.Core.Tests/UnitTests/TestEntryPoints.cs @@ -961,7 +961,7 @@ public void EntryPointPipelineEnsemble() getterAnom(ref scoreAnom); Assert.True(Single.IsNaN(scoreBin) && Single.IsNaN(score) || scoreBin == score); Assert.True(Single.IsNaN(scoreBinCali) && Single.IsNaN(score) || scoreBinCali == score); - Assert.True(Single.IsNaN(scoreSaved) && Single.IsNaN(score) || CompareNumbersWithTolerance(scoreSaved, score, null, 6)); + Assert.True(Single.IsNaN(scoreSaved) && Single.IsNaN(score) || CompareNumbersWithTolerance(scoreSaved, score, null, 5)); Assert.True(Single.IsNaN(scoreAnom) && Single.IsNaN(score) || scoreAnom == score); Single avg = 0; diff --git a/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs b/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs index 9f900b5440..4342fcc49f 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs @@ -339,7 +339,7 @@ public void BinaryClassifierLogisticRegressionBinNormTest() /// ///A test for binary classifiers /// - [ConditionalFact(typeof(Environment), nameof(Environment.Is64BitProcess))] // x86 output differs from Baseline + [ConditionalFact(typeof(BaseTestBaseline), nameof(BaseTestBaseline.LessThanNetCore30OrNotNetCoreAnd64BitProcess))] // x86 output differs from Baseline and flaky on netcore 3.0 [TestCategory("Binary")] public void BinaryClassifierLogisticRegressionGaussianNormTest() { diff --git a/test/Microsoft.ML.TimeSeries.Tests/TimeSeries.cs b/test/Microsoft.ML.TimeSeries.Tests/TimeSeries.cs index f20de461f4..39340d225b 100644 --- a/test/Microsoft.ML.TimeSeries.Tests/TimeSeries.cs +++ b/test/Microsoft.ML.TimeSeries.Tests/TimeSeries.cs @@ -158,7 +158,7 @@ public void SavePipePercentileThreshold() Done(); } - [Fact] + [ConditionalFact(typeof(BaseTestBaseline), nameof(BaseTestBaseline.LessThanNetCore30OrNotNetCore))] // Test is Flaky on netcore 3.0 public void SavePipeMovingAverageUniform() { TestCore(null, true,