Skip to content

Arm build changes #5789

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

Merged
merged 16 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*.user
*.userosscache
*.sln.docstates
*.DS_Store

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand All @@ -37,6 +38,9 @@ msbuild.binlog
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# VSCode files
.vscode/

# Visual Studio 2017 auto generated files
Generated\ Files/

Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<Configurations>Debug;Release;Debug-netcoreapp3_1;Release-netcoreapp3_1;Debug-netfx;Release-netfx</Configurations>
<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
<NativeTargetArchitecture Condition="'$(NativeTargetArchitecture)' == ''">$(TargetArchitecture)</NativeTargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</TargetArchitecture>
<TargetArchitecture>$(TargetArchitecture.ToLower())</TargetArchitecture>
<PlatformConfig>$(Platform).$(Configuration)</PlatformConfig>
<StrongNameKeyId>Open</StrongNameKeyId>
</PropertyGroup>
Expand Down
36 changes: 21 additions & 15 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,33 @@

<Target Name="CopyNativeAssembiles" AfterTargets="CopyFilesToOutputDirectory">
<PropertyGroup>
<LibPrefix Condition="'$(OS)' != 'Windows_NT'">lib</LibPrefix>
<LibExtension Condition="'$(OS)' == 'Windows_NT'">.dll</LibExtension>
<LibExtension Condition="'$(OS)' != 'Windows_NT'">.so</LibExtension>
<LibExtension Condition="$([MSBuild]::IsOSPlatform('osx'))">.dylib</LibExtension>
<LibPrefix Condition="'$(OS)' != 'Windows_NT'">lib</LibPrefix>
<LibExtension Condition="'$(OS)' == 'Windows_NT'">.dll</LibExtension>
<LibExtension Condition="'$(OS)' != 'Windows_NT'">.so</LibExtension>
<LibExtension Condition="$([MSBuild]::IsOSPlatform('osx'))">.dylib</LibExtension>

<TargetArchitecture Condition="'$(Platform)' == ''">x64</TargetArchitecture>
<NativeTargetArchitecture Condition="'$(NativeTargetArchitecture)' == ''">$(TargetArchitecture)</NativeTargetArchitecture>
<BinDir Condition="'$(BinDir)'==''">$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin'))</BinDir>
<NativeOutputPath>$(BinDir)Native\$(NativeTargetArchitecture).$(Configuration)\</NativeOutputPath>
<BinDir Condition="'$(BinDir)'==''">$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', 'bin'))</BinDir>
<NativeOutputPath>$(BinDir)Native\$(TargetArchitecture).$(Configuration)\</NativeOutputPath>

<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
<PlatformConfig>$(Platform).$(Configuration)</PlatformConfig>
<OutputPath Condition="'$(OutputPath)'==''">$(BinDir)$(MSBuildProjectName)\Debug</OutputPath>
</PropertyGroup>
<Platform Condition="'$(Platform)'==''">AnyCPU</Platform>
<PlatformConfig>$(Platform).$(Configuration)</PlatformConfig>
<OutputPath Condition="'$(OutputPath)'==''">$(BinDir)$(MSBuildProjectName)\Debug</OutputPath>
</PropertyGroup>

<ItemGroup>
<NativeAssemblyReference>
<FullAssemblyPath>$(NativeOutputPath)$(LibPrefix)%(NativeAssemblyReference.Identity)$(LibExtension)</FullAssemblyPath>
</NativeAssemblyReference>
<NativeAssemblyReference>
<FullAssemblyPath>$(NativeOutputPath)$(LibPrefix)%(NativeAssemblyReference.Identity)$(LibExtension)</FullAssemblyPath>
</NativeAssemblyReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetArchitecture)' == 'arm64' Or '$(TargetArchitecture)' == 'arm'">
<NativeAssemblyReference Remove="MklImports"/>
<NativeAssemblyReference Remove="CpuMathNative"/>
<NativeAssemblyReference Remove="FastTreeNative"/>
<NativeAssemblyReference Remove="SymSgdNative"/>
<NativeAssemblyReference Remove="MklProxyNative"/>
</ItemGroup>

<Copy SourceFiles = "@(NativeAssemblyReference->'%(FullAssemblyPath)')"
DestinationFolder="$(OutDir)"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Expand Down
16 changes: 16 additions & 0 deletions docs/building/unix-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ sudo apt-get install libssl1.0.0 libicu55
sudo apt-get install libomp-dev
```

#### Cross compiling for ARM

Cross compilation is only supported on an Ubuntu host, 18.x and newer, and only .Net Core 3.1 or newer. You will need to install debootstrap and qemu-user-static to facilitate the process. Once they are installed you will need to build the cross compiling rootfs. We provide a script, `build-rootfs.sh`, to do this. You will also need to set the ROOTFS_DIR environment variable to the location of the rootfs you just created. The general process is as follows:

```sh
sudo apt-get update
sudo apt-get install debootstrap qemu-user-static
sudo ./eng/common/cross/build-rootfs.sh <target architecture> <ubuntu distro name> --rootfsdir <new rootfs location>
export ROOTFS_DIR=<new rootfs location>

# The cross compiling environment is now setup and you can proceed with a normal build
./build.sh -c Release-netcoreapp3_1 /p:TargetArchitecture=<target architecture>
```

Note that the `<target architecture>` will usually be arm or arm64 and the `<ubuntu distro name>` is bionic for 18.04.

### macOS

macOS 10.13 (High Sierra) or higher is needed to build dotnet/machinelearning. We are using a .NET Core 3.1 SDK to build, which supports 10.13 or higher.
Expand Down
24 changes: 22 additions & 2 deletions docs/building/windows-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can build ML.NET either via the command line or by using Visual Studio.
2. **[CMake](https://cmake.org/)** must be installed from [the CMake download page](https://cmake.org/download/#latest) and added to your path.

### Visual Studio 2019 Installation
We have successfully verified the below build instructions for Visual Studio version 16.4 and higher.
We have successfully verified the below build instructions for Visual Studio version 16.4 and higher.

#### Visual Studio 2019 - 'Workloads' based install

Expand Down Expand Up @@ -37,6 +37,12 @@ The following are the minimum requirements:
* .NET Framework 4.6 Targeting Pack
* Windows Universal CRT SDK

#### Visual Studio 2019 - Cross compilation for ARM

If you want to cross compile for arm you will also need from the 'Individual components' section:
* MSVC v142 - VS 2019 C++ ARM build tools
* MSVC v142 - VS 2019 C++ ARM64 build tools

## Building Instructions

In order to fetch dependencies which come through Git submodules the following command needs to be run before building: `git submodule update --init`.
Expand All @@ -51,7 +57,7 @@ After successfully running the command, the project can be built directly from t

### Building From the Command Line

You can use the Developer Command Prompt, Powershell or work in any regular cmd. The Developer Command Prompt will have a name like "Developer Command Prompt for VS 2019" or similar in your start menu.
You can use the Developer Command Prompt, Powershell or work in any regular cmd. The Developer Command Prompt will have a name like "Developer Command Prompt for VS 2019" or similar in your start menu.

From a (non-admin) Command Prompt window:

Expand All @@ -61,6 +67,20 @@ From a (non-admin) Command Prompt window:

**Note**: Before working on individual projects or test projects you **must** run `build.cmd` from the root once before beginning that work. It is also a good idea to run `build.cmd` whenever you pull a large set of unknown changes into your branch.

### Cross compiling for ARM

You can use the Developer Command Prompt, Powershell or work in any regular cmd. The Developer Command Prompt will have a name like "Developer Command Prompt for VS 2019" or similar in your start menu.

From a (non-admin) Command Prompt window based on what you want to target:

- `build.cmd /p:TargetArchitecture=arm`
- `build.cmd /p:TargetArchitecture=arm64`

You can then pack them into nugets, pick the same target architecture you built with:

- `build.cmd /p:TargetArchitecture=arm -pack`
- `build.cmd /p:TargetArchitecture=arm64 -pack`

## Running Tests

### Running tests from Visual Studio
Expand Down
4 changes: 4 additions & 0 deletions eng/common/cross/build-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ __UbuntuPackages+=" libssl-dev"
__UbuntuPackages+=" zlib1g-dev"
__UbuntuPackages+=" libldap2-dev"

# ML.NET dependencies
__UbuntuPackages+=" libomp5"
__UbuntuPackages+=" libomp-dev"

__AlpinePackages+=" curl-dev"
__AlpinePackages+=" krb5-dev"
__AlpinePackages+=" openssl-dev"
Expand Down
44 changes: 28 additions & 16 deletions src/Microsoft.ML.FastTree/Dataset/DenseIntArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ internal abstract class DenseIntArray : IntArray, IIntArrayForwardIndexer
{
public override IntArrayType Type { get { return IntArrayType.Dense; } }

protected DenseIntArray(int length)
protected DenseIntArray(int length, PerformSumup sumupHandler = null)
{
Contracts.Assert(length >= 0);
Length = length;
SumupHandler = sumupHandler;
}

public override int Length { get; }
Expand Down Expand Up @@ -70,7 +71,6 @@ public override IntArray[] Split(int[][] assignment)
return newArrays;
}

#if USE_FASTTREENATIVE
internal const string NativePath = "FastTreeNative";
[DllImport(NativePath), SuppressUnmanagedCodeSecurity]
private static extern unsafe int C_Sumup_float(
Expand Down Expand Up @@ -111,8 +111,6 @@ protected static unsafe void SumupCPlusPlusDense(SumupInputData input, FeatureHi
}
}

#endif

public override IIntArrayForwardIndexer GetIndexer()
{
return this;
Expand Down Expand Up @@ -391,18 +389,21 @@ public Dense8BitIntArray(int len)
: base(len)
{
_data = new byte[len];
SetupSumupHandler(SumupNative, base.Sumup);
}

public Dense8BitIntArray(byte[] buffer, ref int position)
: base(buffer.ToInt(ref position))
{
_data = buffer.ToByteArray(ref position);
SetupSumupHandler(SumupNative, base.Sumup);
}

public Dense8BitIntArray(int len, IEnumerable<int> values)
: base(len)
{
_data = values.Select(i => (byte)i).ToArray(len);
SetupSumupHandler(SumupNative, base.Sumup);
}

/// <summary>
Expand Down Expand Up @@ -445,8 +446,7 @@ public override unsafe int this[int index]
}
}

#if USE_FASTTREENATIVE
public override void Sumup(SumupInputData input, FeatureHistogram histogram)
private void SumupNative(SumupInputData input, FeatureHistogram histogram)
{
unsafe
{
Expand All @@ -456,7 +456,8 @@ public override void Sumup(SumupInputData input, FeatureHistogram histogram)
}
}
}
#endif

public override void Sumup(SumupInputData input, FeatureHistogram histogram) => SumupHandler(input, histogram);
}

/// <summary>
Expand All @@ -475,12 +476,14 @@ public Dense4BitIntArray(int len)
: base(len)
{
_data = new byte[(len + 1) / 2]; // Even length = half the bytes. Odd length = half the bytes+0.5.
SetupSumupHandler(SumupNative, base.Sumup);
}

public Dense4BitIntArray(int len, IEnumerable<int> values)
: base(len)
{
_data = new byte[(len + 1) / 2];
SetupSumupHandler(SumupNative, base.Sumup);

int currentIndex = 0;
bool upper = true;
Expand All @@ -505,6 +508,7 @@ public Dense4BitIntArray(byte[] buffer, ref int position)
: base(buffer.ToInt(ref position))
{
_data = buffer.ToByteArray(ref position);
SetupSumupHandler(SumupNative, base.Sumup);
}

/// <summary>
Expand Down Expand Up @@ -565,8 +569,7 @@ public override unsafe int this[int index]
}
}

#if USE_FASTTREENATIVE
public override void Sumup(SumupInputData input, FeatureHistogram histogram)
public void SumupNative(SumupInputData input, FeatureHistogram histogram)
{
unsafe
{
Expand All @@ -576,7 +579,8 @@ public override void Sumup(SumupInputData input, FeatureHistogram histogram)
}
}
}
#endif

public override void Sumup(SumupInputData input, FeatureHistogram histogram) => SumupHandler(input, histogram);
}

/// <summary>
Expand All @@ -592,18 +596,21 @@ public Dense16BitIntArray(int len)
: base(len)
{
_data = new ushort[len];
SetupSumupHandler(SumupNative, base.Sumup);
}

public Dense16BitIntArray(int len, IEnumerable<int> values)
: base(len)
{
_data = values.Select(i => (ushort)i).ToArray(len);
SetupSumupHandler(SumupNative, base.Sumup);
}

public Dense16BitIntArray(byte[] buffer, ref int position)
: base(buffer.ToInt(ref position))
{
_data = buffer.ToUShortArray(ref position);
SetupSumupHandler(SumupNative, base.Sumup);
}

public override unsafe void Callback(Action<IntPtr> callback)
Expand Down Expand Up @@ -648,8 +655,8 @@ public override unsafe int this[int index]
_data[index] = (ushort)value;
}
}
#if USE_FASTTREENATIVE
public override void Sumup(SumupInputData input, FeatureHistogram histogram)

public void SumupNative(SumupInputData input, FeatureHistogram histogram)
{
unsafe
{
Expand All @@ -660,7 +667,9 @@ public override void Sumup(SumupInputData input, FeatureHistogram histogram)
}
}
}
#endif

public override void Sumup(SumupInputData input, FeatureHistogram histogram) => SumupHandler(input, histogram);

}

/// <summary>
Expand All @@ -676,18 +685,21 @@ public Dense32BitIntArray(int len)
: base(len)
{
_data = new int[len];
SetupSumupHandler(SumupNative, base.Sumup);
}

public Dense32BitIntArray(int len, IEnumerable<int> values)
: base(len)
{
_data = values.ToArray(len);
SetupSumupHandler(SumupNative, base.Sumup);
}

public Dense32BitIntArray(byte[] buffer, ref int position)
: base(buffer.ToInt(ref position))
{
_data = buffer.ToIntArray(ref position);
SetupSumupHandler(SumupNative, base.Sumup);
}

public override unsafe void Callback(Action<IntPtr> callback)
Expand Down Expand Up @@ -733,8 +745,7 @@ public override int this[int index]
}
}

#if USE_FASTTREENATIVE
public override void Sumup(SumupInputData input, FeatureHistogram histogram)
public void SumupNative(SumupInputData input, FeatureHistogram histogram)
{
unsafe
{
Expand All @@ -745,6 +756,7 @@ public override void Sumup(SumupInputData input, FeatureHistogram histogram)
}
}
}
#endif

public override void Sumup(SumupInputData input, FeatureHistogram histogram) => SumupHandler(input, histogram);
}
}
Loading