Skip to content

Commit 97a02ea

Browse files
loisloGoogle-ML-Automation
authored andcommitted
[XLA:GPU] Fix usages of deprecated tsl::errors::AlreadyExists in xla
This change replaces usages of tsl::errors::AlreadyExists with absl::AlreadyExistsError, wrapping arguments in absl::StrCat where necessary. This addresses deprecation warnings and moves towards standard Abseil error handling. Changes: - Replaced errors::AlreadyExists with absl::AlreadyExistsError. - Used absl::StrCat to construct error messages where necessary. PiperOrigin-RevId: 837128775
1 parent 8f81cfb commit 97a02ea

File tree

9 files changed

+67
-20
lines changed

9 files changed

+67
-20
lines changed

xla/tsl/framework/device_id_manager.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ class TfToPlatformDeviceIdMap {
5555
{tf_device_id.value(), platform_device_id.value()});
5656
}
5757
if (!result.second && platform_device_id.value() != result.first->second) {
58-
return errors::AlreadyExists(
59-
"TensorFlow device (", type, ":", tf_device_id.value(),
58+
return absl::AlreadyExistsError(absl::StrCat(
59+
"TensorFlow device (", type.type_string(), ":", tf_device_id.value(),
6060
") is being mapped to multiple devices (", platform_device_id.value(),
6161
" now, and ", result.first->second,
6262
" previously), which is not supported. "
6363
"This may be the result of providing different ",
64-
type, " configurations (ConfigProto.gpu_options, for example ",
64+
type.type_string(),
65+
" configurations (ConfigProto.gpu_options, for example ",
6566
"different visible_device_list) when creating multiple Sessions in ",
6667
"the same process. This is not currently supported, see ",
67-
"https://github.com/tensorflow/tensorflow/issues/19083");
68+
"https://github.com/tensorflow/tensorflow/issues/19083"));
6869
}
6970
return absl::OkStatus();
7071
}

xla/tsl/platform/cloud/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ cc_library(
130130
"//xla/tsl/platform:status",
131131
"//xla/tsl/platform:types",
132132
"@com_google_absl//absl/base:core_headers",
133+
"@com_google_absl//absl/log",
134+
"@com_google_absl//absl/log:check",
133135
"@com_google_absl//absl/status",
134136
"@com_google_absl//absl/strings",
135137
"@com_google_absl//absl/synchronization",
136138
"@com_google_absl//absl/time",
139+
"@com_google_absl//absl/types:span",
137140
"@jsoncpp_git//:jsoncpp",
138141
"@tsl//tsl/platform:numbers",
139142
"@tsl//tsl/platform:path",
@@ -176,10 +179,13 @@ cc_library(
176179
"//xla/tsl/platform:status",
177180
"//xla/tsl/platform:types",
178181
"@com_google_absl//absl/base:core_headers",
182+
"@com_google_absl//absl/log",
183+
"@com_google_absl//absl/log:check",
179184
"@com_google_absl//absl/status",
180185
"@com_google_absl//absl/strings",
181186
"@com_google_absl//absl/synchronization",
182187
"@com_google_absl//absl/time",
188+
"@com_google_absl//absl/types:span",
183189
"@jsoncpp_git//:jsoncpp",
184190
"@tsl//tsl/platform:numbers",
185191
"@tsl//tsl/platform:path",

xla/tsl/platform/cloud/gcs_file_system.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,40 @@ limitations under the License.
1717

1818
#include <stdio.h>
1919

20+
#include <cstdint>
21+
#include <iosfwd>
22+
#include <limits>
2023
#include <memory>
24+
#include <set>
25+
#include <unordered_set>
2126

27+
#include "absl/base/attributes.h"
28+
#include "absl/log/check.h"
29+
#include "absl/log/log.h"
2230
#include "absl/status/status.h"
31+
#include "absl/strings/ascii.h"
32+
#include "absl/strings/match.h"
33+
#include "absl/strings/numbers.h"
2334
#include "absl/strings/str_cat.h"
35+
#include "absl/strings/str_join.h"
36+
#include "absl/strings/str_split.h"
37+
#include "absl/strings/string_view.h"
38+
#include "absl/strings/strip.h"
2439
#include "absl/synchronization/mutex.h"
2540
#include "absl/time/clock.h"
2641
#include "absl/time/time.h"
42+
#include "absl/types/span.h"
43+
#include "xla/tsl/platform/cloud/auth_provider.h"
44+
#include "xla/tsl/platform/cloud/compute_engine_metadata_client.h"
45+
#include "xla/tsl/platform/cloud/compute_engine_zone_provider.h"
46+
#include "xla/tsl/platform/cloud/expiring_lru_cache.h"
47+
#include "xla/tsl/platform/cloud/gcs_dns_cache.h"
48+
#include "xla/tsl/platform/cloud/gcs_throttle.h"
49+
#include "xla/tsl/platform/cloud/http_request.h"
50+
#include "xla/tsl/platform/cloud/zone_provider.h"
51+
#include "xla/tsl/platform/file_system.h"
52+
#include "xla/tsl/platform/status.h"
53+
#include "xla/tsl/platform/types.h"
2754
#include "tsl/platform/retrying_file_system.h"
2855

2956
#ifndef _WIN32
@@ -1986,7 +2013,7 @@ absl::Status GcsFileSystem::CreateDir(const string& dirname,
19862013
if (FileExists(dirname_with_slash, token).ok()) {
19872014
// Use the original name for a correct error here.
19882015
VLOG(3) << "CreateDir: directory already exists, not uploading " << dirname;
1989-
return errors::AlreadyExists(dirname);
2016+
return absl::AlreadyExistsError(dirname);
19902017
}
19912018

19922019
std::unique_ptr<HttpRequest> request;

xla/tsl/platform/cloud/gcs_file_system_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,11 +3622,11 @@ TEST(GcsFileSystemTest, CreateDir_Folder) {
36223622
TF_EXPECT_OK(fs.CreateDir("gs://bucket/subpath", nullptr));
36233623
// Check that when GCS returns the object already exists return that the
36243624
// directory already exists.
3625-
EXPECT_EQ(errors::AlreadyExists("gs://bucket/subpath"),
3625+
EXPECT_EQ(absl::AlreadyExistsError("gs://bucket/subpath"),
36263626
fs.CreateDir("gs://bucket/subpath", nullptr));
36273627
// Check that when GCS returns the object already has a version (failed
36283628
// precondition) return directory already exists.
3629-
EXPECT_EQ(errors::AlreadyExists("gs://bucket/subpath"),
3629+
EXPECT_EQ(absl::AlreadyExistsError("gs://bucket/subpath"),
36303630
fs.CreateDir("gs://bucket/subpath", nullptr));
36313631
}
36323632

xla/tsl/platform/default/BUILD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,15 @@ cc_library(
164164
"@com_google_absl//absl/base:core_headers",
165165
"@com_google_absl//absl/base:nullability",
166166
"@com_google_absl//absl/functional:any_invocable",
167+
"@com_google_absl//absl/log:check",
167168
"@com_google_absl//absl/status",
168169
"@com_google_absl//absl/strings",
169170
"@com_google_absl//absl/strings:cord",
170171
"@com_google_absl//absl/strings:str_format",
171172
"@com_google_absl//absl/synchronization",
172173
"@com_google_absl//absl/types:span",
174+
"@com_google_protobuf//:protobuf",
175+
"@com_google_protobuf//:protobuf_lite",
173176
"@eigen_archive//:eigen3",
174177
"@tsl//tsl/platform",
175178
"@tsl//tsl/platform:blocking_counter",
@@ -185,7 +188,6 @@ cc_library(
185188
"@tsl//tsl/platform:str_util",
186189
"@tsl//tsl/platform:strcat",
187190
"@tsl//tsl/platform:stringpiece",
188-
"@tsl//tsl/platform:stringprintf",
189191
"@tsl//tsl/platform:thread_annotations",
190192
"@tsl//tsl/platform:tracing",
191193
],

xla/tsl/platform/default/posix_file_system.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ absl::Status PosixFileSystem::CreateDir(const std::string& name,
349349
TransactionToken* token) {
350350
std::string translated = TranslateName(name);
351351
if (translated.empty()) {
352-
return errors::AlreadyExists(name);
352+
return absl::AlreadyExistsError(name);
353353
}
354354
if (mkdir(translated.c_str(), 0755) != 0) {
355355
return IOError(name, errno);

xla/tsl/platform/env.cc

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,30 @@ limitations under the License.
1818
#include <sys/stat.h>
1919

2020
#include <cstdint>
21-
#include <deque>
21+
#include <cstdio>
22+
#include <memory>
23+
#include <string>
24+
#include <unordered_map>
2225
#include <utility>
2326
#include <vector>
2427

28+
#include "absl/log/check.h"
29+
#include "absl/status/status.h"
30+
#include "absl/strings/str_cat.h"
2531
#include "absl/strings/str_format.h"
32+
#include "absl/strings/string_view.h"
2633
#include "absl/synchronization/mutex.h"
27-
#include "xla/tsl/platform/env_time.h"
34+
#include "absl/types/span.h"
35+
#include "google/protobuf/io/coded_stream.h"
36+
#include "google/protobuf/io/zero_copy_stream.h"
37+
#include "google/protobuf/message.h"
38+
#include "google/protobuf/message_lite.h"
39+
#include "google/protobuf/text_format.h"
2840
#include "xla/tsl/platform/errors.h"
41+
#include "xla/tsl/platform/file_statistics.h"
42+
#include "xla/tsl/platform/file_system.h"
2943
#include "tsl/platform/host_info.h"
3044
#include "tsl/platform/path.h"
31-
#include "tsl/platform/platform.h"
32-
#include "tsl/platform/protobuf.h"
33-
#include "tsl/platform/stringprintf.h"
3445
#include "tsl/platform/thread_annotations.h"
3546

3647
#if defined(__APPLE__)
@@ -77,8 +88,8 @@ absl::Status FileSystemRegistryImpl::Register(
7788
absl::MutexLock lock(mu_);
7889
if (!registry_.emplace(scheme, std::unique_ptr<FileSystem>(factory()))
7990
.second) {
80-
return errors::AlreadyExists("File factory for ", scheme,
81-
" already registered");
91+
return absl::AlreadyExistsError(
92+
absl::StrCat("File factory for ", scheme, " already registered"));
8293
}
8394
return absl::OkStatus();
8495
}
@@ -87,8 +98,8 @@ absl::Status FileSystemRegistryImpl::Register(
8798
const std::string& scheme, std::unique_ptr<FileSystem> filesystem) {
8899
absl::MutexLock lock(mu_);
89100
if (!registry_.emplace(scheme, std::move(filesystem)).second) {
90-
return errors::AlreadyExists("File system for ", scheme,
91-
" already registered");
101+
return absl::AlreadyExistsError(
102+
absl::StrCat("File system for ", scheme, " already registered"));
92103
}
93104
return absl::OkStatus();
94105
}

xla/tsl/platform/ram_file_system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class RamFileSystem : public FileSystem {
263263

264264
auto it = fs_.find(dirname);
265265
if (it != fs_.end() && it->second != nullptr) {
266-
return errors::AlreadyExists(
266+
return absl::AlreadyExistsError(
267267
"cannot create directory with same name as an existing file");
268268
}
269269

xla/tsl/platform/windows/windows_file_system.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ Status WindowsFileSystem::CreateDir(const string& name,
594594
Status result;
595595
std::wstring ws_name = Utf8ToWideChar(name);
596596
if (ws_name.empty()) {
597-
return errors::AlreadyExists(name);
597+
return absl::AlreadyExistsError(name);
598598
}
599599
if (_wmkdir(ws_name.c_str()) != 0) {
600600
result = IOError("Failed to create a directory: " + name, errno);

0 commit comments

Comments
 (0)