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

Fix bad error message when PjRtComputationClient throws exception #5946

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
23 changes: 11 additions & 12 deletions torch_xla/csrc/runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,37 @@ namespace torch_xla {
namespace runtime {
namespace {

std::atomic<bool> g_computation_client_initialized(false);

ComputationClient* CreateClient() {
bool was_initialized = g_computation_client_initialized.exchange(true);
XLA_CHECK(!was_initialized) << "ComputationClient already initialized";
std::unique_ptr<ComputationClient> CreateClient() {
if (sys_util::GetEnvBool("XLA_DUMP_FATAL_STACK", false)) {
tsl::testing::InstallStacktraceHandler();
}

ComputationClient* client;
std::unique_ptr<ComputationClient> client = nullptr;

if (sys_util::GetEnvString(env::kEnvPjRtDevice, "") != "") {
client = new PjRtComputationClient();
client = std::make_unique<PjRtComputationClient>();
} else {
g_computation_client_initialized = false;
will-cromar marked this conversation as resolved.
Show resolved Hide resolved
XLA_ERROR() << "$PJRT_DEVICE is not set." << std::endl;
}

XLA_CHECK(client != nullptr);
XLA_CHECK(client);

return client;
}

} // namespace

ComputationClient* GetComputationClient() {
static auto client = std::unique_ptr<ComputationClient>(CreateClient());
ComputationClient* GetComputationClient(bool create) {
static std::unique_ptr<ComputationClient> client = nullptr;
if (!client && create) {
static std::once_flag flag;
std::call_once(flag, []() { client = CreateClient(); });
}
return client.get();
}

ComputationClient* GetComputationClientIfInitialized() {
return g_computation_client_initialized ? GetComputationClient() : nullptr;
return GetComputationClient(/*create=*/false);
}

} // namespace runtime
Expand Down
2 changes: 1 addition & 1 deletion torch_xla/csrc/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace torch_xla {
namespace runtime {

// Returns the ComputationClient singleton.
ComputationClient* GetComputationClient();
ComputationClient* GetComputationClient(bool create = true);

ComputationClient* GetComputationClientIfInitialized();

Expand Down
Loading