Skip to content

Commit

Permalink
Add an example using second tile for weights
Browse files Browse the repository at this point in the history
  • Loading branch information
panickal-xmos committed Jul 18, 2024
1 parent 592afc2 commit a275b99
Show file tree
Hide file tree
Showing 8 changed files with 4,828 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/app_single_model_on_two_tiles/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
TARGET = XCORE-AI-EXPLORER
APP_NAME = app_device

APP_FLAGS = -report \
-O3 -fcomment-asm -mcmodel=large -fxscope -Wno-xcore-fptrgroup \
-Wno-unknown-pragmas \
-Wno-bidirectional-buffered-port \
-lquadflash \
-g
#-Wm,--image-size,8388608,--image-base,8388608

# Comment out the below TFLMC_XCORE_PROFILE definition to disable profiling
APP_FLAGS += -DTFLMC_XCORE_PROFILE

# Enable the below SHARED_TENSOR_ARENA definition for multiple models
# or to manage tensor arena array yourself
#APP_FLAGS += -DSHARED_TENSOR_ARENA

# *******************************************************
# 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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from xmos_ai_tools import xformer

TFLITE_MODEL_PATH = "mobilenetv1_25.tflite"
OPTIMIZED_MODEL_PATH = "src/model.tflite"

OPTIMIZED_MODEL_PATH = "src/model.tflite"
WEIGHT_PARAMS_PATH = "src/model_weights.h"
print("Generating app cpp files for model...")
xformer.convert(
TFLITE_MODEL_PATH,
OPTIMIZED_MODEL_PATH,
{
"xcore-thread-count": "5",
# set conv err threshold
"xcore-conv-err-threshold": "0.6",
# operation splitting to reduce tensor arena size
"xcore-op-split-tensor-arena": "True",
"xcore-op-split-top-op": "0",
"xcore-op-split-bottom-op": "4",
"xcore-op-split-num-splits": "10",
# write weights as a header file to be
# placed on second tile
"xcore-load-tile" : "True",
# roughly(tensors are not split) specifies
# size of weights to move out to header file
"xcore-max-load-external-size" : "270000",
# move weights to this file
"xcore-weights-file" : WEIGHT_PARAMS_PATH,
},
)
xformer.print_optimization_report()

print("Done!")
Binary file not shown.
21 changes: 21 additions & 0 deletions examples/app_single_model_on_two_tiles/src/config.xscope
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- ======================================================= -->
<!-- The 'ioMode' attribute on the xSCOPEconfig -->
<!-- element can take the following values: -->
<!-- "none", "basic", "timed" -->
<!-- -->
<!-- The 'type' attribute on Probe -->
<!-- elements can take the following values: -->
<!-- "STARTSTOP", "CONTINUOUS", "DISCRETE", "STATEMACHINE" -->
<!-- -->
<!-- The 'datatype' attribute on Probe -->
<!-- elements can take the following values: -->
<!-- "NONE", "UINT", "INT", "FLOAT" -->
<!-- ======================================================= -->

<xSCOPEconfig ioMode="basic" enabled="true">
<!-- For example: -->
<!-- <Probe name="Probe Name" type="CONTINUOUS" datatype="UINT" units="Value" enabled="true"/> -->
<!-- From the target code, call: xscope_int(PROBE_NAME, value); -->
</xSCOPEconfig>
486 changes: 486 additions & 0 deletions examples/app_single_model_on_two_tiles/src/image.h

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions examples/app_single_model_on_two_tiles/src/main.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdint.h>
#include <stdio.h>
#include <platform.h>
#include "tile_ram_server.h"

#define NUMBER_OF_MODELS 1
#include "model_weights.h"

extern void model_init(chanend f);
extern void inference();

int main(void) {
chan c_flash_or_tile[NUMBER_OF_MODELS];

par {
on tile[0]: {
flash_t headers[NUMBER_OF_MODELS];
tile_ram_server(c_flash_or_tile, headers, NUMBER_OF_MODELS, tile_server_weights);
}

on tile[1]: {
unsafe {
c_flash_or_tile[0] <: FLASH_SERVER_INIT;

model_init(c_flash_or_tile[0]);

inference();

c_flash_or_tile[0] <: FLASH_SERVER_QUIT;
}
}
}
return 0;
}
Loading

0 comments on commit a275b99

Please sign in to comment.