Skip to content

Commit e7db840

Browse files
[mlir][python] Add python support for async dialect and passes.
since the `async` keyword is reserved in python, the dialect is called async_dialect. Differential Revision: https://reviews.llvm.org/D101447
1 parent 262c679 commit e7db840

File tree

11 files changed

+165
-0
lines changed

11 files changed

+165
-0
lines changed

mlir/include/mlir-c/Dialect/Async.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- mlir-c/Dialect/Async.h - C API for Async dialect ---------*- C -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4+
// Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===---------------------------------------------------------------------===//
9+
10+
#ifndef MLIR_C_DIALECT_ASYNC_H
11+
#define MLIR_C_DIALECT_ASYNC_H
12+
13+
#include "mlir-c/Registration.h"
14+
#include "mlir-c/Support.h"
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Async, async);
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#include "mlir/Dialect/Async/Passes.capi.h.inc"
27+
28+
#endif // MLIR_C_DIALECT_ASYNC_H

mlir/include/mlir/Dialect/Async/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ add_subdirectory(IR)
22

33
set(LLVM_TARGET_DEFINITIONS Passes.td)
44
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Async)
5+
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix Async)
6+
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix Async)
57
add_public_tablegen_target(MLIRAsyncPassIncGen)
68

79
add_mlir_doc(Passes AsyncPasses ./ -gen-pass-doc)

mlir/lib/Bindings/Python/AsyncOps.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===-- AsyncOps.td - Entry point async_dialect bindings --*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#ifndef PYTHON_BINDINGS_ASYNC_OPS
10+
#define PYTHON_BINDINGS_ASYNC_OPS
11+
12+
include "mlir/Bindings/Python/Attributes.td"
13+
include "mlir/Dialect/Async/IR/AsyncOps.td"
14+
15+
#endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- AsyncPasses.cpp - Pybind module for the Async passes -------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "mlir-c/Dialect/Async.h"
10+
11+
#include <pybind11/pybind11.h>
12+
13+
// -----------------------------------------------------------------------------
14+
// Module initialization.
15+
// -----------------------------------------------------------------------------
16+
17+
PYBIND11_MODULE(_mlirAsyncPasses, m) {
18+
m.doc() = "MLIR Async Dialect Passes";
19+
20+
// Register all Async passes on load.
21+
mlirRegisterAsyncPasses();
22+
}

mlir/lib/Bindings/Python/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ endforeach()
3131
# Generate dialect-specific bindings.
3232
################################################################################
3333

34+
add_mlir_dialect_python_bindings(MLIRBindingsPythonAsyncOps
35+
TD_FILE AsyncOps.td
36+
DIALECT_NAME async_dialect)
37+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonAsyncOps)
38+
3439
add_mlir_dialect_python_bindings(MLIRBindingsPythonBuiltinOps
3540
TD_FILE BuiltinOps.td
3641
DIALECT_NAME builtin)
@@ -120,6 +125,14 @@ endif()
120125
add_subdirectory(Transforms)
121126
add_subdirectory(Conversions)
122127

128+
add_mlir_python_extension(MLIRAsyncPassesBindingsPythonExtension _mlirAsyncPasses
129+
INSTALL_DIR
130+
python
131+
SOURCES
132+
AsyncPasses.cpp
133+
)
134+
add_dependencies(MLIRBindingsPythonExtension MLIRAsyncPassesBindingsPythonExtension)
135+
123136
add_mlir_python_extension(MLIRLinalgPassesBindingsPythonExtension _mlirLinalgPasses
124137
INSTALL_DIR
125138
python
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
from .._async_dialect_ops_gen import *
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
from ...._cext_loader import _load_extension
6+
_cextAsyncPasses = _load_extension("_mlirAsyncPasses")

mlir/lib/CAPI/Dialect/Async.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===- Async.cpp - C Interface for Async dialect --------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "mlir/Dialect/Async/IR/Async.h"
10+
#include "mlir-c/Dialect/Async.h"
11+
#include "mlir/CAPI/Registration.h"
12+
13+
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Async, async, mlir::async::AsyncDialect)

mlir/lib/CAPI/Dialect/AsyncPasses.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===- AsyncPasses.cpp - C API for Async Dialect Passes -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "mlir/CAPI/Pass.h"
10+
#include "mlir/Dialect/Async/Passes.h"
11+
#include "mlir/Pass/Pass.h"
12+
13+
// Must include the declarations as they carry important visibility attributes.
14+
#include "mlir/Dialect/Async/Passes.capi.h.inc"
15+
16+
using namespace mlir;
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
#include "mlir/Dialect/Async/Passes.capi.cpp.inc"
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif

mlir/lib/CAPI/Dialect/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# TODO: Make the check source feature optional as an argument on *_add_library.
22
set(LLVM_OPTIONAL_SOURCES
3+
Async.cpp
4+
AsyncPasses.cpp
35
Linalg.cpp
46
LinalgPasses.cpp
57
SCF.cpp
@@ -8,6 +10,20 @@ set(LLVM_OPTIONAL_SOURCES
810
Tensor.cpp
911
)
1012

13+
add_mlir_public_c_api_library(MLIRCAPIAsync
14+
Async.cpp
15+
AsyncPasses.cpp
16+
17+
DEPENDS
18+
MLIRAsyncPassIncGen
19+
20+
LINK_LIBS PUBLIC
21+
MLIRCAPIIR
22+
MLIRAsync
23+
MLIRAsyncTransforms
24+
MLIRPass
25+
)
26+
1127
add_mlir_public_c_api_library(MLIRCAPILinalg
1228
Linalg.cpp
1329
LinalgPasses.cpp

0 commit comments

Comments
 (0)