Skip to content

Commit 598b05f

Browse files
committed
Allow CpuMath to reference C# Hardware Intrinsics APIs. (dotnet#542)
* Allow CpuMath to reference C# Hardware Intrinsics APIs. Need to multi-target CpuMath for netstandard and netcoreapp3.0. Also, since we are going to move CpuMath into its own NuGet package, remove the dependency from CpuMath to the ML.Core project. Add a build parameter to enable building against .NET Core 3.0's Runtime Intrinsics APIs. Fix dotnet#534 * Respond to PR feedback.
1 parent 61d044a commit 598b05f

File tree

8 files changed

+168
-10
lines changed

8 files changed

+168
-10
lines changed

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
<PropertyGroup>
1515
<RestoreSources>
1616
https://api.nuget.org/v3/index.json;
17+
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
1718
</RestoreSources>
1819
</PropertyGroup>
1920

2021
<!-- Common repo directories -->
2122
<PropertyGroup>
2223
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
2324
<SourceDir>$(RepoRoot)src/</SourceDir>
25+
<PkgDir>$(RepoRoot)pkg/</PkgDir>
2426

2527
<!-- Output directories -->
2628
<BinDir Condition="'$(BinDir)'==''">$(RepoRoot)bin/</BinDir>

Microsoft.ML.sln

Lines changed: 113 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">
2+
3+
<PropertyGroup>
4+
<TargetFramework Condition="'$(UseIntrinsics)' != 'true'">netstandard2.0</TargetFramework>
5+
<TargetFrameworks Condition="'$(UseIntrinsics)' == 'true'">netstandard2.0;netcoreapp3.0</TargetFrameworks>
6+
<PackageDescription>Microsoft.ML.CpuMath contains optimized math routines for ML.NET.</PackageDescription>
7+
</PropertyGroup>
8+
9+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
10+
<!-- This is only needed until https://github.com/dotnet/corefx/issues/31064 is addressed. -->
11+
<PackageReference Include="System.Runtime.Intrinsics.Experimental" Version="4.6.0-preview1-26708-04" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project DefaultTargets="Pack">
2+
3+
<Import Project="Microsoft.ML.CpuMath.nupkgproj" />
4+
5+
</Project>

pkg/Microsoft.ML/Microsoft.ML.nupkgproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<ProjectReference Include="../Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.nupkgproj" />
10+
911
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1012
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="$(SystemReflectionEmitLightweightPackageVersion)" />
1113
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="$(SystemThreadingTasksDataflowPackageVersion)" />

pkg/_._

Whitespace-only changes.
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<IncludeInPackage>Microsoft.ML</IncludeInPackage>
4+
<Configurations>Debug;Release;Debug-Intrinsics;Release-Intrinsics</Configurations>
5+
<UseIntrinsics Condition="'$(UseIntrinsics)' == ''">$(Configuration.EndsWith('-Intrinsics'))</UseIntrinsics>
6+
7+
<TargetFramework Condition="'$(UseIntrinsics)' != 'true'">netstandard2.0</TargetFramework>
8+
<TargetFrameworks Condition="'$(UseIntrinsics)' == 'true'">netstandard2.0;netcoreapp3.0</TargetFrameworks>
9+
<IncludeInPackage>Microsoft.ML.CpuMath</IncludeInPackage>
610
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7-
<DefineConstants>CORECLR</DefineConstants>
11+
<DefineConstants>$(DefineConstants);CORECLR;PRIVATE_CONTRACTS</DefineConstants>
812
</PropertyGroup>
913

1014
<ItemGroup>
11-
<ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
15+
<Compile Include="..\Microsoft.ML.Core\Utilities\Contracts.cs" />
1216
</ItemGroup>
1317

18+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
19+
<!-- This is only needed until https://github.com/dotnet/corefx/issues/31064 is addressed. -->
20+
<PackageReference Include="System.Runtime.Intrinsics.Experimental" Version="4.6.0-preview1-26708-04" />
21+
</ItemGroup>
1422
</Project>

src/Native/build.proj

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.props))\Directory.Build.props" />
1111

1212
<!-- Target that builds all the native binaries in the Native folder -->
13-
<Target Name="Build" DependsOnTargets="BuildNativeUnix;BuildNativeWindows;PreparePackageAssets" />
13+
<Target Name="Build" DependsOnTargets="BuildNativeUnix;BuildNativeWindows;PreparePackageAssets" />
1414

15+
<PropertyGroup>
16+
<PlaceholderFile>$(PkgDir)_._</PlaceholderFile>
17+
</PropertyGroup>
18+
1519
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
1620
<GenerateVersionSourceFile>true</GenerateVersionSourceFile>
1721
<NativeVersionSourceFile>$(BaseIntermediateOutputPath)version.c</NativeVersionSourceFile>
@@ -68,19 +72,29 @@
6872
<PackageRid>$(PackageRid)-$(TargetArchitecture)</PackageRid>
6973
</PropertyGroup>
7074

71-
<ItemGroup>
75+
<ItemGroup Condition="'$(UseIntrinsics)' != 'true'">
7276
<NativePackageAsset Include="$(NativeAssetsBuiltPath)\$(NativeLibPrefix)CpuMathNative$(NativeLibExtension)"
73-
RelativePath="Microsoft.ML\runtimes\$(PackageRid)\native" />
77+
RelativePath="Microsoft.ML.CpuMath\runtimes\$(PackageRid)\native" />
78+
</ItemGroup>
79+
<ItemGroup Condition="'$(UseIntrinsics)' == 'true'">
80+
<NativePackageAsset Include="$(NativeAssetsBuiltPath)\$(NativeLibPrefix)CpuMathNative$(NativeLibExtension)"
81+
RelativePath="Microsoft.ML.CpuMath\runtimes\$(PackageRid)\nativeassets\netstandard2.0" />
82+
<NativePackageAsset Include="$(PlaceholderFile)"
83+
RelativePath="Microsoft.ML.CpuMath\runtimes\$(PackageRid)\nativeassets\netcoreapp3.0" />
84+
</ItemGroup>
85+
86+
<ItemGroup>
7487
<NativePackageAsset Include="$(NativeAssetsBuiltPath)\$(NativeLibPrefix)FastTreeNative$(NativeLibExtension)"
7588
RelativePath="Microsoft.ML\runtimes\$(PackageRid)\native" />
76-
<NativePackageAsset Include="$(NativeAssetsBuiltPath)\$(NativeLibPrefix)LdaNative$(NativeLibExtension)"
89+
<NativePackageAsset Include="$(NativeAssetsBuiltPath)\$(NativeLibPrefix)LdaNative$(NativeLibExtension)"
7790
RelativePath="Microsoft.ML\runtimes\$(PackageRid)\native" />
7891
<NativePackageAsset Include="$(NativeAssetsBuiltPath)\$(NativeLibPrefix)FactorizationMachineNative$(NativeLibExtension)"
7992
RelativePath="Microsoft.ML\runtimes\$(PackageRid)\native" />
8093
</ItemGroup>
8194

8295
<ItemGroup>
83-
<NativePackageAsset Condition="'$(OS)' == 'Windows_NT' OR '$(StripNativeSymbols)' == 'True'"
96+
<NativePackageAsset Condition="('$(OS)' == 'Windows_NT' OR '$(StripNativeSymbols)' == 'True')
97+
AND '%(NativePackageAsset.Identity)' != '$(PlaceholderFile)'"
8498
Include="@(NativePackageAsset->'%(RootDir)%(Directory)%(Filename)$(NativeLibSymbolExtension)')" />
8599
</ItemGroup>
86100

0 commit comments

Comments
 (0)