[Mlir-commits] [mlir] 64e74e9 - [mlir][linalg] Add script to update the LinalgNamedStructuredOps.yaml. nfc

Stella Laurenzo llvmlistbot at llvm.org
Sun Aug 22 17:27:10 PDT 2021


Author: Stella Laurenzo
Date: 2021-08-22T16:54:51-07:00
New Revision: 64e74e9d7c309065db20c25a399fdfe48abac2bb

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

LOG: [mlir][linalg] Add script to update the LinalgNamedStructuredOps.yaml. nfc

Also adds banners to the files with update instructions.

Differential Revision: https://reviews.llvm.org/D108529

Added: 
    mlir/tools/mlir-linalg-ods-gen/update_core_linalg_named_ops.sh.in

Modified: 
    mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
    mlir/python/mlir/dialects/linalg/opdsl/dump_oplib.py
    mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
index a877d866dbb18..5ce6d4c57e460 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
@@ -1,4 +1,5 @@
-# Auto-generated file. Do not edit!
+### AUTOGENERATED from core_named_ops.py
+### To regenerate, run: bin/update_core_linalg_named_ops.sh
 --- !LinalgOpConfig
 metadata: !LinalgOpMetadata
   name: matmul
@@ -2274,4 +2275,3 @@ structured_op: !LinalgStructuredOpConfig
                     operands:
                     - !ScalarExpression
                       scalar_arg: I
-

diff  --git a/mlir/python/mlir/dialects/linalg/opdsl/dump_oplib.py b/mlir/python/mlir/dialects/linalg/opdsl/dump_oplib.py
index 05c06e737be73..bacc0c302c5e3 100644
--- a/mlir/python/mlir/dialects/linalg/opdsl/dump_oplib.py
+++ b/mlir/python/mlir/dialects/linalg/opdsl/dump_oplib.py
@@ -81,7 +81,6 @@ def main(args):
 
   # Print.
   if args.format == "yaml":
-    print("# Auto-generated file. Do not edit!")
     print(yaml_dump_all(configs))
   elif args.format == "repr":
     for config in configs:

diff  --git a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
index da39db4532f93..2716bcabc4229 100644
--- a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
+++ b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
@@ -69,3 +69,7 @@ if(LLVM_USE_HOST_TOOLS)
     endif()
   endif()
 endif()
+
+configure_file(
+  update_core_linalg_named_ops.sh.in
+  ${MLIR_TOOLS_DIR}/update_core_linalg_named_ops.sh)

diff  --git a/mlir/tools/mlir-linalg-ods-gen/update_core_linalg_named_ops.sh.in b/mlir/tools/mlir-linalg-ods-gen/update_core_linalg_named_ops.sh.in
new file mode 100755
index 0000000000000..b0fbd644e8f38
--- /dev/null
+++ b/mlir/tools/mlir-linalg-ods-gen/update_core_linalg_named_ops.sh.in
@@ -0,0 +1,32 @@
+#!/bin/bash
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# Updates the LinalgStructuredOps.yaml file based on the
+# core_named_ops.py source of truth.
+
+set -eu -o errtrace
+shopt -s inherit_errexit
+
+mlir_source_dir="@MLIR_SOURCE_DIR@"
+python_exe="@Python3_EXECUTABLE@"
+mlir_binary_dir="@MLIR_BINARY_DIR@"
+python_package_dir="$mlir_binary_dir/python_packages/mlir_core"
+
+if ! [[ -d "$python_package_dir" ]]; then
+  echo "ERROR: Python bindings not found. Build with -DMLIR_ENABLE_BINDINGS_PYTHON=ON"
+  exit 1
+fi
+
+dest_file="$mlir_source_dir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml"
+echo "Updating ops in $dest_file"
+
+export PYTHONPATH="$python_package_dir"
+OUTPUT="$(
+  echo "### AUTOGENERATED from core_named_ops.py" && \
+  echo "### To regenerate, run: bin/update_core_linalg_named_ops.sh" && \
+  "$python_exe" -m mlir.dialects.linalg.opdsl.dump_oplib .ops.core_named_ops \
+)"
+echo "$OUTPUT" > "$dest_file"
+echo "Success."


        


More information about the Mlir-commits mailing list