Skip to content

Commit

Permalink
DDR example
Browse files Browse the repository at this point in the history
  • Loading branch information
panickal-xmos committed Jul 19, 2024
1 parent 592afc2 commit c04ab40
Show file tree
Hide file tree
Showing 10 changed files with 47,410 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/app_single_model_on_one_tile_and_DDR/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,41 @@
from xmos_ai_tools import xformer

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

OPTIMIZED_MODEL_PATH = "src/model.tflite"
WEIGHT_PARAMS_PATH = "src/model_weights.c"
FLASH_IMAGE_PATH = "src/xcore_flash_binary.out"
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": "3",
# operation splitting to reduce tensor arena size
"xcore-op-split-tensor-arena": "True",
"xcore-op-split-top-op": "0,7",
"xcore-op-split-bottom-op": "6,14",
"xcore-op-split-num-splits": "8,4",
# write weights as an array 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()

# # Generate flash image to be flashed using xflash
# xformer.generate_flash(
# output_file=FLASH_IMAGE_PATH,
# model_files=[OPTIMIZED_MODEL_PATH],
# param_files=[WEIGHT_PARAMS_PATH],
# )

print("Done!")
Binary file not shown.
21 changes: 21 additions & 0 deletions examples/app_single_model_on_one_tile_and_DDR/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_one_tile_and_DDR/src/image.h

Large diffs are not rendered by default.

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

// #define NFLASH_SPECS 1

// fl_QuadDeviceSpec flash_spec[NFLASH_SPECS] = {
// FL_QUADDEVICE_DEFAULT //FL_QUADDEVICE_MACRONIX_MX25R6435FM2IH0
// };

// on tile[0]: fl_QSPIPorts qspi = {
// PORT_SQI_CS,
// PORT_SQI_SCLK,
// PORT_SQI_SIO,
// XS1_CLKBLK_2
// };

#define NUMBER_OF_MODELS 1
extern void model_init(chanend f);
extern void inference();

// Hack for xc to be happy with EXTMEM
// Have to specify the extern array size
extern const int8_t tile_server_weights[3587236];
const int8_t* weights = (int8_t*)&tile_server_weights;

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, weights);
// flash_server(c_flash_or_tile, headers, NUMBER_OF_MODELS, qspi, flash_spec, 1);
}

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 c04ab40

Please sign in to comment.