Skip to content

Commit 35703ae

Browse files
author
Robert Muchsel
authored
CMSIS-NN builds for CM4 (unsupported) (#144)
1 parent b162abc commit 35703ae

File tree

5 files changed

+158
-11
lines changed

5 files changed

+158
-11
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MAX78000 Model Training and Synthesis
22

3-
_June 29, 2021_
3+
_June 30, 2021_
44

55
The Maxim Integrated AI project is comprised of five repositories:
66

@@ -225,8 +225,8 @@ Change to the project root and run the following commands. Use your GitHub crede
225225

226226
```shell
227227
$ cd $AI_PROJECT_ROOT
228-
$ git clone https://github.com/MaximIntegratedAI/ai8x-training.git
229-
$ git clone https://github.com/MaximIntegratedAI/ai8x-synthesis.git
228+
$ git clone --recursive https://github.com/MaximIntegratedAI/ai8x-training.git
229+
$ git clone --recursive https://github.com/MaximIntegratedAI/ai8x-synthesis.git
230230
```
231231

232232
#### Creating the Virtual Environment
@@ -245,7 +245,6 @@ $ git checkout develop # optional
245245
Then continue with the following:
246246

247247
```shell
248-
$ git submodule update --init
249248
$ pyenv local 3.8.10
250249
$ python3 -m venv .
251250
$ source bin/activate
@@ -368,7 +367,6 @@ $ git checkout develop # optional
368367
Then continue:
369368

370369
```shell
371-
$ git submodule update --init
372370
$ pyenv local 3.8.10
373371
$ python3 -m venv .
374372
$ source bin/activate

assets/cmsis-nn/Makefile.ARM

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
################################################################################
2+
# Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a
5+
# copy of this software and associated documentation files (the "Software"),
6+
# to deal in the Software without restriction, including without limitation
7+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
# and/or sell copies of the Software, and to permit persons to whom the
9+
# Software is furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included
12+
# in all copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
# IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
18+
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
# OTHER DEALINGS IN THE SOFTWARE.
21+
#
22+
# Except as contained in this notice, the name of Maxim Integrated
23+
# Products, Inc. shall not be used except as stated in the Maxim Integrated
24+
# Products, Inc. Branding Policy.
25+
#
26+
# The mere transfer of this software does not imply any licenses
27+
# of trade secrets, proprietary technology, copyrights, patents,
28+
# trademarks, maskwork rights, or any other form of intellectual
29+
# property whatsoever. Maxim Integrated Products, Inc. retains all
30+
# ownership rights.
31+
#
32+
#
33+
###############################################################################
34+
35+
# This is the name of the build output file
36+
ifeq "$(PROJECT)" ""
37+
PROJECT=max78000
38+
endif
39+
40+
# Specify the target processor
41+
ifeq "$(TARGET)" ""
42+
TARGET=MAX78000
43+
endif
44+
45+
# Create Target name variables
46+
TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z)
47+
TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z)
48+
49+
# Select 'GCC' or 'IAR' compiler
50+
COMPILER=GCC
51+
52+
# Specify the board used
53+
ifeq "$(BOARD)" ""
54+
BOARD=EvKit_V1
55+
endif
56+
57+
# This is the path to the CMSIS root directory
58+
ifeq "$(MAXIM_PATH)" ""
59+
LIBS_DIR=../../../../Libraries
60+
else
61+
LIBS_DIR=$(subst \,/,$(subst :,,$(MAXIM_PATH))/Libraries)
62+
endif
63+
CMSIS_ROOT=$(LIBS_DIR)/CMSIS
64+
65+
#Use this for other library make files so they are all based off the same as root as the project
66+
export CMSIS_ROOT
67+
68+
# LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/max78000_arm.ld
69+
70+
# Source files for this test (add path to VPATH below)
71+
SRCS = main.c
72+
SRCS += arm_convolve_HWC_q7_basic.c arm_pool_q7_HWC.c arm_relu_q7.c arm_convolve_HWC_q7_fast.c arm_convolve_HWC_q7_basic_nonsquare.c arm_pool_q7_HWC_nonsquare.c arm_pool_nonsquare_q7_HWC_nonsquare.c
73+
SRCS += arm_relu32_q7.c arm_fully_connected_q7.c arm_fully_connected_q7_q31.c arm_q7_to_q15_reordered_no_shift.c arm_q7_to_q15_no_shift.c arm_nn_mat_mult_kernel_q7_q15.c arm_nn_mat_mult_kernel_q7_q15_reordered.c
74+
75+
# Where to find source files for this test
76+
VPATH = .
77+
VPATH += $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source
78+
# Where to find header files for this test
79+
IPATH = .
80+
81+
# Enable assertion checking for development
82+
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
83+
PROJ_CFLAGS+=-DARM_MATH_CM4
84+
PROJ_CFLAGS+=-I. -ICMSIS/Core/Include -ICMSIS/NN/Include -ICMSIS/DSP/Include -DCMSIS_VECTAB_VIRTUAL
85+
86+
# Enable all warnings
87+
PROJ_CFLAGS+=-Wall -Wcast-align
88+
89+
# Specify the target revision to override default
90+
# "A2" in ASCII
91+
# TARGET_REV=0x4132
92+
93+
# Use this variables to specify and alternate tool path
94+
#TOOL_DIR=/opt/gcc-arm-none-eabi-4_8-2013q4/bin
95+
96+
# Use these variables to add project specific tool options
97+
#PROJ_CFLAGS+=-D__FPU_PRESENT -DKINTEX_EMU
98+
#PROJ_LDFLAGS+=--specs=nano.specs
99+
100+
# Point this variable to a startup file to override the default file
101+
#STARTUPFILE=start.S
102+
103+
# Override the default optimization level using this variable
104+
MXC_OPTIMIZE_CFLAGS=-O2
105+
106+
################################################################################
107+
# Include external library makefiles here
108+
109+
# Include the BSP
110+
BOARD_DIR=$(LIBS_DIR)/Boards/$(TARGET_UC)/$(BOARD)
111+
include $(BOARD_DIR)/board.mk
112+
113+
# Include the peripheral driver
114+
PERIPH_DRIVER_DIR=$(LIBS_DIR)/PeriphDrivers
115+
include $(PERIPH_DRIVER_DIR)/periphdriver.mk
116+
export PERIPH_DRIVER_DIR
117+
118+
################################################################################
119+
# Include the rules for building for this target. All other makefiles should be
120+
# included before this one.
121+
include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk
122+
123+
all:
124+
# arm-none-eabi-objcopy $(BUILD_DIR)/$(PROJECT).elf -R .sig -O binary $(BUILD_DIR)/$(PROJECT).bin
125+
# $(CA_SIGN_BUILD) $(BUILD_DIR)/$(PROJECT).bin $(TEST_KEY)
126+
# arm-none-eabi-objcopy $(BUILD_DIR)/$(PROJECT).elf --update-section .sig=$(BUILD_DIR)/$(PROJECT).bin.sig
127+
128+
libclean:
129+
$(MAKE) -f ${PERIPH_DRIVER_DIR}/periphdriver.mk clean.periph
130+
131+
# The rule to clean out all the build products.
132+
distclean: clean libclean
133+
134+
sla: all
135+
136+
# arm-none-eabi-objcopy $(BUILD_DIR)/$(PROJECT).elf -O binary $(BUILD_DIR)/$(PROJECT).sbin
137+
# $(BUILD_SESSION) $(BUILD_DIR)/$(PROJECT).sbin scp_packets $(TEST_KEY)
138+

assets/cmsis-nn/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The ‘izer’ includes an unsupported CMSIS-NN code generator. To use it:
44

55
1. Understand it is incomplete and unsupported.
6-
2. Use only networks **without any** Conv1d, ConvTranspose2d, element-wise operations, and without input sequences (concatenation). Some or more of these features could be added without too much effort, any suggestions or pull requests are welcome.
6+
2. Use only networks **without any** input sequences (concatenation) and without element-wise operations. Some or more of these features could be added without too much effort, any suggestions or pull requests are welcome.
77
3. Understand that there is no proper build environment.
88

99
### Setup
@@ -25,20 +25,20 @@ There are additional files in the `assets/cmsis-nn` folder of ai8x-synthesis. Th
2525
To generate C code, use the special “CMSIS-NN” device (instead of MAX78000 or MAX78002). For example, to generate a CIFAR-10 demo for CMSIS-NN, run:
2626

2727
```shell
28-
(ai8x-synthesis) $ ./ai8xize.py -e --verbose --top-level cnn -L --test-dir cmsis-demos --prefix cifar-10 --checkpoint-file trained/ai85-cifar10.pth.tar --config-file networks/cifar10-hwc-ai85.yaml --device CMSIS-NN --display-checkpoint
28+
(ai8x-synthesis) $ ./ai8xize.py -e --verbose --top-level cnn -L --test-dir rtldev/cmsis-demos --prefix cifar-10 --checkpoint-file trained/ai85-cifar10.pth.tar --config-file networks/cifar10-hwc-ai85.yaml --device CMSIS-NN --display-checkpoint
2929
```
3030

3131
This is very similar to generating code for MAX78000 (see `gen-demos-max7800.sh`).
3232

33-
Next, go to the target folder (`cmsis-demos/cifar-10` in the above example), and execute:
33+
Next, go to the target folder (`rtldev/cmsis-demos/cifar-10` in the above example), and execute:
3434

3535
```shell
36-
(ai8x-synthesis) $ cd cmisis-demos/cifar-10
36+
(ai8x-synthesis) $ cd rtldev/cmisis-demos/cifar-10
3737
(ai8x-synthesis) $ ./makelinks.sh
3838
(ai8x-synthesis) $ make
3939
```
4040

41-
This builds an executable file called `main` which will run a known-answer test.
41+
This builds an executable file called `main` which will run a known-answer test on the host:
4242

4343
```shell
4444
(ai8x-synthesis) $ ./main
@@ -48,3 +48,9 @@ Output of final layer:
4848
-128 -128 -128 127 -128 -61 -128 -128 -128 -128
4949
```
5050

51+
To build for the Cortex-M4 core in MAX78000, instead run
52+
```
53+
(ai8x-synthesis) $ MAXIM_PATH=../../../sdk make -f Makefile.ARM
54+
```
55+
56+
Note that the SIMD libraries for Arm Cortex-M4 do not implement full rounding, and results may therefore not be an exact match (known-answer test returns “FAIL”).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Empty file for compatibility reasons */

assets/cmsis-nn/makelinks.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/sh
2-
ln -s ../../../CMSIS_5/CMSIS .
2+
ln -s ../../../../CMSIS_5/CMSIS .
33
# ln -s CMSIS/NN/Source/ConvolutionFunctions/arm_convolve_HWC_q7_basic_nonsquare.c .
44
# ln -s CMSIS/NN/Source/ConvolutionFunctions/arm_convolve_HWC_q7_basic.c .
55
# ln -s CMSIS/NN/Source/ConvolutionFunctions/arm_convolve_HWC_q7_fast.c .
66
ln -s CMSIS/NN/Source/PoolingFunctions/arm_pool_q7_HWC.c .
77
ln -s CMSIS/NN/Source/ActivationFunctions/arm_relu_q7.c .
88
ln -s CMSIS/NN/Source/FullyConnectedFunctions/arm_fully_connected_q7.c .
9+
ln -s CMSIS/NN/Source/NNSupportFunctions/arm_q7_to_q15_reordered_no_shift.c .
10+
ln -s CMSIS/NN/Source/NNSupportFunctions/arm_q7_to_q15_no_shift.c .
11+
ln -s CMSIS/NN/Source/ConvolutionFunctions/arm_nn_mat_mult_kernel_q7_q15.c .
12+
ln -s CMSIS/NN/Source/ConvolutionFunctions/arm_nn_mat_mult_kernel_q7_q15_reordered.c .

0 commit comments

Comments
 (0)