Skip to content

Commit 9cf650f

Browse files
committed
Use TFRT CPU client and make parameters modifiable through environment variables.
1 parent dd88cc5 commit 9cf650f

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

third_party/xla_client/env_vars.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const char* const kEnvTpuvmMode = "TPUVM_MODE";
2020
const char* const kEnvPjRtDevice = "PJRT_DEVICE";
2121
const char* const kEnvPjRtTpuMaxInflightComputations =
2222
"PJRT_TPU_MAX_INFLIGHT_COMPUTATIONS";
23+
const char* const kEnvAsyncCpuClient = "CPU_ASYNC_CLIENT";
2324

2425
} // namespace env
2526
} // namespace xla

third_party/xla_client/env_vars.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern const char* const kEnvStartService;
2020
extern const char* const kEnvTpuvmMode;
2121
extern const char* const kEnvPjRtDevice;
2222
extern const char* const kEnvPjRtTpuMaxInflightComputations;
23+
extern const char* const kEnvAsyncCpuClient;
2324

2425
} // namespace env
2526
} // namespace xla

third_party/xla_client/pjrt_computation_client.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ PjRtComputationClient::PjRtComputationClient() {
4646
std::string device_type = sys_util::GetEnvString(env::kEnvPjRtDevice, "");
4747
if (device_type == "CPU") {
4848
TF_VLOG(1) << "Initializing PjRt CPU client...";
49-
client_ = std::move(xla::GetCpuClient(/*asynchronous=*/false).ValueOrDie());
49+
bool async = sys_util::GetEnvBool(env::kEnvAsyncCpuClient, true);
50+
int cpu_device_count = sys_util::GetEnvInt(env::kEnvNumCpu, 1);
51+
client_ = std::move(xla::GetTfrtCpuClient(async, cpu_device_count).ValueOrDie());
5052
} else if (device_type == "TPU") {
5153
TF_VLOG(1) << "Initializing PjRt TPU client...";
5254
int64_t max_inflight_computations = sys_util::GetEnvInt(

0 commit comments

Comments
 (0)