Sfoglia il codice sorgente

CMSIS-NN: Clean up Cmake changes for unit tests

* Remove some unsupported code in CMakeLists.txt
* Remove Platform folder
* Update README

Change-Id: Ib14df9e34df0f09cce8270f45992d505561e5daf
Måns Nilsson 5 anni fa
parent
commit
db88c5de41

+ 19 - 48
CMSIS/NN/Tests/UnitTest/CMakeLists.txt

@@ -21,16 +21,18 @@ cmake_minimum_required(VERSION 3.15.6)
 project(cmsis_nn_unit_tests VERSION 0.0.1)
 
 set(CMSIS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." CACHE PATH "Path to CMSIS.")
-set(CMAKE_EXECUTABLE_SUFFIX ".elf")
 
 # External dependencies.
-set(UART0_BASE "0x49303000" CACHE STRING "UART base address.")
-set(UART_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../drivers/uart" CACHE PATH "Path to UART.")
-set(LINK_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../platform/fastmodels/model" CACHE PATH "Linker file.")
 set(USE_ETHOSU_CORE_PLATFORM_DEFAULT OFF)
 set(ETHOSU_CORE_PLATFORM_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../core_platform" CACHE PATH "Path to Arm Ethos-U Core Platform project.")
 set(FVP_CORSTONE_300_PATH "${ETHOSU_CORE_PLATFORM_PATH}/targets/corstone-300")
 
+option(USE_ETHOSU_CORE_PLATFORM "Use Arm Ethos-U Core Platform project." ${USE_ETHOSU_CORE_PLATFORM_DEFAULT})
+
+if(USE_ETHOSU_CORE_PLATFORM)
+    set(CMAKE_EXECUTABLE_SUFFIX ".elf")
+endif()
+
 set_property(GLOBAL PROPERTY cmsis_nn_unit_test_executables)
 
 # This function should be used instead of add_executable.
@@ -79,8 +81,6 @@ execute_process(COMMAND ${MAKE_CMD} ${MAKE_CMD_SCRIPT} ${MAKE_CMD_SCRIPT_OPTION}
                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 add_subdirectory(Unity)
 
-option(USE_ETHOSU_CORE_PLATFORM "Use Arm Ethos-U Core Platform project." ${USE_ETHOSU_CORE_PLATFORM_DEFAULT})
-
 if(USE_ETHOSU_CORE_PLATFORM)
 add_subdirectory(${FVP_CORSTONE_300_PATH} fvp_corstone_300)
 
@@ -88,31 +88,6 @@ add_library(retarget STATIC
                      ${FVP_CORSTONE_300_PATH}/retarget.c
                      ${FVP_CORSTONE_300_PATH}/uart.c)
 
-else()
-add_subdirectory(${UART_PATH} uart)
-
-include(Platform/cmsis_device.cmake)
-
-add_library(retarget STATIC
-                     Platform/Retarget.c)
-target_link_libraries(retarget INTERFACE ethosu_uart_pl011)
-
-# Linker file settings.
-if (CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang")
-    set(LINK_FILE_EXT "scatter")
-    set(LINK_FILE_OPTION "--scatter")
-    set(LINK_ENTRY_OPTION "--entry")
-    set(LINK_ENTRY "Reset_Handler")
-elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
-    set(LINK_FILE_EXT "ld")
-    set(LINK_FILE_OPTION "-T")
-    set(LINK_ENTRY_OPTION "")
-    set(LINK_ENTRY "")
-endif()
-set(LINK_FILE_OUT ${LINK_FILE}.${LINK_FILE_EXT})
-
-endif()
-
 # Link in dependencies to every unit test.
 get_property(executables GLOBAL PROPERTY cmsis_nn_unit_test_executables)
 string(REPLACE " " ";" cmsis_nn_unit_test_list_of_executables ${executables})
@@ -120,23 +95,19 @@ foreach(target ${cmsis_nn_unit_test_list_of_executables})
     target_link_libraries(${target} PRIVATE $<TARGET_OBJECTS:retarget> retarget)
     target_link_libraries(${target} PRIVATE $<TARGET_OBJECTS:cmsis_startup> cmsis_device)
     add_dependencies(${target} retarget cmsis_startup)
-    if(USE_ETHOSU_CORE_PLATFORM)
-
-        target_compile_definitions(${target} PUBLIC USING_FVP_CORSTONE_300)
-        target_link_options(${target} PRIVATE --entry Reset_Handler)
-
-        # Copy linker files.
-        if (CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang")
-            configure_file(${FVP_CORSTONE_300_PATH}/platform.scatter
-            ${CMAKE_CURRENT_SOURCE_DIR}/platform_${target}.scatter COPYONLY)
-        elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
-            configure_file(${FVP_CORSTONE_300_PATH}/platform.ld
-            ${CMAKE_CURRENT_SOURCE_DIR}/platform_${target}.ld COPYONLY)
-        endif()
 
-        ethosu_link_options(${target} PRIVATE LINK_FILE platform_${target})
-     else()
-        target_link_options(${target} PRIVATE ${LINK_FILE_OPTION} ${LINK_FILE_OUT} ${LINK_ENTRY_OPTION} ${LINK_ENTRY})
-        set_target_properties(${target} PROPERTIES LINK_DEPENDS ${LINK_FILE_OUT})
+    target_compile_definitions(${target} PUBLIC USING_FVP_CORSTONE_300)
+    target_link_options(${target} PRIVATE --entry Reset_Handler)
+
+    # Copy linker files.
+    if (CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang")
+        configure_file(${FVP_CORSTONE_300_PATH}/platform.scatter
+        ${CMAKE_CURRENT_SOURCE_DIR}/platform_${target}.scatter COPYONLY)
+    elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+        configure_file(${FVP_CORSTONE_300_PATH}/platform.ld
+        ${CMAKE_CURRENT_SOURCE_DIR}/platform_${target}.ld COPYONLY)
     endif()
+
+    ethosu_link_options(${target} PRIVATE LINK_FILE platform_${target})
 endforeach()
+endif()

+ 0 - 270
CMSIS/NN/Tests/UnitTest/Platform/Retarget.c

@@ -1,270 +0,0 @@
-/*
- * Copyright (C) 2010-2020 Arm Limited or its affiliates. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) && !defined(GCCCOMPILER)
-#include <rt_misc.h>
-#include <rt_sys.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#else
-#include <errno.h>
-#include <string.h>
-#include <sys/stat.h>
-#endif
-
-extern unsigned char UartPutc(unsigned char my_ch);
-extern unsigned char UartGetc(void);
-
-__attribute__((noreturn)) void UartEndSimulation(int code)
-{
-    UartPutc((char)0x4);  // End of simulation
-    UartPutc((char)code); // Exit code
-    while (1)
-        ;
-}
-
-void exit(int code)
-{
-    UartEndSimulation(code);
-    while (1)
-    {
-    }
-}
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) && !defined(GCCCOMPILER)
-int fputc(int ch, FILE *f)
-{
-    (void)(f);
-    return UartPutc(ch);
-}
-
-int fgetc(FILE *f)
-{
-    (void)f;
-    return UartPutc(UartGetc());
-}
-#else
-int SER_PutChar(int c) { return UartPutc(c); }
-
-int SER_GetChar(void) { return UartPutc(UartGetc()); }
-#endif
-
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) && !defined(GCCCOMPILER)
-/**
-   Copied from CMSIS/DSP/Platforms/FVP/ARMv81MML/system_ARMv81MML.c
-*/
-
-#define FH_STDIN 0x8001
-#define FH_STDOUT 0x8002
-#define FH_STDERR 0x8003
-
-const char __stdin_name[] = ":STDIN";
-const char __stdout_name[] = ":STDOUT";
-const char __stderr_name[] = ":STDERR";
-
-/**
-  The following _sys_xxx functions are defined in rt_sys.h.
-*/
-
-__attribute__((weak)) FILEHANDLE _sys_open(const char *name, int openmode)
-{
-    (void)openmode;
-
-    if (name == NULL)
-    {
-        return (-1);
-    }
-
-    if (name[0] == ':')
-    {
-        if (strcmp(name, ":STDIN") == 0)
-        {
-            return (FH_STDIN);
-        }
-        if (strcmp(name, ":STDOUT") == 0)
-        {
-            return (FH_STDOUT);
-        }
-        if (strcmp(name, ":STDERR") == 0)
-        {
-            return (FH_STDERR);
-        }
-        return (-1);
-    }
-
-    return (-1);
-}
-
-__attribute__((weak)) int _sys_close(FILEHANDLE fh)
-{
-
-    switch (fh)
-    {
-    case FH_STDIN:
-        return (0);
-    case FH_STDOUT:
-        return (0);
-    case FH_STDERR:
-        return (0);
-    }
-
-    return (-1);
-}
-
-__attribute__((weak)) int _sys_write(FILEHANDLE fh, const uint8_t *buf, uint32_t len, int mode)
-{
-    (void)buf;
-    (void)len;
-    (void)mode;
-
-    switch (fh)
-    {
-    case FH_STDIN:
-        return (-1);
-    case FH_STDOUT:
-        return (0);
-    case FH_STDERR:
-        return (0);
-    }
-
-    return (-1);
-}
-
-__attribute__((weak)) int _sys_read(FILEHANDLE fh, uint8_t *buf, uint32_t len, int mode)
-{
-    (void)buf;
-    (void)len;
-    (void)mode;
-
-    switch (fh)
-    {
-    case FH_STDIN:
-        return ((int)(len | 0x80000000U));
-    case FH_STDOUT:
-        return (-1);
-    case FH_STDERR:
-        return (-1);
-    }
-
-    return (-1);
-}
-
-__attribute__((weak)) int _sys_istty(FILEHANDLE fh)
-{
-
-    switch (fh)
-    {
-    case FH_STDIN:
-        return (1);
-    case FH_STDOUT:
-        return (1);
-    case FH_STDERR:
-        return (1);
-    }
-
-    return (0);
-}
-
-__attribute__((weak)) int _sys_seek(FILEHANDLE fh, long pos)
-{
-    (void)pos;
-
-    switch (fh)
-    {
-    case FH_STDIN:
-        return (-1);
-    case FH_STDOUT:
-        return (-1);
-    case FH_STDERR:
-        return (-1);
-    }
-
-    return (-1);
-}
-
-__attribute__((weak)) long _sys_flen(FILEHANDLE fh)
-{
-
-    switch (fh)
-    {
-    case FH_STDIN:
-        return (0);
-    case FH_STDOUT:
-        return (0);
-    case FH_STDERR:
-        return (0);
-    }
-
-    return (0);
-}
-
-__attribute__((weak)) char *(_sys_command_string)(char *cmd, int len)
-{
-    (void)len;
-
-    return cmd;
-}
-
-__attribute__((weak)) void(_sys_exit)(int return_code) { exit(return_code); }
-
-#else
-/**
-   Copied from CMSIS/DSP/DSP_Lib_TestSuite/Common/platform/GCC/Retarget.c
-*/
-
-int _open(const char *path, int flags, ...) { return (-1); }
-
-int _close(int fd) { return (-1); }
-
-int _lseek(int fd, int ptr, int dir) { return (0); }
-
-int __attribute__((weak)) _fstat(int fd, struct stat *st)
-{
-    memset(st, 0, sizeof(*st));
-    st->st_mode = S_IFCHR;
-    return (0);
-}
-
-int _isatty(int fd) { return (1); }
-
-int _read(int fd, char *ptr, int len)
-{
-    char c;
-    int i;
-
-    for (i = 0; i < len; i++)
-    {
-        c = SER_GetChar();
-        if (c == 0x0D)
-            break;
-        *ptr++ = c;
-        SER_PutChar(c);
-    }
-    return (len - i);
-}
-
-int _write(int fd, char *ptr, int len)
-{
-    int i;
-
-    for (i = 0; i < len; i++)
-        SER_PutChar(*ptr++);
-    return (i);
-}
-#endif

+ 0 - 52
CMSIS/NN/Tests/UnitTest/Platform/cmsis_device.cmake

@@ -1,52 +0,0 @@
-# Copyright (C) 2010-2020 Arm Limited or its affiliates. All rights reserved.
-#
-# SPDX-License-Identifier: Apache-2.0
-#
-# Licensed under the Apache License, Version 2.0 (the License); you may
-# not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an AS IS BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Extract the CPU number from the system processor
-string(REGEX MATCH "^cortex-m([0-9]+)$" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR})
-if(NOT CPU_NUMBER)
-    message(FATAL_ERROR "System processor '${CMAKE_SYSTEM_PROCESSOR}' not supported. Should be cortex-m<nr>.")
-endif()
-string(REGEX REPLACE "^cortex-m([0-9]+)$" "\\1" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR})
-
-set(ARM_CPU "ARMCM${CPU_NUMBER}")
-
-# Set CPU specific features
-if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m33")
-    set(ARM_FEATURES "_DSP_FP")
-elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m4")
-    set(ARM_FEATURES "_FP")
-elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "cortex-m7")
-    set(ARM_FEATURES "_DP")
-else()
-    set(ARM_FEATURES "")
-endif()
-
-# CMSIS core
-add_library(cmsis_core INTERFACE)
-target_include_directories(cmsis_core INTERFACE ${CMSIS_PATH}/CMSIS/Core/Include)
-
-# CMSIS device
-add_library(cmsis_device INTERFACE)
-target_include_directories(cmsis_device INTERFACE ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Include)
-target_compile_options(cmsis_device INTERFACE -include${ARM_CPU}${ARM_FEATURES}.h)
-
-# CMSIS startup
-add_library(cmsis_startup STATIC
-    ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/startup_${ARM_CPU}.c
-    ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/system_${ARM_CPU}.c)
-target_compile_definitions(cmsis_startup PRIVATE ${ARM_CPU}${ARM_FEATURES})
-target_link_libraries(cmsis_startup PRIVATE cmsis_device cmsis_core)

+ 2 - 19
CMSIS/NN/Tests/UnitTest/README.md

@@ -46,24 +46,8 @@ Connect any HW (e.g. NUCLEO_F746ZG) that is supported by Arm Mbed OS. Multiple b
 Use the -h flag to get more info.
 
 It is also possible to build the unit test with Cmake. The binaries can then be used with another test platform, e.g. Fastmodel.
-In this case note that toolchain, linker file and Uart code need to be provided. See externs in Retarget.c for specific Uart functions.
-UART and LINK_FILE have default values but you most probably need to replace them unless you place your code relatively to the default paths.
-
-```
-    ```mkdir build```
-    ```cd build```
-    ```cmake .. -DCMAKE_TOOLCHAIN_FILE==/path/to/toolchain.cmake -DCPU=cortex-m55 -DUART=/path/to/uart -DLINK_FILE=linkfile```
-    ```make```
-```
-
-Some examples using Uart and toolchain in Arm Ethos-U Core Software project. See : https://review.mlplatform.org/admin/repos/ml/ethos-u/ethos-u-core-software
-
-```
-    ```cmake .. -DCMAKE_TOOLCHAIN_FILE=~/ethos-u-core-software/cmake/toolchain/arm-none-eabi-gcc.cmake -DCMAKE_SYSTEM_PROCESSOR=cortex-m7 -DUART_PATH=~/ethos-u-core-software/drivers/uart -DLINK_FILE=~/platform/fastmodels/model```
-    ```cmake .. -DCMAKE_TOOLCHAIN_FILE=~/ethos-u-core-software/cmake/toolchain/arm-none-eabi-gcc.cmake -DCMAKE_SYSTEM_PROCESSOR=cortex-m55 -DUART_PATH=~/ethos-u-core-software/drivers/uart -DLINK_FILE=~/platform/fastmodels/model```
-```
-
-If using Cmake it is recommended to use Arm Ethos-U Core Platform project (https://review.mlplatform.org/admin/repos/ml/ethos-u/ethos-u-core-platform) and a fixed virtual platform (FVP) based on Arm Corstone-300 software (https://developer.arm.com/ip-products/subsystem/corstone/corstone-300). First clone the Arm Ethos-U Core Software and Arm Ethos-U Core Platform projects. Arm Ethos-U Core Software is expecting to have Tensorflow cloned but in this case it is enough to create a directory ```tensorflow``` into Arm Ethos-U Core Software. Then build:
+If using Cmake it is recommended to use Arm Ethos-U Core Platform (https://review.mlplatform.org/admin/repos/ml/ethos-u/ethos-u-core-platform) and Arm Ethos-U Core Software (https://review.mlplatform.org/admin/repos/ml/ethos-u/ethos-u-core-software) projects and a fixed virtual platform (FVP) based on Arm Corstone-300 software (https://developer.arm.com/ip-products/subsystem/corstone/corstone-300).
+First clone the Arm Ethos-U Core Software and Arm Ethos-U Core Platform projects. Arm Ethos-U Core Software is expecting to have Tensorflow cloned but in this case it is enough to create a directory ```tensorflow``` into Arm Ethos-U Core Software. Then build:
 
 ```
     ```mkdir build```
@@ -119,4 +103,3 @@ Once you are happy with the new test data set, it should be added in the load_al
 - `TestCases/<cmsis-nn function name>/Unity` - This folder contains a Unity file that calls the actual unit tests. For example for arm_convolve_s8() the file is called unity_test_arm_convolve_s8.c.
 - `TestCases/<cmsis-nn function name>/Unity/TestRunner` - This folder will contain the autogenerated Unity test runner.
 - `TestCases/TestData` - This is auto generated test data that the unit tests are using. It is the same data as in the PregenrateData folder but in actual C header format. The advantage of having the same data in two places, is that the data can be easily regenerated (randomized) with the same config. All data can regenerated or only parts of it (e.g. only bias data). Of course even the config can be regenerated. This might be useful during debugging.
-- `Platform` - This is only used when using Cmake. It is handling dependencies lika Uart, that would otherwise be handled by Arm Mbed OS.