kendryte / canmv

Other
58 stars 21 forks source link

Support for NNCase <= 1.9.0 #35

Closed narduzzi closed 1 year ago

narduzzi commented 1 year ago

Hi,

I am trying to deploy a kmodel on a K210 (Sipeed Maix M1 dock). I would like to support the latest version of NNCase possible. My questions are as follows:

Here is what I did:

  1. Trained model using Keras, converted using NNCase 1.9.0 for MacOS.
  2. Downloaded latest CanMW IDE
  3. Built the project on the feat/kpu branch using Docker (projects/canmv_dock)
  4. Burned .bin using CanMW IDE
  5. Trying to load a kmodel on KPU, the following error is raised:
    
    ...
    kpu = KPU()
    kpu.load_kmodel("/sd/my_model.kmodel")
    ...

Traceback (most recent call last): File "", line 20, in OSError: Failed to load model MicroPython v1.0.5-5-ge1b2766 on 2023-05-23; CanMV_Board with kendryte-k210


6. Went back to docker, tried to build branch `feat/kpu` with kmodel V5 support (commit `e1b276606279797f107dba4d3f95f5a140c69984`), using menuconfig, building nncase from sources. Raises the following error:
```bash
....
[100%] Linking CXX executable canmv
/opt/kendryte-toolchain/lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lnncase
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/canmv.dir/build.make:112: canmv] Error 1
make[1]: *** [CMakeFiles/Makefile2:249: CMakeFiles/canmv.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
root@docker-desktop:/workspace/projects/canmv_dock# python3 project.py build --config_file config_defaults.mk 

How can I make the code work for my model using the latest NNCase version?

Configuration

kendryte747 commented 1 year ago

main branch use NNCase v0.2.0 Beta4 feat/kpu branch now support kmodle v5 update feat/kpu branch code under nncase lib and headers with NNCase (1.9.0) runtime. if compile faild, please check if submodule is updated?

narduzzi commented 1 year ago

Hi @kendryte747,

Thanks for your answer. I have cloned the repository again and initialized the submodules. I then switched to the feat/kpu branch. I did not update the nncase liband headerfiles yet, as I want to check that everything works fine from scratch.

It seems that the error comes from the docker, when I try to compile using nncase source code using the default config file.

Screenshot 2023-05-24 at 11 51 36

At the end of the compilation, the kendryte-toolchain does not find -lnncase.

[100%] Linking CXX executable canmv

/opt/kendryte-toolchain/lib/gcc/riscv64-unknown-elf/8.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lnncase

collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/canmv.dir/build.make:110: canmv] Error 1
make[1]: *** [CMakeFiles/Makefile2:249: CMakeFiles/canmv.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Steps to reproduce

  1. Clone and launch docker
    git clone https://github.com/kendryte/canmv
    cd canmv
    git submodule update --recursive --init
    git checkout feat/kpu
    git pull # to check it is up to date
    cd tools/docker
    sh start.sh # starts docker
    cd ~/canmv # back to root
    docker exec -it k210_build bash
  2. In docker, configure and build
    git branch # correct - feat/kpu
    cd projects/canmv_dock
    # clean project
    python project.py clean
    python project.py distclean
    # configure
    python project.py menuconfig --config_file config_defaults.mk
    # set [*] Others/compile nncase source code, save and quit
    # then compile
    python project.py build --config_file config_defaults.mk # fails at the end

Is there something that I am missing in the configuration? Should I update the kendryte-toolchain in the docker?

kendryte747 commented 1 year ago

run python3 project.py distclean before build

narduzzi commented 1 year ago

Hi @kendryte747,

Unfortunately this ends up failing too.

cd projects/canmv_dock
# clean project
python project.py clean
# edit manually config_v5.mk
python project.py distclean
python project.py build --config_file config_v5.mk # fails at the end

Changes from default configuration are:

# CONFIG_CANMV_ENABLE_KMODEL_V4 is not set
CONFIG_CANMV_ENABLE_KMODEL_V5=y
CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE=y # is this necessary?

Attached is the config file generated during the build. global_config.zip

kendryte747 commented 1 year ago

Hi @kendryte747,

Unfortunately this ends up failing too.

cd projects/canmv_dock
# clean project
python project.py clean
# edit manually config_v5.mk
python project.py distclean
python project.py build --config_file config_v5.mk # fails at the end

Changes from default configuration are:

# CONFIG_CANMV_ENABLE_KMODEL_V4 is not set
CONFIG_CANMV_ENABLE_KMODEL_V5=y
CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE=y # is this necessary?

Attached is the config file generated during the build. global_config.zip

don't select CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE, it will cause build failed. here copy libnncase.a

narduzzi commented 1 year ago

Thanks, disabling CONFIG_LIB_NNCASE_SOURCE_CODE_ENABLE solved the problem.