Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mlir/examples/standalone/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ if(NOT EXTERNAL_PROJECT_BUILD)
add_dependencies(StandalonePythonModules "${_mlir_typestub_gen_target}")
endif()
add_dependencies(StandalonePythonModules "${_standaloneDialectsNanobind_typestub_gen_target}")

target_include_directories(StandalonePythonModules.extension._mlir.dso PRIVATE ${NB_DIR}/ext/robin_map/include)
target_include_directories(StandalonePythonModules.extension._mlir.dso PRIVATE ${NB_DIR}/src)
32 changes: 32 additions & 0 deletions mlir/lib/Bindings/Python/IRCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2897,6 +2897,36 @@ maybeGetTracebackLocation(const std::optional<PyLocation> &location) {
// Populates the core exports of the 'ir' submodule.
//------------------------------------------------------------------------------

#include "nb_internals.h"

auto print_live_op = [](void *k, PyObject *v) {
nb::handle op_py_type = nb::type<PyOperation>();
nb::handle maybe_op_inst{v};
nb::str end{" "};
if (maybe_op_inst.type().is(op_py_type)) {
nb::print("found live operation:", end);
nb::print(maybe_op_inst);
}
};

void print_live_ops() noexcept {
nanobind::detail::nb_internals *p = nanobind::detail::internals;
for (size_t i = 0; i < p->shard_count; ++i) {
nanobind::detail::nb_shard &s = p->shards[i];
nanobind::detail::lock_shard lock(s);
for (auto [k, v] : s.inst_c2p) {
if (NB_UNLIKELY(nanobind::detail::nb_is_seq(v))) {
nanobind::detail::nb_inst_seq *seq = nanobind::detail::nb_get_seq(v);
for (; seq != nullptr; seq = seq->next) {
print_live_op(k, seq->inst);
}
} else {
print_live_op(k, (PyObject *)v);
}
}
}
}

void mlir::python::populateIRCore(nb::module_ &m) {
// disable leak warnings which tend to be false positives.
nb::set_leak_warnings(false);
Expand Down Expand Up @@ -4475,4 +4505,6 @@ void mlir::python::populateIRCore(nb::module_ &m) {
PyErr_SetObject(PyExc_Exception, obj.ptr());
}
});

m.def("print_live_ops", &print_live_ops);
}
3 changes: 3 additions & 0 deletions mlir/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,6 @@ add_dependencies(MLIRPythonModules "${_mlir_typestub_gen_target}")
if(MLIR_INCLUDE_TESTS)
add_dependencies(MLIRPythonModules "${_mlirPythonTestNanobind_typestub_gen_target}")
endif()
message(STATUS "NB_DIR=${NB_DIR}")
target_include_directories(MLIRPythonModules.extension._mlir.dso PRIVATE ${NB_DIR}/ext/robin_map/include)
target_include_directories(MLIRPythonModules.extension._mlir.dso PRIVATE ${NB_DIR}/src)
4 changes: 4 additions & 0 deletions mlir/test/python/dialects/memref.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def testSubViewOpInferReturnTypeSemantics():
# CHECK: %{{.*}} = memref.subview %[[DYNAMICALLOC]][1, 1] [3, 3] [1, 1] : memref<10x10xi32, strided<[10, 1], offset: ?>> to memref<3x3xi32, strided<[10, 1], offset: ?>>
print(y.owner)

# CHECK: %subview_10 = memref.subview
# CHECK: %0 = arith.addi %c3_2, %c4_3 : index
print_live_ops()


# CHECK-LABEL: TEST: testSubViewOpInferReturnTypeExtensiveSlicing
@run
Expand Down
Loading