Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MKL.NET.Matrix Nuget package in docker container #31

Open
RobWomack98 opened this issue Nov 11, 2024 · 3 comments
Open

MKL.NET.Matrix Nuget package in docker container #31

RobWomack98 opened this issue Nov 11, 2024 · 3 comments

Comments

@RobWomack98
Copy link

Encountering errors with matrix multiplication using MKL.NET.Matrix Nuget package in a docker container

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0-windowsservercore-ltsc2022
WORKDIR c:/test/
COPY test.csproj test.cs ./
RUN dotnet build
RUN dotnet test

test.csproj file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net6.0</TargetFrameworks>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="MKL.NET.Matrix" Version="1.1.1"/>
    <PackageReference Include="MKL.NET.win-x64" Version="2022.0.0.115" />
    <PackageReference Include="MSTest" Version="3.6.2"/>
  </ItemGroup>  
</Project>

test.cs file:

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class matrix_test {
    [TestMethod]
    public void matrix_multiply_test(){
        MKLNET.matrix matrixA = new MKLNET.matrix(6, 6);
        for (int i = 0; i < matrixA.Cols; ++i) {
            for (int j = 0; j < matrixA.Rows; ++j) {
                    matrixA[i, j] = (i + 1) * (j + 1);
            }
        }
        try { MKLNET.matrix result = matrixA * matrixA;
        } catch (ExternalException e) {
            Console.WriteLine(e.ErrorCode);
            Console.WriteLine(e.Source);
            Assert.Fail();
        }
        Assert.IsTrue(true);
    }
}

output (catching the exception)

Error Message:
Assert.Fail failed.
Stack Trace:
at matrix_test.matrix_multiply_test() in C:\test\test.cs:line 20

Standard Output Messages:
-2147467259 (translates to 0x80004005, an Unspecified Error)
MKL.NET

output (not catching the exception)

System.Runtime.InteropServices.SEHException: External component has thrown an exception.
Stack Trace:
at MKLNET.Blas.Unsafe.gemm(Layout Layout, Trans TransA, Trans TransB, Int32 M, Int32 N, Int32 K, Double alpha, Double* A, Int32 lda, Double* B, Int32 ldb, Double beta, Double* C, Int32 ldc)
at MKLNET.Expression.MatrixMultiply.Evaluate()
at MKLNET.Expression.MatrixExpression.op_Implicit(MatrixExpression a)
at matrix_test.matrix_multiply_test() in C:\test\test.cs:line 16

Some scenarios where this error doesn't exist (that could help isolate the issue):

  1. when using mcr.microsoft.com/dotnet/sdk:6.0-jammy image (I change the runtime package to MKL.NET.linux-x64 and change dockerfile test path to /test/)
  2. executing the unit test outside of a docker image (i.e. normal windows 11)

Insight on why this error could be happening or how to get more information out of the external failure would be greatly helpful. Thanks

@delreluca
Copy link
Contributor

delreluca commented Nov 16, 2024

There should be an SEHException.ErrorCode property, maybe if you print the value you can find out more.

Oh, you already did that, sorry…

Maybe the windowsservercore-ltsc2022 image is missing something, like an MSVC redistributable or other libraries? That typically should give you a missing DLL error, but I do not have much experience with Windows containers.

@delreluca
Copy link
Contributor

According to Dependency Walker the MKL libraries do not need MSVC. I’ve read that you can run procmon (SysInternals Process Monitor) in a Windows container to monitor what the process does, maybe this will help

@RobWomack98
Copy link
Author

Will look into this using procmon if I can, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants