Prompt file imported from Han-Zhenzhong/ProtoGPU (
.github/prompts/plan-phase4FragmentAssetsAndBuildTimeMerge.prompt.md). Copyright stays with the author.
Plan: Phase 4 Fragment Assets And Build-Time Merge
Replace monolithic mapping-asset editing with fragment-first authoring plus deterministic build-time merge and validation, while keeping runtime interfaces stable and preserving rollback safety.
Steps
- Phase A: Baseline and guardrails.
- Capture baseline artifacts using scripts/run_unit_tests.sh, scripts/run_integration_tests.sh, and scripts/compare_dispatch_modes.sh.
- Record baseline checksums and snapshots for assets/ptx2ir/ptx64_ir_maps.json and assets/ir2uop/ir_uop_maps.json.
- Phase B: Fragment layout and conventions (depends on 1-3).
- Introduce authoring directories assets/ptx2ir/fragments and assets/ir2uop/fragments with family/instruction naming conventions.
- Add authoring docs/examples in assets/ptx2ir/README.md and assets/ir2uop/README.md.
- Phase C: Merge tool skeleton (depends on 5-6).
- Implement merge utility under tools/generators/README.md scope with validate/merge/report modes.
- Add deterministic ordering and canonical serialization in merge output.
- Add merge-tool tests for command behavior and deterministic re-run equivalence.
- Phase D: Schema and semantic validation hardening (depends on 8-10).
- Validate fragments against schemas/ptx_isa.schema.json and schemas/inst_desc.schema.json.
- Add cross-fragment checks: duplicate signature conflicts, dangling IR ops, unresolved uop ops, and ambiguous mappings.
- Emit actionable diagnostics with source fragment path and key tuple context.
- Phase E: Build integration (depends on 12-14).
- Add CMake merge target and generated outputs in CMakeLists.txt.
- Generate canonical outputs assets/ptx2ir/ptx64_ir_maps.generated.json and assets/ir2uop/ir_uop_maps.generated.json.
- Ensure merge failures fail build and test pipelines.
- Phase F: Runtime/test default cutover (depends on 16-18).
- Point default runtime/test asset references to generated outputs via src/apps/cli/main.cpp, scripts/run_integration_tests.sh, and tests/tiny_gpt2_minimal_coverage_tests.cpp.
- Keep compatibility mode for legacy monolith inputs during transition.
- Phase G: Wrapper and CI alignment (depends on 20-21).
- Ensure wrappers trigger merge path directly or through CMake dependency.
- Add merge determinism/validation checks into CI gate.
- Run full phase gate suites and sign off only when generated-asset path is green.
Relevant files
- docs/doc_design/instruction_extensibility/phase4_fragment_and_merge.md — Phase 4 design reference.
- docs/doc_design/instruction_extensibility/phase4_development.md — Phase 4 development playbook.
- assets/ptx2ir/ptx64_ir_maps.json — current PTX->IR monolith.
- assets/ir2uop/ir_uop_maps.json — current IR->uop monolith.
- schemas/ptx_isa.schema.json — PTX ISA schema.
- schemas/inst_desc.schema.json — instruction descriptor schema.
- CMakeLists.txt — merge target wiring and generated-output dependencies.
- src/apps/cli/main.cpp — default asset path inputs.
- scripts/run_unit_tests.sh — unit wrapper alignment.
- scripts/run_integration_tests.sh — integration wrapper alignment.
- tests/tiny_gpt2_minimal_coverage_tests.cpp — generated-asset regression checks.
Verification
- Run merge-tool tests for malformed input, conflict detection, and deterministic output snapshots.
- Run core suites:
gpu-sim-inst-desc-tests,gpu-sim-simt-tests,gpu-sim-memory-tests,gpu-sim-observability-contract-tests,gpu-sim-public-api-tests,gpu-sim-tiny-gpt2-mincov-tests. - Run wrappers scripts/run_unit_tests.sh and scripts/run_integration_tests.sh.
- Run mode equivalence via scripts/compare_dispatch_modes.sh with smoke workload/config.
- Verify generated outputs are byte-identical across repeated merge runs with unchanged fragments.
Decisions
- Included: fragment layout, merge tool, schema+semantic validation, build integration, generated-asset default cutover, CI/wrapper hardening.
- Excluded: runtime dynamic fragment loading, external API changes, one-shot deletion of legacy monolith files.
- Rollout: generated assets become default after gate pass; legacy path remains as compatibility fallback during transition.