Skip to content

Commit 3ad489e

Browse files
authored
Updating MKL (#2867)
Enables OpenMP in both ML.Net and in our usage of Intel's MKL library. This also upgrades the reference of MKL to use version 2018.3.10 for Windows, Linux and Mac. The MKL binaries are packaged in MLNetDeps nuget, with this change we are referencing 0.0.9. As a result of these changes, there were other changes that needed to happen: * Build needed to support openmp, for linux, this updated our docker build containers to have openmp installed as part of the clang compiler installation. For mac, openmp was already installed this now occurs though before the build. * Enabled NumberOfThreads parameter for the SymSGDTrainer, NumberOfThreads now defaults to Environment.ProcessorCount
1 parent 0835c52 commit 3ad489e

File tree

19 files changed

+70
-22
lines changed

19 files changed

+70
-22
lines changed

.vsts-dotnet-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
resources:
66
containers:
77
- container: CentosContainer
8-
image: microsoft/dotnet-buildtools-prereqs:centos-7-b46d863-20180719033416
8+
image: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-7-mlnet-8bba86b-20190314145033
99

1010
- container: UbuntuContainer
11-
image: microsoft/dotnet-buildtools-prereqs:ubuntu-16.04-10fcdcf-20190208200917
11+
image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-mlnet-207e097-20190312152303
1212

1313
phases:
1414
- template: /build/ci/phase-template.yml

build/Dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<GoogleProtobufPackageVersion>3.5.1</GoogleProtobufPackageVersion>
1616
<LightGBMPackageVersion>2.2.3</LightGBMPackageVersion>
1717
<MicrosoftMLOnnxRuntimePackageVersion>0.2.1</MicrosoftMLOnnxRuntimePackageVersion>
18-
<MlNetMklDepsPackageVersion>0.0.0.7</MlNetMklDepsPackageVersion>
18+
<MlNetMklDepsPackageVersion>0.0.0.9</MlNetMklDepsPackageVersion>
1919
<ParquetDotNetPackageVersion>2.1.3</ParquetDotNetPackageVersion>
2020
<SystemDrawingCommonPackageVersion>4.5.0</SystemDrawingCommonPackageVersion>
2121
<SystemIOFileSystemAccessControl>4.5.0</SystemIOFileSystemAccessControl>

build/ci/phase-template.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ phases:
3333
${{ insert }}: ${{ parameters.customMatrixes }}
3434
${{ insert }}: ${{ parameters.queue }}
3535
steps:
36+
- ${{ if eq(parameters.name, 'MacOS') }}:
37+
- script: brew update && brew install libomp && brew install mono-libgdiplus gettext && brew link gettext --force && brew link libomp --force
38+
displayName: Install build dependencies
3639
- script: $(_buildScript) -$(_configuration) -buildArch=$(_arch)
3740
displayName: Build
3841
- script: $(_buildScript) -- /t:DownloadExternalTestFiles /p:IncludeBenchmarkData=$(_includeBenchmarkData)
3942
displayName: Download Benchmark Data
40-
- ${{ if eq(parameters.name, 'MacOS') }}:
41-
- script: brew update && brew install libomp mono-libgdiplus gettext && brew link gettext --force
42-
displayName: Install runtime dependencies
4343
- script: $(_buildScript) -$(_configuration) -runtests -coverage=$(_codeCoverage)
4444
displayName: Run Tests.
4545
- script: $(Build.SourcesDirectory)/Tools/dotnetcli/dotnet msbuild build/Codecoverage.proj /p:CodeCovToken=$(CODECOV_TOKEN)

build/vsts-ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
resources:
66
containers:
77
- container: CentosContainer
8-
image: microsoft/dotnet-buildtools-prereqs:centos-7-b46d863-20180719033416
8+
image: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-7-mlnet-8bba86b-20190314145033
99

1010
phases:
1111
################################################################################
@@ -48,6 +48,8 @@ phases:
4848
demands:
4949
- agent.os -equals Darwin
5050
steps:
51+
- script: brew update && brew install libomp && brew link libomp --force
52+
displayName: Install build dependencies
5153
# Only build native assets to avoid conflicts.
5254
- script: ./build.sh -buildNative -$(BuildConfig) -skipRIDAgnosticAssets
5355
displayName: Build

src/Microsoft.ML.Console/Microsoft.ML.Console.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
<NativeAssemblyReference Include="FastTreeNative" />
3232
<NativeAssemblyReference Include="CpuMathNative" />
3333
<NativeAssemblyReference Include="FactorizationMachineNative" />
34+
<NativeAssemblyReference Include="MatrixFactorizationNative" />
3435
<NativeAssemblyReference Include="LdaNative" />
35-
<NativeAssemblyReference Include="SymSgdNative" />
36+
<NativeAssemblyReference Include="SymSgdNative"/>
37+
<NativeAssemblyReference Include="MklImports"/>
38+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
3639
</ItemGroup>
3740

3841
</Project>

src/Microsoft.ML.Mkl.Components/SymSgdClassificationTrainer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public sealed class Options : TrainerInputBaseWithLabel
4343
{
4444
/// <summary>
4545
/// Degree of lock-free parallelism. Determinism not guaranteed if this is set to higher than 1.
46-
/// Multi-threading is not supported currently.
46+
/// The default value is the number of logical cores that are available on the system.
4747
/// </summary>
4848
[Argument(ArgumentType.AtMostOnce, HelpText = "Degree of lock-free parallelism. Determinism not guaranteed. " +
4949
"Multi-threading is not supported currently.", ShortName = "nt")]
@@ -662,7 +662,8 @@ private TPredictor TrainCore(IChannel ch, RoleMappedData data, LinearModelParame
662662
{
663663
int numFeatures = data.Schema.Feature.Value.Type.GetVectorSize();
664664
var cursorFactory = new FloatLabelCursor.Factory(data, CursOpt.Label | CursOpt.Features);
665-
int numThreads = 1;
665+
int numThreads = _options.NumberOfThreads ?? Environment.ProcessorCount;
666+
666667
ch.CheckUserArg(numThreads > 0, nameof(_options.NumberOfThreads),
667668
"The number of threads must be either null or a positive integer.");
668669

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
project (SymSgdNative)
22

3+
34
set(SOURCES
45
SymSgdNative.cpp
56
)
67

7-
find_library(MKL_LIBRARY MklImports HINTS ${MKL_LIB_PATH})
8-
if(NOT WIN32)
8+
if(APPLE)
9+
# CMake has support for OpenMP, however, Apple has a version of Clang
10+
# that does not support openMP out of the box. Therefore
11+
# these commands are added to sepcifically handle the Apple Clang scenario
12+
# If the LLVM version of clang is used for Apple builds, this can be removed
13+
# and the else condition can be used instead.
14+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xpreprocessor -fopenmp")
15+
SET(OPENMP_LIBRARY "omp")
16+
include_directories("/usr/local/opt/libomp/include")
17+
link_directories("/usr/local/opt/libomp/lib")
18+
919
list(APPEND SOURCES ${VERSION_FILE_PATH})
10-
if(NOT APPLE)
20+
else()
21+
find_package(OpenMP)
22+
if (OPENMP_FOUND)
23+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
24+
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
25+
endif()
26+
27+
if (NOT WIN32)
28+
list(APPEND SOURCES ${VERSION_FILE_PATH})
1129
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
1230
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
1331
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1432
SET(CMAKE_INSTALL_RPATH "$ORIGIN/")
1533
endif()
1634
endif()
1735

36+
find_library(MKL_LIBRARY MklImports HINTS ${MKL_LIB_PATH})
37+
38+
add_definitions(-DUSE_OMP)
1839
add_library(SymSgdNative SHARED ${SOURCES} ${RESOURCES})
19-
target_link_libraries(SymSgdNative PUBLIC ${MKL_LIBRARY})
40+
target_link_libraries(SymSgdNative PUBLIC ${MKL_LIBRARY} PUBLIC ${OPENMP_LIBRARY})
2041

2142
if(APPLE)
2243
set_target_properties(SymSgdNative PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/${MKL_LIB_RPATH}}")
2344
endif()
2445

25-
install_library_and_symbols (SymSgdNative)
46+
install_library_and_symbols (SymSgdNative)

src/Native/build.proj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@
7272

7373
<Copy SourceFiles="$(PackagesDir)mlnetmkldeps\$(MlNetMklDepsPackageVersion)\runtimes\$(PackageRid)\native\$(NativeLibPrefix)MklImports$(NativeLibExtension)"
7474
DestinationFolder="$(NativeAssetsBuiltPath)" />
75-
75+
76+
<Copy Condition="'$(OS)' == 'Windows_NT'" SourceFiles="$(PackagesDir)mlnetmkldeps\$(MlNetMklDepsPackageVersion)\runtimes\$(PackageRid)\native\libiomp5md$(NativeLibExtension)"
77+
DestinationFolder="$(NativeAssetsBuiltPath)" />
78+
7679
<ItemGroup Condition="'$(UseIntrinsics)' != 'true'">
7780
<NativePackageAsset Include="$(NativeAssetsBuiltPath)\$(NativeLibPrefix)CpuMathNative$(NativeLibExtension)"
7881
RelativePath="Microsoft.ML.CpuMath\runtimes\$(PackageRid)\native" />

test/Microsoft.ML.Benchmarks/Microsoft.ML.Benchmarks.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
<NativeAssemblyReference Include="CpuMathNative" />
2525
<NativeAssemblyReference Include="FastTreeNative" />
2626
<NativeAssemblyReference Include="MklImports" />
27+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
2728
</ItemGroup>
28-
</Project>
29+
</Project>

test/Microsoft.ML.Core.Tests/Microsoft.ML.Core.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<NativeAssemblyReference Include="MklImports" />
3231
<NativeAssemblyReference Include="MklProxyNative" />
3332
<NativeAssemblyReference Include="CpuMathNative" />
3433
<NativeAssemblyReference Include="FastTreeNative" />
3534
<NativeAssemblyReference Include="LdaNative" />
35+
<NativeAssemblyReference Include="MklImports" />
36+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
3637
</ItemGroup>
3738

3839
<!-- TensorFlow is 64-bit only -->

test/Microsoft.ML.Functional.Tests/Microsoft.ML.Functional.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<NativeAssemblyReference Include="SymSgdNative" />
3939
<NativeAssemblyReference Include="MklProxyNative" />
4040
<NativeAssemblyReference Include="MklImports" />
41+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
4142
</ItemGroup>
4243

4344
<!-- TensorFlow is 64-bit only -->

test/Microsoft.ML.OnnxTransformerTest/Microsoft.ML.OnnxTransformerTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
<ItemGroup>
3232
<NativeAssemblyReference Include="MklImports" />
33+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
3334
</ItemGroup>
3435

3536
</Project>

test/Microsoft.ML.Predictor.Tests/Microsoft.ML.Predictor.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<NativeAssemblyReference Include="FactorizationMachineNative" />
2222
<NativeAssemblyReference Include="SymSgdNative" />
2323
<NativeAssemblyReference Include="MklImports" />
24+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
2425
</ItemGroup>
2526

2627
</Project>

test/Microsoft.ML.StaticPipelineTesting/Microsoft.ML.StaticPipelineTesting.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
<NativeAssemblyReference Include="FastTreeNative" />
2727
<NativeAssemblyReference Include="LdaNative" />
2828
<NativeAssemblyReference Include="MklImports" />
29+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
2930
</ItemGroup>
3031
</Project>

test/Microsoft.ML.Sweeper.Tests/Microsoft.ML.Sweeper.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<NativeAssemblyReference Include="FastTreeNative" />
1111
<NativeAssemblyReference Include="CpuMathNative" />
1212
<NativeAssemblyReference Include="MklImports" />
13+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
1314
</ItemGroup>
1415
</Project>

test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
<NativeAssemblyReference Include="LdaNative" />
2020
<NativeAssemblyReference Include="FastTreeNative" />
2121
<NativeAssemblyReference Include="CpuMathNative" />
22-
<NativeAssemblyReference Include="MklImports" />
2322
<NativeAssemblyReference Include="MklProxyNative" />
2423
<NativeAssemblyReference Include="FactorizationMachineNative" />
2524
<NativeAssemblyReference Include="MatrixFactorizationNative" />
25+
<NativeAssemblyReference Include="MklImports" />
26+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
2627
</ItemGroup>
2728
</Project>

test/Microsoft.ML.Tests/FeatureContributionTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,22 @@ public void TestSDCABinary()
157157
public void TestSGDBinary()
158158
{
159159
TestFeatureContribution(ML.BinaryClassification.Trainers.SgdCalibrated(
160-
new SgdCalibratedTrainer.Options { NumberOfThreads = 1 }),
160+
new SgdCalibratedTrainer.Options()
161+
{
162+
NumberOfThreads = 1
163+
}),
161164
GetSparseDataset(TaskType.BinaryClassification, 100), "SGDBinary");
162165
}
163166

164167
[Fact]
165168
public void TestSSGDBinary()
166169
{
167-
TestFeatureContribution(ML.BinaryClassification.Trainers.SymbolicSgd(), GetSparseDataset(TaskType.BinaryClassification, 100), "SSGDBinary", 4);
170+
TestFeatureContribution(ML.BinaryClassification.Trainers.SymbolicSgd(
171+
new SymbolicSgdTrainer.Options()
172+
{
173+
NumberOfThreads = 1
174+
}),
175+
GetSparseDataset(TaskType.BinaryClassification, 100), "SSGDBinary", 4);
168176
}
169177

170178
[Fact]

test/Microsoft.ML.Tests/Microsoft.ML.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<NativeAssemblyReference Include="SymSgdNative" />
3939
<NativeAssemblyReference Include="MklProxyNative" />
4040
<NativeAssemblyReference Include="MklImports" />
41+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
4142
</ItemGroup>
4243

4344
<!-- TensorFlow is 64-bit only -->

test/Microsoft.ML.TimeSeries.Tests/Microsoft.ML.TimeSeries.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
<NativeAssemblyReference Include="CpuMathNative" />
1414
<NativeAssemblyReference Include="MklProxyNative" />
1515
<NativeAssemblyReference Include="MklImports" />
16+
<NativeAssemblyReference Condition="'$(OS)' == 'Windows_NT'" Include="libiomp5md"/>
1617
</ItemGroup>
17-
</Project>
18+
</Project>

0 commit comments

Comments
 (0)