Skip to content

D-ONNX-NATIVE-0: lance-graph-onnx, ONNX names over existing native functions - #1754

Merged
AdaWorldAPI merged 8 commits into
mainfrom
feat/lance-graph-onnx-20261023
Oct 24, 2026
Merged

AdaWorldAPI merged 8 commits into
mainfrom
feat/lance-graph-onnx-20261023

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

ONNX is a vocabulary over our existing mathematics, not another execution system. This crate maps ONNX operator names directly onto native functions:

ONNX-compatible Rust API → existing native function

The crate contains:

  • no graph, AST, interpreter or VM;
  • no runtime dispatcher, LazyLock/OnceLock, ClassId routing or per-call backend choice;
  • no SIMD of its own: ndarray owns the kernels.

R2IL routing (D-MPF-4, #1752) is a separate architecture, and this crate does not import it. Plan and crosswalk: .claude/plans/d-onnx-native-v1.md.

What it maps

ALIAS (the native symbol re-exported, pinned by fn_addr_eq):

  • Abs, Sqrt (vml);
  • Greater / GreaterOrEqual / Less / LessOrEqual / Equal (int32 vs a scalar);
  • And / Or / Xor / Not (packed tensor(bool) masks);
  • Where (int32).

INLINE (only the semantic work native lacks):

REFUSE (plan §2): integer arithmetic (ONNX leaves overflow undefined), tensor-vs-tensor compares, MatMul, control flow, protobuf import, automatic Palette substitution.

NATIVE, not exported yet (D-ONNX-NATIVE-1): approximate transcendentals, float ReduceSum tolerance, empty-population min/max. Each row names the decision it is waiting on.

Evidence

Conformance: 11 tests and 1 doctest. They cover:

  • special values and every SIMD tail length;
  • broadcasting against an independent reference;
  • comparison edge thresholds;
  • attribute validation;
  • overflow refusal.

The composite is cross-checked against four independent paths: a plain oracle, a lance-graph-mask-risc program, lance-graph-r2il FoldDialect, and lance-graph-relalg run.

Disable runs: 4, each red on exactly its own test:

  • broadcast check removed;
  • range check removed;
  • noop_with_empty_axes ignored;
  • an alias replaced by a wrapper.

Measurements (ns per call, AVX-512, median of 21; reported, not gated):

rows op direct onnx #1752 wrapper (diagnostic)
64 Greater (ALIAS) 14.6 14.6 —
64 ReduceSum(Where(Greater)) 38.6 39.3 224.4 (3 allocs)
64 Add f32 34.8 35.6 —
4096 ReduceSum(Where(Greater)) 1807.9 1807.3 2047.1

ALIAS and INLINE allocate exactly what direct does: zero, or one for an output array.

Assembly:

  • the alias has no wrapper symbol at all;
  • the inlined composite is 163 instructions vs 147 direct, and the diff is the int32 range check plus the Result write;
  • Add adds only the inlined shape loop;
  • no Lazy, Once, cpuid or feature probe appears anywhere.

Dependencies: the only normal dependency is ndarray, on mask-risc's coordinate and unified by the root [patch]. Nothing depends on this crate (cargo tree -i shows only itself). mask-risc, r2il, relalg and ogar-loco are dev-dependencies only.

Found along the way (for the ndarray owner, not fixed here)

  • vml::vsneg's 16-lane body computes 0.0 - v, so Neg(+0) = +0 for n ≥ 16. That is why Neg is INLINE and not an alias.
  • vml::vsexp saturates +inf to ~3.4e38.

Not done


Generated by Claude Code

…NNX-NATIVE-0)

The new crate depends on ndarray only. It contains no graph, interpreter,
dispatcher, LazyLock/OnceLock or ClassId routing. Each ONNX operator maps to
an existing native function in one of two ways.

ALIAS (re-exported native symbols):
- Abs, Sqrt: hpc::vml.
- Greater / GreaterOrEqual / Less / LessOrEqual / Equal on int32 vs a
  scalar: ndarray::simd *_i32_to_mask.
- And / Or / Xor / Not: mask_*.
- Where (int32): blend_i32.

INLINE (only the semantic work the native call lacks):
- Add / Sub / Mul / Div (f32, f64): a shape-only ONNX broadcast check, then
  ndarray's &a op &b, which broadcasts the same way but panics on a
  mismatch.
- Neg: element map -v. vml::vsneg is not ONNX Neg: its SIMD body returns +0
  for +0.
- ReduceSum (int32, rank 1): attributes validated once; exact i64 sum with
  an int32 range refusal.
- ReduceSum(Where(Greater(X,T),X,0)): gt_i32_to_mask + masked_sum_i32 into
  caller scratch, with the same refusal.

Conformance tests:
- 11 tests, each against an independent per-element reference: special
  floats, every tail length, broadcasting shapes, refusals.
- Alias identity via fn_addr_eq.
- The composite cross-checked against mask-risc, the r2il fold reading and
  relalg.
- A test pins the vsneg divergence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
Adds examples/alias_cost.rs: direct native vs ONNX name vs the #1752
wrapper (diagnostic), with a counting allocator and out-of-line probes
for asm reading. Marks broadcastable, fit, sum_i32 and
sum_where_greater_i32 #[inline], so the composite adapter inlines into
the caller and the only extra instructions are the int32 range check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
Adds .claude/plans/d-onnx-native-v1.md: the source-backed
ALIAS/INLINE/NATIVE/REFUSE crosswalk, the relalg + mask-risc + r2il
cross-check, the direct-vs-onnx-vs-wrapper measurements, the asm
reading and the dependency audit. Adds the crate's test and clippy
steps to rust-test.yml, a STATUS_BOARD section, an INTEGRATION_PLANS
entry and a board entry (index regenerated).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
The CI step added for lance-graph-onnx shifted that line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 91ed4ae2-be07-4024-9a64-9cabc38b0c65
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

AdaWorldAPI pushed a commit that referenced this pull request Oct 23, 2026
[7] sat inside the vertical chain between egglog [6] and Tract [8].
It is a leaf: ONNX names map straight onto existing native functions
and no native layer depends on it. lance-graph-onnx (#1754) implements
it. The S0 ownership question in §6 stays open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review October 23, 2026 22:15
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T22:16:22.131559Z e6d0b2f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

AdaWorldAPI pushed a commit that referenced this pull request Oct 23, 2026
…1754)

Marked supersession: 'R2IL polyfill' reads as the R2IL router
(D-MPF-4), and [7] is the lance-graph-onnx leaf facade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
AdaWorldAPI pushed a commit that referenced this pull request Oct 23, 2026
…1754)

Marked supersession: 'R2IL polyfill' reads as the R2IL router
(D-MPF-4), and [7] is the lance-graph-onnx leaf facade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
AdaWorldAPI pushed a commit that referenced this pull request Oct 23, 2026
…1754)

Marked supersession: 'R2IL polyfill' reads as the R2IL router
(D-MPF-4), and [7] is the lance-graph-onnx leaf facade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
AdaWorldAPI pushed a commit that referenced this pull request Oct 23, 2026
…1754)

Marked supersession: 'R2IL polyfill' reads as the R2IL router
(D-MPF-4), and [7] is the lance-graph-onnx leaf facade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
AdaWorldAPI pushed a commit that referenced this pull request Oct 23, 2026
…1754)

Marked supersession: 'R2IL polyfill' reads as the R2IL router
(D-MPF-4), and [7] is the lance-graph-onnx leaf facade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G22yT6htkcdyXsihxxXdrg
…-20261023

# Conflicts:
#	.claude/board/STATUS_BOARD.md
#	.claude/board/entries/README.md
…-20261023

# Conflicts:
#	.claude/board/STATUS_BOARD.md
#	.claude/board/entries/README.md
@AdaWorldAPI
AdaWorldAPI merged commit cc0bffa into main Oct 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants