From 1823930ea1baaaf5975dc0b03eddb45917509410 Mon Sep 17 00:00:00 2001 From: Kristofer Jonsson Date: Fri, 17 Apr 2020 08:45:38 +0200 Subject: MLBEDSW-1729 Adding core software build files Change-Id: Ia4d90f2e8875f33b70aec2dd53e2128192a4e10a --- .gitignore | 8 ++++++++ CMakeLists.txt | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 16 ++++++++++++++++ cmsis.cmake | 39 +++++++++++++++++++++++++++++++++++++++ tensorflow.cmake | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 cmsis.cmake create mode 100644 tensorflow.cmake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d3eaf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/build +/core_driver +/cmsis +/openamp +/rtos/freertos +/rtos/mbed-os +/rtos/zephyr +/tensorflow diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..90f4319 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +# +# Copyright (c) 2019-2020 Arm Limited. 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. +# + +cmake_minimum_required(VERSION 3.15.6) + +project(core_software VERSION 0.0.1) + +# +# Define build options +# + +# Setup paths +set(CMSIS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmsis" CACHE PATH "Path to CMSIS.") +set(CORE_DRIVER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/core_driver" CACHE PATH "Path to core driver.") +set(TENSORFLOW_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tensorflow" CACHE PATH "Path to Tensorflow.") + +# Enable NPU backend +set(CORE_SOFTWARE_BACKEND "NPU" CACHE STRING "Enable NPU backend. (None, NPU)") + +# Define build options +set(CORE_SOFTWARE_RTOS "None" CACHE STRING "Select RTOS to include. (None, MbedOS, FreeRTOS, Zephyr)") + +# +# Build +# + +# Build CMSIS +include(cmsis.cmake) + +# Build core driver +set(ETHOSU_PMU_INTERACTIVE OFF) +add_subdirectory(${CORE_DRIVER_PATH} core_driver) + +# Build Tensorflow library +include(tensorflow.cmake) + +# Merge libraries into static library +add_library(ethosu_core INTERFACE) +target_link_libraries(ethosu_core INTERFACE tflu cmsis_device ethosu_core_driver) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e9ccbb5 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Ethos-U core software + +## Building + +The core software is built with CMake. It is recommended to build out of tree like illustrated below. + +``` +$ mkdir build +$ cd build +$ cmake .. -DCMAKE_TOOLCHAIN_FILE= -DCMAKE_SYSTEM_PROCESSOR=cortex-m +$ make +``` + +Available build options can be listed with `cmake -LH ..`. + +Supported CPU targets are any of the Cortex-M processors with any of the supported features, for example cortex-m33+nodsp+nofp. A toolchain file is required to cross compile the software. diff --git a/cmsis.cmake b/cmsis.cmake new file mode 100644 index 0000000..27b1090 --- /dev/null +++ b/cmsis.cmake @@ -0,0 +1,39 @@ +# +# Copyright (c) 2019-2020 Arm Limited. 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.") +endif() +string(REGEX REPLACE "^cortex-m([0-9]+)$" "\\1" CPU_NUMBER ${CMAKE_SYSTEM_PROCESSOR}) + +set(ARM_CPU "ARMCM${CPU_NUMBER}") + +# CMSIS core library +add_library(cmsis_core INTERFACE) +target_include_directories(cmsis_core INTERFACE ${CMSIS_PATH}/CMSIS/Core/Include) + +# CMSIS device library +add_library(cmsis_device OBJECT) +target_sources(cmsis_device PRIVATE + ${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_device PRIVATE ${ARM_CPU}) +target_include_directories(cmsis_device PRIVATE ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Include) +target_link_libraries(cmsis_device PRIVATE cmsis_core) diff --git a/tensorflow.cmake b/tensorflow.cmake new file mode 100644 index 0000000..355a673 --- /dev/null +++ b/tensorflow.cmake @@ -0,0 +1,47 @@ +# +# Copyright (c) 2019-2020 Arm Limited. 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. +# + +include(ProcessorCount) +ProcessorCount(J) + +set(TFLU_CC "${CMAKE_C_COMPILER} --target=${CMAKE_C_COMPILER_TARGET} -mcpu=${CMAKE_SYSTEM_PROCESSOR}${CPU_FEATURES}") +set(TFLU_CXX "${CMAKE_CXX_COMPILER} --target=${CMAKE_C_COMPILER_TARGET} -mcpu=${CMAKE_SYSTEM_PROCESSOR}${CPU_FEATURES}") +set(TFLU_AR ${CMAKE_AR}) + +set(TFLU_PATH "${TENSORFLOW_PATH}/tensorflow/lite/micro") +set(TFLU_GENDIR ${CMAKE_CURRENT_BINARY_DIR}/tensorflow/) +set(TFLU_TARGET "lib") +set(TFLU_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}${CPU_FEATURES}) +set(TFLU_ETHOSU_LIBS $) + +if(CORE_SOFTWARE_BACKEND STREQUAL NPU) + list(APPEND TFLU_TAGS "ARM_NPU") +endif() + +string(JOIN TFLU_TAGS " " TFLU_TAGS) + +# Command and target +add_custom_target(tflu_gen ALL + COMMAND make -j${J} -f ${TFLU_PATH}/tools/make/Makefile microlite TARGET=${TFLU_TARGET} TARGET_ARCH=${TFLU_TARGET_ARCH} CC_TOOL=${TFLU_CC} CXX_TOOL=${TFLU_CXX} AR_TOOL=${TFLU_AR} GENDIR=${TFLU_GENDIR} CMSIS_PATH=${CMSIS_PATH} ARM_NPU_PATH=${CORE_DRIVER_PATH} ETHOSU_LIBS=${TFLU_ETHOSU_LIBS} TAGS="${TFLU_TAGS}" + WORKING_DIRECTORY ${TENSORFLOW_PATH}) + +# Create library and link library to custom target +add_library(tflu STATIC IMPORTED) +set_property(TARGET tflu PROPERTY IMPORTED_LOCATION ${TFLU_GENDIR}/lib/libtensorflow-microlite.a) +add_dependencies(tflu tflu_gen) +target_include_directories(tflu INTERFACE ${TENSORFLOW_PATH}) -- cgit v1.2.1