mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-21 21:39:15 +00:00
[CK] [CK_Tile] Add GroupConv to Kernel Dispatcher (#5168)
## Motivation This PR adds CK Tile group convolution (forward, backward-data, backward-weight) support to the kernel dispatcher, matching and unifying with the existing dispatcher GEMM infrastructure in architecture and usability. The dispatcher provides a unified kernel dispatch system with both C++ and Python frontends, and until now only supported GEMM operations. This PR enables framework integrators to use the same declarative kernel workflow for convolutions as they do for GEMM: declare kernels, build a registry JIT, select kernels within the registry at runtime, and dispatch to GPU. Future PRs will include runtime kernel selection heuristics for autotuning of kernel parameters based on (problem, hardware arch). ## Technical Details Grouped convolution support has been added to the CK Tile Dispatcher with generated_conv_backend.hpp enabling dispatcher.run(in, wei, out, problem) for all 6 conv variants (fwd/bwdd/bwdw x 2D/3D), runtime heuristic kernel selection, and GroupedConvKernelKey with full ConvConfigBase fields. Python side adds parallel JIT via registry.build(max_workers) and heuristic registry.select(). Includes 7 C++ and 6 Python examples covering all directions with CPU reference validation, and shared infrastructure improvements (BaseRegistry CRTP, structured exceptions). As a sanity check, JIT compile times for a single kernel remains the same and for multiple kernels there is better parallelism: Kernels | 1 worker | 8 workers 1 | 7.7 s | 7.7 s 2 | 15.9 s | 8.2 s 4 | 33.4 s | 9.7 s 6 | 52.3 s | 10.2 s ## Test Plan 145 ephemeral unit tests have been added to test basic functionality. All 30 examples/integration tests run end-to-end on gfx950 (MI350): 7 C++ conv, 7 C++ GEMM, 6 Python conv, 10 Python GEMM. CPU reference validation for forward, backward-data, and backward-weight (2D) in both C++ and Python examples pass. ## Test Result 30 examples pass. Peak performance: 132 TFLOPS (Batch-32 forward 56x56), 53 TFLOPS (pointwise 1x1). CPU reference accuracy: max_abs_diff < 0.002 for all directions (fp16 vs fp32 reference). ## Submission Checklist - [x] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests. --------- Co-authored-by: Yaswanth Raparti <113389104+yraparti@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fb22cd0c69
commit
a2b844d335
@@ -359,8 +359,8 @@ class ConvTraitConfig:
|
||||
|
||||
|
||||
@dataclass
|
||||
class ConvKernelConfig:
|
||||
"""Complete convolution kernel configuration"""
|
||||
class GroupedConvKernelConfig:
|
||||
"""Complete grouped convolution kernel configuration"""
|
||||
|
||||
tile: ConvTileConfig = field(default_factory=ConvTileConfig)
|
||||
trait: ConvTraitConfig = field(default_factory=ConvTraitConfig)
|
||||
@@ -419,7 +419,11 @@ class ConvKernelConfig:
|
||||
|
||||
def kernel_name(self) -> str:
|
||||
"""Generate kernel name from config"""
|
||||
variant_map = {"forward": "fwd", "bwd_data": "bwdd", "bwd_weight": "bwdw"}
|
||||
variant_map = {
|
||||
"forward": "fwd",
|
||||
"bwd_data": "bwd_data",
|
||||
"bwd_weight": "bwd_weight",
|
||||
}
|
||||
var_str = variant_map.get(self.variant, self.variant)
|
||||
|
||||
name = f"conv_{var_str}_{self.dtype_input}_{self.ndim}d"
|
||||
@@ -433,11 +437,11 @@ class ConvKernelConfig:
|
||||
|
||||
|
||||
@dataclass
|
||||
class ConvKernelConfigSet:
|
||||
class GroupedConvKernelConfigSet:
|
||||
"""A set of convolution kernel configurations loaded from JSON"""
|
||||
|
||||
name: str = "default"
|
||||
configs: List[ConvKernelConfig] = field(default_factory=list)
|
||||
configs: List[GroupedConvKernelConfig] = field(default_factory=list)
|
||||
|
||||
# Tile parameter ranges
|
||||
tile_m_values: List[int] = field(default_factory=lambda: [128])
|
||||
@@ -481,7 +485,7 @@ class ConvKernelConfigSet:
|
||||
layout: str = "nhwgc"
|
||||
gpu_targets: List[str] = field(default_factory=lambda: ["gfx942"])
|
||||
|
||||
def generate_configs(self) -> Iterator[ConvKernelConfig]:
|
||||
def generate_configs(self) -> Iterator[GroupedConvKernelConfig]:
|
||||
"""Generate all kernel configurations (cartesian product)"""
|
||||
# Tile parameters
|
||||
tile_params = itertools.product(
|
||||
@@ -548,7 +552,7 @@ class ConvKernelConfigSet:
|
||||
double_smem_buffer=trait[6],
|
||||
num_groups_to_merge=trait[7],
|
||||
)
|
||||
yield ConvKernelConfig(
|
||||
yield GroupedConvKernelConfig(
|
||||
tile=tile_cfg,
|
||||
trait=trait_cfg,
|
||||
dtype_input=self.dtype_input,
|
||||
@@ -599,7 +603,9 @@ class ConvKernelConfigSet:
|
||||
return tile_count * trait_count * extra_count * len(self.gpu_targets)
|
||||
|
||||
|
||||
def load_conv_kernel_configs(json_path: str | Path) -> ConvKernelConfigSet:
|
||||
def load_grouped_conv_kernel_configs(
|
||||
json_path: str | Path,
|
||||
) -> GroupedConvKernelConfigSet:
|
||||
"""
|
||||
Load convolution kernel configurations from a JSON file.
|
||||
|
||||
@@ -607,14 +613,14 @@ def load_conv_kernel_configs(json_path: str | Path) -> ConvKernelConfigSet:
|
||||
json_path: Path to JSON configuration file
|
||||
|
||||
Returns:
|
||||
ConvKernelConfigSet with all parameter values loaded
|
||||
GroupedConvKernelConfigSet with all parameter values loaded
|
||||
"""
|
||||
json_path = Path(json_path)
|
||||
|
||||
with open(json_path) as f:
|
||||
data = json.load(f)
|
||||
|
||||
config_set = ConvKernelConfigSet()
|
||||
config_set = GroupedConvKernelConfigSet()
|
||||
|
||||
# Name
|
||||
config_set.name = data.get("kernel_set_name", json_path.stem)
|
||||
@@ -680,15 +686,15 @@ def load_conv_kernel_configs(json_path: str | Path) -> ConvKernelConfigSet:
|
||||
|
||||
|
||||
def generate_cpp_conv_kernel_set_declaration(
|
||||
config_set: ConvKernelConfigSet,
|
||||
config_set: GroupedConvKernelConfigSet,
|
||||
set_name: Optional[str] = None,
|
||||
) -> str:
|
||||
"""
|
||||
Generate C++ DECL_CONV_KERNEL_SET code from a ConvKernelConfigSet.
|
||||
Generate C++ DECL_GROUPED_CONV_KERNEL_SET code from a GroupedConvKernelConfigSet.
|
||||
"""
|
||||
name = set_name or config_set.name
|
||||
|
||||
lines = [f"DECL_CONV_KERNEL_SET({name},"]
|
||||
lines = [f"DECL_GROUPED_CONV_KERNEL_SET({name},"]
|
||||
|
||||
for config in config_set.generate_configs():
|
||||
line = f' .add("{config.dtype_input}", "{config.variant}", {config.ndim}, '
|
||||
|
||||
Reference in New Issue
Block a user