[Mlir-commits] [mlir] de0aa68 - [mlir][linalg] Add conv_2d_nhwc_fhwc to core_named_ops.py

Benjamin Kramer llvmlistbot at llvm.org
Mon Jun 13 11:43:21 PDT 2022


Author: Benjamin Kramer
Date: 2022-06-13T20:43:10+02:00
New Revision: de0aa687a290a125fab4ff008c7c10fd64e7172e

URL: https://github.com/llvm/llvm-project/commit/de0aa687a290a125fab4ff008c7c10fd64e7172e
DIFF: https://github.com/llvm/llvm-project/commit/de0aa687a290a125fab4ff008c7c10fd64e7172e.diff

LOG: [mlir][linalg] Add conv_2d_nhwc_fhwc to core_named_ops.py

So it doesn't disappear when running the generator.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
    mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
index 522bec689f122..cfc8f07cf1c5d 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
@@ -1337,8 +1337,8 @@ structured_op: !LinalgStructuredOpConfig
     name: K
     kind: input_tensor
     type_var: T2
-    shape_map: affine_map<()[s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10] -> (s10, s3,
-      s7, s9)>
+    shape_map: affine_map<()[s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10] -> (s10,
+      s3, s7, s9)>
   - !LinalgOperandDefConfig
     name: O
     kind: output_tensor

diff  --git a/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py b/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
index 023a95dc71267..291a4be22fac2 100644
--- a/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
+++ b/mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py
@@ -293,6 +293,29 @@ def conv_2d_nhwc_hwcf(I=TensorDef(T1, S.N, S.OH * S.SH + S.KH * S.DH,
            D.c]) * TypeFn.cast_signed(U, K[D.kh, D.kw, D.c, D.f])
 
 
+ at linalg_structured_op
+def conv_2d_nhwc_fhwc(I=TensorDef(T1, S.N, S.OH * S.SH + S.KH * S.DH,
+                                  S.OW * S.SW + S.KW * S.DW, S.C),
+                      K=TensorDef(T2, S.F, S.KH, S.KW, S.C),
+                      O=TensorDef(U, S.N, S.OH, S.OW, S.F, output=True),
+                      strides=IndexAttrDef(S.SH, S.SW, default=[1, 1]),
+                      dilations=IndexAttrDef(S.DH, S.DW, default=[1, 1])):
+  """Performs 2-D convolution.
+
+  Layout:
+    * Input: NHWC.
+    * Kernel: FHWC.
+
+  Numeric casting is performed on the operands to the inner multiply, promoting
+  them to the same data type as the accumulator/output.
+  """
+  implements(ConvolutionOpInterface)
+  domain(D.n, D.oh, D.ow, D.f, D.kh, D.kw, D.c)
+  O[D.n, D.oh, D.ow, D.f] += TypeFn.cast_signed(
+      U, I[D.n, D.oh * S.SH + D.kh * S.DH, D.ow * S.SW + D.kw * S.DW,
+           D.c]) * TypeFn.cast_signed(U, K[D.f, D.kh, D.kw, D.c])
+
+
 @linalg_structured_op
 def conv_2d_nhwc_hwcf_q(I=TensorDef(T1, S.N, S.OH * S.SH + S.KH * S.DH,
                                     S.OW * S.SW + S.KW * S.DW, S.C),


        


More information about the Mlir-commits mailing list