Skip to content

Commit 8099f58

Browse files
authored
Contracts.Assert statements valid for Debug-Intrinsics (dotnet#1676)
* Contracts.Assert statements valid for Debug-Intrinsics * Fixing netcoreapp 3.0 build
1 parent feddc72 commit 8099f58

6 files changed

+5
-19
lines changed

Directory.Build.props

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<!-- Taken from https://github.com/dotnet/sdk/blob/073c98b92c81066c6c2e17c3674adbb6e833409a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props#L41-L47 -->
114114
<PropertyGroup Condition="'$(Configuration)' == 'Debug-Intrinsics'">
115115
<DebugSymbols>true</DebugSymbols>
116+
<DefineConstants>$(DefineContants);DEBUG</DefineConstants>
116117
<Optimize>false</Optimize>
117118
</PropertyGroup>
118119
<PropertyGroup Condition="'$(Configuration)' == 'Release-Intrinsics'">

src/Microsoft.ML.CpuMath/AssemblyInfo.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.ML;
77

88
[assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netstandard" + PublicKey.TestValue)]
9+
[assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netcoreapp" + PublicKey.TestValue)]
910
[assembly: InternalsVisibleTo("Microsoft.ML.Data" + PublicKey.Value)]
1011
[assembly: InternalsVisibleTo("Microsoft.ML.FastTree" + PublicKey.Value)]
1112
[assembly: InternalsVisibleTo("Microsoft.ML.HalLearners" + PublicKey.Value)]

src/Microsoft.ML.CpuMath/AvxIntrinsics.cs

-9
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,13 @@ 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-
158156
MatMul(mat.Items, src.Items, dst.Items, crow, ccol);
159157
}
160158

161159
public static unsafe void MatMul(ReadOnlySpan<float> mat, ReadOnlySpan<float> src, Span<float> dst, int crow, int ccol)
162160
{
163161
Contracts.Assert(crow % 4 == 0);
164162
Contracts.Assert(ccol % 4 == 0);
165-
Contracts.Assert(src.Length == dst.Length);
166163

167164
fixed (float* psrc = &MemoryMarshal.GetReference(src))
168165
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
@@ -310,8 +307,6 @@ public static unsafe void MatMul(ReadOnlySpan<float> mat, ReadOnlySpan<float> sr
310307
public static unsafe void MatMulP(AlignedArray mat, ReadOnlySpan<int> rgposSrc, AlignedArray src,
311308
int posMin, int iposMin, int iposEnd, AlignedArray dst, int crow, int ccol)
312309
{
313-
Contracts.Assert(src.Size == dst.Size);
314-
315310
MatMulP(mat.Items, rgposSrc, src.Items, posMin, iposMin, iposEnd, dst.Items, crow, ccol);
316311
}
317312

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

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

475469
public static unsafe void MatMulTran(AlignedArray mat, AlignedArray src, AlignedArray dst, int crow, int ccol)
476470
{
477-
Contracts.Assert(src.Size == dst.Size);
478-
479471
MatMulTran(mat.Items, src.Items, dst.Items, crow, ccol);
480472
}
481473

482474
public static unsafe void MatMulTran(ReadOnlySpan<float> mat, ReadOnlySpan<float> src, Span<float> dst, int crow, int ccol)
483475
{
484476
Contracts.Assert(crow % 4 == 0);
485477
Contracts.Assert(ccol % 4 == 0);
486-
Contracts.Assert(src.Length == dst.Length);
487478

488479
fixed (float* psrc = &MemoryMarshal.GetReference(src))
489480
fixed (float* pdst = &MemoryMarshal.GetReference(dst))

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

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public static void MatrixTimesSource(bool transpose, AlignedArray matrix, Aligne
9191
public static void MatrixTimesSource(AlignedArray matrix, ReadOnlySpan<int> rgposSrc, AlignedArray sourceValues,
9292
int posMin, int iposMin, int iposLimit, AlignedArray destination, int stride)
9393
{
94-
Contracts.AssertValue(rgposSrc);
9594
Contracts.Assert(iposMin >= 0);
9695
Contracts.Assert(iposMin <= iposLimit);
9796
Contracts.Assert(iposLimit <= rgposSrc.Length);

src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<Compile Remove="AvxIntrinsics.cs" />
2323

2424
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
2528
<ProjectReference Include="..\..\src\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
2629
</ItemGroup>
2730

src/Microsoft.ML.CpuMath/SseIntrinsics.cs

-9
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,13 @@ internal static Vector128<float> GetNewDst128(in Vector128<float> xDst1, in Vect
117117
// Multiply matrix times vector into vector.
118118
public static unsafe void MatMul(AlignedArray mat, AlignedArray src, AlignedArray dst, int crow, int ccol)
119119
{
120-
Contracts.Assert(src.Size == dst.Size);
121-
122120
MatMul(mat.Items, src.Items, dst.Items, crow, ccol);
123121
}
124122

125123
public static unsafe void MatMul(ReadOnlySpan<float> mat, ReadOnlySpan<float> src, Span<float> dst, int crow, int ccol)
126124
{
127125
Contracts.Assert(crow % 4 == 0);
128126
Contracts.Assert(ccol % 4 == 0);
129-
Contracts.Assert(src.Length == dst.Length);
130127

131128
fixed (float* psrc = &MemoryMarshal.GetReference(src))
132129
fixed (float* pdst = &MemoryMarshal.GetReference(dst))
@@ -282,15 +279,12 @@ public static unsafe void MatMul(ReadOnlySpan<float> mat, ReadOnlySpan<float> sr
282279
public static unsafe void MatMulP(AlignedArray mat, ReadOnlySpan<int> rgposSrc, AlignedArray src,
283280
int posMin, int iposMin, int iposEnd, AlignedArray dst, int crow, int ccol)
284281
{
285-
Contracts.Assert(src.Size == dst.Size);
286-
287282
MatMulP(mat.Items, rgposSrc, src.Items, posMin, iposMin, iposEnd, dst.Items, crow, ccol);
288283
}
289284

290285
public static unsafe void MatMulP(ReadOnlySpan<float> mat, ReadOnlySpan<int> rgposSrc, ReadOnlySpan<float> src,
291286
int posMin, int iposMin, int iposEnd, Span<float> dst, int crow, int ccol)
292287
{
293-
Contracts.Assert(src.Length == dst.Length);
294288
Contracts.Assert(crow % 4 == 0);
295289
Contracts.Assert(ccol % 4 == 0);
296290

@@ -449,14 +443,11 @@ Vector128<float> SparseMultiplicationAcrossRow()
449443

450444
public static unsafe void MatMulTran(AlignedArray mat, AlignedArray src, AlignedArray dst, int crow, int ccol)
451445
{
452-
Contracts.Assert(src.Size == dst.Size);
453-
454446
MatMulTran(mat.Items, src.Items, dst.Items, crow, ccol);
455447
}
456448

457449
public static unsafe void MatMulTran(ReadOnlySpan<float> mat, ReadOnlySpan<float> src, Span<float> dst, int crow, int ccol)
458450
{
459-
Contracts.Assert(src.Length == dst.Length);
460451
Contracts.Assert(crow % 4 == 0);
461452
Contracts.Assert(ccol % 4 == 0);
462453

0 commit comments

Comments
 (0)