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

Propagating frontend attributes from call operation to the callee with respect to the fusion attributes. #17672

Merged
merged 1 commit into from
Oct 3, 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 xla/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,7 @@ cc_library(
":hlo_domain_isolator",
"//xla:status_macros",
"//xla:util",
"//xla:xla_data_proto_cc",
"//xla/hlo/ir:hlo",
"//xla/hlo/pass:hlo_pass",
"@com_google_absl//absl/container:flat_hash_map",
Expand Down
25 changes: 25 additions & 0 deletions xla/service/call_inliner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
#include "xla/service/call_inliner.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

Expand All @@ -34,6 +35,7 @@ limitations under the License.
#include "xla/service/hlo_domain_isolator.h"
#include "xla/status_macros.h"
#include "xla/util.h"
#include "xla/xla_data.pb.h"
#include "tsl/platform/errors.h"
#include "tsl/platform/statusor.h"

Expand Down Expand Up @@ -152,6 +154,29 @@ CallInliner::Inline(HloInstruction* call) {
const auto& callees = call->called_computations();
TF_RET_CHECK(callees.size() == 1);
HloComputation* callee = callees[0];

// Propagate the frontend attributes related to fusion from the call to the
// inlined instructions.
if (call->has_frontend_attributes()) {
const FrontendAttributes& call_attributes = call->frontend_attributes();
std::string has_fuse =
call_attributes.map().contains("MUST_FUSE") ? "MUST_FUSE"
: call_attributes.map().contains("MAXIMAL_FUSE") ? "MAXIMAL_FUSE"
: "";
if (!has_fuse.empty()) {
for (auto instruction : callee->instructions()) {
// Do so for only fusible instructions.
if (instruction->IsFusible()) {
FrontendAttributes frontend_attributes =
instruction->frontend_attributes();
frontend_attributes.mutable_map()->insert(
{has_fuse, call_attributes.map().at(has_fuse)});
instruction->set_frontend_attributes(frontend_attributes);
}
}
}
}

// We visit the callee, cloning its body into its caller.
SubcomputationInsertionVisitor visitor(call);
TF_RETURN_IF_ERROR(callee->Accept(&visitor));
Expand Down
Loading