hip-kernel-optimization

A guide for writing and tuning HIP kernels, which are GPU programs that can run on AMD and NVIDIA hardware. It covers memory access, shared memory, occupancy, vectorization, asynchronous operations, loop unrolling, and profiling.

In plain words
What is it for?
Use it to write or review HIP kernels, port CUDA code to HIP, profile with rocprof, and improve memory access, tiling, block sizing, or loop performance.
Why use it?
It helps diagnose whether a kernel is limited by memory, computation, or the number of active GPU threads, and suggests relevant tuning steps.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/amd-agi/apex/hip-kernel-optimization
Any agent
npx skills add AMD-AGI/Apex --skill hip-kernel-optimization
Clone the repo
git clone --depth 1 https://github.com/AMD-AGI/Apex

Made for: Claude Code, Codex.

Per session 56 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,699 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00056 $0.02699
Opus 5 $0.00028 $0.01350
Sonnet 5 $0.00011 $0.00540
Haiku 4.5 $0.00006 $0.00270

Measured 2d ago against content hash a9c9cfd80b48, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

hip-kernel-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

tools/skills/hip-kernel-optimization/SKILL.md · 256 lines

How it starts

The opening of the file, as written. The whole thing — 256 lines — stays where its author put it; the contents beside it link to each section on GitHub.

HIP Kernel Optimization

Purpose

Provide ready patterns for efficient HIP kernels and guide diagnosis of memory throughput, occupancy, and synchronization bottlenecks.

When to Use

  • Implementing or reviewing HIP kernels for AMD MI/CDNA architectures or CUDA-portable code
  • Porting CUDA code to HIP while retaining performance
  • Preparing profiling runs with rocprof

Optimization Priority

Phase 1: Low-hanging fruit (try first, low risk)

  1. #pragma unroll on hot loops with small, fixed trip counts
  2. Enable -ffast-math compiler flag for floating-point kernels
  3. Use 32B vectorized loads/stores instead of 16B
  4. Add __launch_bounds__(maxThreads, minBlocks) to guarantee occupancy
  5. Add const qualifiers on read-only pointers
  6. Verify memory coalescing (consecutive threads → consecutive addresses)

Phase 2: Targeted improvements (profile first) 7. Profile with rocprof to confirm bottleneck 8. If memory-bound: CK-Tile buffer views with vectorization 9. If compute-bound: Shared memory tiling 10. Dynamically calculate block size based on problem dimensions 11. Replace large 2D shared arrays with atomicAdd for sparse patterns 12. Provide multiple block size configurations to avoid register spill 13. Add explicit rounding mode control for numerical correctness 14. Pre-compute workspace size to avoid dynamic allocation 15. Implement CSV-based tuning cache for repeated GEMM shapes

Phase 3: Complex transformations (high effort) 16. Algorithm changes (e.g., Top-K-only softmax) 17. gfx950: Use 16x16x32 MFMA instead of 2x 16x16x16 18. Kernel fusion (multi-op in single kernel) 19. Persistent kernels for repeatedly executed operations 20. Shape-based heuristic dispatching

Anti-patterns:

  • Optimizing everything at once
  • Manual loop unrolling (use #pragma unroll instead)
  • Over-unrolling (factor > 8)
  • Premature vectorization without alignment check
  • Unnecessary buffer coherence flags (e.g., glc)

Core Optimization Patterns

1. Memory Access

  • Coalescing: Map consecutive threads to consecutive addresses; prefer SoA over AoS
  • Vectorization: Use CK-Tile buffer views for efficient I/O; prefer 32B loads over 16B
  • Boundary handling: Separate fast vectorized path from slow boundary path
    if(idx + VEC_SIZE <= d) {
        vec_o out_vec;
        #pragma unroll
        for(size_t j = 0; j < VEC_SIZE; j++) {
            out_vec[j] = compute(x[j], y[j]);
        }
        buffer_out.template set(idx, 0, true, out_vec);  // Fast path
    } else {
        for(size_t j = 0; j < VEC_SIZE; j++) {          // Boundary path
            if(idx + j < d) ptr_out[idx + j] = compute(...);
        }
    }
    

Read the full file on GitHub · 256 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 256 lines · 56 tokens per session scan A a9c9cfd80b48

Subscribe to this mod's changes

hip-kernel-optimization is a skill published in the GitHub repository AMD-AGI/Apex (76 stars, last pushed 5d ago), licensed MIT. It adds 56 tokens to every session and 2,699 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

optimize-global-memory-access

Guide the agent through diagnosing and restructuring CUDA global memory access patterns to maximize effective memory bandwidth, covering coalescing requirements, vectorized loads, AoS vs SoA layouts, shared memory staging for non-coalesced patterns, and L2 cache behavior.

tensormux/kernel-skills · 0 tokens

platform-port

Guide porting FastLED to new MCU platforms, including int.h types, clockless drivers, SPI implementations, and platform detection. Use when adding support for a new microcontroller family or board.

FastLED/FastLED · 42 tokens

eide

EIDE (Embedded IDE) 工程构建工具,用于扫描 .eide/eide.yml 工程、枚举构建 配置 (ConfigName)、执行 build/rebuild/clean 并解析构建日志,返回可供 jlink/openocd 复用的产物路径。当用户提到 EIDE、Embedded IDE、eide.yml、 unifybuilder、VS Code EIDE 扩展、Cl.eide 时自动触发,也兼容 /eide 显式调用。 即使用户只是说"用 EIDE 编译一下"或"EIDE 烧录到板子上",只要上下文涉及 EIDE 嵌入式工程就应触发此 skill。.

zhinkgit/embeddedskills · 151 tokens

gcc

GCC 嵌入式工程构建工具(CMake + arm-none-eabi-gcc),用于扫描 CMake 型嵌入式工程、 列出预设、配置、编译、重建、清理和分析 ELF 大小。当用户提到 GCC、arm-none-eabi、 CMake 嵌入式编译、Ninja 构建、ELF 大小分析、arm-gcc、交叉编译、cmake --build、 cmake --preset 时自动触发,也兼容 /gcc 显式调用。即使用户只是说"编译一下"或 "看看固件多大",只要上下文涉及 CMake 嵌入式 GCC 工程就应触发此 skill。.

zhinkgit/embeddedskills · 162 tokens

tilelang-ascend-tile-api

TileLang-Ascend 新增 Ascend 专属 T.tile.xxx 小 API 的端到端开发流程。用户要求新增、封装、暴露、实现或测试 ascendtile.py 中的 T.tile API / Ascend tile primitive 时必须使用本 skill,尤其适用于需要同时打通 Python 前端、C++ lowering/codegen、Ascend C helper、文档和 CI 测试的任务。.

tile-ai/tilelang-ascend · 96 tokens

cpu-optimization-arm

ARM CPU 架构性能优化技巧、NEON SIMD 向量化、数值稳定性和调试策略.

mindspore-ai/akg · 30 tokens