| name | paracodex-supervisor |
| description | ParaCodex prompt for supervisor step. |
Goal: Your sole purpose is to ensure the candidate code at {kernel_dir} (file(s): {file_list_str}) is algorithmically (e.g. can be different algorithms, but must have identical result) identical to the golden reference at {golden_file_str}. You will achieve this by instrumenting both with gate.h macros and fixing any discrepancies in the candidate code.
MANDATORY: You must not fallback to CPU implementation. The code must run on the GPU. If correctness cannot be achieved explain why in details.
You must {instructions_context}
Context:
- You are activated after an optimization step has modified the file(s): {file_list_str} in
{kernel_dir}.
{backup_msg}
- gate macros are located in
{abs_gate_sdk}/gate.h.
Your Task (Step-by-Step Workflow)
- Instrument Golden Reference (if needed):
- Ensure
{golden_file_str} includes #include "gate.h".
- Gate Macros should only be included in code files and not header files.
- After the main computation, add
GATE_CHECKSUM_* or GATE_STATS_* macros to the golden file to capture only the designated final result buffers from the correctness contract. This is your "source of truth". You should only need to do this once.
- Instrument Candidate Code:
- Ensure the candidate file(s) in
{kernel_dir} include #include "gate.h":
{file_listing}
- Add the exact same GATE macros as the golden reference, observing the same variables. The metric names, data types, and sample counts (
n for stats) must match perfectly.
- Preserve the optimized structure of the candidate. Do not reintroduce per-element or per-row host work when one compact checksum over the same logical buffer is sufficient.
- When the candidate uses contiguous storage behind pointer-to-pointer views, checksum the contiguous logical buffer directly rather than emitting one checksum call per row.
- Do not instrument intermediate state unless it is explicitly part of the final correctness contract. Final-output verification only.
- Wrap verification-only instrumentation in a compile-time guard so ordinary runs do not pay the overhead.
- Ensure the guard is enabled for
make -f Makefile.nvc check-correctness and disabled for normal builds/runs.
- Align Makefile:
- Ensure the path to the golden reference is correct in the Makefile (
{golden_file_str}).
- Build and Run Check:
- From the
{kernel_dir} directory, run the following commands in order:
{clean_cmd}
make -f Makefile.nvc check-correctness > supervisor_output.txt 2>&1
- The output of the check-correctness command will be saved to
supervisor_output.txt in {kernel_dir}/ for inspection.
- Debug and Fix (Iterate if Needed):
- If the check passes: Write
correctness_verification.md in {kernel_dir} (see template below), then stop.
- If compilation fails (build error, not a GATE check failure):
a. Read
supervisor_output.txt to identify the compiler error.
b. If the error is a missing header/include path or missing source file, fix the Makefile (Makefile.nvc) minimally to resolve it.
c. If the error is in the source code (e.g., syntax from GATE macros), fix the source.
d. Loop back to Step 3.
- If the check fails (GATE mismatch):
a. Read
supervisor_output.txt to analyze the failure output from the GATE check.
b. Make the absolute minimum change to the relevant file(s) to fix the numerical error.
c. Prefer fixes that preserve kernel shape, offload granularity, and end-to-end runtime.
d. Loop back to Step 3 (Build and Run Check). Do not stop until the check passes.
Debugging Strategy
When a check fails, use this hierarchy of likely causes:
{debugging_strategy}
Strict Rules
- BEFORE any time you you want to compile the code, you must run
{clean_cmd} in {kernel_dir}.
- DO NOT perform any performance optimizations. Your only goal is correctness.
- DO NOT degrade the candidate's end-to-end runtime with pathological instrumentation. Correctness instrumentation must be compact, proportional to the logical outputs, and excluded from ordinary runs with a compile-time guard.
- DO NOT modify Makefiles unless compilation fails or unless a minimal change is required to enable the verification guard only for
check-correctness (e.g., missing include path for gate.h, wrong source file list, missing -I flag, wrong reference code path, or missing -D flag for the guard on the correctness target). If the build fails and the only fix is a Makefile change, you may edit the Makefile minimally to fix the compilation error. Allowed: adding -I paths, fixing source file lists, adding -lgatelib or similar link flags, adding a verification-only -D... define to the correctness target. Forbidden: changing compiler, optimization flags (-O), or target architecture.
- DO NOT change the golden reference file (
{golden_file_str}) except to add gate.h and GATE macros.
- ONLY edit the candidate file(s) in
{kernel_dir}:
{file_listing}
{strict_rules_extra}
Never / Forbidden
- Run commands that read / write to files outside of your current working directory.
- NO GIT COMMANDS
- DO NOT READ/WRITE OUTSIDE THE WORKING DIRECTORY
Output Files:
supervisor_output.txt - Raw output of make -f Makefile.nvc check-correctness
correctness_verification.md - Human-readable summary written when the check passes (see template)
correctness_verification.md template:
# Correctness Verification
**Kernel:** {kernel_dir}
**Candidate files:** {file_list_str}
**Golden reference:** {golden_file_str}
**Status:** PASS
## GATE Checks
| Metric | Golden | Candidate | Match |
|--------|--------|-----------|-------|
| <metric name> | <value> | <value> | ✓ |
## Fixes Applied
<!-- List any changes made to candidate code to achieve correctness, or "None" if it passed immediately -->
- <description of fix, or "None">
## Makefile Changes
<!-- List any Makefile edits required for compilation, or "None" -->
- <description, or "None">
Deliverable:
- The final, corrected source code for the file(s) in
{kernel_dir} that passes make -f Makefile.nvc check-correctness:
{file_listing}
supervisor_output.txt — raw check output
correctness_verification.md — verification summary
Constraints