[Mlir-commits] [mlir] [mlir] Init the `TransformsInterfaces` for configuring transformations (PR #99566)

Fabian Mora llvmlistbot at llvm.org
Sun Jul 21 13:10:59 PDT 2024


================
@@ -409,3 +415,38 @@ void mlir::populateGpuToNVVMConversionPatterns(LLVMTypeConverter &converter,
                                    "__nv_tanh");
   populateOpPatterns<math::TanOp>(converter, patterns, "__nv_tanf", "__nv_tan");
 }
+
+//===----------------------------------------------------------------------===//
+// NVVMTargetAttr conversion patterns attr interface
+//===----------------------------------------------------------------------===//
+
+namespace {
+struct NVVMTargetPatternsAttrInterface
+    : public ConversionPatternsAttrInterface::ExternalModel<
+          NVVMTargetPatternsAttrInterface, NVVM::NVVMTargetAttr> {
+  /// Configure GPU to NVVM.
+  void populateConversionPatterns(Attribute attr,
+                                  ConversionPatternAttrOptions &options,
+                                  RewritePatternSet &patterns) const;
+};
+} // namespace
+
+void NVVMTargetPatternsAttrInterface::populateConversionPatterns(
----------------
fabianmcg wrote:

> This implementation does not use attr.

That's something that should change in future patches. Right now I tried to keep the patch small.

> What's the benefit of this attr interface over the existing ConvertToLLVMPatternInterface dialect interface, which seems to do almost the same thing

`ConvertToLLVMPatternInterface` is a dialect interface, hence it is possible to use it for things like `arith-to-llvm`, because the lowering is mostly target independent -it shouldn't be but that's a different discussion.

However, that approach doesn't work for the `gpu` dialect because `gpu` goes to either `nvvm` or `rocdl`, instead of `llvm`. Hence, implementing `ConvertToLLVMPatternInterface` for the `gpu` dialect is not possible with a dedicated cost-model to select the right patterns (either `nvvm` or `rocdl`).

This proposal solves the issue by adding an attribute interface allowing for finer configuration of the conversion process. For example, this interface allows converting things like:

```mlir
gpu.module @nvvm [#nvvm.target] {
 // uses NVVM patterns
 ...
}
gpu.module @nvvm [#nvvm.target<chip = "sm_90">] {
 // uses NVVM patterns specific to `sm_90`
 ...
}
gpu.module @rocdl [#rocdl.target] {
 // uses ROCDL patterns
 ...
}
``` 


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


More information about the Mlir-commits mailing list