mathnet / mathnet-numerics

Math.NET Numerics
http://numerics.mathdotnet.com
MIT License
3.44k stars 891 forks source link

VsTest is unable to load MKL Native Provider in UnitTest #992

Closed manuelmainz closed 1 year ago

manuelmainz commented 1 year ago

Environment:

Unit Test project with target Framework .NET Framework 4.8 build in x64 with packages

We have a Buildserver with Azure DevOps which runs the tests with VSTest@2

- task: VSTest@2 displayName: 'Run Tests' inputs: platform: '$(buildPlatform)' # x64 configuration: '$(buildConfiguration)' # Release searchFolder: '$(Pipeline.Workspace)' testSelector: 'testAssemblies' testAssemblyVer2: | \MyProject.Tests\bin\\MyProject.Tests.dll

The Problem:

In a UnitTest we have the line Control.UseNativeMKL();. Unfortunately since the update of MathNet this throws following exception on the buildserver, whereas it works fine locally in VisualStudio.

System.NotSupportedException : MKL Native Provider not found. ----> System.DllNotFoundException : Unable to load DLL 'libMathNetNumericsMKL': The specified module could not be found. (Exception from HRESULT: 0x8007007E) StackTrace: at MathNet.Numerics.Providers.MKL.MklProvider.Load(String hintPath, MklConsistency consistency, MklPrecision precision, MklAccuracy accuracy) at MathNet.Numerics.Providers.MKL.LinearAlgebra.MklLinearAlgebraProvider.InitializeVerify() at xx.Tests.xx.xxTests.TestSetup() in C:\agents_work\6\s\xx.Tests\xx\xx.cs:line 27 --DllNotFoundException at MathNet.Numerics.Providers.MKL.SafeNativeMethods.query_capability(Int32 capability) at MathNet.Numerics.Providers.MKL.MklProvider.Load(String hintPath, MklConsistency consistency, MklPrecision precision, MklAccuracy accuracy)

Investigation:

I have done some checks in the UnitTest.

When downgrading to MathNet.Numerics .v4.15.0 and MathNet.Numerics.MKL.Win-x64 v2.5.0 it works fine.

I would be very happy for any help or ideas. Thanks!

manuelmainz commented 1 year ago

While trying to figure out the problem, the command MathNet.Numerics.Control.Describe() was quite helpful.

Which returns this Version 5.0.0 Built for .NET Framework 4.8 Linear Algebra Provider: **Managed** Fourier Transform Provider: **Managed** Sparse Solver Provider: **Managed** Max Degree of Parallelism: 6 Parallelize Elements: 300 Parallelize Order: 64 Check Distribution Parameters: True Thread-Safe RNGs: True Operating System: Microsoft Windows 10.0.19045 Operating System Architecture: X64 Framework: .NET Framework 4.8.9139.0 Process Architecture: X64 Processor Architecture: AMD64 Processor Identifier: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel

I restarted the Buildserver machine by coincidence and it seems to have solved the problem.

So now I get this result and everything works again as expected.

Math.NET Numerics Configuration: Version 5.0.0 Built for .NET Framework 4.8 Linear Algebra Provider: Intel MKL (x64; revision 15; MKL 2022.0) Fourier Transform Provider: Intel MKL (x64; revision 15; MKL 2022.0) Sparse Solver Provider: Intel MKL (x64; revision 15; MKL 2022.0) Max Degree of Parallelism: 6 Parallelize Elements: 300 Parallelize Order: 64 Check Distribution Parameters: True Thread-Safe RNGs: True Operating System: Microsoft Windows 10.0.19045 Operating System Architecture: X64 Framework: .NET Framework 4.8.9139.0 Process Architecture: X64 Processor Architecture: AMD64 Processor Identifier: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel