[Mlir-commits] [mlir] [mlir][gpu] Add metadata attributes for storing kernel metadata in GPU objects (PR #95292)

Fabian Mora llvmlistbot at llvm.org
Wed Jun 26 10:44:48 PDT 2024


fabianmcg wrote:

> why store these as attributes on the module rather than keeping kernel function declarations in the region?

This attribute is primarily used inside the `#gpu.object` attribute, for example:
```mlir
#gpu.object<#rocdl.target<chip = "gfx900">, kernels = #gpu.kernel_table<{
    kernel0 = #gpu.kernel<"kernel0", (i32) -> (), metadata = {sgpr_count = 255}>,
    kernel1 = #gpu.kernel<"kernel1", (i32, f32) -> (), arg_attrs = [{llvm.read_only}, {}]>
  }> , bin = "BLOB">
```
As such, it doesn't have regions.

While it would be possible to add regions to the `gpu.binary` op and add function declarations there. `gpu.binary` can hold multiple objects creating conflicts between the metadata of each binary, for example:
```mlir
gpu.binary @myMultiTargetBin [
    #gpu.object<#rocdl.target<chip = "gfx900">, kernels = #gpu.kernel_table<{
      kernel0 = #gpu.kernel<"kernel0", (i32) -> (), metadata = {sgpr_count = 255}>,
    }> , bin = "BLOB0">,
    #gpu.object<#rocdl.target<chip = "gfx90a">, kernels = #gpu.kernel_table<{
      kernel0 = #gpu.kernel<"kernel0", (i32) -> (), metadata = {sgpr_count = 64}>,
    }> , bin = "BLOB1">,
    #gpu.object<#nvvm.target<chip = "sm_90">, kernels = #gpu.kernel_table<{
      kernel0 = #gpu.kernel<"kernel0", (i32) -> (), metadata = {reg_count = 125}>,
    }> , bin = "BLOB2">,
  ]
```
In this example `kernel0` is using 255 scalar registers in the first object, and 64 in the second object, and the third object is an NVIDIA target with completely different nomenclature.

https://github.com/llvm/llvm-project/pull/95292


More information about the Mlir-commits mailing list