Skip to content

Need to refactor CpuMath to enable using C# intrinsics APIs on .NET Core #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eerhardt opened this issue Jul 13, 2018 · 0 comments
Closed

Comments

@eerhardt
Copy link
Member

.NET Core 2.1 introduced hardware intrinsics APIs that allow C# code to take full advantage of the CPU. For example, you can now write algorithms using SSE or AVX instructions purely from C# code.

The CpuMathNative assembly exists solely so ML.NET can take advantage of SSE and AVX instructions in its algorithms. When running on .NET Core 2.1+, we can remove our dependency on this native assembly, and instead port the C++ SIMD code to using the new C# intrinsics APIs.

However, to do this (and still support the full .NET Framework), we need to do some refactoring to our assemblies and NuGet packages.

The first thing we need to do is allow Microsoft.ML.CpuMath to be multi-targeted for netstandard2.0;netcoreapp2.1. This will allow us to compile against the netcoreapp2.1 specific SSE APIs.

However, doing that affects our Microsoft.ML nuget package. This is because when you make a nuget package, you put your assemblies into TFM specific folders lib\netstandard2.0, lib\netcoreapp2.1, etc. And the way asset picking works is that once it finds assets for a specific TFM, it stops looking. (The reasoning is typically there is a single assembly per nuget package.) So if we have a single assembly, CpuMath, that needs to go into both lib\netstandard2.0 and lib\netcoreapp2.1, we have a problem. It means ALL our assemblies need to go into BOTH folders, which is unnecessary duplication.

To solve this duplication, I propose to split CpuMath into its own nuget package. So we will have this structure:

  • Microsoft.ML.CpuMath
    • Contains the CpuMath managed assemblies (one for each TFM) and the CpuMathNative assemblies.
  • Microsoft.ML
    • Has a dependency on Microsoft.ML.CpuMath.

In order to do this correctly, we need to remove the assembly reference from Microsoft.ML.CpuMath.dll on Microsoft.ML.Core.dll. This is because the nuget dependency goes the other way. The only reason Microsoft.ML.CpuMath.dll depends on Microsoft.ML.Core.dll is so it can use the Contracts class. We can break this dependency by using the PRIVATE_CONTRACTS define constant, and source linking the Contracts.cs file into CpuMath.

/cc @TomFinley @ericstj @briancylui @tannergooding

eerhardt added a commit to eerhardt/machinelearning that referenced this issue Jul 17, 2018
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
eerhardt added a commit that referenced this issue Jul 19, 2018
* 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 #534

* Respond to PR feedback.
eerhardt added a commit to eerhardt/machinelearning that referenced this issue Jul 27, 2018
* 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.
codemzs pushed a commit to codemzs/machinelearning that referenced this issue Aug 1, 2018
* 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.
@ghost ghost locked as resolved and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant