mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-14 18:12:05 +00:00
Add csharp dml sample code to EP doc and Stable Diff Repo (#15103)
This commit is contained in:
parent
c7ea60ef39
commit
c5dfd1ce81
2 changed files with 18 additions and 1 deletions
|
|
@ -67,6 +67,7 @@ When using the [C API](../get-started/with-c.md) with a DML-enabled build of onn
|
|||
|
||||
Creates a DirectML Execution Provider which executes on the hardware adapter with the given `device_id`, also known as the adapter index. The device ID corresponds to the enumeration order of hardware adapters as given by [IDXGIFactory::EnumAdapters](https://docs.microsoft.com/windows/win32/api/dxgi/nf-dxgi-idxgifactory-enumadapters). A `device_id` of 0 always corresponds to the default adapter, which is typically the primary display GPU installed on the system. Beware that in systems with multiple GPU's, the primary display (GPU 0) is often not the most performant one, particularly on laptops with dual adapters where battery lifetime is preferred over performance. So you can double check in Task Manager's performance tab to see which GPU is which. A negative `device_id` is invalid.
|
||||
|
||||
Example for C API:
|
||||
```c
|
||||
OrtStatus* OrtSessionOptionsAppendExecutionProvider_DML(
|
||||
_In_ OrtSessionOptions* options,
|
||||
|
|
@ -74,6 +75,16 @@ OrtStatus* OrtSessionOptionsAppendExecutionProvider_DML(
|
|||
);
|
||||
```
|
||||
|
||||
Example for C# API:
|
||||
|
||||
Install the Nuget Package [Microsoft.ML.OnnxRuntime.DirectML](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.DirectML/1.14.1) and use the following code to enable the DirectML EP:
|
||||
|
||||
```csharp
|
||||
SessionOptions sessionOptions = newSessionOptions();
|
||||
sessionOptions.GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_ALL;
|
||||
sessionOptions.AppendExecutionProvider_DML(0);
|
||||
```
|
||||
|
||||
### `OrtSessionOptionsAppendExecutionProviderEx_DML` function
|
||||
{: .no_toc }
|
||||
|
||||
|
|
@ -87,6 +98,7 @@ OrtStatus* OrtSessionOptionsAppendExecutionProviderEx_DML(
|
|||
);
|
||||
```
|
||||
|
||||
|
||||
## Configuration Options
|
||||
|
||||
The DirectML execution provider does not support the use of memory pattern optimizations or parallel execution in onnxruntime. When supplying session options during InferenceSession creation, these options must be disabled or an error will be returned.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,12 @@ This tutorial can be run locally or in the cloud by leveraging Azure Machine Lea
|
|||
To run locally:
|
||||
|
||||
- [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [VS Code](https://code.visualstudio.com/Download)
|
||||
- A GPU enabled machine with CUDA EP Configured. This was built on a GTX 3070 and it has not been tested on anything smaller. Follow [this tutorial to configure CUDA and cuDNN for GPU with ONNX Runtime and C# on Windows 11](https://onnxruntime.ai/docs/tutorials/csharp/csharp-gpu.html)
|
||||
|
||||
- A GPU enabled machine with CUDA or DirectML on Windows
|
||||
- Configure CUDA EP. Follow [this tutorial to configure CUDA and cuDNN for GPU with ONNX Runtime and C# on Windows 11](https://onnxruntime.ai/docs/tutorials/csharp/csharp-gpu.html)
|
||||
- Windows comes with DirectML support. No additional configuration is needed. Be sure to clone the [`direct-ML-EP`](https://github.com/cassiebreviu/StableDiffusion/tree/direct-ML-EP) branch of this repo if you choose this option.
|
||||
- This was built on a GTX 3070 and it has not been tested on anything smaller.
|
||||
|
||||
|
||||
To run in the cloud with Azure Machine Learning:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue