This is an automated email from the ASF dual-hosted git repository.

mehrdadh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new b241bca292 [microTVM][CMSIS] Add CMSIS libraries/sources to Zephyr 
CMake file (#11835)
b241bca292 is described below

commit b241bca29279149433b5f8869dd14a180a9f0080
Author: Mehrdad Hessar <[email protected]>
AuthorDate: Wed Jun 22 17:06:20 2022 -0700

    [microTVM][CMSIS] Add CMSIS libraries/sources to Zephyr CMake file (#11835)
    
    * Add CMSIS libraries to cmake build model with CMSIS
---
 .../template_project/CMakeLists.txt.template       | 29 +++++++++++++++++++---
 .../zephyr/template_project/microtvm_api_server.py | 29 +++++++++++-----------
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/apps/microtvm/zephyr/template_project/CMakeLists.txt.template 
b/apps/microtvm/zephyr/template_project/CMakeLists.txt.template
index 17e9d75c76..710cf3550c 100644
--- a/apps/microtvm/zephyr/template_project/CMakeLists.txt.template
+++ b/apps/microtvm/zephyr/template_project/CMakeLists.txt.template
@@ -23,9 +23,32 @@ set(ENV{QEMU_BIN_PATH} "${CMAKE_SOURCE_DIR}/qemu-hack")
 
 set(QEMU_PIPE "\${QEMU_PIPE}")  # QEMU_PIPE is set by the calling TVM instance.
 
+set(ENABLE_CMSIS <ENABLE_CMSIS>)
+
 find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
 project(microtvm_autogenerated_project)
 
+if(${ENABLE_CMSIS})
+  set(CMSIS_PATH $ENV{CMSIS_PATH})
+
+  file(GLOB_RECURSE cmsis_lib_srcs
+    ${CMSIS_PATH}/CMSIS/NN/Source/SoftmaxFunctions/*.c
+    ${CMSIS_PATH}/CMSIS/NN/Source/ConvolutionFunctions/*.c
+    ${CMSIS_PATH}/CMSIS/NN/Source/FullyConnectedFunctions/*.c
+    ${CMSIS_PATH}/CMSIS/NN/Source/NNSupportFunctions/*.c
+    ${CMSIS_PATH}/CMSIS/NN/Source/PoolingFunctions/*.c
+  )
+
+  set(cmsis_includes
+    ${CMSIS_PATH}/CMSIS/NN/Include
+    ${CMSIS_PATH}/CMSIS/DSP/Include
+    ${CMSIS_PATH}/CMSIS/DSP/Include/dsp
+  )
+else()
+  set(cmsis_lib_srcs "")
+  set(cmsis_includes "")
+endif()
+
 set(CRT_LIBS <API_SERVER_CRT_LIBS>)
 set(CRT_LIB_BASE crt/src/runtime/crt)
 foreach(crt_lib_name ${CRT_LIBS})
@@ -40,10 +63,10 @@ endforeach(crt_lib_name ${CRT_LIBS})
 zephyr_library_named(tvm_model)
 file(GLOB_RECURSE tvm_model_srcs model/codegen/host/src/*.c 
model/codegen/host/lib/*.o)
 target_sources(tvm_model PRIVATE ${tvm_model_srcs})
-target_include_directories(tvm_model PRIVATE ${CMAKE_SOURCE_DIR}/include 
crt_config crt/include)
+target_include_directories(tvm_model PRIVATE ${CMAKE_SOURCE_DIR}/include 
crt_config crt/include ${cmsis_includes})
 target_compile_options(tvm_model PRIVATE -Wno-unused-variable)  # 
TVM-generated code tends to include lots of these.
 target_link_libraries(app PRIVATE tvm_model)
 
 file(GLOB_RECURSE app_srcs src/**.c)
-target_sources(app PRIVATE ${app_srcs})
-target_include_directories(app PRIVATE crt_config ${CMAKE_SOURCE_DIR}/include 
crt/include)
+target_sources(app PRIVATE ${app_srcs} ${cmsis_lib_srcs})
+target_include_directories(app PRIVATE crt_config ${CMAKE_SOURCE_DIR}/include 
crt/include ${cmsis_includes})
diff --git a/apps/microtvm/zephyr/template_project/microtvm_api_server.py 
b/apps/microtvm/zephyr/template_project/microtvm_api_server.py
index 4ed3614e7a..d3559cc5f7 100644
--- a/apps/microtvm/zephyr/template_project/microtvm_api_server.py
+++ b/apps/microtvm/zephyr/template_project/microtvm_api_server.py
@@ -418,6 +418,7 @@ class Handler(server.ProjectAPIHandler):
             f.write("\n")
 
     API_SERVER_CRT_LIBS_TOKEN = "<API_SERVER_CRT_LIBS>"
+    ENABLE_CMSIS_TOKEN = "<ENABLE_CMSIS>"
 
     CRT_LIBS_BY_PROJECT_TYPE = {
         "host_driven": "microtvm_rpc_server microtvm_rpc_common 
aot_executor_module aot_executor common",
@@ -443,7 +444,15 @@ class Handler(server.ProjectAPIHandler):
             if path.is_file():
                 with open(path, "r") as lib_f:
                     lib_content = lib_f.read()
-                if "<arm_nnsupportfunctions.h>" in lib_content and 
"<arm_math.h>" in lib_content:
+                if any(
+                    header in lib_content
+                    for header in [
+                        "<arm_nnsupportfunctions.h>",
+                        "<arm_math.h>",
+                        "arm_nn_types.h",
+                        "arm_nnfunctions.h",
+                    ]
+                ):
                     return True
         return False
 
@@ -500,6 +509,10 @@ class Handler(server.ProjectAPIHandler):
                         crt_libs = 
self.CRT_LIBS_BY_PROJECT_TYPE[options["project_type"]]
                         line = line.replace("<API_SERVER_CRT_LIBS>", crt_libs)
 
+                    if self.ENABLE_CMSIS_TOKEN in line:
+                        enable_cmsis = self._cmsis_required(extract_path)
+                        line = line.replace(self.ENABLE_CMSIS_TOKEN, 
str(enable_cmsis).upper())
+
                     cmake_f.write(line)
 
                 if options.get("compile_definitions"):
@@ -507,20 +520,6 @@ class Handler(server.ProjectAPIHandler):
                     for item in flags:
                         cmake_f.write(f"target_compile_definitions(app PUBLIC 
{item})\n")
 
-            # Include CMSIS libraries if required.
-            if self._cmsis_required(extract_path):
-                cmsis_path = get_cmsis_path(options)
-                cmake_f.write("\n")
-                cmake_f.write(
-                    f'target_include_directories(tvm_model PRIVATE 
{str(cmsis_path / "CMSIS" / "DSP" / "Include")})\n'
-                )
-                cmake_f.write(
-                    f'target_include_directories(tvm_model PRIVATE 
{str(cmsis_path / "CMSIS" / "DSP" / "Include" / "dsp")})\n'
-                )
-                cmake_f.write(
-                    f'target_include_directories(tvm_model PRIVATE 
{str(cmsis_path / "CMSIS" / "NN" / "Include")})\n'
-                )
-
         self._create_prj_conf(project_dir, options)
 
         # Populate crt-config.h

Reply via email to