DirectML Samples

Windows Machine Learning Development
Windows Development DirectML Home View All Samples

DirectML Model Conversion

Convert your existing machine learning models to a format optimized for DirectML, enabling hardware-accelerated inference on Windows devices. DirectML provides a high-performance layer for machine learning on Windows, leveraging DirectX 12 compute capabilities.

Important: Ensure you have the latest Windows SDK and DirectML NuGet package installed for optimal compatibility.

Supported Model Formats

DirectML supports conversion from several popular machine learning frameworks. The primary tool for this is the DirectMLX converter.

Using the DirectMLX Converter

The DirectMLX tool is a command-line utility that facilitates the conversion process. It's typically included with the DirectML SDK or available as a separate NuGet package.

Example: Converting an ONNX Model

To convert an ONNX model named my_model.onnx to the DirectML operator graph format, use the following command:

directmlx.exe convert --input-model my_model.onnx --output-model my_model.dml --platform windows --target arch_x64

Key parameters:

  • --input-model: Path to your source model file (e.g., ONNX).
  • --output-model: Desired path for the converted DirectML model.
  • --platform: Target operating system (e.g., windows).
  • --target: Target architecture (e.g., arch_x64 for 64-bit Intel/AMD).

Conversion Considerations

When converting models, keep the following in mind:

Integration with DirectML API

Once converted, your .dml file can be loaded and executed using the DirectML C++ API. This involves:

  1. Initializing DirectML Device and Command Queue.
  2. Loading the operator graph from the .dml file.
  3. Creating Input and Output Resources (e.g., ID3D12Resource).
  4. Binding resources and dispatching the compute.
  5. Synchronizing and retrieving results.

Refer to the DirectML API Reference for detailed usage.

Resources