Skip to content

Commit dc85d0c

Browse files
authored
[mlir][python] UB dialect python bindings (llvm#157127)
1 parent 2540fb6 commit dc85d0c

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

mlir/include/mlir/Dialect/UB/IR/UBOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
include "mlir/Interfaces/SideEffectInterfaces.td"
1313
include "mlir/IR/AttrTypeBase.td"
1414

15-
include "UBOpsInterfaces.td"
15+
include "mlir/Dialect/UB/IR/UBOpsInterfaces.td"
1616

1717
def UB_Dialect : Dialect {
1818
let name = "ub";

mlir/python/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ declare_mlir_dialect_python_bindings(
453453
DIALECT_NAME tosa
454454
)
455455

456+
declare_mlir_dialect_python_bindings(
457+
ADD_TO_PARENT MLIRPythonSources.Dialects
458+
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
459+
TD_FILE dialects/UBOps.td
460+
SOURCES dialects/ub.py
461+
DIALECT_NAME ub
462+
)
463+
456464
declare_mlir_dialect_python_bindings(
457465
ADD_TO_PARENT MLIRPythonSources.Dialects
458466
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
@@ -847,4 +855,3 @@ add_mlir_python_modules(MLIRPythonModules
847855
COMMON_CAPI_LINK_LIBS
848856
MLIRPythonCAPI
849857
)
850-

mlir/python/mlir/dialects/UBOps.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- UBOps.td - Entry point for UB 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_UB_OPS
10+
#define PYTHON_BINDINGS_UB_OPS
11+
12+
include "mlir/Dialect/UB/IR/UBOps.td"
13+
14+
#endif // PYTHON_BINDINGS_UB_OPS

mlir/python/mlir/dialects/ub.py

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 ._ub_ops_gen import *

mlir/test/python/dialects/ub.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# RUN: %PYTHON %s | FileCheck %s
2+
# This is just a smoke test that the dialect is functional.
3+
from array import array
4+
5+
from mlir.ir import *
6+
from mlir.dialects import ub
7+
from mlir.extras import types as T
8+
9+
10+
def constructAndPrintInModule(f):
11+
print("\nTEST:", f.__name__)
12+
with Context(), Location.unknown():
13+
module = Module.create()
14+
with InsertionPoint(module.body):
15+
f()
16+
print(module)
17+
return f
18+
19+
20+
# CHECK-LABEL: testSmoke
21+
@constructAndPrintInModule
22+
def testSmoke():
23+
# CHECK: Value(%{{.*}} = ub.poison : f32
24+
f32 = F32Type.get()
25+
poison = ub.poison(f32)
26+
print(poison)
27+
assert isinstance(poison, Value)

0 commit comments

Comments
 (0)