ANeuralNetworksMemory_createFromDesc

Function ANeuralNetworksMemory_createFromDesc 

Source
pub unsafe extern "C" fn ANeuralNetworksMemory_createFromDesc(
    desc: *const ANeuralNetworksMemoryDesc,
    memory: *mut *mut ANeuralNetworksMemory,
) -> c_int
Expand description

Creates a memory object from a memory descriptor.

The memory object is created with an uninitialized buffer. A memory object with an uninitialized buffer may only be used according to the roles specified by {@link ANeuralNetworksMemoryDesc_addOutputRole}, or as the destination memory in {@link ANeuralNetworksMemory_copy}. The buffer of a memory object is initialized after the memory object is used as an output in a successful execution, or used as the destination memory in a successful {@link ANeuralNetworksMemory_copy}. A memory object with an initialized buffer may be used according to all roles specified in {@link ANeuralNetworksMemoryDesc}, or as the source or destination memory in {@link ANeuralNetworksMemory_copy}. The buffer of a memory object will return to the uninitialized state if the memory object is used as an output in a failed execution, or used as the destination memory in a failed {@link ANeuralNetworksMemory_copy}.

The dimensions of the memory descriptor are deduced from the dimensions of the corresponding model operands of all the roles specified by {@link ANeuralNetworksMemoryDesc_addInputRole} and {@link ANeuralNetworksMemoryDesc_addOutputRole}, as well as the dimensions set by the call to {@link ANeuralNetworksMemoryDesc_setDimensions}, if any. The memory descriptor may have unspecified dimensions or rank. In such a case, the same memory object may be used with different shapes of outputs in different executions. When the memory is used as an input, the input shape must be the same as the output shape from the last execution using this memory object as an output, or the last {@link ANeuralNetworkMemory_copy} using this memory object as the destination memory. Creating a memory object with unspecified dimensions or rank may fail for certain sets of roles.

Using the memory in roles or shapes that are not compatible with the rules specified above will return an error.

When calling {@link ANeuralNetworksExecution_setInputFromMemory} or {@link ANeuralNetworksExecution_setOutputFromMemory} with the memory object, both offset and length must be set to zero and the entire memory region will be associated with the specified input or output operand.

Calling {@link ANeuralNetworksModel_setOperandValueFromMemory} with the memory created from this function will return an error.

{@link ANeuralNetworksMemory_free} must be called once the memory is no longer needed.

Attempting to create memory from an unfinished memory descriptor will return an error.

The provided {@link ANeuralNetworksMemoryDesc} need not outlive the {@link ANeuralNetworksMemory} object.

Available since API level 30.

@param desc The memory descriptor. @param memory The memory object to be created. Set to NULL if unsuccessful.

@return ANEURALNETWORKS_NO_ERROR if successful; ANEURALNETWORKS_OP_FAILED if the memory is created with unspecified dimensions or rank and it is not supported for this set of roles.