From d051fb76118dec53fddb49e58c04310d0d8a1f68 Mon Sep 17 00:00:00 2001 From: Advait Jain Date: Fri, 11 Dec 2020 16:38:02 -0800 Subject: [PATCH] Build xtensa for Vision P6. Confirmed that all tests pass for vision P6: ``` make -f tensorflow/lite/micro/tools/make/Makefile TARGET=xtensa OPTIMIZED_KERNEL_DIR=xtensa TARGET_ARCH=vision_p6 XTENSA_CORE=P6_200528 test ``` --- tensorflow/lite/micro/kernels/BUILD | 24 ++++++++++++++++++- tensorflow/lite/micro/kernels/xtensa/conv.cc | 6 ++--- .../micro/kernels/xtensa/depthwise_conv.cc | 6 ++--- .../micro/kernels/xtensa/fixedpoint_utils.h | 7 ++++-- .../micro/kernels/xtensa/fully_connected.cc | 6 ++--- .../lite/micro/kernels/xtensa/quantize.cc | 3 +-- .../lite/micro/kernels/xtensa/softmax.cc | 3 +-- tensorflow/lite/micro/kernels/xtensa/svdf.cc | 7 +++--- tensorflow/lite/micro/kernels/xtensa/xtensa.h | 23 ++++++++++++++++++ 9 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 tensorflow/lite/micro/kernels/xtensa/xtensa.h diff --git a/tensorflow/lite/micro/kernels/BUILD b/tensorflow/lite/micro/kernels/BUILD index a6590780f5a..6dba309a2e3 100644 --- a/tensorflow/lite/micro/kernels/BUILD +++ b/tensorflow/lite/micro/kernels/BUILD @@ -34,7 +34,9 @@ cc_library( ], }), copts = micro_copts(), - deps = select({ + deps = [ + ":xtensa", + ] + select({ "//conditions:default": [], ":xtensa_hifimini": [ #"//third_party/xtensa/cstub64s:hifi_mini", @@ -62,6 +64,7 @@ cc_library( deps = [ ":fixedpoint_utils", ":kernel_util", + ":xtensa", "//tensorflow/lite/c:common", "//tensorflow/lite/kernels:kernel_util", "//tensorflow/lite/kernels/internal:common", @@ -162,6 +165,7 @@ cc_library( ":kernel_util", ":fixedpoint_utils", ":micro_utils", + ":xtensa", "//tensorflow/lite/c:common", "//tensorflow/lite/kernels:kernel_util", "//tensorflow/lite/kernels:op_macros", @@ -183,6 +187,24 @@ cc_library( }), ) +cc_library( + name = "xtensa", + hdrs = select({ + "//conditions:default": [ + ], + ":xtensa_hifimini": [ + "xtensa/xtensa.h", + ], + }), + copts = micro_copts(), + deps = select({ + "//conditions:default": [], + ":xtensa_hifimini": [ + #"//third_party/xtensa/cstub64s:hifi_mini", + ], + }), +) + test_suite( name = "all_tests", ) diff --git a/tensorflow/lite/micro/kernels/xtensa/conv.cc b/tensorflow/lite/micro/kernels/xtensa/conv.cc index 80de57d7bd9..290b23638e7 100644 --- a/tensorflow/lite/micro/kernels/xtensa/conv.cc +++ b/tensorflow/lite/micro/kernels/xtensa/conv.cc @@ -13,20 +13,18 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "tensorflow/lite/kernels/internal/reference/conv.h" - -#include - #include "tensorflow/lite/c/builtin_op_data.h" #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/kernels/internal/common.h" #include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/conv.h" #include "tensorflow/lite/kernels/internal/reference/integer_ops/conv.h" #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/kernels/padding.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" #include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" namespace tflite { namespace { diff --git a/tensorflow/lite/micro/kernels/xtensa/depthwise_conv.cc b/tensorflow/lite/micro/kernels/xtensa/depthwise_conv.cc index 58d9f563147..7446a9651a2 100644 --- a/tensorflow/lite/micro/kernels/xtensa/depthwise_conv.cc +++ b/tensorflow/lite/micro/kernels/xtensa/depthwise_conv.cc @@ -13,21 +13,19 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h" - -#include - #include "tensorflow/lite/c/builtin_op_data.h" #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/kernels/internal/common.h" #include "tensorflow/lite/kernels/internal/quantization_util.h" #include "tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h" #include "tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h" #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/kernels/padding.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" #include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" namespace tflite { namespace { diff --git a/tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h b/tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h index a1d14df1352..2f8a4bd26a8 100644 --- a/tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h +++ b/tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h @@ -16,16 +16,17 @@ limitations under the License. #ifndef TENSORFLOW_LITE_MICRO_KERNELS_XTENSA_HIFIMINI_FIXEDPOINT_UTILS_H_ #define TENSORFLOW_LITE_MICRO_KERNELS_XTENSA_HIFIMINI_FIXEDPOINT_UTILS_H_ -#include - #include #include #include #include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" namespace tflite { +#if defined(HIFIMINI) + // INT24 MIN/MAX #define INT24_MIN -8388608 #define INT24_MAX 8388607 @@ -132,6 +133,8 @@ inline int CreateQConstantForInt24(int integer_bits, float f) { return static_cast(raw); } +#endif // defined(HIFIMINI) + } // namespace tflite #endif // TENSORFLOW_LITE_MICRO_KERNELS_XTENSA_HIFIMINI_FIXEDPOINT_UTILS_H_ diff --git a/tensorflow/lite/micro/kernels/xtensa/fully_connected.cc b/tensorflow/lite/micro/kernels/xtensa/fully_connected.cc index 3b0a7d8a57a..c50d42b74ad 100644 --- a/tensorflow/lite/micro/kernels/xtensa/fully_connected.cc +++ b/tensorflow/lite/micro/kernels/xtensa/fully_connected.cc @@ -13,19 +13,17 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "tensorflow/lite/kernels/internal/reference/fully_connected.h" - -#include - #include "tensorflow/lite/c/builtin_op_data.h" #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/kernels/internal/common.h" #include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/fully_connected.h" #include "tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h" #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" #include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" namespace tflite { namespace { diff --git a/tensorflow/lite/micro/kernels/xtensa/quantize.cc b/tensorflow/lite/micro/kernels/xtensa/quantize.cc index b552131e698..7559281ee88 100644 --- a/tensorflow/lite/micro/kernels/xtensa/quantize.cc +++ b/tensorflow/lite/micro/kernels/xtensa/quantize.cc @@ -13,8 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include - #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/kernels/internal/quantization_util.h" #include "tensorflow/lite/kernels/internal/reference/quantize.h" @@ -24,6 +22,7 @@ limitations under the License. #include "tensorflow/lite/micro/kernels/kernel_util.h" #include "tensorflow/lite/micro/kernels/quantize.h" #include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" #include "tensorflow/lite/micro/micro_utils.h" namespace tflite { diff --git a/tensorflow/lite/micro/kernels/xtensa/softmax.cc b/tensorflow/lite/micro/kernels/xtensa/softmax.cc index 945e38dd9a8..4a29cf79ced 100644 --- a/tensorflow/lite/micro/kernels/xtensa/softmax.cc +++ b/tensorflow/lite/micro/kernels/xtensa/softmax.cc @@ -13,12 +13,11 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "tensorflow/lite/kernels/internal/reference/softmax.h" - #include "tensorflow/lite/c/builtin_op_data.h" #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/kernels/internal/common.h" #include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/softmax.h" #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/kernels/op_macros.h" diff --git a/tensorflow/lite/micro/kernels/xtensa/svdf.cc b/tensorflow/lite/micro/kernels/xtensa/svdf.cc index 33489e6b44f..3b51f1ba8bd 100644 --- a/tensorflow/lite/micro/kernels/xtensa/svdf.cc +++ b/tensorflow/lite/micro/kernels/xtensa/svdf.cc @@ -13,10 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "tensorflow/lite/micro/kernels/svdf.h" - -#include -#include +#include #include "tensorflow/lite/c/builtin_op_data.h" #include "tensorflow/lite/c/common.h" @@ -27,7 +24,9 @@ limitations under the License. #include "tensorflow/lite/kernels/op_macros.h" #include "tensorflow/lite/micro/kernels/activation_utils.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/svdf.h" #include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" namespace tflite { namespace { diff --git a/tensorflow/lite/micro/kernels/xtensa/xtensa.h b/tensorflow/lite/micro/kernels/xtensa/xtensa.h new file mode 100644 index 00000000000..7ada7f5906e --- /dev/null +++ b/tensorflow/lite/micro/kernels/xtensa/xtensa.h @@ -0,0 +1,23 @@ +/* Copyright 2020 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. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_XTENSA_XTENSA_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_XTENSA_XTENSA_H_ + +#if defined(HIFIMINI) +#include +#endif + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_XTENSA_XTENSA_H_