Skip to content

Commit

Permalink
tflite/micro: change nuclei demosoc to evalsoc
Browse files Browse the repository at this point in the history
  • Loading branch information
shuzhuo committed May 25, 2023
1 parent 3edebea commit a8f39b8
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/nmsis_nn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ if you have that version of prebuilt library, you can specify NUCLEI_SDK_NMSIS=<
Building the kernel conv unit test.

For more information about this specific target, check out
[Nuclei Demosoc QEMU software](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/nuclei-demosoc/README.md).
[Nuclei Demosoc QEMU software](https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/nuclei-evalsoc/README.md).

Using prebuilt NMSIS-NN library prebuilt in downloaded Nuclei SDK.

```
make -f tensorflow/lite/micro/tools/make/Makefile OPTIMIZED_KERNEL_DIR=nmsis_nn TARGET=nuclei_demosoc kernel_conv_test
make -f tensorflow/lite/micro/tools/make/Makefile OPTIMIZED_KERNEL_DIR=nmsis_nn TARGET=nuclei_evalsoc kernel_conv_test
```

Using prebuilt NMSIS-NN library built in NMSIS repo, not the one in Nuclei SDK.

```
make -f tensorflow/lite/micro/tools/make/Makefile OPTIMIZED_KERNEL_DIR=nmsis_nn NUCLEI_SDK_NMSIS=<external/path/to/NMSIS/NMSIS> TARGET=nuclei_demosoc kernel_conv_test
make -f tensorflow/lite/micro/tools/make/Makefile OPTIMIZED_KERNEL_DIR=nmsis_nn NUCLEI_SDK_NMSIS=<external/path/to/NMSIS/NMSIS> TARGET=nuclei_evalsoc kernel_conv_test
```

**Notice:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ Example usage:
# Make sure your are in tflm repo directory
cd /path/to/tensorflow
# cd to where this script located
cd tensorflow/lite/micro/nuclei_demosoc
cd tensorflow/lite/micro/nuclei_evalsoc
## current CORE is nx900fd, RISV-ARCH is rv64imafdc
# select your CORE, for example, n205, n900fd
## Support CORE list can be found in SUPPORTED_CORES
## in tensorflow/lite/micro/tools/make/targets/nuclei_demosoc_corearchabi.inc
## in tensorflow/lite/micro/tools/make/targets/nuclei_evalsoc_corearchabi.inc
## for example, select CORE nx900fd
export CORE=nx900fd
# select your ARCH_EXT, for example, p, pv
Expand All @@ -187,8 +187,8 @@ example by make command.
~~~shell
pwd
# make sure you are in the root directory of tflite-micro repo
# CORE, ARCH_EXT, DOWNLOAD, SIMU are new introduced make variables supppored by TARGET=nuclei_demosoc
## CORE can be set to be one of the SUPPORTED_CORES in tensorflow/lite/micro/tools/make/targets/nuclei_demosoc_corearchabi.inc
# CORE, ARCH_EXT, DOWNLOAD, SIMU are new introduced make variables supppored by TARGET=nuclei_evalsoc
## CORE can be set to be one of the SUPPORTED_CORES in tensorflow/lite/micro/tools/make/targets/nuclei_evalsoc_corearchabi.inc
## such as CORE=nx900f
## ARCH_EXT can be set to empty or p, v, pv
## such as ARCH_EXT=p ARCH_EXT= ARCH_EXT=pv
Expand All @@ -198,18 +198,18 @@ pwd
# You can set OPTIMIZED_KERNEL_DIR=nmsis_nn to select optimized nmsis_nn tflite-micro kernels
### Examples
## 1. Build kernel_conv_test for n300f with p extension, and optimized with nmsis_nn
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_demosoc CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn kernel_conv_test
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_evalsoc CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn kernel_conv_test
## 2. If you want to run on qemu, SIMU=qemu is required to pass to make, and clean project and rebuild is required
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_demosoc SIMU=qemu CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn clean
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_evalsoc SIMU=qemu CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn clean
## 3. Build and run on qemu for kernel_conv_test
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_demosoc SIMU=qemu CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn test_kernel_conv_test
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_evalsoc SIMU=qemu CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn test_kernel_conv_test
## 4. Build and run on qemu for micro_speech_test without nmsis_nn optimized kernel for nx600fd - p
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_demosoc SIMU=qemu CORE=nx600fd ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn test_micro_speech_test
## The build elf can be found in tensorflow/lite/micro/tools/make/gen/nuclei_demosoc_nx600fdp_micro/
# for micro_speech_test, it should be tensorflow/lite/micro/tools/make/gen/nuclei_demosoc_nx600fdp_micro/bin/micro_speech_test
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_evalsoc SIMU=qemu CORE=nx600fd ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn test_micro_speech_test
## The build elf can be found in tensorflow/lite/micro/tools/make/gen/nuclei_evalsoc_nx600fdp_micro/
# for micro_speech_test, it should be tensorflow/lite/micro/tools/make/gen/nuclei_evalsoc_nx600fdp_micro/bin/micro_speech_test
## 5. Build and run all test cases on qemu for CORE=n300f ARCH_EXT=p
## Need to use 4M ilm linker script file LINKER_SCRIPT=tensorflow/lite/micro/nuclei_demosoc/gcc_ilm_4M.ld
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_demosoc SIMU=qemu CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn LINKER_SCRIPT=tensorflow/lite/micro/nuclei_demosoc/gcc_ilm_4M.ld test
## Need to use 4M ilm linker script file LINKER_SCRIPT=tensorflow/lite/micro/nuclei_evalsoc/gcc_ilm_4M.ld
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=nuclei_evalsoc SIMU=qemu CORE=n300f ARCH_EXT=p OPTIMIZED_KERNEL_DIR=nmsis_nn LINKER_SCRIPT=tensorflow/lite/micro/nuclei_evalsoc/gcc_ilm_4M.ld test
## all the test cases will be ran on qemu, and show Pass Rate
~~~

Expand All @@ -226,7 +226,7 @@ you can type following command to download program.
# load application
(gdb) load /path/to/tflite-micro/prebuilt_elf
# example command to load prebuilt elf
# (gdb) load /home/lab/tensorflow/lite/micro/tools/make/gen/nuclei_demosoc_nx600fdp_micro/bin/micro_speech_test
# (gdb) load /home/lab/tensorflow/lite/micro/tools/make/gen/nuclei_evalsoc_nx600fdp_micro/bin/micro_speech_test
# resume core execution
(gdb) monitor resume
# quit gdb
Expand Down Expand Up @@ -297,7 +297,7 @@ This script will run all the test cases and record run log into log file.

## FAQs

### Default ilm/dlm size in demosoc is 64K/64K, need to change it to 512K to run these cases
### Default ilm/dlm size in evalsoc is 64K/64K, need to change it to 512K to run these cases

If you met issue like this: `section \`.text' will not fit in region \`ilm'`, this is caused by ilm size is not big enough to store the code, 64K is not enough to run this application, please use 512K, if you want to run on hardware,
please make sure your hardware configured with 512K ILM/DLM.
Expand All @@ -307,7 +307,7 @@ Some cases may need to change to bigger ilm/dlm to run on qemu, such as 4M.
Now this patching step is done by build system, no need to do any more steps.

~~~shell
sed -i "s/64K/512K/g" /path/to/tensorflow/lite/micro/tools/make/downloads/nuclei_sdk/SoC/demosoc/Board/nuclei_fpga_eval/Source/GCC/gcc_demosoc_ilm.ld
sed -i "s/64K/512K/g" /path/to/tensorflow/lite/micro/tools/make/downloads/nuclei_sdk/SoC/evalsoc/Board/nuclei_fpga_eval/Source/GCC/gcc_evalsoc_ilm.ld
~~~

### Error 35 downloading 'https://github.com/Nuclei-Software/nuclei-sdk/archive/refs/tags/0.4.1.zip'
Expand Down Expand Up @@ -349,7 +349,7 @@ collect2: error: ld returned 1 exit status
signalr.c:(.text._kill_r+0x14): warning: _kill is not implemented and will always fail
/home/share/devtools/nucleistudio/2022.04/NucleiStudio/toolchain/gcc/bin/../lib/gcc/riscv-nuclei-elf/10.2.0/../../../../riscv-nuclei-elf/bin/ld: /home/share/devtools/nucleistudio/2022.04/NucleiStudio/toolchain/gcc/bin/../lib/gcc/riscv-nuclei-elf/10.2.0/../../../../riscv-nuclei-elf/lib/rv64imafdc/lp64d/libc_nano.a(lib_a-lseekr.o): in function `.L0 ':
lseekr.c:(.text._lseek_r+0x16): warning: _lseek is not implemented and will always fail
make: *** [tensorflow/lite/micro/examples/micro_speech/Makefile.inc:230: tensorflow/lite/micro/tools/make/gen/nuclei_demosoc_nx900fdpv_micro/bin/micro_features_generator_test] Error 1
make: *** [tensorflow/lite/micro/examples/micro_speech/Makefile.inc:230: tensorflow/lite/micro/tools/make/gen/nuclei_evalsoc_nx900fdpv_micro/bin/micro_features_generator_test] Error 1
/home/share/devtools/nucleistudio/2022.04/NucleiStudio/toolchain/gcc/bin/../lib/gcc/riscv-nuclei-elf/10.2.0/../../../../riscv-nuclei-elf/bin/ld: /home/share/devtools/nucleistudio/2022.04/NucleiStudio/toolchain/gcc/bin/../lib/gcc/riscv-nuclei-elf/10.2.0/../../../../riscv-nuclei-elf/lib/rv64imafdc/lp64d/libc_nano.a(lib_a-readr.o): in function `.L0 ':
readr.c:(.text._read_r+0x16): warning: _read is not implemented and will always fail
/home/share/devtools/nucleistudio/2022.04/NucleiStudio/toolchain/gcc/bin/../lib/gcc/riscv-nuclei-elf/10.2.0/../../../../riscv-nuclei-elf/bin/ld: /home/share/devtools/nucleistudio/2022.04/NucleiStudio/toolchain/gcc/bin/../lib/gcc/riscv-nuclei-elf/10.2.0/../../../../riscv-nuclei-elf/lib/rv64imafdc/lp64d/libc_nano.a(lib_a-writer.o): in function `.L0 ':
Expand All @@ -362,7 +362,7 @@ Then you clean the project first by adding `CLEAN=1`, such as steps below
# Make sure your are in tflm repo directory
cd /path/to/tensorflow
# cd to where this script located
cd tensorflow/lite/micro/nuclei_demosoc
cd tensorflow/lite/micro/nuclei_evalsoc
# Assume CORE and ARCH_EXT environment variable are exported
# clean project first before run micro_speech_test provided in micro_speech example
CLEAN=1 ./run.sh micro_speech_test
Expand All @@ -378,7 +378,7 @@ Normally most will be solved by install `libglib2.0-0 libpixman-1-0`
### declared 'static' but never defined [-Werror=unused-function]
Need to add extra compiler option `-Wno-unused-function` in **PLATFORM_FLAGS** of
`tensorflow/lite/micro/tools/make/targets/nuclei_demosoc_makefile.inc`.
`tensorflow/lite/micro/tools/make/targets/nuclei_evalsoc_makefile.inc`.
### svdf.cc:272:7: error: cannot convert 'int16_t*' {aka 'short int*'} to 'q7_t*' {aka 'signed char*'}
Expand All @@ -398,8 +398,8 @@ The simple solution is use the NMSIS DSP/NN 1.1.1 we used in Nuclei SDK 0.4.1.
1. Make sure the NMSIS version is v1.1.1 (Corresponding nuclei SDK version is v0.4.1), if not, please change to this version,
just replace NMSIS from nuclei sdk 0.4.1
2. Adapt `tensorflow/lite/micro/tools/make/targets/nuclei_demosoc_makefile.inc` line 112 to 149
3. If you are using Nuclei RISC-V CPU, please select correct CORE according to nuclei_demosoc_corearchabi.inc,
2. Adapt `tensorflow/lite/micro/tools/make/targets/nuclei_evalsoc_makefile.inc` line 112 to 149
3. If you are using Nuclei RISC-V CPU, please select correct CORE according to nuclei_evalsoc_corearchabi.inc,
for example, if your RISC-V ARCH is rv32imafdc, and CPU is 300 series, then select CORE=n300fd,
if you have extra p/v extension, such as p, then ARCH_EXT should be ``p``
4. Then **DOWNLOAD** should set to correct mode to match the linker script file you want to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/
/******************************************************************************
* @file gcc_demosoc_ilm.ld
* @file gcc_evalsoc_ilm.ld
* @brief GNU Linker Script for Nuclei N/NX based device in ilm Download Mode
* @version V1.0.0
* @date 17. Dec 2019
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/env bash
TARGET=nuclei_demosoc
TARGET=nuclei_evalsoc
OPTIMIZED=${OPTIMIZED-nmsis_nn}
TARGET=nuclei_demosoc
TARGET=nuclei_evalsoc
CORE=${CORE:-nx900fd}
DOWNLOAD=${DOWNLOAD:-ilm}
ARCH_EXT=${ARCH_EXT-pv}
Expand All @@ -21,7 +21,7 @@ CASE=${2:-add}

TF_ROOT=$(readlink -f $SCRIPTDIR/../../../..)

APPBINS=tensorflow/lite/micro/tools/make/gen/${TARGET}_${CORE}${ARCH_EXT}_micro/bin
APPBINS=gen/${TARGET}_${CORE}${ARCH_EXT}_micro/bin

makeopts="-f ${TF_ROOT}/tensorflow/lite/micro/tools/make/Makefile -j DOWNLOAD=${DOWNLOAD} TARGET=${TARGET} CORE=${CORE} ARCH_EXT=${ARCH_EXT} OPTIMIZED_KERNEL_DIR=${OPTIMIZED}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fi

LOGDIR=$(pwd)/$LOGDIR

rm -rf $BUILDGENDIR/nuclei_demosoc*
rm -rf $BUILDGENDIR/nuclei_evalsoc*

mkdir -p $LOGDIR

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/env bash
TARGET=nuclei_demosoc
TARGET=nuclei_evalsoc
OPTIMIZED=${OPTIMIZED-nmsis_nn}
CORE=${CORE:-nx900fd}
DOWNLOAD=${DOWNLOAD:-ilm}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/env bash
DRYRUN=${DRYRUN:-0}
TARGET=nuclei_demosoc
TARGET=nuclei_evalsoc
OPTIMIZED=${OPTIMIZED-nmsis_nn}
LOGDIR=${LOGDIR:-gentest}
NUCLEI_SDK_NMSIS=${NUCLEI_SDK_NMSIS-}
Expand All @@ -18,7 +18,7 @@ TF_ROOT=$(readlink -f $SCRIPTDIR/../../../..)
LDSCRIPT=${LDSCRIPT-${SCRIPTDIR}/gcc_ilm_4M.ld}

if [ "x$DRYRUN" == "x0" ] ; then
rm -rf $BUILDGENDIR/nuclei_demosoc*
rm -rf $BUILDGENDIR/nuclei_evalsoc*
fi

mkdir -p $LOGDIR
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/lite/micro/testing/test_with_nuclei_qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ARCH_EXT=${4-pv}
RUNON=${5:-qemu}
DRYRUN=${DRYRUN:-0}
TMOUT=${TMOUT:-}
LOGDIR=${LOGDIR:-/tmp/nuclei_demosoc}
LOGDIR=${LOGDIR:-/tmp/nuclei_evalsoc}

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TFLM_ROOT_DIR=${SCRIPT_DIR}/..
Expand Down Expand Up @@ -109,7 +109,7 @@ function run_for_target {
do
arrs=(${binary//\// })
corearch=${arrs[-3]}
corearch=${corearch//nuclei_demosoc_/}
corearch=${corearch//nuclei_evalsoc_/}
corearch=${corearch//nuclei_evalsoc_/}
corearch=${corearch//_micro/}
break
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/tools/make/download_and_extract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ set -e
patch_nuclei_sdk() {
local nsdk_dir="${1}"

local nsdk_demosoc_lds=${1}/SoC/demosoc/Board/nuclei_fpga_eval/Source/GCC/gcc_demosoc_ilm.ld
local nsdk_evalsoc_lds=${1}/SoC/evalsoc/Board/nuclei_fpga_eval/Source/GCC/gcc_evalsoc_ilm.ld

echo "Patching Nuclei SDK, change demosoc ilm link script file, ilm/dlm size changed from 64K to 512K"
sed -i "s/64K/512K/g" $nsdk_demosoc_lds
echo "Patching Nuclei SDK, change evalsoc ilm link script file, ilm/dlm size changed from 64K to 512K"
sed -i "s/64K/512K/g" $nsdk_evalsoc_lds
echo "Finished preparing Nuclei SDK files"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uc = $(shell echo $(1) | tr a-z A-Z)
lc = $(shell echo $(1) | tr A-Z a-z)
check_item_exist = $(strip $(if $(filter 1, $(words $(1))),$(filter $(1), $(sort $(2))),))

include $(MAKEFILE_DIR)/targets/nuclei_demosoc_corearchabi.inc
include $(MAKEFILE_DIR)/targets/nuclei_evalsoc_corearchabi.inc

CORE_UPPER := $(call uc, $(CORE))
CORE_ARCH_ABI := $($(CORE_UPPER)_CORE_ARCH_ABI)
Expand All @@ -20,7 +20,7 @@ $(error Here we only support these cores: $(SUPPORTED_CORES))
endif
# Check whether CORE_ARCH_ABI is presented for CORE
ifneq ($(words $(wordlist 1, 2, $(CORE_ARCH_ABI))), 2)
$(error No correct CORE_ARCH_ABI setting for CORE=$(CORE) found in $(realpath $(MAKEFILE_DIR)/targets/nuclei_demosoc_corearchabi.inc)
$(error No correct CORE_ARCH_ABI setting for CORE=$(CORE) found in $(realpath $(MAKEFILE_DIR)/targets/nuclei_evalsoc_corearchabi.inc)
endif

# Handle Nuclei RISC-V ARCH/ABI/CMODEL/TUNE
Expand Down Expand Up @@ -114,22 +114,22 @@ CCFLAGS += $(PLATFORM_FLAGS)
INCLUDES += \
-I$(NUCLEI_SDK_NMSIS)/Core/Include \
-I$(NUCLEI_SDK_NMSIS)/NN/Include \
-I$(NUCLEI_SDK_ROOT)/SoC/demosoc/Board/nuclei_fpga_eval/Include \
-I$(NUCLEI_SDK_ROOT)/SoC/demosoc/Common/Include
-I$(NUCLEI_SDK_ROOT)/SoC/evalsoc/Board/nuclei_fpga_eval/Include \
-I$(NUCLEI_SDK_ROOT)/SoC/evalsoc/Common/Include


MICROLITE_CC_SRCS += \
$(wildcard tensorflow/lite/micro/nuclei_demosoc/*.cc)
$(wildcard tensorflow/lite/micro/nuclei_evalsoc/*.cc)

NUCLEI_SDK_SRCS := \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/demosoc/Common/Source/Drivers/*.c) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/demosoc/Common/Source/GCC/*.S) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/demosoc/Common/Source/Stubs/newlib/*.c) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/demosoc/Common/Source/*.c) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/demosoc/Board/nuclei_fpga_eval/Source/*.c)
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/evalsoc/Common/Source/Drivers/*.c) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/evalsoc/Common/Source/GCC/*.S) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/evalsoc/Common/Source/Stubs/newlib/*.c) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/evalsoc/Common/Source/*.c) \
$(wildcard $(NUCLEI_SDK_ROOT)/SoC/evalsoc/Board/nuclei_fpga_eval/Source/*.c)

THIRD_PARTY_CC_SRCS += $(NUCLEI_SDK_SRCS)
LINKER_SCRIPT ?= $(NUCLEI_SDK_ROOT)/SoC/demosoc/Board/nuclei_fpga_eval/Source/GCC/gcc_demosoc_$(DOWNLOAD).ld
LINKER_SCRIPT ?= $(NUCLEI_SDK_ROOT)/SoC/evalsoc/Board/nuclei_fpga_eval/Source/GCC/gcc_evalsoc_$(DOWNLOAD).ld

LDFLAGS += \
-T $(LINKER_SCRIPT) \
Expand Down

0 comments on commit a8f39b8

Please sign in to comment.