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

[mlir][transform] Fix new interpreter and library preloading passes. #69190

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion mlir/include/mlir/Dialect/Transform/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def PreloadLibraryPass : Pass<"transform-preload-library"> {

Warning: Only a single such pass should exist for a given MLIR context.
This is a temporary solution until a resource-based solution is available.
TODO: investigate using a resource blob if some ownership mode allows it.
}];
// TODO: investigate using a resource blob if some ownership mode allows it.
let dependentDialects = ["transform::TransformDialect"];
let options = [
ListOption<"transformLibraryPaths", "transform-library-paths", "std::string",
"Optional paths to files with modules that should be merged into the "
Expand All @@ -67,6 +68,7 @@ def InterpreterPass : Pass<"transform-interpreter"> {
sequence transformation specified by the provided name (defaults to
`__transform_main`).
}];
let dependentDialects = ["transform::TransformDialect"];
let options = [
Option<"entryPoint", "entry-point", "std::string",
/*default=*/[{"__transform_main"}],
Expand Down
15 changes: 3 additions & 12 deletions mlir/lib/Dialect/Transform/Transforms/InterpreterPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ class InterpreterPass
public:
using Base::Base;

LogicalResult initialize(MLIRContext *context) override {
// TODO: investigate using a resource blob if some ownership mode allows it.
transformModule = transform::detail::getPreloadedTransformModule(context);
return success();
}

void runOnOperation() override {
MLIRContext *context = &getContext();
ModuleOp transformModule =
transform::detail::getPreloadedTransformModule(context);
if (failed(transform::applyTransformNamedSequence(
getOperation(), transformModule,
options.enableExpensiveChecks(true), entryPoint)))
Expand All @@ -41,11 +38,5 @@ class InterpreterPass
private:
/// Transform interpreter options.
transform::TransformOptions options;

/// The separate transform module to be used for transformations, shared
/// across multiple instances of the pass if it is applied in parallel to
/// avoid potentially expensive cloning. MUST NOT be modified after the pass
/// has been initialized.
ModuleOp transformModule;
};
} // namespace
17 changes: 17 additions & 0 deletions mlir/test/Dialect/Transform/interpreter-entry-point.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: mlir-opt %s -transform-interpreter=entry-point=entry_point \
// RUN: -split-input-file -verify-diagnostics

module attributes { transform.with_named_sequence } {
transform.named_sequence @entry_point(!transform.any_op {transform.readonly}) {
^bb0(%arg0: !transform.any_op):
// expected-remark @below {{applying transformation}}
transform.test_transform_op
transform.yield
}

transform.named_sequence @__transform_main(!transform.any_op {transform.readonly}) {
^bb0(%arg0: !transform.any_op):
transform.test_transform_op // Note: does not yield remark.
transform.yield
}
}
17 changes: 17 additions & 0 deletions mlir/test/Dialect/Transform/interpreter.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: mlir-opt %s -transform-interpreter \
// RUN: -split-input-file -verify-diagnostics

module attributes { transform.with_named_sequence } {
transform.named_sequence @__transform_main(!transform.any_op {transform.readonly}) {
^bb0(%arg0: !transform.any_op):
// expected-remark @below {{applying transformation}}
transform.test_transform_op
transform.yield
}

transform.named_sequence @entry_point(!transform.any_op {transform.readonly}) {
^bb0(%arg0: !transform.any_op):
transform.test_transform_op // Note: does not yield remark.
transform.yield
}
}
19 changes: 19 additions & 0 deletions mlir/test/Dialect/Transform/preload-library.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: mlir-opt %s \
// RUN: -transform-preload-library=transform-library-paths=%p%{fs-sep}test-interpreter-library \
// RUN: -transform-interpreter=entry-point=private_helper \
// RUN: -split-input-file -verify-diagnostics

// expected-remark @below {{message}}
module {}

// -----

// Note: no remark here since local entry point takes precedence.
module attributes { transform.with_named_sequence } {
transform.named_sequence @private_helper(!transform.any_op {transform.readonly}) {
^bb0(%arg0: !transform.any_op):
// expected-remark @below {{applying transformation}}
transform.test_transform_op
transform.yield
}
}