diff --git a/tensorflow/lite/micro/testing/test_xcore_binary.sh b/tensorflow/lite/micro/testing/test_xcore_binary.sh new file mode 100755 index 00000000000..e059968c885 --- /dev/null +++ b/tensorflow/lite/micro/testing/test_xcore_binary.sh @@ -0,0 +1,47 @@ +#!/bin/bash -e +# Copyright 2018 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. +# ============================================================================== +# +# Tests an XS3 binary by executing it using the XSIM simulator and parsing +# the log output. +# +# First argument is the binary location. +# Second argument is a regular expression that's required to be in the output +# logs for the test to pass. + +declare -r ROOT_DIR=`pwd` +declare -r TEST_TMPDIR=/tmp/test_xcore_binary/ +declare -r MICRO_LOG_PATH=${TEST_TMPDIR}/$1 +declare -r MICRO_LOG_FILENAME=${MICRO_LOG_PATH}/logs.txt +declare -r XCORE_ +mkdir -p ${MICRO_LOG_PATH} + +# Get the location of this script file as an absolute path +SCRIPT_PATH="`dirname \"$BASH_SOURCE\"`" +SCRIPT_PATH="`( cd \"$SCRIPT_PATH\" && pwd )`" +XSIM_FLAGS="" + + +xsim $1 ${XSIM_FLAGS} 2>&1 | tee ${MICRO_LOG_FILENAME} + +if grep -q "$2" ${MICRO_LOG_FILENAME} +then + echo "$1: PASS" + exit 0 +else + echo "$1: FAIL - '$2' not found in logs." + exit 1 +fi + diff --git a/tensorflow/lite/micro/tools/make/download_and_extract.sh b/tensorflow/lite/micro/tools/make/download_and_extract.sh index a403019d192..da9a474b004 100755 --- a/tensorflow/lite/micro/tools/make/download_and_extract.sh +++ b/tensorflow/lite/micro/tools/make/download_and_extract.sh @@ -137,6 +137,9 @@ download_and_extract() { exit 1 fi + # delete anything after the '?' in a url that may mask true file extension + url=$(echo "${url}" | sed "s/\?.*//") + if [[ "${url}" == *gz ]]; then tar -C "${dir}" --strip-components=1 -xzf ${tempfile} elif [[ "${url}" == *tar.xz ]]; then diff --git a/tensorflow/lite/micro/tools/make/targets/xcore_makefile.inc b/tensorflow/lite/micro/tools/make/targets/xcore_makefile.inc new file mode 100644 index 00000000000..9a0f7463688 --- /dev/null +++ b/tensorflow/lite/micro/tools/make/targets/xcore_makefile.inc @@ -0,0 +1,24 @@ +# Settings for XMOS XS3 based processors (xcore.ai, ...) + +#IMPORTANT: to set up environment variables correctly run the following from the top tensorflow directory: +# $ make -f tensorflow/lite/micro/tools/make/Makefile TARGET="xcore" clean clean_downloads test +# $ pushd tensorflow/lite/micro/tools/make/downloads/xtimecomposer/xTIMEcomposer/15.0.0/ && source SetEnv && popd +# $ make -f tensorflow/lite/micro/tools/make/Makefile TARGET="xcore" test + +ifeq ($(TARGET), xcore) + XTIME_URL := "https://www.xmos.com/download/Tools-15---Linux-64%2815.0.0_rc1%29.tgz?key=132D-9DC9-E913-0229-ECE6-D5AB-F511-2B19" + XTIME_MD5 := "8f6543c8ac4af7583edf75e62df322a2" + $(eval $(call add_third_party_download,$(XTIME_URL),$(XTIME_MD5),xtimecomposer)) + PLATFORM_FLAGS = -target=XU316-1024-FB265-C32 -mcmodel=large -Os -DXCORE -Wno-xcore-fptrgroup -report + CXX_TOOL := xcc + CC_TOOL := xcc + AR_TOOL := xmosar + override CXXFLAGS := -std=c++11 -g -DTF_LITE_STATIC_MEMORY -DNDEBUG + override CXXFLAGS += $(PLATFORM_FLAGS) + override CCFLAGS := -g -DTF_LITE_STATIC_MEMORY -DNDEBUG + override CCFLAGS += $(PLATFORM_FLAGS) + TARGET_ARCH := xcore + #TARGET_TOOLCHAIN_PREFIX := tensorflow/lite/micro/tools/make/downloads/xtimecomposer/bin/ + TEST_SCRIPT := tensorflow/lite/micro/testing/test_xcore_binary.sh + #GCC_XCORE := $(MAKEFILE_DIR)/downloads/xtimecomposer/bin/ +endif diff --git a/tensorflow/lite/micro/xcore/README.md b/tensorflow/lite/micro/xcore/README.md new file mode 100644 index 00000000000..796b73a8ca1 --- /dev/null +++ b/tensorflow/lite/micro/xcore/README.md @@ -0,0 +1,30 @@ +# Quickstart to install tools and run unit tests: + +``` +$ make -f tensorflow/lite/micro/tools/make/Makefile TARGET="xcore" clean clean_downloads && make -f tensorflow/lite/micro/tools/make/Makefile TARGET="xcore" test_greedy_memory_planner_test || true && pushd tensorflow/lite/micro/tools/make/downloads/xtimecomposer/xTIMEcomposer/15.0.0/ && source SetEnv && popd && make -f tensorflow/lite/micro/tools/make/Makefile TARGET="xcore" test +``` + +(add -jN to the final make command to run builds / tests in N parallel threads) + +# Background information: + +* To start from a fresh repo (this will also remove non-xcore builds and + downloads): `$ make -f tensorflow/lite/micro/tools/make/Makefile + TARGET="xcore" clean clean_downloads` +* To force xcore.ai tools download from a clean repo: `$ make -f + tensorflow/lite/micro/tools/make/Makefile TARGET="xcore" + test_greedy_memory_planner_test` (this will fail to build the test, but if + it succeeds because you already have tools it will exit quickly) + +* To set up environment variables correctly run the following from the top + tensorflow directory: `$ make -f tensorflow/lite/micro/tools/make/Makefile + TARGET="xcore" test $ pushd + ./tensorflow/lite/micro/tools/make/downloads/xtimecomposer/xTIMEcomposer/15.0.0/ + && source SetEnv && popd $ make -f tensorflow/lite/micro/tools/make/Makefile + TARGET="xcore" test` + +* Assuming tools are already set up the following are the most commonly used + commands: `$ make -f tensorflow/lite/micro/tools/make/Makefile + TARGET="xcore" build $ make -f tensorflow/lite/micro/tools/make/Makefile + TARGET="xcore" test $ make -f tensorflow/lite/micro/tools/make/Makefile + TARGET="xcore" < name_of_example i.e. hello_world_test >` diff --git a/tensorflow/lite/micro/xcore/debug_log.cc b/tensorflow/lite/micro/xcore/debug_log.cc new file mode 100644 index 00000000000..c206f057c02 --- /dev/null +++ b/tensorflow/lite/micro/xcore/debug_log.cc @@ -0,0 +1,16 @@ +/* Copyright 2018 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/lite/micro/debug_log.h" + +#include <cstdio> +extern "C" void DebugLog(const char* s) { printf("%s", s); }