fn filter_ids(ids: &mut [u32; 32], keep: impl Fn(u32) -> bool)Expand description
Drop the hidden GPUs from a gpuIds[] array in place — but only ever a strict subset, so
the filter can never accidentally blank out every GPU and strand the container with none. Ids
that pass keep are compacted to the front and the rest back-filled with INVALID_GPU_ID.
- Scan the populated prefix: iterate until the first
INVALID_GPU_ID, countingtotallive ids and collecting the kept ones into a scratch array (nkept). - Commit only a strict subset (
0 < nkept < total): copy the kept prefix back overidsand set every trailing slot toINVALID_GPU_ID. - Fail-safe: if none survive or all survive, leave the array untouched — never blank out every GPU, and never do redundant work when nothing was dropped.
The keep predicate is injected so this stays free of /proc and /dev access and is
unit-testable in isolation.