[Mlir-commits] [mlir] [mlir][acc] Add MappableType API for generating private recipe init (PR #148293)

Razvan Lupusoru llvmlistbot at llvm.org
Fri Jul 11 13:55:39 PDT 2025


https://github.com/razvanlupusoru updated https://github.com/llvm/llvm-project/pull/148293

>From 6c928550fcc0389a14b01485cc59b3774f1fb192 Mon Sep 17 00:00:00 2001
From: Razvan Lupusoru <rlupusoru at nvidia.com>
Date: Fri, 11 Jul 2025 13:39:23 -0700
Subject: [PATCH 1/2] [mlir][acc] Add MappableType API for generating private
 recipe init

This introduces the first in a series of APIs that will allow a
MappableType to generate the body of the recipes. The current API
does not actually generate the recipe itself - it generates the body
of it. So it can either be placed in a recipe or inlined directly
as needed.
---
 .../Dialect/OpenACC/OpenACCTypeInterfaces.td  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td
index 9ff2507629856..b8602535296dd 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td
@@ -180,6 +180,36 @@ def OpenACC_MappableTypeInterface : TypeInterface<"MappableType"> {
         return ::mlir::acc::VariableTypeCategory::uncategorized;
       }]
     >,
+      InterfaceMethod<
+      /*description=*/[{
+        Generates the operations that would be normally placed in a recipe's
+        init region. It inserts at the builder's current location.
+        It can be used either to directly "inline" the init region
+        or if the caller sets the insertion point to inside a recipe body,
+        it fills it in. This does not generate the `acc.yield` that normally
+        would terminate a recipe.
+
+        The `extents` are optional and can be empty - it is only when a
+        slice of the private variable needs allocated.
+        The `initVal` can be empty - it is primarily needed for reductions
+        to ensure the variable is also initialized with appropriate value.
+
+        If the return value is empty, it means that recipe body was not
+        successfully generated.
+      }],
+      /*retTy=*/"::mlir::Value",
+      /*methodName=*/"generatePrivateInit",
+      /*args=*/(ins "::mlir::OpBuilder &":$builder,
+                    "::mlir::Location":$loc,
+                    "::mlir::TypedValue<::mlir::acc::MappableType>":$var,
+                    "::llvm::StringRef":$varName,
+                    "::mlir::ValueRange":$extents,
+                    "::mlir::Value":$initVal),
+      /*methodBody=*/"",
+      /*defaultImplementation=*/[{
+        return {};
+      }]
+    >,
   ];
 }
 

>From ae4fea57ab949bc2e3d33407753b5a17faf1bfec Mon Sep 17 00:00:00 2001
From: Razvan Lupusoru <razvan.lupusoru at gmail.com>
Date: Fri, 11 Jul 2025 13:55:30 -0700
Subject: [PATCH 2/2] Update wording allocated to allocation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval at gmail.com>
---
 mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td
index b8602535296dd..9123ac34af67d 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td
@@ -190,7 +190,7 @@ def OpenACC_MappableTypeInterface : TypeInterface<"MappableType"> {
         would terminate a recipe.
 
         The `extents` are optional and can be empty - it is only when a
-        slice of the private variable needs allocated.
+        slice of the private variable needs allocation.
         The `initVal` can be empty - it is primarily needed for reductions
         to ensure the variable is also initialized with appropriate value.
 



More information about the Mlir-commits mailing list