diff --git a/mindspore/lite/micro/coder/generator/component/const_blocks/benchmark.cc b/mindspore/lite/micro/coder/generator/component/const_blocks/benchmark.cc index 764a411599..929ab82403 100644 --- a/mindspore/lite/micro/coder/generator/component/const_blocks/benchmark.cc +++ b/mindspore/lite/micro/coder/generator/component/const_blocks/benchmark.cc @@ -118,7 +118,7 @@ int main(int argc, const char **argv) { const char *model_buffer = nullptr; int model_size = 0; - // read .net file by ReadBinaryFile; + // read .bin file by ReadBinaryFile; if (argc >= 3) { model_buffer = static_cast(ReadInputData(argv[2], &model_size)); } diff --git a/mindspore/lite/micro/coder/generator/component/const_blocks/cmake_lists.cc b/mindspore/lite/micro/coder/generator/component/const_blocks/cmake_lists.cc index a8b89f8775..b306c153cb 100644 --- a/mindspore/lite/micro/coder/generator/component/const_blocks/cmake_lists.cc +++ b/mindspore/lite/micro/coder/generator/component/const_blocks/cmake_lists.cc @@ -19,32 +19,17 @@ namespace mindspore::lite::micro { const char *bench_cmake_lists_txt = R"RAW( + cmake_minimum_required(VERSION 3.14) project(benchmark) -if(NOT DEFINED MODEL_LIB) - message(FATAL_ERROR "MODEL_LIB not set") -endif() - -if(NOT DEFINED HEADER_PATH) - message(FATAL_ERROR "HEADER_PATH not set") +if(NOT DEFINED PKG_PATH) + message(FATAL_ERROR "PKG_PATH not set") endif() -get_filename_component(MODEL_LIB ${MODEL_LIB} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -get_filename_component(HEADER_PATH ${HEADER_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) - -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) +get_filename_component(PKG_PATH ${PKG_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -parse_lib_info(${MODEL_LIB} MODEL_LIB_NAME MODEL_LIB_PATH) - -message("project name: ${MODEL_LIB_NAME}") +set(HEADER_PATH ${PKG_PATH}/inference) option(MICRO_BUILD_ARM64 "build android arm64" OFF) option(MICRO_BUILD_ARM32A "build android arm32" OFF) @@ -73,37 +58,39 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default") else() - set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O3 -Wall -Werror -fstack-protector-strong -Wno-attributes \ + set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ -Wno-deprecated-declarations -Wno-missing-braces ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O3 -Wall -Werror -fstack-protector-strong -Wno-attributes \ + set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ -Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") endif() -link_directories(${MODEL_LIB_PATH}) -include(benchmark.cmake) + +add_subdirectory(src) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/) +include_directories(${HEADER_PATH}) +set(SRC_FILES + benchmark/benchmark.cc + benchmark/load_input.c +) add_executable(benchmark ${SRC_FILES}) -target_link_libraries(benchmark ${MODEL_LIB_NAME} -lm -pthread) +target_link_libraries(benchmark net -lm -pthread) )RAW"; const char *src_cmake_lists_txt = R"RAW( + cmake_minimum_required(VERSION 3.14) project(net) -if(NOT DEFINED OP_LIB) - message(FATAL_ERROR "OP_LIB not set") +if(NOT DEFINED PKG_PATH) + message(FATAL_ERROR "PKG_PATH not set") endif() -if(NOT DEFINED OP_HEADER_PATH) - message(FATAL_ERROR "OP_HEADER_PATH not set") -endif() - -if(NOT DEFINED HEADER_PATH) - message(FATAL_ERROR "HEADER_PATH not set") -endif() +get_filename_component(PKG_PATH ${PKG_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -get_filename_component(OP_LIB ${OP_LIB} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -get_filename_component(OP_HEADER_PATH ${OP_HEADER_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -get_filename_component(HEADER_PATH ${HEADER_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(OP_LIB ${PKG_PATH}/tools/codegen/operator_library/lib/libops.a) +set(OP_HEADER_PATH ${PKG_PATH}/tools/codegen/operator_library/include) +set(HEADER_PATH ${PKG_PATH}/inference) message("operator lib path: ${OP_LIB}") message("operator header path: ${OP_HEADER_PATH}") diff --git a/mindspore/lite/micro/coder/generator/generator.cc b/mindspore/lite/micro/coder/generator/generator.cc index e990a59b1a..6fc56205c1 100644 --- a/mindspore/lite/micro/coder/generator/generator.cc +++ b/mindspore/lite/micro/coder/generator/generator.cc @@ -71,23 +71,6 @@ void Generator::CodeNetRunFunc(std::ofstream &ofs) { ofs << "}\n"; } -int Generator::CodeBenchmarkCMakeFile() { - std::string net_main_cmake_file_path = net_main_file_path_; - std::string test_cmake_file = net_main_cmake_file_path + "benchmark.cmake"; - std::ofstream ofs(test_cmake_file); - MS_CHECK_TRUE(!ofs.bad(), "filed to open file"); - MS_LOG(INFO) << "write " << test_cmake_file; - ofs << "include_directories(${CMAKE_CURRENT_SOURCE_DIR})\n"; - ofs << "include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/)\n"; - ofs << "include_directories(${HEADER_PATH})\n"; - ofs << "set(SRC_FILES\n"; - ofs << "\t\t" << kBenchmarkFile << "\n"; - ofs << "\t\tload_input.c\n"; - ofs << ")\n"; - ofs.close(); - return RET_OK; -} - int Generator::CodeSourceCMakeFile() { std::string src_cmake_file = net_src_file_path_ + cmake_file_name_; std::ofstream ofs(src_cmake_file); @@ -102,7 +85,7 @@ int Generator::CodeStaticContent() { std::vector> const_blocks = { {net_main_file_path_ + "load_input.h", load_input_h}, {net_main_file_path_ + "load_input.c", load_input_c}, - {net_main_file_path_ + "CMakeLists.txt", bench_cmake_lists_txt}, + {config_->code_path() + "/" + "CMakeLists.txt", bench_cmake_lists_txt}, {net_main_file_path_ + "benchmark.cc", benchmark_source}, {net_src_file_path_ + "CMakeLists.txt", src_cmake_lists_txt}, {net_src_file_path_ + "session.h", session_header}, @@ -169,7 +152,6 @@ int Generator::GenerateCode() { MS_CHECK_RET_CODE(CodeNetCFile(), "code net c file failed."); MS_CHECK_RET_CODE(CodeWeightFile(), "code weight file failed."); MS_CHECK_RET_CODE(CodeSourceCMakeFile(), "code net cmake file failed."); - MS_CHECK_RET_CODE(CodeBenchmarkCMakeFile(), "code benchmark cmake file failed."); MS_CHECK_RET_CODE(CodeStaticContent(), "code static content failed."); MS_CHECK_RET_CODE(CodeSessionImplement(), "code session file failed."); return RET_OK; diff --git a/mindspore/lite/micro/coder/generator/generator.h b/mindspore/lite/micro/coder/generator/generator.h index 2588ea521f..2e04140fa8 100644 --- a/mindspore/lite/micro/coder/generator/generator.h +++ b/mindspore/lite/micro/coder/generator/generator.h @@ -61,7 +61,6 @@ class Generator { std::string net_main_file_path_; private: - int CodeBenchmarkCMakeFile(); int CodeSourceCMakeFile(); int CodeStaticContent(); int CodeSessionImplement(); diff --git a/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.cc b/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.cc index 9d6a27c2aa..524e35c30b 100644 --- a/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.cc +++ b/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.cc @@ -102,7 +102,7 @@ int Conv2D3x3Int8Coder::InitTmpBuffer(CoderContext *const context) { /*=============================tmp_out_============================*/ tmp_out_size_ = oc4 * C4NUM * output_batch * output_w * output_h * sizeof(uint8_t); - tmp_out_ = static_cast(allocator_->Malloc(kNumberTypeUInt8, tmp_out_size_, kWorkspace)); + tmp_out_ = static_cast(allocator_->Malloc(kNumberTypeInt8, tmp_out_size_, kWorkspace)); /*=============================input_data_============================*/ c8_input_size_ = in_batch * input_h * input_w * ic8 * C8NUM * sizeof(int16_t); diff --git a/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.h b/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.h index 27641d7f94..7bcea0b5f3 100644 --- a/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.h +++ b/mindspore/lite/micro/coder/opcoders/nnacl/int8/conv2d_3x3_int8_coder.h @@ -51,7 +51,7 @@ class Conv2D3x3Int8Coder final : public Conv2DBaseCoder { int16_t *block_unit_buffer_{nullptr}; int16_t *tile_buffer_{nullptr}; int32_t *tmp_dst_buffer_{nullptr}; - uint8_t *tmp_out_{nullptr}; + int8_t *tmp_out_{nullptr}; int16_t *c8_input_{nullptr}; size_t tile_buffer_size_{0}; diff --git a/mindspore/lite/micro/coder/opcoders/nnacl/int8/matmul_base_int8_coder.cc b/mindspore/lite/micro/coder/opcoders/nnacl/int8/matmul_base_int8_coder.cc index 27c04a6634..ac0e6525a9 100644 --- a/mindspore/lite/micro/coder/opcoders/nnacl/int8/matmul_base_int8_coder.cc +++ b/mindspore/lite/micro/coder/opcoders/nnacl/int8/matmul_base_int8_coder.cc @@ -184,7 +184,7 @@ int MatMulBaseInt8Coder::DoCode(CoderContext *const context) { init_code.CodeFunction("memset", weight_bias_sums_, 0, weight_bias_sums_size_); init_code.CodeMallocExpression(pack_b_ptr_, b_pack_ptr_size_); init_code.CodeFunction("memset", pack_b_ptr_, 0, b_pack_ptr_size_); - init_code.CodeArray("init_filter_zp", quant_.filter_zp_, weight_quant_num_); + init_code.CodeArray("init_filter_zp", quant_.filter_zp_, weight_quant_num_, false); init_code.CodeFunction("InitInt8MatrixB", filter_tensor_, weight_bias_sums_, pack_b_ptr_, param_->batch, param_->deep_, param_->col_, param_->col_align_, param_->deep_16_, quant_.input_.zp_, "init_filter_zp", bias_ptr_, param_->b_transpose_, filter_per_channel_); diff --git a/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_int8_serializer.cc b/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_int8_serializer.cc index 90e2c49b4a..1bcf7b8300 100644 --- a/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_int8_serializer.cc +++ b/mindspore/lite/micro/coder/opcoders/serializers/nnacl_serializer/nnacl_int8_serializer.cc @@ -45,20 +45,20 @@ void NNaclInt8Serializer::CodeStruct(const std::string &name, const ConvParamete std::string conv_quant_arg = name + "_conv_quant_arg"; - CodeBaseStruct("ConvQuantArg", conv_quant_arg, quant_arg.round_mode_, quant_arg.quant_multiplier_mode_, quant_arg_in, - quant_arg_w, quant_arg_out, real_multiplier, left_shift, right_shift, quant_multiplier, out_act_min, - out_act_max, quant_arg.input_arg_num_, quant_arg.filter_arg_num_, quant_arg.output_arg_num_, - quant_arg.per_channel_); + CodeBaseStruct("ConvQuantArg", conv_quant_arg, quant_arg.round_mode_, quant_arg.quant_multiplier_mode_, + quant_arg_in, quant_arg_w, quant_arg_out, real_multiplier, left_shift, right_shift, + quant_multiplier, out_act_min, out_act_max, quant_arg.input_arg_num_, quant_arg.filter_arg_num_, + quant_arg.output_arg_num_, quant_arg.per_channel_); code << "int thread_num = MSMIN(" << gThreadNum << ", " << conv_parameter.output_h_ << ");\n"; - CodeBaseStruct("ConvParameter", name, conv_parameter.op_parameter_, conv_quant_arg, conv_parameter.kernel_h_, - conv_parameter.kernel_w_, conv_parameter.stride_h_, conv_parameter.stride_w_, - conv_parameter.dilation_h_, conv_parameter.dilation_w_, conv_parameter.pad_u_, conv_parameter.pad_d_, - conv_parameter.pad_l_, conv_parameter.pad_r_, conv_parameter.group_, conv_parameter.tile_num_, - conv_parameter.input_batch_, conv_parameter.input_h_, conv_parameter.input_w_, - conv_parameter.input_channel_, conv_parameter.output_batch_, conv_parameter.output_h_, - conv_parameter.output_w_, conv_parameter.output_channel_, "thread_num", conv_parameter.input_unit_, - conv_parameter.output_unit_, conv_parameter.pad_mode_, conv_parameter.act_type_, - conv_parameter.channel_multiplie_, conv_parameter.output_padding_w_, conv_parameter.output_padding_h_); + CodeBaseStruct( + "ConvParameter", name, conv_parameter.op_parameter_, conv_quant_arg, conv_parameter.kernel_h_, + conv_parameter.kernel_w_, conv_parameter.stride_h_, conv_parameter.stride_w_, conv_parameter.dilation_h_, + conv_parameter.dilation_w_, conv_parameter.pad_u_, conv_parameter.pad_d_, conv_parameter.pad_l_, + conv_parameter.pad_r_, conv_parameter.group_, conv_parameter.tile_num_, conv_parameter.input_batch_, + conv_parameter.input_h_, conv_parameter.input_w_, conv_parameter.input_channel_, conv_parameter.output_batch_, + conv_parameter.output_h_, conv_parameter.output_w_, conv_parameter.output_channel_, "thread_num", + conv_parameter.input_unit_, conv_parameter.output_unit_, conv_parameter.pad_mode_, conv_parameter.act_type_, + conv_parameter.channel_multiplie_, conv_parameter.output_padding_w_, conv_parameter.output_padding_h_); } void NNaclInt8Serializer::CodeStruct(const std::string &name, const MatMulParameter &matmul_parameter) { @@ -201,11 +201,11 @@ void NNaclInt8Serializer::CodeStruct(const std::string &name, const ReshapeQuant void NNaclInt8Serializer::CodeStruct(const std::string &name, const MatmulQuantParameter &matmul_quant_arg, int weight_quant_num) { - CodeArray("filter_scale", matmul_quant_arg.filter_scale_, weight_quant_num); - CodeArray("filter_zp", matmul_quant_arg.filter_zp_, weight_quant_num); - CodeArray("left_shift", matmul_quant_arg.left_shift_, weight_quant_num); - CodeArray("right_shift", matmul_quant_arg.right_shift_, weight_quant_num); - CodeArray("multiplier", matmul_quant_arg.quant_multiplier_, weight_quant_num); + CodeArray("filter_scale", matmul_quant_arg.filter_scale_, weight_quant_num, false); + CodeArray("filter_zp", matmul_quant_arg.filter_zp_, weight_quant_num, false); + CodeArray("left_shift", matmul_quant_arg.left_shift_, weight_quant_num, false); + CodeArray("right_shift", matmul_quant_arg.right_shift_, weight_quant_num, false); + CodeArray("multiplier", matmul_quant_arg.quant_multiplier_, weight_quant_num, false); CodeBaseStruct("MatmulQuantParameter", name, matmul_quant_arg.input_, matmul_quant_arg.weight_, matmul_quant_arg.output_, matmul_quant_arg.out_act_min_, matmul_quant_arg.out_act_max_, "filter_scale", "filter_zp", "left_shift", "right_shift", "multiplier"); diff --git a/mindspore/lite/micro/example/mnist/benchmark/CMakeLists.txt b/mindspore/lite/micro/example/mnist/CMakeLists.txt similarity index 66% rename from mindspore/lite/micro/example/mnist/benchmark/CMakeLists.txt rename to mindspore/lite/micro/example/mnist/CMakeLists.txt index 4fb563683a..f6356a13db 100644 --- a/mindspore/lite/micro/example/mnist/benchmark/CMakeLists.txt +++ b/mindspore/lite/micro/example/mnist/CMakeLists.txt @@ -1,25 +1,15 @@ + cmake_minimum_required(VERSION 3.14) project(benchmark) -if(NOT DEFINED MODEL_LIB) - message(FATAL_ERROR "MODEL_LIB not set") +if(NOT DEFINED PKG_PATH) + message(FATAL_ERROR "PKG_PATH not set") endif() -get_filename_component(MODEL_LIB ${MODEL_LIB} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) - -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) +get_filename_component(PKG_PATH ${PKG_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -parse_lib_info(${MODEL_LIB} MODEL_LIB_NAME MODEL_LIB_PATH) - -message("project name: ${MODEL_LIB_NAME}") +set(HEADER_PATH ${PKG_PATH}/inference) option(MICRO_BUILD_ARM64 "build android arm64" OFF) option(MICRO_BUILD_ARM32A "build android arm32" OFF) @@ -53,8 +43,15 @@ else() set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ -Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") endif() -link_directories(${MODEL_LIB_PATH}) -include(benchmark.cmake) + +add_subdirectory(src) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/) +include_directories(${HEADER_PATH}) +set(SRC_FILES + benchmark/benchmark.cc + benchmark/load_input.c +) add_executable(benchmark ${SRC_FILES}) -target_link_libraries(benchmark ${MODEL_LIB_NAME} -lm -pthread) +target_link_libraries(benchmark net -lm -pthread) diff --git a/mindspore/lite/micro/example/mnist/benchmark/benchmark.cc b/mindspore/lite/micro/example/mnist/benchmark/benchmark.cc index 5c8472adaf..6abbcd8313 100644 --- a/mindspore/lite/micro/example/mnist/benchmark/benchmark.cc +++ b/mindspore/lite/micro/example/mnist/benchmark/benchmark.cc @@ -1,4 +1,5 @@ + /** * Copyright 2021 Huawei Technologies Co., Ltd * @@ -38,6 +39,55 @@ void usage() { "args[5]: runtime thread bind mode\n\n"); } +template +void PrintData(void *data, size_t data_number) { + if (data == nullptr) { + return; + } + auto casted_data = static_cast(data); + for (size_t i = 0; i < 10 && i < data_number; i++) { + std::cout << std::to_string(casted_data[i]) << ", "; + } + std::cout << std::endl; +} + +void TensorToString(tensor::MSTensor *tensor) { + uint8_t i = 0; + std::cout << "uint8: " << i << std::endl; + + std::cout << "Name: " << tensor->tensor_name(); + std::cout << ", DataType: " << tensor->data_type(); + std::cout << ", Size: " << tensor->Size(); + std::cout << ", Shape:"; + for (auto &dim : tensor->shape()) { + std::cout << " " << dim; + } + std::cout << ", Data:" << std::endl; + switch (tensor->data_type()) { + case kNumberTypeFloat32: { + PrintData(tensor->MutableData(), tensor->ElementsNum()); + } break; + case kNumberTypeFloat16: { + PrintData(tensor->MutableData(), tensor->ElementsNum()); + } break; + case kNumberTypeInt32: { + PrintData(tensor->MutableData(), tensor->ElementsNum()); + } break; + case kNumberTypeInt16: { + PrintData(tensor->MutableData(), tensor->ElementsNum()); + } break; + case kNumberTypeInt8: { + PrintData(tensor->MutableData(), tensor->ElementsNum()); + } break; + case kNumberTypeUInt8: { + PrintData(tensor->MutableData(), tensor->ElementsNum()); + } break; + default: + std::cout << "Unsupported data type to print" << std::endl; + break; + } +} + int main(int argc, const char **argv) { if (argc < 2) { std::cout << "input command is invalid\n" << std::endl; @@ -84,7 +134,7 @@ int main(int argc, const char **argv) { std::cout << "output size: " << outputs.size() << std::endl; for (const auto &item : outputs) { auto output = item.second; - std::cout << "name: " << output->tensor_name() << ", size: " << output->Size() << std::endl; + TensorToString(output); } std::cout << "run benchmark success" << std::endl; diff --git a/mindspore/lite/micro/example/mnist/benchmark/benchmark.cmake b/mindspore/lite/micro/example/mnist/benchmark/benchmark.cmake deleted file mode 100644 index 63ea2d62f9..0000000000 --- a/mindspore/lite/micro/example/mnist/benchmark/benchmark.cmake +++ /dev/null @@ -1,8 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/) -include_directories(${HEADER_PATH}) -set(SRC_FILES - benchmark.cc - load_input.c - debug_utils.c -) diff --git a/mindspore/lite/micro/example/mnist/benchmark/debug_utils.c b/mindspore/lite/micro/example/mnist/benchmark/debug_utils.c deleted file mode 100644 index 289472a9ea..0000000000 --- a/mindspore/lite/micro/example/mnist/benchmark/debug_utils.c +++ /dev/null @@ -1,216 +0,0 @@ - -/** - * 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 -#include "debug_utils.h" - -#define UP_DIV(x, y) (((x) + (y) - (1)) / (y)) - -static const unsigned int kPrintNums = 20; -static const unsigned int kLineSplitNum = 44; -static const unsigned int kLineNum = 45; -unsigned int GetTensorElementSize(const MicroTensor *tensor) { - unsigned int ans = 1; - if (tensor->format == Format_NC4HW4) { - for (unsigned int i = 0; i < tensor->ndim; ++i) { - unsigned int dim = tensor->dim[i]; - if (i == 1) { - dim = UP_DIV(dim, 4) * 4; - } - ans *= dim; - } - } else { - for (unsigned int i = 0; i < tensor->ndim; ++i) { - ans *= tensor->dim[i]; - } - } - return ans; -} - -static const char *const TypeNames[] = {"DT_FLOAT", "DT_FLOAT16", "DT_INT8", "DT_INT32", "DT_UINT8", "DT_INT16", - "", "", "DT_UINT32", "DT_INT64", "DT_UINT16", "", - "", "", "", "", "DT_UNDEFINED", ""}; - -const char *EnumNameFormat(enum Format e) { - switch (e) { - case Format_NCHW: - return "NCHW"; - case Format_NHWC: - return "NHWC"; - case Format_HWKC: - return "HWKC"; - case Format_HWCK: - return "HWCK"; - case Format_KCHW: - return "KCHW"; - case Format_CKHW: - return "CKHW"; - case Format_KHWC: - return "KHWC"; - case Format_CHWK: - return "CHWK"; - case Format_NC4HW4: - return "NC4HW4"; - case Format_NUM_OF_FORMAT: - return "NUM_OF_FORMAT"; - default: - return ""; - } -} - -void PrintTensorData(MicroTensor *tensor) { - void *data = tensor->data; - unsigned int elenums = GetTensorElementSize(tensor); - if (data == NULL || elenums == 0) { - MICRO_ERROR("print tensor data failed"); - return; - } - switch (tensor->type) { - case DataType_DT_FLOAT: { - float *addr = (float *)(data); - for (int i = 0; i < elenums && i < kPrintNums; ++i) { - printf("%f, ", addr[i]); - } - break; - } - case DataType_DT_INT32: { - int32_t *addr = (int32_t *)(data); - for (int i = 0; i < elenums && i < kPrintNums; ++i) { - printf("%d, ", addr[i]); - } - break; - } - case DataType_DT_INT8: { - int8_t *addr = (int8_t *)(data); - for (int i = 0; i < elenums && i < kPrintNums; ++i) { - printf("%d, ", addr[i]); - } - break; - } - case DataType_DT_UINT32: { - uint32_t *addr = (uint32_t *)(data); - for (int i = 0; i < elenums && i < kPrintNums; ++i) { - printf("%u, ", addr[i]); - } - break; - } - case DataType_DT_UINT8: { - uint8_t *addr = (uint8_t *)(data); - for (int i = 0; i < elenums && i < kPrintNums; ++i) { - printf("%u, ", addr[i]); - } - break; - } - default: - MICRO_ERROR("unsupported data type %d", tensor->type); - } - printf("\n"); -} - -void PrintDataToFile(const void *data, const size_t elenums, const enum DataType type, FILE *file) { - if (data == NULL || elenums == 0) { - MICRO_ERROR("print tensor data to file failed"); - return; - } - switch (type) { - case DataType_DT_FLOAT: { - float *addr = (float *)(data); - for (int i = 0; i < elenums; ++i) { - fprintf(file, "%0.15f, ", addr[i]); - if (i % kLineNum == kLineSplitNum) { - fprintf(file, "\n"); - } - } - break; - } - case DataType_DT_INT32: { - int32_t *addr = (int32_t *)(data); - for (int i = 0; i < elenums; ++i) { - fprintf(file, "%d, ", addr[i]); - if (i % kLineNum == kLineSplitNum) { - fprintf(file, "\n"); - } - } - break; - } - case DataType_DT_INT8: { - int8_t *addr = (int8_t *)(data); - for (int i = 0; i < elenums; ++i) { - fprintf(file, "%d, ", addr[i]); - if (i % kLineNum == kLineSplitNum) { - fprintf(file, "\n"); - } - } - break; - } - case DataType_DT_UINT32: { - uint32_t *addr = (uint32_t *)(data); - for (int i = 0; i < elenums; ++i) { - fprintf(file, "%u, ", addr[i]); - if (i % kLineNum == kLineSplitNum) { - fprintf(file, "\n"); - } - } - break; - } - case DataType_DT_UINT8: { - uint8_t *addr = (uint8_t *)(data); - for (int i = 0; i < elenums; ++i) { - fprintf(file, "%u, ", addr[i]); - if (i % kLineNum == kLineSplitNum) { - fprintf(file, "\n"); - } - } - break; - } - default: - MICRO_ERROR("unsupported data type %d", type); - } - fprintf(file, "\n"); -} - -void PrintTensor(MicroTensor *tensor, FILE *output_file, const char *is_input) { - if (output_file == NULL) { - MICRO_ERROR("output file is NULL"); - return; - } - fprintf(output_file, "%s ", is_input); - for (int i = 0; i < tensor->ndim; ++i) { - fprintf(output_file, "%u, ", tensor->dim[i]); - } - fprintf(output_file, "\n"); - - const char *type = TypeNames[tensor->type]; - const char *format = EnumNameFormat(tensor->format); - unsigned int tensorSize = GetTensorElementSize(tensor); - fprintf(output_file, "%s type:%s, format:%s, elementSize: %u\n", is_input, type, format, tensorSize); - fprintf(output_file, "%s Data:\n", is_input); - PrintDataToFile(tensor->data, tensorSize, tensor->type, output_file); - (void)fflush(output_file); -} - -uint64_t GetTimeUs() { - const int USEC = 1000000; - const int MSEC = 1000; - struct timespec ts = {0, 0}; - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { - return 0; - } - uint64_t retval = (uint64_t)((ts.tv_sec * USEC) + (ts.tv_nsec / MSEC)); - return retval; -} - diff --git a/mindspore/lite/micro/example/mnist/benchmark/debug_utils.h b/mindspore/lite/micro/example/mnist/benchmark/debug_utils.h deleted file mode 100644 index b86810388d..0000000000 --- a/mindspore/lite/micro/example/mnist/benchmark/debug_utils.h +++ /dev/null @@ -1,34 +0,0 @@ - -/** - * 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_MICRO_MICRODEBUGUTIL_H_ -#define MINDSPORE_LITE_MICRO_MICRODEBUGUTIL_H_ - -#include -#include -#include -#include -#include "microtensor.h" - -void PrintTensor(MicroTensor *tensor, FILE *output_file, const char *is_input); - -void PrintTensorData(MicroTensor *tensor); - -uint64_t GetTimeUs(); - -#endif // MINDSPORE_LITE_MICRO_MICRODEBUGUTIL_H_ - diff --git a/mindspore/lite/micro/example/mnist/mnist.sh b/mindspore/lite/micro/example/mnist/mnist.sh index 4c3dfaa128..0646e060bd 100644 --- a/mindspore/lite/micro/example/mnist/mnist.sh +++ b/mindspore/lite/micro/example/mnist/mnist.sh @@ -42,31 +42,12 @@ fi tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ || exit 1 rm ${BASEPATH}/build/${MINDSPORE_FILE} || exit 1 -CODEGEN_PATH=${BASEPATH}/build/${MINDSPORE_FILE_NAME}/tools/codegen -HEADER_PATH=${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference -# 1. build static lib.a -echo -e "building static library" -mkdir -p ${BASEPATH}/build/src && cd ${BASEPATH}/build/src || exit 1 -OP_HEADER_PATH=${CODEGEN_PATH}/operator_library/include -OP_LIB=${CODEGEN_PATH}/operator_library/lib/libops.a -echo "Head Path: ${OP_HEADER_PATH}" -echo "Lib Path: ${OP_LIB}" -echo "Header Path: ${HEADER_PATH}" - -cmake -DCMAKE_BUILD_TYPE=Debug \ - -DOP_LIB=${OP_LIB} \ - -DOP_HEADER_PATH=${OP_HEADER_PATH} \ - -DHEADER_PATH=${HEADER_PATH} \ - ${BASEPATH}/src -make - -# 2. build benchmark +PKG_PATH=${BASEPATH}/build/${MINDSPORE_FILE_NAME} +# build benchmark mkdir -p ${BASEPATH}/build/benchmark && cd ${BASEPATH}/build/benchmark || exit 1 -cmake -DMODEL_LIB="${BASEPATH}/build/src/libnet.a" \ - -DHEADER_PATH=${HEADER_PATH} \ - ${BASEPATH}/benchmark +cmake -DPKG_PATH=${PKG_PATH} ${BASEPATH} make -echo "net file: ${BASEPATH}/src/mnist.net" +echo "net file: ${BASEPATH}/src/mnist.bin" # 3. run benchmark -./benchmark ${INPUT_BIN} ${BASEPATH}/src/net.net +./benchmark ${INPUT_BIN} ${BASEPATH}/src/net.bin diff --git a/mindspore/lite/micro/example/mnist/src/CMakeLists.txt b/mindspore/lite/micro/example/mnist/src/CMakeLists.txt index ec9239d65f..30cab63b3f 100644 --- a/mindspore/lite/micro/example/mnist/src/CMakeLists.txt +++ b/mindspore/lite/micro/example/mnist/src/CMakeLists.txt @@ -1,17 +1,17 @@ + cmake_minimum_required(VERSION 3.14) project(net) -if(NOT DEFINED OP_LIB) - message(FATAL_ERROR "OP_LIB not set") +if(NOT DEFINED PKG_PATH) + message(FATAL_ERROR "PKG_PATH not set") endif() -if(NOT DEFINED OP_HEADER_PATH) - message(FATAL_ERROR "OP_HEADER_PATH not set") -endif() +get_filename_component(PKG_PATH ${PKG_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -get_filename_component(OP_LIB ${OP_LIB} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) -get_filename_component(OP_HEADER_PATH ${OP_HEADER_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set(OP_LIB ${PKG_PATH}/tools/codegen/operator_library/lib/libops.a) +set(OP_HEADER_PATH ${PKG_PATH}/tools/codegen/operator_library/include) +set(HEADER_PATH ${PKG_PATH}/inference) message("operator lib path: ${OP_LIB}") message("operator header path: ${OP_HEADER_PATH}") @@ -48,9 +48,9 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default") else() - set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ + set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O3 -Wall -Werror -fstack-protector-strong -Wno-attributes \ -Wno-deprecated-declarations -Wno-missing-braces ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ + set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O3 -Wall -Werror -fstack-protector-strong -Wno-attributes \ -Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") endif() diff --git a/mindspore/lite/micro/example/mnist/src/microtensor.h b/mindspore/lite/micro/example/mnist/src/microtensor.h deleted file mode 100644 index 861d2a002b..0000000000 --- a/mindspore/lite/micro/example/mnist/src/microtensor.h +++ /dev/null @@ -1,88 +0,0 @@ - -/** - * 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 -#include -#include -#include -#include - -#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 - diff --git a/mindspore/lite/micro/example/mnist/src/net.net b/mindspore/lite/micro/example/mnist/src/net.bin similarity index 100% rename from mindspore/lite/micro/example/mnist/src/net.net rename to mindspore/lite/micro/example/mnist/src/net.bin diff --git a/mindspore/lite/micro/example/mnist/src/net.c b/mindspore/lite/micro/example/mnist/src/net.c index c19bc1e5a7..ae15c50fa4 100644 --- a/mindspore/lite/micro/example/mnist/src/net.c +++ b/mindspore/lite/micro/example/mnist/src/net.c @@ -15,34 +15,21 @@ * limitations under the License. */ -#include "microtensor.h" -#include "net_weight.h" + +#include "weight.h" #include "net.h" -static const unsigned char *net_I0 = 0; -int net_SetInputs(const void **inputs, int num) { +static const unsigned char *g_Input0 = 0; +int SetInputs(const void **inputs, int num) { if (inputs == NULL) { return RET_ERROR; } if (num !=1) { return RET_ERROR; } - net_I0 = inputs[0]; + g_Input0 = inputs[0]; return RET_OK; } -const MicroTensorList* net_GetOutputs() { - static MicroTensor net_O[1] ; - static int dim0[] = {1, 10, }; - net_O[0].ndim = 2; - net_O[0].dim = dim0; - net_O[0].type = DataType_DT_FLOAT; - net_O[0].format = Format_NHWC; - net_O[0].data =net_B+56; - static MicroTensorList net_TensorArray; - net_TensorArray.num = 1; - net_TensorArray.tensor = &net_O[0]; - return &net_TensorArray; -} int CopyOutputsData(void **outputs, int num) { if (outputs == NULL) { return RET_ERROR; @@ -50,41 +37,40 @@ int CopyOutputsData(void **outputs, int num) { if (num != 1) { return RET_ERROR; } - memcpy(outputs[0], net_B+56, 40); - outputs[0] = net_B; + memcpy(outputs[0], g_Buffer+56, 40); return RET_OK; } -int net_GetBufferSize() { +int GetBufferSize() { return 40032; } -int net_SetBuffer( void *buffer) { +int SetBuffer( void *buffer) { if (buffer == NULL) { return RET_ERROR; } - net_B = buffer; + g_Buffer = buffer; return RET_OK; } -void net_FreeResource() { - net_B= NULL; - net_I0 = NULL; - void *allocated[] = {net_W14, net_W15, net_W16, net_W17, net_W18, net_W19, }; +void FreeResource() { + g_Buffer= NULL; + g_Input0 = NULL; + void *allocated[] = {g_Weight14, g_Weight15, g_Weight16, g_Weight17, g_Weight18, g_Weight19, }; for (int i = 0; i < 6; ++i) { free(allocated[i]); allocated[i] = NULL; } } -void net_Inference() { +void Inference() { const int g_thread_num = 1; { -DoQuantizeFp32ToInt8((float *)(net_I0), (int8_t *)(net_B+0), 0.007874015718698501587, 0, 784, false); +DoQuantizeFp32ToInt8((float *)(g_Input0), (int8_t *)(g_Buffer+0), 0.007874015718698501587, 0, 784, false); } { -memset((int16_t *)(net_B+10928), 0, 2048); -memset((int16_t *)(net_B+12976), 0, 256); -memset((int *)(net_B+13232), 0, 6144); -memset((uint8_t *)(net_B+19376), 0, 8112); -memset((int16_t *)(net_B+27488), 0, 12544); +memset((int16_t *)(g_Buffer+10928), 0, 2048); +memset((int16_t *)(g_Buffer+12976), 0, 256); +memset((int *)(g_Buffer+13232), 0, 6144); +memset((int8_t *)(g_Buffer+19376), 0, 8112); +memset((int16_t *)(g_Buffer+27488), 0, 12544); static QuantArg conv_param__quant_arg_in[1] = {{0.007874015718698501587, 0}}; static QuantArg conv_param__quant_arg_w[12] = {{0.003238174133002758026, -6}, {0.003890725085511803627, -8}, {0.003394871251657605171, -7}, {0.001685356837697327137, -127}, {0.004322394262999296188, 1}, {0.002274985425174236298, -56}, {0.003617759561166167259, 17}, {0.004447745624929666519, 23}, {0.004683905746787786484, 26}, {0.004021023400127887726, 24}, {0.005650237202644348145, 11}, {0.001966834301128983498, -84}}; static QuantArg conv_param__quant_arg_out[1] = {{0.01778890006244182587, 0}}; @@ -94,26 +80,26 @@ static int conv_param__right_shift[12] = {-9, -9, -9, -10, -9, -9, -9, -8, -8, - static int conv_param__quant_multiplier[12] = {1575967367, 1893553389, 1652229306, 1640472199, 2103639903, 1107198867, 1760705490, 1082323130, 1139790877, 1956967540, 1374939873, 1914453388}; static int conv_param__out_act_min[1] = {0}; static int conv_param__out_act_max[1] = {127}; -const ConvQuantArg conv_param__conv_quant_arg = {(RoundingMode)(1), 2, conv_param__quant_arg_in, conv_param__quant_arg_w, conv_param__quant_arg_out, conv_param__real_multiplier, conv_param__left_shift, conv_param__right_shift, conv_param__quant_multiplier, conv_param__out_act_min, conv_param__out_act_max, 1, 12, 1, 2}; +ConvQuantArg conv_param__conv_quant_arg = {(RoundingMode)(1), 2, conv_param__quant_arg_in, conv_param__quant_arg_w, conv_param__quant_arg_out, conv_param__real_multiplier, conv_param__left_shift, conv_param__right_shift, conv_param__quant_multiplier, conv_param__out_act_min, conv_param__out_act_max, 1, 12, 1, 2}; int thread_num = MSMIN(g_thread_num, 26); -const ConvParameter conv_param_ = {{ "", 35, g_thread_num}, conv_param__conv_quant_arg, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 28, 28, 1, 1, 26, 26, 12, thread_num, 0, 0, (PadMode)(2), (ActType)(1), 0, 0, 0}; -PackInputToC8Int8((int8_t *)(net_B+0), (int16_t *)(net_B+27488), &conv_param_); -Conv3x3Int8((int16_t *)(net_B+27488), net_W10, net_W11, (int8_t *)(net_B+784), (int16_t *)(net_B+10928), (int16_t *)(net_B+12976), (int *)(net_B+13232), (uint8_t *)(net_B+19376), 0, &conv_param_); -PackNC4HW4ToNHWCInt8((uint8_t *)(net_B+19376), (int8_t *)(net_B+784), 1, 676, 12); +ConvParameter conv_param_ = {{ "", 35, g_thread_num}, conv_param__conv_quant_arg, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 28, 28, 1, 1, 26, 26, 12, thread_num, 0, 0, (PadMode)(2), (ActType)(1), 0, 0, 0}; +PackInputToC8Int8((int8_t *)(g_Buffer+0), (int16_t *)(g_Buffer+27488), &conv_param_); +Conv3x3Int8((int16_t *)(g_Buffer+27488), g_Weight10, g_Weight11, (int8_t *)(g_Buffer+784), (int16_t *)(g_Buffer+10928), (int16_t *)(g_Buffer+12976), (int *)(g_Buffer+13232), (int8_t *)(g_Buffer+19376), 0, &conv_param_); +PackNC4HW4ToNHWCInt8((int8_t *)(g_Buffer+19376), (int8_t *)(g_Buffer+784), 1, 676, 12); } { static QuantArg pooling_parameter_quant_in = {0.01778890006244182587, 0}; static QuantArg pooling_parameter_quant_out = {0.01778890006244182587, 0}; static QuantArg *pooling_parameter_quant[2] = { &pooling_parameter_quant_in, &pooling_parameter_quant_out}; const PoolingParameter pooling_parameter = {{ "", 92, g_thread_num}, (PoolMode)(1), (RoundMode)(2), (PadMode)(2), (ActType)(0), 0, false, 2, 2, 2, 2, 26, 26, 1, 12, 13, 13, 1, 12, 0, 0, 0, 0, 0, pooling_parameter_quant, false}; -MaxPoolingInt8((int8_t *)(net_B+784), (int8_t *)(net_B+8896), (PoolingParameter *)&pooling_parameter, 0); +MaxPoolingInt8((int8_t *)(g_Buffer+784), (int8_t *)(g_Buffer+8896), (PoolingParameter *)&pooling_parameter, 0); } { -memset((int16_t *)(net_B+10928), 0, 4096); -memset((int16_t *)(net_B+15024), 0, 256); -memset((int *)(net_B+15280), 0, 6144); -memset((uint8_t *)(net_B+21424), 0, 1452); -memset((int16_t *)(net_B+22876), 0, 5408); +memset((int16_t *)(g_Buffer+10928), 0, 4096); +memset((int16_t *)(g_Buffer+15024), 0, 256); +memset((int *)(g_Buffer+15280), 0, 6144); +memset((int8_t *)(g_Buffer+21424), 0, 1452); +memset((int16_t *)(g_Buffer+22876), 0, 5408); static QuantArg conv_param__quant_arg_in[1] = {{0.01778890006244182587, 0}}; static QuantArg conv_param__quant_arg_w[12] = {{0.005374609492719173431, 33}, {0.005837683100253343582, 22}, {0.004709810949862003326, -15}, {0.003726204857230186462, 27}, {0.00318551529198884964, -8}, {0.003453079145401716232, 50}, {0.004045850131660699844, -9}, {0.003903790842741727829, 30}, {0.004003710579127073288, -10}, {0.00560879148542881012, 27}, {0.005486610345542430878, -23}, {0.003554018214344978333, 4}}; static QuantArg conv_param__quant_arg_out[1] = {{0.07183934003114700317, 0}}; @@ -123,62 +109,62 @@ static int conv_param__right_shift[12] = {-9, -9, -9, -10, -10, -10, -9, -10, -9 static int conv_param__quant_multiplier[12] = {1463300414, 1589377630, 1282301201, 2029005945, 1734587761, 1880282530, 1101530164, 2125705720, 1090057119, 1527059240, 1493794012, 1935246286}; static int conv_param__out_act_min[1] = {0}; static int conv_param__out_act_max[1] = {127}; -const ConvQuantArg conv_param__conv_quant_arg = {(RoundingMode)(1), 2, conv_param__quant_arg_in, conv_param__quant_arg_w, conv_param__quant_arg_out, conv_param__real_multiplier, conv_param__left_shift, conv_param__right_shift, conv_param__quant_multiplier, conv_param__out_act_min, conv_param__out_act_max, 1, 12, 1, 2}; +ConvQuantArg conv_param__conv_quant_arg = {(RoundingMode)(1), 2, conv_param__quant_arg_in, conv_param__quant_arg_w, conv_param__quant_arg_out, conv_param__real_multiplier, conv_param__left_shift, conv_param__right_shift, conv_param__quant_multiplier, conv_param__out_act_min, conv_param__out_act_max, 1, 12, 1, 2}; int thread_num = MSMIN(g_thread_num, 11); -const ConvParameter conv_param_ = {{ "", 35, g_thread_num}, conv_param__conv_quant_arg, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 13, 13, 12, 1, 11, 11, 12, thread_num, 0, 0, (PadMode)(2), (ActType)(1), 0, 0, 0}; -PackInputToC8Int8((int8_t *)(net_B+8896), (int16_t *)(net_B+22876), &conv_param_); -Conv3x3Int8((int16_t *)(net_B+22876), net_W12, net_W13, (int8_t *)(net_B+0), (int16_t *)(net_B+10928), (int16_t *)(net_B+15024), (int *)(net_B+15280), (uint8_t *)(net_B+21424), 0, &conv_param_); -PackNC4HW4ToNHWCInt8((uint8_t *)(net_B+21424), (int8_t *)(net_B+0), 1, 121, 12); +ConvParameter conv_param_ = {{ "", 35, g_thread_num}, conv_param__conv_quant_arg, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 13, 13, 12, 1, 11, 11, 12, thread_num, 0, 0, (PadMode)(2), (ActType)(1), 0, 0, 0}; +PackInputToC8Int8((int8_t *)(g_Buffer+8896), (int16_t *)(g_Buffer+22876), &conv_param_); +Conv3x3Int8((int16_t *)(g_Buffer+22876), g_Weight12, g_Weight13, (int8_t *)(g_Buffer+0), (int16_t *)(g_Buffer+10928), (int16_t *)(g_Buffer+15024), (int *)(g_Buffer+15280), (int8_t *)(g_Buffer+21424), 0, &conv_param_); +PackNC4HW4ToNHWCInt8((int8_t *)(g_Buffer+21424), (int8_t *)(g_Buffer+0), 1, 121, 12); } { static QuantArg pooling_parameter_quant_in = {0.07136065512895584106, 0}; static QuantArg pooling_parameter_quant_out = {0.07136065512895584106, 0}; static QuantArg *pooling_parameter_quant[2] = { &pooling_parameter_quant_in, &pooling_parameter_quant_out}; const PoolingParameter pooling_parameter = {{ "", 92, g_thread_num}, (PoolMode)(1), (RoundMode)(2), (PadMode)(2), (ActType)(0), 0, false, 2, 2, 2, 2, 11, 11, 1, 12, 5, 5, 1, 12, 0, 0, 0, 0, 0, pooling_parameter_quant, false}; -MaxPoolingInt8((int8_t *)(net_B+0), (int8_t *)(net_B+1456), (PoolingParameter *)&pooling_parameter, 0); +MaxPoolingInt8((int8_t *)(g_Buffer+0), (int8_t *)(g_Buffer+1456), (PoolingParameter *)&pooling_parameter, 0); } { const ReshapeQuantArg reshape_quant_arg = {{0.07136065512895584106, 0}, {0.07136065512895584106, 0}, -128, 127}; -Int8Reshape((int8_t *)(net_B+1456), (int8_t *)(net_B+0), 300, reshape_quant_arg); +Int8Reshape((int8_t *)(g_Buffer+1456), (int8_t *)(g_Buffer+0), 300, reshape_quant_arg); } { int32_t tmp_weight_zp = 1; -RowMajor2Row16x4MajorInt8((int8_t *)(net_B+0)+0, (int8_t *)(net_B+10928), 1, 300); -CalcInputSums((int8_t *)(net_B+0)+0, 1, 300, tmp_weight_zp, (int *)(net_B+12144), RowMajor); -const float filter_scale[20] = {0.003479549195617437363, 0.004490676335990428925, 0.004529818892478942871, 0.002983231563121080399, 0.003455155529081821442, 0.003223794745281338692, 0.003272445406764745712, 0.003801185870543122292, 0.003679843153804540634, 0.003040234791114926338, 0.003704284550622105598, 0.003355232765898108482, 0.002904496388509869576, 0.003024494973942637444, 0.002794801956042647362, 0.004355110693722963333, 0.003499472280964255333, 0.004184196703135967255, 0.003057289868593215942, 0.003264668164774775505}; -const int filter_zp[20] = {1, 12, 3, 2, -10, -5, -11, 5, 12, 22, 16, 1, -5, 15, 13, 5, -10, -5, -6, 0}; -const int left_shift[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -const int right_shift[20] = {-10, -9, -9, -10, -10, -10, -10, -9, -9, -10, -9, -10, -10, -10, -10, -9, -10, -9, -10, -10}; -const int multiplier[20] = {2108215049, 1360422072, 1372280070, 1807502393, 2093435146, 1953256619, 1982733521, 1151545365, 1114785262, 1842040025, 1122189669, 2032893316, 1759797843, 1832503464, 1693335354, 1319353429, 2120286176, 1267576078, 1852373503, 1978021333}; +RowMajor2Row16x4MajorInt8((int8_t *)(g_Buffer+0)+0, (int8_t *)(g_Buffer+10928), 1, 300); +CalcInputSums((int8_t *)(g_Buffer+0)+0, 1, 300, tmp_weight_zp, (int *)(g_Buffer+12144), RowMajor); +static float filter_scale[20] = {0.003479549195617437363, 0.004490676335990428925, 0.004529818892478942871, 0.002983231563121080399, 0.003455155529081821442, 0.003223794745281338692, 0.003272445406764745712, 0.003801185870543122292, 0.003679843153804540634, 0.003040234791114926338, 0.003704284550622105598, 0.003355232765898108482, 0.002904496388509869576, 0.003024494973942637444, 0.002794801956042647362, 0.004355110693722963333, 0.003499472280964255333, 0.004184196703135967255, 0.003057289868593215942, 0.003264668164774775505}; +static int filter_zp[20] = {1, 12, 3, 2, -10, -5, -11, 5, 12, 22, 16, 1, -5, 15, 13, 5, -10, -5, -6, 0}; +static int left_shift[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static int right_shift[20] = {-10, -9, -9, -10, -10, -10, -10, -9, -9, -10, -9, -10, -10, -10, -10, -9, -10, -9, -10, -10}; +static int multiplier[20] = {2108215049, 1360422072, 1372280070, 1807502393, 2093435146, 1953256619, 1982733521, 1151545365, 1114785262, 1842040025, 1122189669, 2032893316, 1759797843, 1832503464, 1693335354, 1319353429, 2120286176, 1267576078, 1852373503, 1978021333}; const MatmulQuantParameter matmul_quant_parameter = {{0.07136065512895584106, 0}, {0, 0}, {0.258998185396194458, 0}, -128, 127, filter_scale, filter_zp, left_shift, right_shift, multiplier}; int32_t *cur_left = matmul_quant_parameter.left_shift_ + 0; int32_t *cur_right = matmul_quant_parameter.right_shift_ + 0; int32_t *cur_mul = matmul_quant_parameter.quant_multiplier_ + 0; int32_t *cur_zp = matmul_quant_parameter.filter_zp_ + 0; -MatmulInt8Opt((int8_t *)(net_B+10928), net_W15+0 + 0, (int8_t *)(net_B+304)+0+0, 1, 20, 304, (int *)(net_B+12144), net_W16+0, -128, 127, 0, cur_mul, cur_left, cur_right, 20, true, cur_zp); +MatmulInt8Opt((int8_t *)(g_Buffer+10928), g_Weight15+0 + 0, (int8_t *)(g_Buffer+304)+0+0, 1, 20, 304, (int *)(g_Buffer+12144), g_Weight16+0, -128, 127, 0, cur_mul, cur_left, cur_right, 20, true, cur_zp); } { int32_t tmp_weight_zp = 1; -RowMajor2Row16x4MajorInt8((int8_t *)(net_B+304)+0, (int8_t *)(net_B+10928), 1, 20); -CalcInputSums((int8_t *)(net_B+304)+0, 1, 20, tmp_weight_zp, (int *)(net_B+11056), RowMajor); -const float filter_scale[10] = {0.004678330849856138229, 0.005127115640789270401, 0.00471437256783246994, 0.004531511571258306503, 0.005476122256368398666, 0.004348111804574728012, 0.004803542047739028931, 0.006081215571612119675, 0.004532597027719020844, 0.004762654658406972885}; -const int filter_zp[10] = {7, -2, 9, 2, -6, 21, 16, 10, -19, 8}; -const int left_shift[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -const int right_shift[10] = {-8, -8, -8, -8, -8, -8, -8, -8, -8, -8}; -const int multiplier[10] = {1242805482, 1362025788, 1252380041, 1203802750, 1454739904, 1155082292, 1276068015, 1615483838, 1204091115, 1265206260}; +RowMajor2Row16x4MajorInt8((int8_t *)(g_Buffer+304)+0, (int8_t *)(g_Buffer+10928), 1, 20); +CalcInputSums((int8_t *)(g_Buffer+304)+0, 1, 20, tmp_weight_zp, (int *)(g_Buffer+11056), RowMajor); +static float filter_scale[10] = {0.004678330849856138229, 0.005127115640789270401, 0.00471437256783246994, 0.004531511571258306503, 0.005476122256368398666, 0.004348111804574728012, 0.004803542047739028931, 0.006081215571612119675, 0.004532597027719020844, 0.004762654658406972885}; +static int filter_zp[10] = {7, -2, 9, 2, -6, 21, 16, 10, -19, 8}; +static int left_shift[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static int right_shift[10] = {-8, -8, -8, -8, -8, -8, -8, -8, -8, -8}; +static int multiplier[10] = {1242805482, 1362025788, 1252380041, 1203802750, 1454739904, 1155082292, 1276068015, 1615483838, 1204091115, 1265206260}; const MatmulQuantParameter matmul_quant_parameter = {{0.258998185396194458, 0}, {0, 0}, {0.5359870791435241699, 0}, -128, 127, filter_scale, filter_zp, left_shift, right_shift, multiplier}; int32_t *cur_left = matmul_quant_parameter.left_shift_ + 0; int32_t *cur_right = matmul_quant_parameter.right_shift_ + 0; int32_t *cur_mul = matmul_quant_parameter.quant_multiplier_ + 0; int32_t *cur_zp = matmul_quant_parameter.filter_zp_ + 0; -MatmulInt8Opt((int8_t *)(net_B+10928), net_W18+0 + 0, (int8_t *)(net_B+0)+0+0, 1, 10, 32, (int *)(net_B+11056), net_W19+0, -128, 127, 0, cur_mul, cur_left, cur_right, 10, true, cur_zp); +MatmulInt8Opt((int8_t *)(g_Buffer+10928), g_Weight18+0 + 0, (int8_t *)(g_Buffer+0)+0+0, 1, 10, 32, (int *)(g_Buffer+11056), g_Weight19+0, -128, 127, 0, cur_mul, cur_left, cur_right, 10, true, cur_zp); } { -DoDequantizeInt8ToFp32((int8_t *)(net_B+0), (float *)(net_B+16), 0.5359870791435241699, 0, 10); +DoDequantizeInt8ToFp32((int8_t *)(g_Buffer+0), (float *)(g_Buffer+16), 0.5359870791435241699, 0, 10); } { const SoftmaxParameter softmax_parameter = {{ "", 138, g_thread_num}, 1, {1, 10}, 10, 2}; -memset((float *)(net_B+10928), 0, 4); -Softmax((float *)(net_B+16), (float *)(net_B+56), (float *)(net_B+10928), &softmax_parameter); +memset((float *)(g_Buffer+10928), 0, 4); +Softmax((float *)(g_Buffer+16), (float *)(g_Buffer+56), (float *)(g_Buffer+10928), &softmax_parameter); } } diff --git a/mindspore/lite/micro/example/mnist/src/net.cmake b/mindspore/lite/micro/example/mnist/src/net.cmake index c6e47df7d4..dd8a2ea236 100644 --- a/mindspore/lite/micro/example/mnist/src/net.cmake +++ b/mindspore/lite/micro/example/mnist/src/net.cmake @@ -13,7 +13,7 @@ set(OP_SRC quant_dtype_cast_int8.c.o reshape_int8.c.o softmax_fp32.c.o - net_weight.c.o + weight.c.o net.c.o session.cc.o tensor.cc.o diff --git a/mindspore/lite/micro/example/mnist/src/net.h b/mindspore/lite/micro/example/mnist/src/net.h index ab4ab32732..acc734d428 100644 --- a/mindspore/lite/micro/example/mnist/src/net.h +++ b/mindspore/lite/micro/example/mnist/src/net.h @@ -15,24 +15,15 @@ * limitations under the License. */ -#include "microtensor.h" - - #ifdef __cplusplus extern "C" { #endif - /** * set input tensors * @param inputs, the input data ptr's array of the model, the tensors' count of input may be greater than one. * @param num, the input data's number of the model. **/ -int net_SetInputs(const void **inputs, int num); - -/** - * get output tensor of the model - **/ -const MicroTensorList *net_GetOutputs(); +int SetInputs(const void **inputs, int num); int CopyOutputsData(void **outputs, int num); @@ -40,28 +31,26 @@ int CopyOutputsData(void **outputs, int num); * @param weight_buffer, the address of the weight binary file * @param weight_size, the size of the model file in bytes **/ -int net_Init(void *weight_buffer, int weight_size); +int Init(void *weight_buffer, int weight_size); /** * get the memory space size of the inference. **/ -int net_GetBufferSize(); +int GetBufferSize(); /** * set the memory space for the inference **/ -int net_SetBuffer(void *buffer); +int SetBuffer(void *buffer); /** * free the memory of packed weights, and set the membuf buffer and input address to NULL **/ -void net_FreeResource(); +void FreeResource(); /** * net inference function **/ -void net_Inference(); - +void Inference(); #ifdef __cplusplus } #endif - diff --git a/mindspore/lite/micro/example/mnist/src/net_weight.c b/mindspore/lite/micro/example/mnist/src/net_weight.c deleted file mode 100644 index 5defba035c..0000000000 --- a/mindspore/lite/micro/example/mnist/src/net_weight.c +++ /dev/null @@ -1,103 +0,0 @@ - -/** - * 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 "net_weight.h" - -unsigned char * net_B = 0 ; -int16_t net_W10[1536]; -int32_t net_W11[12]; -int16_t net_W12[3072]; -int32_t net_W13[12]; -int32_t *net_W14 = NULL; -int8_t *net_W15 = NULL; -int32_t *net_W16 = NULL; -int32_t *net_W17 = NULL; -int8_t *net_W18 = NULL; -int32_t *net_W19 = NULL; - -int net_Init(void *weight_buffer, int weight_size) { - if (weight_buffer == NULL) { - return RET_ERROR; - } - int g_thread_num = 1; - - struct ModelParameter { - void *addr; - size_t size; - size_t offset; - }; - int8_t *net_W6 = (weight_buffer + 9312); - int32_t *net_W7 = (weight_buffer + 15312); - int8_t *net_W8 = (weight_buffer + 15392); - int32_t *net_W9 = (weight_buffer + 15592); - - struct ModelParameter model_params[] = { - {net_W10, 3072, 0}, - {net_W11, 48, 3072}, - {net_W12, 6144, 3120}, - {net_W13, 48, 9264}, - }; - - for(int i = 0; i < 4; ++i) { - if (model_params[i].offset + model_params[i].size > weight_size) { - return RET_ERROR; - } - memcpy(model_params[i].addr, (weight_buffer + model_params[i].offset), model_params[i].size); - } -{ -net_W14 = malloc(80); -if (net_W14 == NULL) { - return RET_ERROR; -} -memset(net_W14, 0, 80); -memcpy(net_W14, net_W7, 80); -net_W16 = malloc(80); -if (net_W16 == NULL) { - return RET_ERROR; -} -memset(net_W16, 0, 80); -net_W15 = malloc(6080); -if (net_W15 == NULL) { - return RET_ERROR; -} -memset(net_W15, 0, 6080); -const int init_filter_zp[20] = {1, 12, 3, 2, -10, -5, -11, 5, 12, 22, 16, 1, -5, 15, 13, 5, -10, -5, -6, 0}; -InitInt8MatrixB(net_W6, net_W16, net_W15, 1, 300, 20, 20, 304, 0, init_filter_zp, net_W14, true, true); -} -{ -net_W17 = malloc(48); -if (net_W17 == NULL) { - return RET_ERROR; -} -memset(net_W17, 0, 48); -memcpy(net_W17, net_W9, 48); -net_W19 = malloc(48); -if (net_W19 == NULL) { - return RET_ERROR; -} -memset(net_W19, 0, 48); -net_W18 = malloc(384); -if (net_W18 == NULL) { - return RET_ERROR; -} -memset(net_W18, 0, 384); -const int init_filter_zp[10] = {7, -2, 9, 2, -6, 21, 16, 10, -19, 8}; -InitInt8MatrixB(net_W8, net_W19, net_W18, 1, 20, 10, 12, 32, 0, init_filter_zp, net_W17, true, true); -} - return RET_OK; -} - diff --git a/mindspore/lite/micro/example/mnist/src/session.cc b/mindspore/lite/micro/example/mnist/src/session.cc index 04a1170b95..6ecb582244 100644 --- a/mindspore/lite/micro/example/mnist/src/session.cc +++ b/mindspore/lite/micro/example/mnist/src/session.cc @@ -39,9 +39,9 @@ int LiteSession::RunGraph(const KernelCallBack &before, const KernelCallBack &af for (size_t i = 0; i < inputs_.size(); ++i) { inputs_data[i] = inputs_[i]->MutableData(); } - net_SetInputs(inputs_data, inputs_.size()); + SetInputs(inputs_data, inputs_.size()); - net_Inference(); + Inference(); void *outputs_data[outputs_.size()]; for (size_t i = 0; i < outputs_.size(); ++i) { @@ -53,7 +53,7 @@ int LiteSession::RunGraph(const KernelCallBack &before, const KernelCallBack &af } LiteSession::~LiteSession() { - net_FreeResource(); + FreeResource(); if (runtime_buffer_ != nullptr) { free(runtime_buffer_); runtime_buffer_ = nullptr; @@ -76,12 +76,12 @@ LiteSession::~LiteSession() { } int LiteSession::InitRuntimeBuffer() { - int buffer_size = net_GetBufferSize(); + int buffer_size = GetBufferSize(); runtime_buffer_ = malloc(buffer_size); if (runtime_buffer_ == nullptr) { return RET_ERROR; } - int ret = net_SetBuffer(runtime_buffer_); + int ret = SetBuffer(runtime_buffer_); if (ret != RET_OK) { return RET_ERROR; } @@ -150,7 +150,7 @@ session::LiteSession *session::LiteSession::CreateSession(const char *net_buf, s if (ret != lite::RET_OK) { return nullptr; } - net_Init(const_cast(net_buf), size); + Init(const_cast(net_buf), size); return session; } } // namespace mindspore diff --git a/mindspore/lite/micro/example/mnist/src/weight.c b/mindspore/lite/micro/example/mnist/src/weight.c new file mode 100644 index 0000000000..ca72d9b718 --- /dev/null +++ b/mindspore/lite/micro/example/mnist/src/weight.c @@ -0,0 +1,102 @@ + +/** + * 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 "weight.h" + +unsigned char * g_Buffer = 0 ; +int16_t g_Weight10[1536]; +int32_t g_Weight11[12]; +int16_t g_Weight12[3072]; +int32_t g_Weight13[12]; +int32_t *g_Weight14 = NULL; +int8_t *g_Weight15 = NULL; +int32_t *g_Weight16 = NULL; +int32_t *g_Weight17 = NULL; +int8_t *g_Weight18 = NULL; +int32_t *g_Weight19 = NULL; + +int Init(void *weight_buffer, int weight_size) { + if (weight_buffer == NULL) { + return RET_ERROR; + } + + struct ModelParameter { + void *addr; + size_t size; + size_t offset; + }; + int8_t *g_Weight6 = (weight_buffer + 9312); + int32_t *g_Weight7 = (weight_buffer + 15312); + int8_t *g_Weight8 = (weight_buffer + 15392); + int32_t *g_Weight9 = (weight_buffer + 15592); + + struct ModelParameter model_params[] = { + {g_Weight10, 3072, 0}, + {g_Weight11, 48, 3072}, + {g_Weight12, 6144, 3120}, + {g_Weight13, 48, 9264}, + }; + + for(int i = 0; i < 4; ++i) { + if (model_params[i].offset + model_params[i].size > weight_size) { + return RET_ERROR; + } + memcpy(model_params[i].addr, (weight_buffer + model_params[i].offset), model_params[i].size); + } +{ +g_Weight14 = malloc(80); +if (g_Weight14 == NULL) { + return RET_ERROR; +} +memset(g_Weight14, 0, 80); +memcpy(g_Weight14, g_Weight7, 80); +g_Weight16 = malloc(80); +if (g_Weight16 == NULL) { + return RET_ERROR; +} +memset(g_Weight16, 0, 80); +g_Weight15 = malloc(6080); +if (g_Weight15 == NULL) { + return RET_ERROR; +} +memset(g_Weight15, 0, 6080); +static int init_filter_zp[20] = {1, 12, 3, 2, -10, -5, -11, 5, 12, 22, 16, 1, -5, 15, 13, 5, -10, -5, -6, 0}; +InitInt8MatrixB(g_Weight6, g_Weight16, g_Weight15, 1, 300, 20, 20, 304, 0, init_filter_zp, g_Weight14, true, true); +} +{ +g_Weight17 = malloc(48); +if (g_Weight17 == NULL) { + return RET_ERROR; +} +memset(g_Weight17, 0, 48); +memcpy(g_Weight17, g_Weight9, 48); +g_Weight19 = malloc(48); +if (g_Weight19 == NULL) { + return RET_ERROR; +} +memset(g_Weight19, 0, 48); +g_Weight18 = malloc(384); +if (g_Weight18 == NULL) { + return RET_ERROR; +} +memset(g_Weight18, 0, 384); +static int init_filter_zp[10] = {7, -2, 9, 2, -6, 21, 16, 10, -19, 8}; +InitInt8MatrixB(g_Weight8, g_Weight19, g_Weight18, 1, 20, 10, 12, 32, 0, init_filter_zp, g_Weight17, true, true); +} + return RET_OK; +} + diff --git a/mindspore/lite/micro/example/mnist/src/net_weight.h b/mindspore/lite/micro/example/mnist/src/weight.h similarity index 74% rename from mindspore/lite/micro/example/mnist/src/net_weight.h rename to mindspore/lite/micro/example/mnist/src/weight.h index 65b597cc19..887e4dacae 100644 --- a/mindspore/lite/micro/example/mnist/src/net_weight.h +++ b/mindspore/lite/micro/example/mnist/src/weight.h @@ -28,16 +28,19 @@ #include "wrapper/int8/matmul_int8_wrapper.h" #include #include -#include "microtensor.h" +extern unsigned char *g_Buffer; +enum STATUS { + RET_OK = 0, + RET_ERROR = 1, +}; -extern unsigned char *net_B; -extern int16_t net_W10[]; -extern int32_t net_W11[]; -extern int16_t net_W12[]; -extern int32_t net_W13[]; -extern int32_t *net_W14; -extern int8_t *net_W15; -extern int32_t *net_W16; -extern int32_t *net_W17; -extern int8_t *net_W18; -extern int32_t *net_W19; +extern int16_t g_Weight10[]; +extern int32_t g_Weight11[]; +extern int16_t g_Weight12[]; +extern int32_t g_Weight13[]; +extern int32_t *g_Weight14; +extern int8_t *g_Weight15; +extern int32_t *g_Weight16; +extern int32_t *g_Weight17; +extern int8_t *g_Weight18; +extern int32_t *g_Weight19;