Skip to content

Commit 0a8cce2

Browse files
akuegeltensorflower-gardener
authored andcommitted
Migrate from CanShareBuffer hook to AliasInfo.
PiperOrigin-RevId: 780895093
1 parent 38e3226 commit 0a8cce2

8 files changed

Lines changed: 40 additions & 28 deletions

File tree

third_party/xla/xla/service/buffer_assignment.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ BuildIdToLogicalBufferMap(
9797
const BufferAssignmentProto& proto,
9898
const absl::flat_hash_map<int64_t, const HloInstruction*>&
9999
id_to_hlo_instruction,
100-
const std::unique_ptr<HloAliasAnalysis>& alias_analysis) {
100+
HloDataflowAnalysis& dataflow_analysis) {
101101
absl::flat_hash_map<int64_t, const HloValue*> id_to_logical_buffer;
102102
// Process each logical buffer in the proto.
103103
for (const LogicalBufferProto& logical_buffer_proto :
@@ -122,8 +122,8 @@ BuildIdToLogicalBufferMap(
122122
ShapeIndex proto_shape_index(shape_idx_vals);
123123

124124
// Look up logical buffer by hlo instruction and shape index.
125-
auto& logical_buffer = alias_analysis->dataflow_analysis().GetUniqueValueAt(
126-
hlo_instruction, proto_shape_index);
125+
auto& logical_buffer =
126+
dataflow_analysis.GetUniqueValueAt(hlo_instruction, proto_shape_index);
127127

128128
// Assign color to a logical buffer from the proto.
129129
logical_buffer.set_color(logical_buffer_proto.color());
@@ -1221,11 +1221,10 @@ BufferAssignmentProto BufferAssignment::ToProto() const {
12211221
/* static */
12221222
absl::StatusOr<std::unique_ptr<BufferAssignment>> BufferAssignment::FromProto(
12231223
const BufferAssignmentProto& proto, const HloModule* module,
1224-
BufferValue::SizeFunction buffer_size,
1225-
HloDataflowAnalysis::CanShareBuffer can_share_buffer) {
1224+
BufferValue::SizeFunction buffer_size, const AliasInfo* alias_info) {
12261225
// Create alias and dataflow analysis.
12271226
TF_ASSIGN_OR_RETURN(std::unique_ptr<HloAliasAnalysis> alias_analysis,
1228-
HloAliasAnalysis::Run(module, can_share_buffer));
1227+
HloAliasAnalysis::Run(module, alias_info));
12291228

12301229
// Build a map from a unique_id to corresponding HloInstruction in the module.
12311230
auto id_to_hlo_instruction = BuildIdToHloInstructionMap(module);
@@ -1235,7 +1234,8 @@ absl::StatusOr<std::unique_ptr<BufferAssignment>> BufferAssignment::FromProto(
12351234
absl::flat_hash_map<int64_t, const HloValue*> id_to_logical_buffer;
12361235
TF_ASSIGN_OR_RETURN(
12371236
id_to_logical_buffer,
1238-
BuildIdToLogicalBufferMap(proto, id_to_hlo_instruction, alias_analysis));
1237+
BuildIdToLogicalBufferMap(proto, id_to_hlo_instruction,
1238+
alias_analysis->dataflow_analysis()));
12391239

12401240
std::unique_ptr<BufferAssignment> buffer_assignment =
12411241
absl::WrapUnique(new BufferAssignment(

third_party/xla/xla/service/buffer_assignment.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,7 @@ class BufferAssignment {
525525
BufferAssignmentProto ToProto() const;
526526
static absl::StatusOr<std::unique_ptr<BufferAssignment>> FromProto(
527527
const BufferAssignmentProto& proto, const HloModule* module,
528-
BufferValue::SizeFunction buffer_size,
529-
HloDataflowAnalysis::CanShareBuffer can_share_buffer);
528+
BufferValue::SizeFunction buffer_size, const AliasInfo* alias_info);
530529

531530
// Returns string representation of buffer assignment statistics. Also
532531
// calculates and returns the total fragmentation.

third_party/xla/xla/service/buffer_assignment_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class BufferAssignmentTest : public HloHardwareIndependentTestBase {
132132
auto proto = buffers->ToProto();
133133
// Recreate buffer assignment from proto.
134134
return BufferAssignment::FromProto(proto, module, &BufferSizeBytes,
135-
/*can_share_buffer=*/nullptr);
135+
&alias_info_);
136136
}
137137

138138
std::unique_ptr<BufferAssignment> RunBufferAssignmentWithSequentialOrdering(

third_party/xla/xla/service/cpu/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ cc_library(
425425
"//xla/backends/cpu/runtime:thunk",
426426
"//xla/backends/cpu/runtime:thunk_proto_cc",
427427
"//xla/backends/cpu/runtime:thunk_proto_serdes",
428+
"//xla/hlo/analysis:alias_info",
428429
"//xla/hlo/ir:hlo",
429430
"//xla/service:buffer_assignment",
430431
"//xla/service:buffer_value",

third_party/xla/xla/service/cpu/cpu_aot_compilation_result.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ limitations under the License.
3535
#include "xla/backends/cpu/runtime/thunk.pb.h"
3636
#include "xla/backends/cpu/runtime/thunk_proto_serdes.h"
3737
#include "xla/cpu_function_runtime.h"
38+
#include "xla/hlo/analysis/alias_info.h"
3839
#include "xla/hlo/ir/hlo_module.h"
3940
#include "xla/hlo/ir/hlo_schedule.h"
4041
#include "xla/service/buffer_assignment.h"
@@ -187,11 +188,11 @@ CpuAotCompilationResultThunks::LoadExecutable(
187188
}();
188189

189190
// Recreate BufferAssignment from proto.
190-
TF_ASSIGN_OR_RETURN(
191-
std::unique_ptr<BufferAssignment> buffer_assignment,
192-
BufferAssignment::FromProto(proto_.buffer_assignment(), module.get(),
193-
buffer_size_bytes_function_getter,
194-
/*can_share_buffer=*/nullptr));
191+
AliasInfo alias_info;
192+
TF_ASSIGN_OR_RETURN(std::unique_ptr<BufferAssignment> buffer_assignment,
193+
BufferAssignment::FromProto(
194+
proto_.buffer_assignment(), module.get(),
195+
buffer_size_bytes_function_getter, &alias_info));
195196

196197
std::unique_ptr<CpuExecutable> cpu_executable;
197198

third_party/xla/xla/service/cpu/cpu_compiler.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,11 +2557,11 @@ CpuExecutableAotCompilationResult::LoadExecutable(
25572557
VLOG(2) << "Load XLA:CPU executable for module: " << module->name();
25582558

25592559
// Recreate BufferAssignment from proto.
2560-
TF_ASSIGN_OR_RETURN(
2561-
std::unique_ptr<BufferAssignment> buffer_assignment,
2562-
BufferAssignment::FromProto(proto_.buffer_assignment(), module.get(),
2563-
compiler->BufferSizeBytesFunction(),
2564-
/*can_share_buffer=*/nullptr));
2560+
AliasInfo alias_info;
2561+
TF_ASSIGN_OR_RETURN(std::unique_ptr<BufferAssignment> buffer_assignment,
2562+
BufferAssignment::FromProto(
2563+
proto_.buffer_assignment(), module.get(),
2564+
compiler->BufferSizeBytesFunction(), &alias_info));
25652565

25662566
const DebugOptions& debug_options = module->config().debug_options();
25672567
VlogMaxIsa(debug_options.xla_cpu_max_isa());

third_party/xla/xla/service/gpu/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ cc_library(
14651465
"//xla/backends/gpu/codegen/triton:support",
14661466
"//xla/backends/gpu/runtime:sequential_thunk",
14671467
"//xla/backends/gpu/runtime:thunk",
1468+
"//xla/hlo/analysis:alias_info",
14681469
"//xla/hlo/analysis:hlo_dataflow_analysis",
14691470
"//xla/hlo/analysis:hlo_ordering",
14701471
"//xla/hlo/ir:hlo",

third_party/xla/xla/service/gpu/gpu_compiler.cc

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ limitations under the License.
6363
#include "mlir/Support/LLVM.h"
6464
#include "xla/backends/gpu/codegen/triton/support.h"
6565
#include "xla/backends/gpu/runtime/sequential_thunk.h"
66+
#include "xla/hlo/analysis/alias_info.h"
6667
#include "xla/hlo/analysis/hlo_dataflow_analysis.h"
6768
#include "xla/hlo/ir/hlo_casting_utils.h"
6869
#include "xla/hlo/ir/hlo_computation.h"
@@ -430,9 +431,14 @@ GpuThunkAotCompilationResult::buffer_assignment() const {
430431
};
431432

432433
// Recreate BufferAssignment from proto.
434+
// Technically, we should pass the proper GpuAliasInfo, but the FromProto()
435+
// method does not actually make use of the MayAlias function. And for now, we
436+
// don't have backend-specific MustAlias rules.
437+
// TODO(b/424109294): This needs to be fixed when we implement
438+
// backend-specific MustAlias rules.
439+
AliasInfo alias_info;
433440
return BufferAssignment::FromProto(proto_.buffer_assignment(), module_.get(),
434-
buffer_size_bytes_function,
435-
/*can_share_buffer=*/nullptr);
441+
buffer_size_bytes_function, &alias_info);
436442
}
437443

438444
absl::StatusOr<std::unique_ptr<Executable>>
@@ -444,12 +450,6 @@ GpuThunkAotCompilationResult::LoadExecutable(
444450
std::unique_ptr<HloModule> hlo_module,
445451
HloModule::CreateFromProtoWithConfig(proto_.hlo_module_with_config()));
446452

447-
// Recreate BufferAssignment from proto.
448-
TF_ASSIGN_OR_RETURN(
449-
std::unique_ptr<BufferAssignment> buffer_assignment,
450-
BufferAssignment::FromProto(proto_.buffer_assignment(), hlo_module.get(),
451-
compiler->BufferSizeBytesFunction(),
452-
/*can_share_buffer=*/nullptr));
453453

454454
ExecutionStreamAssignment execution_stream_assignment(hlo_module.get());
455455

@@ -472,6 +472,16 @@ GpuThunkAotCompilationResult::LoadExecutable(
472472
auto llvm_module = std::make_unique<llvm::Module>("", llvm_context);
473473
llvm_module->setTargetTriple(llvm::Triple(gpu_compiler->target_triple()));
474474
llvm_module->setDataLayout(gpu_compiler->data_layout());
475+
476+
// Recreate BufferAssignment from proto.
477+
std::unique_ptr<GpuAliasInfo> alias_info =
478+
gpu_compiler->GetAliasInfo(gpu_device_info);
479+
TF_ASSIGN_OR_RETURN(
480+
std::unique_ptr<BufferAssignment> buffer_assignment,
481+
BufferAssignment::FromProto(proto_.buffer_assignment(), hlo_module.get(),
482+
compiler->BufferSizeBytesFunction(),
483+
alias_info.get()));
484+
475485
IrEmitterContext ir_emitter_context(
476486
hlo_module.get(), buffer_assignment.get(), &execution_stream_assignment,
477487
platform_name, gpu_device_info, mlir_context.get(), llvm_module.get(),

0 commit comments

Comments
 (0)