-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #914 from xmos/ddr_example
DDR example
- Loading branch information
Showing
24 changed files
with
930 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
TARGET = XCORE-AI-EXPLORER | ||
TARGET = XCORE-AI-EXPLORER-800 | ||
APP_NAME = | ||
|
||
APP_FLAGS = -report \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
TARGET = XCORE-AI-EXPLORER-800 | ||
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 | ||
|
43 changes: 43 additions & 0 deletions
43
examples/app_single_model_on_one_tile_and_DDR/generate_optimized_cpp_for_xcore.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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" | ||
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 in DDR | ||
"xcore-write-weights-as-array" : "True", | ||
"xcore-weights-in-external-memory" : "True", | ||
# For DDR, we want to ideally reduce loads smaller | ||
# than 4000 bytes, as they are slower. | ||
# But this would increase memory usage on tile | ||
# and so it is a tradeoff | ||
"xcore-load-externally-if-larger" : "1500", | ||
# 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.
104 changes: 104 additions & 0 deletions
104
examples/app_single_model_on_one_tile_and_DDR/src/XCORE-AI-EXPLORER-800.xn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Network xmlns="http://www.xmos.com" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.xmos.com http://www.xmos.com"> | ||
<Type>Board</Type> | ||
<Name>xcore.ai Explorer Kit</Name> | ||
|
||
<Declarations> | ||
<Declaration>tileref tile[2]</Declaration> | ||
</Declarations> | ||
|
||
<Packages> | ||
<Package id="0" Type="XS3-UnA-1024-FB265"> | ||
<Nodes> | ||
<Node Id="0" InPackageId="0" Type="XS3-L16A-1024" Oscillator="24MHz" SystemFrequency="800MHz" ReferenceFrequency="100MHz" | ||
SecondaryPllInputDiv="1" SecondaryPllOutputDiv="3" SecondaryPllFeedbackDiv="83"> | ||
<Boot> | ||
<Source Location="bootFlash"/> | ||
</Boot> | ||
<Extmem sizeMbit="1024" SourcePll="SecondaryPll" Divider="2"> | ||
<!-- Attributes for Padctrl and Lpddr XML elements are as per equivalently named 'Node Configuration' registers in datasheet --> | ||
|
||
<Padctrl clk="0x30" cke="0x30" cs_n="0x30" we_n="0x30" cas_n="0x30" ras_n="0x30" addr="0x30" ba="0x30" dq="0x31" dqs="0x31" dm="0x30"/> | ||
<!-- | ||
Attributes all have the same meaning, which is: | ||
[6] = Schmitt enable, [5] = Slew, [4:3] = drive strength, [2:1] = pull option, [0] = read enable | ||
Therefore: | ||
0x30: 8mA-drive, fast-slew output | ||
0x31: 8mA-drive, fast-slew bidir | ||
--> | ||
|
||
<Lpddr emr_opcode="0x20"/> | ||
<!-- | ||
Attributes have various meanings: | ||
emr_opcode[7:5] = LPDDR drive strength to xcore.ai | ||
protocol_engine_conf_0[23:21] = tWR clock count at the Extmem Frequency | ||
protocol_engine_conf_0[20:15] = tXSR clock count at the Extmem Frequency | ||
protocol_engine_conf_0[14:11] = tRAS clock count at the Extmem Frequency | ||
protocol_engine_conf_0[10:0] = tREFI clock count at the Extmem Frequency | ||
Therefore: | ||
0x20: Half drive strength | ||
0x30b: tREFI 7.79us, tRAS 0us, tXSR 0us, tWR 0us | ||
--> | ||
</Extmem> | ||
<Tile Number="0" Reference="tile[0]"> | ||
<Port Location="XS1_PORT_1B" Name="PORT_SQI_CS"/> | ||
<Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK"/> | ||
<Port Location="XS1_PORT_4B" Name="PORT_SQI_SIO"/> | ||
|
||
<Port Location="XS1_PORT_4C" Name="PORT_LEDS"/> | ||
<Port Location="XS1_PORT_4D" Name="PORT_BUTTONS"/> | ||
|
||
<Port Location="XS1_PORT_1I" Name="WIFI_WIRQ"/> | ||
<Port Location="XS1_PORT_1J" Name="WIFI_MOSI"/> | ||
<Port Location="XS1_PORT_4E" Name="WIFI_WUP_RST_N"/> | ||
<Port Location="XS1_PORT_4F" Name="WIFI_CS_N"/> | ||
<Port Location="XS1_PORT_1L" Name="WIFI_CLK"/> | ||
<Port Location="XS1_PORT_1M" Name="WIFI_MISO"/> | ||
</Tile> | ||
<Tile Number="1" Reference="tile[1]"> | ||
<!-- Mic related ports --> | ||
<Port Location="XS1_PORT_1G" Name="PORT_PDM_CLK"/> | ||
<Port Location="XS1_PORT_1F" Name="PORT_PDM_DATA"/> | ||
|
||
<!-- Audio ports --> | ||
<Port Location="XS1_PORT_1D" Name="PORT_MCLK_IN"/> | ||
<Port Location="XS1_PORT_1C" Name="PORT_I2S_BCLK"/> | ||
<Port Location="XS1_PORT_1B" Name="PORT_I2S_LRCLK"/> | ||
<Port Location="XS1_PORT_1A" Name="PORT_I2S_DAC_DATA"/> | ||
<Port Location="XS1_PORT_1N" Name="PORT_I2S_ADC_DATA"/> | ||
<Port Location="XS1_PORT_4A" Name="PORT_CODEC_RST_N"/> | ||
</Tile> | ||
</Node> | ||
</Nodes> | ||
</Package> | ||
</Packages> | ||
<Nodes> | ||
<Node Id="2" Type="device:" RoutingId="0x8000"> | ||
<Service Id="0" Proto="xscope_host_data(chanend c);"> | ||
<Chanend Identifier="c" end="3"/> | ||
</Service> | ||
</Node> | ||
</Nodes> | ||
<Links> | ||
<Link Encoding="2wire" Delays="5clk" Flags="XSCOPE"> | ||
<LinkEndpoint NodeId="0" Link="XL0"/> | ||
<LinkEndpoint NodeId="2" Chanend="1"/> | ||
</Link> | ||
</Links> | ||
<ExternalDevices> | ||
<Device NodeId="0" Tile="0" Class="SQIFlash" Name="bootFlash" PageSize="256" SectorSize="4096" NumPages="16384"> | ||
<Attribute Name="PORT_SQI_CS" Value="PORT_SQI_CS"/> | ||
<Attribute Name="PORT_SQI_SCLK" Value="PORT_SQI_SCLK"/> | ||
<Attribute Name="PORT_SQI_SIO" Value="PORT_SQI_SIO"/> | ||
</Device> | ||
</ExternalDevices> | ||
<JTAGChain> | ||
<JTAGDevice NodeId="0"/> | ||
</JTAGChain> | ||
|
||
</Network> |
21 changes: 21 additions & 0 deletions
21
examples/app_single_model_on_one_tile_and_DDR/src/config.xscope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.