aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLev Proleev <levp@google.com>2021-02-26 20:30:08 +0000
committerLev Proleev <levp@google.com>2021-03-10 20:19:04 +0000
commita49199886d1a7befbb55e6f63433c5d4d3c371c3 (patch)
treea1a09681f40e33e1c133cfeb716bde399f1ad844
parent9913b83cee35af81a7ee9483ae274b48f70bdd2b (diff)
downloadtensorflow-a49199886d1a7befbb55e6f63433c5d4d3c371c3.tar.gz
Make TF Lite compile after rebase
The merge CL that is a parent of this one was done by accepting all incoming changes and addressing build errors afterwards. Here is what was done to make TF Lite and NNAPI compile after this update: * bfloat16 implementation was moved to eigen upstream. I've restored it in the original place, so that we don't have to upgrade eigen to an unstable version yet. * Disabled log sinks, reverted to old implementation of LogMessage::GenerateLogMessage() * Added new source files to Android.bp files * Switched code to use farmhash from libtextclassifier * Switched absl::optional to std::optional * Added a genrule for lite/schema/mutable/schema_generated.h * Ruy was moved to its own project external/ruy * Temporary disabled registration of RFFT2D op until the corresponding fft library is imported to Android Bug: 178609672 Test: mma, NeuralNetworksTest_static Change-Id: I97088e763bf430390e5becfee5bb937088613b18
-rw-r--r--Android.bp12
-rw-r--r--tensorflow/core/lib/bfloat16/bfloat16.cc28
-rw-r--r--tensorflow/core/lib/bfloat16/bfloat16.h508
-rw-r--r--tensorflow/core/platform/bfloat16.h4
-rw-r--r--tensorflow/core/platform/cord.h11
-rw-r--r--tensorflow/core/platform/default/logging.cc31
-rw-r--r--tensorflow/core/platform/default/logging.h2
-rw-r--r--tensorflow/lite/Android.bp49
-rw-r--r--tensorflow/lite/delegates/nnapi/java/Android.bp2
-rw-r--r--tensorflow/lite/delegates/nnapi/nnapi_delegate.cc4
-rw-r--r--tensorflow/lite/java/Android.bp5
-rw-r--r--tensorflow/lite/kernels/Android.bp53
-rw-r--r--tensorflow/lite/kernels/acceleration_test_util.cc1
-rw-r--r--tensorflow/lite/kernels/acceleration_test_util_internal.h6
-rw-r--r--tensorflow/lite/kernels/dequantize.h2
-rw-r--r--tensorflow/lite/kernels/internal/optimized/neon_tensor_utils.cc3
-rw-r--r--tensorflow/lite/kernels/internal/reference/reference_ops.h1
-rw-r--r--tensorflow/lite/kernels/lsh_projection.cc2
-rw-r--r--tensorflow/lite/kernels/register.cc3
-rw-r--r--tensorflow/lite/profiling/atrace_profiler.cc7
-rw-r--r--tensorflow/lite/testing/nnapi_tflite_zip_tests/Android.bp7
-rw-r--r--tensorflow/lite/tflite_static.bp102
-rw-r--r--tensorflow/lite/tools/optimize/sparsity/format_converter.h2
-rw-r--r--tensorflow/lite/tools/versioning/op_version.cc3
24 files changed, 718 insertions, 130 deletions
diff --git a/Android.bp b/Android.bp
index dde21f8fb9b..7828d88f347 100644
--- a/Android.bp
+++ b/Android.bp
@@ -61,11 +61,19 @@ cc_library_headers {
host_supported: true,
sdk_version: "current",
apex_available: [
+ "//apex_available:platform",
+ "com.android.extservices",
"com.android.neuralnetworks",
"test_com.android.neuralnetworks",
- "com.android.extservices",
- "//apex_available:platform",
],
}
+genrule {
+ name: "libtflite_mutable_schema",
+ tools: ["flatc"],
+ cmd: "$(location flatc) --cpp --no-union-value-namespacing --gen-object-api --gen-mutable --keep-prefix -o $$(dirname $(out)) $(in)",
+ srcs: [ "tensorflow/lite/schema/schema.fbs" ],
+ out: [ "tensorflow/lite/schema/mutable/schema_generated.h" ],
+}
+
subdirs = ["tensorflow/lite"]
diff --git a/tensorflow/core/lib/bfloat16/bfloat16.cc b/tensorflow/core/lib/bfloat16/bfloat16.cc
new file mode 100644
index 00000000000..e6e24bc0786
--- /dev/null
+++ b/tensorflow/core/lib/bfloat16/bfloat16.cc
@@ -0,0 +1,28 @@
+/* Copyright 2017 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.
+==============================================================================*/
+
+#include "tensorflow/core/lib/bfloat16/bfloat16.h"
+
+#include "third_party/eigen3/Eigen/Core"
+
+namespace tensorflow {
+
+const uint16_t bfloat16::NAN_VALUE;
+const uint16_t bfloat16::ZERO_VALUE;
+
+B16_DEVICE_FUNC bfloat16::operator Eigen::half() const {
+ return static_cast<Eigen::half>(float(*this));
+}
+} // end namespace tensorflow
diff --git a/tensorflow/core/lib/bfloat16/bfloat16.h b/tensorflow/core/lib/bfloat16/bfloat16.h
index d6ac77b6750..a133f7e0f17 100644
--- a/tensorflow/core/lib/bfloat16/bfloat16.h
+++ b/tensorflow/core/lib/bfloat16/bfloat16.h
@@ -16,6 +16,512 @@ limitations under the License.
#ifndef TENSORFLOW_CORE_LIB_BFLOAT16_BFLOAT16_H_
#define TENSORFLOW_CORE_LIB_BFLOAT16_BFLOAT16_H_
-#include "tensorflow/core/platform/bfloat16.h"
+#include <cmath>
+#include <complex>
+
+#include "tensorflow/core/platform/byte_order.h"
+
+#ifdef __CUDACC__
+// All functions callable from CUDA code must be qualified with __device__
+#define B16_DEVICE_FUNC __host__ __device__
+
+#else
+#define B16_DEVICE_FUNC
+
+#endif
+
+namespace Eigen {
+struct half;
+}
+
+namespace tensorflow {
+
+// Single precision complex.
+typedef std::complex<float> complex64;
+// Double precision complex.
+typedef std::complex<double> complex128;
+
+// see framework/bfloat16.h for description.
+struct bfloat16 {
+ // The default constructor must yield a zero value, not an uninitialized
+ // value; some TF kernels use T() as a zero value.
+ B16_DEVICE_FUNC bfloat16() : value(ZERO_VALUE) {}
+
+ B16_DEVICE_FUNC static bfloat16 truncate_to_bfloat16(const float v) {
+ bfloat16 output;
+ if (float_isnan(v)) {
+ output.value = NAN_VALUE;
+ return output;
+ }
+ const uint16_t* p = reinterpret_cast<const uint16_t*>(&v);
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ output.value = p[0];
+#else
+ output.value = p[1];
+#endif
+ return output;
+ }
+
+ B16_DEVICE_FUNC explicit bfloat16(const float v) {
+ value = round_to_bfloat16(v).value;
+ }
+
+ B16_DEVICE_FUNC explicit bfloat16(const double val)
+ : bfloat16(static_cast<float>(val)) {}
+ // Following the convention of numpy, converting between complex and
+ // float will lead to loss of imag value.
+ B16_DEVICE_FUNC explicit bfloat16(const complex64& val)
+ : bfloat16(val.real()) {}
+
+ B16_DEVICE_FUNC explicit bfloat16(const complex128& val)
+ : bfloat16(static_cast<float>(val.real())) {}
+
+ B16_DEVICE_FUNC explicit bfloat16(const unsigned short val)
+ : bfloat16(static_cast<float>(val)) {}
+
+ B16_DEVICE_FUNC explicit bfloat16(const unsigned int val)
+ : bfloat16(static_cast<float>(val)) {}
+
+ B16_DEVICE_FUNC explicit bfloat16(const int val)
+ : bfloat16(static_cast<float>(val)) {}
+
+ B16_DEVICE_FUNC explicit bfloat16(const long val)
+ : bfloat16(static_cast<float>(val)) {}
+
+ B16_DEVICE_FUNC explicit bfloat16(const long long val)
+ : bfloat16(static_cast<float>(val)) {}
+
+ template <class T>
+ B16_DEVICE_FUNC explicit bfloat16(const T& val)
+ : bfloat16(static_cast<float>(val)) {}
+
+ B16_DEVICE_FUNC explicit operator float() const {
+ float result = 0;
+
+ uint16_t* q = reinterpret_cast<uint16_t*>(&result);
+
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ q[0] = value;
+#else
+ q[1] = value;
+#endif
+ return result;
+ }
+
+ B16_DEVICE_FUNC explicit operator bool() const {
+ return static_cast<bool>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator Eigen::half() const;
+
+ B16_DEVICE_FUNC explicit operator short() const {
+ return static_cast<short>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator int() const {
+ return static_cast<int>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator long() const {
+ return static_cast<long>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator char() const {
+ return static_cast<char>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator signed char() const {
+ return static_cast<signed char>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator unsigned char() const {
+ return static_cast<unsigned char>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator unsigned short() const {
+ return static_cast<unsigned short>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator unsigned int() const {
+ return static_cast<unsigned int>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator unsigned long() const {
+ return static_cast<unsigned long>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator unsigned long long() const {
+ return static_cast<unsigned long long>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator long long() const {
+ return static_cast<long long>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator double() const {
+ return static_cast<double>(float(*this));
+ }
+
+ B16_DEVICE_FUNC explicit operator complex64() const {
+ return complex64(float(*this), float(0.0));
+ }
+
+ B16_DEVICE_FUNC explicit operator complex128() const {
+ return complex128(double(*this), double(0.0));
+ }
+
+ union FP32 {
+ unsigned int u;
+ float f;
+ };
+
+ // Converts a float point to bfloat16, with round-nearest-to-even as rounding
+ // method.
+ // TODO: There is a slightly faster implementation (8% faster on CPU)
+ // than this (documented in cl/175987786), that is exponentially harder to
+ // understand and document. Switch to the faster version when converting to
+ // BF16 becomes compute-bound.
+ B16_DEVICE_FUNC static bfloat16 round_to_bfloat16(float v) {
+ uint32_t input;
+ FP32 f;
+ f.f = v;
+ input = f.u;
+ bfloat16 output;
+
+ if (float_isnan(v)) {
+ // If the value is a NaN, squash it to a qNaN with msb of fraction set,
+ // this makes sure after truncation we don't end up with an inf.
+ //
+ // qNaN magic: All exponent bits set + most significant bit of fraction
+ // set.
+ output.value = 0x7fc0;
+ } else {
+ // Fast rounding algorithm that rounds a half value to nearest even. This
+ // reduces expected error when we convert a large number of floats. Here
+ // is how it works:
+ //
+ // Definitions:
+ // To convert a float 32 to bfloat16, a float 32 can be viewed as 32 bits
+ // with the following tags:
+ //
+ // Sign | Exp (8 bits) | Frac (23 bits)
+ // S EEEEEEEE FFFFFFLRTTTTTTTTTTTTTTT
+ //
+ // S: Sign bit.
+ // E: Exponent bits.
+ // F: First 6 bits of fraction.
+ // L: Least significant bit of resulting bfloat16 if we truncate away the
+ // rest of the float32. This is also the 7th bit of fraction
+ // R: Rounding bit, 8th bit of fraction.
+ // T: Sticky bits, rest of fraction, 15 bits.
+ //
+ // To round half to nearest even, there are 3 cases where we want to round
+ // down (simply truncate the result of the bits away, which consists of
+ // rounding bit and sticky bits) and two cases where we want to round up
+ // (truncate then add one to the result).
+ //
+ // The fast converting algorithm simply adds lsb (L) to 0x7fff (15 bits of
+ // 1s) as the rounding bias, adds the rounding bias to the input, then
+ // truncates the last 16 bits away.
+ //
+ // To understand how it works, we can analyze this algorithm case by case:
+ //
+ // 1. L = 0, R = 0:
+ // Expect: round down, this is less than half value.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 0 = 0x7fff
+ // - Adding rounding bias to input may create any carry, depending on
+ // whether there is any value set to 1 in T bits.
+ // - R may be set to 1 if there is a carry.
+ // - L remains 0.
+ // - Note that this case also handles Inf and -Inf, where all fraction
+ // bits, including L, R and Ts are all 0. The output remains Inf after
+ // this algorithm.
+ //
+ // 2. L = 1, R = 0:
+ // Expect: round down, this is less than half value.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 1 = 0x8000
+ // - Adding rounding bias to input doesn't change sticky bits but
+ // adds 1 to rounding bit.
+ // - L remains 1.
+ //
+ // 3. L = 0, R = 1, all of T are 0:
+ // Expect: round down, this is exactly at half, the result is already
+ // even (L=0).
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 0 = 0x7fff
+ // - Adding rounding bias to input sets all sticky bits to 1, but
+ // doesn't create a carry.
+ // - R remains 1.
+ // - L remains 0.
+ //
+ // 4. L = 1, R = 1:
+ // Expect: round up, this is exactly at half, the result needs to be
+ // round to the next even number.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 1 = 0x8000
+ // - Adding rounding bias to input doesn't change sticky bits, but
+ // creates a carry from rounding bit.
+ // - The carry sets L to 0, creates another carry bit and propagate
+ // forward to F bits.
+ // - If all the F bits are 1, a carry then propagates to the exponent
+ // bits, which then creates the minimum value with the next exponent
+ // value. Note that we won't have the case where exponents are all 1,
+ // since that's either a NaN (handled in the other if condition) or inf
+ // (handled in case 1).
+ //
+ // 5. L = 0, R = 1, any of T is 1:
+ // Expect: round up, this is greater than half.
+ //
+ // Algorithm:
+ // - Rounding bias: 0x7fff + 0 = 0x7fff
+ // - Adding rounding bias to input creates a carry from sticky bits,
+ // sets rounding bit to 0, then create another carry.
+ // - The second carry sets L to 1.
+ //
+ // Examples:
+ //
+ // Exact half value that is already even:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1000000000000000
+ //
+ // This falls into case 3. We truncate the rest of 16 bits and no
+ // carry is created into F and L:
+ //
+ // Output:
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
+ //
+ // Exact half value, round to next even number:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1000000000000000
+ //
+ // This falls into case 4. We create a carry from R and T,
+ // which then propagates into L and F:
+ //
+ // Output:
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
+ //
+ //
+ // Max denormal value round to min normal value:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1111111111111111
+ //
+ // This falls into case 4. We create a carry from R and T,
+ // propagate into L and F, which then propagates into exponent
+ // bits:
+ //
+ // Output:
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
+ //
+ // Max normal value round to Inf:
+ // Input:
+ // Sign | Exp (8 bit) | Frac (first 7 bit) | Frac (last 16 bit)
+ // S E E E E E E E E F F F F F F L RTTTTTTTTTTTTTTT
+ // 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1111111111111111
+ //
+ // This falls into case 4. We create a carry from R and T,
+ // propagate into L and F, which then propagates into exponent
+ // bits:
+ //
+ // Sign | Exp (8 bit) | Frac (first 7 bit)
+ // S E E E E E E E E F F F F F F L
+ // 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
+ //
+ //
+ // Least significant bit of resulting bfloat.
+ uint32_t lsb = (input >> 16) & 1;
+ uint32_t rounding_bias = 0x7fff + lsb;
+ input += rounding_bias;
+ output.value = static_cast<uint16_t>(input >> 16);
+ }
+ return output;
+ }
+
+ static bfloat16 epsilon() {
+ bfloat16 x;
+ x.value = 0x3c00; // 0x1.0p-7
+ return x;
+ }
+
+ static bfloat16 highest() {
+ bfloat16 x;
+ x.value = 0x7F7F; // 0x1.FEp127
+ return x;
+ }
+
+ static bfloat16 lowest() {
+ bfloat16 x;
+ x.value = 0xFF7F; // -0x1.FEp127
+ return x;
+ }
+
+ static bfloat16 min_positive_normal() {
+ bfloat16 x;
+ x.value = 0x0080; // 0x1p-126
+ return x;
+ }
+
+ bool IsZero() const { return (value & 0x7FFF) == ZERO_VALUE; }
+
+ uint16_t value;
+
+ // A value that represents "not a number".
+ static const uint16_t NAN_VALUE = 0x7FC0;
+
+ private:
+ // A value that represents "zero".
+ static const uint16_t ZERO_VALUE = 0;
+
+ B16_DEVICE_FUNC static bool float_isnan(const float& x) {
+#ifdef __CUDA_ARCH__
+ return ::isnan(x);
+#else
+ return std::isnan(x);
+#endif
+ }
+};
+
+B16_DEVICE_FUNC inline std::ostream& operator<<(std::ostream& os,
+ const bfloat16& dt) {
+ os << static_cast<float>(dt);
+ return os;
+}
+
+B16_DEVICE_FUNC inline bfloat16 operator+(bfloat16 a, bfloat16 b) {
+ return bfloat16(static_cast<float>(a) + static_cast<float>(b));
+}
+B16_DEVICE_FUNC inline bfloat16 operator+(bfloat16 a, int b) {
+ return bfloat16(static_cast<float>(a) + static_cast<float>(b));
+}
+B16_DEVICE_FUNC inline bfloat16 operator+(int a, bfloat16 b) {
+ return bfloat16(static_cast<float>(a) + static_cast<float>(b));
+}
+B16_DEVICE_FUNC inline bfloat16 operator-(bfloat16 a, bfloat16 b) {
+ return bfloat16(static_cast<float>(a) - static_cast<float>(b));
+}
+B16_DEVICE_FUNC inline bfloat16 operator*(bfloat16 a, bfloat16 b) {
+ return bfloat16(static_cast<float>(a) * static_cast<float>(b));
+}
+B16_DEVICE_FUNC inline bfloat16 operator/(bfloat16 a, bfloat16 b) {
+ return bfloat16(static_cast<float>(a) / static_cast<float>(b));
+}
+B16_DEVICE_FUNC inline bfloat16 operator-(bfloat16 a) {
+ a.value ^= 0x8000;
+ return a;
+}
+B16_DEVICE_FUNC inline bool operator<(bfloat16 a, bfloat16 b) {
+ return static_cast<float>(a) < static_cast<float>(b);
+}
+B16_DEVICE_FUNC inline bool operator<=(bfloat16 a, bfloat16 b) {
+ return static_cast<float>(a) <= static_cast<float>(b);
+}
+B16_DEVICE_FUNC inline bool operator==(bfloat16 a, bfloat16 b) {
+ return static_cast<float>(a) == static_cast<float>(b);
+}
+B16_DEVICE_FUNC inline bool operator!=(bfloat16 a, bfloat16 b) {
+ return static_cast<float>(a) != static_cast<float>(b);
+}
+B16_DEVICE_FUNC inline bool operator>(bfloat16 a, bfloat16 b) {
+ return static_cast<float>(a) > static_cast<float>(b);
+}
+B16_DEVICE_FUNC inline bool operator>=(bfloat16 a, bfloat16 b) {
+ return static_cast<float>(a) >= static_cast<float>(b);
+}
+B16_DEVICE_FUNC inline bfloat16& operator+=(bfloat16& a, bfloat16 b) {
+ a = a + b;
+ return a;
+}
+B16_DEVICE_FUNC inline bfloat16& operator-=(bfloat16& a, bfloat16 b) {
+ a = a - b;
+ return a;
+}
+B16_DEVICE_FUNC inline bfloat16 operator++(bfloat16& a) {
+ a += bfloat16(1);
+ return a;
+}
+B16_DEVICE_FUNC inline bfloat16 operator--(bfloat16& a) {
+ a -= bfloat16(1);
+ return a;
+}
+B16_DEVICE_FUNC inline bfloat16 operator++(bfloat16& a, int) {
+ bfloat16 original_value = a;
+ ++a;
+ return original_value;
+}
+B16_DEVICE_FUNC inline bfloat16 operator--(bfloat16& a, int) {
+ bfloat16 original_value = a;
+ --a;
+ return original_value;
+}
+B16_DEVICE_FUNC inline bfloat16& operator*=(bfloat16& a, bfloat16 b) {
+ a = a * b;
+ return a;
+}
+B16_DEVICE_FUNC inline bfloat16& operator/=(bfloat16& a, bfloat16 b) {
+ a = a / b;
+ return a;
+}
+} // end namespace tensorflow
+
+namespace std {
+template <>
+struct hash<tensorflow::bfloat16> {
+ size_t operator()(const tensorflow::bfloat16& v) const {
+ return hash<float>()(static_cast<float>(v));
+ }
+};
+
+using tensorflow::bfloat16;
+inline bool isinf(const bfloat16& a) { return std::isinf(float(a)); }
+inline bool isnan(const bfloat16& a) { return std::isnan(float(a)); }
+inline bool isfinite(const bfloat16& a) { return std::isfinite(float(a)); }
+inline bfloat16 abs(const bfloat16& a) { return bfloat16(std::abs(float(a))); }
+inline bfloat16 exp(const bfloat16& a) { return bfloat16(std::exp(float(a))); }
+inline bfloat16 expm1(const bfloat16& a) {
+ return bfloat16(std::expm1(float(a)));
+}
+inline bfloat16 log(const bfloat16& a) { return bfloat16(std::log(float(a))); }
+inline bfloat16 log1p(const bfloat16& a) {
+ return bfloat16(std::log1p(float(a)));
+}
+inline bfloat16 log10(const bfloat16& a) {
+ return bfloat16(std::log10(float(a)));
+}
+inline bfloat16 sqrt(const bfloat16& a) {
+ return bfloat16(std::sqrt(float(a)));
+}
+inline bfloat16 pow(const bfloat16& a, const bfloat16& b) {
+ return bfloat16(std::pow(float(a), float(b)));
+}
+inline bfloat16 sin(const bfloat16& a) { return bfloat16(std::sin(float(a))); }
+inline bfloat16 cos(const bfloat16& a) { return bfloat16(std::cos(float(a))); }
+inline bfloat16 tan(const bfloat16& a) { return bfloat16(std::tan(float(a))); }
+inline bfloat16 tanh(const bfloat16& a) {
+ return bfloat16(std::tanh(float(a)));
+}
+inline bfloat16 floor(const bfloat16& a) {
+ return bfloat16(std::floor(float(a)));
+}
+inline bfloat16 ceil(const bfloat16& a) {
+ return bfloat16(std::ceil(float(a)));
+}
+} // namespace std
#endif // TENSORFLOW_CORE_LIB_BFLOAT16_BFLOAT16_H_
diff --git a/tensorflow/core/platform/bfloat16.h b/tensorflow/core/platform/bfloat16.h
index 3e3ab2ce55a..5ce7c54d7bd 100644
--- a/tensorflow/core/platform/bfloat16.h
+++ b/tensorflow/core/platform/bfloat16.h
@@ -18,11 +18,11 @@ limitations under the License.
// clang-format off
#include "tensorflow/core/platform/byte_order.h"
-#include "third_party/eigen3/Eigen/Core"
+#include "Eigen/Core"
// clang-format on
namespace tensorflow {
-typedef Eigen::bfloat16 bfloat16;
+//typedef Eigen::bfloat16 bfloat16;
} // end namespace tensorflow
#endif // TENSORFLOW_CORE_LIB_BFLOAT16_BFLOAT16_H_
diff --git a/tensorflow/core/platform/cord.h b/tensorflow/core/platform/cord.h
index 4564eb3fdbe..4016e105728 100644
--- a/tensorflow/core/platform/cord.h
+++ b/tensorflow/core/platform/cord.h
@@ -18,11 +18,12 @@ limitations under the License.
#include "tensorflow/core/platform/platform.h"
+// No Cord implementation on Android
// Include appropriate platform-dependent implementations
-#if defined(PLATFORM_GOOGLE)
-#include "tensorflow/core/platform/google/cord.h"
-#else
-#include "tensorflow/core/platform/default/cord.h"
-#endif
+//#if defined(PLATFORM_GOOGLE)
+//#include "tensorflow/core/platform/google/cord.h"
+//#else
+//#include "tensorflow/core/platform/default/cord.h"
+//#endif
#endif // TENSORFLOW_CORE_PLATFORM_CORD_H_
diff --git a/tensorflow/core/platform/default/logging.cc b/tensorflow/core/platform/default/logging.cc
index cafb3734302..e24895f44b2 100644
--- a/tensorflow/core/platform/default/logging.cc
+++ b/tensorflow/core/platform/default/logging.cc
@@ -41,11 +41,16 @@ limitations under the License.
#include <queue>
#include <unordered_map>
+#ifdef __ANDROID__
+#include <unistd.h>
+#endif
+
namespace tensorflow {
namespace internal {
namespace {
+#ifdef TF_ANDROID_ENABLE_LOGSINK
// This is an internal singleton class that manages the log sinks. It allows
// adding and removing the log sinks, as well as handling sending log messages
// to all the registered log sinks.
@@ -103,7 +108,6 @@ TFLogSinks& TFLogSinks::Instance() {
static TFLogSinks* instance = new TFLogSinks();
return *instance;
}
-#endif // TF_ANDROID_ENABLE_LOGSINK
void TFLogSinks::Add(TFLogSink* sink) {
assert(sink != nullptr && "The sink must not be a nullptr");
@@ -166,6 +170,7 @@ void TFLogSinks::SendToSink(TFLogSink& sink, const TFLogEntry& entry) {
sink.Send(entry);
sink.WaitTillSent();
}
+#endif // TF_ANDROID_ENABLE_LOGSINK
int ParseInteger(const char* str, size_t size) {
// Ideally we would use env_var / safe_strto64, but it is
@@ -253,14 +258,12 @@ VmoduleMap* VmodulesMapFromEnv() {
return result;
}
-#if !defined(PLATFORM_POSIX_ANDROID)
bool EmitThreadIdFromEnv() {
const char* tf_env_var_val = getenv("TF_CPP_LOG_THREAD_ID");
return tf_env_var_val == nullptr
? false
: ParseInteger(tf_env_var_val, strlen(tf_env_var_val)) != 0;
}
-#endif
} // namespace
@@ -312,7 +315,26 @@ LogMessage::~LogMessage() {
}
void LogMessage::GenerateLogMessage() {
+#ifdef TF_ANDROID_ENABLE_LOGSINK
TFLogSinks::Instance().Send(TFLogEntry(severity_, fname_, line_, str()));
+#else
+ static bool log_thread_id = EmitThreadIdFromEnv();
+ uint64 now_micros = EnvTime::NowMicros();
+ time_t now_seconds = static_cast<time_t>(now_micros / 1000000);
+ int32 micros_remainder = static_cast<int32>(now_micros % 1000000);
+ const size_t time_buffer_size = 30;
+ char time_buffer[time_buffer_size];
+ strftime(time_buffer, time_buffer_size, "%Y-%m-%d %H:%M:%S",
+ localtime(&now_seconds));
+ const size_t tid_buffer_size = 10;
+ char tid_buffer[tid_buffer_size] = "";
+ if (log_thread_id) {
+ snprintf(tid_buffer, sizeof(tid_buffer), " %7u", gettid());
+ }
+ // TODO(jeff,sanjay): Replace this with something that logs through the env.
+ fprintf(stderr, "%s.%06d: %c%s %s:%d] %s\n", time_buffer, micros_remainder,
+ "IWEF"[severity_], tid_buffer, fname_, line_, str().c_str());
+#endif // TF_ANDROID_ENABLE_LOGSINK
}
int64 LogMessage::MaxVLogLevel() {
@@ -412,6 +434,7 @@ uint32 LossyIncrement(std::atomic<uint32>* counter) {
counter->store(value + 1, std::memory_order_relaxed);
return value;
}
+
} // namespace
bool LogEveryNState::ShouldLog(int n) {
@@ -450,6 +473,7 @@ bool LogEveryNSecState::ShouldLog(double seconds) {
} // namespace internal
+#ifdef TF_ANDROID_ENABLE_LOGSINK
void TFAddLogSink(TFLogSink* sink) {
internal::TFLogSinks::Instance().Add(sink);
}
@@ -549,5 +573,6 @@ void TFDefaultLogSink::Send(const TFLogEntry& entry) {
entry.ToString().c_str());
#endif // PLATFORM_POSIX_ANDROID
}
+#endif // TF_ANDROID_ENABLE_LOGSINK
} // namespace tensorflow
diff --git a/tensorflow/core/platform/default/logging.h b/tensorflow/core/platform/default/logging.h
index 5aebaf95d00..cd2816afab8 100644
--- a/tensorflow/core/platform/default/logging.h
+++ b/tensorflow/core/platform/default/logging.h
@@ -544,9 +544,9 @@ class TFDefaultLogSink : public TFLogSink {
// Add or remove a `LogSink` as a consumer of logging data. Thread-safe.
void TFAddLogSink(TFLogSink* sink);
void TFRemoveLogSink(TFLogSink* sink);
-
// Get all the log sinks. Thread-safe.
std::vector<TFLogSink*> TFGetLogSinks();
+#endif // TF_ANDROID_ENABLE_LOGSINK
} // namespace tensorflow
diff --git a/tensorflow/lite/Android.bp b/tensorflow/lite/Android.bp
index 7abde66788c..baf2e9fa581 100644
--- a/tensorflow/lite/Android.bp
+++ b/tensorflow/lite/Android.bp
@@ -65,52 +65,47 @@ cc_library_static {
"core/subgraph.cc",
"delegates/nnapi/nnapi_delegate.cc",
"delegates/nnapi/quant_lstm_sup.cc",
+ "experimental/resource/resource_variable.cc",
"external_cpu_backend_context.cc",
"graph_info.cc",
"interpreter.cc",
+ "interpreter_builder.cc",
+ "kernels/cpu_backend_context.cc",
+ "kernels/cpu_backend_gemm_eigen.cc",
+ "kernels/eigen_support.cc",
"minimal_logging.cc",
"minimal_logging_android.cc",
"mmap_allocation.cc",
- "model.cc",
+ "model_builder.cc",
"mutable_op_resolver.cc",
"nnapi/nnapi_implementation.cc",
"nnapi/nnapi_util.cc",
"optional_debug_tools.cc",
+ "profiling/atrace_profiler.cc",
+ "profiling/platform_profiler.cc",
+ "schema/schema_utils.cc",
"simple_memory_arena.cc",
"stderr_reporter.cc",
"string_util.cc",
+ "tflite_with_xnnpack_optional.cc",
"tools/optimize/sparsity/format_converter.cc",
"util.cc",
- "kernels/cpu_backend_context.cc",
- "kernels/cpu_backend_gemm_eigen.cc",
- "kernels/eigen_support.cc",
- "experimental/resource/resource_variable.cc",
- "experimental/ruy/allocator.cc",
- "experimental/ruy/block_map.cc",
- "experimental/ruy/blocking_counter.cc",
- "experimental/ruy/context.cc",
- "experimental/ruy/detect_arm.cc",
- "experimental/ruy/detect_x86.cc",
- "experimental/ruy/have_built_path_for_avx2.cc",
- "experimental/ruy/have_built_path_for_avx512.cc",
- "experimental/ruy/have_built_path_for_avxvnni.cc",
- "experimental/ruy/have_built_path_for_sse42.cc",
- "experimental/ruy/kernel_arm32.cc",
- "experimental/ruy/kernel_arm64.cc",
- "experimental/ruy/pack_arm.cc",
- "experimental/ruy/prepacked_cache.cc",
- "experimental/ruy/thread_pool.cc",
- "experimental/ruy/trmul.cc",
- "experimental/ruy/tune.cc",
- "experimental/ruy/wait.cc",
+ ],
+ include_dirs: [
+ "external/libtextclassifier/native/",
+ ],
+ whole_static_libs: [
+ "libtextclassifier_hash_static",
],
header_libs: [
- "libeigen",
"flatbuffer_headers",
- "libbase_headers",
"gemmlowp_headers",
+ "libbase_headers",
+ "libeigen",
+ "libruy_headers",
],
cflags: [
+ "-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
"-Wno-deprecated-declarations",
"-Wno-extern-c-compat",
"-Wno-ignored-attributes",
@@ -118,6 +113,7 @@ cc_library_static {
"-Wno-mismatched-tags",
"-Wno-sign-compare",
"-Wno-unused-const-variable",
+ "-Wno-unused-function",
"-Wno-unused-lambda-capture",
],
}
@@ -126,8 +122,9 @@ cc_library_shared {
name: "libtflite",
defaults: ["tflite_defaults"],
shared_libs: [
- "libtextclassifier_hash",
"libflatbuffers-cpp",
+ "libruy",
+ "libtextclassifier_hash",
],
whole_static_libs: [
"libtflite_context",
diff --git a/tensorflow/lite/delegates/nnapi/java/Android.bp b/tensorflow/lite/delegates/nnapi/java/Android.bp
index a38e0430819..b6ac98840a0 100644
--- a/tensorflow/lite/delegates/nnapi/java/Android.bp
+++ b/tensorflow/lite/delegates/nnapi/java/Android.bp
@@ -27,6 +27,6 @@ filegroup {
"src/main/java/org/tensorflow/lite/nnapi/*.java",
],
visibility: [
- "//visibility:public"
+ "//visibility:public",
],
}
diff --git a/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc b/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc
index 5e3acc31c75..30d599aa104 100644
--- a/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc
+++ b/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc
@@ -57,7 +57,7 @@ limitations under the License.
#include "tensorflow/lite/nnapi/nnapi_implementation.h"
#include "tensorflow/lite/nnapi/nnapi_util.h"
#include "tensorflow/lite/util.h"
-#include <farmhash.h>
+#include "utils/hash/farmhash.h"
namespace tflite {
namespace {
@@ -3665,7 +3665,7 @@ TfLiteStatus NNAPIDelegateKernel::Init(TfLiteContext* context,
// Using farmhash fingerprint instead of std::hash, as the latter is not
// guaranteed to be stable across program invocations.
token_parts[0] =
- ::util::Fingerprint64(model_token, std::strlen(model_token));
+ farmhash::Fingerprint64(model_token, std::strlen(model_token));
// Create bits from params->nodes_to_replace.
token_parts[1] = GetHash(params->nodes_to_replace);
// Create bits from params->input_tensors. These include the input tensor
diff --git a/tensorflow/lite/java/Android.bp b/tensorflow/lite/java/Android.bp
index ee8da5b28c1..c51227379a1 100644
--- a/tensorflow/lite/java/Android.bp
+++ b/tensorflow/lite/java/Android.bp
@@ -45,19 +45,20 @@ cc_library_shared {
"src/main/native/*.cc",
],
header_libs: [
+ "flatbuffer_headers",
"jni_headers",
"tensorflow_headers",
- "flatbuffer_headers",
],
static_libs: [
+ "libruy_static",
"libtflite_static",
],
shared_libs: [
"liblog",
],
cflags: [
- "-Wno-unused-parameter",
"-Wno-unused-function",
+ "-Wno-unused-parameter",
],
stl: "libc++_static",
}
diff --git a/tensorflow/lite/kernels/Android.bp b/tensorflow/lite/kernels/Android.bp
index e2f691ab79c..325daf3185c 100644
--- a/tensorflow/lite/kernels/Android.bp
+++ b/tensorflow/lite/kernels/Android.bp
@@ -26,29 +26,32 @@ cc_library_static {
defaults: ["tflite_defaults"],
vendor_available: true,
apex_available: [
+ "//apex_available:platform",
"com.android.neuralnetworks",
"test_com.android.neuralnetworks",
- "//apex_available:platform",
],
srcs: [
- "kernel_util.cc",
- "internal/tensor_utils.cc",
- "internal/transpose_utils.cc",
- "internal/quantization_util.cc",
- "internal/reference/portable_tensor_utils.cc",
"internal/optimized/neon_tensor_utils.cc",
"internal/optimized/sse_tensor_utils.cc",
+ "internal/quantization_util.cc",
+ "internal/reference/portable_tensor_utils.cc",
+ "internal/tensor_utils.cc",
+ "internal/transpose_utils.cc",
+ "kernel_util.cc",
],
header_libs: [
"flatbuffer_headers",
"gemmlowp_headers",
"libeigen",
],
+ static_libs: [
+ "libruy_static",
+ ],
cflags: [
"-Wno-extern-c-compat",
"-Wno-sign-compare",
"-Wno-unused-function",
- ]
+ ],
}
cc_library_static {
@@ -60,14 +63,20 @@ cc_library_static {
"add_n.cc",
"arg_min_max.cc",
"basic_rnn.cc",
+ "batch_matmul.cc",
"batch_to_space_nd.cc",
"bidirectional_sequence_lstm.cc",
"bidirectional_sequence_rnn.cc",
+ "broadcast_to.cc",
+ "call_once.cc",
"cast.cc",
"ceil.cc",
"comparisons.cc",
+ "complex_support.cc",
"concatenation.cc",
"conv.cc",
+ "conv3d.cc",
+ "cumsum.cc",
"densify.cc",
"depth_to_space.cc",
"depthwise_conv.cc",
@@ -89,6 +98,14 @@ cc_library_static {
"gather_nd.cc",
"hashtable_lookup.cc",
"if.cc",
+ "internal/kernel_utils.cc",
+ "internal/optimized/cpu_check.cc",
+ "internal/optimized/neon_tensor_utils.cc",
+ "internal/optimized/sse_tensor_utils.cc",
+ "internal/quantization_util.cc",
+ "internal/reference/portable_tensor_utils.cc",
+ "internal/tensor_utils.cc",
+ "internal/transpose_utils.cc",
"kernel_util.cc",
"l2norm.cc",
"local_response_norm.cc",
@@ -105,8 +122,8 @@ cc_library_static {
"non_max_suppression.cc",
"numeric_verify.cc",
"one_hot.cc",
- "pad.cc",
"pack.cc",
+ "pad.cc",
"pooling.cc",
"pow.cc",
"quantize.cc",
@@ -114,11 +131,11 @@ cc_library_static {
"rank.cc",
"reduce.cc",
"register.cc",
- "reverse.cc",
- "reverse_sequence.cc",
"reshape.cc",
"resize_bilinear.cc",
"resize_nearest_neighbor.cc",
+ "reverse.cc",
+ "reverse_sequence.cc",
"round.cc",
"scatter_nd.cc",
"segment_sum.cc",
@@ -147,32 +164,26 @@ cc_library_static {
"where.cc",
"while.cc",
"zeros_like.cc",
- "internal/kernel_utils.cc",
- "internal/tensor_utils.cc",
- "internal/transpose_utils.cc",
- "internal/quantization_util.cc",
- "internal/reference/portable_tensor_utils.cc",
- "internal/optimized/neon_tensor_utils.cc",
- "internal/optimized/sse_tensor_utils.cc",
],
header_libs: [
"flatbuffer_headers",
"gemmlowp_headers",
"libeigen",
+ "libruy_headers",
"libtextclassifier_hash_headers",
],
cflags: [
"-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
"-Wno-array-bounds",
"-Wno-extern-c-compat",
- "-Wno-invalid-partial-specialization",
"-Wno-ignored-attributes",
+ "-Wno-invalid-partial-specialization",
+ "-Wno-mismatched-tags",
"-Wno-missing-field-initializers",
"-Wno-sign-compare",
- "-Wno-unused-local-typedef",
"-Wno-unused-function",
- "-Wno-unused-variable",
+ "-Wno-unused-local-typedef",
"-Wno-unused-private-field",
- "-Wno-mismatched-tags",
+ "-Wno-unused-variable",
],
}
diff --git a/tensorflow/lite/kernels/acceleration_test_util.cc b/tensorflow/lite/kernels/acceleration_test_util.cc
index 741c34d9672..6dbb0bd554b 100644
--- a/tensorflow/lite/kernels/acceleration_test_util.cc
+++ b/tensorflow/lite/kernels/acceleration_test_util.cc
@@ -18,7 +18,6 @@ limitations under the License.
#include <string>
#include <gtest/gtest.h>
-#include "absl/types/optional.h"
namespace tflite {
diff --git a/tensorflow/lite/kernels/acceleration_test_util_internal.h b/tensorflow/lite/kernels/acceleration_test_util_internal.h
index cd3fca1e609..50990242455 100644
--- a/tensorflow/lite/kernels/acceleration_test_util_internal.h
+++ b/tensorflow/lite/kernels/acceleration_test_util_internal.h
@@ -18,13 +18,11 @@ limitations under the License.
#include <algorithm>
#include <atomic>
#include <functional>
+#include <optional>
#include <iterator>
#include <string>
#include <vector>
-#include "absl/types/optional.h"
-#include "re2/re2.h"
-
namespace tflite {
// Reads the acceleration configuration, handles comments and empty lines and
@@ -93,7 +91,7 @@ std::optional<T> GetAccelerationTestParam(std::string test_id) {
[&test_id](ConfigurationEntry<T> elem) { return elem.Matches(test_id); });
if (test_config_iter != test_config->end() &&
!test_config_iter->IsDenylistEntry()) {
- return absl::optional<T>(test_config_iter->TestConfig());
+ return std::optional<T>(test_config_iter->TestConfig());
} else {
return std::optional<T>();
}
diff --git a/tensorflow/lite/kernels/dequantize.h b/tensorflow/lite/kernels/dequantize.h
index 30739eb2c57..c3ae62625d1 100644
--- a/tensorflow/lite/kernels/dequantize.h
+++ b/tensorflow/lite/kernels/dequantize.h
@@ -17,7 +17,7 @@ limitations under the License.
#include <stdint.h>
-#include "third_party/eigen3/Eigen/Core"
+#include "Eigen/Core"
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/kernels/internal/optimized/optimized_ops.h"
#include "tensorflow/lite/kernels/internal/reference/dequantize.h"
diff --git a/tensorflow/lite/kernels/internal/optimized/neon_tensor_utils.cc b/tensorflow/lite/kernels/internal/optimized/neon_tensor_utils.cc
index ca80676d646..fe0df637992 100644
--- a/tensorflow/lite/kernels/internal/optimized/neon_tensor_utils.cc
+++ b/tensorflow/lite/kernels/internal/optimized/neon_tensor_utils.cc
@@ -40,7 +40,8 @@ limitations under the License.
#if !defined(__ANDROID__) || __ANDROID_API__ >= 28
// Neither Apple nor Windows provide aligned_alloc.
#if !defined(__APPLE__) && !defined(_WIN32)
-#define TFLITE_USE_STD_ALIGNED_ALLOC
+// TODO(miaowang): Re-enable std::aligned_alloc when it is avalaible in Android.
+// #define TFLITE_USE_STD_ALIGNED_ALLOC
#endif
#endif
#endif
diff --git a/tensorflow/lite/kernels/internal/reference/reference_ops.h b/tensorflow/lite/kernels/internal/reference/reference_ops.h
index 49e390ab261..98cf9bb9ab2 100644
--- a/tensorflow/lite/kernels/internal/reference/reference_ops.h
+++ b/tensorflow/lite/kernels/internal/reference/reference_ops.h
@@ -19,6 +19,7 @@ limitations under the License.
#include <sys/types.h>
#include <algorithm>
+#include <array>
#include <cmath>
#include <cstring>
#include <functional>
diff --git a/tensorflow/lite/kernels/lsh_projection.cc b/tensorflow/lite/kernels/lsh_projection.cc
index 84aa23e5df3..232fc3534c9 100644
--- a/tensorflow/lite/kernels/lsh_projection.cc
+++ b/tensorflow/lite/kernels/lsh_projection.cc
@@ -60,7 +60,7 @@ limitations under the License.
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
#include "tensorflow/lite/kernels/kernel_util.h"
-#include <farmhash.h>
+#include "utils/hash/farmhash.h"
namespace tflite {
namespace ops {
diff --git a/tensorflow/lite/kernels/register.cc b/tensorflow/lite/kernels/register.cc
index 840377148b3..34346d8e741 100644
--- a/tensorflow/lite/kernels/register.cc
+++ b/tensorflow/lite/kernels/register.cc
@@ -311,7 +311,8 @@ BuiltinOpResolver::BuiltinOpResolver() {
/* max_version = */ 3);
AddBuiltin(BuiltinOperator_CALL_ONCE,
tflite::ops::builtin::Register_CALL_ONCE());
- AddBuiltin(BuiltinOperator_RFFT2D, Register_RFFT2D());
+ // TODO: reenable once fft2d is imported to Android
+ //AddBuiltin(BuiltinOperator_RFFT2D, Register_RFFT2D());
AddBuiltin(BuiltinOperator_CONV_3D, Register_CONV_3D());
AddBuiltin(BuiltinOperator_IMAG, Register_IMAG());
AddBuiltin(BuiltinOperator_REAL, Register_REAL());
diff --git a/tensorflow/lite/profiling/atrace_profiler.cc b/tensorflow/lite/profiling/atrace_profiler.cc
index ec796daf7f2..07612489814 100644
--- a/tensorflow/lite/profiling/atrace_profiler.cc
+++ b/tensorflow/lite/profiling/atrace_profiler.cc
@@ -21,7 +21,7 @@ limitations under the License.
#include <type_traits>
-#include "absl/strings/str_cat.h"
+#include <string>
namespace tflite {
namespace profiling {
@@ -71,8 +71,9 @@ class ATraceProfiler : public tflite::Profiler {
// Regardless the 'event_type', we encode the perfetto event name as
// tag@event_metadata1/event_metadata2. In case of OPERATOR_INVOKE_EVENT,
// the perfetto event name will be op_name@node_index/subgraph_index
- std::string trace_event_tag =
- absl::StrCat(tag, "@", event_metadata1, "/", event_metadata2);
+ std::string trace_event_tag = std::string(tag) + "@" +
+ std::to_string(event_metadata1) + "/" +
+ std::to_string(event_metadata2);
atrace_begin_section_(trace_event_tag.c_str());
}
return 0;
diff --git a/tensorflow/lite/testing/nnapi_tflite_zip_tests/Android.bp b/tensorflow/lite/testing/nnapi_tflite_zip_tests/Android.bp
index bc101512fcc..783ab3a471a 100644
--- a/tensorflow/lite/testing/nnapi_tflite_zip_tests/Android.bp
+++ b/tensorflow/lite/testing/nnapi_tflite_zip_tests/Android.bp
@@ -12,10 +12,10 @@ cc_test {
sdk_version: "current",
srcs: [
"generated_examples_zip_test.cc",
+ "message.cc",
"parse_testdata.cc",
- "tflite_driver.cc",
"split.cc",
- "message.cc",
+ "tflite_driver.cc",
"tokenize.cc",
],
data: [
@@ -38,8 +38,9 @@ cc_test {
],
stl: "libc++_static",
static_libs: [
- "libtflite_static",
"libgmock_ndk",
+ "libruy_static",
+ "libtflite_static",
],
shared_libs: [
"liblog",
diff --git a/tensorflow/lite/tflite_static.bp b/tensorflow/lite/tflite_static.bp
index 918ea3d13bc..1d962fd237a 100644
--- a/tensorflow/lite/tflite_static.bp
+++ b/tensorflow/lite/tflite_static.bp
@@ -28,39 +28,35 @@ cc_library_static {
"core/api/op_resolver.cc",
"core/api/tensor_utils.cc",
"core/subgraph.cc",
+ "create_op_resolver_with_builtin_ops.cc",
"delegates/nnapi/nnapi_delegate.cc",
"delegates/nnapi/quant_lstm_sup.cc",
+ "experimental/resource/resource_variable.cc",
"external_cpu_backend_context.cc",
"graph_info.cc",
"interpreter.cc",
- "minimal_logging.cc",
- "minimal_logging_android.cc",
- "mmap_allocation.cc",
- "model.cc",
- "mutable_op_resolver.cc",
- "optional_debug_tools.cc",
- "simple_memory_arena.cc",
- "stderr_reporter.cc",
- "string_util.cc",
- "util.cc",
- "kernels/elementwise.cc",
- "kernels/split.cc",
- "kernels/topk_v2.cc",
+ "interpreter_builder.cc",
"kernels/activations.cc",
"kernels/add.cc",
"kernels/add_n.cc",
"kernels/arg_min_max.cc",
"kernels/basic_rnn.cc",
+ "kernels/batch_matmul.cc",
"kernels/batch_to_space_nd.cc",
"kernels/bidirectional_sequence_lstm.cc",
"kernels/bidirectional_sequence_rnn.cc",
+ "kernels/broadcast_to.cc",
+ "kernels/call_once.cc",
"kernels/cast.cc",
"kernels/ceil.cc",
"kernels/comparisons.cc",
+ "kernels/complex_support.cc",
"kernels/concatenation.cc",
"kernels/conv.cc",
+ "kernels/conv3d.cc",
"kernels/cpu_backend_context.cc",
"kernels/cpu_backend_gemm_eigen.cc",
+ "kernels/cumsum.cc",
"kernels/densify.cc",
"kernels/depth_to_space.cc",
"kernels/depthwise_conv.cc",
@@ -68,12 +64,13 @@ cc_library_static {
"kernels/detection_postprocess.cc",
"kernels/div.cc",
"kernels/eigen_support.cc",
+ "kernels/elementwise.cc",
"kernels/embedding_lookup.cc",
"kernels/embedding_lookup_sparse.cc",
"kernels/exp.cc",
"kernels/expand_dims.cc",
- "kernels/fill.cc",
"kernels/fake_quant.cc",
+ "kernels/fill.cc",
"kernels/floor.cc",
"kernels/floor_div.cc",
"kernels/floor_mod.cc",
@@ -82,6 +79,14 @@ cc_library_static {
"kernels/gather_nd.cc",
"kernels/hashtable_lookup.cc",
"kernels/if.cc",
+ "kernels/internal/kernel_utils.cc",
+ "kernels/internal/optimized/cpu_check.cc",
+ "kernels/internal/optimized/neon_tensor_utils.cc",
+ "kernels/internal/optimized/sse_tensor_utils.cc",
+ "kernels/internal/quantization_util.cc",
+ "kernels/internal/reference/portable_tensor_utils.cc",
+ "kernels/internal/tensor_utils.cc",
+ "kernels/internal/transpose_utils.cc",
"kernels/kernel_util.cc",
"kernels/l2norm.cc",
"kernels/local_response_norm.cc",
@@ -98,8 +103,8 @@ cc_library_static {
"kernels/non_max_suppression.cc",
"kernels/numeric_verify.cc",
"kernels/one_hot.cc",
- "kernels/pad.cc",
"kernels/pack.cc",
+ "kernels/pad.cc",
"kernels/pooling.cc",
"kernels/pow.cc",
"kernels/quantize.cc",
@@ -123,13 +128,16 @@ cc_library_static {
"kernels/space_to_batch_nd.cc",
"kernels/space_to_depth.cc",
"kernels/sparse_to_dense.cc",
+ "kernels/split.cc",
"kernels/split_v.cc",
- "kernels/squeeze.cc",
"kernels/squared_difference.cc",
+ "kernels/squeeze.cc",
"kernels/strided_slice.cc",
"kernels/sub.cc",
"kernels/svdf.cc",
+ "kernels/test_delegate_providers.cc",
"kernels/tile.cc",
+ "kernels/topk_v2.cc",
"kernels/transpose.cc",
"kernels/transpose_conv.cc",
"kernels/unidirectional_sequence_lstm.cc",
@@ -139,37 +147,29 @@ cc_library_static {
"kernels/where.cc",
"kernels/while.cc",
"kernels/zeros_like.cc",
- "kernels/internal/kernel_utils.cc",
- "kernels/internal/tensor_utils.cc",
- "kernels/internal/transpose_utils.cc",
- "kernels/internal/quantization_util.cc",
- "kernels/internal/reference/portable_tensor_utils.cc",
- "kernels/internal/optimized/neon_tensor_utils.cc",
- "kernels/internal/optimized/sse_tensor_utils.cc",
+ "minimal_logging.cc",
+ "minimal_logging_android.cc",
+ "mmap_allocation.cc",
+ "model_builder.cc",
+ "mutable_op_resolver.cc",
"nnapi/nnapi_implementation.cc",
"nnapi/nnapi_util.cc",
- "experimental/resource/resource_variable.cc",
- "experimental/ruy/allocator.cc",
- "experimental/ruy/block_map.cc",
- "experimental/ruy/blocking_counter.cc",
- "experimental/ruy/context.cc",
- "experimental/ruy/detect_arm.cc",
- "experimental/ruy/detect_x86.cc",
- "experimental/ruy/have_built_path_for_avx2.cc",
- "experimental/ruy/have_built_path_for_avx512.cc",
- "experimental/ruy/have_built_path_for_avxvnni.cc",
- "experimental/ruy/have_built_path_for_sse42.cc",
- "experimental/ruy/kernel_arm64.cc",
- "experimental/ruy/kernel_arm32.cc",
- "experimental/ruy/pack_arm.cc",
- "experimental/ruy/prepacked_cache.cc",
- "experimental/ruy/thread_pool.cc",
- "experimental/ruy/trmul.cc",
- "experimental/ruy/tune.cc",
- "experimental/ruy/wait.cc",
+ "optional_debug_tools.cc",
+ "profiling/atrace_profiler.cc",
+ "profiling/platform_profiler.cc",
+ "schema/schema_conversion_utils.cc",
+ "schema/schema_utils.cc",
+ "simple_memory_arena.cc",
+ "stderr_reporter.cc",
+ "string_util.cc",
+ "tflite_with_xnnpack_optional.cc",
"tools/optimize/sparsity/format_converter.cc",
+ "tools/tool_params.cc",
+ "tools/versioning/op_version.cc",
+ "util.cc",
],
header_libs: ["liblog_headers"],
+ generated_headers: ["libtflite_mutable_schema"],
include_dirs: [
"external/eigen",
"external/flatbuffers/include",
@@ -178,11 +178,12 @@ cc_library_static {
"external/tensorflow",
],
whole_static_libs: [
+ "libruy_static",
"libtextclassifier_hash_static",
],
cflags: [
- "-DTF_LITE_DISABLE_X86_NEON",
"-DNAMESPACE_FOR_HASH_FUNCTIONS=farmhash",
+ "-DTF_LITE_DISABLE_X86_NEON",
"-Wall",
"-Werror",
"-Wextra",
@@ -190,6 +191,8 @@ cc_library_static {
"-Wno-deprecated-declarations",
"-Wno-extern-c-compat",
"-Wno-invalid-partial-specialization",
+ "-Wno-invalid-partial-specialization",
+ "-Wno-mismatched-tags",
"-Wno-mismatched-tags",
"-Wno-missing-field-initializers",
"-Wno-sign-compare",
@@ -200,8 +203,6 @@ cc_library_static {
"-Wno-unused-parameter",
"-Wno-unused-private-field",
"-Wno-unused-variable",
- "-Wno-invalid-partial-specialization",
- "-Wno-mismatched-tags",
"-Wno-visibility",
],
stl: "libc++_static",
@@ -211,3 +212,14 @@ cc_library_static {
"com.android.extservices",
],
}
+
+// Header library for CTS target
+cc_library_headers {
+ name: "libtflite_schema_headers",
+ generated_headers: [
+ "libtflite_mutable_schema",
+ ],
+ export_generated_headers: [
+ "libtflite_mutable_schema",
+ ],
+}
diff --git a/tensorflow/lite/tools/optimize/sparsity/format_converter.h b/tensorflow/lite/tools/optimize/sparsity/format_converter.h
index 1ac324c7d1b..f92aeb4876f 100644
--- a/tensorflow/lite/tools/optimize/sparsity/format_converter.h
+++ b/tensorflow/lite/tools/optimize/sparsity/format_converter.h
@@ -17,7 +17,7 @@ limitations under the License.
#include <vector>
-#include "third_party/eigen3/Eigen/Core"
+#include "Eigen/Core"
#include "tensorflow/lite/c/common.h"
namespace tflite {
diff --git a/tensorflow/lite/tools/versioning/op_version.cc b/tensorflow/lite/tools/versioning/op_version.cc
index 44d8ecee934..28b22a6f81e 100644
--- a/tensorflow/lite/tools/versioning/op_version.cc
+++ b/tensorflow/lite/tools/versioning/op_version.cc
@@ -19,9 +19,6 @@ limitations under the License.
#include <utility>
#include <vector>
-#include "absl/memory/memory.h"
-#include "absl/strings/numbers.h"
-#include "absl/strings/str_split.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/lite/kernels/internal/compatibility.h"
#include "tensorflow/lite/schema/schema_generated.h"