Skip to content

Conversation

@razvanlupusoru
Copy link
Contributor

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2025

@llvm/pr-subscribers-mlir

Author: Razvan Lupusoru (razvanlupusoru)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/148293.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td (+30)
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 {};
+      }]
+    >,
   ];
 }
 

@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2025

@llvm/pr-subscribers-mlir-openacc

Author: Razvan Lupusoru (razvanlupusoru)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/148293.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td (+30)
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 {};
+      }]
+    >,
   ];
 }
 

@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2025

@llvm/pr-subscribers-openacc

Author: Razvan Lupusoru (razvanlupusoru)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/148293.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td (+30)
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 {};
+      }]
+    >,
   ];
 }
 

Copy link
Contributor

@clementval clementval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a comment in the description. needs allocated reads weird to me but I might be wrong.

Co-authored-by: Valentin Clement (バレンタイン クレメン) <[email protected]>
@razvanlupusoru razvanlupusoru merged commit 8f37fb2 into llvm:main Jul 11, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants