diff --git a/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs b/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs index 5a30b74dee..aaa44a6bc7 100644 --- a/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs +++ b/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs @@ -16,6 +16,7 @@ [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Legacy" + PublicKey.Value)] [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Maml" + PublicKey.Value)] [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.ResultProcessor" + PublicKey.Value)] +[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.CpuMath" + PublicKey.Value)] [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Data" + PublicKey.Value)] [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Api" + PublicKey.Value)] diff --git a/src/Microsoft.ML.Core/Utilities/Contracts.cs b/src/Microsoft.ML.Core/Utilities/Contracts.cs index e1ee11a0d4..67f559d2fb 100644 --- a/src/Microsoft.ML.Core/Utilities/Contracts.cs +++ b/src/Microsoft.ML.Core/Utilities/Contracts.cs @@ -16,11 +16,7 @@ using System.IO; using System.Threading; -#if PRIVATE_CONTRACTS -namespace Microsoft.ML.Runtime.Internal -#else namespace Microsoft.ML.Runtime -#endif { using Conditional = System.Diagnostics.ConditionalAttribute; using Debug = System.Diagnostics.Debug; @@ -31,11 +27,7 @@ namespace Microsoft.ML.Runtime /// totally replace the exception, etc. It is not legal to return null from /// Process (unless null was passed in, which really shouldn't happen). /// -#if PRIVATE_CONTRACTS - internal interface IExceptionContext -#else public interface IExceptionContext -#endif { TException Process(TException ex) where TException : Exception; @@ -46,18 +38,7 @@ TException Process(TException ex) string ContextDescription { get; } } -#if PRIVATE_CONTRACTS - [Flags] - internal enum MessageSensitivity - { - None = 0, - Unknown = ~None - } -#endif - -#if !PRIVATE_CONTRACTS [BestFriend] -#endif internal static partial class Contracts { public const string IsMarkedKey = "ML_IsMarked"; @@ -156,7 +137,6 @@ public static MessageSensitivity Sensitivity(this Exception ex) return (ex.Data[SensitivityKey] as MessageSensitivity?) ?? MessageSensitivity.Unknown; } -#if !PRIVATE_CONTRACTS /// /// This is an internal convenience implementation of an exception context to make marking /// 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) /// public static IExceptionContext SchemaSensitive(this IExceptionContext ctx) => new SensitiveExceptionContext(ctx, MessageSensitivity.Schema); -#endif /// /// 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) throw ExceptIO(ctx, msg); } -#if !PRIVATE_CONTRACTS /// /// Check state of the host and throw exception if host marked to stop all exection. /// @@ -751,7 +729,7 @@ public static void CheckAlive(this IHostEnvironment env) if (env.IsCancelled) throw Process(new OperationCanceledException("Operation was cancelled."), env); } -#endif + /// /// This documents that the parameter can legally be null. /// diff --git a/src/Microsoft.ML.CpuMath/AlignedArray.cs b/src/Microsoft.ML.CpuMath/AlignedArray.cs index 9902edc4df..d5e0c6406a 100644 --- a/src/Microsoft.ML.CpuMath/AlignedArray.cs +++ b/src/Microsoft.ML.CpuMath/AlignedArray.cs @@ -16,13 +16,14 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath /// /// The ctor takes an alignment value, which must be a power of two at least sizeof(Float). /// - public sealed class AlignedArray + [BestFriend] + internal sealed class AlignedArray { // Items includes "head" items filled with NaN, followed by _size entries, followed by "tail" // items, also filled with NaN. Note that _size * sizeof(Float) is divisible by _cbAlign. // It is illegal to access any slot outsize [_base, _base + _size). This is internal so clients // can easily pin it. - internal Float[] Items; + public Float[] Items; private readonly int _size; // Must be divisible by (_cbAlign / sizeof(Float)). 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) _lock = new object(); } - internal unsafe int GetBase(long addr) + public unsafe int GetBase(long addr) { #if DEBUG fixed (Float* pv = Items) diff --git a/src/Microsoft.ML.CpuMath/AlignedMatrix.cs b/src/Microsoft.ML.CpuMath/AlignedMatrix.cs index f76ec7815d..b2ec514376 100644 --- a/src/Microsoft.ML.CpuMath/AlignedMatrix.cs +++ b/src/Microsoft.ML.CpuMath/AlignedMatrix.cs @@ -18,7 +18,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath /// the AlignedArray with a logical size, which does not include padding, while the AlignedArray /// size does include padding. /// - public sealed class CpuAlignedVector : ICpuVector + [BestFriend] + internal sealed class CpuAlignedVector : ICpuVector { private readonly AlignedArray _items; private readonly int _size; // The logical size. @@ -231,7 +232,8 @@ IEnumerator IEnumerable.GetEnumerator() /// This implements a logical matrix of Floats that is automatically aligned for SSE/AVX operations. /// The ctor takes an alignment value, which must be a power of two at least sizeof(Float). /// - public abstract class CpuAlignedMatrixBase + [BestFriend] + internal abstract class CpuAlignedMatrixBase { // _items includes "head" items filled with NaN, followed by RunLenPhy * RunCntPhy entries, followed by // "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) /// This implements a logical row-major matrix of Floats that is automatically aligned for SSE/AVX operations. /// The ctor takes an alignment value, which must be a power of two at least sizeof(Float). /// - public abstract class CpuAlignedMatrixRowBase : CpuAlignedMatrixBase, ICpuBuffer + [BestFriend] + internal abstract class CpuAlignedMatrixRowBase : CpuAlignedMatrixBase, ICpuBuffer { protected CpuAlignedMatrixRowBase(int crow, int ccol, int cbAlign) : base(ccol, crow, cbAlign) @@ -497,7 +500,8 @@ IEnumerator IEnumerable.GetEnumerator() /// This implements a row-major matrix of Floats that is automatically aligned for SSE/AVX operations. /// The ctor takes an alignment value, which must be a power of two at least sizeof(Float). /// - public sealed class CpuAlignedMatrixRow : CpuAlignedMatrixRowBase, ICpuFullMatrix + [BestFriend] + internal sealed class CpuAlignedMatrixRow : CpuAlignedMatrixRowBase, ICpuFullMatrix { public CpuAlignedMatrixRow(int crow, int ccol, int cbAlign) : base(crow, ccol, cbAlign) @@ -558,7 +562,8 @@ public void ZeroItems(int[] indices) /// This implements a logical matrix of Floats that is automatically aligned for SSE/AVX operations. /// The ctor takes an alignment value, which must be a power of two at least sizeof(Float). /// - public sealed class CpuAlignedMatrixCol : CpuAlignedMatrixBase, ICpuFullMatrix + [BestFriend] + internal sealed class CpuAlignedMatrixCol : CpuAlignedMatrixBase, ICpuFullMatrix { /// /// Allocate an aligned matrix with the given alignment (in bytes). diff --git a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs index cb45bf5608..442075957f 100644 --- a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs +++ b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs @@ -2,8 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; +using Microsoft.ML; -[assembly: InternalsVisibleTo("Microsoft.ML.StandardLearners, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")] \ No newline at end of file +[assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netstandard" + PublicKey.TestValue)] +[assembly: InternalsVisibleTo("Microsoft.ML.Data" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.FastTree" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.HalLearners" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.KMeansClustering" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.PCA" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.StandardLearners" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.Sweeper" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.TimeSeries" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.Transforms" + PublicKey.Value)] +[assembly: InternalsVisibleTo("Microsoft.ML.Benchmarks.Tests" + PublicKey.TestValue)] + +[assembly: WantsToBeBestFriends] diff --git a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs index eacdd85213..d4c8e8e087 100644 --- a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs +++ b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs @@ -4,7 +4,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath { - public static class CpuAligenedMathUtils + [BestFriend] + internal static class CpuAligenedMathUtils where TMatrix : CpuAlignedMatrixBase, ICpuFullMatrix { /// diff --git a/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs b/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs index 973b2278a3..3d6f9e94f4 100644 --- a/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs +++ b/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs @@ -8,7 +8,7 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath { - public static partial class CpuMathUtils + internal static partial class CpuMathUtils { // The count of bytes in Vector128, corresponding to _cbAlign in AlignedArray private const int Vector128Alignment = 16; diff --git a/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs b/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs index 5d54ee6fe0..b3f46f0a5a 100644 --- a/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs +++ b/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs @@ -7,7 +7,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath { - public static partial class CpuMathUtils + [BestFriend] + internal static partial class CpuMathUtils { // The count of bytes in Vector128, corresponding to _cbAlign in AlignedArray private const int Vector128Alignment = 16; diff --git a/src/Microsoft.ML.CpuMath/EigenUtils.cs b/src/Microsoft.ML.CpuMath/EigenUtils.cs index 622849d368..fc20b8bfe7 100644 --- a/src/Microsoft.ML.CpuMath/EigenUtils.cs +++ b/src/Microsoft.ML.CpuMath/EigenUtils.cs @@ -7,8 +7,9 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath { + [BestFriend] // REVIEW: improve perf with SSE and Multithreading - public static class EigenUtils + internal static class EigenUtils { //Compute the Eigen-decomposition of a symmetric matrix // REVIEW: use matrix/vector operations, not Array Math diff --git a/src/Microsoft.ML.CpuMath/ICpuBuffer.cs b/src/Microsoft.ML.CpuMath/ICpuBuffer.cs index ad55f5c8c6..7f0c0e8126 100644 --- a/src/Microsoft.ML.CpuMath/ICpuBuffer.cs +++ b/src/Microsoft.ML.CpuMath/ICpuBuffer.cs @@ -10,7 +10,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath { using Conditional = System.Diagnostics.ConditionalAttribute; - public interface ICpuBuffer : IEnumerable, IDisposable + [BestFriend] + internal interface ICpuBuffer : IEnumerable, IDisposable where T : struct { int ValueCount { get; } @@ -39,7 +40,8 @@ public interface ICpuBuffer : IEnumerable, IDisposable /// /// A logical math vector. /// - public interface ICpuVector : ICpuBuffer + [BestFriend] + internal interface ICpuVector : ICpuBuffer { /// /// The vector size @@ -52,7 +54,8 @@ public interface ICpuVector : ICpuBuffer Float GetValue(int i); } - public interface ICpuMatrix : ICpuBuffer + [BestFriend] + internal interface ICpuMatrix : ICpuBuffer { /// /// The row count @@ -68,7 +71,8 @@ public interface ICpuMatrix : ICpuBuffer /// /// A 2-dimensional matrix. /// - public interface ICpuFullMatrix : ICpuMatrix + [BestFriend] + internal interface ICpuFullMatrix : ICpuMatrix { /// /// Copy the values for the given row into dst, starting at slot ivDst. diff --git a/src/Microsoft.ML.CpuMath/IntUtils.cs b/src/Microsoft.ML.CpuMath/IntUtils.cs index 2492dddaff..cec2b71dfb 100644 --- a/src/Microsoft.ML.CpuMath/IntUtils.cs +++ b/src/Microsoft.ML.CpuMath/IntUtils.cs @@ -9,7 +9,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath { - public static class IntUtils + [BestFriend] + internal static class IntUtils { /// /// Add src to the 128 bits contained in dst. Ignores overflow, that is, the addition is done modulo 2^128. diff --git a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj index f9d3d90b59..f5d6de3f05 100644 --- a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj +++ b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj @@ -5,7 +5,6 @@ netstandard2.0;netcoreapp3.0 Microsoft.ML.CpuMath true - $(DefineConstants);CORECLR;PRIVATE_CONTRACTS 7.3 @@ -13,13 +12,6 @@ - - - - - - - @@ -30,6 +22,7 @@ + - \ No newline at end of file + diff --git a/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs b/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs index 6b9659e753..ed1208c80c 100644 --- a/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs +++ b/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs @@ -9,7 +9,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath /// /// Probability Functions. /// - public sealed class ProbabilityFunctions + [BestFriend] + internal sealed class ProbabilityFunctions { /// /// The approximate complimentary error function (i.e., 1-erf). diff --git a/src/Microsoft.ML.CpuMath/Sse.cs b/src/Microsoft.ML.CpuMath/Sse.cs index 5c4ace31cd..b3f00d1136 100644 --- a/src/Microsoft.ML.CpuMath/Sse.cs +++ b/src/Microsoft.ML.CpuMath/Sse.cs @@ -11,7 +11,8 @@ namespace Microsoft.ML.Runtime.Internal.CpuMath /// Keep Sse.cs in sync with Avx.cs. When making changes to one, use BeyondCompare or a similar tool /// to view diffs and propagate appropriate changes to the other. /// - public static class SseUtils + [BestFriend] + internal static class SseUtils { public const int CbAlign = 16; diff --git a/src/Microsoft.ML.CpuMath/Thunk.cs b/src/Microsoft.ML.CpuMath/Thunk.cs index 86e3992f62..faf0b82c66 100644 --- a/src/Microsoft.ML.CpuMath/Thunk.cs +++ b/src/Microsoft.ML.CpuMath/Thunk.cs @@ -3,11 +3,11 @@ // See the LICENSE file in the project root for more information. using System.Runtime.InteropServices; -using System.Runtime.CompilerServices; using System.Security; namespace Microsoft.ML.Runtime.Internal.CpuMath { + [BestFriend] internal static unsafe class Thunk { internal const string NativePath = "CpuMathNative"; diff --git a/src/Microsoft.ML.StandardLearners/FactorizationMachine/FactorizationMachineInterface.cs b/src/Microsoft.ML.StandardLearners/FactorizationMachine/FactorizationMachineInterface.cs index a4a2b79787..f746c3bd89 100644 --- a/src/Microsoft.ML.StandardLearners/FactorizationMachine/FactorizationMachineInterface.cs +++ b/src/Microsoft.ML.StandardLearners/FactorizationMachine/FactorizationMachineInterface.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using Microsoft.ML.Runtime.Internal.CpuMath; -using Microsoft.ML.Runtime.Internal.Utilities; using System.Runtime.InteropServices; using System.Security; diff --git a/src/Microsoft.ML.Sweeper/Algorithms/SmacSweeper.cs b/src/Microsoft.ML.Sweeper/Algorithms/SmacSweeper.cs index f3bc7a362d..cf4de98e66 100644 --- a/src/Microsoft.ML.Sweeper/Algorithms/SmacSweeper.cs +++ b/src/Microsoft.ML.Sweeper/Algorithms/SmacSweeper.cs @@ -12,7 +12,6 @@ using Microsoft.ML.Runtime.Sweeper; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.Runtime.EntryPoints; using Microsoft.ML.Trainers.FastTree; using Microsoft.ML.Trainers.FastTree.Internal; using Microsoft.ML.Runtime.Internal.Utilities; diff --git a/src/Microsoft.ML.Sweeper/Algorithms/SweeperProbabilityUtils.cs b/src/Microsoft.ML.Sweeper/Algorithms/SweeperProbabilityUtils.cs index 08ef587596..503ffe75cc 100644 --- a/src/Microsoft.ML.Sweeper/Algorithms/SweeperProbabilityUtils.cs +++ b/src/Microsoft.ML.Sweeper/Algorithms/SweeperProbabilityUtils.cs @@ -2,12 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Float = System.Single; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.ML.Runtime.Internal.CpuMath; namespace Microsoft.ML.Runtime.Sweeper.Algorithms @@ -160,11 +156,11 @@ public static double[] InverseNormalize(double[] weights) return Normalize(weights); } - public static Float[] ParameterSetAsFloatArray(IHost host, IValueGenerator[] sweepParams, ParameterSet ps, bool expandCategoricals = true) + public static float[] ParameterSetAsFloatArray(IHost host, IValueGenerator[] sweepParams, ParameterSet ps, bool expandCategoricals = true) { host.Assert(ps.Count == sweepParams.Length); - var result = new List(); + var result = new List(); for (int i = 0; i < sweepParams.Length; i++) { @@ -212,7 +208,7 @@ public static Float[] ParameterSetAsFloatArray(IHost host, IValueGenerator[] swe return result.ToArray(); } - public static ParameterSet FloatArrayAsParameterSet(IHost host, IValueGenerator[] sweepParams, Float[] array, bool expandedCategoricals = true) + public static ParameterSet FloatArrayAsParameterSet(IHost host, IValueGenerator[] sweepParams, float[] array, bool expandedCategoricals = true) { Contracts.Assert(array.Length == sweepParams.Length); diff --git a/src/Microsoft.ML.Sweeper/AsyncSweeper.cs b/src/Microsoft.ML.Sweeper/AsyncSweeper.cs index fa537e793a..7f29dc2fa8 100644 --- a/src/Microsoft.ML.Sweeper/AsyncSweeper.cs +++ b/src/Microsoft.ML.Sweeper/AsyncSweeper.cs @@ -10,7 +10,6 @@ using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.CommandLine; -using Microsoft.ML.Runtime.EntryPoints; using Microsoft.ML.Runtime.Internal.Utilities; using Microsoft.ML.Runtime.Sweeper; diff --git a/src/Microsoft.ML.Sweeper/ConfigRunner.cs b/src/Microsoft.ML.Sweeper/ConfigRunner.cs index 806af2f5e6..504ba298a0 100644 --- a/src/Microsoft.ML.Sweeper/ConfigRunner.cs +++ b/src/Microsoft.ML.Sweeper/ConfigRunner.cs @@ -7,11 +7,8 @@ using System.IO; using System.Linq; using System.Threading.Tasks; - -using Microsoft.ML; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.CommandLine; -using Microsoft.ML.Runtime.EntryPoints; using Microsoft.ML.Runtime.Internal.Utilities; using Microsoft.ML.Runtime.Sweeper;