[all-commits] [llvm/llvm-project] b43068: [mlir][gpu] Update GPU translation to accept binar...

Fabian Mora via All-commits all-commits at lists.llvm.org
Fri Aug 11 17:29:59 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b43068e8707dea0ad601377b3133b4abe89d370a
      https://github.com/llvm/llvm-project/commit/b43068e8707dea0ad601377b3133b4abe89d370a
  Author: Fabian Mora <fmora.dev at gmail.com>
  Date:   2023-08-12 (Sat, 12 Aug 2023)

  Changed paths:
    M mlir/lib/Target/LLVMIR/CMakeLists.txt
    M mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
    M mlir/lib/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.cpp
    A mlir/test/Target/LLVMIR/gpu.mlir

  Log Message:
  -----------
  [mlir][gpu] Update GPU translation to accept binaries.

== Commit message ==
Modifies GPU translation to accept GPU binaries embedding them using the
object manager interface method `embedBinary`, as well as accepting kernel
launch operations translating them using the interface method `launchKernel`.

Depends on D154152

= Explanation =
**Summary:**
These patches aim to be a replacement to the current GPU compilation infrastructure, with extensibility and trying to minimizing future disruption as the primary goal.
The biggest updates performed by these patches are:
 - The introduction of Target attributes, these attributes handle compilation of GPU modules into binary strings. These attributes can be implemented by any dialect, leaving the option for downstream users to implement their own serializations.
 - The introduction of the GPU binary operation, this operation stores GPU objects for different targets and can be invoked by `gpu.launch_func`.
 - Making `gpu.binary` & `gpu.launch_func` translatable to LLVM IR, with the translation being controlled by Object Manager attributes.
 - The introduction of the `gpu-module-to-binary` pass. This pass serializes GPU modules into GPU binaries, using the GPU targets available in the module.
 - The introduction of the `#gpu.select_object` object manager as the default object manager, it selects a single object for embedding in the IR, by default it selects the first object.

These patches leave the current infrastructure in place, allowing for a migration period for downstream users.

**Examples:**
- GPU modules using target attributes:
```
gpu.module @my_module [#gpu.nvptx<chip = "sm_90">, #gpu.amdgpu, #gpu.amdgpu<chip = "gfx90a">] {
...
}
```
- Applying the `gpu-module-to-binary` pass:
```
gpu.module @my_module [#gpu.nvptx<chip = "sm_90">, #gpu.amdgpu] {
...
}
; mlir-opt --gpu-module-to-binary
gpu.binary @my_module [#gpu.object<#gpu.nvptx<chip = "sm_90">, "BINARY DATA">, #gpu.object<#gpu.amdgpu, "BINARY DATA">]
```
- Choosing the `#gpu.amdgpu` object for embedding:
```
gpu.binary @my_module <#gpu.select_object<#gpu.amdgpu>> [#gpu.object<#gpu.nvptx<chip = "sm_90">, "BINARY DATA">, #gpu.object<#gpu.amdgpu, "BINARY DATA">]
; It's also valid to pass the index of the object.
gpu.binary @my_module <#gpu.select_object<1>> [#gpu.object<#gpu.nvptx<chip = "sm_90">, "BINARY DATA">, #gpu.object<#gpu.amdgpu, "BINARY DATA">]
```

**Testing:**
This infrastructure was tested in 2 systems, one with a NVIDIA V100 and the other one with a AMD MI250X, in both cases the test completion was successful.

Input files:
 - **test.cpp**  {F28084155}
 - **test_nvvm.mlir** {F28084157}
 - **test_rocdl.mlir** {F28084162}

1.  Steps for assembling the test for the NVIDIA system:
```
mlir-opt --gpu-to-llvm --gpu-module-to-binary test_nvvm.mlir | mlir-translate --mlir-to-llvmir -o test_nvptx.ll
clang++ test_nvptx.ll test.cpp -l
```
**Output file:** test_nvptx.ll {F28084210}

2.  Steps for assembling the test for the AMD system:
```
mlir-opt --gpu-to-llvm --gpu-module-to-binary test_rocdl.mlir | mlir-translate --mlir-to-llvmir -o test_amdgpu.ll
clang++ test_amdgpu.ll test.cpp -l
```
**Output file:** test_amdgpu.ll {F28084217}

== Diff list ==
The following patches implement the proposal described in: https://discourse.llvm.org/t/rfc-extending-mlir-gpu-device-codegen-pipeline/70199/54 :
 - D154098: Add a `GlobalSymbol` trait.
 - D154097: Add a parameter for passing default values to `StringRefParameter`
 - D154100: Adds an utility class for serializing operations to binary strings.
 - D154104: Add GPU target attribute interface.
 - D154113: Add target attribute to GPU modules.
 - D154117: Adds the NVPTX target attribute.
 - D154129: Adds the AMDGPU target attribute.
 - D154108: Add the GPU object manager attribute interface.
 - D154132: Add `gpu.binary` op and `#gpu.object` attribute.
 - D154137: Modifies `gpu.launch_func` to allow lowering it after gpu-to-llvm.
 - D154147: Add the Select Object compilation attribute.
 - D154149: Add the `gpu-module-to-binary` pass.
 - D154152: Add GPU target support to `gpu-to-llvm`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D154153




More information about the All-commits mailing list