Browse Source

Native: cleanup

pull/312/head
Christoph Ruegg 11 years ago
parent
commit
c906a2a6af
  1. 2
      src/NativeProviders/OpenBLAS/capabilities.cpp
  2. 4
      src/Numerics/Control.cs
  3. 4
      src/Numerics/Numerics.csproj
  4. 37
      src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs
  5. 49
      src/Numerics/Providers/LinearAlgebra/Cuda/CudaProviderCapabilities.cs
  6. 33
      src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
  7. 15
      src/Numerics/Providers/LinearAlgebra/Mkl/MklProviderCapabilities.cs
  8. 27
      src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs
  9. 51
      src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasProviderCapabilities.cs

2
src/NativeProviders/OpenBLAS/capabilities.cpp

@ -41,7 +41,7 @@ extern "C" {
#endif
// COMMON/SHARED
case 64: return 7; // revision
case 64: return 1; // revision
case 66: return 1; // threading control
// LINEAR ALGEBRA

4
src/Numerics/Control.cs

@ -82,6 +82,10 @@ namespace MathNet.Numerics
case "CUDA":
LinearAlgebraProvider = new Providers.LinearAlgebra.Cuda.CudaLinearAlgebraProvider();
break;
case "OPENBLAS":
LinearAlgebraProvider = new Providers.LinearAlgebra.OpenBlas.OpenBlasLinearAlgebraProvider();
break;
#endif
default:
LinearAlgebraProvider = new ManagedLinearAlgebraProvider();

4
src/Numerics/Numerics.csproj

@ -162,7 +162,9 @@
<Compile Include="Providers\LinearAlgebra\Cuda\CudaLinearAlgebraProvider.cs" />
<Compile Include="Providers\LinearAlgebra\Cuda\CudaLinearAlgebraProvider.Double.cs" />
<Compile Include="Providers\LinearAlgebra\Cuda\CudaLinearAlgebraProvider.Single.cs" />
<Compile Include="Providers\LinearAlgebra\Cuda\CudaProviderCapabilities.cs" />
<Compile Include="Providers\LinearAlgebra\Cuda\SafeNativeMethods.cs" />
<Compile Include="Providers\LinearAlgebra\Mkl\MklProviderCapabilities.cs" />
<Compile Include="Providers\LinearAlgebra\OpenBlas\OpenBlasLinearAlgebraProvider.cs" />
<Compile Include="Providers\LinearAlgebra\OpenBlas\OpenBlasLinearAlgebraProvider.Complex.cs" />
<Compile Include="Providers\LinearAlgebra\OpenBlas\OpenBlasLinearAlgebraProvider.Complex32.cs" />
@ -198,7 +200,7 @@
<Compile Include="LinearAlgebra\Vector.BCL.cs" />
<Compile Include="LinearAlgebra\Vector.Operators.cs" />
<Compile Include="Exceptions.cs" />
<Compile Include="Providers\LinearAlgebra\ProviderCapabilities.cs" />
<Compile Include="Providers\LinearAlgebra\OpenBlas\OpenBlasProviderCapabilities.cs" />
<Compile Include="Providers\NativeProviderLoader.cs" />
<Compile Include="Random\SystemRandomSource.cs" />
<Compile Include="Random\RandomSeed.cs" />

37
src/Numerics/Providers/LinearAlgebra/Cuda/CudaLinearAlgebraProvider.cs

@ -39,21 +39,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
/// </summary>
public partial class CudaLinearAlgebraProvider : ManagedLinearAlgebraProvider, IDisposable
{
private int _nativeRevision;
private bool _nativeIX86;
private bool _nativeX64;
private bool _nativeIA64;
private IntPtr _blasHandle;
private IntPtr _solverHandle;
/// <summary>
/// Constructor.
/// </summary>
[CLSCompliant(false)]
public CudaLinearAlgebraProvider()
{
}
int _nativeRevision;
bool _nativeIX86;
bool _nativeX64;
bool _nativeIA64;
IntPtr _blasHandle;
IntPtr _solverHandle;
/// <summary>
/// Initialize and verify that the provided is indeed available.
@ -70,12 +61,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
a = SafeNativeMethods.query_capability(0);
b = SafeNativeMethods.query_capability(1);
_nativeIX86 = SafeNativeMethods.query_capability(8) > 0;
_nativeX64 = SafeNativeMethods.query_capability(9) > 0;
_nativeIA64 = SafeNativeMethods.query_capability(10) > 0;
_nativeIX86 = SafeNativeMethods.query_capability((int)ProviderPlatform.x86) > 0;
_nativeX64 = SafeNativeMethods.query_capability((int)ProviderPlatform.x64) > 0;
_nativeIA64 = SafeNativeMethods.query_capability((int)ProviderPlatform.ia64) > 0;
_nativeRevision = SafeNativeMethods.query_capability(64);
linearAlgebra = SafeNativeMethods.query_capability(128);
_nativeRevision = SafeNativeMethods.query_capability((int)ProviderConfig.Revision);
linearAlgebra = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebra);
}
catch (DllNotFoundException e)
{
@ -180,14 +171,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
default:
throw new Exception("Unrecognized cuSolverDn status code: " + status);
}
}
public override string ToString()
{
return string.Format("Nvidia CUDA ({1}; revision {0})", _nativeRevision, _nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : "unknown");
return string.Format("Nvidia CUDA ({1}; revision {0})",
_nativeRevision,
_nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : "unknown");
}

49
src/Numerics/Providers/LinearAlgebra/Cuda/CudaProviderCapabilities.cs

@ -0,0 +1,49 @@
// <copyright file="CudaProviderCapabilities.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Providers.LinearAlgebra.Cuda
{
internal enum ProviderPlatform : int
{
x86 = 8,
x64 = 9,
ia64 = 10,
}
internal enum ProviderConfig : int
{
Revision = 64,
}
internal enum ProviderCapability : int
{
LinearAlgebra = 128,
}
}

33
src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs

@ -143,12 +143,12 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
a = SafeNativeMethods.query_capability(0);
b = SafeNativeMethods.query_capability(1);
_nativeIX86 = SafeNativeMethods.query_capability(8) > 0;
_nativeX64 = SafeNativeMethods.query_capability(9) > 0;
_nativeIA64 = SafeNativeMethods.query_capability(10) > 0;
_nativeIX86 = SafeNativeMethods.query_capability((int)ProviderPlatform.x86) > 0;
_nativeX64 = SafeNativeMethods.query_capability((int)ProviderPlatform.x64) > 0;
_nativeIA64 = SafeNativeMethods.query_capability((int)ProviderPlatform.ia64) > 0;
_nativeRevision = SafeNativeMethods.query_capability(64);
linearAlgebra = SafeNativeMethods.query_capability(128);
_nativeRevision = SafeNativeMethods.query_capability((int)ProviderConfig.Revision);
linearAlgebra = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebra);
}
catch (DllNotFoundException e)
{
@ -169,14 +169,14 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
}
// set numerical consistency, precision and accuracy modes, if supported
if (SafeNativeMethods.query_capability(65) > 0)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Precision) > 0)
{
SafeNativeMethods.set_consistency_mode((int)_consistency);
SafeNativeMethods.set_vml_mode((uint)_precision | (uint)_accuracy);
}
// set threading settings, if supported
if (SafeNativeMethods.query_capability(66) > 0)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Threading) > 0)
{
SafeNativeMethods.set_max_threads(Control.MaxDegreeOfParallelism);
}
@ -187,7 +187,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public void FreeBuffers()
{
if (SafeNativeMethods.query_capability(67) < 1)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Memory) < 1)
{
throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version.");
}
@ -200,7 +200,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public void ThreadFreeBuffers()
{
if (SafeNativeMethods.query_capability(67) < 1)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Memory) < 1)
{
throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version.");
}
@ -213,7 +213,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public void DisableMemoryPool()
{
if (SafeNativeMethods.query_capability(67) < 1)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Memory) < 1)
{
throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version.");
}
@ -228,7 +228,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// <returns>Returns the number of bytes allocated to all memory buffers.</returns>
public long MemoryStatistics(out int allocatedBuffers)
{
if (SafeNativeMethods.query_capability(67) < 1)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Memory) < 1)
{
throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version.");
}
@ -241,7 +241,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public void EnablePeakMemoryStatistics()
{
if (SafeNativeMethods.query_capability(67) < 1)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Memory) < 1)
{
throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version.");
}
@ -254,7 +254,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// </summary>
public void DisablePeakMemoryStatistics()
{
if (SafeNativeMethods.query_capability(67) < 1)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Memory) < 1)
{
throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version.");
}
@ -269,7 +269,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
/// <returns>The peak number of bytes allocated to all memory buffers.</returns>
public long PeakMemoryStatistics(bool reset = true)
{
if (SafeNativeMethods.query_capability(67) < 1)
if (SafeNativeMethods.query_capability((int)ProviderConfig.Memory) < 1)
{
throw new NotSupportedException("MKL Native Provider does not support memory management functions. Consider upgrading to a newer version.");
}
@ -279,9 +279,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
public override string ToString()
{
return string.Format("Intel MKL ({1}; revision {0})", _nativeRevision, _nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : "unknown");
return string.Format("Intel MKL ({1}; revision {0})",
_nativeRevision,
_nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : "unknown");
}
}
}

15
src/Numerics/Providers/LinearAlgebra/ProviderCapabilities.cs → src/Numerics/Providers/LinearAlgebra/Mkl/MklProviderCapabilities.cs

@ -1,4 +1,4 @@
// <copyright file="ProviderCapabilities.cs" company="Math.NET">
// <copyright file="MklProviderCapabilities.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -28,17 +28,16 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Providers.LinearAlgebra
namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl
{
public enum ProviderPlatform : int
internal enum ProviderPlatform : int
{
x86 = 8,
x64 = 9,
ia64 = 10,
arm = 11,
}
public enum ProviderConfig : int
internal enum ProviderConfig : int
{
Revision = 64,
Precision = 65,
@ -46,10 +45,8 @@ namespace MathNet.Numerics.Providers.LinearAlgebra
Memory = 67,
}
public enum ProviderCapability : int
internal enum ProviderCapability : int
{
LinearAlgebra = 128,
Optimization = 256,
FFT = 384,
}
}
}

27
src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasLinearAlgebraProvider.cs

@ -30,10 +30,7 @@
#if NATIVE
using MathNet.Numerics.Properties;
using System;
using System.Numerics;
using System.Security;
namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
{
@ -49,29 +46,29 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
/// </summary>
public partial class OpenBlasLinearAlgebraProvider : ManagedLinearAlgebraProvider
{
int _nativeRevision;
bool _nativeIX86;
bool _nativeX64;
bool _nativeIA64;
bool _nativeARM;
public OpenBlasLinearAlgebraProvider()
{
}
public override void InitializeVerify()
{
int linearAlgebra;
int a, b, linearAlgebra;
try
{
// Load the native library
NativeProviderLoader.TryLoad(SafeNativeMethods.DllName);
a = SafeNativeMethods.query_capability(0);
b = SafeNativeMethods.query_capability(1);
_nativeIX86 = SafeNativeMethods.query_capability((int)ProviderPlatform.x86) > 0;
_nativeX64 = SafeNativeMethods.query_capability((int)ProviderPlatform.x64) > 0;
_nativeIA64 = SafeNativeMethods.query_capability((int)ProviderPlatform.ia64) > 0;
_nativeARM = SafeNativeMethods.query_capability((int)ProviderPlatform.arm) > 0;
_nativeRevision = SafeNativeMethods.query_capability((int)ProviderConfig.Revision);
linearAlgebra = SafeNativeMethods.query_capability((int)ProviderCapability.LinearAlgebra);
}
catch (DllNotFoundException e)
@ -87,6 +84,11 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
throw new NotSupportedException("OpenBLAS Native Provider does not support capability querying and is therefore not compatible. Consider upgrading to a newer version.", e);
}
if (a != 0 || b != -1 || linearAlgebra <=0 || _nativeRevision < 1)
{
throw new NotSupportedException("OpenBLAS Native Provider too old or not compatible. Consider upgrading to a newer version.");
}
// set threading settings, if supported
if (SafeNativeMethods.query_capability((int)ProviderConfig.Threading) > 0)
{
@ -96,10 +98,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
public override string ToString()
{
return string.Format("OpenBLAS\r\nProvider revision: {0}\r\nCPU core name: {1}\r\nLibrary config: {1})",
SafeNativeMethods.query_capability((int)ProviderConfig.Revision),
SafeNativeMethods.get_cpu_core(),
SafeNativeMethods.get_build_config());
return string.Format("OpenBLAS ({1}; revision {0})",
_nativeRevision,
_nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : _nativeARM ? "ARM" : "unknown");
}
}
}

51
src/Numerics/Providers/LinearAlgebra/OpenBlas/OpenBlasProviderCapabilities.cs

@ -0,0 +1,51 @@
// <copyright file="OpenBlasProviderCapabilities.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Providers.LinearAlgebra.OpenBlas
{
internal enum ProviderPlatform : int
{
x86 = 8,
x64 = 9,
ia64 = 10,
arm = 11,
}
internal enum ProviderConfig : int
{
Revision = 64,
Threading = 66,
}
internal enum ProviderCapability : int
{
LinearAlgebra = 128,
}
}
Loading…
Cancel
Save