Skip to content

Commit 84e869c

Browse files
ezhulenevGoogle-ML-Automation
authored andcommitted
PR #36190: [xla:gpu] Extract Command into a separate target
Imported from GitHub PR #36190 Keep splitting `command_buffer_cmd` into more manageable targets. This is an NFC change, simply moving code into separate build target and updating dependencies. Add `AsyncStartCommand` and `AsyncDoneCommand` to be able to break circular dependency between Command and CommandExecutor (coming next PR). Copybara import of the project: -- 65c6cb5 by Eugene Zhulenev <[email protected]>: [xla:gpu] Extract CommandState into a separate target + improve documentation -- d914208 by Eugene Zhulenev <[email protected]>: [xla:gpu] CommandExecutor: Correctly split RecordCreate from RecordUpdate and cleanup public facing Record API -- 7cc56e5 by Eugene Zhulenev <[email protected]>: fix BUILD -- c76bbff by Eugene Zhulenev <[email protected]>: [xla:gpu] Extract Command into a separate target Merging this change closes #36190 COPYBARA_INTEGRATE_REVIEW=#36190 from ezhulenev:command-split-3 c76bbff PiperOrigin-RevId: 855161008
1 parent 9c7af86 commit 84e869c

13 files changed

+581
-453
lines changed

xla/backends/gpu/profiler/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ xla_test(
7373
],
7474
deps = [
7575
":kernel_name_tracer",
76+
"//xla/backends/gpu/runtime:command",
7677
"//xla/backends/gpu/runtime:command_buffer_cmd",
7778
"//xla/backends/gpu/runtime:command_buffer_thunk",
7879
"//xla/backends/gpu/runtime:thunk",

xla/backends/gpu/profiler/kernel_name_tracer_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ limitations under the License.
2929
#include "absl/status/statusor.h"
3030
#include "absl/strings/ascii.h"
3131
#include "absl/strings/string_view.h"
32+
#include "xla/backends/gpu/runtime/command.h"
3233
#include "xla/backends/gpu/runtime/command_buffer_cmd.h"
3334
#include "xla/backends/gpu/runtime/command_buffer_thunk.h"
3435
#include "xla/backends/gpu/runtime/thunk.h"
@@ -155,7 +156,7 @@ void LaunchCommandBufferThunk(stream_executor::StreamExecutor* executor,
155156
BufferUse::MemoryAccess::kWrite};
156157

157158
// Prepare commands sequence for constructing command buffer.
158-
CommandBufferCmdSequence commands;
159+
CommandSequence commands;
159160
commands.Emplace<LaunchCmd>("AddI32", args, args_access,
160161
LaunchDimensions(1, kLength),
161162
/*shmem_bytes=*/0);

xla/backends/gpu/runtime/BUILD

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ xla_cc_test(
8080
],
8181
)
8282

83+
cc_library(
84+
name = "command",
85+
srcs = ["command.cc"],
86+
hdrs = ["command.h"],
87+
deps = [
88+
":command_state",
89+
":thunk",
90+
"//xla/runtime:buffer_use",
91+
"//xla/runtime:resource_use",
92+
"//xla/stream_executor:command_buffer",
93+
],
94+
)
95+
8396
cc_library(
8497
name = "command_buffer_cmd",
8598
srcs = ["command_buffer_cmd.cc"],
@@ -93,6 +106,7 @@ cc_library(
93106
":collective_execution",
94107
":collective_permute_thunk",
95108
":collective_thunk",
109+
":command",
96110
":command_state",
97111
":copy_thunk",
98112
":custom_call_thunk",
@@ -164,7 +178,6 @@ cc_library(
164178
"@com_google_absl//absl/strings:str_format",
165179
"@com_google_absl//absl/synchronization",
166180
"@com_google_absl//absl/types:span",
167-
"@llvm-project//llvm:Support",
168181
"@tsl//tsl/profiler/lib:scoped_annotation",
169182
],
170183
)
@@ -174,6 +187,7 @@ xla_test(
174187
srcs = ["command_buffer_cmd_test.cc"],
175188
backends = ["gpu"],
176189
deps = [
190+
":command",
177191
":command_buffer_cmd",
178192
":command_state",
179193
":copy_thunk",
@@ -221,6 +235,7 @@ cc_library(
221235
":collective_broadcast_thunk",
222236
":collective_permute_thunk",
223237
":collective_thunk",
238+
":command",
224239
":command_buffer_cmd",
225240
":command_state",
226241
":conditional_thunk",
@@ -354,6 +369,7 @@ cc_library(
354369
srcs = ["command_buffer_thunk.cc"],
355370
hdrs = ["command_buffer_thunk.h"],
356371
deps = [
372+
":command",
357373
":command_buffer_cmd",
358374
":command_state",
359375
":sequential_thunk", # build_cleaner: keep
@@ -385,6 +401,7 @@ xla_test(
385401
srcs = ["command_buffer_thunk_test.cc"],
386402
backends = ["gpu"],
387403
deps = [
404+
":command",
388405
":command_buffer_cmd",
389406
":command_buffer_thunk",
390407
":dynamic_slice_thunk",
@@ -436,6 +453,7 @@ xla_test(
436453
backends = ["gpu"],
437454
tags = ["cuda-only"],
438455
deps = [
456+
":command",
439457
":command_buffer_cmd",
440458
":command_buffer_thunk",
441459
":thunk",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Copyright 2026 The OpenXLA Authors.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
#include "xla/backends/gpu/runtime/command.h"
17+
18+
#include <string>
19+
20+
namespace xla::gpu {
21+
22+
std::string CommandTypeString(CommandType type) {
23+
switch (type) {
24+
#define CASE_CMD_STRING(enum_name, cmd_name, ...) \
25+
case CommandType::enum_name: \
26+
return cmd_name;
27+
XLA_GPU_COMMAND_LIST(CASE_CMD_STRING)
28+
#undef CASE_CMD_STRING
29+
}
30+
}
31+
32+
bool IsCollectiveCommand(CommandType type) {
33+
switch (type) {
34+
case CommandType::kAllGatherCmd:
35+
case CommandType::kAllReduceCmd:
36+
case CommandType::kAllToAllCmd:
37+
case CommandType::kReduceScatterCmd:
38+
case CommandType::kCollectiveBroadcastCmd:
39+
case CommandType::kCollectivePermuteCmd:
40+
return true;
41+
default:
42+
return false;
43+
}
44+
}
45+
46+
} // namespace xla::gpu

0 commit comments

Comments
 (0)