[rocm-libraries] ROCm/rocm-libraries#5135 (commit 5ccc138)
Proof of concept for removing forward declarations (#5135) ## Motivation Currently, we forward declare CK device operation templates in CK-Builder's reflection code: https://github.com/ROCm/composable_kernel/blob/9b168082b7aa19bcf50fd9991baf10a0c77d105b/experimental/builder/include/ck_tile/builder/reflect/instance_traits_device_grouped_conv_bwd_weight_xdl_cshuffle.hpp#L13-L57 This is mainly required to break a circular dependency in reflection. The architecture of that is as follows: MyDeviceOp implements GetInstanceString(). This is typically defined directly in the class definition (no forward declaration). GetInstanceString() calls instance_string<MyDeviceOp>() instance_string<MyDeviceOp>() calls InstanceTraits<MyDeviceOp>::instance_string() InstanceTraits has a specialization for MyDeviceOp which implements instance_string() So order for GetInstanceString() to work properly, InstanceTraits must already be defined. And for InstanceTraits to be defined, the device op needs to be defined. In order to do that, we are currently using aforementioned forward declaration. ## Technical Details C++'s lazy template evaluation is used by calling into an as-of-yet undefined function static member function of `InstanceTraits<MyDeviceOp>` in `GetInstanceString()`, and then specializing `InstanceTraits` only _after that_. The caveat here is that both the device op itself as well as the instance traits specialization must be in scope, otherwise there would be an undefined function error. In practise, we can solve that either by placing the instance traits directly into the file that defines `MyDeviceOp`, or possibly by using a `.inc` file to keep the concerns separated. ## Test Plan The results were verified by running the existing regression tests for CK Builder ## Submission Checklist - [ ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests. --------- Co-authored-by: Márton Bidlek <marton.bidlek@streamhpc.com>
M
Márton Bidlek committed
dfa680345feef34ed4031acf9d25da9e99dabe61
Parent: 87ba196
Committed by GitHub <noreply@github.com>
on 3/9/2026, 4:34:18 PM