Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example with tensor arena in external memory #907

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/app_flash_single_model_arena_ext_mem/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
TARGET = XCORE-AI-EXPLORER
APP_NAME =

APP_FLAGS = -report \
-O3 -mcmodel=large -fxscope -Wno-xcore-fptrgroup \
-DSHARED_TENSOR_ARENA \
-g \
-lquadflash

# *******************************************************
# Include AI Tools library and headers
# *******************************************************
# The following variables are defined for AI Tools library
# and should be included when building the app.
# XMOS_AITOOLSLIB_DEFINITIONS
# XMOS_AITOOLSLIB_INCLUDES
# XMOS_AITOOLSLIB_LIBRARIES
#
ifeq ($(XMOS_AITOOLSLIB_PATH),)
$(error Path to XMOS AI Tools library and headers not set correctly!)
endif
include ${XMOS_AITOOLSLIB_PATH}/buildfiles/aitoolslib.make

XCC_FLAGS = $(APP_FLAGS) $(XMOS_AITOOLSLIB_DEFINITIONS) $(XMOS_AITOOLSLIB_INCLUDES)
XCC_CPP_FLAGS = $(APP_FLAGS) -std=c++14 $(XMOS_AITOOLSLIB_DEFINITIONS) $(XMOS_AITOOLSLIB_INCLUDES)
XCC_MAP_FLAGS = $(APP_FLAGS) $(XMOS_AITOOLSLIB_LIBRARIES)

#=============================================================================
# The following part of the Makefile includes the common build infrastructure
# for compiling XMOS applications. You should not need to edit below here.

XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
35 changes: 35 additions & 0 deletions examples/app_flash_single_model_arena_ext_mem/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Example with flash and tensor arena on external memory
==================

Please consult `here <../../docs/rst/flow.rst>`_ on how to install the tools.

This is an example with one network using a tensor arena in external memory.
This is much slower than having the tensor arena in the 512 kB SRAM, but it allows tensor arenas to have a size larger than 512 kB.

The differences with the ``app_flash_single_model`` example are minimal:

* The shared-arena definition ``-DSHARED_TENSOR_ARENA`` has been added to the
Makefile; this allows the application to define the tensor arena buffer.

* In support.cpp a tensor arena is declared in external memory::\

__attribute__ ((section(".ExtMem.bss")))
uint8_t tensor_arena[LARGEST_TENSOR_ARENA_SIZE] __attribute__((aligned(8)));

In order to compile and run this example follow these steps::

xcore-opt --xcore-weights-file=model.params vww_quant.tflite -o model.tflite
mv model.tflite.cpp model.tflite.h src
xmake
python -c 'from xmos_ai_tools import xformer as xf; xf.generate_flash(
output_file="xcore_flash_binary.out",
model_files=["model.tflite"],
param_files=["model.params"]
)'
xflash --target XCORE-AI-EXPLORER --data xcore_flash_binary.out
xrun --xscope bin/app_flash_single_model.xe

This should print::

No human (9%)
Human (98%)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>

<xSCOPEconfig ioMode="basic" enabled="true"/>
Loading
Loading