TECHNOLOGY

Linux IIO scans: enabled channels do not form a packed array of native values

In this article
THE QUICK TAKE

Build the decoder from the enabled scan elements and their declared storage contract; filenames, valid-bit counts and tensor shapes do not determine physical scan offsets.

The tensor shape is correct but its channels are wrong

An edge model receives a sensor feature vector of the expected length, yet its values change unexpectedly when another IIO channel is enabled. The application casts each scan as a packed native-language structure and assumes channel files appear in byte order. The declared tensor shape cannot validate that assumption. Capture the actual enabled scan elements and their metadata before investigating model drift. A parser can remain within the input buffer while consistently interpreting padding or another channel as a valid feature.

Use enablement together with scan indices

The IIO buffer documentation says channel indices are independent of enablement and may be noncontiguous. Combine each element’s enable state, index and type to reconstruct the current layout. Directory iteration order is not the contract. Preserve the metadata snapshot with the acquisition configuration and update the decoder when that configuration changes. Adding a timestamp or disabling an intermediate channel can alter offsets and stride even if the application still extracts the same number of model features afterward.

Valid bits and storage bits answer different questions

The documented type le:s12/16>>4 represents signed little-endian data with valid bits inside a wider storage element and a shift before masking. Use storage width for locating the next element, then apply the declared interpretation to the current value. Do not sign-extend an unrelated padding region or treat the valid-bit count as a packed byte length. Other declared formats require their own supported decoding path; one integer example cannot justify silently interpreting every channel as the same native integer type.

Account for padding and physical-value conversion

The kernel generic-buffer example calculates channel locations and scan padding before interpreting data. It also separates endian/bit extraction from scale and offset conversion. Review the selected channel’s conversion contract independently of the storage grammar. Raw decoding can be correct while physical units or model normalization are wrong. Treat this example as inspectable implementation guidance with supported-format limits, not evidence that copying its output routine makes every possible IIO device or future scan format compatible.

Propose a metadata-driven scan fixture

Use harmless synthetic scans with known signed and unsigned values, disabled-index gaps and padding. Change only the enabled channel set and verify the rebuilt decoder’s offsets, stride and feature identities. Include unsupported type metadata and a truncated scan for clear rejection rather than guessed completion. Acceptance requires the known raw values and declared conversions before testing the model. No sensor capture or kernel example ran here; the fixture describes decoder evidence without inventing a measured sample rate or accuracy result.

Preserve layout evidence before quality conclusions

Binary tensor boundaries establish another framing contract. Device-buffer metadata and lifetime explain why a pointer is insufficient. IIO adds a sensor-specific scan schema before feature extraction. Retain enabled channels, indices, storage types and conversion settings with the model input. This makes a quality regression reproducible without assuming that matching vector length, plausible numbers or an unchanged device filename establishes unchanged physical observations.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles