Skip to content

Refactor generated kernels into an immutable registry - #12

Merged
onlyxItachi merged 1 commit into
mainfrom
feat/alpha-generated-elf-registry
Aug 2, 2026
Merged

Refactor generated kernels into an immutable registry#12
onlyxItachi merged 1 commit into
mainfrom
feat/alpha-generated-elf-registry

Conversation

@onlyxItachi

Copy link
Copy Markdown
Owner

Summary

  • replace the add-specific generated-ELF singleton with a closed manifest-driven registry
  • bind each generated kernel by both device-artifact cache identity and immutable receipt identity
  • preserve native capability authority, legacy evidence schemas, transactional XRT publication, and the exact BF16[1024] add-only support boundary

Why

The current singleton could not safely coexist with a second physically qualified generated kernel. This change creates the narrow runtime and artifact-admission foundation needed by the matmul work without claiming matmul or changing the active product surface.

Validation

  • complete hardware-free suite: 726 passed, 15 expected skips in the final installed-extension environment
  • focused evidence, registry, initialization, and Inductor suite: 161 passed
  • independent review suite: 80 passed
  • Ruff check and format: passed
  • strict mypy: passed
  • shell syntax and diff checks: passed
  • rebuilt CPython 3.12 native extension SHA-256: c810e2ff4bd89938a6e2a4145fffed6e1c149f29b6f8bc57e1f4a99bb73ba5b7

Physical evidence

The exact commit tree was exercised from a fresh compiler cache on RyzenAI-npu4 with XRT 2.20:

  • cold, warm, and trapped-wrapper BF16[1024] Strategy B launches completed
  • 1024 of 1024 raw BF16 words matched on every launch
  • output stayed on xdna:0 until explicit copy-back
  • ERT_CMD_STATE_COMPLETED with positive device intervals
  • one validated direct three-BO ELF load across all launches
  • alias rejection changed no allocation, cache, execution, or runtime state
  • post-run XRT platform health passed

Boundary

This PR does not add matmul, a second manifest entry, a new operator, a public API, fallback behavior, a compiler fork, or artifact distribution. The manifest and native validators remain restricted to the one already qualified BF16 add until the next receipt is independently proven.

AI-assisted development: OpenAI Codex assisted implementation, testing, and review. The human maintainer retains responsibility for the change.

Problem:
The generated Strategy B ELF service and native runtime were singletons, so a second physically qualified generated kernel could not coexist without replacing process-global artifact state.

Ownership:
This is downstream torch-xdna artifact admission, compiler cache, native XRT runtime, Inductor wiring, tests, and documentation. It does not change PyTorch, Triton-XDNA, MLIR-AIR, XRT, firmware, or driver ownership.

Implementation boundary:
Replace the add-specific service with a closed manifest-driven registry keyed by device-artifact cache and receipt identities. Store independently constructed native ELF states per immutable key, reject either identity being reused for another specification, and retain the exact legacy runtime-stats evidence schema. Keep native capability selection and all product admission validators restricted to the already proven BF16[1024] add.

Test Plan:
- python -m pytest -q -p no:cacheprovider
- python -m pytest -q -p no:cacheprovider tests/test_acceptance_physical.py tests/test_alpha_physical_evidence_validator.py tests/test_generated_elf_native_contract.py tests/test_generated_kernel_registry.py tests/test_strategy_b_initialization.py tests/test_inductor_adapter.py
- python -m ruff check .
- python -m ruff format --check .
- python -m mypy --follow-imports=skip --ignore-missing-imports --strict build_support.py torch_xdna/_artifact_paths.py torch_xdna/_capability.py torch_xdna/_cache_runtime.py torch_xdna/_compiler_artifacts.py torch_xdna/_compiler_cache.py torch_xdna/_compiler_contracts.py torch_xdna/_generated_kernel_registry.py torch_xdna/_triton_adapter.py scripts/_acceptance_physical.py scripts/_bootstrap_receipt.py scripts/_package_inventory.py scripts/run_acceptance.py scripts/validate_alpha_physical_evidence.py scripts/validate_physical_evidence.py scripts/validate_physical_range.py scripts/verify_artifacts.py tests/physical_support.py
- python tests/physical_inductor_strategy_b_bfloat16_add.py
- xrt-smi examine --device DEVICE --report platform

Physical evidence:
A rebuilt non-editable CPython 3.12 extension passed cold, warm, and trapped-wrapper BF16[1024] add launches on RyzenAI-npu4. All 1,024 raw BF16 words matched, outputs remained on xdna:0 until copy-back, ERT completed with positive intervals, the exact direct three-BO artifact loaded once, unsupported aliasing had no side effects, and post-run XRT health passed.

Limitations:
The product manifest and native validators still admit only the exact proven BF16[1024] add. Independent multi-entry physical execution, matmul, broader shapes, and multi-artifact provisioning remain unclaimed until separately qualified.

AI-assisted development: OpenAI Codex assisted implementation, testing, and review; the human maintainer retains responsibility for the change.
@onlyxItachi
onlyxItachi marked this pull request as ready for review August 2, 2026 19:25
Copilot AI review requested due to automatic review settings August 2, 2026 19:25
@onlyxItachi
onlyxItachi merged commit 234c70b into main Aug 2, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors Strategy B generated-kernel artifact admission from a single-purpose service into a manifest-driven, immutable registry, enabling safe coexistence with additional physically-qualified generated kernels while preserving the existing BF16[1024] add-only boundary and native capability authority.

Changes:

  • Replaced the Strategy B artifact singleton/service with a closed XdnaGeneratedKernelRegistry keyed by (device-artifact cache digest, receipt identity digest).
  • Updated the Python ↔ native binding contract and runtime state to support a per-entry generated-kernel registry (including a new native state introspection endpoint).
  • Migrated and expanded tests/docs/workflow gating to cover the new registry and renamed native binding entrypoint.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
torch_xdna/inductor.py Switches Strategy B artifact binding from the old service to the generated-kernel registry during codegen/binding.
torch_xdna/compiler.py Threads the generated-kernel registry through compile-contract registration.
torch_xdna/init.py Initializes/adopts the generated-kernel registry during runtime initialization (replacing Strategy B service admission).
torch_xdna/_generated_kernel_registry.py Adds the manifest-driven registry implementation and key/entry types.
torch_xdna/_strategy_b_artifact_service.py Removes the old singleton-style Strategy B artifact service.
torch_xdna/_compiler_artifacts.py Renames/updates the native binder entrypoint to _bind_generated_kernel.
torch_xdna/csrc/XdnaRuntime.h Replaces single generated-ELF state with a keyed generated-kernel registry and new query API.
torch_xdna/csrc/XdnaRuntime.cpp Implements composite-keyed publication/binding and per-entry state tracking for generated kernels.
torch_xdna/csrc/bindings.cpp Renames the pybind binding entrypoint and adds _generated_kernel_registry_state.
tests/test_workflow_contracts.py Updates workflow contract assertions for the new registry module.
tests/test_strategy_b_initialization.py Updates initialization tests to validate registry-based admission.
tests/test_strategy_b_artifact_service.py Removes tests for the deleted Strategy B artifact service.
tests/test_inductor_adapter.py Updates adapter tests to use the registry path and per-family binding.
tests/test_generated_kernel_registry.py Adds focused unit tests for manifest/registry behavior and failure modes.
tests/test_generated_elf_native_contract.py Updates native contract tests for composite-key registry and renamed entrypoint.
tests/test_compiler_artifacts.py Updates binder naming to match the renamed native entrypoint.
pyproject.toml Updates hardware-free Python file list to include the new registry module.
docs/COMPILER_CACHE.md Documents the new registry structure and its invariants/boundary.
docs/alpha/STRATEGY_B_COMPILER_CONTRACT.md Updates the contract documentation to describe keyed binding semantics.
.github/workflows/hardware-free.yml Updates workflow file allowlist for the new registry module.
Suppressed comments (2)

torch_xdna/csrc/XdnaRuntime.cpp:737

  • bind_generated_kernel() still logs/checks the fork-safety operation as "bind an XDNA generated ELF". Since the API and Python entrypoint were renamed to "generated kernel", this message is now inconsistent and makes debugging harder.
GeneratedElfObservation XdnaRuntime::bind_generated_kernel(
    CompilerElfSpec spec,
    std::vector<char> elf_data) {
  check_not_in_bad_fork("bind an XDNA generated ELF");
  validate_generated_elf_spec(spec);

torch_xdna/csrc/XdnaRuntime.cpp:846

  • launch_generated_bfloat16_add() still uses the fork-safety operation string "launch an XDNA generated ELF" even though the binding/publication surface was renamed to "generated kernel". Aligning the message avoids confusion when diagnosing bad-fork failures.
void XdnaRuntime::launch_generated_bfloat16_add(
    XdnaAllocation& lhs,
    XdnaAllocation& rhs,
    XdnaAllocation& output,
    const std::string& expected_device_artifact_cache_key_sha256,
    const std::string& expected_artifact_receipt_identity_sha256) {
  check_not_in_bad_fork("launch an XDNA generated ELF");
  TORCH_CHECK(

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread torch_xdna/inductor.py
Comment on lines +984 to +987
selection = decision.get("selection")
if not isinstance(selection, dict):
raise _unsupported("Strategy B source has no native kernel selection")
entry = registry.require_family(str(selection.get("kernel_family")))
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