[Mlir-commits] [mlir] [mlir][python] python binding wrapper for the affine.AffineForOp (PR #74408)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Dec 4 19:46:24 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r 74c00d432944ca4ada5f105b0d396b55f2692f05..baf42cdea2f243a1c9d2f89c456589e351c50521 mlir/python/mlir/dialects/affine.py mlir/test/python/dialects/affine.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- python/mlir/dialects/affine.py	2023-12-05 03:31:58.000000 +0000
+++ python/mlir/dialects/affine.py	2023-12-05 03:46:16.692634 +0000
@@ -30,52 +30,56 @@
         iter_args: Optional[Union[Operation, OpView, Sequence[Value]]] = None,
         *,
         lower_bound_operands=[],
         upper_bound_operands=[],
         loc=None,
-        ip=None
+        ip=None,
     ):
         """Creates an Affine `for` operation.
 
         - `lower_bound` is the affine map to use as lower bound of the loop.
         - `upper_bound` is the affine map to use as upper bound of the loop.
         - `step` is the value to use as loop step.
         - `iter_args` is a list of additional loop-carried arguments or an operation
           producing them as results.
-        - `lower_bound_operands` is the list of arguments to substitute the dimensions, 
+        - `lower_bound_operands` is the list of arguments to substitute the dimensions,
           then symbols in the `lower_bound` affine map, in an increasing order
-        - `upper_bound_operands` is the list of arguments to substitute the dimensions, 
+        - `upper_bound_operands` is the list of arguments to substitute the dimensions,
           then symbols in the `upper_bound` affine map, in an increasing order
         """
 
         if iter_args is None:
             iter_args = []
         iter_args = _get_op_results_or_values(iter_args)
 
         if len(lower_bound_operands) != lower_bound.n_inputs:
             raise ValueError(
-                f"Wrong number of lower bound operands passed to AffineForOp. " +
-                "Expected {lower_bound.n_symbols}, got {len(lower_bound_operands)}.")
+                f"Wrong number of lower bound operands passed to AffineForOp. "
+                + "Expected {lower_bound.n_symbols}, got {len(lower_bound_operands)}."
+            )
 
         if len(upper_bound_operands) != upper_bound.n_inputs:
             raise ValueError(
-                f"Wrong number of upper bound operands passed to AffineForOp. " +
-                "Expected {upper_bound.n_symbols}, got {len(upper_bound_operands)}.")
+                f"Wrong number of upper bound operands passed to AffineForOp. "
+                + "Expected {upper_bound.n_symbols}, got {len(upper_bound_operands)}."
+            )
 
         results = [arg.type for arg in iter_args]
         super().__init__(
             results_=results,
-            lowerBoundOperands=[_get_op_result_or_value(
-                o) for o in lower_bound_operands],
-            upperBoundOperands=[_get_op_result_or_value(
-                o) for o in upper_bound_operands],
+            lowerBoundOperands=[
+                _get_op_result_or_value(o) for o in lower_bound_operands
+            ],
+            upperBoundOperands=[
+                _get_op_result_or_value(o) for o in upper_bound_operands
+            ],
             inits=list(iter_args),
             lowerBoundMap=AffineMapAttr.get(lower_bound),
             upperBoundMap=AffineMapAttr.get(upper_bound),
             step=IntegerAttr.get(IndexType.get(), step),
             loc=loc,
-            ip=ip
+            ip=ip,
         )
         self.regions[0].blocks.append(IndexType.get(), *results)
 
     @property
     def body(self):
--- test/python/dialects/affine.py	2023-12-05 03:31:58.000000 +0000
+++ test/python/dialects/affine.py	2023-12-05 03:46:16.743065 +0000
@@ -55,11 +55,10 @@
             memref_type_in = MemRefType.get([10, 10], f32)
 
             # CHECK: func.func @affine_load_test(%[[I_VAR:.*]]: memref<10x10xf32>, %[[ARG0:.*]]: index) -> f32 {
             @func.FuncOp.from_py_func(memref_type_in, index_type)
             def affine_load_test(I, arg0):
-
                 d0 = AffineDimExpr.get(0)
                 s0 = AffineSymbolExpr.get(0)
                 map = AffineMap.get(1, 1, [s0 * 3, d0 + s0 + 1])
 
                 # CHECK: {{.*}} = affine.load %[[I_VAR]][symbol(%[[ARG0]]) * 3, %[[ARG0]] + symbol(%[[ARG0]]) + 1] : memref<10x10xf32>
@@ -103,21 +102,23 @@
                 ub = AffineMap.get(2, 0, [d0 - 2, 32 * d1])
                 sum_0 = arith.ConstantOp(f32, 0.0)
 
                 # CHECK: %0 = affine.for %[[INDVAR:.*]] = max #[[MAP0]](%[[C2]])[%[[C3]]] to min #[[MAP1]](%[[C9]], %[[C1]]) step 2 iter_args(%[[SUM0:.*]] = %[[AC0]]) -> (f32) {
                 sum = affine.AffineForOp(
-                    lb, ub, 2,
+                    lb,
+                    ub,
+                    2,
                     iter_args=[sum_0],
                     lower_bound_operands=[c2, c3],
-                    upper_bound_operands=[c9, c1]
+                    upper_bound_operands=[c9, c1],
                 )
 
                 with InsertionPoint(sum.body):
-
                     # CHECK: %[[TMP:.*]] = memref.load %[[BUFFER]][%[[INDVAR]]] : memref<1024xf32>
                     tmp = memref.LoadOp(buffer, [sum.induction_variable])
                     sum_next = arith.AddFOp(sum.inner_iter_args[0], tmp)
 
                     affine.AffineYieldOp([sum_next])
 
                 return
+
         print(module)

``````````

</details>


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


More information about the Mlir-commits mailing list