Onnxruntime: Expose DirectML to C#

Created on 27 Aug 2020  路  13Comments  路  Source: microsoft/onnxruntime

Is your feature request related to a problem? Please describe.
I need to be able to run inference on an integrated Intel GPU from C#

System information
Microsoft.ML.OnnxRuntime.DirectML v1.4.0 nuget package.

Describe the solution you'd like
There seems to be no ability to select the DirectML provider from the C# api, even when using the DirectML build. I would like that to be exposed.

Describe alternatives you've considered
I have considered using the OpenVINO provider, which apparently recently added C# support. However, there is no nuget package, and I have not yet been able to make it through the installation and build process to see if that works.

C#

Most helpful comment

issue #4876 related

@dashesy - Not sure if these are completely related. The issue here is that there is a Nuget supported for DML (Microsoft.ML.OnnxRuntime.DirectML) and the C# API lacks support for creating sessions that can leverage the binary shipped in the Nuget. #4876 seems to be a request for a Nuget for each EP supported in ORT.

All 13 comments

issue #4876 related

issue #4876 related

@dashesy - Not sure if these are completely related. The issue here is that there is a Nuget supported for DML (Microsoft.ML.OnnxRuntime.DirectML) and the C# API lacks support for creating sessions that can leverage the binary shipped in the Nuget. #4876 seems to be a request for a Nuget for each EP supported in ORT.

Trying to use the DML provider in C# with options.AppendExecutionProvider_Dml() gives the following error:
System.EntryPointNotFoundException: Unable to find an entry point named 'OrtSessionOptionsAppendExecutionProvider_Dml' in DLL 'onnxruntime'.
What am I missing?

You need to build onnxruntime with dml enabled (鈥攗se_dml). Please refer to the steps in Build.md.

@hariharans29 - Thanks for your quick response but I did build onnxruntime with --use_dml option but still having the same error.
Steps taken:

  1. build.bat --use_dml
  2. Open and build /onnxruntime/csharp/OnnxRuntime.CSharp.sln
  3. Open and execute sample Microsoft.ML.OnnxRuntime.InferenceSample with AppendExecutionProvider_Dml() option
  4. System.EntryPointNotFoundException

After some research, it seems to be a problem with the name of the exported function.
The name of the function exported by the onnxruntime.dll is OrtSessionOptionsAppendExecutionProvider_DML() but the CSharp code uses:
OrtSessionOptionsAppendExecutionProvider_dml (dml in lower case).

After fixing the typo, I get the following error:
Exception(1) tid(4990) 80004005 Unspecified error
[onnxruntime::CreateExecutionProviderFactory_DML(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&d3d12_device)))]

Oops you're right, thank you. I ll fix the typo.

@fdwr - Any idea why the DML EP doesn't get initialized properly ?

Its working now. It was probably a problem with my device adapter. Thanks!

Great thanks. Did you pass in a device id of 0 ?

Actually - I get the same exception when I try on my machine. Did you try anything to solve the problem with the device adapter ?

I'm currently using the onnxruntime.dll from package Microsoft.ML.OnnxRuntime.DirectML and it works for me.
I'm passing device id 0.

I've tried using the Microsoft.ML.OnnxRuntime.DirectML 1.4.0 Nuget and I don't see the DML option available. Should it be be there at the moment or would it be in the next update?

It was added after 1.4.0 released. So it should be in the upcoming release or you can build from source following the step listed in the discussion above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JammyZhou picture JammyZhou  路  3Comments

vlad3996 picture vlad3996  路  5Comments

Exlsunshine picture Exlsunshine  路  4Comments

walbermr picture walbermr  路  3Comments

lewisword picture lewisword  路  5Comments