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

[Documentation] How do I use the DirectML EP from an NUnit unit test? #17793

Open
klasma opened this issue Oct 5, 2023 · 10 comments
Open

[Documentation] How do I use the DirectML EP from an NUnit unit test? #17793

klasma opened this issue Oct 5, 2023 · 10 comments
Labels
documentation improvements or additions to documentation; typically submitted using template ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot

Comments

@klasma
Copy link

klasma commented Oct 5, 2023

I am not able to select the DirectML EP from a unit test. I assume that it is possible somehow and therefore I am tagging this as a documentation issue. I am using version 1.16.0 of the Microsoft.ML.OnnxRuntime.DirectML nuget and Windows 10. Here is the code that I am running:

using Microsoft.ML.OnnxRuntime;

namespace DirectMLTest
{
    public class Tests
    {
        [SetUp]
        public void Setup()
        {
        }

        [Test]
        public void Test1()
        {
            var sessionOptions = new SessionOptions();
            sessionOptions.AppendExecutionProvider_DML();
            Assert.Pass();
        }
    }
}

I am getting the following error:

Microsoft.ML.OnnxRuntime.OnnxRuntimeException : [ErrorCode:RuntimeException] D:\a_work\1\s\onnxruntime\core\providers\dml\dml_provider_factory.cc(158)\onnxruntime.DLL!00007FFCAB1BA1C0: (caller: 00007FFCAB1B9EAE) Exception(1) tid(9b74) 887A0004 The specified device interface or feature level is not supported on this system.

at Microsoft.ML.OnnxRuntime.SessionOptions.AppendExecutionProvider_DML(Int32 deviceId)
at DirectMLTest.Tests.Test1() in C:\git\DirectMLTest\DirectMLTest\DirectMLTest\UnitTest1.cs:line 16

If I run the same code in a console app, everything works as expected and it also works if I replace AppendExecutionProvider_DML with AppendExecutionProvider_CPU.

I am using the x64 configuration and not Any CPU. I read that the Any CPU configuration could cause similar problems.

Page / URL

No response

@klasma klasma added the documentation improvements or additions to documentation; typically submitted using template label Oct 5, 2023
@github-actions github-actions bot added ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform labels Oct 5, 2023
@klasma klasma changed the title [Documentation] How do I use the DirectML EP from an NUnit unit test? [Documentation] How to use the DirectML EP from an NUnit unit test? Oct 5, 2023
@klasma klasma changed the title [Documentation] How to use the DirectML EP from an NUnit unit test? [Documentation] How do I use the DirectML EP from an NUnit unit test? Oct 5, 2023
@wschin
Copy link
Contributor

wschin commented Oct 5, 2023

Looks like you have an old DirectML. The code throwing that error is

  ORT_THROW_IF_FAILED(DMLCreateDevice1(d3d12_device.Get(),
                                   flags,
                                   DML_FEATURE_LEVEL_5_0,
                                   IID_PPV_ARGS(&dml_device)));

And DML_FEATURE_LEVEL_5_0 is available after DirectML version 1.8.0.

@wchao1115
Copy link

@klasma if you get your ORT package from nuget.org, the dependencies tab should clearly mark which corresponding version of DirectML you'll need to successfully run ORT end to end. i.e. https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.DirectML#dependencies-body-tab

@klasma
Copy link
Author

klasma commented Oct 5, 2023

Thank you very much for your input. I am getting the Microsoft.ML.OnnxRuntime.DirectML nuget from nuget.org and the correct version of DirectML.dll seems to be in the bin directory next to my test assembly. Is an older version of the dll found somewhere in my windows installation? At first I thought that "C:\Windows\System32\directml.dll" was found, but if I drop that file in the bin-directory of my console application where everything works fine, I get a different error so I assumed that that was not the case. How do I solve this issue?

image

Copy link
Contributor

github-actions bot commented Nov 5, 2023

This issue has been automatically marked as stale due to inactivity and will be closed in 7 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Nov 5, 2023
@matteosal
Copy link

Looks like you have an old DirectML. The code throwing that error is

  ORT_THROW_IF_FAILED(DMLCreateDevice1(d3d12_device.Get(),
                                   flags,
                                   DML_FEATURE_LEVEL_5_0,
                                   IID_PPV_ARGS(&dml_device)));

And DML_FEATURE_LEVEL_5_0 is available after DirectML version 1.8.0.

@wschin I'm getting this error when trying to use the DML provider from the C API on Windows 10. This document states that feature level 5 / DML v1.8.0 is indeed only available on Windows 11: https://learn.microsoft.com/en-us/windows/ai/directml/dml-version-history

So this means that the DML provider is not supported on Windows 10 out of the box. Is it possible to get it to work by manually installing DML 1.8.0, or is this version incompatible with Windows 10?

@edward0802
Copy link

@klasma did you resolve this issue on Windows 10?

@klasma
Copy link
Author

klasma commented Mar 5, 2024

No, I did not.

@edward0802
Copy link

@klasma thanks for the quick response. So there is no way to use Microsoft.ML.OnnxRuntime.DirectML v 1.16.0 on Windows 10? how about lower versions of Microsoft.ML.OnnxRuntime.DirectML do they work on Windows 10?

@klasma
Copy link
Author

klasma commented Mar 5, 2024

I was able to run inrerence, but not from tests in NUnit.

@klasma
Copy link
Author

klasma commented Mar 5, 2024

I never tried earlier versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation improvements or additions to documentation; typically submitted using template ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

5 participants