From 712d9b95030348aca1251794ef1b1781ee803c5c Mon Sep 17 00:00:00 2001 From: Luka Macan Date: Wed, 7 Feb 2024 11:20:16 +0100 Subject: [PATCH] wip: add cmake support for test --- test/.gitignore | 2 + test/app/CMakeLists.txt | 57 ++++++++++++++++++++ test/app/cmake/gap9.cmake | 16 ++++++ test/app/cmake/pulp-sdk-base.cmake | 72 +++++++++++++++++++++++++ test/app/cmake/pulp-sdk-siracusa.cmake | 66 +++++++++++++++++++++++ test/app/cmake/toolchain-gcc-pulp.cmake | 51 ++++++++++++++++++ 6 files changed, 264 insertions(+) create mode 100644 test/app/CMakeLists.txt create mode 100644 test/app/cmake/gap9.cmake create mode 100644 test/app/cmake/pulp-sdk-base.cmake create mode 100644 test/app/cmake/pulp-sdk-siracusa.cmake create mode 100644 test/app/cmake/toolchain-gcc-pulp.cmake diff --git a/test/.gitignore b/test/.gitignore index 50e5358..521477d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -6,3 +6,5 @@ app/gen **/compile_commands.json **/*.log **/*.pt +**/build +**/sdk.config diff --git a/test/app/CMakeLists.txt b/test/app/CMakeLists.txt new file mode 100644 index 0000000..0da6378 --- /dev/null +++ b/test/app/CMakeLists.txt @@ -0,0 +1,57 @@ +cmake_minimum_required(VERSION 3.19) + +# Board includes +if (NOT DEFINED ENV{ACCELERATOR}) + message(FATAL_ERROR "Environment variable ACCELERATOR is undefined. Set it to the preferred accelerator.") +endif() + +if ($ENV{ACCELERATOR} STREQUAL ne16) + include(cmake/gap9.cmake) + set(USE_NE16 ON) +elseif ($ENV{ACCELERATOR} STREQUAL neureka) + include(cmake/toolchain-gcc-pulp.cmake) + set(USE_NEUREKA ON) +else() + message(FATAL_ERROR "Unrecognized ACCELERATOR: $ENV{ACCELERATOR}. Set accelerator to either \"ne16\" or \"neureka\".") +endif() + +# Project +project("nnx_test_app" C ASM) + +file(GLOB GEN_SRCS gen/src/*.c) +add_executable(nnx_test_app + src/main.c + src/nnx_layer.c + ${GEN_SRCS} + ) + +target_include_directories(nnx_test_app PUBLIC inc gen/inc) + +# PULP-NNX library +add_subdirectory(../.. pulp-nnx) + +if ($ENV{ACCELERATOR} STREQUAL ne16) + get_target_property(PULP_NNX_SRCS pulp-nnx SOURCES) + list(TRANSFORM PULP_NNX_SRCS PREPEND "../../") + target_sources(nnx_test_app PUBLIC ${PULP_NNX_SRCS}) + + get_target_property(PULP_NNX_INC_DIRS pulp-nnx INCLUDE_DIRECTORIES) + target_include_directories(nnx_test_app PUBLIC ${PULP_NNX_INC_DIRS}) + + add_compile_definitions(NNX_ACCELERATOR="ne16") + add_compile_definitions(NNX_NE16) + board_postamble(nnx_test_app) +elseif ($ENV{ACCELERATOR} STREQUAL neureka) + include(cmake/pulp-sdk-siracusa.cmake) + + get_target_property(PULP_SDK_INC_DIRS pulp-sdk INCLUDE_DIRECTORIES) + message(STATUS ${PULP_SDK_INC_DIRS}) + + target_include_directories(nnx_test_app PUBLIC ${PULP_SDK_INCLUDES}) + target_compile_options(nnx_test_app PUBLIC ${PULP_SDK_COMPILE_FLAGS}) + + target_link_libraries(nnx_test_app PUBLIC pulp-nnx pulp-sdk) + + add_compile_definitions(NNX_ACCELERATOR="neureka") + add_compile_definitions(NNX_NEUREKA) +endif() diff --git a/test/app/cmake/gap9.cmake b/test/app/cmake/gap9.cmake new file mode 100644 index 0000000..c9c0ff5 --- /dev/null +++ b/test/app/cmake/gap9.cmake @@ -0,0 +1,16 @@ +set(CONFIG_GAP_SDK_HOME $ENV{GAP_SDK_HOME}) +include($ENV{GAP_SDK_HOME}/utils/cmake/setup.cmake) + +function(board_postamble target) + # For validation purposes + if (DEFINED USE_CUSTOM_XIP) + if (${USE_CUSTOM_XIP} EQUAL 1) + set(CONFIG_XIP y) + set(CONFIG_XIP_VIRTUAL_ADDRESS 0x20000000) + set(CONFIG_XIP_PAGE_SIZE 2) + set(CONFIG_XIP_PAGE_NUMBER 12) + endif() + endif() + + setupos(${target}) +endfunction() diff --git a/test/app/cmake/pulp-sdk-base.cmake b/test/app/cmake/pulp-sdk-base.cmake new file mode 100644 index 0000000..8c7109d --- /dev/null +++ b/test/app/cmake/pulp-sdk-base.cmake @@ -0,0 +1,72 @@ +set(PULP_SDK_HOME $ENV{PULP_SDK_HOME}) + +set(PULP_SDK_BASE_C_SOURCE + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/ram/ram.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/ram/alloc_extern.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/ram/hyperram/hyperram.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/fs/read_fs/read_fs.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/fs/host_fs/semihost.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/fs/host_fs/host_fs.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/fs/fs.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/flash/hyperflash/hyperflash.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/flash/flash.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/partition/partition.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/partition/flash_partition.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/crc/md5.c + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/bsp/siracusa.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/init.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/kernel.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/device.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/task.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/alloc.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/alloc_pool.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/irq.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/soc_event.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/log.c + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/time.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/hyperbus/hyperbus-v3.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/uart/uart-v1.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/udma/udma-v3.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/cluster/cluster.c + ${PULP_SDK_HOME}/rtos/pulpos/common/lib/libc/minimal/io.c + ${PULP_SDK_HOME}/rtos/pulpos/common/lib/libc/minimal/fprintf.c + ${PULP_SDK_HOME}/rtos/pulpos/common/lib/libc/minimal/prf.c + ${PULP_SDK_HOME}/rtos/pulpos/common/lib/libc/minimal/sprintf.c + ${PULP_SDK_HOME}/rtos/pulpos/common/lib/libc/minimal/semihost.c +) + +set(PULP_SDK_BASE_ASM_SOURCE + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/crt0.S + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/irq_asm.S + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/task_asm.S + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/time_asm.S + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel/soc_event_v2_itc.S + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/cluster/pe-eu-v3.S +) + +set(PULP_SDK_BASE_INCLUDE + ${PULP_SDK_HOME}/rtos/pulpos/common/lib/libc/minimal/include + ${PULP_SDK_HOME}/rtos/pulpos/common/include + ${PULP_SDK_HOME}/rtos/pulpos/common/kernel + ${PULP_SDK_HOME}/rtos/pulpos/pulp_archi/include + ${PULP_SDK_HOME}/rtos/pulpos/pulp_hal/include + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_api/include + ${PULP_SDK_HOME}/rtos/pulpos/pulp/include + ${PULP_SDK_HOME}/rtos/pmsis/pmsis_bsp/include +) + +set(PULP_SDK_BASE_COMPILE_FLAGS + -D__riscv__ + -D__CONFIG_UDMA__ + -D__PULPOS2__ + -D__PLATFORM__=ARCHI_PLATFORM_GVSOC + -DARCHI_CLUSTER_NB_PE=8 + -DPOS_CONFIG_IO_UART=0 + -DPOS_CONFIG_IO_UART_BAUDRATE=115200 + -DPOS_CONFIG_IO_UART_ITF=0 + -D__TRACE_LEVEL__=3 + -DPI_LOG_LOCAL_LEVEL=2 +) + +set_source_files_properties(${PULP_SDK_BASE_ASM_SOURCE} PROPERTIES COMPILE_FLAGS -DLANGUAGE_ASSEMBLY) +add_library(pulp-sdk-base OBJECT ${PULP_SDK_BASE_C_SOURCE} ${PULP_SDK_BASE_ASM_SOURCE}) diff --git a/test/app/cmake/pulp-sdk-siracusa.cmake b/test/app/cmake/pulp-sdk-siracusa.cmake new file mode 100644 index 0000000..ec1235d --- /dev/null +++ b/test/app/cmake/pulp-sdk-siracusa.cmake @@ -0,0 +1,66 @@ +include(cmake/pulp-sdk-base.cmake) + +set(PULP_SDK_HOME $ENV{PULP_SDK_HOME}) + +set(SIRACUSA_COMPILE_FLAGS + -include ${PULP_SDK_HOME}/rtos/pulpos/pulp/include/pos/chips/siracusa/config.h + -DCONFIG_SIRACUSA + -DCONFIG_BOARD_VERSION_SIRACUSA + -DCONFIG_PROFILE_SIRACUSA + -DSKIP_PLL_INIT + -DUSE_HYPERFLASH + -DUSE_HYPERRAM + -DPULP_CHIP_STR=siracusa +) + +set(SIRACUSA_INCLUDES + ${PULP_SDK_HOME}/rtos/pulpos/pulp/include/pos/chips/siracusa + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/i3c/include + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/siracusa_padmux/include +) + +set(PULP_SDK_SIRACUSA_C_SOURCE + ${PULP_SDK_HOME}/rtos/pulpos/pulp/kernel/chips/siracusa/pll.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/kernel/chips/siracusa/soc.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/i3c/src/cdn_print.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/i3c/src/command_list.c + #${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/i3c/src/i3c.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/i3c/src/i3c_obj_if.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/i3c/src/cps_impl.c + ${PULP_SDK_HOME}/rtos/pulpos/pulp/drivers/siracusa_padmux/src/siracusa_padctrl.c +) + +set_source_files_properties(${PULP_SDK_SIRACUSA_ASM_SOURCE} PROPERTIES COMPILE_FLAGS -DLANGUAGE_ASSEMBLY) +add_library(pulp-sdk OBJECT ${PULP_SDK_BASE_C_SOURCE} ${PULP_SDK_BASE_ASM_SOURCE} ${PULP_SDK_SIRACUSA_C_SOURCE} ${PULP_SDK_SIRACUSA_ASM_SOURCE}) + +set(PULP_SDK_COMPILE_FLAGS ${SIRACUSA_COMPILE_FLAGS} ${PULP_SDK_BASE_COMPILE_FLAGS}) +set(PULP_SDK_INCLUDES ${SIRACUSA_INCLUDES} ${PULP_SDK_BASE_INCLUDE}) + +target_include_directories(pulp-sdk SYSTEM PUBLIC ${PULP_SDK_INCLUDES}) +target_compile_options(pulp-sdk PUBLIC ${PULP_SDK_COMPILE_FLAGS}) +target_compile_options(pulp-sdk PRIVATE + -O2 + -Wno-sign-conversion + -Wno-unused-function + -Wno-unused-parameter + -Wno-conversion + -Wno-sign-conversion + -Wno-unused-variable + -Wno-sign-compare + -Wno-return-type + -fno-inline-functions +) +target_compile_options(pulp-sdk INTERFACE + -Wno-unused-function +) + + +set(SIRACUSA_LINK_OPTIONS + -Wl,--gc-sections + -L${PULP_SDK_HOME}/rtos/pulpos/pulp/kernel + -Tchips/siracusa/link.ld +) + +target_link_libraries(pulp-sdk PUBLIC + ${SIRACUSA_LINK_OPTIONS} +) diff --git a/test/app/cmake/toolchain-gcc-pulp.cmake b/test/app/cmake/toolchain-gcc-pulp.cmake new file mode 100644 index 0000000..ab5d566 --- /dev/null +++ b/test/app/cmake/toolchain-gcc-pulp.cmake @@ -0,0 +1,51 @@ +set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") + +set(TOOLCHAIN_PREFIX $ENV{PULP_RISCV_GCC_TOOLCHAIN}/bin/riscv32-unknown-elf) + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_EXECUTABLE_SUFFIX ".elf") + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy) +set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump) +set(CMAKE_AR ${TOOLCHAIN_PREFIX}-ar) +set(SIZE ${TOOLCHAIN_PREFIX}-size) + +set(ISA rv32imfcxpulpv3) +set(PE 8) +set(FC 1) + +add_compile_options( + -march=${ISA} + -mPE=${PE} + -mFC=${FC} + -ffunction-sections + -fdata-sections + -fomit-frame-pointer + -O2 + -g3 + -DNUM_CORES=${NUM_CORES} + -MMD + -MP +) + +add_link_options( + -MMD + -MP + -march=${ISA} + -mPE=${PE} + -mFC=${FC} + -nostartfiles + -nostdlib + -Wl,--print-memory-usage +) + +link_libraries( + -lm + -lgcc +) + +add_compile_definitions(__LINK_LD) +add_compile_definitions(__TOOLCHAIN_GCC__)