Skip to content

Commit 6aabec6

Browse files
committed
Merge branch 'master' into obsolete-api
2 parents 4ce300b + df1c2af commit 6aabec6

File tree

74 files changed

+2052
-1307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2052
-1307
lines changed

docs/building/unix-instructions.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ macOS 10.12 (Sierra) or higher is needed to build dotnet/machinelearning.
4242

4343
On macOS a few components are needed which are not provided by a default developer setup:
4444
* cmake 3.10.3
45-
* gcc
45+
* libomp
46+
* libgdiplus
47+
* gettext
4648
* All the requirements necessary to run .NET Core 2.0 applications. To view macOS prerequisites click [here](https://docs.microsoft.com/en-us/dotnet/core/macos-prerequisites?tabs=netcore2x).
4749

48-
One way of obtaining CMake and gcc is via [Homebrew](https://brew.sh):
50+
One way of obtaining CMake and other required libraries is via [Homebrew](https://brew.sh):
4951
```sh
50-
$ brew install cmake
51-
$ brew install gcc
52+
$ brew install cmake libomp mono-libgdiplus gettext && brew link gettext --force
5253
```

src/Microsoft.ML.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Legacy" + PublicKey.Value)]
1717
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Maml" + PublicKey.Value)]
1818
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.ResultProcessor" + PublicKey.Value)]
19+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.CpuMath" + PublicKey.Value)]
1920

2021
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Data" + PublicKey.Value)]
2122
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Api" + PublicKey.Value)]

src/Microsoft.ML.Core/Utilities/Contracts.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
using System.IO;
1717
using System.Threading;
1818

19-
#if PRIVATE_CONTRACTS
20-
namespace Microsoft.ML.Runtime.Internal
21-
#else
2219
namespace Microsoft.ML.Runtime
23-
#endif
2420
{
2521
using Conditional = System.Diagnostics.ConditionalAttribute;
2622
using Debug = System.Diagnostics.Debug;
@@ -31,11 +27,7 @@ namespace Microsoft.ML.Runtime
3127
/// totally replace the exception, etc. It is not legal to return null from
3228
/// Process (unless null was passed in, which really shouldn't happen).
3329
/// </summary>
34-
#if PRIVATE_CONTRACTS
35-
internal interface IExceptionContext
36-
#else
3730
public interface IExceptionContext
38-
#endif
3931
{
4032
TException Process<TException>(TException ex)
4133
where TException : Exception;
@@ -46,18 +38,7 @@ TException Process<TException>(TException ex)
4638
string ContextDescription { get; }
4739
}
4840

49-
#if PRIVATE_CONTRACTS
50-
[Flags]
51-
internal enum MessageSensitivity
52-
{
53-
None = 0,
54-
Unknown = ~None
55-
}
56-
#endif
57-
58-
#if !PRIVATE_CONTRACTS
5941
[BestFriend]
60-
#endif
6142
internal static partial class Contracts
6243
{
6344
public const string IsMarkedKey = "ML_IsMarked";
@@ -156,7 +137,6 @@ public static MessageSensitivity Sensitivity(this Exception ex)
156137
return (ex.Data[SensitivityKey] as MessageSensitivity?) ?? MessageSensitivity.Unknown;
157138
}
158139

159-
#if !PRIVATE_CONTRACTS
160140
/// <summary>
161141
/// This is an internal convenience implementation of an exception context to make marking
162142
/// exceptions with a specific sensitivity flag a bit less onorous. The alternative to a scheme
@@ -233,7 +213,6 @@ public static IExceptionContext UserSensitive(this IExceptionContext ctx)
233213
/// </summary>
234214
public static IExceptionContext SchemaSensitive(this IExceptionContext ctx)
235215
=> new SensitiveExceptionContext(ctx, MessageSensitivity.Schema);
236-
#endif
237216

238217
/// <summary>
239218
/// Sets the assert handler to the given function, returning the previous handler.
@@ -742,7 +721,6 @@ public static void CheckIO(this IExceptionContext ctx, bool f, string msg)
742721
throw ExceptIO(ctx, msg);
743722
}
744723

745-
#if !PRIVATE_CONTRACTS
746724
/// <summary>
747725
/// Check state of the host and throw exception if host marked to stop all exection.
748726
/// </summary>
@@ -751,7 +729,7 @@ public static void CheckAlive(this IHostEnvironment env)
751729
if (env.IsCancelled)
752730
throw Process(new OperationCanceledException("Operation was cancelled."), env);
753731
}
754-
#endif
732+
755733
/// <summary>
756734
/// This documents that the parameter can legally be null.
757735
/// </summary>

src/Microsoft.ML.CpuMath/AlignedArray.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath
1616
///
1717
/// The ctor takes an alignment value, which must be a power of two at least sizeof(Float).
1818
/// </summary>
19-
public sealed class AlignedArray
19+
[BestFriend]
20+
internal sealed class AlignedArray
2021
{
2122
// Items includes "head" items filled with NaN, followed by _size entries, followed by "tail"
2223
// items, also filled with NaN. Note that _size * sizeof(Float) is divisible by _cbAlign.
2324
// It is illegal to access any slot outsize [_base, _base + _size). This is internal so clients
2425
// can easily pin it.
25-
internal Float[] Items;
26+
public Float[] Items;
2627

2728
private readonly int _size; // Must be divisible by (_cbAlign / sizeof(Float)).
2829
private readonly int _cbAlign; // The alignment in bytes, a power of two, divisible by sizeof(Float).
@@ -49,7 +50,7 @@ public AlignedArray(int size, int cbAlign)
4950
_lock = new object();
5051
}
5152

52-
internal unsafe int GetBase(long addr)
53+
public unsafe int GetBase(long addr)
5354
{
5455
#if DEBUG
5556
fixed (Float* pv = Items)

src/Microsoft.ML.CpuMath/AlignedMatrix.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath
1818
/// the AlignedArray with a logical size, which does not include padding, while the AlignedArray
1919
/// size does include padding.
2020
/// </summary>
21-
public sealed class CpuAlignedVector : ICpuVector
21+
[BestFriend]
22+
internal sealed class CpuAlignedVector : ICpuVector
2223
{
2324
private readonly AlignedArray _items;
2425
private readonly int _size; // The logical size.
@@ -231,7 +232,8 @@ IEnumerator IEnumerable.GetEnumerator()
231232
/// This implements a logical matrix of Floats that is automatically aligned for SSE/AVX operations.
232233
/// The ctor takes an alignment value, which must be a power of two at least sizeof(Float).
233234
/// </summary>
234-
public abstract class CpuAlignedMatrixBase
235+
[BestFriend]
236+
internal abstract class CpuAlignedMatrixBase
235237
{
236238
// _items includes "head" items filled with NaN, followed by RunLenPhy * RunCntPhy entries, followed by
237239
// "tail" items, also filled with NaN. Note that RunLenPhy and RunCntPhy are divisible by the alignment
@@ -393,7 +395,8 @@ public void CopyFrom(CpuAlignedMatrixBase src)
393395
/// This implements a logical row-major matrix of Floats that is automatically aligned for SSE/AVX operations.
394396
/// The ctor takes an alignment value, which must be a power of two at least sizeof(Float).
395397
/// </summary>
396-
public abstract class CpuAlignedMatrixRowBase : CpuAlignedMatrixBase, ICpuBuffer<Float>
398+
[BestFriend]
399+
internal abstract class CpuAlignedMatrixRowBase : CpuAlignedMatrixBase, ICpuBuffer<Float>
397400
{
398401
protected CpuAlignedMatrixRowBase(int crow, int ccol, int cbAlign)
399402
: base(ccol, crow, cbAlign)
@@ -497,7 +500,8 @@ IEnumerator IEnumerable.GetEnumerator()
497500
/// This implements a row-major matrix of Floats that is automatically aligned for SSE/AVX operations.
498501
/// The ctor takes an alignment value, which must be a power of two at least sizeof(Float).
499502
/// </summary>
500-
public sealed class CpuAlignedMatrixRow : CpuAlignedMatrixRowBase, ICpuFullMatrix
503+
[BestFriend]
504+
internal sealed class CpuAlignedMatrixRow : CpuAlignedMatrixRowBase, ICpuFullMatrix
501505
{
502506
public CpuAlignedMatrixRow(int crow, int ccol, int cbAlign)
503507
: base(crow, ccol, cbAlign)
@@ -558,7 +562,8 @@ public void ZeroItems(int[] indices)
558562
/// This implements a logical matrix of Floats that is automatically aligned for SSE/AVX operations.
559563
/// The ctor takes an alignment value, which must be a power of two at least sizeof(Float).
560564
/// </summary>
561-
public sealed class CpuAlignedMatrixCol : CpuAlignedMatrixBase, ICpuFullMatrix
565+
[BestFriend]
566+
internal sealed class CpuAlignedMatrixCol : CpuAlignedMatrixBase, ICpuFullMatrix
562567
{
563568
/// <summary>
564569
/// Allocate an aligned matrix with the given alignment (in bytes).

src/Microsoft.ML.CpuMath/AssemblyInfo.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Reflection;
65
using System.Runtime.CompilerServices;
7-
using System.Runtime.InteropServices;
6+
using Microsoft.ML;
87

9-
[assembly: InternalsVisibleTo("Microsoft.ML.StandardLearners, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
8+
[assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netstandard" + PublicKey.TestValue)]
9+
[assembly: InternalsVisibleTo("Microsoft.ML.Data" + PublicKey.Value)]
10+
[assembly: InternalsVisibleTo("Microsoft.ML.FastTree" + PublicKey.Value)]
11+
[assembly: InternalsVisibleTo("Microsoft.ML.HalLearners" + PublicKey.Value)]
12+
[assembly: InternalsVisibleTo("Microsoft.ML.KMeansClustering" + PublicKey.Value)]
13+
[assembly: InternalsVisibleTo("Microsoft.ML.PCA" + PublicKey.Value)]
14+
[assembly: InternalsVisibleTo("Microsoft.ML.StandardLearners" + PublicKey.Value)]
15+
[assembly: InternalsVisibleTo("Microsoft.ML.Sweeper" + PublicKey.Value)]
16+
[assembly: InternalsVisibleTo("Microsoft.ML.TimeSeries" + PublicKey.Value)]
17+
[assembly: InternalsVisibleTo("Microsoft.ML.Transforms" + PublicKey.Value)]
18+
[assembly: InternalsVisibleTo("Microsoft.ML.Benchmarks.Tests" + PublicKey.TestValue)]
19+
20+
[assembly: WantsToBeBestFriends]

src/Microsoft.ML.CpuMath/AvxIntrinsics.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,16 @@ private static Vector256<float> MultiplyAdd(Vector256<float> src1, Vector256<flo
153153
// Multiply matrix times vector into vector.
154154
public static unsafe void MatMul(AlignedArray mat, AlignedArray src, AlignedArray dst, int crow, int ccol)
155155
{
156+
Contracts.Assert(src.Size == dst.Size);
157+
156158
MatMul(mat.Items, src.Items, dst.Items, crow, ccol);
157159
}
158160

159161
public static unsafe void MatMul(ReadOnlySpan<float> mat, ReadOnlySpan<float> src, Span<float> dst, int crow, int ccol)
160162
{
161163
Contracts.Assert(crow % 4 == 0);
162164
Contracts.Assert(ccol % 4 == 0);
165+
Contracts.Assert(src.Length == dst.Length);
163166

164167
fixed (float* psrc = &MemoryMarshal.GetReference(src))
165168
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
@@ -307,6 +310,8 @@ public static unsafe void MatMul(ReadOnlySpan<float> mat, ReadOnlySpan<float> sr
307310
public static unsafe void MatMulP(AlignedArray mat, ReadOnlySpan<int> rgposSrc, AlignedArray src,
308311
int posMin, int iposMin, int iposEnd, AlignedArray dst, int crow, int ccol)
309312
{
313+
Contracts.Assert(src.Size == dst.Size);
314+
310315
MatMulP(mat.Items, rgposSrc, src.Items, posMin, iposMin, iposEnd, dst.Items, crow, ccol);
311316
}
312317

@@ -315,6 +320,7 @@ public static unsafe void MatMulP(ReadOnlySpan<float> mat, ReadOnlySpan<int> rgp
315320
{
316321
Contracts.Assert(crow % 8 == 0);
317322
Contracts.Assert(ccol % 8 == 0);
323+
Contracts.Assert(src.Length == dst.Length);
318324

319325
// REVIEW: For extremely sparse inputs, interchanging the loops would
320326
// likely be more efficient.
@@ -468,13 +474,16 @@ Vector256<float> SparseMultiplicationAcrossRow()
468474

469475
public static unsafe void MatMulTran(AlignedArray mat, AlignedArray src, AlignedArray dst, int crow, int ccol)
470476
{
477+
Contracts.Assert(src.Size == dst.Size);
478+
471479
MatMulTran(mat.Items, src.Items, dst.Items, crow, ccol);
472480
}
473481

474482
public static unsafe void MatMulTran(ReadOnlySpan<float> mat, ReadOnlySpan<float> src, Span<float> dst, int crow, int ccol)
475483
{
476484
Contracts.Assert(crow % 4 == 0);
477485
Contracts.Assert(ccol % 4 == 0);
486+
Contracts.Assert(src.Length == dst.Length);
478487

479488
fixed (float* psrc = &MemoryMarshal.GetReference(src))
480489
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
@@ -951,6 +960,8 @@ public static unsafe void Scale(float scale, Span<float> dst)
951960

952961
public static unsafe void ScaleSrcU(float scale, ReadOnlySpan<float> src, Span<float> dst, int count)
953962
{
963+
Contracts.Assert(src.Length == dst.Length);
964+
954965
fixed (float* psrc = &MemoryMarshal.GetReference(src))
955966
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
956967
{
@@ -1044,6 +1055,8 @@ public static unsafe void ScaleAddU(float a, float b, Span<float> dst)
10441055

10451056
public static unsafe void AddScaleU(float scale, ReadOnlySpan<float> src, Span<float> dst, int count)
10461057
{
1058+
Contracts.Assert(src.Length == dst.Length);
1059+
10471060
fixed (float* psrc = &MemoryMarshal.GetReference(src))
10481061
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
10491062
{
@@ -1096,6 +1109,8 @@ public static unsafe void AddScaleU(float scale, ReadOnlySpan<float> src, Span<f
10961109

10971110
public static unsafe void AddScaleCopyU(float scale, ReadOnlySpan<float> src, ReadOnlySpan<float> dst, Span<float> result, int count)
10981111
{
1112+
Contracts.Assert(src.Length == dst.Length);
1113+
10991114
fixed (float* psrc = &MemoryMarshal.GetReference(src))
11001115
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
11011116
fixed (float* pres = &MemoryMarshal.GetReference(result))
@@ -1150,6 +1165,8 @@ public static unsafe void AddScaleCopyU(float scale, ReadOnlySpan<float> src, Re
11501165

11511166
public static unsafe void AddScaleSU(float scale, ReadOnlySpan<float> src, ReadOnlySpan<int> idx, Span<float> dst, int count)
11521167
{
1168+
Contracts.Assert(src.Length == dst.Length);
1169+
11531170
fixed (float* psrc = &MemoryMarshal.GetReference(src))
11541171
fixed (int* pidx = &MemoryMarshal.GetReference(idx))
11551172
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
@@ -1198,6 +1215,8 @@ public static unsafe void AddScaleSU(float scale, ReadOnlySpan<float> src, ReadO
11981215

11991216
public static unsafe void AddU(ReadOnlySpan<float> src, Span<float> dst, int count)
12001217
{
1218+
Contracts.Assert(src.Length == dst.Length);
1219+
12011220
fixed (float* psrc = &MemoryMarshal.GetReference(src))
12021221
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
12031222
{
@@ -1245,6 +1264,8 @@ public static unsafe void AddU(ReadOnlySpan<float> src, Span<float> dst, int cou
12451264

12461265
public static unsafe void AddSU(ReadOnlySpan<float> src, ReadOnlySpan<int> idx, Span<float> dst, int count)
12471266
{
1267+
Contracts.Assert(src.Length == dst.Length);
1268+
12481269
fixed (float* psrc = &MemoryMarshal.GetReference(src))
12491270
fixed (int* pidx = &MemoryMarshal.GetReference(idx))
12501271
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
@@ -1726,6 +1747,8 @@ public static unsafe float MaxAbsDiffU(float mean, ReadOnlySpan<float> src)
17261747

17271748
public static unsafe float DotU(ReadOnlySpan<float> src, ReadOnlySpan<float> dst, int count)
17281749
{
1750+
Contracts.Assert(src.Length == dst.Length);
1751+
17291752
fixed (float* psrc = &MemoryMarshal.GetReference(src))
17301753
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
17311754
{
@@ -1778,6 +1801,8 @@ public static unsafe float DotU(ReadOnlySpan<float> src, ReadOnlySpan<float> dst
17781801

17791802
public static unsafe float DotSU(ReadOnlySpan<float> src, ReadOnlySpan<float> dst, ReadOnlySpan<int> idx, int count)
17801803
{
1804+
Contracts.Assert(src.Length == dst.Length);
1805+
17811806
fixed (float* psrc = &MemoryMarshal.GetReference(src))
17821807
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
17831808
fixed (int* pidx = &MemoryMarshal.GetReference(idx))
@@ -1832,6 +1857,8 @@ public static unsafe float DotSU(ReadOnlySpan<float> src, ReadOnlySpan<float> ds
18321857

18331858
public static unsafe float Dist2(ReadOnlySpan<float> src, ReadOnlySpan<float> dst, int count)
18341859
{
1860+
Contracts.Assert(src.Length == dst.Length);
1861+
18351862
fixed (float* psrc = &MemoryMarshal.GetReference(src))
18361863
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
18371864
{

src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace Microsoft.ML.Runtime.Internal.CpuMath
66
{
7-
public static class CpuAligenedMathUtils<TMatrix>
7+
[BestFriend]
8+
internal static class CpuAligenedMathUtils<TMatrix>
89
where TMatrix : CpuAlignedMatrixBase, ICpuFullMatrix
910
{
1011
/// <summary>

src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Microsoft.ML.Runtime.Internal.CpuMath
1010
{
11-
public static partial class CpuMathUtils
11+
internal static partial class CpuMathUtils
1212
{
1313
// The count of bytes in Vector128<T>, corresponding to _cbAlign in AlignedArray
1414
private const int Vector128Alignment = 16;

src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace Microsoft.ML.Runtime.Internal.CpuMath
99
{
10-
public static partial class CpuMathUtils
10+
[BestFriend]
11+
internal static partial class CpuMathUtils
1112
{
1213
// The count of bytes in Vector128<T>, corresponding to _cbAlign in AlignedArray
1314
private const int Vector128Alignment = 16;

src/Microsoft.ML.CpuMath/EigenUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Microsoft.ML.Runtime.Internal.CpuMath
99
{
10+
[BestFriend]
1011
// REVIEW: improve perf with SSE and Multithreading
11-
public static class EigenUtils
12+
internal static class EigenUtils
1213
{
1314
//Compute the Eigen-decomposition of a symmetric matrix
1415
// REVIEW: use matrix/vector operations, not Array Math

0 commit comments

Comments
 (0)