From 2d3ab484dd84e473adbaf76320a539e1120e9ece Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 15 Jul 2020 11:28:11 -0700 Subject: [PATCH] Modify type-specific mappings to be explicit about long/long long rather than relying on a specific definition meaning int64. PiperOrigin-RevId: 321402137 Change-Id: I8f3e753725551bdba4eb0b2855e8515a3a7828b4 --- tensorflow/core/framework/types.h | 55 ++++++++++++++++++- tensorflow/core/kernels/sparse_cross_op.cc | 4 +- .../core/platform/default/strong_hash.h | 6 +- tensorflow/core/platform/strong_hash.h | 2 +- .../core/profiler/utils/xplane_builder.h | 20 ++++++- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/tensorflow/core/framework/types.h b/tensorflow/core/framework/types.h index fe52f8b2b59..2b5f41be0de 100644 --- a/tensorflow/core/framework/types.h +++ b/tensorflow/core/framework/types.h @@ -395,8 +395,6 @@ MATCH_TYPE_AND_ENUM(int8, DT_INT8); MATCH_TYPE_AND_ENUM(tstring, DT_STRING); MATCH_TYPE_AND_ENUM(complex64, DT_COMPLEX64); MATCH_TYPE_AND_ENUM(complex128, DT_COMPLEX128); -MATCH_TYPE_AND_ENUM(int64, DT_INT64); -MATCH_TYPE_AND_ENUM(uint64, DT_UINT64); MATCH_TYPE_AND_ENUM(bool, DT_BOOL); MATCH_TYPE_AND_ENUM(qint8, DT_QINT8); MATCH_TYPE_AND_ENUM(quint8, DT_QUINT8); @@ -408,6 +406,59 @@ MATCH_TYPE_AND_ENUM(Eigen::half, DT_HALF); MATCH_TYPE_AND_ENUM(ResourceHandle, DT_RESOURCE); MATCH_TYPE_AND_ENUM(Variant, DT_VARIANT); +template <> +struct DataTypeToEnum { + static DataType v() { return value; } + static DataType ref() { return MakeRefType(value); } + static constexpr DataType value = sizeof(long) == 4 ? DT_INT32 : DT_INT64; +}; +template <> +struct IsValidDataType { + static constexpr bool value = true; +}; +template <> +struct EnumToDataType { + typedef tensorflow::int64 Type; +}; + +template <> +struct DataTypeToEnum { + static DataType v() { return value; } + static DataType ref() { return MakeRefType(value); } + static constexpr DataType value = + sizeof(unsigned long) == 4 ? DT_UINT32 : DT_UINT64; +}; +template <> +struct IsValidDataType { + static constexpr bool value = true; +}; +template <> +struct EnumToDataType { + typedef tensorflow::uint64 Type; +}; + +template <> +struct DataTypeToEnum { + static DataType v() { return DT_INT64; } + static DataType ref() { return MakeRefType(DT_INT64); } + static constexpr DataType value = DT_INT64; +}; +template <> +struct IsValidDataType { + static constexpr bool value = true; +}; + +template <> +struct DataTypeToEnum { + static DataType v() { return DT_UINT64; } + static DataType ref() { return MakeRefType(DT_UINT64); } + static constexpr DataType value = DT_UINT64; +}; +template <> +struct IsValidDataType { + static constexpr bool value = true; +}; + #undef MATCH_TYPE_AND_ENUM // All types not specialized are marked invalid. diff --git a/tensorflow/core/kernels/sparse_cross_op.cc b/tensorflow/core/kernels/sparse_cross_op.cc index 9a80aad5d04..583235b4a30 100644 --- a/tensorflow/core/kernels/sparse_cross_op.cc +++ b/tensorflow/core/kernels/sparse_cross_op.cc @@ -101,7 +101,7 @@ class KeyedSparseTensorColumn : public ColumnInterface { private: const Tensor& values_; - uint64 key_[2]; + tensorflow::uint64 key_[2]; std::vector feature_counts_; std::vector feature_start_indices_; }; @@ -201,7 +201,7 @@ class KeyedDenseTensorColumn : public ColumnInterface { private: const Tensor& tensor_; - uint64 key_[2]; + tensorflow::uint64 key_[2]; }; // InternalType is int64 only when using HashCrosser. diff --git a/tensorflow/core/platform/default/strong_hash.h b/tensorflow/core/platform/default/strong_hash.h index f04f1b7b6ae..e7c8047235c 100644 --- a/tensorflow/core/platform/default/strong_hash.h +++ b/tensorflow/core/platform/default/strong_hash.h @@ -21,8 +21,10 @@ limitations under the License. namespace tensorflow { -inline uint64 StrongKeyedHash(const uint64 (&key)[2], const string& s) { - return highwayhash::StringHasher()(key, s); +inline uint64 StrongKeyedHash(const tensorflow::uint64 (&key)[2], + const string& s) { + return highwayhash::StringHasher()( + {key[0], key[1]}, s); } } // namespace tensorflow diff --git a/tensorflow/core/platform/strong_hash.h b/tensorflow/core/platform/strong_hash.h index cbd267f90ed..987df5da59d 100644 --- a/tensorflow/core/platform/strong_hash.h +++ b/tensorflow/core/platform/strong_hash.h @@ -32,7 +32,7 @@ namespace tensorflow { // string input = "input string"; // uint64 hash_value = StrongKeyedHash(key, input); // -uint64 StrongKeyedHash(const uint64 (&)[2], const string&); +uint64 StrongKeyedHash(const tensorflow::uint64 (&)[2], const string&); } // namespace tensorflow diff --git a/tensorflow/core/profiler/utils/xplane_builder.h b/tensorflow/core/profiler/utils/xplane_builder.h index d5a4d443e21..01d38f0aa11 100644 --- a/tensorflow/core/profiler/utils/xplane_builder.h +++ b/tensorflow/core/profiler/utils/xplane_builder.h @@ -44,13 +44,29 @@ class XStatsBuilder { void AddStatValue(const XStatMetadata& metadata, uint32 value) { AddStat(metadata)->set_uint64_value(value); } - void AddStatValue(const XStatMetadata& metadata, uint64 value) { + void AddStatValue(const XStatMetadata& metadata, + unsigned long value) { // NOLINT + if constexpr (sizeof(unsigned long) == 8) { // NOLINT + AddStat(metadata)->set_uint64_value(value); + } else { + AddStat(metadata)->set_uint32_value(value); + } + } + void AddStatValue(const XStatMetadata& metadata, + unsigned long long value) { // NOLINT AddStat(metadata)->set_uint64_value(value); } void AddStatValue(const XStatMetadata& metadata, int32 value) { AddStat(metadata)->set_int64_value(value); } - void AddStatValue(const XStatMetadata& metadata, int64 value) { + void AddStatValue(const XStatMetadata& metadata, long value) { // NOLINT + if constexpr (sizeof(long) == 8) { // NOLINT + AddStat(metadata)->set_int64_value(value); + } else { + AddStat(metadata)->set_int32_value(value); + } + } + void AddStatValue(const XStatMetadata& metadata, long long value) { // NOLINT AddStat(metadata)->set_int64_value(value); } void AddStatValue(const XStatMetadata& metadata, double value) {