Skip to main content

Module neural_network

Module neural_network 

Source
Expand description

Neural network device class control commands and protocol definitions.

Neural network devices are registered under class prefix crate::kind::NEURAL_NETWORK (b'N').

§Protocol Overview

Applications interact with neural network character devices using standard VFS operations ([file_system::BaseOperations]):

  • Fixed-model devices (NeuralNetworkDevice): A platform mounts a fixed model at a designated path (e.g. /devices/nn/digit_classifier).

    1. Query tensor counts and shapes using GET_INPUT_COUNT, GET_INPUT_INFO, GET_OUTPUT_COUNT, and GET_OUTPUT_INFO.
    2. Select the input tensor index using SET_INPUT_INDEX. Seek the file descriptor to 0 and write the tensor bytes sequentially with write().
    3. Execute inference by issuing the COMPUTE command.
    4. Select the output tensor index using SET_OUTPUT_INDEX. Seek the file descriptor to 0 and read the result bytes with read().
    5. Closing the file descriptor releases the per-open execution arena.
  • Runtime model loader devices (LoaderDevice): A platform mounts a loader node (e.g. /devices/nn/cpu).

    1. Open the loader node. The descriptor starts in the Staging state.
    2. Write the model binary bytes sequentially from offset 0 using write(). Writes beyond the loader’s maximum model size are rejected with [file_system::IoErrorKind::FileTooLarge]. Non-contiguous writes are rejected with [file_system::IoErrorKind::InvalidArgument].
    3. Send the LOAD command with a LoadRequest payload (e.g. TensorFlow Lite format). Upon successful preparation, the descriptor transitions to the Ready state.
    4. From this point forward, the descriptor behaves identically to a fixed-model device: input/output inspection, tensor staging via write(), COMPUTE, and output retrieval via read().
    5. Attempting inference commands before LOAD returns [file_system::IoErrorKind::InvalidState]. A second LOAD on a ready descriptor returns [file_system::IoErrorKind::InvalidState].
    6. Closing the descriptor frees both the dynamically allocated model and its execution state.

Structs§

COMPUTE
GET_INPUT_COUNT
GET_INPUT_INFO
GET_INPUT_QUANTIZATION
GET_OUTPUT_COUNT
GET_OUTPUT_INFO
GET_OUTPUT_QUANTIZATION
LOAD
LoadRequest
Request payload for the LOAD control command.
QuantizationEntry
One scale/zero-point pair for a tensor quantization axis. Layout: scale at offset 0, reserved at offset 4 (must be zero when read back), zero_point at offset 8; 16 bytes, no padding.
QuantizationRequest
Selects a quantization entry for an input or output tensor.
SET_INPUT_INDEX
SET_OUTPUT_INDEX
TensorInfo
Metadata returned by GET_INPUT_INFO and GET_OUTPUT_INFO.

Constants§

MAX_TENSOR_RANK
Maximum rank in the version-one VFS tensor metadata layout.