본문으로 건너뛰기
cccskills
무료GitHub에 공개

gpu-kernel-baseline

Learn the target framework from enabled knowledge tools and implement a baseline GPU kernel. Use this skill to understand compute semantics, determine the target platform and framework, search reference implementations, and produce a correct V0 baseline with performance records for later profile-driven optimization.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md8.3 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

GPU Kernel Baseline

When to Use

Use this skill when the user provides PyTorch logic or a kernel demo and asks to:

  • Write a GPU kernel for the target platform.
  • Build a baseline from scratch.
  • Prepare kernel.py, reference.py, test_kernel.py, and baseline_report.md for later profile-driven optimization.

Workflow

This stage first understands the PyTorch semantics, then learns the framework APIs (CuteDSL or FlyDSL) through enabled knowledge tools, implements kernel.py and test_kernel.py, validates correctness, records performance, writes baseline_report.md, and writes memory/v0.json.

The orchestrator installs discovered plugin instructions at .atrex_plugins/instructions.md.

Phase 1: Understand PyTorch Semantics

  1. Read the user-provided PyTorch logic and kernel_demo.
  2. Extract and record:
    • Compute pattern, such as GEMM, Decode Attention, Reduction, or Elementwise.
    • Input/output shape, stride, dtype, layout, and device.
    • Data dependencies, broadcasting, masks, boundary handling, and write-back semantics.
    • Accuracy requirements, tolerance, accumulation dtype, and special-value handling.
  3. Determine target platform and framework:
    • H100/H20/H200 -> Hopper -> CuteDSL
    • MI300X/MI308X -> CDNA3 -> FlyDSL
    • MI355X -> CDNA4 -> FlyDSL
  4. If the PyTorch logic is ambiguous, first create a minimal runnable reference, then continue.

Phase 2: Learn Framework APIs from enabled knowledge tools

  1. Read .atrex_plugins/instructions.md and inspect python3 tools/plugin.py list for enabled tool names and input schemas. Follow the session's phase-specific plugin instructions.
  2. Query available knowledge tools with the exact product, authoritative runtime architecture, framework, operator, shapes, dtypes and missing implementation facts. If no suitable plugin is enabled, use available reference sources and record missing facts explicitly.
  3. Preserve returned source and attribution identifiers exactly. Respect hardware scope and context budgets. Never substitute another hardware identity or treat a fallback sample as a match.
  4. Prefer sources with the same framework and compute pattern. Record references and the constraints they establish in plans/v0_plan.md.

Phase 3: Implement Baseline Kernel and Correctness Tests

  1. Implement a correct baseline kernel.py based on PyTorch semantics and the learned framework APIs.Not only must the functionality be correct, but the framework implementation must also be correct, using either CuteDSL or FlyDSL.
  2. Write test_kernel.py using PyTorch logic directly as the correctness reference.
  3. Cover representative inputs, including normal shapes, boundary shapes, and relevant dtype or stride cases.
  4. Example correctness check:
ref = pytorch_reference(inputs)
out = kernel_v1(inputs)
rel_err = (out.float() - ref).norm() / ref.norm()
assert rel_err < 0.01
  1. The default BF16 threshold is rel_err < 0.01; lower precision formats may use task-specific relaxed thresholds.
  2. Add per-case timeout guard in test_kernel.py to prevent hanging:
import signal

def timeout_handler(signum, frame):
    raise TimeoutError("Test case exceeded timeout limit")

signal.signal(signal.SIGALRM, timeout_handler)

TIMEOUT_SEC = int(os.environ.get("TEST_TIMEOUT_SEC", "30"))

for case in test_cases:
    signal.alarm(TIMEOUT_SEC)
    try:
        run_test(case)
    except TimeoutError:
        record_failure(case, "TIMEOUT_FAIL")
    finally:
        signal.alarm(0)
  1. If API, compilation, accuracy, performance, or hardware issues appear, query enabled knowledge tools again with the exact failure and measured evidence, and then fix the implementation.
  2. Record the baseline configuration, including tile size, thread organization, grid/block design, and major data-movement patterns.

Phase 4: Performance, Correctness, and Quality Gate

  1. Run exactly one full-workload base-seed V0 measurement through the mandatory sandbox. Do not pass --multi-seed and do not launch a separate robustness run for V0:
python tools/sandbox.py --kind run --no-sync -- \
  python test_kernel.py --version v0 --no-memory

Parse the emitted [test_kernel] RESULT_JSON=..., use its performance result and accompanying correctness status for memory/v0.json, and avoid repeating the expensive baseline workload.

  • Each individual test case must complete within 30 seconds (configurable via TEST_TIMEOUT_SEC env var).
  • If a case exceeds the timeout, mark it as TIMEOUT_FAIL, kill the process, and record the failure in baseline_report.md.
  • Common timeout causes: infinite loops in index calculation, deadlocks in synchronization, or excessive compilation time. Consult enabled knowledge tools with the failure mode to diagnose.
  1. Verify all correctness cases pass and record max rel_err plus PASS/FAIL.
  2. Measure baseline performance and record:
latency(us) | TFLOPS | bandwidth(GB/s) | TFLOPS peak utilization(%) | bandwidth peak utilization(%)
  1. Use compute_utilization.py to calculate TFLOPS and bandwidth utilization:
python tools/compute_utilization.py   --gpu <gpu> --dtype <dtype>   --flops-expr '<expr>' --bytes-expr '<expr>'   --time-ms <ms> --grid-blocks <blocks>
  1. Every theoretical peak, bandwidth, and utilization calculation must cite the auditable spec sources registered in Step 0.

  2. Write baseline_report.md with:

    • Baseline kernel path
    • Correctness test path
    • PyTorch reference logic description
    • Stable source record ids consulted
    • Baseline configuration summary
    • Correctness results: case list, max rel_err, PASS/FAIL (include any TIMEOUT_FAIL cases)
    • Baseline performance: latency(us), TFLOPS, bandwidth(GB/s), and peak utilization percentages
  3. Write baseline iteration data to memory/v0.json using tools/memory_manager.py:

    # Create the iteration file
    python tools/memory_manager.py create --workspace kernel_opt_<name> --version v0
    
    # Fill in performance and metadata
    python tools/memory_manager.py update --workspace kernel_opt_<name> --version v0 \
        --set 'performance.latency_us=<value>' \
        --set 'performance.tflops=<value>' \
        --set 'performance.bandwidth_gbps=<value>' \
        --set 'performance.tflops_peak_utilization_pct=<value>' \
        --set 'performance.bandwidth_peak_utilization_pct=<value>' \
        --set 'optimization.action_category=baseline' \
        --set 'optimization.action_description=<summary>' \
        --set 'correctness.rel_err=<value>' \
        --set 'correctness.status=PASS' \
        --set 'quality_gate.result=PASS'
    

    For array fields (pitfalls_and_fixes, references), update the JSON file directly or use read + manual edit + write-back. Fill in:

    • pitfalls_and_fixes: any errors encountered during implementation
    • references: stable source record ids and other docs referenced during learning
  4. After the quality gate passes, commit:

git add kernel.py test_kernel.py baseline_report.md memory/v0.json README.md
git commit -m "V0: baseline kernel"

memory/ Requirements

Each iteration produces a memory/v<N>.json file following the schema defined in reference/v_iteration.schema.json. The JSON structure captures performance data, optimization actions, profile evidence, correctness results, ISA metric progress, search logs, pitfalls and fixes, and references.

Key rules:

  • The masked field defaults to false. When set to true, the file is skipped during reads.
  • ISA optimization target thresholds are stored in README.md and must be derived from documented best practices, hardware specs, and Step 0 Roofline conclusions. Do not fabricate thresholds from experience.

Deliverables

  • Runnable and correct(using either CuteDSL or FlyDSL) kernel.py
  • PyTorch reference.py
  • test_kernel.py
  • baseline_report.md
  • Created memory/v0.json
  • Git commit

Appendix: Prohibited Actions

  • Do not use unspecified programming frameworks or import external projects.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Let AKA autonomously add, run, inspect, and revise intra-kernel timeline probes for standalone CUDA/inline PTX or CuTe DSL when ordinary benchmark, NSYS, or NCU evidence cannot answer a specific kernel-internal timing question.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/atrex-kernel-agent1822026년 10월 15일 업데이트

gen-plan

무료

Generate a structured implementation plan from an evidence draft. Validate paths, obtain configured independent Codex and Qoder reviews, synthesize available advice against repository evidence, preserve the draft, and produce testable acceptance criteria and validation steps.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/atrex-kernel-agent1822026년 10월 15일 업데이트

Run the evidence loop of one long-horizon GPU kernel optimization episode. Use this skill to reconstruct the incumbent, profile and localize a bottleneck, research progressively, plan one coherent direction, implement and repair, validate development correctness and performance, and record every decisive experiment in the episode journal.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/atrex-kernel-agent1822026년 10월 15일 업데이트

Mine a per-kernel optimization trace — a git repository capturing successive versions of one kernel being optimized — into structured, gate-validated optimization-experience records for the GPU kernel wiki. Use when asked to distill an optimization run, a kernel_opt trace directory or a version ladder into wiki records; to report what such a run actually achieved; to build, extend, re-run or validate the staging store behind those records; or to explain how a trace-derived record's number, snippet or provenance was established.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/atrex-kernel-agent1822026년 10월 15일 업데이트

Choose and run ACU-only, adaptive PPU in-kernel timeline, or optional bounded joint analysis for a PPU kernel. Use for device-level bottleneck diagnosis, kernel-internal critical-path questions, or evidence that genuinely needs both; do not require all three modes.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/atrex-kernel-agent1822026년 10월 15일 업데이트

Quickly extract a typed GPU-Wiki query intent from prose. Never inspect or query a knowledge store.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

alibaba/atrex-kernel-agent1822026년 10월 15일 업데이트

alibaba의 스킬 모두 보기

이 스킬의 문제 신고