Skip to content
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

Refactor portable api to use main registration method #1981

Merged
merged 2 commits into from
Feb 1, 2024
Merged
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
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ cc_library(
],
strip_include_prefix = ".",
deps = [
":register",
":stablehlo_ops",
":stablehlo_serialization",
":version",
Expand Down
1 change: 1 addition & 0 deletions stablehlo/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_mlir_dialect_library(StablehloPortableApi
LINK_LIBS PUBLIC
ChloOps
StablehloOps
StablehloRegister
StablehloSerialization
Version
VhloOps
Expand Down
13 changes: 7 additions & 6 deletions stablehlo/api/PortableApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/Parser/Parser.h"
#include "stablehlo/dialect/Register.h"
#include "stablehlo/dialect/Serialization.h"
#include "stablehlo/dialect/StablehloOps.h"
#include "stablehlo/dialect/Version.h"
Expand All @@ -29,10 +30,10 @@ limitations under the License.
namespace mlir {
namespace stablehlo {
namespace {
void loadSerializationDialects(MLIRContext* context) {
context->loadDialect<mlir::func::FuncDialect>();
context->loadDialect<mlir::stablehlo::StablehloDialect>();
context->loadDialect<mlir::vhlo::VhloDialect>();
void loadSerializationDialects(MLIRContext& context) {
mlir::DialectRegistry registry;
mlir::stablehlo::registerAllDialects(registry);
context.appendDialectRegistry(registry);
}
} // namespace

Expand All @@ -48,7 +49,7 @@ LogicalResult serializePortableArtifact(StringRef moduleStr,
StringRef targetVersion,
raw_ostream& os) {
MLIRContext context;
loadSerializationDialects(&context);
loadSerializationDialects(context);
auto module = mlir::parseSourceString<mlir::ModuleOp>(moduleStr, &context);
if (!module || failed(module->verifyInvariants())) return failure();

Expand All @@ -58,7 +59,7 @@ LogicalResult serializePortableArtifact(StringRef moduleStr,
LogicalResult deserializePortableArtifact(StringRef artifactStr,
raw_ostream& os) {
MLIRContext context;
loadSerializationDialects(&context);
loadSerializationDialects(context);
auto module = deserializePortableArtifact(artifactStr, &context);
if (!module) return failure();

Expand Down
Loading