-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python] Remove unused MLIR components #2443
base: main
Are you sure you want to change the base?
Changes from all commits
5b4059b
61fc3ac
4c60654
13848f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. # | ||
# All rights reserved. # | ||
# # | ||
# This source code and the accompanying materials are made available under # | ||
# the terms of the Apache License 2.0 which accompanies this distribution. # | ||
# ============================================================================ # | ||
|
||
from ._mlir_libs._quakeDialects import register_all_dialects |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,19 +6,13 @@ | |||||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||||||
******************************************************************************/ | ||||||
|
||||||
#include "mlir/Bindings/Python/PybindAdaptors.h" | ||||||
|
||||||
#include "cudaq/Optimizer/Builder/Intrinsics.h" | ||||||
#include "cudaq/Optimizer/CAPI/Dialects.h" | ||||||
#include "cudaq/Optimizer/CodeGen/Passes.h" | ||||||
#include "cudaq/Optimizer/CodeGen/Pipelines.h" | ||||||
#include "cudaq/Optimizer/Dialect/CC/CCDialect.h" | ||||||
#include "cudaq/Optimizer/Dialect/CC/CCOps.h" | ||||||
#include "cudaq/Optimizer/Dialect/CC/CCTypes.h" | ||||||
#include "cudaq/Optimizer/Dialect/Quake/QuakeDialect.h" | ||||||
#include "cudaq/Optimizer/Dialect/Quake/QuakeTypes.h" | ||||||
#include "cudaq/Optimizer/Transforms/Passes.h" | ||||||
#include "mlir/InitAllDialects.h" | ||||||
#include "cudaq/Optimizer/InitAllDialects.h" | ||||||
#include "cudaq/Optimizer/InitAllPasses.h" | ||||||
#include "mlir/Bindings/Python/PybindAdaptors.h" | ||||||
#include "mlir/CAPI/IR.h" | ||||||
#include <fmt/core.h> | ||||||
#include <pybind11/complex.h> | ||||||
#include <pybind11/stl.h> | ||||||
|
@@ -28,32 +22,10 @@ using namespace mlir::python::adaptors; | |||||
using namespace mlir; | ||||||
|
||||||
namespace cudaq { | ||||||
static bool registered = false; | ||||||
|
||||||
void registerQuakeDialectAndTypes(py::module &m) { | ||||||
void registerQuakeTypes(py::module &m) { | ||||||
auto quakeMod = m.def_submodule("quake"); | ||||||
|
||||||
quakeMod.def( | ||||||
"register_dialect", | ||||||
[](MlirContext context, bool load) { | ||||||
MlirDialectHandle handle = mlirGetDialectHandle__quake__(); | ||||||
mlirDialectHandleRegisterDialect(handle, context); | ||||||
if (load) { | ||||||
mlirDialectHandleLoadDialect(handle, context); | ||||||
} | ||||||
|
||||||
if (!registered) { | ||||||
cudaq::opt::registerOptCodeGenPasses(); | ||||||
cudaq::opt::registerOptTransformsPasses(); | ||||||
cudaq::opt::registerAggressiveEarlyInlining(); | ||||||
cudaq::opt::registerUnrollingPipeline(); | ||||||
cudaq::opt::registerTargetPipelines(); | ||||||
cudaq::opt::registerMappingPipeline(); | ||||||
registered = true; | ||||||
} | ||||||
}, | ||||||
py::arg("context") = py::none(), py::arg("load") = true); | ||||||
|
||||||
mlir_type_subclass(quakeMod, "RefType", [](MlirType type) { | ||||||
return unwrap(type).isa<quake::RefType>(); | ||||||
}).def_classmethod("get", [](py::object cls, MlirContext ctx) { | ||||||
|
@@ -143,21 +115,10 @@ void registerQuakeDialectAndTypes(py::module &m) { | |||||
}); | ||||||
} | ||||||
|
||||||
void registerCCDialectAndTypes(py::module &m) { | ||||||
void registerCCTypes(py::module &m) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Assuming that's ok, should move these 2 out of the namespace as well. |
||||||
|
||||||
auto ccMod = m.def_submodule("cc"); | ||||||
|
||||||
ccMod.def( | ||||||
"register_dialect", | ||||||
[](MlirContext context, bool load) { | ||||||
MlirDialectHandle ccHandle = mlirGetDialectHandle__cc__(); | ||||||
mlirDialectHandleRegisterDialect(ccHandle, context); | ||||||
if (load) { | ||||||
mlirDialectHandleLoadDialect(ccHandle, context); | ||||||
} | ||||||
}, | ||||||
py::arg("context") = py::none(), py::arg("load") = true); | ||||||
|
||||||
mlir_type_subclass(ccMod, "CharspanType", [](MlirType type) { | ||||||
return unwrap(type).isa<cudaq::cc::CharspanType>(); | ||||||
}).def_classmethod("get", [](py::object cls, MlirContext ctx) { | ||||||
|
@@ -298,9 +259,6 @@ void registerCCDialectAndTypes(py::module &m) { | |||||
} | ||||||
|
||||||
void bindRegisterDialects(py::module &mod) { | ||||||
registerQuakeDialectAndTypes(mod); | ||||||
registerCCDialectAndTypes(mod); | ||||||
|
||||||
mod.def("load_intrinsic", [](MlirModule module, std::string name) { | ||||||
auto unwrapped = unwrap(module); | ||||||
cudaq::IRBuilder builder = IRBuilder::atBlockEnd(unwrapped.getBody()); | ||||||
|
@@ -310,14 +268,17 @@ void bindRegisterDialects(py::module &mod) { | |||||
|
||||||
mod.def("register_all_dialects", [](MlirContext context) { | ||||||
DialectRegistry registry; | ||||||
registry.insert<quake::QuakeDialect, cudaq::cc::CCDialect>(); | ||||||
cudaq::opt::registerCodeGenDialect(registry); | ||||||
registerAllDialects(registry); | ||||||
auto *mlirContext = unwrap(context); | ||||||
cudaq::registerAllDialects(registry); | ||||||
MLIRContext *mlirContext = unwrap(context); | ||||||
mlirContext->appendDialectRegistry(registry); | ||||||
mlirContext->loadAllAvailableDialects(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does loadAllAvailableDialects actually load Quake, CC, and CodeGen? Do we need an explicit test to verify that all the dialects we expect to be loaded are loaded? |
||||||
}); | ||||||
|
||||||
// Register type as passes once, when the module is loaded. | ||||||
registerQuakeTypes(mod); | ||||||
registerCCTypes(mod); | ||||||
cudaq::registerAllPasses(); | ||||||
|
||||||
mod.def("gen_vector_of_complex_constant", [](MlirLocation loc, | ||||||
MlirModule module, | ||||||
std::string name, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.