Rewrite RISP4ML in plain-C for Shodan

This CL is Part 1 of the comprehensive 3-part changes of integrating RISP4ML into Shodan ML toolchain. This change focuses on re-writing RISP4ML in plain-C.

Part 2 and 3 will be submitted after this CL is merged (codes can be
seen at Patch Set #13).

Details of the 3-part changes:

(Part 1) Completely re-wrote RISP4ML in plain C.
- The original RISP4ML on google3 was written in C++. The memory usage with C++ RISP4ML was significantly larger. Thus, I have completely re-written RISP4ML in plain C. The memory increase with the plain-C RISP4ML is much smaller.
- Made the input/output shape to be configurable arguments instead of constants.
- Made low-level optimizations and simplifications.

(Part 2) Integrated plain-C RISP4ML into Shodan ML toolchain
- Use fssd_25_8bit_v2 as an example to load the binary (raw bayer) file and go through RISP4ML toolchain, and feed the RISP4ML output into IREE flow.
- The fssd_25_8bit_v2 example is up and running, and the correctness of output has been verified (compare output@plain-C risp4ml against output@google3).

(Part 3) Added unit tests for plain-C RISP4ML
- Added unit tests based on pw_unit_test
- Build unit tests in iree_cc_binary
- Run and check unit tests via lit_test

Change-Id: Id17dd01fd3848d9705b8b39ea2866bde3334613c
25 files changed
tree: 720fb46991ac4430c27947df8619232afb6c7160
  1. build_tools/
  2. cmake/
  3. native_log/
  4. samples/
  5. CMakeLists.txt
  6. README.md
  7. springbok_config.h
README.md

Springbok Model Execution Repository

This project contains ML model codegen and execution libraries/examples. The artifacts built from this project is targeted for RISC-V 32-bit baremetal machine (Springbok).

Prerequisite

If you get this project from Project Shodan manifest, you are all set. If not, you need to have following projects as well to build the project successfully.

This project needs to be at <dir>/sw/vec_iree

Code structure

  • build_tools: Utility scripts for the project
  • cmake: CMake Macros for the project
  • native_log: BSP support for the Linux userspace emulation
  • samples: Codegen and execution of ML models based on IREE
    • device: Device HAL driver library
    • float_model: float model examples
    • quant_model: quantized model examples
    • simple_vec_mul: Point-wise vector multiplication examples
    • util: Runtime utility library for model execution

Build the project

If you are running from Project Shodan repo, you can build the artifacts with m iree. If you download this project alone, you need to download/build IREE's host compiler, then at the top level directory

  cmake -B <output dir> -G Ninja \
     -DCMAKE_TOOLCHAIN_FILE="$(realpath sw/vec_iree/cmake/riscv_iree.cmake)" \
     -DCMAKE_BUILD_TYPE=MinSizeRel \
     -DIREE_HOST_BINARY_ROOT="$(IREE_COMPILER_DIR)/install" \
     -DRISCV_TOOLCHAIN_ROOT=$(TOOLCHAINRV32_PATH) \
     <dir>/sw/vec_iree
  cmake --build <output dir> --target all

Run the executables

You can run QEMU or RENODE emulation with the built executables. In Shodan repo, qemu_sim_springbok for QEMU emulation, and sim_springbok for Renode simulation. Out-of-repo emulation is possible but require more steps.

Test the executables

In Shodan, this project utilizes LLVM lit and FileCheck to test the ML executable performance. The tests are defined in the *_test.txt files under samples. To run the test, at the Shodan top level directory

lit --path <Filecheck dir> -a sw/vec_iree/samples

Filecheck in Debian testing is under /usr/lib/llvm-11/bin

Add -D FEATURES=internal to enable the internal model tests. Add -D RUNNER=qemu to enable the qemu tests.