Ref model

From babyworm/rtl-agent-team · View interactive version

Ref model is an AI agent skill from the GitHub repository babyworm/rtl-agent-team. Builds Phase 2 golden C reference model with bitexact conformance and bandwidth estimation. Use for 'build reference model', 'C ref model', 'golden model'.

How to use this skill

Skill file

<Purpose>

Build a golden C functional reference model (Phase 2) that validates algorithm correctness and estimates external memory bandwidth. Outputs: refc/*.c, refc/include/*.h, conformance_report.json, bandwidth_report.json, and reviews/phase-2-architecture/ref-model-feature-coverage.md.

</Purpose>

<Use_When>

</Use_When>

<Do_Not_Use_When>

</Do_Not_Use_When>

<Why_This_Exists>

Writing the reference model before RTL forces algorithm understanding and exposes spec ambiguities before silicon commitment. Bitexact match against JM/HM is the industry-standard acceptance criterion. The model doubles as a bandwidth analysis tool by routing all external memory traffic through ext_mem_read/ext_mem_write, enabling memory-bandwidth estimation without RTL.

</Why_This_Exists>

Prerequisites

If missing: WARNING — proceed with available artifacts; feature coverage step will note absent requirements file.

<Assets>

| Path | Role |

|------|------|

| templates/Makefile | Build + test + bandwidth targets (build, test, bandwidth, sanitize). |

| templates/ref_model_main.c | Scaffold with ext_mem_read/write stubs and PARALLEL_LANES define. |

| templates/ref_model_header.h | Struct typedefs: input_t, output_t, context_t, ext_mem_stats_t. |

| templates/dpi_wrapper.h | DPI-C export declarations for SV testbench linkage. |

| scripts/run_ref_model.py | Build-and-run wrapper: locates refc/, builds via Makefile (direct cc -std=c11 fallback), runs the model with --input/--output/--args pass-through, writes a JSON run report. |

| references/ref-model-conventions.md | C11/DPI-C rules, output schemas, anti-patterns. |

| examples/sat_add/ | Worked example: self-testing saturating-adder ref model + committed expected_run_report.json (regeneration-checked in CI). |

</Assets>

<Responsibility_Boundary>

</Responsibility_Boundary>

<Execution>

  1. Spawn domain expert for algorithm pseudocode and edge-case table (see Tool_Usage).
  2. Spawn ref-model-dev to implement refc/*.c — pure C11, no clock/reset, I/O as function args, internal state as arrays/struct members, external memory via ext_mem_read/write, PARALLEL_LANES parameterizable, no C++ features.
  3. Build: cd refc && make build (must compile with -Wall -Wextra -Werror).
  4. Test: cd refc && make test — bitexact comparison against JM/HM; fix mismatches and iterate.

For a single build+run cycle with a machine-readable result, use

python3 {plugin_root}/skills/ref-model/scripts/run_ref_model.py --refc-dir refc --report refc_run_report.json

({plugin_root} resolved from .rat/state/spawn-context.json) — exit 0 = model ran clean, 1 = build/run failure (report written), 2 = environment error.

  1. Bandwidth: cd refc && make bandwidth — captures ext_mem_stats_t; write bandwidth_report.json.
  2. Feature coverage: read iron-requirements.json, map every REQ-F-* to a real code path (structural check — not just bitexact coverage); save reviews/phase-2-architecture/ref-model-feature-coverage.md. Escalate any unmapped feature to the user before proceeding.
  3. Spawn ref-model-reviewer for algorithm fidelity, numeric precision, and UB/memory-safety review.
  4. Write conformance_report.json with JM/HM version and per-vector pass/fail.
  5. Sanitize: cd refc && make sanitize (-fsanitize=address,undefined) — must pass clean.

Apply steps 1-9 to every algorithm unit requested — do not stop after the first.

</Execution>

<Tool_Usage>

Task(subagent_type="rtl-agent-team:vcodec-syntax-entropy-expert",
     prompt="Provide algorithm pseudocode and edge case table for CABAC entropy coding per H.264 spec §9.3.")

Task(subagent_type="rtl-agent-team:ref-model-dev",
     prompt="Implement C functional reference model at refc/. Must be bitexact vs JM. "
            "No clock/reset — pure functional. I/O as function args. Internal memory as arrays/struct. "
            "External memory via ext_mem_read/write. PARALLEL_LANES parameterizable. "
            "C11, DPI-C compatible (no C++ features). Use templates/ scaffolding.")

Task(subagent_type="rtl-agent-team:ref-model-reviewer",
     prompt="Review refc/ model quality. Check algorithm fidelity, fixed-point/bit-width correctness, "
            "build warnings, UB risks, and I/O format compatibility. "
            "Save report to reviews/phase-2-architecture/ref-model-review.md with PASS/FAIL verdict.")

</Tool_Usage>

<Examples>

<example index="1">

<scenario>New CABAC entropy coder; Phase 1 complete; JM 19.0 available.</scenario>

<expected_output>refc/cabac_encoder.c compiled clean; 500 ITU-T vectors pass bitexact vs JM 19.0; bandwidth_report.json shows 2.3 MB/frame reads; all REQ-F-* mapped; ref-model-reviewer issues PASS.</expected_output>

</example>

<example index="2">

<scenario>Spec change adds intra 8×8 prediction; existing ref model misses REQ-F-042.</scenario>

<expected_output>ref-model-dev adds intra_predict_8x8(); feature-coverage.md updated; re-run confirms bitexact match; conformance_report.json refreshed.</expected_output>

</example>

<example index="3">

<scenario>Datapath width exploration: choose between PARALLEL_LANES=4 and PARALLEL_LANES=8.</scenario>

<expected_output>bandwidth_report.json generated for both configs; estimated_read_cycles compared; architect selects PARALLEL_LANES=4 based on memory bandwidth budget.</expected_output>

</example>

</Examples>

<Escalation_And_Stop_Conditions>

</Escalation_And_Stop_Conditions>

Output

<Final_Checklist>

</Final_Checklist>

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.