AddInitializerToGraph property
\brief Add an initializer to the OrtGraph
ORT will take ownership of the OrtValue and you should NOT call ReleaseOrtValue.
Two options:
Allocated memory:
Use CreateTensorAsOrtValue (allocates memory) and populate the tensor with the data.
Set data_is_external to false.
Pre-existing memory:
Use CreateTensorWithDataAsOrtValue or CreateTensorWithDataAndDeleterAsOrtValue to create an OrtValue
with a tensor that contains a pointer to the existing data.
Set data_is_external to true.
The pointer must remain valid for the duration of the inference session. If using CreateTensorWithDataAsOrtValue you are responsible for freeing the memory after the inference session is released. If using CreateTensorWithDataAndDeleterAsOrtValue, ORT will free the memory using the provided deleter as soon as the OrtValue is no longer in use.
NOTE: A tensor containing pre-existing memory MUST have 128 bytes of data or more. For smaller tensors use CreateTensorAsOrtValue.
ONNX shape inferencing does not support external data. An initializer involved in shape inferencing is
typically small (a single value or limited by the rank of a tensor) and uses less than 128 bytes of
memory, so this limit acts as a simple catch-all rule to avoid issues.
e.g. Reshape's shape, Clip's min and max, various ops axes.
\paramin graph The OrtGraph instance to update.
\paramin name The value name for the initializer.
\paramin tensor The OrtValue instance containing the tensor data.
\paramin data_is_external Set to true if the data is external and should not be copied.
\snippet{doc} snippets.dox OrtStatus Return Value
\since Version 1.22.
Implementation
external ffi.Pointer<
ffi.NativeFunction<
OrtStatusPtr Function(
ffi.Pointer<OrtGraph> graph,
ffi.Pointer<ffi.Char> name,
ffi.Pointer<OrtValue> tensor,
ffi.Bool data_is_external,
)
>
>
AddInitializerToGraph;