!13090 use c++ raw string && fix bug

From: @zhujingxuan
Reviewed-by: @wangchengyuan,@zhanghaibo5
Signed-off-by: @wangchengyuan
pull/13090/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit ca8c07d65b

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.14)
project(micro)
option(BUILD_TESTCASES "if build testcase" on)
option(ENABLE_CONVERTER "turn it on to compile codegen" on)
string(REPLACE "/mindspore/lite/micro" "" TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_STANDARD 17)

@ -25,6 +25,12 @@ set(CODER_GENERATOR_SRC
${MICRO_DIR}/coder/generator/component/cmake_component.cc
${MICRO_DIR}/coder/generator/component/train_component.cc
${MICRO_DIR}/coder/generator/component/parallel_component.cc
${MICRO_DIR}/coder/generator/component/const_blocks/cmake_lists.cc
${MICRO_DIR}/coder/generator/component/const_blocks/debug_utils.cc
${MICRO_DIR}/coder/generator/component/const_blocks/license.cc
${MICRO_DIR}/coder/generator/component/const_blocks/load_input.cc
${MICRO_DIR}/coder/generator/component/const_blocks/micro_tensor.cc
${MICRO_DIR}/coder/generator/component/const_blocks/thread_pool.cc
)
set(MINDSPORE_CORE
@ -305,7 +311,6 @@ set(LITE_KERNEL_SRC
if("${X86_64_SIMD}" STREQUAL "sse")
set(SSE_SRC
${LITE_DIR}/nnacl/intrinsics/sse/sse_common.c
${LITE_DIR}/nnacl/intrinsics/sse/PackNHWCToNCHWFp32.c
${LITE_DIR}/nnacl/intrinsics/sse/MatMul_Sse.c
)
set_property(SOURCE ${SSE_SRC} PROPERTY LANGUAGE C)
@ -319,7 +324,6 @@ if("${X86_64_SIMD}" STREQUAL "avx")
${LITE_DIR}/nnacl/intrinsics/avx/common_utils.c
${LITE_DIR}/nnacl/intrinsics/sse/sse_common.c
${LITE_DIR}/nnacl/intrinsics/sse/MatMul_Sse.c
${LITE_DIR}/nnacl/intrinsics/sse/PackNHWCToNCHWFp32.c
${LITE_DIR}/nnacl/assembly/avx/MatmulAvx.S
)
set_property(SOURCE ${AVX_SRC} PROPERTY LANGUAGE C)

@ -25,7 +25,7 @@ include(${MICRO_DIR}/cmake/file_list.cmake)
include(${MICRO_DIR}/cmake/package_wrapper.cmake)
add_subdirectory(operator_library)
if(NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64)
if(ENABLE_CONVERTER)
add_executable(codegen main.cc ${FILE_SET})
add_dependencies(codegen fbs_src)
add_dependencies(codegen fbs_inner_src)

@ -0,0 +1,141 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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 "coder/generator/component/const_blocks/cmake_lists.h"
namespace mindspore::lite::micro {
const char *bench_cmake_lists_txt = R"RAW(
cmake_minimum_required(VERSION 3.14)
project(benchmark)
message("project name: ${MODEL_LIB_PATH}")
function(parse_lib_info lib_full_path lib_name lib_path)
string(FIND "${lib_full_path}" "/" POS REVERSE)
math(EXPR POS "${POS} + 1")
string(SUBSTRING ${lib_full_path} 0 ${POS} path)
set(${lib_path} ${path} PARENT_SCOPE)
string(SUBSTRING ${lib_full_path} "${POS}" "-1" name)
set(${lib_name} ${name} PARENT_SCOPE)
endfunction(parse_lib_info)
parse_lib_info(${MODEL_LIB} MODEL_LIB_NAME MODEL_LIB_PATH)
option(MICRO_BUILD_ARM64 "build android arm64" OFF)
option(MICRO_BUILD_ARM32A "build android arm32" OFF)
if(MICRO_BUILD_ARM64 OR MICRO_BUILD_ARM32A)
add_compile_definitions(ENABLE_NEON)
add_compile_definitions(ENABLE_ARM)
endif()
if(MICRO_BUILD_ARM64)
add_compile_definitions(ENABLE_ARM64)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+dotprod")
endif()
if(MICRO_BUILD_ARM32A)
add_compile_definitions(ENABLE_ARM32)
add_definitions(-mfloat-abi=softfp -mfpu=neon)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
set(CMAKE_C_FLAGS "${CMAKE_ENABLE_C99} ${CMAKE_C_FLAGS}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message("*******************${CMAKE_BUILD_TYPE}**********")
set(CMAKE_C_FLAGS "-DDebug -g -fPIC -fPIE -fvisibility=default ${CMAKE_C_FLAGS}")
else()
set(CMAKE_C_FLAGS "-fPIC -fPIE -O3 -fstack-protector-strong -fomit-frame-pointer ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_Release "${CMAKE_C_FLAGS_Release} -O3 -ffunction-sections -fdata-sections")
endif()
link_directories(${MODEL_LIB_PATH})
include(benchmark.cmake)
add_executable(benchmark ${SRC_FILES})
target_link_libraries(benchmark ${MODEL_LIB_NAME} -lm -pthread)
)RAW";
const char *src_cmake_lists_txt = R"RAW(
cmake_minimum_required(VERSION 3.14)
project(net)
message("operator lib path: ${OP_LIB}")
message("operator header path: ${OP_HEADER_PATH}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
include_directories(${OP_HEADER_PATH})
include(net.cmake)
option(MICRO_BUILD_ARM64 "build android arm64" OFF)
option(MICRO_BUILD_ARM32A "build android arm32" OFF)
if(MICRO_BUILD_ARM64 OR MICRO_BUILD_ARM32A)
add_compile_definitions(ENABLE_NEON)
add_compile_definitions(ENABLE_ARM)
endif()
if(MICRO_BUILD_ARM64)
add_compile_definitions(ENABLE_ARM64)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+dotprod")
endif()
if(MICRO_BUILD_ARM32A)
add_compile_definitions(ENABLE_ARM32)
add_definitions(-mfloat-abi=softfp -mfpu=neon)
endif()
set(CMAKE_C_FLAGS "${CMAKE_ENABLE_C99} ${CMAKE_C_FLAGS}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(CMAKE_C_FLAGS "-DDebug -g -fPIC -fPIE -fvisibility=default ${CMAKE_C_FLAGS}")
else()
set(CMAKE_C_FLAGS "-fPIC -fPIE -O3 -Werror -fstack-protector-strong -fomit-frame-pointer ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_Release "${CMAKE_C_FLAGS_Release} -O3 -ffunction-sections -Werror -fdata-sections")
string(REPLACE "-g" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endif()
function(create_library)
add_custom_command(TARGET net
POST_BUILD
COMMAND rm -rf tmp
COMMAND mkdir tmp
COMMAND cd tmp && ar -x ${OP_LIB}
COMMAND echo "raw static library ${library_name} size:"
COMMAND ls -lh ${library_name}
COMMAND mv ${library_name} ./tmp && cd tmp && ar -x ${library_name}
COMMENT "unzip raw static library ${library_name}"
)
foreach(object_file ${OP_SRC})
add_custom_command(TARGET net POST_BUILD COMMAND mv ./tmp/${object_file} .)
endforeach()
add_custom_command(TARGET net
POST_BUILD
COMMAND ar cr ${library_name} *.o
COMMAND ranlib ${library_name}
COMMAND echo "new static library ${library_name} size:"
COMMAND ls -lh ${library_name}
COMMAND rm -rf tmp && rm -rf *.o
COMMENT "generate specified static library ${library_name}"
)
endfunction(create_library)
string(CONCAT library_name "lib" net ".a")
create_library()
)RAW";
} // namespace mindspore::lite::micro

@ -14,101 +14,14 @@
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_CMAKE_LISTS_CODE_H_
#define MICRO_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_CMAKE_LISTS_CODE_H_
#ifndef MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_CMAKE_LISTS_H_
#define MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_CMAKE_LISTS_H_
const char *bench_cmake_lists_txt =
"cmake_minimum_required(VERSION 3.14)\n"
"project(benchmark)\n"
"\n"
"message(\"project name: ${MODEL_LIB_PATH}\")\n"
"message(\"architecture cmake file path: ${ARCH_CMAKE_PATH}\")\n"
"\n"
"function(parse_lib_info lib_full_path lib_name lib_path)\n"
" string(FIND \"${lib_full_path}\" \"/\" POS REVERSE)\n"
" math(EXPR POS \"${POS} + 1\")\n"
" string(SUBSTRING ${lib_full_path} 0 ${POS} path)\n"
" set(${lib_path} ${path} PARENT_SCOPE)\n"
" string(SUBSTRING ${lib_full_path} \"${POS}\" \"-1\" name)\n"
" set(${lib_name} ${name} PARENT_SCOPE)\n"
"endfunction(parse_lib_info)\n"
"\n"
"parse_lib_info(${MODEL_LIB} MODEL_LIB_NAME MODEL_LIB_PATH)\n"
"\n"
"if (\"${ARCH_CMAKE_PATH}\" STREQUAL \"\")\n"
" message(\"arch is x86_64\")\n"
"else ()\n"
" include(${ARCH_CMAKE_PATH})\n"
"endif ()\n"
"\n"
"include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)\n"
"\n"
"set(CMAKE_C_FLAGS \"${CMAKE_ENABLE_C99} ${CMAKE_C_FLAGS}\")\n"
"if (\"${CMAKE_BUILD_TYPE}\" STREQUAL \"Debug\")\n"
" message(\"*******************${CMAKE_BUILD_TYPE}**********\")\n"
" set(CMAKE_C_FLAGS \"-DDebug -g -fPIC -fPIE -fvisibility=default ${CMAKE_C_FLAGS}\")\n"
"else ()\n"
" set(CMAKE_C_FLAGS \"-fPIC -fPIE -O3 -fstack-protector-strong -fomit-frame-pointer ${CMAKE_C_FLAGS}\")\n"
" set(CMAKE_C_FLAGS_Release \"${CMAKE_C_FLAGS_Release} -O3 -ffunction-sections -fdata-sections\")\n"
"endif ()\n"
"link_directories(${MODEL_LIB_PATH})\n"
"include(benchmark.cmake)\n"
"add_executable(benchmark ${SRC_FILES})\n"
"target_link_libraries(benchmark ${MODEL_LIB_NAME} -lm -pthread)\n";
namespace mindspore::lite::micro {
const char *src_cmake_lists_txt =
"cmake_minimum_required(VERSION 3.14)\n"
"project(net)\n"
"\n"
"message(\"architecture cmake file path: ${ARCH_CMAKE_PATH}\")\n"
"message(\"operator lib path: ${OP_LIB}\")\n"
"message(\"operator header path: ${OP_HEADER_PATH}\")\n"
"\n"
"include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)\n"
"include_directories(${OP_HEADER_PATH})\n"
"\n"
"include(net.cmake)\n"
"\n"
"if(\"${ARCH_CMAKE_PATH}\" STREQUAL \"\")\n"
" message(\"arch is x86_64\")\n"
"else()\n"
" include(${ARCH_CMAKE_PATH})\n"
"endif()\n"
"\n"
"set(CMAKE_C_FLAGS \"${CMAKE_ENABLE_C99} ${CMAKE_C_FLAGS}\")\n"
"if(\"${CMAKE_BUILD_TYPE}\" STREQUAL \"Debug\")\n"
" set(CMAKE_C_FLAGS \"-DDebug -g -fPIC -fPIE -fvisibility=default ${CMAKE_C_FLAGS}\")\n"
"else()\n"
" set(CMAKE_C_FLAGS \"-fPIC -fPIE -O3 -Werror -fstack-protector-strong -fomit-frame-pointer ${CMAKE_C_FLAGS}\")\n"
" set(CMAKE_C_FLAGS_Release \"${CMAKE_C_FLAGS_Release} -O3 -ffunction-sections -Werror -fdata-sections\")\n"
" string(REPLACE \"-g\" \"\" CMAKE_C_FLAGS \"${CMAKE_C_FLAGS}\")\n"
"endif()\n"
"\n"
"function(create_library)\n"
" add_custom_command(TARGET net\n"
" POST_BUILD\n"
" COMMAND rm -rf tmp\n"
" COMMAND mkdir tmp\n"
" COMMAND cd tmp && ar -x ${OP_LIB}\n"
" COMMAND echo \"raw static library ${library_name} size:\"\n"
" COMMAND ls -lh ${library_name}\n"
" COMMAND mv ${library_name} ./tmp && cd tmp && ar -x ${library_name}\n"
" COMMENT \"unzip raw static library ${library_name}\"\n"
" )\n"
" foreach (object_file ${OP_SRC})\n"
" add_custom_command(TARGET net POST_BUILD COMMAND mv ./tmp/${object_file} .)\n"
" endforeach ()\n"
" add_custom_command(TARGET net\n"
" POST_BUILD\n"
" COMMAND ar cr ${library_name} *.o\n"
" COMMAND ranlib ${library_name}\n"
" COMMAND echo \"new static library ${library_name} size:\"\n"
" COMMAND ls -lh ${library_name}\n"
" COMMAND rm -rf tmp && rm -rf *.o\n"
" COMMENT \"generate specified static library ${library_name}\"\n"
" )\n"
"endfunction(create_library)\n"
"string(CONCAT library_name \"lib\" net \".a\")\n"
"create_library()\n";
extern const char *bench_cmake_lists_txt;
extern const char *src_cmake_lists_txt;
#endif // MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_CMAKE_LISTS_CODE_H_
} // namespace mindspore::lite::micro
#endif // MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_CMAKE_LISTS_H_

@ -0,0 +1,40 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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 "coder/generator/component/const_blocks/license.h"
namespace mindspore::lite::micro {
const char *g_hwLicense = R"RAW(
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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.
*/
)RAW";
} // namespace mindspore::lite::micro

@ -19,22 +19,8 @@
namespace mindspore::lite::micro {
static const char *g_hwLicense =
"/**\n"
" * Copyright 2021 Huawei Technologies Co., Ltd\n"
" *\n"
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
" * you may not use this file except in compliance with the License.\n"
" * You may obtain a copy of the License at\n"
" *\n"
" * http://www.apache.org/licenses/LICENSE-2.0\n"
" *\n"
" * Unless required by applicable law or agreed to in writing, software\n"
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
" * See the License for the specific language governing permissions and\n"
" * limitations under the License.\n"
" */\n\n";
extern const char *g_hwLicense;
} // namespace mindspore::lite::micro
#endif // MINDSPORE_LITE_MICRO_GENERATOR_CONST_BLOCK_LICENSE_INFOS_H_

@ -0,0 +1,147 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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 "coder/generator/component/const_blocks/load_input.h"
namespace mindspore::lite::micro {
const char *load_input_h = R"RAW(
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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.
*/
#ifndef MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_
#define MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_
void *ReadInputData(const char *real_input_path, int *size);
void SaveOutputData(char *final_name, unsigned char *output_data, unsigned int out_size);
int ReadInputsFile(char *path, void **buffers, const int *inputs_size, int inputs_num);
#endif // MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_
)RAW";
const char *load_input_c = R"RAW(
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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 "load_input.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void *ReadInputData(const char *real_input_path, int *size) {
if (real_input_path == NULL) {
return NULL;
}
if (strstr(real_input_path, ".bin") || strstr(real_input_path, ".net")) {
FILE *file;
file = fopen(real_input_path, "rb+");
if (!file) {
printf("Can't find %s\n", real_input_path);
return NULL;
}
int curr_file_posi = ftell(file);
fseek(file, 0, SEEK_END);
*size = ftell(file);
unsigned char *buf = malloc((*size));
(void)memset(buf, 0, (*size));
fseek(file, curr_file_posi, SEEK_SET);
int read_size = (int)(fread(buf, 1, *size, file));
if (read_size != (*size)) {
printf("read file failed, total file size: %d, read_size: %d\n", (*size), read_size);
fclose(file);
free(buf);
return NULL;
}
fclose(file);
return (void *)buf;
} else {
printf("input data file should be .bin , .net");
return NULL;
}
}
void SaveOutputData(char *final_name, unsigned char *output_data, unsigned int out_size) {
FILE *output_file;
output_file = fopen(final_name, "w");
if (output_file == NULL) {
printf("fopen output file: %s failed\n", final_name);
return;
}
unsigned char str[out_size];
for (unsigned int i = 0; i < out_size; ++i) {
str[i] = output_data[i];
fprintf(output_file, "%d\t", str[i]);
}
fclose(output_file);
}
int ReadInputsFile(char *path, void **buffers, const int *inputs_size, int inputs_num) {
char *inputs_path[inputs_num];
char *delim = ",";
char *token;
int i = 0;
while ((token = strtok_r(path, delim, &path))) {
if (i >= inputs_num) {
printf("inputs num is error, need: %d\n", inputs_num);
return -1;
}
inputs_path[i] = token;
printf("input %d: %s\n", i, inputs_path[i]);
i++;
}
for (i = 0; i < inputs_num; ++i) {
int size = 0;
buffers[i] = ReadInputData(inputs_path[i], &size);
if (size != inputs_size[i] || buffers[i] == NULL) {
printf("size mismatch, %s, input: %d, needed: %d\n", inputs_path[i], size, inputs_size[i]);
return -1;
}
}
return 0;
}
)RAW";
} // namespace mindspore::lite::micro

@ -16,126 +16,12 @@
#ifndef MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_BENCH_LOAD_INPUT_H_
#define MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_BENCH_LOAD_INPUT_H_
const char *load_input_h =
"/**\n"
" * Copyright 2021 Huawei Technologies Co., Ltd\n"
" *\n"
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
" * you may not use this file except in compliance with the License.\n"
" * You may obtain a copy of the License at\n"
" *\n"
" * http://www.apache.org/licenses/LICENSE-2.0\n"
" *\n"
" * Unless required by applicable law or agreed to in writing, software\n"
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
" * See the License for the specific language governing permissions and\n"
" * limitations under the License.\n"
" */\n"
"\n"
"#ifndef MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_\n"
"#define MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_\n"
"void *ReadInputData(const char *real_input_path, int *size);\n"
"\n"
"void SaveOutputData(char *final_name, unsigned char *output_data, unsigned int out_size);\n"
"\n"
"int ReadInputsFile(char *path, void **buffers, const int *inputs_size, int inputs_num);\n"
"\n"
"#endif // MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_\n";
const char *load_input_c =
"/**\n"
" * Copyright 2021 Huawei Technologies Co., Ltd\n"
" *\n"
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
" * you may not use this file except in compliance with the License.\n"
" * You may obtain a copy of the License at\n"
" *\n"
" * http://www.apache.org/licenses/LICENSE-2.0\n"
" *\n"
" * Unless required by applicable law or agreed to in writing, software\n"
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
" * See the License for the specific language governing permissions and\n"
" * limitations under the License.\n"
" */\n"
"\n"
"#include \"load_input.h\"\n"
"#include <stdlib.h>\n"
"#include <stdio.h>\n"
"#include <string.h>\n"
"\n"
"void *ReadInputData(const char *real_input_path, int *size) {\n"
" if (real_input_path == NULL) {\n"
" return NULL;\n"
" }\n"
" if (strstr(real_input_path, \".bin\") || strstr(real_input_path, \".net\")) {\n"
" FILE *file;\n"
" file = fopen(real_input_path, \"rb+\");\n"
" if (!file) {\n"
" printf(\"Can't find %s\\n\", real_input_path);\n"
" return NULL;\n"
" }\n"
" int curr_file_posi = ftell(file);\n"
" fseek(file, 0, SEEK_END);\n"
" *size = ftell(file);\n"
" unsigned char *buf = malloc((*size));\n"
" (void)memset(buf, 0, (*size));\n"
" fseek(file, curr_file_posi, SEEK_SET);\n"
" int read_size = (int)(fread(buf, 1, *size, file));\n"
" if (read_size != (*size)) {\n"
" printf(\"read file failed, total file size: %d, read_size: %d\\n\", (*size), read_size);\n"
" fclose(file);\n"
" free(buf);\n"
" return NULL;\n"
" }\n"
" fclose(file);\n"
" return (void *)buf;\n"
" } else {\n"
" printf(\"input data file should be .bin , .net\");\n"
" return NULL;\n"
" }\n"
"}\n"
"\n"
"void SaveOutputData(char *final_name, unsigned char *output_data, unsigned int out_size) {\n"
" FILE *output_file;\n"
" output_file = fopen(final_name, \"w\");\n"
" if (output_file == NULL) {\n"
" printf(\"fopen output file: %s failed\\n\", final_name);\n"
" return;\n"
" }\n"
" unsigned char str[out_size];\n"
" for (unsigned int i = 0; i < out_size; ++i) {\n"
" str[i] = output_data[i];\n"
" fprintf(output_file, \"%d\\t\", str[i]);\n"
" }\n"
" fclose(output_file);\n"
"}\n"
"\n"
"int ReadInputsFile(char *path, void **buffers, const int *inputs_size, int inputs_num) {\n"
" char *inputs_path[inputs_num];\n"
" char *delim = \",\";\n"
" char *token;\n"
" int i = 0;\n"
" while ((token = strtok_r(path, delim, &path))) {\n"
" if (i >= inputs_num) {\n"
" printf(\"inputs num is error, need: %d\\n\", inputs_num);\n"
" return -1;\n"
" }\n"
" inputs_path[i] = token;\n"
" printf(\"input %d: %s\\n\", i, inputs_path[i]);\n"
" i++;\n"
" }\n"
"\n"
" for (i = 0; i < inputs_num; ++i) {\n"
" int size = 0;\n"
" buffers[i] = ReadInputData(inputs_path[i], &size);\n"
" if (size != inputs_size[i] || buffers[i] == NULL) {\n"
" printf(\"size mismatch, %s, input: %d, needed: %d\\n\", inputs_path[i], size, inputs_size[i]);\n"
" return -1;\n"
" }\n"
" }\n"
" return 0;\n"
"}\n";
namespace mindspore::lite::micro {
extern const char *load_input_h;
extern const char *load_input_c;
} // namespace mindspore::lite::micro
#endif // MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_BENCH_LOAD_INPUT_H_

@ -0,0 +1,111 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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 "coder/generator/component/const_blocks/micro_tensor.h"
namespace mindspore::lite::micro {
const char *micro_tensor_h = R"RAW(
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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.
*/
#ifndef MSMICRO_TENSOR_H
#define MSMICRO_TENSOR_H
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#define MICRO_INFO(content, args...) \
{ printf("[INFO] %s|%d: " #content "\r\n", __func__, __LINE__, ##args); }
#define MICRO_ERROR(content, args...) \
{ printf("[ERROR] %s|%d: " #content "\r\n", __func__, __LINE__, ##args); }
enum STATUS {
RET_OK = 0,
RET_ERROR = 1,
};
enum DataType {
DataType_DT_FLOAT = 0,
DataType_DT_FLOAT16 = 1,
DataType_DT_INT8 = 2,
DataType_DT_INT32 = 3,
DataType_DT_UINT8 = 4,
DataType_DT_INT16 = 5,
DataType_DT_UINT32 = 8,
DataType_DT_INT64 = 9,
DataType_DT_UINT16 = 10,
DataType_DT_UNDEFINED = 16,
DataType_MIN = DataType_DT_FLOAT,
DataType_MAX = DataType_DT_UNDEFINED
};
enum Format {
Format_NCHW = 0,
Format_NHWC = 1,
Format_HWKC = 2,
Format_HWCK = 3,
Format_KCHW = 4,
Format_CKHW = 5,
Format_KHWC = 6,
Format_CHWK = 7,
Format_NC4HW4 = 100,
Format_NUM_OF_FORMAT = 101,
Format_MIN = Format_NCHW,
Format_MAX = Format_NUM_OF_FORMAT
};
typedef struct {
enum DataType type;
enum Format format;
int ndim;
int *dim;
void *data;
} MicroTensor;
typedef struct {
int num;
MicroTensor *tensor;
} MicroTensorList;
typedef struct {
float in_scale;
float out_scale;
int in_zero_point;
int out_zero_point;
} GraphQuantArgs;
#endif // MSMICRO_TENSOR_H
)RAW";
} // namespace mindspore::lite::micro

@ -16,91 +16,10 @@
#ifndef MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_MICRO_TENSOR_H_
#define MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_MICRO_TENSOR_H_
const char *micro_tensor_h =
"/**\n"
" * Copyright 2021 Huawei Technologies Co., Ltd\n"
" *\n"
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
" * you may not use this file except in compliance with the License.\n"
" * You may obtain a copy of the License at\n"
" *\n"
" * http://www.apache.org/licenses/LICENSE-2.0\n"
" *\n"
" * Unless required by applicable law or agreed to in writing, software\n"
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
" * See the License for the specific language governing permissions and\n"
" * limitations under the License.\n"
" */\n"
"\n"
"#ifndef MSMICRO_TENSOR_H\n"
"#define MSMICRO_TENSOR_H\n"
"\n"
"#include <stdlib.h>\n"
"#include <string.h>\n"
"#include <stdio.h>\n"
"#include <stdbool.h>\n"
"#include <stdint.h>\n"
"\n"
"#define MICRO_INFO(content, args...) \\\n"
" { printf(\"[INFO] %s|%d: \" #content \"\\r\\n\", __func__, __LINE__, ##args); }\n"
"#define MICRO_ERROR(content, args...) \\\n"
" { printf(\"[ERROR] %s|%d: \" #content \"\\r\\n\", __func__, __LINE__, ##args); }\n"
"\n"
"enum STATUS {\n"
" RET_OK = 0,\n"
" RET_ERROR = 1,\n"
"};\n"
"\n"
"enum DataType {\n"
" DataType_DT_FLOAT = 0,\n"
" DataType_DT_FLOAT16 = 1,\n"
" DataType_DT_INT8 = 2,\n"
" DataType_DT_INT32 = 3,\n"
" DataType_DT_UINT8 = 4,\n"
" DataType_DT_INT16 = 5,\n"
" DataType_DT_UINT32 = 8,\n"
" DataType_DT_INT64 = 9,\n"
" DataType_DT_UINT16 = 10,\n"
" DataType_DT_UNDEFINED = 16,\n"
" DataType_MIN = DataType_DT_FLOAT,\n"
" DataType_MAX = DataType_DT_UNDEFINED\n"
"};\n"
"\n"
"enum Format {\n"
" Format_NCHW = 0,\n"
" Format_NHWC = 1,\n"
" Format_HWKC = 2,\n"
" Format_HWCK = 3,\n"
" Format_KCHW = 4,\n"
" Format_CKHW = 5,\n"
" Format_KHWC = 6,\n"
" Format_CHWK = 7,\n"
" Format_NC4HW4 = 100,\n"
" Format_NUM_OF_FORMAT = 101,\n"
" Format_MIN = Format_NCHW,\n"
" Format_MAX = Format_NUM_OF_FORMAT\n"
"};\n"
"\n"
"typedef struct {\n"
" enum DataType type;\n"
" enum Format format;\n"
" int ndim;\n"
" int *dim;\n"
" void *data;\n"
"} MicroTensor;\n"
"\n"
"typedef struct {\n"
" int num;\n"
" MicroTensor *tensor;\n"
"} MicroTensorList;\n"
"\n"
"typedef struct {\n"
" float in_scale;\n"
" float out_scale;\n"
" int in_zero_point;\n"
" int out_zero_point;\n"
"} GraphQuantArgs;\n"
"\n"
"#endif // MSMICRO_TENSOR_H\n";
namespace mindspore::lite::micro {
extern const char *micro_tensor_h;
} // namespace mindspore::lite::micro
#endif // MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_MICRO_TENSOR_H_

@ -0,0 +1,99 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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 "coder/generator/component/const_blocks/thread_pool.h"
namespace mindspore::lite::micro {
const char *thread_pool_h = R"RAW(
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* 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
*
* http://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.
*/
#ifndef MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_
#define MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_
#include <stdbool.h>
#define MAX_TASK_NUM (2)
// brief BindMode defined for holding bind cpu strategy argument.
typedef enum {
NO_BIND_MODE = 0, /**< no bind */
HIGHER_MODE = 1, /**< bind higher cpu first */
MID_MODE = 2 /**< bind middle cpu first */
} BindMode;
struct ThreadPool;
struct ThreadPool *CreateThreadPool(int thread_num, int mode);
/**
*
* @param session_index, support multi session
* @param job
* @param content
* @param task_num
*/
int ParallelLaunch(struct ThreadPool *thread_pool, int (*job)(void *, int), void *content, int task_num);
/**
* bind each thread to specified cpu core
* @param is_bind
* @param mode
*/
int BindThreads(struct ThreadPool *thread_pool, bool is_bind, int mode);
/**
* activate the thread pool
* @param thread_pool_id
*/
void ActivateThreadPool(struct ThreadPool *thread_pool);
/**
* deactivate the thread pool
* @param thread_pool_id
*/
void DeactivateThreadPool(struct ThreadPool *thread_pool);
/**
*
* @return current thread num
*/
int GetCurrentThreadNum(struct ThreadPool *thread_pool);
/**
* destroy thread pool, and release resource
*/
void DestroyThreadPool(struct ThreadPool *thread_pool);
#endif // MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_
)RAW";
} // namespace mindspore::lite::micro

@ -19,81 +19,8 @@
namespace mindspore::lite::micro {
const char *thread_pool_h =
"/**\n"
" * Copyright 2021 Huawei Technologies Co., Ltd\n"
" *\n"
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
" * you may not use this file except in compliance with the License.\n"
" * You may obtain a copy of the License at\n"
" *\n"
" * http://www.apache.org/licenses/LICENSE-2.0\n"
" *\n"
" * Unless required by applicable law or agreed to in writing, software\n"
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
" * See the License for the specific language governing permissions and\n"
" * limitations under the License.\n"
" */\n"
"\n"
"#ifndef MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_\n"
"#define MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_\n"
"\n"
"#include <stdbool.h>\n"
"\n"
"#define MAX_TASK_NUM (2)\n"
"\n"
"/// \\brief BindMode defined for holding bind cpu strategy argument.\n"
"typedef enum {\n"
" NO_BIND_MODE = 0, /**< no bind */\n"
" HIGHER_MODE = 1, /**< bind higher cpu first */\n"
" MID_MODE = 2 /**< bind middle cpu first */\n"
"} BindMode;\n"
"\n"
"struct ThreadPool;\n"
"\n"
"struct ThreadPool *CreateThreadPool(int thread_num, int mode);\n"
"\n"
"/**\n"
" *\n"
" * @param session_index, support multi session\n"
" * @param job\n"
" * @param content\n"
" * @param task_num\n"
" */\n"
"int ParallelLaunch(struct ThreadPool *thread_pool, int (*job)(void *, int), void *content, int task_num);\n"
"\n"
"/**\n"
" * bind each thread to specified cpu core\n"
" * @param is_bind\n"
" * @param mode\n"
" */\n"
"int BindThreads(struct ThreadPool *thread_pool, bool is_bind, int mode);\n"
"\n"
"/**\n"
" * activate the thread pool\n"
" * @param thread_pool_id\n"
" */\n"
"void ActivateThreadPool(struct ThreadPool *thread_pool);\n"
"\n"
"/**\n"
" * deactivate the thread pool\n"
" * @param thread_pool_id\n"
" */\n"
"void DeactivateThreadPool(struct ThreadPool *thread_pool);\n"
"\n"
"/**\n"
" *\n"
" * @return current thread num\n"
" */\n"
"int GetCurrentThreadNum(struct ThreadPool *thread_pool);\n"
"\n"
"/**\n"
" * destroy thread pool, and release resource\n"
" */\n"
"void DestroyThreadPool(struct ThreadPool *thread_pool);\n"
"\n"
"#endif // MINDSPORE_LITE_SRC_RUNTIME_THREAD_POOL_H_\n";
extern const char *thread_pool_h;
} // namespace mindspore::lite::micro
#endif // MINDSPORE_LITE_MICRO_CODER_GENERATOR_CONST_BLOCKS_THREAD_POOL_H_

@ -26,16 +26,18 @@ set(HEADER_PATH "${OPERATOR_LIBRARY_PATH}/include")
message("===========>start to pack operators' head file")
file(REMOVE_RECURSE ${OPERATOR_LIBRARY_PATH})
file(MAKE_DIRECTORY ${OPERATOR_LIBRARY_PATH})
file(INSTALL ${LITE_DIR}/nnacl DESTINATION ${HEADER_PATH} FILES_MATCHING PATTERN "*.h")
file(INSTALL ${MICRO_DIR}/coder/operator_library/wrapper DESTINATION ${HEADER_PATH} FILES_MATCHING PATTERN "*.h")
file(INSTALL ${CMAKE_BINARY_DIR}/cmsis/CMSIS/Core/Include DESTINATION ${HEADER_PATH}/CMSIS/Core)
file(INSTALL ${CMAKE_BINARY_DIR}/cmsis/CMSIS/DSP/Include DESTINATION ${HEADER_PATH}/CMSIS/DSP)
file(INSTALL ${CMAKE_BINARY_DIR}/cmsis/CMSIS/NN/Include DESTINATION ${HEADER_PATH}/CMSIS/NN)
file(REMOVE_RECURSE ${HEADER_PATH}/nnacl/assembly)
file(REMOVE_RECURSE ${HEADER_PATH}/nnacl/fp16)
file(REMOVE_RECURSE ${HEADER_PATH}/nnacl/fp16_grad)
file(REMOVE_RECURSE ${HEADER_PATH}/nnacl/fp32_grad)
file(REMOVE_RECURSE ${HEADER_PATH}/nnacl/optimize)
file(GLOB NNACL_FILES GLOB ${LITE_DIR}/nnacl/*.h)
file(COPY ${NNACL_FILES} DESTINATION ${HEADER_PATH}/nnacl/)
file(COPY ${LITE_DIR}/nnacl/base
${LITE_DIR}/nnacl/int8
${LITE_DIR}/nnacl/fp32
${LITE_DIR}/nnacl/intrinsics
DESTINATION ${HEADER_PATH}/nnacl FILES_MATCHING PATTERN "*.h")
file(COPY ${MICRO_DIR}/coder/operator_library/wrapper DESTINATION ${HEADER_PATH} FILES_MATCHING PATTERN "*.h")
file(COPY ${CMAKE_BINARY_DIR}/cmsis/CMSIS/Core/Include
${CMAKE_BINARY_DIR}/cmsis/CMSIS/DSP/Include
${CMAKE_BINARY_DIR}/cmsis/CMSIS/NN/Include
DESTINATION ${HEADER_PATH}/CMSIS/Core)
if(PLATFORM_ARM64)
set(MICRO_BUILD_ARM64 ON)

Loading…
Cancel
Save