Skip to content

Commit 8b4583a

Browse files
committed
[MLIR][Python] enable precise registration
1 parent 17d76f8 commit 8b4583a

File tree

89 files changed

+1185
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1185
-95
lines changed

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,14 @@ endfunction()
457457
# This file is where the *Attrs are defined, not where the *Enums are defined.
458458
# **WARNING**: This arg will shortly be removed when the TODO for
459459
# declare_mlir_dialect_python_bindings is satisfied. Use at your risk.
460+
# EMBED_CAPI_LINK_LIBS: Dependent CAPI libraries that this extension depends
461+
# on. These will be collected for all extensions and put into an
462+
# aggregate dylib that is linked against.
460463
function(declare_mlir_dialect_extension_python_bindings)
461464
cmake_parse_arguments(ARG
462465
"GEN_ENUM_BINDINGS"
463466
"ROOT_DIR;ADD_TO_PARENT;TD_FILE;DIALECT_NAME;EXTENSION_NAME"
464-
"SOURCES;SOURCES_GLOB;DEPENDS;GEN_ENUM_BINDINGS_TD_FILE"
467+
"SOURCES;SOURCES_GLOB;DEPENDS;GEN_ENUM_BINDINGS_TD_FILE;EMBED_CAPI_LINK_LIBS"
465468
${ARGN})
466469
# Source files.
467470
set(_extension_target "${ARG_ADD_TO_PARENT}.${ARG_EXTENSION_NAME}")
@@ -503,6 +506,7 @@ function(declare_mlir_dialect_extension_python_bindings)
503506
ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}"
504507
ADD_TO_PARENT "${_extension_target}"
505508
SOURCES ${_sources}
509+
EMBED_CAPI_LINK_LIBS "${ARG_EMBED_CAPI_LINK_LIBS}"
506510
)
507511
endif()
508512
endfunction()

mlir/include/mlir-c/Bindings/Python/Interop.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
#define MLIR_PYTHON_CAPSULE_VALUE MAKE_MLIR_PYTHON_QUALNAME("ir.Value._CAPIPtr")
8585
#define MLIR_PYTHON_CAPSULE_TYPEID \
8686
MAKE_MLIR_PYTHON_QUALNAME("ir.TypeID._CAPIPtr")
87+
#define MLIR_PYTHON_CAPSULE_DIALECT_HANDLE \
88+
MAKE_MLIR_PYTHON_QUALNAME("ir.DialectHandle._CAPIPtr")
8789

8890
/** Attribute on MLIR Python objects that expose their C-API pointer.
8991
* This will be a type-specific capsule created as per one of the helpers
@@ -457,6 +459,13 @@ static inline MlirValue mlirPythonCapsuleToValue(PyObject *capsule) {
457459
return value;
458460
}
459461

462+
static inline MlirDialectHandle
463+
mlirPythonCapsuleToDialectHandle(PyObject *capsule) {
464+
void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_DIALECT_HANDLE);
465+
MlirDialectHandle handle = {ptr};
466+
return handle;
467+
}
468+
460469
#ifdef __cplusplus
461470
}
462471
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- mlir-c/Dialect/Affine.h - C API for Affine 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+
// This header declares the C interface for registering and accessing the
11+
// Affine dialect. A dialect should be registered with a context to make it
12+
// available to users of the context. These users must load the dialect
13+
// before using any of its attributes, operations or types. Parser and pass
14+
// manager can load registered dialects automatically.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef MLIR_C_DIALECT_AFFINE_H
19+
#define MLIR_C_DIALECT_AFFINE_H
20+
21+
#include "mlir-c/IR.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Affine, affine);
28+
29+
MLIR_CAPI_EXPORTED void
30+
mlirAffineRegisterTransformDialectExtension(MlirDialectRegistry registry);
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif // MLIR_C_DIALECT_AFFINE_H
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- mlir-c/Dialect/Bufferization.h - C API for Bufferization dialect --===//
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+
// This header declares the C interface for registering and accessing the
11+
// Bufferization dialect. A dialect should be registered with a context to make
12+
// it available to users of the context. These users must load the dialect
13+
// before using any of its attributes, operations or types. Parser and pass
14+
// manager can load registered dialects automatically.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef MLIR_C_DIALECT_BUFFERIZATION_H
19+
#define MLIR_C_DIALECT_BUFFERIZATION_H
20+
21+
#include "mlir-c/IR.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Bufferization, bufferization);
28+
29+
MLIR_CAPI_EXPORTED void mlirBufferizationRegisterTransformDialectExtension(
30+
MlirDialectRegistry registry);
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif // MLIR_C_DIALECT_BUFFERIZATION_H
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- mlir-c/Dialect/Builtin.h - C API for Builtin 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+
// This header declares the C interface for registering and accessing the
11+
// Builtin dialect. A dialect should be registered with a context to make it
12+
// available to users of the context. These users must load the dialect
13+
// before using any of its attributes, operations or types. Parser and pass
14+
// manager can load registered dialects automatically.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef MLIR_C_DIALECT_BUILTIN_H
19+
#define MLIR_C_DIALECT_BUILTIN_H
20+
21+
#include "mlir-c/IR.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Builtin, builtin);
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif
32+
33+
#endif // MLIR_C_DIALECT_BUILTIN_H
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- mlir-c/Dialect/Complex.h - C API for Complex 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+
// This header declares the C interface for registering and accessing the
11+
// Complex dialect. A dialect should be registered with a context to make it
12+
// available to users of the context. These users must load the dialect
13+
// before using any of its attributes, operations or types. Parser and pass
14+
// manager can load registered dialects automatically.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef MLIR_C_DIALECT_COMPLEX_H
19+
#define MLIR_C_DIALECT_COMPLEX_H
20+
21+
#include "mlir-c/IR.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Complex, complex);
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif
32+
33+
#endif // MLIR_C_DIALECT_COMPLEX_H

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ mlirGPUObjectAttrHasKernels(MlirAttribute mlirObjectAttr);
6363
MLIR_CAPI_EXPORTED MlirAttribute
6464
mlirGPUObjectAttrGetKernels(MlirAttribute mlirObjectAttr);
6565

66+
MLIR_CAPI_EXPORTED void
67+
mlirGPURegisterTransformDialectExtension(MlirDialectRegistry registry);
68+
6669
#ifdef __cplusplus
6770
}
6871
#endif

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ mlirLinalgGetIndexingMapsAttribute(MlirOperation op);
5555

5656
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Linalg, linalg);
5757

58+
MLIR_CAPI_EXPORTED void
59+
mlirLinalgRegisterTransformDialectExtension(MlirDialectRegistry registry);
60+
5861
#ifdef __cplusplus
5962
}
6063
#endif

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ extern "C" {
2626

2727
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(MemRef, memref);
2828

29+
MLIR_CAPI_EXPORTED void
30+
mlirMemRefRegisterTransformDialectExtension(MlirDialectRegistry registry);
31+
2932
#ifdef __cplusplus
3033
}
3134
#endif

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ MLIR_CAPI_EXPORTED MlirType mlirNVGPUTensorMapDescriptorTypeGet(
2929
MlirContext ctx, MlirType tensorMemrefType, int swizzle, int l2promo,
3030
int oobFill, int interleave);
3131

32+
MLIR_CAPI_EXPORTED void
33+
mlirNVGPURegisterTransformDialectExtension(MlirDialectRegistry registry);
34+
3235
#ifdef __cplusplus
3336
}
3437
#endif

0 commit comments

Comments
 (0)