From 9a691fd4967045f19bd5faeb5b694b50058b0a14 Mon Sep 17 00:00:00 2001 From: Gunhan Gulsoy Date: Sat, 30 Nov 2019 14:39:01 -0800 Subject: [PATCH] Move tensorflow/core/lib/core/coding to tensorflow/core/platform PiperOrigin-RevId: 283166018 Change-Id: I7123412386eeb448ca01ea27b859292128a35cad --- tensorflow/core/BUILD | 1 + tensorflow/core/lib/core/BUILD | 7 +- tensorflow/core/lib/core/coding.h | 45 +----------- tensorflow/core/platform/BUILD | 14 ++++ .../core/{lib/core => platform}/coding.cc | 2 +- tensorflow/core/platform/coding.h | 69 +++++++++++++++++++ 6 files changed, 87 insertions(+), 51 deletions(-) rename tensorflow/core/{lib/core => platform}/coding.cc (99%) create mode 100644 tensorflow/core/platform/coding.h diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index f18242e51e7..492a6fef318 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -2260,6 +2260,7 @@ cc_library( "//tensorflow/core/lib/strings:strcat", "//tensorflow/core/lib/strings:stringprintf", "//tensorflow/core/platform:abi", + "//tensorflow/core/platform:coding", "//tensorflow/core/platform:context", "//tensorflow/core/platform:cord", "//tensorflow/core/platform:cpu_feature_guard", diff --git a/tensorflow/core/lib/core/BUILD b/tensorflow/core/lib/core/BUILD index baf81113029..baca47df789 100644 --- a/tensorflow/core/lib/core/BUILD +++ b/tensorflow/core/lib/core/BUILD @@ -53,13 +53,9 @@ cc_library( cc_library( name = "coding", - srcs = ["coding.cc"], hdrs = ["coding.h"], deps = [ - "//tensorflow/core/lib/core:raw_coding", - "//tensorflow/core/lib/core:stringpiece", - "//tensorflow/core/platform:byte_order", - "//tensorflow/core/platform:types", + "//tensorflow/core/platform:coding", ], ) @@ -172,7 +168,6 @@ filegroup( srcs = [ "arena.cc", "bitmap.cc", - "coding.cc", ], visibility = ["//tensorflow/core:__pkg__"], ) diff --git a/tensorflow/core/lib/core/coding.h b/tensorflow/core/lib/core/coding.h index bfab80dd007..a1121c888dd 100644 --- a/tensorflow/core/lib/core/coding.h +++ b/tensorflow/core/lib/core/coding.h @@ -21,49 +21,6 @@ limitations under the License. #ifndef TENSORFLOW_CORE_LIB_CORE_CODING_H_ #define TENSORFLOW_CORE_LIB_CORE_CODING_H_ -#include "tensorflow/core/lib/core/raw_coding.h" -#include "tensorflow/core/lib/core/stringpiece.h" -#include "tensorflow/core/platform/types.h" - -namespace tensorflow { -namespace core { - -// Maximum number of bytes occupied by a varint32. -static const int kMaxVarint32Bytes = 5; - -// Maximum number of bytes occupied by a varint64. -static const int kMaxVarint64Bytes = 10; - -// Lower-level versions of Put... that write directly into a character buffer -// REQUIRES: dst has enough space for the value being written -extern void EncodeFixed16(char* dst, uint16 value); -extern void EncodeFixed32(char* dst, uint32 value); -extern void EncodeFixed64(char* dst, uint64 value); -extern void PutFixed16(string* dst, uint16 value); -extern void PutFixed32(string* dst, uint32 value); -extern void PutFixed64(string* dst, uint64 value); - -extern void PutVarint32(string* dst, uint32 value); -extern void PutVarint64(string* dst, uint64 value); - -extern bool GetVarint32(StringPiece* input, uint32* value); -extern bool GetVarint64(StringPiece* input, uint64* value); - -extern const char* GetVarint32Ptr(const char* p, const char* limit, uint32* v); -extern const char* GetVarint64Ptr(const char* p, const char* limit, uint64* v); - -// Internal routine for use by fallback path of GetVarint32Ptr -extern const char* GetVarint32PtrFallback(const char* p, const char* limit, - uint32* value); -extern const char* GetVarint32Ptr(const char* p, const char* limit, - uint32* value); -extern char* EncodeVarint32(char* dst, uint32 v); -extern char* EncodeVarint64(char* dst, uint64 v); - -// Returns the length of the varint32 or varint64 encoding of "v" -extern int VarintLength(uint64_t v); - -} // namespace core -} // namespace tensorflow +#include "tensorflow/core/platform/coding.h" #endif // TENSORFLOW_CORE_LIB_CORE_CODING_H_ diff --git a/tensorflow/core/platform/BUILD b/tensorflow/core/platform/BUILD index 1c363209a48..e800684fe53 100644 --- a/tensorflow/core/platform/BUILD +++ b/tensorflow/core/platform/BUILD @@ -88,6 +88,18 @@ cc_library( hdrs = ["byte_order.h"], ) +cc_library( + name = "coding", + srcs = ["coding.cc"], + hdrs = ["coding.h"], + deps = [ + ":byte_order", + ":raw_coding", + ":stringpiece", + ":types", + ], +) + cc_library( name = "context", textual_hdrs = ["context.h"], @@ -746,6 +758,7 @@ filegroup( "**/unbounded_work_queue.cc", "**/windows_file_system.cc", "abi.cc", + "coding.cc", "cpu_info.cc", "hash.cc", "numbers.cc", @@ -852,6 +865,7 @@ filegroup( "**/human_readable_json.cc", "**/rocm_rocdl_path.cc", "abi.cc", + "coding.cc", "cpu_info.cc", "cpu_feature_guard.cc", "denormal.cc", diff --git a/tensorflow/core/lib/core/coding.cc b/tensorflow/core/platform/coding.cc similarity index 99% rename from tensorflow/core/lib/core/coding.cc rename to tensorflow/core/platform/coding.cc index 4c33dfa211e..ef0df8fa42a 100644 --- a/tensorflow/core/lib/core/coding.cc +++ b/tensorflow/core/platform/coding.cc @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "tensorflow/core/lib/core/coding.h" +#include "tensorflow/core/platform/coding.h" #include "tensorflow/core/platform/byte_order.h" diff --git a/tensorflow/core/platform/coding.h b/tensorflow/core/platform/coding.h new file mode 100644 index 00000000000..cd66e54dfdb --- /dev/null +++ b/tensorflow/core/platform/coding.h @@ -0,0 +1,69 @@ +/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Endian-neutral encoding: +// * Fixed-length numbers are encoded with least-significant byte first +// * In addition we support variable length "varint" encoding +// * Strings are encoded prefixed by their length in varint format + +#ifndef TENSORFLOW_CORE_PLATFORM_CODING_H_ +#define TENSORFLOW_CORE_PLATFORM_CODING_H_ + +#include "tensorflow/core/platform/raw_coding.h" +#include "tensorflow/core/platform/stringpiece.h" +#include "tensorflow/core/platform/types.h" + +namespace tensorflow { +namespace core { + +// Maximum number of bytes occupied by a varint32. +static const int kMaxVarint32Bytes = 5; + +// Maximum number of bytes occupied by a varint64. +static const int kMaxVarint64Bytes = 10; + +// Lower-level versions of Put... that write directly into a character buffer +// REQUIRES: dst has enough space for the value being written +extern void EncodeFixed16(char* dst, uint16 value); +extern void EncodeFixed32(char* dst, uint32 value); +extern void EncodeFixed64(char* dst, uint64 value); +extern void PutFixed16(string* dst, uint16 value); +extern void PutFixed32(string* dst, uint32 value); +extern void PutFixed64(string* dst, uint64 value); + +extern void PutVarint32(string* dst, uint32 value); +extern void PutVarint64(string* dst, uint64 value); + +extern bool GetVarint32(StringPiece* input, uint32* value); +extern bool GetVarint64(StringPiece* input, uint64* value); + +extern const char* GetVarint32Ptr(const char* p, const char* limit, uint32* v); +extern const char* GetVarint64Ptr(const char* p, const char* limit, uint64* v); + +// Internal routine for use by fallback path of GetVarint32Ptr +extern const char* GetVarint32PtrFallback(const char* p, const char* limit, + uint32* value); +extern const char* GetVarint32Ptr(const char* p, const char* limit, + uint32* value); +extern char* EncodeVarint32(char* dst, uint32 v); +extern char* EncodeVarint64(char* dst, uint64 v); + +// Returns the length of the varint32 or varint64 encoding of "v" +extern int VarintLength(uint64_t v); + +} // namespace core +} // namespace tensorflow + +#endif // TENSORFLOW_CORE_PLATFORM_CODING_H_