ANeuralNetworksMemory_createFromAHardwareBuffer

Function ANeuralNetworksMemory_createFromAHardwareBuffer 

Source
pub unsafe extern "C" fn ANeuralNetworksMemory_createFromAHardwareBuffer(
    ahwb: *const AHardwareBuffer,
    memory: *mut *mut ANeuralNetworksMemory,
) -> c_int
Expand description

Creates a shared memory object from an AHardwareBuffer handle.

If the shared memory is backed by an AHardwareBuffer of AHARDWAREBUFFER_FORMAT_BLOB format, it can be used the same way as shared memory created from a file handle. See {@link ANeuralNetworksMemory} for a description on how to use this shared memory.

If the shared memory is backed by an AHardwareBuffer of a format other than AHARDWAREBUFFER_FORMAT_BLOB, it can only be used for Model inputs and outputs. When calling {@link ANeuralNetworksExecution_setInputFromMemory} or {@link ANeuralNetworksExecution_setOutputFromMemory} with the shared memory, both offset and length must be set to zero and the entire memory region will be associated with the specified input or output operand. There is no guarantee that an arbitrary AHardwareBuffer_Format and AHardwareBuffer_UsageFlags combination can be used by arbitrary devices. The execution will fail if the selected set of devices cannot consume the buffer.

Calling {@link ANeuralNetworksModel_setOperandValueFromMemory} with shared memory backed by an AHardwareBuffer of a format other than AHARDWAREBUFFER_FORMAT_BLOB is disallowed.

The provided AHardwareBuffer must outlive the ANeuralNetworksMemory object.

Available since API level 29.

@param ahwb The AHardwareBuffer handle. @param memory The memory object to be created. Set to NULL if unsuccessful.

@return ANEURALNETWORKS_NO_ERROR if the request completed normally.

@see AHardwareBuffer