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).- Query tensor counts and shapes using
GET_INPUT_COUNT,GET_INPUT_INFO,GET_OUTPUT_COUNT, andGET_OUTPUT_INFO. - Select the input tensor index using
SET_INPUT_INDEX. Seek the file descriptor to 0 and write the tensor bytes sequentially withwrite(). - Execute inference by issuing the
COMPUTEcommand. - Select the output tensor index using
SET_OUTPUT_INDEX. Seek the file descriptor to 0 and read the result bytes withread(). - Closing the file descriptor releases the per-open execution arena.
- Query tensor counts and shapes using
-
Runtime model loader devices (
LoaderDevice): A platform mounts a loader node (e.g./devices/nn/cpu).- Open the loader node. The descriptor starts in the Staging state.
- 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]. - Send the
LOADcommand with aLoadRequestpayload (e.g. TensorFlow Lite format). Upon successful preparation, the descriptor transitions to the Ready state. - From this point forward, the descriptor behaves identically to a fixed-model device:
input/output inspection, tensor staging via
write(),COMPUTE, and output retrieval viaread(). - Attempting inference commands before
LOADreturns [file_system::IoErrorKind::InvalidState]. A secondLOADon a ready descriptor returns [file_system::IoErrorKind::InvalidState]. - 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
- Load
Request - Request payload for the
LOADcontrol command. - Quantization
Entry - One scale/zero-point pair for a tensor quantization axis. Layout:
scaleat offset 0,reservedat offset 4 (must be zero when read back),zero_pointat offset 8; 16 bytes, no padding. - Quantization
Request - Selects a quantization entry for an input or output tensor.
- SET_
INPUT_ INDEX - SET_
OUTPUT_ INDEX - Tensor
Info - Metadata returned by
GET_INPUT_INFOandGET_OUTPUT_INFO.
Constants§
- MAX_
TENSOR_ RANK - Maximum rank in the version-one VFS tensor metadata layout.