Browse Source

Sparse Solver MKL provider can be self contained

pull/769/head
Christoph Ruegg 5 years ago
parent
commit
71259eff61
  1. 24
      src/Numerics/Providers/SparseSolver/Managed/ManagedSparseSolverProvider.cs
  2. 18
      src/Providers.MKL/FourierTransform/MklFourierTransformProvider.cs
  3. 2
      src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.cs
  4. 2
      src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex.cs
  5. 2
      src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex32.cs
  6. 2
      src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Double.cs
  7. 2
      src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Single.cs
  8. 10
      src/Providers.MKL/SparseSolver/MklSparseSolverProvider.cs

24
src/Numerics/Providers/SparseSolver/Managed/ManagedSparseSolverProvider.cs

@ -6,13 +6,13 @@ namespace MathNet.Numerics.Providers.SparseSolver.Managed
/// <summary>
/// The managed sparse solver provider
/// </summary>
public partial class ManagedSparseSolverProvider : ISparseSolverProvider
internal class ManagedSparseSolverProvider : ISparseSolverProvider
{
/// <summary>
/// Try to find out whether the provider is available, at least in principle.
/// Verification may still fail if available, but it will certainly fail if unavailable.
/// </summary>
public virtual bool IsAvailable()
public bool IsAvailable()
{
return true;
}
@ -20,7 +20,7 @@ namespace MathNet.Numerics.Providers.SparseSolver.Managed
/// <summary>
/// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider
/// </summary>
public virtual void InitializeVerify()
public void InitializeVerify()
{
}
@ -28,7 +28,7 @@ namespace MathNet.Numerics.Providers.SparseSolver.Managed
/// Frees memory buffers, caches and handles allocated in or to the provider.
/// Does not unload the provider itself, it is still usable afterwards.
/// </summary>
public virtual void FreeResources()
public void FreeResources()
{
}
@ -37,29 +37,29 @@ namespace MathNet.Numerics.Providers.SparseSolver.Managed
return "Managed";
}
public virtual DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] ColumnIndices, float[] values,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, float[] values,
int nRhs, float[] rhs, float[] solution)
{
throw new NotImplementedException();
}
public virtual DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] ColumnIndices, double[] values,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, double[] values,
int nRhs, double[] rhs, double[] solution)
{
throw new NotImplementedException();
}
public virtual DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] ColumnIndices, Complex32[] values,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, Complex32[] values,
int nRhs, Complex32[] rhs, Complex32[] solution)
{
throw new NotImplementedException();
}
public virtual DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] ColumnIndices, Complex[] values,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, Complex[] values,
int nRhs, Complex[] rhs, Complex[] solution)
{
throw new NotImplementedException();

18
src/Providers.MKL/FourierTransform/MklFourierTransformProvider.cs

@ -27,6 +27,7 @@
// </copyright>
using System;
using System.Security;
using System.Threading;
using MathNet.Numerics.Providers.FourierTransform;
using Complex = System.Numerics.Complex;
@ -67,6 +68,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
/// <summary>
/// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider
/// </summary>
[SecuritySafeCritical]
public void InitializeVerify()
{
int revision = MklProvider.Load(hintPath: _hintPath);
@ -88,6 +90,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
/// Frees memory buffers, caches and handles allocated in or to the provider.
/// Does not unload the provider itself, it is still usable afterwards.
/// </summary>
[SecuritySafeCritical]
public virtual void FreeResources()
{
Kernel kernel = Interlocked.Exchange(ref _kernel, null);
@ -104,6 +107,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
return MklProvider.Describe();
}
[SecuritySafeCritical]
Kernel Configure(int length, FourierTransformScaling scaling, bool real, bool single)
{
Kernel kernel = Interlocked.Exchange(ref _kernel, null);
@ -157,6 +161,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
return kernel;
}
[SecuritySafeCritical]
Kernel Configure(int[] dimensions, FourierTransformScaling scaling, bool single)
{
if (dimensions.Length == 1)
@ -236,6 +241,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
return kernel;
}
[SecuritySafeCritical]
void Release(Kernel kernel)
{
Kernel existing = Interlocked.Exchange(ref _kernel, kernel);
@ -245,6 +251,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
}
}
[SecuritySafeCritical]
public void Forward(Complex32[] samples, FourierTransformScaling scaling)
{
Kernel kernel = Configure(samples.Length, scaling, false, true);
@ -252,6 +259,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void Forward(Complex[] samples, FourierTransformScaling scaling)
{
Kernel kernel = Configure(samples.Length, scaling, false, false);
@ -259,6 +267,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void Backward(Complex32[] spectrum, FourierTransformScaling scaling)
{
Kernel kernel = Configure(spectrum.Length, scaling, false, true);
@ -266,6 +275,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void Backward(Complex[] spectrum, FourierTransformScaling scaling)
{
Kernel kernel = Configure(spectrum.Length, scaling, false, false);
@ -273,6 +283,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void ForwardReal(float[] samples, int n, FourierTransformScaling scaling)
{
Kernel kernel = Configure(n, scaling, true, true);
@ -280,6 +291,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void ForwardReal(double[] samples, int n, FourierTransformScaling scaling)
{
Kernel kernel = Configure(n, scaling, true, false);
@ -287,6 +299,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void BackwardReal(float[] spectrum, int n, FourierTransformScaling scaling)
{
Kernel kernel = Configure(n, scaling, true, true);
@ -296,6 +309,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
spectrum[n] = 0f;
}
[SecuritySafeCritical]
public void BackwardReal(double[] spectrum, int n, FourierTransformScaling scaling)
{
Kernel kernel = Configure(n, scaling, true, false);
@ -305,6 +319,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
spectrum[n] = 0d;
}
[SecuritySafeCritical]
public void ForwardMultidim(Complex32[] samples, int[] dimensions, FourierTransformScaling scaling)
{
Kernel kernel = Configure(dimensions, scaling, true);
@ -312,6 +327,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void ForwardMultidim(Complex[] samples, int[] dimensions, FourierTransformScaling scaling)
{
Kernel kernel = Configure(dimensions, scaling, false);
@ -319,6 +335,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void BackwardMultidim(Complex32[] spectrum, int[] dimensions, FourierTransformScaling scaling)
{
Kernel kernel = Configure(dimensions, scaling, true);
@ -326,6 +343,7 @@ namespace MathNet.Numerics.Providers.MKL.FourierTransform
Release(kernel);
}
[SecuritySafeCritical]
public void BackwardMultidim(Complex[] spectrum, int[] dimensions, FourierTransformScaling scaling)
{
Kernel kernel = Configure(dimensions, scaling, false);

2
src/Providers.MKL/LinearAlgebra/MklLinearAlgebraProvider.cs

@ -28,6 +28,7 @@
// </copyright>
using System;
using System.Security;
using MathNet.Numerics.Providers.LinearAlgebra.Managed;
namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
@ -88,6 +89,7 @@ namespace MathNet.Numerics.Providers.MKL.LinearAlgebra
/// Initialize and verify that the provided is indeed available.
/// If calling this method fails, consider to fall back to alternatives like the managed provider.
/// </summary>
[SecuritySafeCritical]
public override void InitializeVerify()
{
int revision = MklProvider.Load(_hintPath, _consistency, _precision, _accuracy);

2
src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex.cs

@ -27,7 +27,7 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
/// <param name="solution">The left hand side matrix</param>
/// <returns>The status of the solver.</returns>
[SecuritySafeCritical]
public override DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, Complex[] values,
int nRhs, Complex[] rhs, Complex[] solution)
{

2
src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Complex32.cs

@ -26,7 +26,7 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
/// <param name="solution">The left hand side matrix</param>
/// <returns>The status of the solver.</returns>
[SecuritySafeCritical]
public override DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, Complex32[] values,
int nRhs, Complex32[] rhs, Complex32[] solution)
{

2
src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Double.cs

@ -26,7 +26,7 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
/// <param name="solution">The left hand side matrix</param>
/// <returns>The status of the solver.</returns>
[SecuritySafeCritical]
public override DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, double[] values,
int nRhs, double[] rhs, double[] solution)
{

2
src/Providers.MKL/SparseSolver/MklSparseSolverProvider.Single.cs

@ -26,7 +26,7 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
/// <param name="solution">The left hand side matrix</param>
/// <returns>The status of the solver.</returns>
[SecuritySafeCritical]
public override DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
public DssStatus Solve(DssMatrixStructure matrixStructure, DssMatrixType matrixType, DssSystemType systemType,
int rowCount, int columnCount, int nonZerosCount, int[] rowPointers, int[] columnIndices, float[] values,
int nRhs, float[] rhs, float[] solution)
{

10
src/Providers.MKL/SparseSolver/MklSparseSolverProvider.cs

@ -1,12 +1,12 @@
using System;
using MathNet.Numerics.Providers.SparseSolver.Managed;
using MathNet.Numerics.Providers.SparseSolver;
namespace MathNet.Numerics.Providers.MKL.SparseSolver
{
/// <summary>
/// Intel's Math Kernel Library (MKL) sparse solver provider.
/// </summary>
internal partial class MklSparseSolverProvider : ManagedSparseSolverProvider, IDisposable
internal partial class MklSparseSolverProvider : ISparseSolverProvider, IDisposable
{
const int MinimumCompatibleRevision = 14;
@ -25,7 +25,7 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
/// Try to find out whether the provider is available, at least in principle.
/// Verification may still fail if available, but it will certainly fail if unavailable.
/// </summary>
public override bool IsAvailable()
public bool IsAvailable()
{
return MklProvider.IsAvailable(hintPath: _hintPath);
}
@ -34,7 +34,7 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
/// Initialize and verify that the provided is indeed available.
/// If calling this method fails, consider to fall back to alternatives like the managed provider.
/// </summary>
public override void InitializeVerify()
public void InitializeVerify()
{
int revision = MklProvider.Load(_hintPath);
if (revision < MinimumCompatibleRevision)
@ -54,7 +54,7 @@ namespace MathNet.Numerics.Providers.MKL.SparseSolver
/// Frees memory buffers, caches and handles allocated in or to the provider.
/// Does not unload the provider itself, it is still usable afterwards.
/// </summary>
public override void FreeResources()
public void FreeResources()
{
MklProvider.FreeResources();
}

Loading…
Cancel
Save