Browse Source

Providers: attempt to use runtimes folders in provider packages (hybrid)

dependabot/nuget/NUnit3TestAdapter-4.2.0
Christoph Ruegg 5 years ago
parent
commit
d177c11972
  1. 16
      build/MathNet.Numerics.CUDA.Win.nuspec
  2. 12
      build/MathNet.Numerics.MKL.Linux-x64.nuspec
  3. 12
      build/MathNet.Numerics.MKL.Linux-x86.nuspec
  4. 16
      build/MathNet.Numerics.MKL.Linux.nuspec
  5. 12
      build/MathNet.Numerics.MKL.Win-x64.nuspec
  6. 12
      build/MathNet.Numerics.MKL.Win-x86.nuspec
  7. 16
      build/MathNet.Numerics.MKL.Win.nuspec
  8. 28
      build/MathNet.Numerics.OpenBLAS.Win.nuspec
  9. 6
      build/NativeProvider.targets
  10. 106
      src/Providers.CUDA/NativeProviderLoader.cs
  11. 108
      src/Providers.MKL/NativeProviderLoader.cs
  12. 106
      src/Providers.OpenBLAS/NativeProviderLoader.cs

16
build/MathNet.Numerics.CUDA.Win.nuspec

@ -5,24 +5,22 @@
<version>@build.number@</version>
<title>Math.NET Numerics - CUDA Native Provider for Windows (x64)</title>
<authors>Matthew A Johnson, Christoph Ruegg</authors>
<owners>Matthew A Johnson, Christoph Ruegg</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>Nvidia CUDA native libraries for Math.NET Numerics.</description>
<summary>Nvidia CUDA native libraries for Math.NET Numerics.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native cuda gpu</tags>
</metadata>
<files>
<file src="..\..\out\CUDA\Windows\x64\cublas64_70.dll" target="build\x64\cublas64_70.dll" />
<file src="..\..\out\CUDA\Windows\x64\cudart64_70.dll" target="build\x64\cudart64_70.dll" />
<file src="..\..\out\CUDA\Windows\x64\cusolver64_70.dll" target="build\x64\cusolver64_70.dll" />
<file src="..\..\out\CUDA\Windows\x64\MathNet.Numerics.CUDA.dll" target="build\x64\MathNet.Numerics.CUDA.dll" />
<file src="..\..\out\CUDA\Windows\x64\cublas64_70.dll" target="runtimes\win-x64\native\cublas64_70.dll" />
<file src="..\..\out\CUDA\Windows\x64\cudart64_70.dll" target="runtimes\win-x64\native\cudart64_70.dll" />
<file src="..\..\out\CUDA\Windows\x64\cusolver64_70.dll" target="runtimes\win-x64\native\cusolver64_70.dll" />
<file src="..\..\out\CUDA\Windows\x64\MathNet.Numerics.CUDA.dll" target="runtimes\win-x64\native\MathNet.Numerics.CUDA.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.CUDA.Win.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

12
build/MathNet.Numerics.MKL.Linux-x64.nuspec

@ -5,23 +5,21 @@
<version>@build.number@</version>
<title>Math.NET Numerics - MKL Native Provider for Linux (x64)</title>
<authors>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</authors>
<owners>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>Intel MKL native libraries for Math.NET Numerics on Linux.</description>
<summary>Intel MKL native libraries for Math.NET Numerics on Linux.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native mkl</tags>
@dependencies@
</metadata>
<files>
<file src="..\..\out\MKL\Linux\x64\libiomp5.so" target="build\x64\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x64\MathNet.Numerics.MKL.dll" target="build\x64\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Linux\x64\libiomp5.so" target="runtimes\linux-x64\native\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x64\MathNet.Numerics.MKL.dll" target="runtimes\linux-x64\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.MKL.Linux-x64.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

12
build/MathNet.Numerics.MKL.Linux-x86.nuspec

@ -5,23 +5,21 @@
<version>@build.number@</version>
<title>Math.NET Numerics - MKL Native Provider for Linux (x86)</title>
<authors>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</authors>
<owners>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>Intel MKL native libraries for Math.NET Numerics on Linux.</description>
<summary>Intel MKL native libraries for Math.NET Numerics on Linux.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native mkl</tags>
@dependencies@
</metadata>
<files>
<file src="..\..\out\MKL\Linux\x86\libiomp5.so" target="build\x86\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x86\MathNet.Numerics.MKL.dll" target="build\x86\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Linux\x86\libiomp5.so" target="runtimes\linux-x86\native\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x86\MathNet.Numerics.MKL.dll" target="runtimes\linux-x86\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.MKL.Linux-x86.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

16
build/MathNet.Numerics.MKL.Linux.nuspec

@ -5,25 +5,23 @@
<version>@build.number@</version>
<title>Math.NET Numerics - MKL Native Provider for Linux (x64 and x86)</title>
<authors>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</authors>
<owners>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>Intel MKL native libraries for Math.NET Numerics on Linux.</description>
<summary>Intel MKL native libraries for Math.NET Numerics on Linux.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native mkl</tags>
@dependencies@
</metadata>
<files>
<file src="..\..\out\MKL\Linux\x64\libiomp5.so" target="build\x64\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x64\MathNet.Numerics.MKL.dll" target="build\x64\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Linux\x86\libiomp5.so" target="build\x86\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x86\MathNet.Numerics.MKL.dll" target="build\x86\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Linux\x64\libiomp5.so" target="runtimes\linux-x64\native\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x64\MathNet.Numerics.MKL.dll" target="runtimes\linux-x64\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Linux\x86\libiomp5.so" target="runtimes\linux-x86\native\libiomp5.so" />
<file src="..\..\out\MKL\Linux\x86\MathNet.Numerics.MKL.dll" target="runtimes\linux-x86\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.MKL.Linux.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

12
build/MathNet.Numerics.MKL.Win-x64.nuspec

@ -5,23 +5,21 @@
<version>@build.number@</version>
<title>Math.NET Numerics - MKL Native Provider for Windows (x64)</title>
<authors>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</authors>
<owners>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>Intel oneAPI MKL native libraries for Math.NET Numerics on Windows.</description>
<summary>Intel oneAPI MKL native libraries for Math.NET Numerics on Windows.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native mkl</tags>
@dependencies@
</metadata>
<files>
<file src="..\..\out\MKL\Windows\x64\libiomp5md.dll" target="build\x64\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x64\MathNet.Numerics.MKL.dll" target="build\x64\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Windows\x64\libiomp5md.dll" target="runtimes\win-x64\native\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x64\MathNet.Numerics.MKL.dll" target="runtimes\win-x64\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.MKL.Win-x64.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

12
build/MathNet.Numerics.MKL.Win-x86.nuspec

@ -5,23 +5,21 @@
<version>@build.number@</version>
<title>Math.NET Numerics - MKL Native Provider for Windows (x86)</title>
<authors>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</authors>
<owners>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>Intel oneAPI MKL native libraries for Math.NET Numerics on Windows.</description>
<summary>Intel oneAPI MKL native libraries for Math.NET Numerics on Windows.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native mkl</tags>
@dependencies@
</metadata>
<files>
<file src="..\..\out\MKL\Windows\x86\libiomp5md.dll" target="build\x86\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x86\MathNet.Numerics.MKL.dll" target="build\x86\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Windows\x86\libiomp5md.dll" target="runtimes\win-x86\native\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x86\MathNet.Numerics.MKL.dll" target="runtimes\win-x86\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.MKL.Win-x86.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

16
build/MathNet.Numerics.MKL.Win.nuspec

@ -5,25 +5,23 @@
<version>@build.number@</version>
<title>Math.NET Numerics - MKL Native Provider for Windows (x64 and x86)</title>
<authors>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</authors>
<owners>Christoph Ruegg, Marcus Cuda, Jurgen Van Gael</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>Intel oneAPI MKL native libraries for Math.NET Numerics on Windows.</description>
<summary>Intel oneAPI MKL native libraries for Math.NET Numerics on Windows.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native mkl</tags>
@dependencies@
</metadata>
<files>
<file src="..\..\out\MKL\Windows\x64\libiomp5md.dll" target="build\x64\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x64\MathNet.Numerics.MKL.dll" target="build\x64\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Windows\x86\libiomp5md.dll" target="build\x86\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x86\MathNet.Numerics.MKL.dll" target="build\x86\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Windows\x64\libiomp5md.dll" target="runtimes\win-x64\native\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x64\MathNet.Numerics.MKL.dll" target="runtimes\win-x64\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\out\MKL\Windows\x86\libiomp5md.dll" target="runtimes\win-x86\native\libiomp5md.dll" />
<file src="..\..\out\MKL\Windows\x86\MathNet.Numerics.MKL.dll" target="runtimes\win-x86\native\MathNet.Numerics.MKL.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.MKL.Win.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

28
build/MathNet.Numerics.OpenBLAS.Win.nuspec

@ -5,31 +5,29 @@
<version>@build.number@</version>
<title>Math.NET Numerics - OpenBLAS Native Provider for Windows (x64 and x86)</title>
<authors>Kuan Bartel, Christoph Ruegg, Marcus Cuda</authors>
<owners>Kuan Bartel, Christoph Ruegg, Marcus Cuda</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://numerics.mathdotnet.com/License.html</licenseUrl>
<license type="expression">MIT</license>
<projectUrl>https://numerics.mathdotnet.com/</projectUrl>
<iconUrl>https://www.mathdotnet.com/images/MathNet128.png</iconUrl>
<repository type="git" url="https://github.com/mathnet/mathnet-numerics" />
<description>OpenBLAS native libraries for Math.NET Numerics.</description>
<summary>OpenBLAS native libraries for Math.NET Numerics.</summary>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright Math.NET Project</copyright>
<tags>math numeric statistics probability integration interpolation linear algebra matrix fft native openblas</tags>
@dependencies@
</metadata>
<files>
<file src="..\..\out\OpenBLAS\Windows\x64\libgcc_s_seh-1.dll" target="build\x64\libgcc_s_seh-1.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\libgfortran-3.dll" target="build\x64\libgfortran-3.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\libopenblas.dll" target="build\x64\libopenblas.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\libquadmath-0.dll" target="build\x64\libquadmath-0.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\MathNet.Numerics.OpenBLAS.dll" target="build\x64\MathNet.Numerics.OpenBLAS.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libgcc_s_sjlj-1.dll" target="build\x86\libgcc_s_sjlj-1.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libgfortran-3.dll" target="build\x86\libgfortran-3.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libopenblas.dll" target="build\x86\libopenblas.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libquadmath-0.dll" target="build\x86\libquadmath-0.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\MathNet.Numerics.OpenBLAS.dll" target="build\x86\MathNet.Numerics.OpenBLAS.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\libgcc_s_seh-1.dll" target="runtimes\win-x64\native\libgcc_s_seh-1.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\libgfortran-3.dll" target="runtimes\win-x64\native\libgfortran-3.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\libopenblas.dll" target="runtimes\win-x64\native\libopenblas.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\libquadmath-0.dll" target="runtimes\win-x64\native\libquadmath-0.dll" />
<file src="..\..\out\OpenBLAS\Windows\x64\MathNet.Numerics.OpenBLAS.dll" target="runtimes\win-x64\native\MathNet.Numerics.OpenBLAS.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libgcc_s_sjlj-1.dll" target="runtimes\win-x86\native\libgcc_s_sjlj-1.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libgfortran-3.dll" target="runtimes\win-x86\native\libgfortran-3.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libopenblas.dll" target="runtimes\win-x86\native\libopenblas.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\libquadmath-0.dll" target="runtimes\win-x86\native\libquadmath-0.dll" />
<file src="..\..\out\OpenBLAS\Windows\x86\MathNet.Numerics.OpenBLAS.dll" target="runtimes\win-x86\native\MathNet.Numerics.OpenBLAS.dll" />
<file src="..\..\build\NativeProvider.targets" target="build\MathNet.Numerics.OpenBLAS.Win.targets" />
<file src="license.txt" target="license.txt" />
<file src="readme.txt" target="readme.txt" />
<file src="..\..\build\icon.png" target="icon.png" />
</files>
</package>

6
build/NativeProvider.targets

@ -4,9 +4,9 @@
** Math.NET Native Provider Interop Files **
******************************************************************************
-->
<ItemGroup Condition="'$(MSBuildThisFileDirectory)' != '' And HasTrailingSlash('$(MSBuildThisFileDirectory)')">
<MathNetInteropFiles Include="$(MSBuildThisFileDirectory)**\*.dll" />
<MathNetInteropFiles Include="$(MSBuildThisFileDirectory)**\*.so" />
<ItemGroup Condition="'$(UsingMicrosoftNETSdk)' != 'true' And '$(MSBuildThisFileDirectory)' != '' And HasTrailingSlash('$(MSBuildThisFileDirectory)')">
<MathNetInteropFiles Include="$(MSBuildThisFileDirectory)..\runtimes\**\*.dll" />
<MathNetInteropFiles Include="$(MSBuildThisFileDirectory)..\runtimes\**\*.so" />
<None Include="@(MathNetInteropFiles)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

106
src/Providers.CUDA/NativeProviderLoader.cs

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -37,6 +37,17 @@ using System.Threading;
namespace MathNet.Numerics.Providers.CUDA
{
internal enum Runtime
{
Unknown = 0,
WindowsX64,
WindowsX86,
WindowsArm64,
WindowsArm,
LinuxX64,
LinuxX86,
}
/// <summary>
/// Helper class to load native libraries depending on the architecture of the OS and process.
/// </summary>
@ -44,12 +55,6 @@ namespace MathNet.Numerics.Providers.CUDA
{
static readonly object StaticLock = new Object();
const string X86 = "x86";
const string X64 = "x64";
const string IA64 = "ia64";
const string ARM = "arm";
const string ARM64 = "arm64";
/// <summary>
/// Dictionary of handles to previously loaded libraries,
/// </summary>
@ -58,7 +63,7 @@ namespace MathNet.Numerics.Providers.CUDA
/// <summary>
/// Gets a string indicating the architecture and bitness of the current process.
/// </summary>
static readonly Lazy<string> ArchitectureKey = new Lazy<string>(EvaluateArchitectureKey, LazyThreadSafetyMode.PublicationOnly);
static readonly Lazy<Runtime> RuntimeKey = new Lazy<Runtime>(EvaluateRuntime, LazyThreadSafetyMode.PublicationOnly);
/// <summary>
/// If the last native library failed to load then gets the corresponding exception
@ -75,42 +80,35 @@ namespace MathNet.Numerics.Providers.CUDA
}
}
static string EvaluateArchitectureKey()
static Runtime EvaluateRuntime()
{
//return (IntPtr.Size == 8) ? X64 : X86;
if (IsUnix)
{
// Only support x86 and amd64 on Unix as there isn't a reliable way to detect the architecture
return Environment.Is64BitProcess ? X64 : X86;
return Environment.Is64BitProcess ? Runtime.LinuxX64 : Runtime.LinuxX86;
}
var architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if (string.Equals(architecture, "x86", StringComparison.OrdinalIgnoreCase))
{
return X86;
return Runtime.WindowsX86;
}
if (string.Equals(architecture, "amd64", StringComparison.OrdinalIgnoreCase)
|| string.Equals(architecture, "x64", StringComparison.OrdinalIgnoreCase))
{
return Environment.Is64BitProcess ? X64 : X86;
}
if (string.Equals(architecture, "ia64", StringComparison.OrdinalIgnoreCase))
{
return IA64;
return Environment.Is64BitProcess ? Runtime.WindowsX64 : Runtime.WindowsX86;
}
if (string.Equals(architecture, "arm", StringComparison.OrdinalIgnoreCase))
{
return Environment.Is64BitProcess ? ARM64 : ARM;
return Environment.Is64BitProcess ? Runtime.WindowsArm64 : Runtime.WindowsArm;
}
// Fallback if unknown
return architecture;
return Runtime.Unknown;
}
/// <summary>
@ -169,31 +167,77 @@ namespace MathNet.Numerics.Providers.CUDA
directory = Path.GetFullPath(directory);
// If we have a know architecture, try the matching subdirectory first
var architecture = ArchitectureKey.Value;
if (!string.IsNullOrEmpty(architecture) && TryLoadFile(new FileInfo(Path.Combine(Path.Combine(directory, architecture), fileName))))
switch (RuntimeKey.Value)
{
return true;
case Runtime.WindowsX64:
if (TryLoadFile(directory, "x64", fileName)
|| TryLoadFile(directory, "win-x64/native", fileName)
|| TryLoadFile(directory, "win-x64", fileName))
{
return true;
}
break;
case Runtime.WindowsX86:
if (TryLoadFile(directory, "x86", fileName)
|| TryLoadFile(directory, "win-x86/native", fileName)
|| TryLoadFile(directory, "win-x86", fileName))
{
return true;
}
break;
case Runtime.WindowsArm64:
if (TryLoadFile(directory, "arm64", fileName)
|| TryLoadFile(directory, "win-arm64/native", fileName)
|| TryLoadFile(directory, "win-arm64", fileName))
{
return true;
}
break;
case Runtime.WindowsArm:
if (TryLoadFile(directory, "arm", fileName)
|| TryLoadFile(directory, "win-arm/native", fileName)
|| TryLoadFile(directory, "win-arm", fileName))
{
return true;
}
break;
case Runtime.LinuxX64:
if (TryLoadFile(directory, "x64", fileName)
|| TryLoadFile(directory, "linux-x64/native", fileName)
|| TryLoadFile(directory, "linux-x64", fileName))
{
return true;
}
break;
case Runtime.LinuxX86:
if (TryLoadFile(directory, "x86", fileName)
|| TryLoadFile(directory, "linux-x86/native", fileName)
|| TryLoadFile(directory, "linux-x86", fileName))
{
return true;
}
break;
}
// Otherwise try to load directly from the provided directory
return TryLoadFile(new FileInfo(Path.Combine(directory, fileName)));
return TryLoadFile(directory, string.Empty, fileName);
}
/// <summary>
/// Try to load a native library by providing the full path including the file name of the library.
/// </summary>
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
static bool TryLoadFile(FileInfo file)
static bool TryLoadFile(string directory, string relativePath, string fileName)
{
lock (StaticLock)
{
IntPtr libraryHandle;
if (NativeHandles.Value.TryGetValue(file.Name, out libraryHandle))
if (NativeHandles.Value.TryGetValue(fileName, out IntPtr libraryHandle))
{
return true;
}
if (!file.Exists)
var fullPath = Path.GetFullPath(Path.Combine(Path.Combine(directory, relativePath), fileName));
if (!File.Exists(fullPath))
{
// If the library isn't found within an architecture specific folder then return false
// to allow normal P/Invoke searching behavior when the library is called
@ -201,7 +245,7 @@ namespace MathNet.Numerics.Providers.CUDA
}
// If successful this will return a handle to the library
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(file.FullName) : WindowsLoader.LoadLibrary(file.FullName);
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(fullPath) : WindowsLoader.LoadLibrary(fullPath);
if (libraryHandle == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
@ -211,7 +255,7 @@ namespace MathNet.Numerics.Providers.CUDA
else
{
LastException = null;
NativeHandles.Value[file.Name] = libraryHandle;
NativeHandles.Value[fileName] = libraryHandle;
}
return libraryHandle != IntPtr.Zero;

108
src/Providers.MKL/NativeProviderLoader.cs

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -35,8 +35,21 @@ using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
// ReSharper disable InconsistentNaming
namespace MathNet.Numerics.Providers.MKL
{
internal enum Runtime
{
Unknown = 0,
WindowsX64,
WindowsX86,
WindowsArm64,
WindowsArm,
LinuxX64,
LinuxX86,
}
/// <summary>
/// Helper class to load native libraries depending on the architecture of the OS and process.
/// </summary>
@ -44,12 +57,6 @@ namespace MathNet.Numerics.Providers.MKL
{
static readonly object StaticLock = new Object();
const string X86 = "x86";
const string X64 = "x64";
const string IA64 = "ia64";
const string ARM = "arm";
const string ARM64 = "arm64";
/// <summary>
/// Dictionary of handles to previously loaded libraries,
/// </summary>
@ -58,7 +65,7 @@ namespace MathNet.Numerics.Providers.MKL
/// <summary>
/// Gets a string indicating the architecture and bitness of the current process.
/// </summary>
static readonly Lazy<string> ArchitectureKey = new Lazy<string>(EvaluateArchitectureKey, LazyThreadSafetyMode.PublicationOnly);
static readonly Lazy<Runtime> RuntimeKey = new Lazy<Runtime>(EvaluateRuntime, LazyThreadSafetyMode.PublicationOnly);
/// <summary>
/// If the last native library failed to load then gets the corresponding exception
@ -75,42 +82,35 @@ namespace MathNet.Numerics.Providers.MKL
}
}
static string EvaluateArchitectureKey()
static Runtime EvaluateRuntime()
{
//return (IntPtr.Size == 8) ? X64 : X86;
if (IsUnix)
{
// Only support x86 and amd64 on Unix as there isn't a reliable way to detect the architecture
return Environment.Is64BitProcess ? X64 : X86;
return Environment.Is64BitProcess ? Runtime.LinuxX64 : Runtime.LinuxX86;
}
var architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if (string.Equals(architecture, "x86", StringComparison.OrdinalIgnoreCase))
{
return X86;
return Runtime.WindowsX86;
}
if (string.Equals(architecture, "amd64", StringComparison.OrdinalIgnoreCase)
|| string.Equals(architecture, "x64", StringComparison.OrdinalIgnoreCase))
{
return Environment.Is64BitProcess ? X64 : X86;
}
if (string.Equals(architecture, "ia64", StringComparison.OrdinalIgnoreCase))
{
return IA64;
return Environment.Is64BitProcess ? Runtime.WindowsX64 : Runtime.WindowsX86;
}
if (string.Equals(architecture, "arm", StringComparison.OrdinalIgnoreCase))
{
return Environment.Is64BitProcess ? ARM64 : ARM;
return Environment.Is64BitProcess ? Runtime.WindowsArm64 : Runtime.WindowsArm;
}
// Fallback if unknown
return architecture;
return Runtime.Unknown;
}
/// <summary>
@ -169,31 +169,77 @@ namespace MathNet.Numerics.Providers.MKL
directory = Path.GetFullPath(directory);
// If we have a know architecture, try the matching subdirectory first
var architecture = ArchitectureKey.Value;
if (!string.IsNullOrEmpty(architecture) && TryLoadFile(new FileInfo(Path.Combine(Path.Combine(directory, architecture), fileName))))
switch (RuntimeKey.Value)
{
return true;
case Runtime.WindowsX64:
if (TryLoadFile(directory, "x64", fileName)
|| TryLoadFile(directory, "win-x64/native", fileName)
|| TryLoadFile(directory, "win-x64", fileName))
{
return true;
}
break;
case Runtime.WindowsX86:
if (TryLoadFile(directory, "x86", fileName)
|| TryLoadFile(directory, "win-x86/native", fileName)
|| TryLoadFile(directory, "win-x86", fileName))
{
return true;
}
break;
case Runtime.WindowsArm64:
if (TryLoadFile(directory, "arm64", fileName)
|| TryLoadFile(directory, "win-arm64/native", fileName)
|| TryLoadFile(directory, "win-arm64", fileName))
{
return true;
}
break;
case Runtime.WindowsArm:
if (TryLoadFile(directory, "arm", fileName)
|| TryLoadFile(directory, "win-arm/native", fileName)
|| TryLoadFile(directory, "win-arm", fileName))
{
return true;
}
break;
case Runtime.LinuxX64:
if (TryLoadFile(directory, "x64", fileName)
|| TryLoadFile(directory, "linux-x64/native", fileName)
|| TryLoadFile(directory, "linux-x64", fileName))
{
return true;
}
break;
case Runtime.LinuxX86:
if (TryLoadFile(directory, "x86", fileName)
|| TryLoadFile(directory, "linux-x86/native", fileName)
|| TryLoadFile(directory, "linux-x86", fileName))
{
return true;
}
break;
}
// Otherwise try to load directly from the provided directory
return TryLoadFile(new FileInfo(Path.Combine(directory, fileName)));
return TryLoadFile(directory, string.Empty, fileName);
}
/// <summary>
/// Try to load a native library by providing the full path including the file name of the library.
/// </summary>
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
static bool TryLoadFile(FileInfo file)
static bool TryLoadFile(string directory, string relativePath, string fileName)
{
lock (StaticLock)
{
IntPtr libraryHandle;
if (NativeHandles.Value.TryGetValue(file.Name, out libraryHandle))
if (NativeHandles.Value.TryGetValue(fileName, out IntPtr libraryHandle))
{
return true;
}
if (!file.Exists)
var fullPath = Path.GetFullPath(Path.Combine(Path.Combine(directory, relativePath), fileName));
if (!File.Exists(fullPath))
{
// If the library isn't found within an architecture specific folder then return false
// to allow normal P/Invoke searching behavior when the library is called
@ -201,7 +247,7 @@ namespace MathNet.Numerics.Providers.MKL
}
// If successful this will return a handle to the library
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(file.FullName) : WindowsLoader.LoadLibrary(file.FullName);
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(fullPath) : WindowsLoader.LoadLibrary(fullPath);
if (libraryHandle == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
@ -211,7 +257,7 @@ namespace MathNet.Numerics.Providers.MKL
else
{
LastException = null;
NativeHandles.Value[file.Name] = libraryHandle;
NativeHandles.Value[fileName] = libraryHandle;
}
return libraryHandle != IntPtr.Zero;

106
src/Providers.OpenBLAS/NativeProviderLoader.cs

@ -3,7 +3,7 @@
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2016 Math.NET
// Copyright (c) 2009-2021 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -37,6 +37,17 @@ using System.Threading;
namespace MathNet.Numerics.Providers.OpenBLAS
{
internal enum Runtime
{
Unknown = 0,
WindowsX64,
WindowsX86,
WindowsArm64,
WindowsArm,
LinuxX64,
LinuxX86,
}
/// <summary>
/// Helper class to load native libraries depending on the architecture of the OS and process.
/// </summary>
@ -44,12 +55,6 @@ namespace MathNet.Numerics.Providers.OpenBLAS
{
static readonly object StaticLock = new Object();
const string X86 = "x86";
const string X64 = "x64";
const string IA64 = "ia64";
const string ARM = "arm";
const string ARM64 = "arm64";
/// <summary>
/// Dictionary of handles to previously loaded libraries,
/// </summary>
@ -58,7 +63,7 @@ namespace MathNet.Numerics.Providers.OpenBLAS
/// <summary>
/// Gets a string indicating the architecture and bitness of the current process.
/// </summary>
static readonly Lazy<string> ArchitectureKey = new Lazy<string>(EvaluateArchitectureKey, LazyThreadSafetyMode.PublicationOnly);
static readonly Lazy<Runtime> RuntimeKey = new Lazy<Runtime>(EvaluateRuntime, LazyThreadSafetyMode.PublicationOnly);
/// <summary>
/// If the last native library failed to load then gets the corresponding exception
@ -75,42 +80,35 @@ namespace MathNet.Numerics.Providers.OpenBLAS
}
}
static string EvaluateArchitectureKey()
static Runtime EvaluateRuntime()
{
//return (IntPtr.Size == 8) ? X64 : X86;
if (IsUnix)
{
// Only support x86 and amd64 on Unix as there isn't a reliable way to detect the architecture
return Environment.Is64BitProcess ? X64 : X86;
return Environment.Is64BitProcess ? Runtime.LinuxX64 : Runtime.LinuxX86;
}
var architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if (string.Equals(architecture, "x86", StringComparison.OrdinalIgnoreCase))
{
return X86;
return Runtime.WindowsX86;
}
if (string.Equals(architecture, "amd64", StringComparison.OrdinalIgnoreCase)
|| string.Equals(architecture, "x64", StringComparison.OrdinalIgnoreCase))
{
return Environment.Is64BitProcess ? X64 : X86;
}
if (string.Equals(architecture, "ia64", StringComparison.OrdinalIgnoreCase))
{
return IA64;
return Environment.Is64BitProcess ? Runtime.WindowsX64 : Runtime.WindowsX86;
}
if (string.Equals(architecture, "arm", StringComparison.OrdinalIgnoreCase))
{
return Environment.Is64BitProcess ? ARM64 : ARM;
return Environment.Is64BitProcess ? Runtime.WindowsArm64 : Runtime.WindowsArm;
}
// Fallback if unknown
return architecture;
return Runtime.Unknown;
}
/// <summary>
@ -169,31 +167,77 @@ namespace MathNet.Numerics.Providers.OpenBLAS
directory = Path.GetFullPath(directory);
// If we have a know architecture, try the matching subdirectory first
var architecture = ArchitectureKey.Value;
if (!string.IsNullOrEmpty(architecture) && TryLoadFile(new FileInfo(Path.Combine(Path.Combine(directory, architecture), fileName))))
switch (RuntimeKey.Value)
{
return true;
case Runtime.WindowsX64:
if (TryLoadFile(directory, "x64", fileName)
|| TryLoadFile(directory, "win-x64/native", fileName)
|| TryLoadFile(directory, "win-x64", fileName))
{
return true;
}
break;
case Runtime.WindowsX86:
if (TryLoadFile(directory, "x86", fileName)
|| TryLoadFile(directory, "win-x86/native", fileName)
|| TryLoadFile(directory, "win-x86", fileName))
{
return true;
}
break;
case Runtime.WindowsArm64:
if (TryLoadFile(directory, "arm64", fileName)
|| TryLoadFile(directory, "win-arm64/native", fileName)
|| TryLoadFile(directory, "win-arm64", fileName))
{
return true;
}
break;
case Runtime.WindowsArm:
if (TryLoadFile(directory, "arm", fileName)
|| TryLoadFile(directory, "win-arm/native", fileName)
|| TryLoadFile(directory, "win-arm", fileName))
{
return true;
}
break;
case Runtime.LinuxX64:
if (TryLoadFile(directory, "x64", fileName)
|| TryLoadFile(directory, "linux-x64/native", fileName)
|| TryLoadFile(directory, "linux-x64", fileName))
{
return true;
}
break;
case Runtime.LinuxX86:
if (TryLoadFile(directory, "x86", fileName)
|| TryLoadFile(directory, "linux-x86/native", fileName)
|| TryLoadFile(directory, "linux-x86", fileName))
{
return true;
}
break;
}
// Otherwise try to load directly from the provided directory
return TryLoadFile(new FileInfo(Path.Combine(directory, fileName)));
return TryLoadFile(directory, string.Empty, fileName);
}
/// <summary>
/// Try to load a native library by providing the full path including the file name of the library.
/// </summary>
/// <returns>True if the library was successfully loaded or if it has already been loaded.</returns>
static bool TryLoadFile(FileInfo file)
static bool TryLoadFile(string directory, string relativePath, string fileName)
{
lock (StaticLock)
{
IntPtr libraryHandle;
if (NativeHandles.Value.TryGetValue(file.Name, out libraryHandle))
if (NativeHandles.Value.TryGetValue(fileName, out IntPtr libraryHandle))
{
return true;
}
if (!file.Exists)
var fullPath = Path.GetFullPath(Path.Combine(Path.Combine(directory, relativePath), fileName));
if (!File.Exists(fullPath))
{
// If the library isn't found within an architecture specific folder then return false
// to allow normal P/Invoke searching behavior when the library is called
@ -201,7 +245,7 @@ namespace MathNet.Numerics.Providers.OpenBLAS
}
// If successful this will return a handle to the library
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(file.FullName) : WindowsLoader.LoadLibrary(file.FullName);
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(fullPath) : WindowsLoader.LoadLibrary(fullPath);
if (libraryHandle == IntPtr.Zero)
{
int lastError = Marshal.GetLastWin32Error();
@ -211,7 +255,7 @@ namespace MathNet.Numerics.Providers.OpenBLAS
else
{
LastException = null;
NativeHandles.Value[file.Name] = libraryHandle;
NativeHandles.Value[fileName] = libraryHandle;
}
return libraryHandle != IntPtr.Zero;

Loading…
Cancel
Save