DirectML API Reference

DMLCreateDevice

Function Signature


HRESULT DMLCreateDevice(
    _In_opt_ IUnknown *pAdapter,
    _In_ DML_CREATE_DEVICE_FLAGS flags,
    _In_ REFIID riid,
    _COM_Outptr_ void **ppvDevice
);
            

Description

Creates a DirectML device. This device is the primary object for interacting with DirectML, and it represents a connection to the underlying hardware. You use the device to create operators, command lists, and other DirectML objects.

Parameters

pAdapter

  • Type: IUnknown*
  • Description: An optional pointer to an adapter object (e.g., a Direct3D 12 adapter). If nullptr, the default adapter will be used.

flags

  • Type: DML_CREATE_DEVICE_FLAGS
  • Description: Flags that specify how to create the device. Can be DML_CREATE_DEVICE_FLAG_NONE or DML_CREATE_DEVICE_FLAG_DEBUG.

riid

  • Type: REFIID
  • Description: The globally unique identifier (GUID) of the desired DirectML device interface. Typically __uuidof(IDMLDevice).

ppvDevice

  • Type: void**
  • Description: A pointer to a memory block that receives a pointer to the newly created DirectML device.

Return Value

HRESULT

Returns an HRESULT success or error code. Typical success code is S_OK. Errors might include E_INVALIDARG if invalid parameters are provided, or DXGI_ERROR_UNSUPPORTED if the hardware or driver does not support DirectML.

DMLCreateOperatorInitializer

Function Signature


HRESULT DMLCreateOperatorInitializer(
    _In_ IDMLDevice *pDevice,
    _In_ IDMLOperator *pOperator,
    _In_ IDMLOperatorInitializer **ppInitializer
);
            

Description

Creates an operator initializer for a given operator. An operator initializer is used to bind required persistent resources to an operator before it can be compiled or executed. This is typically used for operators that have persistent resources like weights or trained parameters.

Parameters

pDevice

  • Type: IDMLDevice*
  • Description: The DirectML device.

pOperator

  • Type: IDMLOperator*
  • Description: The operator for which to create the initializer.

ppInitializer

  • Type: IDMLOperatorInitializer**
  • Description: A pointer to a memory block that receives a pointer to the newly created operator initializer.

Return Value

HRESULT

Returns an HRESULT success or error code. S_OK on success.

DMLCreateOperator

Function Signature


HRESULT DMLCreateOperator(
    _In_ IDMLDevice *pDevice,
    _In_ const DML_OPERATOR_DESC *pOperatorDesc,
    _In_ REFIID riid,
    _COM_Outptr_ void **ppOperator
);
            

Description

Creates a DirectML operator based on the provided operator description. Operators represent the individual computations within a machine learning graph, such as convolution, GEMM, or activation functions.

Parameters

pDevice

  • Type: IDMLDevice*
  • Description: The DirectML device.

pOperatorDesc

  • Type: const DML_OPERATOR_DESC*
  • Description: A pointer to a structure that describes the operator to create. The specific structure depends on the operator type (e.g., DML_CONVOLUTION_OPERATOR_DESC, DML_GEMM_OPERATOR_DESC).

riid

  • Type: REFIID
  • Description: The globally unique identifier (GUID) of the desired DirectML operator interface. Typically __uuidof(IDMLOperator).

ppOperator

  • Type: void**
  • Description: A pointer to a memory block that receives a pointer to the newly created DirectML operator.

Return Value

HRESULT

Returns an HRESULT success or error code. S_OK on success.

dml_operator_set_input_data_buffer

Function Signature


void DML_BINDING_DESC_DIRECT3D12_SET_INPUT_DATA_BUFFER(
    _In_ IDMLOperator *pOperator,
    _In_ UINT32 Index,
    _In_ DML_BINDING_TYPE Type,
    _In_reads_bytes_opt_(Size) void const *pData,
    _In_ UINT64 Size
);
            

Description

A utility macro/function to set an input data buffer for an operator binding. This is part of the binding mechanism for operators, allowing you to specify where input data resides.

Parameters

pOperator

  • Type: IDMLOperator*
  • Description: The operator.

Index

  • Type: UINT32
  • Description: The index of the input.

Type

  • Type: DML_BINDING_TYPE
  • Description: The type of binding (e.g., DML_BINDING_TYPE_NONE, DML_BINDING_TYPE_BUFFER).

pData

  • Type: void const*
  • Description: Pointer to the data.

Size

  • Type: UINT64
  • Description: Size of the data in bytes.

Return Value

This function does not return a value.

dml_operator_set_output_data_buffer

Function Signature


void DML_BINDING_DESC_DIRECT3D12_SET_OUTPUT_DATA_BUFFER(
    _In_ IDMLOperator *pOperator,
    _In_ UINT32 Index,
    _In_ DML_BINDING_TYPE Type,
    _In_reads_bytes_opt_(Size) void const *pData,
    _In_ UINT64 Size
);
            

Description

A utility macro/function to set an output data buffer for an operator binding. Similar to setting input data, this defines where the operator's output will be stored.

Parameters

pOperator

  • Type: IDMLOperator*
  • Description: The operator.

Index

  • Type: UINT32
  • Description: The index of the output.

Type

  • Type: DML_BINDING_TYPE
  • Description: The type of binding.

pData

  • Type: void const*
  • Description: Pointer to the data.

Size

  • Type: UINT64
  • Description: Size of the data in bytes.

Return Value

This function does not return a value.

DMLExecuteOperator

Function Signature


HRESULT DMLExecuteOperator(
    _In_ IDMLCommandRecorder *pCommandRecorder,
    _In_ IDMLOperator *pOperator,
    _In_ const DML_EXECUTE_ARGUMENTS *pArguments
);
            

Description

Records an operator execution command into a DirectML command list. This is how you tell DirectML to perform the computation defined by an operator. The execution is asynchronous and typically managed within a Direct3D 12 command queue.

Parameters

pCommandRecorder

  • Type: IDMLCommandRecorder*
  • Description: A pointer to the DirectML command recorder.

pOperator

  • Type: IDMLOperator*
  • Description: The operator to execute.

pArguments

  • Type: const DML_EXECUTE_ARGUMENTS*
  • Description: A structure containing information about the inputs, outputs, and temporary resources for the operator execution.

Return Value

HRESULT

Returns an HRESULT success or error code. S_OK on success.

DMLCloseDevice

Function Signature


void DMLCloseDevice(
    _In_ IDMLDevice *pDevice
);
            

Description

Releases a DirectML device. This function is typically called when the DirectML device is no longer needed. It ensures that all associated resources are properly cleaned up.

Parameters

pDevice

  • Type: IDMLDevice*
  • Description: The DirectML device to close.

Return Value

This function does not return a value.