-
Notifications
You must be signed in to change notification settings - Fork 74.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve HloModuleConfig in HLO<->MHLO.
PiperOrigin-RevId: 642016412
- Loading branch information
1 parent
705c22d
commit 6312122
Showing
14 changed files
with
300 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
third_party/xla/xla/translate/hlo_to_mhlo/module_config_importer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* Copyright 2019 The OpenXLA Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include "xla/translate/hlo_to_mhlo/module_config_importer.h" | ||
|
||
#include "mlir/IR/Builders.h" // from @llvm-project | ||
#include "mlir/IR/BuiltinOps.h" // from @llvm-project | ||
#include "xla/service/hlo_module_config.h" | ||
|
||
namespace xla { | ||
|
||
namespace { | ||
|
||
constexpr char kConfigNumPartitions[] = "mhlo.num_partitions"; | ||
constexpr char kConfigNumReplicas[] = "mhlo.num_replicas"; | ||
|
||
} // namespace | ||
|
||
void ImportHloModuleConfig(const HloModuleConfig& config, | ||
mlir::ModuleOp module) { | ||
mlir::Builder builder(module.getContext()); | ||
if (config.num_partitions() != 1) { | ||
module->setAttr(kConfigNumPartitions, | ||
builder.getI32IntegerAttr(config.num_partitions())); | ||
} | ||
if (config.replica_count() != 1) { | ||
module->setAttr(kConfigNumReplicas, | ||
builder.getI32IntegerAttr(config.replica_count())); | ||
} | ||
} | ||
|
||
} // namespace xla |
30 changes: 30 additions & 0 deletions
30
third_party/xla/xla/translate/hlo_to_mhlo/module_config_importer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Copyright 2024 The OpenXLA Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#ifndef XLA_TRANSLATE_HLO_TO_MHLO_MODULE_CONFIG_IMPORTER_H_ | ||
#define XLA_TRANSLATE_HLO_TO_MHLO_MODULE_CONFIG_IMPORTER_H_ | ||
|
||
#include "mlir/IR/BuiltinOps.h" // from @llvm-project | ||
#include "xla/service/hlo_module_config.h" | ||
|
||
namespace xla { | ||
// Imports the HLO module config into the MLIR module as module attributes | ||
// prefixed with `mhlo.`. | ||
// TODO (b/345755258) Support roundtrip of all HLO module config fields. | ||
void ImportHloModuleConfig(const xla::HloModuleConfig& config, | ||
mlir::ModuleOp module); | ||
} // namespace xla | ||
|
||
#endif // XLA_TRANSLATE_HLO_TO_MHLO_MODULE_CONFIG_IMPORTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
third_party/xla/xla/translate/hlo_to_mhlo/tests/module_config.hlo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: xla-translate --print-sugar=false -hlo-text-to-mlir-hlo -hlo-import-all-computations %s -o - | FileCheck %s | ||
|
||
// CHECK: module @check_imported_configs attributes {{.*}} mhlo.num_partitions = 4 : i32, mhlo.num_replicas = 2 : i32 | ||
HloModule check_imported_configs, replica_count=2, num_partitions=4 | ||
|
||
ENTRY %main.2 (Arg_0.1: f32[1]) -> f32[1] { | ||
ROOT %Arg_0.1 = f32[1] parameter(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.