• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "coder/generator/component/cmake_component.h"
18 #include <set>
19 #include <memory>
20 
21 namespace mindspore::lite::micro {
CodeCMakeNetLibrary(std::ofstream & ofs,const std::unique_ptr<CoderContext> & ctx,const Configurator * config)22 void CodeCMakeNetLibrary(std::ofstream &ofs, const std::unique_ptr<CoderContext> &ctx, const Configurator *config) {
23   ofs << "include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/)\n";
24   if (config->target() == kARM32M) {
25     ofs << "include_directories(${OP_HEADER_PATH}/CMSIS/NN/Include)\n"
26         << "include_directories(${OP_HEADER_PATH}/CMSIS/DSP/Include)\n"
27         << "include_directories(${OP_HEADER_PATH}/CMSIS/Core/Include)\n";
28   }
29   ofs << "set(OP_SRC\n";
30   for (const std::string &c_file : ctx->c_files()) {
31     ofs << "    " << c_file << ".o\n";
32   }
33   ofs << "    weight.c.o\n"
34       << "    net.c.o\n"
35       << "    session.cc.o\n"
36       << "    tensor.cc.o\n";
37   if (config->debug_mode()) {
38     ofs << "    debug_utils.c.o\n";
39   }
40   if (config->support_parallel()) {
41     ofs << "    thread_wrapper.cc.o\n"
42            "    core_affinity.cc.o\n"
43            "    threadpool.cc.o\n";
44   }
45   ofs << ")\n";
46   std::set<std::string> kernel_cmake_asm_set_files = ctx->asm_files();
47   if (!kernel_cmake_asm_set_files.empty() && (config->target() == kARM32A || config->target() == kARM64)) {
48     ofs << "set(ASSEMBLY_SRC\n";
49     for (const std::string &asm_file : kernel_cmake_asm_set_files) {
50       ofs << "    " << asm_file << ".o\n";
51     }
52     ofs << ")\n"
53         << "set_property(SOURCE ${ASSEMBLY_SRC} PROPERTY LANGUAGE C)\n"
54         << "list(APPEND OP_SRC ${ASSEMBLY_SRC})\n";
55   }
56   ofs << "file(GLOB NET_SRC\n"
57          "     ${CMAKE_CURRENT_SOURCE_DIR}/*.cc\n"
58          "     ${CMAKE_CURRENT_SOURCE_DIR}/*.c\n"
59          "     )\n"
60          "add_library(net STATIC ${NET_SRC})\n";
61 }
62 }  // namespace mindspore::lite::micro
63