From 5ad27ef6506b5e50b82ee97f1a0a6aaa5fe0dbbf Mon Sep 17 00:00:00 2001 From: Ashutosh Parkhi <86472128+ashutosh-arm@users.noreply.github.com> Date: Wed, 13 Jul 2022 11:04:41 +0100 Subject: [PATCH] [CMSIS_NN] Align CMSIS-NN in TVM to TFLu SHA (#12030) * [CMSIS_NN] Align CMSIS-NN in TVM to TFLu SHA Change-Id: I7bb3b92196ad9f1a22eee87d704545e72b79ca0b * Updated CMSIS SHA to CMSIS TOT Change-Id: I0fec18e823478da991d49aa782f58f1c2f6212ba --- apps/microtvm/cmsisnn/Makefile | 39 ++++--------------- apps/microtvm/ethosu/Makefile | 30 ++++---------- docker/install/ubuntu_install_cmsis.sh | 4 +- .../backend/contrib/cmsisnn/tir_to_runtime.cc | 12 +++--- src/target/source/codegen_c_host.cc | 1 + tests/python/relay/aot/corstone300.mk | 16 ++++---- 6 files changed, 32 insertions(+), 70 deletions(-) diff --git a/apps/microtvm/cmsisnn/Makefile b/apps/microtvm/cmsisnn/Makefile index cf7d375b7e54..db72ab889663 100644 --- a/apps/microtvm/cmsisnn/Makefile +++ b/apps/microtvm/cmsisnn/Makefile @@ -56,6 +56,7 @@ DEMO_MAIN = src/demo_bare_metal.c CODEGEN_SRCS = $(wildcard $(abspath $(BUILD_DIR))/codegen/host/src/*.c) CODEGEN_OBJS = $(subst .c,.o,$(CODEGEN_SRCS)) CMSIS_STARTUP_SRCS = $(wildcard ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/*.c) +CMSIS_NN_SRCS = $(shell find ${CMSIS_PATH}/CMSIS/NN/Source/*/*.c) UART_SRCS = $(wildcard ${CORSTONE_300_PATH}/*.c) demo: $(BUILD_DIR)/demo @@ -81,42 +82,18 @@ ${BUILD_DIR}/libcmsis_startup.a: $(CMSIS_STARTUP_SRCS) $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libcmsis_startup.a) $(abspath $(BUILD_DIR))/libcmsis_startup/*.o $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libcmsis_startup.a) -CMSIS_SHA_FILE=${CMSIS_PATH}/977abe9849781a2e788b02282986480ff4e25ea6.sha -ifneq ("$(wildcard $(CMSIS_SHA_FILE))","") -${BUILD_DIR}/cmsis_nn/Source/libcmsis-nn.a: - $(QUIET)mkdir -p $(@D) - $(QUIET)cd $(CMSIS_PATH)/CMSIS/NN && $(CMAKE) -B $(abspath $(BUILD_DIR)/cmsis_nn) $(CMSIS_NN_CMAKE_FLAGS) - $(QUIET)cd $(abspath $(BUILD_DIR)/cmsis_nn) && $(MAKE) all -else -# Build CMSIS-NN -${BUILD_DIR}/cmsis_nn/Source/SoftmaxFunctions/libCMSISNNSoftmax.a: - $(QUIET)mkdir -p $(@D) - $(QUIET)cd $(CMSIS_PATH)/CMSIS/NN && $(CMAKE) -B $(abspath $(BUILD_DIR)/cmsis_nn) $(CMSIS_NN_CMAKE_FLAGS) - $(QUIET)cd $(abspath $(BUILD_DIR)/cmsis_nn) && $(MAKE) all -endif +# Build CMSIS-NN code +${BUILD_DIR}/libcmsis_nn.a: $(CMSIS_NN_SRCS) + $(QUIET)mkdir -p $(abspath $(BUILD_DIR)/libcmsis_nn) + $(QUIET)cd $(abspath $(BUILD_DIR)/libcmsis_nn) && $(CC) -c $(PKG_CFLAGS) -D${ARM_CPU} $^ + $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libcmsis_nn.a) $(abspath $(BUILD_DIR))/libcmsis_nn/*.o + $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libcmsis_nn.a) # Build demo application -ifneq ("$(wildcard $(CMSIS_SHA_FILE))","") -$(BUILD_DIR)/demo: $(DEMO_MAIN) $(UART_SRCS) $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o \ - ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a ${BUILD_DIR}/cmsis_nn/Source/libcmsis-nn.a - $(QUIET)mkdir -p $(@D) - $(QUIET)$(CC) $(PKG_CFLAGS) $(FREERTOS_FLAGS) -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(PKG_LDFLAGS) -else $(BUILD_DIR)/demo: $(DEMO_MAIN) $(UART_SRCS) $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o \ - ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a \ - ${BUILD_DIR}/cmsis_nn/Source/SoftmaxFunctions/libCMSISNNSoftmax.a \ - ${BUILD_DIR}/cmsis_nn/Source/FullyConnectedFunctions/libCMSISNNFullyConnected.a \ - ${BUILD_DIR}/cmsis_nn/Source/SVDFunctions/libCMSISNNSVDF.a \ - ${BUILD_DIR}/cmsis_nn/Source/ReshapeFunctions/libCMSISNNReshape.a \ - ${BUILD_DIR}/cmsis_nn/Source/ActivationFunctions/libCMSISNNActivation.a \ - ${BUILD_DIR}/cmsis_nn/Source/NNSupportFunctions/libCMSISNNSupport.a \ - ${BUILD_DIR}/cmsis_nn/Source/ConcatenationFunctions/libCMSISNNConcatenation.a \ - ${BUILD_DIR}/cmsis_nn/Source/BasicMathFunctions/libCMSISNNBasicMaths.a \ - ${BUILD_DIR}/cmsis_nn/Source/ConvolutionFunctions/libCMSISNNConvolutions.a \ - ${BUILD_DIR}/cmsis_nn/Source/PoolingFunctions/libCMSISNNPooling.a + ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a ${BUILD_DIR}/libcmsis_nn.a $(QUIET)mkdir -p $(@D) $(QUIET)$(CC) $(PKG_CFLAGS) $(FREERTOS_FLAGS) -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(PKG_LDFLAGS) -endif clean: $(QUIET)rm -rf $(BUILD_DIR)/codegen diff --git a/apps/microtvm/ethosu/Makefile b/apps/microtvm/ethosu/Makefile index ccfa8c1af083..1b79548eaf62 100644 --- a/apps/microtvm/ethosu/Makefile +++ b/apps/microtvm/ethosu/Makefile @@ -78,6 +78,7 @@ endif CODEGEN_SRCS = $(wildcard $(abspath $(BUILD_DIR))/codegen/host/src/*.c) CODEGEN_OBJS = $(subst .c,.o,$(CODEGEN_SRCS)) CMSIS_STARTUP_SRCS = $(wildcard ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/*.c) +CMSIS_NN_SOFTMAX_SRCS = $(shell find ${CMSIS_PATH}/CMSIS/NN/Source/SoftmaxFunctions/*.c) UART_SRCS = $(wildcard ${CORSTONE_300_PATH}/*.c) demo: $(BUILD_DIR)/demo @@ -109,33 +110,16 @@ ${BUILD_DIR}/ethosu_core_driver/libethosu_core_driver.a: $(QUIET)cd $(ETHOSU_DRIVER_PATH) && $(CMAKE) -B $(abspath $(BUILD_DIR)/ethosu_core_driver) $(DRIVER_CMAKE_FLAGS) $(QUIET)cd $(abspath $(BUILD_DIR)/ethosu_core_driver) && $(MAKE) - -CMSIS_SHA_FILE=${CMSIS_PATH}/977abe9849781a2e788b02282986480ff4e25ea6.sha -ifneq ("$(wildcard $(CMSIS_SHA_FILE))","") -# Build CMSIS-NN -${BUILD_DIR}/cmsis_nn/Source/libcmsis-nn.a: - $(QUIET)mkdir -p $(@D) - $(QUIET)cd $(CMSIS_PATH)/CMSIS/NN && $(CMAKE) -B $(abspath $(BUILD_DIR)/cmsis_nn) $(CMSIS_NN_CMAKE_FLAGS) - $(QUIET)cd $(abspath $(BUILD_DIR)/cmsis_nn) && $(MAKE) all -else # Build CMSIS-NN Softmax -${BUILD_DIR}/cmsis_nn/Source/SoftmaxFunctions/libCMSISNNSoftmax.a: - $(QUIET)mkdir -p $(@D) - $(QUIET)cd $(CMSIS_PATH)/CMSIS/NN && $(CMAKE) -B $(abspath $(BUILD_DIR)/cmsis_nn) $(CMSIS_NN_CMAKE_FLAGS) - $(QUIET)cd $(abspath $(BUILD_DIR)/cmsis_nn) && $(MAKE) CMSISNNSoftmax -endif +${BUILD_DIR}/libcmsis_nn_softmax.a: $(CMSIS_NN_SOFTMAX_SRCS) + $(QUIET)mkdir -p $(abspath $(BUILD_DIR)/libcmsis_nn) + $(QUIET)cd $(abspath $(BUILD_DIR)/libcmsis_nn) && $(CC) -c $(PKG_CFLAGS) -D${ARM_CPU} $^ + $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libcmsis_nn_softmax.a) $(abspath $(BUILD_DIR))/libcmsis_nn/*.o + $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libcmsis_nn_softmax.a) - -# Build demo application -ifneq ("$(wildcard $(CMSIS_SHA_FILE))","") -$(BUILD_DIR)/demo: $(DEMO_MAIN) src/tvm_ethosu_runtime.c $(FREERTOS_SOURCES) $(UART_SRCS) $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a ${BUILD_DIR}/ethosu_core_driver/libethosu_core_driver.a ${BUILD_DIR}/cmsis_nn/Source/libcmsis-nn.a +$(BUILD_DIR)/demo: $(DEMO_MAIN) src/tvm_ethosu_runtime.c $(FREERTOS_SOURCES) $(UART_SRCS) $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a ${BUILD_DIR}/ethosu_core_driver/libethosu_core_driver.a ${BUILD_DIR}/libcmsis_nn_softmax.a $(QUIET)mkdir -p $(@D) $(QUIET)$(CC) $(PKG_CFLAGS) $(FREERTOS_FLAGS) -o $@ $^ $(PKG_LDFLAGS) -else -$(BUILD_DIR)/demo: $(DEMO_MAIN) src/tvm_ethosu_runtime.c $(FREERTOS_SOURCES) $(UART_SRCS) $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a ${BUILD_DIR}/ethosu_core_driver/libethosu_core_driver.a ${BUILD_DIR}/cmsis_nn/Source/SoftmaxFunctions/libCMSISNNSoftmax.a - $(QUIET)mkdir -p $(@D) - $(QUIET)$(CC) $(PKG_CFLAGS) $(FREERTOS_FLAGS) -o $@ $^ $(PKG_LDFLAGS) -endif clean: $(QUIET)rm -rf $(BUILD_DIR)/codegen diff --git a/docker/install/ubuntu_install_cmsis.sh b/docker/install/ubuntu_install_cmsis.sh index 1fae6e57e006..1116b5bd6929 100755 --- a/docker/install/ubuntu_install_cmsis.sh +++ b/docker/install/ubuntu_install_cmsis.sh @@ -39,8 +39,8 @@ shift mkdir -p "${INSTALLATION_PATH}" # Download and extract CMSIS -CMSIS_SHA="977abe9849781a2e788b02282986480ff4e25ea6" -CMSIS_SHASUM="86c88d9341439fbb78664f11f3f25bc9fda3cd7de89359324019a4d87d169939eea85b7fdbfa6ad03aa428c6b515ef2f8cd52299ce1959a5444d4ac305f934cc" +CMSIS_SHA="e336766b1b5654f36244bca649917281f399bf37" +CMSIS_SHASUM="30c40824c4e008dcb9c6c77adee5115efa0cb04b6701fe2bc31ddf7be2da59f2161aeb4dbe5780cbaa709af23a3e21ea460bb2b84fa12418563125b4d426ac86" CMSIS_URL="http://github.com/ARM-software/CMSIS_5/archive/${CMSIS_SHA}.tar.gz" DOWNLOAD_PATH="/tmp/${CMSIS_SHA}.tar.gz" diff --git a/src/relay/backend/contrib/cmsisnn/tir_to_runtime.cc b/src/relay/backend/contrib/cmsisnn/tir_to_runtime.cc index d5fb2ac97e83..50fa3821b7fa 100644 --- a/src/relay/backend/contrib/cmsisnn/tir_to_runtime.cc +++ b/src/relay/backend/contrib/cmsisnn/tir_to_runtime.cc @@ -342,7 +342,7 @@ class CodeGenCMSISNN : public codegen::CodeGenCHost { // Emit CMSIS-NN API PrintIndent(); - stream << "arm_status status = "; + stream << "arm_cmsis_nn_status status = "; stream << cmsis_func_name << "("; stream << "&" << context << ", "; stream << "&" << conv_params << ", "; @@ -352,7 +352,7 @@ class CodeGenCMSISNN : public codegen::CodeGenCHost { stream << "&" << bias_dim << ", " << bias_data << ", "; stream << "&" << output_dim << ", " << output_data << ");\n"; PrintIndent(); - stream << "if (status != ARM_MATH_SUCCESS) {\n"; + stream << "if (status != ARM_CMSIS_NN_SUCCESS) {\n"; PrintIndent(); PrintIndent(); stream << "return -1;\n"; @@ -411,7 +411,7 @@ class CodeGenCMSISNN : public codegen::CodeGenCHost { std::string output_dim = EmitCMSISNNDims(stream, "output", output_dims); PrintIndent(); - stream << "arm_status status = "; + stream << "arm_cmsis_nn_status status = "; stream << cmsis_func_name << "("; stream << "&" << context << ", "; stream << "&" << cmsisnn_fc_params << ", "; @@ -421,7 +421,7 @@ class CodeGenCMSISNN : public codegen::CodeGenCHost { stream << "&" << bias_dim << ", " << bias_data << ", "; stream << "&" << output_dim << ", " << output_data << ");\n"; PrintIndent(); - stream << "if (status != ARM_MATH_SUCCESS) {\n"; + stream << "if (status != ARM_CMSIS_NN_SUCCESS) {\n"; PrintIndent(); PrintIndent(); stream << "return -1;\n"; @@ -467,7 +467,7 @@ class CodeGenCMSISNN : public codegen::CodeGenCHost { std::string output_dim = EmitCMSISNNDims(stream, "output", output_dims); PrintIndent(); - stream << "arm_status status = "; + stream << "arm_cmsis_nn_status status = "; stream << cmsis_func_name << "("; stream << "&" << context << ", "; stream << "&" << cmsisnn_pool_params << ", "; @@ -475,7 +475,7 @@ class CodeGenCMSISNN : public codegen::CodeGenCHost { stream << "&" << filter_dim << ", "; stream << "&" << output_dim << ", " << output_data << ");\n"; PrintIndent(); - stream << "if (status != ARM_MATH_SUCCESS) {\n"; + stream << "if (status != ARM_CMSIS_NN_SUCCESS) {\n"; PrintIndent(); PrintIndent(); stream << "return -1;\n"; diff --git a/src/target/source/codegen_c_host.cc b/src/target/source/codegen_c_host.cc index 67106ff07f7e..54975d166ea2 100644 --- a/src/target/source/codegen_c_host.cc +++ b/src/target/source/codegen_c_host.cc @@ -62,6 +62,7 @@ void CodeGenCHost::Init(bool output_ssa, bool emit_asserts, std::string target_s decl_stream << "#include \n"; decl_stream << "#include \n"; decl_stream << "#include \n"; + decl_stream << "#include \n"; } CodeGenC::Init(output_ssa); } diff --git a/tests/python/relay/aot/corstone300.mk b/tests/python/relay/aot/corstone300.mk index 7f95c0af2b41..374e2008f42b 100644 --- a/tests/python/relay/aot/corstone300.mk +++ b/tests/python/relay/aot/corstone300.mk @@ -74,15 +74,9 @@ CC_CODEGEN_SRCS = $(shell find $(abspath $(CODEGEN_ROOT)/host/src/*.cc)) C_CODEGEN_OBJS = $(subst .c,.o,$(C_CODEGEN_SRCS)) CC_CODEGEN_OBJS = $(subst .cc,.o,$(CC_CODEGEN_SRCS)) CMSIS_STARTUP_SRCS = $(shell find ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/*.c) +CMSIS_NN_SRCS = $(shell find ${CMSIS_PATH}/CMSIS/NN/Source/*/*.c) UART_SRCS = $(shell find ${PLATFORM_PATH}/*.c) -CMSIS_SHA_FILE=${CMSIS_PATH}/977abe9849781a2e788b02282986480ff4e25ea6.sha -ifneq ("$(wildcard $(CMSIS_SHA_FILE))","") - CMSIS_NN_LIBS = $(wildcard ${CMSIS_PATH}/CMSIS/NN/build/Source/libcmsis-nn.a) -else - CMSIS_NN_LIBS = $(wildcard ${CMSIS_PATH}/CMSIS/NN/build/Source/*/*.a) -endif - ifdef ETHOSU_TEST_ROOT ETHOSU_DRIVER_LIBS = $(wildcard ${DRIVER_PATH}/build/*.a) ETHOSU_RUNTIME=$(build_dir)/tvm_ethosu_runtime.o @@ -114,13 +108,19 @@ ${build_dir}/libcmsis_startup.a: $(CMSIS_STARTUP_SRCS) $(QUIET)$(AR) -cr $(abspath $(build_dir)/libcmsis_startup.a) $(abspath $(build_dir))/libcmsis_startup/*.o $(QUIET)$(RANLIB) $(abspath $(build_dir)/libcmsis_startup.a) +${build_dir}/libcmsis_nn.a: $(CMSIS_NN_SRCS) + $(QUIET)mkdir -p $(abspath $(build_dir)/libcmsis_nn) + $(QUIET)cd $(abspath $(build_dir)/libcmsis_nn) && $(CC) -c $(PKG_CFLAGS) -D${ARM_CPU} $^ + $(QUIET)$(AR) -cr $(abspath $(build_dir)/libcmsis_nn.a) $(abspath $(build_dir))/libcmsis_nn/*.o + $(QUIET)$(RANLIB) $(abspath $(build_dir)/libcmsis_nn.a) + ${build_dir}/libuart.a: $(UART_SRCS) $(QUIET)mkdir -p $(abspath $(build_dir)/libuart) $(QUIET)cd $(abspath $(build_dir)/libuart) && $(CC) -c $(PKG_CFLAGS) $^ $(QUIET)$(AR) -cr $(abspath $(build_dir)/libuart.a) $(abspath $(build_dir))/libuart/*.o $(QUIET)$(RANLIB) $(abspath $(build_dir)/libuart.a) -$(build_dir)/aot_test_runner: $(build_dir)/test.c $(build_dir)/crt_backend_api.o $(build_dir)/stack_allocator.o ${build_dir}/libcmsis_startup.a ${build_dir}/libuart.a $(build_dir)/libcodegen.a $(CMSIS_NN_LIBS) $(ETHOSU_DRIVER_LIBS) $(ETHOSU_RUNTIME) +$(build_dir)/aot_test_runner: $(build_dir)/test.c $(build_dir)/crt_backend_api.o $(build_dir)/stack_allocator.o $(build_dir)/libcodegen.a ${build_dir}/libcmsis_startup.a ${build_dir}/libcmsis_nn.a ${build_dir}/libuart.a $(ETHOSU_DRIVER_LIBS) $(ETHOSU_RUNTIME) $(QUIET)mkdir -p $(@D) $(QUIET)$(CC) $(PKG_CFLAGS) $(ETHOSU_INCLUDE) -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(PKG_LDFLAGS)