Skip to content

v1.0.0: Rewrite native extension, Ruby API, packaging, and CI from scratch - #2

Merged
benngarcia merged 7 commits into
masterfrom
v1-rewrite
Nov 20, 2026
Merged

benngarcia merged 7 commits into
masterfrom
v1-rewrite

Conversation

@benngarcia

@benngarcia benngarcia commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Complete from-scratch v1.0.0 rewrite targeting ExecuTorch 1.6.0 and Ruby >= 3.2:

flowchart TD
  RB["Ruby Interface (lib/executorch/*)<br/>Module, MethodMeta, Tensor, Numo/Torch adapters, stdlib SDK fetcher"]
  CAPI["Thin Ruby C-API Seam (ext/executorch/rb_*.cpp)<br/>TypedData + dsize + gc_adjust, without_gvl, RB_GC_GUARD, IO::Buffer, only Init_executorch exported"]
  CORE["noexcept C++17 Core (ext/executorch/core/*)<br/>Zero Ruby headers, per-method std::mutex, PAL log capture, X-macro 13 dtypes, NHWC layout"]
  ET["ExecuTorch 1.6.0 Shared SDK<br/>libexecutorch + XNNPACK + optimized & quantized kernels (+ CoreML/MLX on macOS)"]
  RB --> CAPI --> CORE --> ET
Loading

Key changes:

  • Dropped Rice for a noexcept C++17 core + direct Ruby C API, eliminating rb_raise longjmp-past-destructor UB, hidden per-element rb_protect overhead, and unbounded rice >= 4.3 coupling.
  • VM citizenship & safety: rb_thread_call_without_gvl with per-method mutex locking; dsize + rb_gc_adjust_memory_usage; rb_global_variable registration for GC.compact safety; RUBY_TYPED_FROZEN_SHAREABLE; strict symbol hiding (Init_executorch only on Linux ELF and macOS Mach-O); overflow-safe shapes, reentrancy-safe single-pass C++ nested-array flattening, and NHWC strided contiguous normalization.
  • v1 Ruby surface: Executorch::Module (open with :mmap default, Pathname, block cleanup, .ptd data_files, from_bytes, meta, load_method/unload_method, execute/forward/call, close), all 13 numeric/bool dtypes with explicit canonical names (:float32, :int64, etc.), 0-D #item, zero-copy IO::Buffer, out: buffer reuse, symmetric EValue coercion, runtime introspection (backends, kernel_count, num_threads=), and typed Executorch::Error subclasses carrying #code and #pal_log.
  • Distribution & CI: Pure-stdlib SHA-256-verified ExecuTorch 1.6.0 SDK fetcher (lib/executorch/sdk.rb), fat platform gem packaging (rake package_platform with $ORIGIN/../vendor / @loader_path/../vendor rpath), launch-ready README.md, CI matrix across Linux x86_64/arm64 + macOS arm64 + Ruby 3.2–3.4 + ASan/UBSan + zero-skip real .pte/.ptd fixtures, and CI-gated OIDC release.yml.

Calls for Ben to review

  • [scope] Primary distribution via precompiled fat platform gems (x86_64-linux, aarch64-linux, arm64-darwin) bundling official ExecuTorch 1.6.0 shared libs + auto-fetching source fallback.
  • [scope] Minimum Ruby version raised to >= 3.2.0 (for IO::Buffer).
  • [scope] Clean v1.0.0 break: Executorch::Module replaces Executorch::Model; canonical dtypes are explicit-width (:float32, :int64, accepting short aliases on input).

Evidence

Claim Command Artifact
Compiles warning-free, exports only Init_executorch / _Init_executorch, passes all 32 tests (7 real .pte/.ptd models, 0 skips) across Linux x86_64/arm64 & macOS arm64 on Ruby 3.2–3.4 bundle exec rake compile && bundle exec rake test https://github.com/benngarcia/executorch-ruby/actions/runs/44813001012
Zero memory errors or UB under ASan + UBSan EXECUTORCH_SANITIZE=1 bundle exec rake compile && bundle exec rake test https://github.com/benngarcia/executorch-ruby/actions/runs/44813001012
Self-contained fat platform gem installs and runs XNNPACK inference from clean GEM_HOME on Linux & macOS bundle exec rake package_platform && gem install --local pkg/executorch-*-*.gem https://github.com/benngarcia/executorch-ruby/actions/runs/44813001012
  • Before (master @ b03ddcd): Uninstallable from scratch (missing -fPIC, missing module.h, Rice 4.12 compile break), 8/59 tests silently skipped (0 executed model tests), rb_raise longjmp UB, GVL held during inference, portable-only kernels.
  • After (v1-rewrite @ ca36fcff9c85ce6ea55d5607e72e84b50a668c4b): 9/9 CI jobs green (run 44813001012); 32 runs / 247,422 assertions / 0 failures / 0 errors / 0 skips on Linux x86_64, Linux arm64, macOS arm64, Ruby 3.2–3.4, and ASan+UBSan; isolated fat-gem smoke tests green on Ubuntu and macOS; local add_mul zero-copy out: p50 6.3 µs.

Merge Danger

Door: Two-way (prior to publishing v1.0.0 to RubyGems).

Blast Radius: Breaking

Replaces Executorch::Model with Executorch::Module, changes canonical dtype symbols to explicit widths (:float32, :int64), and raises minimum Ruby to >= 3.2.0. Superseded PR #1 is closed in favor of this PR.

Benjamin Garcia added 4 commits November 19, 2026 19:10
…ct Ruby C API

Drop Rice to eliminate rb_raise longjmp-past-destructor UB by construction,
hide all internal symbols (exporting only Init_executorch), release the GVL
around module load and execution with per-method locking, capture PAL logs,
support all 13 numeric/bool dtypes, NHWC dim_order normalization, zero-copy
IO::Buffer, out: buffer reuse, and dsize/gc memory pressure tracking.
…tcher

Introduce Executorch::Module (.open with mmap default, Pathname, .ptd data_files,
block cleanup, .from_bytes), MethodMeta/TensorInfo introspection, explicit-width
canonical dtypes, Numo/Torch adapters, and a stdlib SHA-256-verified ExecuTorch
1.6.0 C++ SDK fetcher with fat platform gem packaging.
…benchmarks

Replace silently skipped model tests with real golden-verified .pte/.ptd
fixtures (0 skips) plus adversarial OOB/overflow, reentrancy, GC.stress/compact,
GVL-release concurrency, symbol-visibility, and RSS leak checks.
Benjamin Garcia added 3 commits November 19, 2026 23:54
…r GC.compact

Prevents stale class VALUE pointers after GC.compact on Ruby 3.2+ (caught by
SafetyTest running GC.compact before ModuleTest#test_method_meta_and_lifecycle).
Also synchronize ticker thread startup in the GVL-release test.
@benngarcia
benngarcia merged commit 46a35b0 into master Nov 20, 2026
9 checks passed
@benngarcia
benngarcia deleted the v1-rewrite branch November 20, 2026 20:39
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.

1 participant