Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ad2695d
[CK] [CK_Tile] Add GroupConv to Kernel Dispatcher (#5168)
vidyasagar-amd Apr 9, 2026
5a8b805
[CK] Adding FMHA functionality.
vidyasagar-amd Mar 9, 2026
b8dc9e7
[CK] Adding FMHA functionality.
vidyasagar-amd Mar 9, 2026
a1cf3b5
[CK] Add further support for bwd kernels.
vidyasagar-amd Mar 10, 2026
0d10d23
[CK] Add parity matrix for fmha against current example folder.
vidyasagar-amd Mar 10, 2026
f4cded7
[CK] Resolve issue with hdims mismatch.
vidyasagar-amd Mar 10, 2026
657e50f
[CK] Relax validation rules to match example.
vidyasagar-amd Mar 11, 2026
dce8dfe
[CK] Add a few more examples for fmha features.
vidyasagar-amd Mar 11, 2026
74f0d6b
[CK] Address review comments.
vidyasagar-amd Mar 11, 2026
6dcd644
[CK] Address further review comments.
vidyasagar-amd Mar 11, 2026
3695a5a
[CK] Tile engine fmha support through dispatcher interface.
vidyasagar-amd Mar 12, 2026
1e18c99
[CK] Fixing readmes and further review comments.
vidyasagar-amd Mar 12, 2026
ea07406
[CK] Code cleanup and another round of review comments.
vidyasagar-amd Mar 12, 2026
6450998
[CK] Addressing another round of review comments.
vidyasagar-amd Mar 12, 2026
342636d
[CK] Add support for bwd kernels.
vidyasagar-amd Mar 13, 2026
eb9c43d
[CK] Add testing matrix.
vidyasagar-amd Mar 16, 2026
281d1ed
[CK] Fix missing instances.
vidyasagar-amd Mar 19, 2026
dd0dd44
[CK] Fix issues with kernel runtime errors.
vidyasagar-amd Mar 20, 2026
f850518
[CK] Fix bug in bwd kernels.
vidyasagar-amd Mar 21, 2026
d1c2518
[CK] Fix minor issues with bwd group kernels.
vidyasagar-amd Mar 22, 2026
f99064a
[CK] Fix filtering rules, improve tile engine parallelism.
vidyasagar-amd Mar 24, 2026
ac94ada
[CK] Fix process parallelism for tile engine generation.
vidyasagar-amd Mar 24, 2026
fb7aa8d
[CK] Further improve benchmarking outputs.
vidyasagar-amd Mar 25, 2026
3566a22
[CK] Batch benchmarking for speed.
vidyasagar-amd Mar 25, 2026
1a98a59
[CK] Further benchmarking efficiency improvements.
vidyasagar-amd Mar 25, 2026
32825ed
Merge branch 'develop' into users/vanantha/ck/dispatcher-fmha
vidyasagar-amd Apr 9, 2026
167141c
Merge branch 'develop' into users/vanantha/ck/dispatcher-fmha
vidyasagar-amd May 1, 2026
e32054f
Fix FMHA tile_engine benchmark and dispatcher ctypes
msaffari-amd Apr 29, 2026
4488a89
Add splitkv variant support to tile_engine FMHA benchmark
msaffari-amd Apr 30, 2026
2682d38
Fix bf16 data encoding in FMHA benchmark
msaffari-amd May 4, 2026
4105ee9
fmha_benchmark: add --num-splits sweep for splitkv kernels
msaffari-amd May 4, 2026
56ed522
fmha_benchmark: show separate Q/K dims in problem display
msaffari-amd May 4, 2026
7cf521e
Fix FMHA JIT compile flags to match CK CMake build
msaffari-amd May 6, 2026
cd25c47
Allow block_per_cu=-1 (auto) to use CK pipeline's built-in occupancy …
msaffari-amd May 6, 2026
abb8e6c
Add block_per_cu=-1 (auto-detect) and list sweep to FMHA fwd dispatcher
msaffari-amd May 7, 2026
d5e9447
correct clang format
msaffari-amd May 7, 2026
b036cd3
Address PR review: fix ref_cache per mask, int64 stride cast, input v…
msaffari-amd May 8, 2026
4c54a43
Merge branch 'develop' into users/vanantha/ck/dispatcher-fmha
tenpercent May 13, 2026
59369ad
refactor(fmha): reorganize codegen into fmha/ package, clean up bench…
amd-yashagar May 11, 2026
104e988
copilot review fixes
amd-yashagar May 12, 2026
ce29358
refactor(fmha): rename specs.py to validation.py, extract arch data i…
amd-yashagar May 13, 2026
0576ed9
Merge branch 'develop' into users/vanantha/ck/dispatcher-fmha
vidyasagar-amd May 15, 2026
4823356
Merge branch 'develop' into users/vanantha/ck/dispatcher-fmha
vidyasagar-amd May 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion projects/composablekernel/dispatcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ endif()
add_library(ck_tile_dispatcher
src/registry.cpp
src/dispatcher.cpp
src/fmha_registry.cpp
src/fmha_dispatcher.cpp
)

# Enable PIC for Python bindings
Expand All @@ -34,13 +36,21 @@ target_include_directories(ck_tile_dispatcher
$<INSTALL_INTERFACE:include>
)

# Link against CK Tile headers (header-only)
# CK Tile core headers (ck_tile/core, ck_tile/ops, etc.)
target_include_directories(ck_tile_dispatcher
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<INSTALL_INTERFACE:include>
)

# CK project root -- needed only for FMHA generated wrappers that include
# "example/ck_tile/01_fmha/fmha_fwd.hpp". PRIVATE to avoid exposing the
# entire project tree to downstream consumers.
target_include_directories(ck_tile_dispatcher
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
)

# Link against HIP headers if available
if(hip_FOUND)
target_link_libraries(ck_tile_dispatcher PUBLIC hip::host)
Expand Down
167 changes: 129 additions & 38 deletions projects/composablekernel/dispatcher/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CK Tile Dispatcher

A unified kernel dispatch system for AMD GPUs with C++ and Python frontends.
A unified kernel dispatch system for AMD GPUs with C++ and Python frontends, supporting GEMM and Grouped Convolution operations.

**Validated Platform:** AMD Instinct MI300 series (gfx942)

Expand Down Expand Up @@ -319,8 +319,8 @@ ls examples/libdispatcher_gemm_lib.so
| `CMAKE_PREFIX_PATH` | - | ROCm installation path |
| `CMAKE_CXX_COMPILER` | - | Path to hipcc compiler |

⚠️ **Important:** Always use `-DCMAKE_BUILD_TYPE=Release` for benchmarking. Debug builds are slower.
⚠️ **Important:** Note that the current system provides single GPU target support for architecture-based kernel filtering, please do not use multiple GPU targets at a time (if necessary, please compile into different build directories).
WARNING: **Important:** Always use `-DCMAKE_BUILD_TYPE=Release` for benchmarking. Debug builds are slower.
WARNING: **Important:** Note that the current system provides single GPU target support for architecture-based kernel filtering, please do not use multiple GPU targets at a time (if necessary, please compile into different build directories).

---

Expand All @@ -340,6 +340,15 @@ cd build/examples
./gemm_04_heuristics # Heuristic kernel selection
./gemm_05_json_export # Registry JSON export
./gemm_06_multi_registry # Multiple registries

# Grouped Convolution Examples
./grouped_conv_01_basic # Declaration patterns + GPU execution
./grouped_conv_02_all_dirs # Forward/BwdData/BwdWeight with GPU
./grouped_conv_03_bench_val # Benchmark + CPU reference validation
./grouped_conv_04_registry_json # Heuristic selection + JSON export
./grouped_conv_05_bwd_data # Backward data + CPU validation
./grouped_conv_06_bwd_weight # Backward weight + CPU validation
./grouped_conv_07_benchmark # Multi-tile ResNet benchmark
```

### Python Examples
Expand All @@ -352,8 +361,22 @@ cd /path/to/composable_kernel/dispatcher
# GEMM Examples
python3 examples/gemm/python/01_basic_gemm.py # Basic multi-kernel GEMM
python3 examples/gemm/python/04_validation.py # CPU reference validation
python3 examples/gemm/python/07_stress_test.py # Stress test (48 kernels)
python3 examples/gemm/python/07_stress_test.py # Stress test
python3 examples/gemm/python/08_heuristics.py # Heuristic selection

# Grouped Convolution Examples
python3 examples/grouped_conv/python/01_basic_grouped_conv.py # Config patterns + registry + GPU
python3 examples/grouped_conv/python/02_forward.py # Forward 2D/3D + CPU ref
python3 examples/grouped_conv/python/03_bwd_data.py # Backward data + CPU ref
python3 examples/grouped_conv/python/04_bwd_weight.py # Backward weight + CPU ref
python3 examples/grouped_conv/python/05_benchmark.py # Multi-problem benchmark
python3 examples/grouped_conv/python/06_registry_json.py # Heuristic selection + JSON

# FMHA Examples (JIT-compiled on the fly)
python3 examples/fmha/python/01_basic_fmha.py # Basic forward attention
python3 examples/fmha/python/12_masks_fmha.py # Causal masks
python3 examples/fmha/python/18_backward_fmha.py # Backward pass
python3 examples/fmha/python/16_splitkv_fmha.py # Split-KV for long sequences
```

### Example Output
Expand Down Expand Up @@ -588,7 +611,7 @@ lib = DispatcherLib.load("/absolute/path/to/libdispatcher_gemm_lib.so")
### Data Flow

```
KernelConfig Registry Dispatcher GPU Execution
KernelConfig -> Registry -> Dispatcher -> GPU Execution
```

1. **KernelConfig**: Defines kernel parameters (tile sizes, data types, layouts)
Expand Down Expand Up @@ -640,7 +663,7 @@ This matrix shows all CK Tile operations with per-data-type, per-layout, and per
| GEMM | streamk_gemm<br>example: `40_streamk_gemm/` | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Reduce | multi_reduce2d<br>example: `05_reduce/` | ❌ | | ❌ | | | | | | | | | ❌ | ❌ | ❌ | ❌ |
| Reduce | reduce2d<br>example: `05_reduce/` | ❌ | | ❌ | | | | | | | | | ❌ | ❌ | ❌ | ❌ |
| Attention | fmha<br>example: `01_fmha/` | | | | | ❌ | | | | | | | | | | ❌ |
| Attention | fmha<br>example: `01_fmha/` | | | | | ❌ | | | | | | | | | | ❌ |
| Attention | sparse_attn<br>example: `50_sparse_attn/` | ❌ | | ❌ | | ❌ | | | | | | | ❌ | ❌ | ❌ | ❌ |
| Activation | softmax | ❌ | | ❌ | | | | | | | | | ❌ | ❌ | ❌ | ❌ |
| Activation | topk_softmax<br>example: `09_topk_softmax/` | ❌ | ❌ | ❌ | | | | | | | | | ❌ | ❌ | ❌ | ❌ |
Expand Down Expand Up @@ -784,31 +807,65 @@ make -j$(nproc)

```
dispatcher/
├── README.md # This file
├── CMakeLists.txt # Build configuration
├── include/ck_tile/dispatcher/ # C++ headers
│ ├── dispatcher.hpp # GEMM dispatcher
│ ├── registry.hpp # Kernel registry
│ └── kernel_key.hpp # Kernel configuration
├── src/ # C++ implementation
├── codegen/ # Kernel generation
│ ├── unified_gemm_codegen.py # GEMM kernel generator
│ └── arch_specs.json # GPU specifications
├── bindings/ctypes/ # Python ctypes interface
│ └── gemm_ctypes_lib.cpp # GEMM Python library
├── examples/ # Examples
│ └── gemm/
│ ├── cpp/ # C++ GEMM examples (01-06)
│ └── python/ # Python GEMM examples (01-11)
├── scripts/ # Build scripts
└── tests/ # Unit tests
|---- README.md # This file
|---- CMakeLists.txt # Build configuration
|
|---- include/ck_tile/dispatcher/ # C++ headers
| |---- dispatcher.hpp # Main dispatcher include
| |---- registry.hpp # GEMM kernel registry
| |---- kernel_key.hpp # Kernel configuration
| |---- grouped_conv_config.hpp # Grouped conv configuration
| |---- grouped_conv_problem.hpp # Grouped conv problem (with builder)
| |---- grouped_conv_kernel_decl.hpp # Grouped conv kernel declarations
| |---- grouped_conv_registry.hpp # Grouped conv registry (thread-safe)
| |---- grouped_conv_utils.hpp # Grouped conv utilities
| |---- fmha_types.hpp # FMHA fwd/bwd args and traits structs
| |---- fmha_problem.hpp # FmhaProblem, FmhaProblemBuilder
| |---- fmha_kernel_key.hpp # FmhaKernelKey (Signature + Algorithm)
| |---- fmha_kernel_instance.hpp # FmhaKernelInstance virtual interface
| |---- fmha_kernel_decl.hpp # Declarative FmhaSignature/FmhaAlgorithm
| |---- fmha_registry.hpp # FmhaRegistry (thread-safe)
| +---- fmha_dispatcher.hpp # FmhaDispatcher (plan, select, run)
|
|---- src/ # C++ implementation
|
|---- codegen/ # Kernel generation
| |---- codegen_common.py # Shared: TileConfig, TraitConfigBase, type mappings
| |---- unified_gemm_codegen.py # GEMM kernel generator
| |---- unified_grouped_conv_codegen.py # Grouped conv kernel generator
| |---- unified_fmha_codegen.py # FMHA kernel generator
| |---- fmha_arch_specs.json # FMHA per-arch tile/pipeline specs
| |---- fmha_rules.py # FMHA validation rules
| |---- fmha_profiles.py # FMHA named profiles/receipts
| +---- arch_specs.json # GPU specifications
|
|---- python/ # Python utilities
| |---- dispatcher_common.py # Shared: paths, validation, Colors, phased output
| |---- ctypes_utils.py # GEMM ctypes utilities
| |---- grouped_conv_utils.py # Grouped conv utilities
| +---- fmha_utils.py # FMHA: JIT compile, FmhaRunner, FmhaKernelConfig
|
Comment thread
vidyasagar-amd marked this conversation as resolved.
|---- scripts/ # Build scripts
| |---- compile_gemm_examples.py # GEMM build script
| +---- compile_grouped_conv_examples.py # Grouped conv build script
|
|---- bindings/ctypes/ # Python ctypes interface
| |---- gemm_ctypes_lib.cpp # GEMM Python library
| |---- conv_ctypes_lib.cpp # Grouped conv Python library
| +---- fmha_ctypes_lib.cpp # FMHA Python library
|
|---- examples/ # Examples
| |---- gemm/
| | |---- cpp/ # C++ GEMM examples (01-07)
| | +---- python/ # Python GEMM examples (01-11)
| |---- grouped_conv/
| | |---- cpp/ # C++ Grouped Conv examples (01-07)
| | +---- python/ # Python Grouped Conv examples (01-06)
| +---- fmha/
| |---- cpp/ # C++ FMHA examples (01-35)
| +---- python/ # Python FMHA examples (01-38)
|
+---- tests/ # Unit tests (C++ and Python)
```

---
Expand All @@ -819,18 +876,52 @@ dispatcher/
|-----------|--------|
| GEMM C++ | [examples/gemm/cpp/README.md](examples/gemm/cpp/README.md) |
| GEMM Python | [examples/gemm/python/README.md](examples/gemm/python/README.md) |
| FMHA C++ | examples/fmha/cpp/ (35 examples covering all FMHA variants) |
| FMHA Python | examples/fmha/python/ (38 examples with JIT compilation) |
| Codegen | [codegen/README.md](codegen/README.md) |
| Python Utils | [python/README.md](python/README.md) |
| C++ Headers | [include/ck_tile/dispatcher/README.md](include/ck_tile/dispatcher/README.md) |

---

## Archived Content
## Grouped Convolution Support

Grouped convolution is fully supported alongside GEMM, with shared infrastructure to eliminate duplication.

### Python

```bash
# Generate grouped conv kernels
python3 codegen/unified_grouped_conv_codegen.py \
--output-dir build/generated_kernels \
--datatype fp16 --variant forward --ndim-spatial 2

# Build grouped conv examples
python3 scripts/compile_grouped_conv_examples.py examples/grouped_conv/cpp/01_basic_grouped_conv.cpp
```

### Key Files

| Component | File |
|-----------|------|
| C++ Headers | `include/ck_tile/dispatcher/grouped_conv_*.hpp` |
| Python Codegen | `codegen/unified_grouped_conv_codegen.py` |
| Python Utils | `python/grouped_conv_utils.py` |
| Build Script | `scripts/compile_grouped_conv_examples.py` |
| Shared Codegen | `codegen/codegen_common.py` |
| Shared Utils | `python/dispatcher_common.py` |

### Variants

- **Forward** (`grouped_conv_fwd`) - Standard grouped convolution
- **Backward Data** (`grouped_conv_bwd_data`) - Gradient w.r.t. input
- **Backward Weight** (`grouped_conv_bwd_weight`) - Gradient w.r.t. weights

### Shared Infrastructure

Convolution examples and utilities have been archived to `ck-2/conv_archive/dispatcher/`:
- `examples/conv/cpp/` - 11 C++ convolution examples
- `examples/conv/python/` - 14 Python convolution examples
- `codegen/unified_conv_codegen.py` - Conv kernel generator
- `include/ck_tile/dispatcher/conv_*.hpp` - Conv headers
- `python/conv_utils.py` - Conv Python utilities
GEMM and grouped convolution share common code to avoid duplication:
- `codegen/codegen_common.py` - TileConfig, TraitConfigBase, type mappings, parallel generation, arch-aware expansion
- `python/dispatcher_common.py` - Path helpers, validation, auto-correction, Colors, phased output

---

Expand Down
26 changes: 17 additions & 9 deletions projects/composablekernel/dispatcher/bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ This directory contains language bindings for the CK Tile Dispatcher.

```
bindings/
├── ctypes/ # Python ctypes bindings (C API)
│ ├── gemm_ctypes_lib.cpp # GEMM dispatcher C API
│ ├── conv_ctypes_lib.cpp # Convolution dispatcher C API (fwd + bwd_data)
│ ├── conv_bwdw_ctypes_lib.cpp # Convolution backward weight C API
│ ├── gpu_helper.cpp # CLI helper for Python
│ └── CMakeLists.txt
└── README.md
|---- ctypes/ # Python ctypes bindings (C API)
| |---- gemm_ctypes_lib.cpp # GEMM dispatcher C API
| |---- conv_ctypes_lib.cpp # Grouped conv dispatcher C API (fwd + bwd_data)
| |---- conv_bwdw_ctypes_lib.cpp # Grouped conv backward weight C API (separate library)
| |---- conv_bwdw_ctypes_lib.cpp # Grouped conv backward weight C API
| |---- fmha_ctypes_lib.cpp # FMHA dispatcher C API (fwd + bwd)
| |---- gpu_helper.cpp # CLI helper for Python
| +---- CMakeLists.txt
+---- README.md
Comment thread
vidyasagar-amd marked this conversation as resolved.
```

## ctypes Bindings
Expand Down Expand Up @@ -65,7 +67,7 @@ lib.dispatcher_cleanup()
| `dispatcher_export_registry_json()` | Export registry as JSON |
| `dispatcher_cleanup()` | Release resources |

### Convolution API
### Grouped Convolution API

| Function | Description |
|----------|-------------|
Expand Down Expand Up @@ -105,5 +107,11 @@ Output is JSON for easy parsing:
See the examples that use these bindings:

- **GEMM**: `dispatcher/examples/gemm/python/`
- **Conv**: `dispatcher/examples/conv/python/`

### Grouped Convolution

Grouped convolution C++ headers and Python utilities are in:
- **C++ Headers**: `dispatcher/include/ck_tile/dispatcher/grouped_conv_*.hpp`
- **Python Utils**: `dispatcher/python/grouped_conv_utils.py`
- **Build Script**: `dispatcher/scripts/compile_grouped_conv_examples.py`

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ endif()
# Look for forward kernels
file(GLOB CONV_FWD_KERNEL_HEADERS "${CMAKE_BINARY_DIR}/generated_kernels/conv_fwd_*.hpp")
# Look for backward data kernels
file(GLOB CONV_BWDD_KERNEL_HEADERS "${CMAKE_BINARY_DIR}/generated_kernels/conv_bwdd_*.hpp")
file(GLOB CONV_BWDD_KERNEL_HEADERS "${CMAKE_BINARY_DIR}/generated_kernels/conv_bwd_data_*.hpp")
# Fallback: any conv kernel (for backwards compatibility)
file(GLOB CONV_KERNEL_HEADERS "${CMAKE_BINARY_DIR}/generated_kernels/conv_*.hpp")

Expand Down Expand Up @@ -112,7 +112,7 @@ endif()
# Add backward data kernel if available
if(CONV_BWDD_KERNEL_HEADERS)
list(GET CONV_BWDD_KERNEL_HEADERS 0 CONV_BWDD_KERNEL_HEADER)
message(STATUS "Found Conv BWD_DATA kernel for ctypes lib: ${CONV_BWDD_KERNEL_HEADER}")
message(STATUS "Found Conv BWD_DATA kernel for ctypes lib: ${CONV_BWD_DATA_KERNEL_HEADER}")
target_compile_options(dispatcher_conv_lib PRIVATE -include ${CONV_BWDD_KERNEL_HEADER})
target_compile_definitions(dispatcher_conv_lib PRIVATE CONV_BWD_DATA_AVAILABLE)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct ConvBwdwProblemC
int stride_d, stride_h, stride_w;
int pad_d, pad_h, pad_w;
int dilation_d, dilation_h, dilation_w;
int split_k;
};

// =============================================================================
Expand Down Expand Up @@ -108,8 +109,7 @@ static float run_bwd_weight_impl(const void* input_ptr,
grad_weight_ptr, // wei_ptr = grad_weight (output)
{}, // ds_ptr
grad_output_ptr, // out_ptr = grad_output
1 // k_batch
);
(prob->split_k > 1) ? prob->split_k : 1);

ck_tile::stream_config stream_cfg{static_cast<hipStream_t>(stream), true, 1, 3, 10};

Expand Down
Loading