Skip to content

Commit

Permalink
Merge pull request tensorflow#34803 from foss-for-synopsys-dwc-arc-pr…
Browse files Browse the repository at this point in the history
…ocessors:arcport_pullrequest

PiperOrigin-RevId: 287895175
Change-Id: Ie2bb3d7f6d82fb246f4a71b239a95c58472ba6eb
  • Loading branch information
tensorflower-gardener committed Jan 2, 2020
2 parents 34ac7a9 + 579cf3e commit 3018293
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 3 deletions.
36 changes: 36 additions & 0 deletions tensorflow/lite/micro/tools/ci_build/test_arc.sh
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Copyright 2019 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 the microcontroller code using arc platform.
# These tests require a metaware compiler.

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR=${SCRIPT_DIR}/../../../../..
cd ${ROOT_DIR}

source tensorflow/lite/micro/tools/ci_build/helper_functions.sh

readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean

TARGET_ARCH=arc

# TODO(b/143715361): downloading first to allow for parallel builds.
readable_run make -f tensorflow/lite/micro/tools/make/Makefile TARGET_ARCH=${TARGET_ARCH} third_party_downloads
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET_ARCH=${TARGET_ARCH} generate_hello_world_test_make_project
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET_ARCH=${TARGET_ARCH} generate_person_detection_test_make_project
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET_ARCH=${TARGET_ARCH} hello_world_test
11 changes: 9 additions & 2 deletions tensorflow/lite/micro/tools/make/download_and_extract.sh
Expand Up @@ -68,13 +68,18 @@ patch_kissfft() {
echo "Finished patching kissfft"
}

build_embarc_mli() {
gmake -j 4 -C ${1}/lib/make TCF_FILE=${2}
}

# Main function handling the download, verify, extract, and patch process.
download_and_extract() {
local usage="Usage: download_and_extract URL MD5 DIR [ACTION]"
local usage="Usage: download_and_extract URL MD5 DIR [ACTION] [ACTION_PARAM]"
local url="${1:?${usage}}"
local expected_md5="${2:?${usage}}"
local dir="${3:?${usage}}"
local action=${4}
local action_param1=${5} # optional action parameter
local tempdir=$(mktemp -d)
local tempdir2=$(mktemp -d)
local tempfile=${tempdir}/temp_file
Expand Down Expand Up @@ -140,10 +145,12 @@ download_and_extract() {
patch_am_sdk ${dir}
elif [[ ${action} == "patch_kissfft" ]]; then
patch_kissfft ${dir}
elif [[ ${action} == "build_embarc_mli" ]]; then
build_embarc_mli ${dir} ${action_param1}
elif [[ ${action} ]]; then
echo "Unknown action '${action}'"
exit 1
fi
}

download_and_extract "$1" "$2" "$3" "$4"
download_and_extract "$1" "$2" "$3" "$4" "$5"
38 changes: 37 additions & 1 deletion tensorflow/lite/micro/tools/make/helper_functions.inc
Expand Up @@ -99,6 +99,40 @@ list_$(3)_$(1)_files:
ALL_PROJECT_TARGETS += generate_$(3)_$(1)_project
endef

# Creates a set of rules to build a standalone makefile project for the ARC platform
# including all of the source and header files required in a
# separate folder and a simple makefile.
# Arguments are:
# 1 - Project type (make, mbed, etc).
# 2 - Project file template name.
# 3 - Name of executable.
# 4 - List of C/C++ source files needed to build the target.
# 5 - List of C/C++ header files needed to build the target.
# 6 - Linker flags required.
# 7 - C++ compilation flags needed.
# 8 - C compilation flags needed.
# Calling eval on the output will create a <Name>_makefile target that you
# can invoke to create the standalone project.
define generate_arc_project

ifeq ($(TARGET_ARCH), arc)
$(PRJDIR)$(3)/$(1)/Makefile: tensorflow/lite/micro/tools/make/templates/Makefile.tpl
@mkdir -p $$(dir $$@)
@sed -E 's#\%\{SRCS\}\%#$(4)#g' $$< | \
sed -E '1 i\CC = ccac\nCXX = ccac\nLD = ccac\n' | \
sed -E 's#\%\{EXECUTABLE\}\%#$(3).elf#g' | \
sed -E 's#\%\{LINKER_FLAGS\}\%#$(6)#g' | \
sed -E 's#\%\{CXX_FLAGS\}\%#$(7)#g' | \
sed -E 's#\%\{CC_FLAGS\}\%#$(8)#g' > $$@

# Special rule to copy TCF in case the local filesystem file name has been defined
ifneq ($(TCF_FILE_NAME), )
$(PRJDIR)$(3)/$(1)/$(TCF_FILE_NAME): $(TCF_FILE)
@cp $$< $$@
endif
endif
endef

# Creates a set of rules to build a standalone Arduino project for an
# executable, including all of the source and header files required in a
# separate folder and a simple makefile.
Expand Down Expand Up @@ -303,6 +337,7 @@ endef
# generate the standalone project.
define generate_microlite_projects
$(call generate_project,make,$(MAKE_PROJECT_FILES),$(1),$(MICROLITE_CC_SRCS) $(THIRD_PARTY_CC_SRCS) $(2),$(MICROLITE_CC_HDRS) $(THIRD_PARTY_CC_HDRS) $(MICROLITE_TEST_HDRS) $(3),$(LDFLAGS) $(MICROLITE_LIBS),$(CXXFLAGS) $(GENERATED_PROJECT_INCLUDES), $(CCFLAGS) $(GENERATED_PROJECT_INCLUDES))
$(call generate_arc_project,make,$(MAKE_PROJECT_FILES),$(1),$(MICROLITE_CC_SRCS) $(THIRD_PARTY_CC_SRCS) $(2),$(MICROLITE_CC_HDRS) $(THIRD_PARTY_CC_HDRS) $(MICROLITE_TEST_HDRS) $(3),$(LDFLAGS) $(GENERATED_PROJECT_LIBS),$(CXXFLAGS) $(GENERATED_PROJECT_INCLUDES), $(CCFLAGS) $(GENERATED_PROJECT_INCLUDES))
$(call generate_project,mbed,$(MBED_PROJECT_FILES),$(1),$(MICROLITE_CC_SRCS) $(THIRD_PARTY_CC_SRCS) $(2),$(MICROLITE_CC_HDRS) $(THIRD_PARTY_CC_HDRS) $(MICROLITE_TEST_HDRS) $(3),$(MICROLITE_LIBS),$(CXXFLAGS),$(CCFLAGS))
$(call generate_project,keil,$(KEIL_PROJECT_FILES),$(1),$(MICROLITE_CC_SRCS) $(THIRD_PARTY_CC_SRCS) $(2),$(MICROLITE_CC_HDRS) $(THIRD_PARTY_CC_HDRS) $(MICROLITE_TEST_HDRS) $(3),$(MICROLITE_LIBS),$(CXXFLAGS),$(CCFLAGS))
$(call generate_arduino_project,$(ARDUINO_PROJECT_FILES),$(1),$(MICROLITE_CC_SRCS) $(THIRD_PARTY_CC_SRCS) $(2),$(MICROLITE_CC_HDRS) $(THIRD_PARTY_CC_HDRS) $(MICROLITE_TEST_HDRS) $(3),$(MICROLITE_LIBS),$(CXXFLAGS),$(CCFLAGS))
Expand Down Expand Up @@ -347,10 +382,11 @@ endef
# 2 - MD5 sum of archive, to check integrity. Use md5sum tool to generate.
# 3 - Folder name to unpack library into, inside tf/l/x/m/t/downloads root.
# 4 - Optional patching action, must match clause in download_and_extract.sh.
# 5 - Optional patching action parameter
# These arguments are packed into a single '!' separated string, so no element
# can contain a '!'.
define add_third_party_download
THIRD_PARTY_DOWNLOADS += $(1)!$(2)!tensorflow/lite/micro/tools/make/downloads/$(3)!$(4)
THIRD_PARTY_DOWNLOADS += $(1)!$(2)!tensorflow/lite/micro/tools/make/downloads/$(3)!$(4)!$(5)
endef

# Unpacks an entry in a list of strings created by add_third_party_download, and
Expand Down
86 changes: 86 additions & 0 deletions tensorflow/lite/micro/tools/make/targets/arc_makefile.inc
@@ -0,0 +1,86 @@
# Settings for arc processors
ifeq ($(TARGET_ARCH), arc)

CC_TOOL = ccac
AR_TOOL = arac
CXX_TOOL = ccac

ifneq ($(TCF_FILE), )
TARGET = $(basename $(notdir $(TCF_FILE)))
else
TARGET = em7d_voice_audio
TCF_FILE = em7d_voice_audio
endif

# The variable TCF_FILE_NAME stores the TCF file name (including .tcf extension), this variable is used later to add the option to the linker/compiler flags.
# This condition also handles the case when the user/makefile specifies the configuration bundled with MWDT (usually without .tcf extension) and that doesn't require copying.
ifneq (,$(findstring .tcf,$(TCF_FILE)))
TCF_FILE_NAME = $(notdir $(TCF_FILE))
THIRD_PARTY_CC_HDRS += $(TCF_FILE_NAME)
else
TCF_FILE_NAME = $(TCF_FILE)
endif

PLATFORM_FLAGS = -tcf=$(TCF_FILE_NAME) -Hnocopyr -O3 -Hpurge -Hcl -fslp-vectorize-aggressive -ffunction-sections -fdata-sections
PLATFORM_LDFLAGS = -tcf=$(TCF_FILE_NAME) -Hnocopyr -m -Hldopt=-Coutput=memory.map

CXXFLAGS += $(PLATFORM_FLAGS)
CXXFLAGS:=$(filter-out -std=c++11,$(CXXFLAGS))
CCFLAGS += $(PLATFORM_FLAGS)
LDFLAGS += $(PLATFORM_LDFLAGS)

MICROLITE_LIBS := $(filter-out -lm,$(MICROLITE_LIBS))

USE_EMBARC_MLI ?= true

ifeq ($(USE_EMBARC_MLI), true)
ALL_TAGS += arc

ifeq ($(PRE_COMPILED_MLI),true)
$(eval $(call add_third_party_download,$(EMBARC_OSP_URL),$(EMBARC_OSP_MD5),embarc_osp,))

MLI_INCLUDE_FOLDER = embarc_osp/library/embarc_mli/include
MLI_LIB = third_party/embarc_osp/library/embarc_mli/lib/arcem9d/libmli_iotdk.a

THIRD_PARTY_CC_HDRS += \
third_party/embarc_osp/LICENSE
else
MLI_LIB_DIR = embarc_mli_$(basename $(TCF_FILE_NAME))

$(eval $(call add_third_party_download,$(EMBARC_MLI_URL),$(EMBARC_MLI_MD5),$(MLI_LIB_DIR),build_embarc_mli,$(TCF_FILE)))

MLI_INCLUDE_FOLDER = $(MLI_LIB_DIR)/include
MLI_LIB = third_party/$(MLI_LIB_DIR)/bin/libmli.a
MICROLITE_LIBS += $(MAKEFILE_DIR)/downloads/$(MLI_LIB_DIR)/bin/libmli.a

THIRD_PARTY_CC_HDRS += \
third_party/$(MLI_LIB_DIR)/LICENSE
endif

THIRD_PARTY_CC_HDRS += $(MLI_LIB)
GENERATED_PROJECT_LIBS += $(MLI_LIB)

INCLUDES += \
-I$(MAKEFILE_DIR)/downloads/$(MLI_INCLUDE_FOLDER) \
-I$(MAKEFILE_DIR)/downloads/$(MLI_INCLUDE_FOLDER)/api

GENERATED_PROJECT_INCLUDES += \
-I. \
-I./third_party/$(MLI_INCLUDE_FOLDER) \
-I./third_party/$(MLI_INCLUDE_FOLDER)/api


THIRD_PARTY_CC_HDRS += \
third_party/$(MLI_INCLUDE_FOLDER)/mli_api.h \
third_party/$(MLI_INCLUDE_FOLDER)/mli_config.h \
third_party/$(MLI_INCLUDE_FOLDER)/mli_types.h \
third_party/$(MLI_INCLUDE_FOLDER)/api/mli_helpers_api.h \
third_party/$(MLI_INCLUDE_FOLDER)/api/mli_kernels_api.h \
third_party/$(MLI_INCLUDE_FOLDER)/api/mli_krn_avepool_spec_api.h \
third_party/$(MLI_INCLUDE_FOLDER)/api/mli_krn_conv2d_spec_api.h \
third_party/$(MLI_INCLUDE_FOLDER)/api/mli_krn_depthwise_conv2d_spec_api.h \
third_party/$(MLI_INCLUDE_FOLDER)/api/mli_krn_maxpool_spec_api.h \

endif # USE_EMBARC_MLI

endif
6 changes: 6 additions & 0 deletions tensorflow/lite/micro/tools/make/templates/Makefile.tpl
@@ -1,3 +1,5 @@
RM = rm -f

SRCS := \
%{SRCS}%

Expand All @@ -19,3 +21,7 @@ LDFLAGS += %{LINKER_FLAGS}%
$(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS)

all: %{EXECUTABLE}%

clean:
-$(RM) $(OBJS)
-$(RM) %{EXECUTABLE}%
6 changes: 6 additions & 0 deletions tensorflow/lite/micro/tools/make/third_party_downloads.inc
Expand Up @@ -54,3 +54,9 @@ KISSFFT_MD5="438ba1fef5783cc5f5f201395cc477ca"

PERSON_MODEL_URL := "https://storage.googleapis.com/download.tensorflow.org/data/tf_lite_micro_person_data_grayscale_2019_11_21.zip"
PERSON_MODEL_MD5 := "fe2934bd0788f1dcc7af3f0a954542ab"

EMBARC_OSP_URL := "https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp/archive/embarc_mli.zip"
EMBARC_OSP_MD5 := "9eaf7b3a1ed05872a03da9796672a776"

EMBARC_MLI_URL := "https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_mli/archive/datatypes.zip"
EMBARC_MLI_MD5 := "e2243f53c88ca3bedbb8cc8c3bb44053"

0 comments on commit 3018293

Please sign in to comment.