robertknight / rten

ONNX neural network inference engine
124 stars 9 forks source link

Convert `NodeId` from an alias for `usize` to u32-sized opaque type #381

Closed robertknight closed 1 month ago

robertknight commented 1 month ago

Align the representation of NodeId values with the FlatBuffers schema, which uses uint (u32) as the type, except for operator inputs and outputs where ints are used, with negative values representing missing optional inputs.

Since node IDs are in the range [0, i32::MAX] we can reserve higher values as a niche, making Option<NodeId> the same size as a NodeId.

Performance-wise the main function of interest is Graph::run_plan. Testing with GPT-2 which has 3.3K operations, the change appears to be a small win or neutral. The time spent in run_plan drops from ~3.2% of runtime to ~3.0%.