[Mlir-commits] [mlir] 2b664d6 - [mlir][python bindings] turn on openmp

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Aug 23 16:17:10 PDT 2023


Author: max
Date: 2023-08-23T18:17:04-05:00
New Revision: 2b664d678dcd6b23eda992b45d009788e34ea8f1

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

LOG: [mlir][python bindings] turn on openmp

Just as in https://reviews.llvm.org/D157820, dialect registration is independent of any vendor specific libs having been linked/built/etc.

Reviewed By: rkayaith

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

Added: 
    mlir/include/mlir-c/Dialect/OpenMP.h
    mlir/lib/CAPI/Dialect/OpenMP.cpp
    mlir/python/mlir/dialects/OpenMPOps.td
    mlir/python/mlir/dialects/openmp.py
    mlir/test/python/dialects/openmp_ops.py

Modified: 
    mlir/lib/CAPI/Dialect/CMakeLists.txt
    mlir/python/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir-c/Dialect/OpenMP.h b/mlir/include/mlir-c/Dialect/OpenMP.h
new file mode 100644
index 00000000000000..719ed702aad29a
--- /dev/null
+++ b/mlir/include/mlir-c/Dialect/OpenMP.h
@@ -0,0 +1,25 @@
+//===-- mlir-c/Dialect/OpenMP.h - C API for OpenMP Dialect --------*- C -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_C_DIALECT_OPENM_H
+#define MLIR_C_DIALECT_OPENM_H
+
+#include "mlir-c/IR.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OpenMP, omp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // MLIR_C_DIALECT_OPENM_H

diff  --git a/mlir/lib/CAPI/Dialect/CMakeLists.txt b/mlir/lib/CAPI/Dialect/CMakeLists.txt
index 13e57a29d65c92..d815eba48d9b9d 100644
--- a/mlir/lib/CAPI/Dialect/CMakeLists.txt
+++ b/mlir/lib/CAPI/Dialect/CMakeLists.txt
@@ -198,6 +198,15 @@ add_mlir_upstream_c_api_library(MLIRCAPIQuant
   MLIRQuantDialect
 )
 
+add_mlir_upstream_c_api_library(MLIRCAPIOpenMP
+  OpenMP.cpp
+
+  PARTIAL_SOURCES_INTENDED
+  LINK_LIBS PUBLIC
+  MLIRCAPIIR
+  MLIROpenMPDialect
+)
+
 add_mlir_upstream_c_api_library(MLIRCAPIPDL
   PDL.cpp
 

diff  --git a/mlir/lib/CAPI/Dialect/OpenMP.cpp b/mlir/lib/CAPI/Dialect/OpenMP.cpp
new file mode 100644
index 00000000000000..3ffa57ab575ffa
--- /dev/null
+++ b/mlir/lib/CAPI/Dialect/OpenMP.cpp
@@ -0,0 +1,16 @@
+//===- OPENMP.cpp - C Interface for OPENMP dialect
+//------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir-c/Dialect/OpenMP.h"
+#include "mlir/CAPI/Registration.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+
+using namespace mlir;
+
+MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(OpenMP, omp, omp::OpenMPDialect)

diff  --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 225da778cf3b3a..5d2f233caa85d8 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -315,6 +315,14 @@ declare_mlir_dialect_python_bindings(
     _mlir_libs/_mlir/dialects/pdl.pyi
   DIALECT_NAME pdl)
 
+declare_mlir_dialect_python_bindings(
+  ADD_TO_PARENT MLIRPythonSources.Dialects
+  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+  TD_FILE dialects/OpenMPOps.td
+  SOURCES
+    dialects/openmp.py
+  DIALECT_NAME omp)
+
 declare_mlir_dialect_python_bindings(
   ADD_TO_PARENT MLIRPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"

diff  --git a/mlir/python/mlir/dialects/OpenMPOps.td b/mlir/python/mlir/dialects/OpenMPOps.td
new file mode 100644
index 00000000000000..b91179b0d90be2
--- /dev/null
+++ b/mlir/python/mlir/dialects/OpenMPOps.td
@@ -0,0 +1,14 @@
+//===-- OpenMPOps.td - Entry point for OpenMPOps bind ------------*- tablegen -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef PYTHON_BINDINGS_OPENMP_OPS
+#define PYTHON_BINDINGS_OPENMP_OPS
+
+include "mlir/Dialect/OpenMP/OpenMPOps.td"
+
+#endif

diff  --git a/mlir/python/mlir/dialects/openmp.py b/mlir/python/mlir/dialects/openmp.py
new file mode 100644
index 00000000000000..604f0bd03e9326
--- /dev/null
+++ b/mlir/python/mlir/dialects/openmp.py
@@ -0,0 +1,5 @@
+#  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
+
+from ._omp_ops_gen import *

diff  --git a/mlir/test/python/dialects/openmp_ops.py b/mlir/test/python/dialects/openmp_ops.py
new file mode 100644
index 00000000000000..d1368535234022
--- /dev/null
+++ b/mlir/test/python/dialects/openmp_ops.py
@@ -0,0 +1,23 @@
+# RUN: %PYTHON %s | FileCheck %s
+
+from mlir.ir import *
+from mlir.dialects.openmp import *
+
+
+def constructAndPrintInModule(f):
+    print("\nTEST:", f.__name__)
+    with Context(), Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            f()
+        print(module)
+    return f
+
+
+# CHECK-LABEL: test_barrier
+# CHECK: module {
+# CHECK:   omp.barrier
+# CHECK: }
+ at constructAndPrintInModule
+def test_barrier():
+    barrier = BarrierOp()


        


More information about the Mlir-commits mailing list