Using NMSIS-NN¶
Here we will describe how to run the nmsis nn examples in Nuclei Spike.
Preparation¶
Nuclei Modified Spike -
xl_spike
Nuclei SDK modified for
xl_spike
branchdev_xlspike
Nuclei RISCV GNU Toolchain
CMake >= 3.5
Tool Setup¶
Export PATH correctly for xl_spike and riscv-nuclei-elf-gcc
export PATH=/path/to/xl_spike/bin:/path/to/riscv-nuclei-elf-gcc/bin/:$PATH
Build NMSIS NN Library¶
Download or clone NMSIS source code into NMSIS directory.
cd to NMSIS/NMSIS/ directory
Build NMSIS NN library using
make gen_nn_lib
Strip debug informations using
make strip_nn_lib
to make the generated library smallerThe nn library will be generated into
./Library/NN/GCC
folderThe nn libraries will be look like this:
$ ll Library/NN/GCC/
total 3000
-rw-r--r-- 1 hqfang nucleisys 128482 Jul 14 14:51 libnmsis_nn_rv32imac.a
-rw-r--r-- 1 hqfang nucleisys 281834 Jul 14 14:51 libnmsis_nn_rv32imacp.a
-rw-r--r-- 1 hqfang nucleisys 128402 Jul 14 14:51 libnmsis_nn_rv32imafc.a
-rw-r--r-- 1 hqfang nucleisys 282750 Jul 14 14:51 libnmsis_nn_rv32imafcp.a
-rw-r--r-- 1 hqfang nucleisys 128650 Jul 14 14:51 libnmsis_nn_rv32imafdc.a
-rw-r--r-- 1 hqfang nucleisys 282978 Jul 14 14:51 libnmsis_nn_rv32imafdcp.a
-rw-r--r-- 1 hqfang nucleisys 183918 Jul 14 14:51 libnmsis_nn_rv64imac.a
-rw-r--r-- 1 hqfang nucleisys 418598 Jul 14 14:51 libnmsis_nn_rv64imacp.a
-rw-r--r-- 1 hqfang nucleisys 184206 Jul 14 14:51 libnmsis_nn_rv64imafc.a
-rw-r--r-- 1 hqfang nucleisys 418070 Jul 14 14:51 libnmsis_nn_rv64imafcp.a
-rw-r--r-- 1 hqfang nucleisys 184454 Jul 14 14:51 libnmsis_nn_rv64imafdc.a
-rw-r--r-- 1 hqfang nucleisys 419774 Jul 14 14:51 libnmsis_nn_rv64imafdcp.a
library name with extra
p
is build with RISCV DSP enabled.libnmsis_nn_rv32imac.a
: Build for RISCV_ARCH=rv32imac without DSP enabled.libnmsis_nn_rv32imacp.a
: Build for RISCV_ARCH=rv32imac with DSP enabled.
Note
You can also directly build both DSP and NN library using
make gen
You can strip the generated DSP and NN library using
make strip
How to run¶
Set environment variables
NUCLEI_SDK_ROOT
andNUCLEI_SDK_NMSIS
, and set Nuclei SDK SoC to xlspike
export NUCLEI_SDK_ROOT=/path/to/nuclei_sdk
export NUCLEI_SDK_NMSIS=/path/to/NMSIS/NMSIS
export SOC=xlspike
Let us take
./cifar10/
for example
cd ./cifar10/
Run with RISCV DSP enabled NMSIS-NN library for CORE
n307
# Clean project
make DSP_ENABLE=ON CORE=n307 clean
# Build project
make DSP_ENABLE=ON CORE=n307 all
# Run application using xl_spike
make DSP_ENABLE=ON CORE=n307 run
Run with RISCV DSP disabled NMSIS-NN library for CORE
n307
make DSP_ENABLE=OFF CORE=n307 clean
make DSP_ENABLE=OFF CORE=n307 all
make DSP_ENABLE=OFF CORE=n307 run
Note
You can easily run this example in your hardware, if you have enough memory to run it, just modify the
SOC
to the one your are using in step 1.