Skip to content

Refactor generated kernels behind one native manifest - #17

Merged
onlyxItachi merged 5 commits into
mainfrom
refactor/alpha-generated-operation-schema
Aug 9, 2026
Merged

Refactor generated kernels behind one native manifest#17
onlyxItachi merged 5 commits into
mainfrom
refactor/alpha-generated-operation-schema

Conversation

@onlyxItachi

Copy link
Copy Markdown
Owner

Summary

  • centralize the two approved generated-kernel declarations in native C++
  • validate the complete Python projection before cache construction or artifact admission
  • normalize the legacy add and matmul receipts without changing their device-artifact identities
  • use one scheduler-derived generated-wrapper graph identity and manifest-routed launch metadata

Validation

  • 345 focused compiler, manifest, ABI, cache, initialization, and adapter tests passed
  • 864 hardware-free tests passed; 15 physical tests skipped by the default lane
  • strict mypy passed for the 20 CI-designated modules
  • Ruff check and format passed
  • clean non-editable CPython 3.12 wheel built against pinned PyTorch 85ef666ce184b62346977ae19330cda383b49ab3 with GCC 14 and MAX_JOBS=6
  • source-exact physical BF16 add and exact BF16 [128,64] x [64,128] matmul smokes passed from that installed wheel
  • pre/post XRT validation passed on RyzenAI-npu4

Boundary

This does not add an operator, shape, dtype, stream, dynamic-shape, training, or autograd capability. The common normalized schema is an inspection view for the two legacy receipt formats, not a general third-family admission wire. Future generated families still require reviewed codec and physical qualification work.

AI-assisted development

Codex assisted with implementation, testing, and review. The human maintainer remains responsible for understanding and approving the change.

Problem: PrivateUse1 rename and device-module registration occurred outside the restart-only boundary even though earlier native and compiler registration had already mutated process-global state.

Ownership: downstream torch-xdna initialization and tests only; no PyTorch, driver, firmware, or runtime changes.

Boundary: keep the existing registration order, classify post-mutation rename/device-module failures as process-fatal, and require a fresh process rather than claiming rollback.

Test Plan: python -m pytest -q tests/test_strategy_b_initialization.py tests/test_initialization_contracts.py (17 passed); python -m ruff check torch_xdna/__init__.py tests/test_strategy_b_initialization.py; python -m ruff format --check torch_xdna/__init__.py tests/test_strategy_b_initialization.py; git diff --check.

Physical Evidence: not required; registration ordering and injected failures are hardware-free process semantics.

Limitations: irreversible process-global mutations are not rolled back; callers must discard a process after a reported late initialization failure.

AI-assisted development: Codex assisted implementation and validation; the human maintainer remains responsible for review and acceptance.
Problem: the two approved generated add and matmul receipts used parallel final-ABI and operation shapes, obscuring their shared launch contract.

Ownership: downstream torch-xdna legacy receipt normalization and hardware-free contract tests.

Boundary: preserve both approved receipt wire formats and identities, project them into immutable typed operation and final-ABI views, and derive direct-three-BO eligibility. This does not introduce a general receipt wire format or authorize a third kernel family.

Test Plan: python -m pytest -q tests/test_compiler_contracts.py tests/test_generated_contract_schema.py (110 passed); python -m ruff check torch_xdna/_generated_contract_schema.py tests/test_generated_contract_schema.py; python -m ruff format --check torch_xdna/_generated_contract_schema.py tests/test_generated_contract_schema.py; python -m mypy --strict --follow-imports=skip torch_xdna/_generated_contract_schema.py; python -m py_compile torch_xdna/_generated_contract_schema.py tests/test_generated_contract_schema.py; git diff --check.

Physical Evidence: not required; this commit preserves the exact qualified receipt bytes and device-artifact identities and is not yet wired into runtime admission.

Limitations: the two legacy receipt codecs remain the authoritative wire formats; a future family needs a reviewed codec or a separate common-wire migration.

AI-assisted development: Codex assisted design, implementation, and validation; the human maintainer remains responsible for review and acceptance.
Problem:
Generated add and matmul ABI facts were duplicated across native capability, runtime, and Python binding code, with operation-specific field inference.

Ownership:
Downstream torch-xdna native capability, direct-BO runtime, packaging, and contract tests.

Boundary:
Introduce one closed C++ declaration table for the two physically approved generated families. Capability, runtime, and bindings consume the exact family, receipt, artifact profile, operation payload, and named final-ABI bindings. No operator, shape, dtype, stream, or launch surface is added.

Test Plan:
- python -m pytest -q tests/test_generated_kernel_manifest_cpp.py tests/test_native_capability_cpp.py tests/test_generated_elf_native_contract.py
- python -m pytest -q tests/test_bootstrap_script.py::test_source_distribution_build_does_not_require_xrt
- python -m ruff check .
- python -m ruff format --check .
- git diff --check

Results:
The integrated focused contract set passed 345 tests; the source-distribution subset passed 4 tests; Ruff, formatting, and diff checks passed.

Physical Evidence:
Not rerun for this isolated commit. The native source identity changes, so a source-exact targeted add and matmul smoke remains mandatory before the branch can merge.

Limitations:
The table authorizes only exact BF16[1024] add and BF16 [128,64]@[64,128] matmul receipts. It is not a general generated-kernel wire or capability claim.

AI-assisted development:
Codex assisted with implementation and tests. The human maintainer remains responsible for review and approval.
Problem:
Python artifact admission, compiler profiles, source symbols, and native launch bindings maintained separate add-versus-matmul tables and could drift after native state or cache mutation.

Ownership:
Downstream torch-xdna compiler contracts, artifact cache, initialization, and adapter metadata.

Boundary:
Add one closed two-family Python manifest, exact-match its complete native-approved receipt, ABI, operation, and artifact-profile identity before cache construction, and route admission/source metadata through it. Legacy receipt bytes and device-artifact identities remain unchanged. The normalized legacy schema remains inspection-only and is not promoted to a general wire format.

Test Plan:
- python -m pytest -q tests/test_generated_kernel_manifest.py tests/test_compiler_artifacts.py tests/test_generated_kernel_registry.py tests/test_strategy_b_initialization.py tests/test_triton_adapter.py
- python -m pytest -q tests/test_generated_kernel_manifest_cpp.py tests/test_native_capability_cpp.py
- python -m mypy --follow-imports=skip --ignore-missing-imports --strict torch_xdna/_generated_kernel_manifest.py torch_xdna/_compiler_artifacts.py torch_xdna/_generated_kernel_registry.py torch_xdna/_triton_adapter.py
- python -m ruff check .
- python -m ruff format --check .
- git diff --check

Results:
The integrated focused contract set passed 345 tests. Strict typing passed for the complete 20-module CI set; Ruff, formatting, and diff checks passed.

Physical Evidence:
Not rerun for this isolated adapter commit. Source-exact targeted generated-add and matmul smokes remain required for the completed stack because native and wrapper identities change.

Limitations:
Only the exact approved BF16 add and matmul families are represented. A future family still requires a reviewed receipt codec or separately versioned common-wire migration and independent physical qualification.

AI-assisted development:
Codex assisted with implementation and tests. The human maintainer remains responsible for review and approval.
Problem:
Generated BF16 add and matmul wrappers used different graph-identity implementations and repeated operation-to-kernel routing tables, making cache invalidation and later family review inconsistent.

Ownership:
Downstream torch-xdna Inductor scheduling, wrapper generation, compiler-cache identity, tests, and alpha documentation.

Boundary:
Introduce one versioned binary contiguous generated-graph identity, require a real scheduler-stage native capability decision, resolve wrapper and launch metadata through the approved manifest, and preserve the legacy INT32 identity. The identity remains static, synchronous, inference-only, binary, no-alias, no-broadcast, and no-runtime-scalar.

Test Plan:
- python -m pytest -q tests/test_compiler_cache.py tests/test_inductor_adapter.py
- python -m pytest -q tests/test_generated_kernel_manifest.py tests/test_compiler_artifacts.py tests/test_generated_kernel_registry.py tests/test_strategy_b_initialization.py tests/test_triton_adapter.py
- python -m ruff check .
- python -m ruff format --check .
- python -m mypy --follow-imports=skip --ignore-missing-imports --strict torch_xdna/_compiler_cache.py
- git diff --check

Results:
The final focused integration set passed 345 tests, including a real SchedulerNode-to-wrapper identity path. Independent review passed 337 tests and found no fail-open or authority-drift blocker. Ruff, formatting, typing, and diff checks passed.

Physical Evidence:
Not rerun for this isolated wrapper commit. Exact source-built add and matmul physical smokes are required before merge.

Limitations:
This is not a general N-ary graph schema. Unary, reduction, runtime-scalar, dynamic, aliased, non-contiguous, stream, training, and autograd identities remain unsupported.

AI-assisted development:
Codex assisted with implementation and tests. The human maintainer remains responsible for review and approval.
Copilot AI lite review requested due to automatic review settings August 9, 2026 14:14

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@onlyxItachi
onlyxItachi merged commit 8157c95 into main Aug 9, 2026
1 check 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