[TSL] Clean up integral types

Let's migrate to u?int\d+_t types instead of our own bespoke stuff.

PiperOrigin-RevId: 820815523
This commit is contained in:
David Majnemer 2025-10-17 13:45:02 -07:00 committed by TensorFlower Gardener
parent d531cdce30
commit bdb78510d0
12 changed files with 263 additions and 64 deletions

View File

@ -493,7 +493,6 @@ cc_library(
"@local_tsl//tsl/platform:framework_lite_hdrs",
"@local_xla//xla/tsl/framework:numeric_types.h",
"@local_xla//xla/tsl/framework:type_traits.h",
"@local_xla//xla/tsl/platform/default:integral_types.h",
],
visibility = ["//visibility:public"],
deps = [
@ -1537,7 +1536,6 @@ cc_library(
hdrs = [
"//tensorflow/core/platform:tflite_portable_logging_hdrs",
"@local_tsl//tsl/platform:tflite_portable_logging_hdrs",
"@local_xla//xla/tsl/platform/default:integral_types.h",
],
compatible_with = get_compatible_with_portable(),
copts = tf_copts(),

View File

@ -16,7 +16,9 @@ limitations under the License.
#include "tensorflow/core/common_runtime/graph_view.h"
#include <atomic>
#include <cstdint>
#include <deque>
#include <limits>
#include <memory>
#include <string>
#include <unordered_map>
@ -252,9 +254,9 @@ absl::Status GraphView::Initialize(const Graph* g) {
for (const Node* n : g->nodes()) {
if (n->out_edges().size() > kint32max) {
return errors::InvalidArgument(
"The executor cannot handle nodes with more than ", kint32max,
" output edges. Node ", n->name(), " had ", n->out_edges().size(),
" output edges.");
"The executor cannot handle nodes with more than ",
std::numeric_limits<int32_t>::max(), " output edges. Node ",
n->name(), " had ", n->out_edges().size(), " output edges.");
}
total_bytes += NodeItemBytes(n);
}

View File

@ -52,7 +52,6 @@ cc_library(
"//tensorflow/core/lib/gtl:legacy_android_gif_internal_headers",
"//tensorflow/core/platform:gif_internal_hdrs",
"@local_tsl//tsl/platform:gif_internal_hdrs",
"@local_xla//xla/tsl/platform/default:integral_types.h",
],
copts = tf_copts(),
features = ["-layering_check"],

View File

@ -61,7 +61,6 @@ cc_library(
"//tensorflow/core/lib/core:legacy_lib_core_stringpiece_header",
"//tensorflow/core/platform:jpeg_internal_hdrs",
"@local_tsl//tsl/platform:jpeg_internal_hdrs",
"@local_xla//xla/tsl/platform/default:integral_types.h",
],
copts = tf_copts(),
linkopts = if_android(["-ldl"]),

View File

@ -940,6 +940,7 @@ cc_library(
":bfloat16",
":platform",
":tstring",
"@com_google_absl//absl/base:core_headers",
"@local_tsl//tsl/platform:bfloat16",
"@local_tsl//tsl/platform:ml_dtypes",
"@local_tsl//tsl/platform:tstring",

View File

@ -19,32 +19,32 @@ limitations under the License.
#include <cstdint>
#include <string>
#include "absl/base/macros.h"
#include "xla/tsl/platform/types.h"
#include "tensorflow/core/platform/bfloat16.h"
#include "tensorflow/core/platform/platform.h"
#include "tensorflow/core/platform/tstring.h"
#include "tsl/platform/bfloat16.h"
#include "tsl/platform/tstring.h"
#include "tsl/platform/types.h"
namespace tensorflow {
// Alias tensorflow::string to std::string.
using tsl::string;
using string ABSL_DEPRECATE_AND_INLINE() = std::string;
using tsl::uint16;
using tsl::uint2;
using tsl::uint32;
using tsl::uint4;
using tsl::uint64;
using tsl::uint8;
using uint8 ABSL_DEPRECATE_AND_INLINE() = uint8_t;
using uint16 ABSL_DEPRECATE_AND_INLINE() = uint16_t;
using uint32 ABSL_DEPRECATE_AND_INLINE() = uint32_t;
using uint64 ABSL_DEPRECATE_AND_INLINE() = uint64_t;
using tsl::int16;
using tsl::int2;
using tsl::int32;
using tsl::int4;
using tsl::int64;
using tsl::int8;
using int8 ABSL_DEPRECATE_AND_INLINE() = int8_t;
using int16 ABSL_DEPRECATE_AND_INLINE() = int16_t;
using int32 ABSL_DEPRECATE_AND_INLINE() = int32_t;
using int64 ABSL_DEPRECATE_AND_INLINE() = int64_t;
using tsl::float8_e4m3b11fnuz;
using tsl::float8_e4m3fn;
@ -52,18 +52,18 @@ using tsl::float8_e4m3fnuz;
using tsl::float8_e5m2;
using tsl::float8_e5m2fnuz;
static const uint8 kuint8max = tsl::kuint8max;
static const uint16 kuint16max = tsl::kuint16max;
static const uint32 kuint32max = tsl::kuint32max;
static const uint64 kuint64max = tsl::kuint64max;
static const int8_t kint8min = tsl::kint8min;
static const int8_t kint8max = tsl::kint8max;
static const int16_t kint16min = tsl::kint16min;
static const int16_t kint16max = tsl::kint16max;
static const int32_t kint32min = tsl::kint32min;
static const int32_t kint32max = tsl::kint32max;
static const int64_t kint64min = tsl::kint64min;
static const int64_t kint64max = tsl::kint64max;
using tsl::kint16max;
using tsl::kint16min;
using tsl::kint32max;
using tsl::kint32min;
using tsl::kint64max;
using tsl::kint64min;
using tsl::kint8max;
using tsl::kint8min;
using tsl::kuint16max;
using tsl::kuint32max;
using tsl::kuint64max;
using tsl::kuint8max;
// A typedef for a uint64 used as a short fingerprint.
using tsl::bfloat16;

View File

@ -123,6 +123,7 @@ EXPORTS
??0Tensor@tensorflow@@QEAA@XZ
??0TensorFlowDialect@TF@mlir@@QEAA@PEAVMLIRContext@2@@Z
??0VirtualCluster@grappler@tensorflow@@QEAA@AEBV?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VDeviceProperties@tensorflow@@U?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VDeviceProperties@tensorflow@@@std@@@2@@std@@@Z
??0VirtualPlacer@grappler@tensorflow@@QEAA@AEBV?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VDeviceProperties@tensorflow@@U?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VDeviceProperties@tensorflow@@@std@@@2@@std@@@Z
??0WorkerConfig@experimental@data@tensorflow@@IEAA@PEAVArena@protobuf@google@@@Z
??1ApiDefMap@tensorflow@@QEAA@XZ
??1AttrValue@tensorflow@@UEAA@XZ
@ -799,6 +800,8 @@ EXPORTS
?getMemBuffer@MemoryBuffer@llvm@@SA?AV?$unique_ptr@VMemoryBuffer@llvm@@U?$default_delete@VMemoryBuffer@llvm@@@std@@@std@@VStringRef@2@0_N@Z
?getOrLoadDialect@MLIRContext@mlir@@QEAAPEAVDialect@2@VStringRef@llvm@@VTypeID@2@V?$function_ref@$$A6A?AV?$unique_ptr@VDialect@mlir@@U?$default_delete@VDialect@mlir@@@std@@@std@@XZ@5@@Z
?getValuePtr@?$SpecificNodeAccess@U?$node_options@VOperation@mlir@@$0A@$0A@X$0A@X@ilist_detail@llvm@@@ilist_detail@llvm@@KAPEAVOperation@mlir@@PEAV?$ilist_node_impl@U?$node_options@VOperation@mlir@@$0A@$0A@X$0A@X@ilist_detail@llvm@@@3@@Z
?get_canonical_device_name@VirtualPlacer@grappler@tensorflow@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVNodeDef@3@@Z
?get_device@VirtualPlacer@grappler@tensorflow@@QEBAAEBVDeviceProperties@3@AEBVNodeDef@3@@Z
?id@?$TypeIDResolver@VArithDialect@arith@mlir@@X@detail@mlir@@0VSelfOwningTypeID@3@A
?id@?$TypeIDResolver@VFuncDialect@func@mlir@@X@detail@mlir@@0VSelfOwningTypeID@3@A
?id@?$TypeIDResolver@VModuleOp@mlir@@X@detail@mlir@@0VSelfOwningTypeID@3@A

View File

@ -729,6 +729,7 @@ cc_library(
hdrs = ["types.h"],
compatible_with = get_compatible_with_portable(),
deps = [
"@com_google_absl//absl/base:core_headers",
"@local_tsl//tsl/platform",
"@local_tsl//tsl/platform:bfloat16",
"@local_tsl//tsl/platform:ml_dtypes",

View File

@ -298,7 +298,6 @@ filegroup(
name = "xla_cpu_runtime_srcs",
srcs = [
"context.h",
"integral_types.h",
] + if_not_windows(["env_time.cc"]),
)
@ -477,7 +476,6 @@ cc_library(
"no_oss",
"nobuilder",
],
textual_hdrs = ["integral_types.h"],
)
cc_library(
@ -638,7 +636,6 @@ exports_files(
srcs = glob(
["*"],
exclude = [
"integral_types.h",
"test.cc",
],
),
@ -647,7 +644,6 @@ exports_files(
exports_files(
srcs = [
"integral_types.h",
"test.cc",
],
visibility = internal_visibility([

View File

@ -321,7 +321,6 @@ def tf_additional_lib_hdrs():
clean_dep("//xla/tsl/platform/default:casts.h"),
clean_dep("//xla/tsl/platform/default:context.h"),
clean_dep("//xla/tsl/platform/default:criticality.h"),
clean_dep("//xla/tsl/platform/default:integral_types.h"),
clean_dep("//xla/tsl/platform/default:stacktrace.h"),
clean_dep("//xla/tsl/platform/default:status.h"),
clean_dep("//xla/tsl/platform/default:statusor.h"),

View File

@ -16,47 +16,218 @@ limitations under the License.
#ifndef XLA_TSL_PLATFORM_TYPES_H_
#define XLA_TSL_PLATFORM_TYPES_H_
#include <cstdint>
#include <limits>
#include <string>
#include "tsl/platform/bfloat16.h"
#include "absl/base/const_init.h"
#include "absl/base/macros.h"
#include "tsl/platform/bfloat16.h" // IWYU pragma: export
#include "tsl/platform/ml_dtypes.h" // IWYU pragma: export
#include "tsl/platform/platform.h"
#include "tsl/platform/tstring.h"
// Include appropriate platform-dependent implementations
#if defined(PLATFORM_GOOGLE) || defined(GOOGLE_INTEGRAL_TYPES)
#include "xla/tsl/platform/google/integral_types.h" // IWYU pragma: export
#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \
defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \
defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS)
#include "xla/tsl/platform/default/integral_types.h" // IWYU pragma: export
#else
#error Define the appropriate PLATFORM_<foo> macro for this platform
#endif
namespace tsl {
// Alias tsl::string to std::string.
using std::string;
using string ABSL_DEPRECATE_AND_INLINE() = std::string;
using uint8 ABSL_DEPRECATE_AND_INLINE() = uint8_t;
using uint16 ABSL_DEPRECATE_AND_INLINE() = uint16_t;
using uint32 ABSL_DEPRECATE_AND_INLINE() = uint32_t;
using uint64 ABSL_DEPRECATE_AND_INLINE() = uint64_t;
using int8 ABSL_DEPRECATE_AND_INLINE() = int8_t;
using int16 ABSL_DEPRECATE_AND_INLINE() = int16_t;
using int32 ABSL_DEPRECATE_AND_INLINE() = int32_t;
using int64 ABSL_DEPRECATE_AND_INLINE() = int64_t;
static const uint4 kuint4max = static_cast<uint4>(0x0F);
static const uint8 kuint8max = static_cast<uint8>(0xFF);
static const uint16 kuint16max = static_cast<uint16>(0xFFFF);
static const uint32 kuint32max = static_cast<uint32>(0xFFFFFFFF);
static const uint64 kuint64max = static_cast<uint64>(0xFFFFFFFFFFFFFFFFull);
static const int8_t kint8min = static_cast<int8>(~0x7F);
static const int8_t kint8max = static_cast<int8>(0x7F);
static const int4 kint4min = static_cast<int4>(0x08);
static const int4 kint4max = static_cast<int4>(0x07);
static const int16_t kint16min = static_cast<int16>(~0x7FFF);
static const int16_t kint16max = static_cast<int16>(0x7FFF);
static const int32_t kint32min = static_cast<int32>(~0x7FFFFFFF);
static const int32_t kint32max = static_cast<int32>(0x7FFFFFFF);
static const int64_t kint64min = static_cast<int64_t>(~0x7FFFFFFFFFFFFFFFll);
static const int64_t kint64max = static_cast<int64_t>(0x7FFFFFFFFFFFFFFFll);
// Note: This duplication is necessary because the inliner doesn't handle
// macros very well and templates will cause it to replace int32_t with int.
namespace detail {
class Uint8Max {
public:
constexpr explicit Uint8Max(absl::ConstInitType) {}
// Not copyable or movable.
Uint8Max(const Uint8Max&) = delete;
Uint8Max& operator=(const Uint8Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator uint8_t() const {
return std::numeric_limits<uint8_t>::max();
}
};
class Uint16Max {
public:
constexpr explicit Uint16Max(absl::ConstInitType) {}
// Not copyable or movable.
Uint16Max(const Uint16Max&) = delete;
Uint16Max& operator=(const Uint16Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator uint16_t() const {
return std::numeric_limits<uint16_t>::max();
}
};
class Uint32Max {
public:
constexpr explicit Uint32Max(absl::ConstInitType) {}
// Not copyable or movable.
Uint32Max(const Uint32Max&) = delete;
Uint32Max& operator=(const Uint32Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator uint32_t() const {
return std::numeric_limits<uint32_t>::max();
}
};
class Uint64Max {
public:
constexpr explicit Uint64Max(absl::ConstInitType) {}
// Not copyable or movable.
Uint64Max(const Uint64Max&) = delete;
Uint64Max& operator=(const Uint64Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator uint64_t() const {
return std::numeric_limits<uint64_t>::max();
}
};
class Int8Min {
public:
constexpr explicit Int8Min(absl::ConstInitType) {}
// Not copyable or movable.
Int8Min(const Int8Min&) = delete;
Int8Min& operator=(const Int8Min&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int8_t() const {
return std::numeric_limits<int8_t>::min();
}
};
class Int16Min {
public:
constexpr explicit Int16Min(absl::ConstInitType) {}
// Not copyable or movable.
Int16Min(const Int16Min&) = delete;
Int16Min& operator=(const Int16Min&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int16_t() const {
return std::numeric_limits<int16_t>::min();
}
};
class Int32Min {
public:
constexpr explicit Int32Min(absl::ConstInitType) {}
// Not copyable or movable.
Int32Min(const Int32Min&) = delete;
Int32Min& operator=(const Int32Min&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int32_t() const {
return std::numeric_limits<int32_t>::min();
}
};
class Int64Min {
public:
constexpr explicit Int64Min(absl::ConstInitType) {}
// Not copyable or movable.
Int64Min(const Int64Min&) = delete;
Int64Min& operator=(const Int64Min&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int64_t() const {
return std::numeric_limits<int64_t>::min();
}
};
class Int8Max {
public:
constexpr explicit Int8Max(absl::ConstInitType) {}
// Not copyable or movable.
Int8Max(const Int8Max&) = delete;
Int8Max& operator=(const Int8Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int8_t() const {
return std::numeric_limits<int8_t>::max();
}
};
class Int16Max {
public:
constexpr explicit Int16Max(absl::ConstInitType) {}
// Not copyable or movable.
Int16Max(const Int16Max&) = delete;
Int16Max& operator=(const Int16Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int16_t() const {
return std::numeric_limits<int16_t>::max();
}
};
class Int32Max {
public:
constexpr explicit Int32Max(absl::ConstInitType) {}
// Not copyable or movable.
Int32Max(const Int32Max&) = delete;
Int32Max& operator=(const Int32Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int32_t() const {
return std::numeric_limits<int32_t>::max();
}
};
class Int64Max {
public:
constexpr explicit Int64Max(absl::ConstInitType) {}
// Not copyable or movable.
Int64Max(const Int64Max&) = delete;
Int64Max& operator=(const Int64Max&) = delete;
ABSL_DEPRECATE_AND_INLINE()
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr operator int64_t() const {
return std::numeric_limits<int64_t>::max();
}
};
} // namespace detail
inline constexpr detail::Uint8Max kuint8max{absl::kConstInit};
inline constexpr detail::Uint16Max kuint16max{absl::kConstInit};
inline constexpr detail::Uint32Max kuint32max{absl::kConstInit};
inline constexpr detail::Uint64Max kuint64max{absl::kConstInit};
inline constexpr detail::Int8Min kint8min{absl::kConstInit};
inline constexpr detail::Int16Min kint16min{absl::kConstInit};
inline constexpr detail::Int32Min kint32min{absl::kConstInit};
inline constexpr detail::Int64Min kint64min{absl::kConstInit};
inline constexpr detail::Int8Max kint8max{absl::kConstInit};
inline constexpr detail::Int16Max kint16max{absl::kConstInit};
inline constexpr detail::Int32Max kint32max{absl::kConstInit};
inline constexpr detail::Int64Max kint64max{absl::kConstInit};
// A typedef for a uint64 used as a short fingerprint.
using Fprint = uint64;
using Fprint = uint64_t;
} // namespace tsl

View File

@ -54,3 +54,33 @@ diff --git a/xprof/convert/xplane_to_tools_data.cc b/xprof/convert/xplane_to_too
auto encode_status =
tsl::protobuf::util::MessageToJsonString(profile, &json_output, opts);
diff --git a/xprof/convert/trace_viewer/trace_events.cc b/xprof/convert/trace_viewer/trace_events.cc
--- a/xprof/convert/trace_viewer/trace_events.cc
+++ b/xprof/convert/trace_viewer/trace_events.cc
@@ -38,9 +38,7 @@ limitations under the License.
#include "xla/tsl/platform/env.h"
#include "xla/tsl/platform/errors.h"
#include "xla/tsl/platform/file_system.h"
-#include "xla/tsl/platform/macros.h"
#include "xla/tsl/profiler/utils/timespan.h"
-#include "xla/tsl/platform/types.h"
#include "xprof/convert/trace_viewer/trace_events_filter_interface.h"
#include "xprof/convert/trace_viewer/trace_events_util.h"
#include "xprof/convert/trace_viewer/trace_viewer_visibility.h"
@@ -49,7 +47,6 @@ limitations under the License.
namespace tensorflow {
namespace profiler {
-using tsl::kint64max;
namespace {
@@ -137,7 +134,7 @@ std::pair<uint64_t, uint64_t> GetLevelBoundsForDuration(uint64_t duration_ps) {
for (; i < NumLevels(); ++i) {
if (duration_ps > kLayerResolutions[i]) {
if (i == 0) {
- return std::make_pair(kLayerResolutions[i], kint64max);
+ return std::make_pair(kLayerResolutions[i], std::numeric_limits<int64_t>::max());
} else {
return std::make_pair(kLayerResolutions[i], kLayerResolutions[i - 1]);
}