!13461 format cli && add support for relative path

From: @zhujingxuan
Reviewed-by: @wangchengyuan,@ddwsky
Signed-off-by: @wangchengyuan
This commit is contained in:
mindspore-ci-bot 2021-03-17 15:14:28 +08:00 committed by Gitee
commit 93f64e38dd
6 changed files with 30 additions and 49 deletions

View File

@ -45,6 +45,11 @@ else()
-fstack-protector-all -Wno-attributes -Wno-deprecated-declarations \
-Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}")
endif()
if(NOT WIN32)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIC -pie ${CMAKE_EXE_LINKER_FLAGS}")
endif()
add_subdirectory(coder)
if(BUILD_TESTCASES AND NOT PLATFORM_ARM64 AND NOT PLATFORM_ARM32)
add_subdirectory(test)

View File

@ -201,10 +201,8 @@ set(LITE_KERNEL_SRC
${LITE_DIR}/nnacl/infer/arithmetic_compare_infer.c
${LITE_DIR}/nnacl/infer/arithmetic_grad_infer.c
${LITE_DIR}/nnacl/infer/arithmetic_infer.c
${LITE_DIR}/nnacl/infer/assert_op_infer.c
${LITE_DIR}/nnacl/infer/assign_add_infer.c
${LITE_DIR}/nnacl/infer/assign_infer.c
${LITE_DIR}/nnacl/infer/audio_spectrogram_infer.c
${LITE_DIR}/nnacl/infer/batch_to_space_infer.c
${LITE_DIR}/nnacl/infer/bias_grad_infer.c
${LITE_DIR}/nnacl/infer/binary_cross_entropy_infer.c
@ -217,67 +215,36 @@ set(LITE_KERNEL_SRC
${LITE_DIR}/nnacl/infer/conv2d_grad_filter_infer.c
${LITE_DIR}/nnacl/infer/conv2d_grad_input_infer.c
${LITE_DIR}/nnacl/infer/conv2d_infer.c
${LITE_DIR}/nnacl/infer/crop_and_resize_infer.c
${LITE_DIR}/nnacl/infer/crop_infer.c
${LITE_DIR}/nnacl/infer/custom_extract_features_infer.c
${LITE_DIR}/nnacl/infer/custom_normalize_infer.c
${LITE_DIR}/nnacl/infer/custom_predict_infer.c
${LITE_DIR}/nnacl/infer/deconv2d_infer.c
${LITE_DIR}/nnacl/infer/dedepthwise_conv2d_infer.c
${LITE_DIR}/nnacl/infer/depth_to_space_infer.c
${LITE_DIR}/nnacl/infer/depthwise_conv2d_infer.c
${LITE_DIR}/nnacl/infer/detection_post_process_infer.c
${LITE_DIR}/nnacl/infer/dropout_grad_infer.c
${LITE_DIR}/nnacl/infer/dropout_infer.c
${LITE_DIR}/nnacl/infer/embedding_lookup_infer.c
${LITE_DIR}/nnacl/infer/expand_dims_infer.c
${LITE_DIR}/nnacl/infer/fft_imag_infer.c
${LITE_DIR}/nnacl/infer/fft_real_infer.c
${LITE_DIR}/nnacl/infer/fill_infer.c
${LITE_DIR}/nnacl/infer/flatten_grad_infer.c
${LITE_DIR}/nnacl/infer/flatten_infer.c
${LITE_DIR}/nnacl/infer/full_connection_infer.c
${LITE_DIR}/nnacl/infer/fused_batchnorm_infer.c
${LITE_DIR}/nnacl/infer/gather_infer.c
${LITE_DIR}/nnacl/infer/gather_nd_infer.c
${LITE_DIR}/nnacl/infer/group_conv2d_grad_input_infer.c
${LITE_DIR}/nnacl/infer/gru_infer.c
${LITE_DIR}/nnacl/infer/hashtable_lookup_infer.c
${LITE_DIR}/nnacl/infer/infer_register.c
${LITE_DIR}/nnacl/infer/invert_permutation_infer.c
${LITE_DIR}/nnacl/infer/layer_norm_infer.c
${LITE_DIR}/nnacl/infer/layer_norm_grad_infer.c
${LITE_DIR}/nnacl/infer/lin_space_infer.c
${LITE_DIR}/nnacl/infer/lsh_projection_infer.c
${LITE_DIR}/nnacl/infer/lstm_infer.c
${LITE_DIR}/nnacl/infer/matmul_infer.c
${LITE_DIR}/nnacl/infer/maximum_grad_infer.c
${LITE_DIR}/nnacl/infer/mean_infer.c
${LITE_DIR}/nnacl/infer/merge_infer.c
${LITE_DIR}/nnacl/infer/mfcc_infer.c
${LITE_DIR}/nnacl/infer/non_max_suppression_infer.c
${LITE_DIR}/nnacl/infer/one_hot_infer.c
${LITE_DIR}/nnacl/infer/pad_infer.c
${LITE_DIR}/nnacl/infer/partial_infer.c
${LITE_DIR}/nnacl/infer/pooling_grad_infer.c
${LITE_DIR}/nnacl/infer/pooling_infer.c
${LITE_DIR}/nnacl/infer/power_infer.c
${LITE_DIR}/nnacl/infer/prior_box_infer.c
${LITE_DIR}/nnacl/infer/quant_dtype_cast_infer.c
${LITE_DIR}/nnacl/infer/random_standard_normal_infer.c
${LITE_DIR}/nnacl/infer/range_infer.c
${LITE_DIR}/nnacl/infer/rank_infer.c
${LITE_DIR}/nnacl/infer/reduce_infer.c
${LITE_DIR}/nnacl/infer/reshape_infer.c
${LITE_DIR}/nnacl/infer/resize_infer.c
${LITE_DIR}/nnacl/infer/rfft_infer.c
${LITE_DIR}/nnacl/infer/roi_pooling_infer.c
${LITE_DIR}/nnacl/infer/scatter_nd_infer.c
${LITE_DIR}/nnacl/infer/select_infer.c
${LITE_DIR}/nnacl/infer/sgd_infer.c
${LITE_DIR}/nnacl/infer/shape_infer.c
${LITE_DIR}/nnacl/infer/size_infer.c
${LITE_DIR}/nnacl/infer/skip_gram_infer.c
${LITE_DIR}/nnacl/infer/slice_infer.c
${LITE_DIR}/nnacl/infer/softmax_cross_entropy_infer.c
${LITE_DIR}/nnacl/infer/softmax_infer.c
@ -288,23 +255,13 @@ set(LITE_KERNEL_SRC
${LITE_DIR}/nnacl/infer/sparse_to_dense_infer.c
${LITE_DIR}/nnacl/infer/split_infer.c
${LITE_DIR}/nnacl/infer/squeeze_infer.c
${LITE_DIR}/nnacl/infer/stack_infer.c
${LITE_DIR}/nnacl/infer/strided_slice_grad_infer.c
${LITE_DIR}/nnacl/infer/strided_slice_infer.c
${LITE_DIR}/nnacl/infer/switch_infer.c
${LITE_DIR}/nnacl/infer/tensorlist_fromtensor_infer.c
${LITE_DIR}/nnacl/infer/tensorlist_getitem_infer.c
${LITE_DIR}/nnacl/infer/tensorlist_reserve_infer.c
${LITE_DIR}/nnacl/infer/tensorlist_setitem_infer.c
${LITE_DIR}/nnacl/infer/tensorlist_stack_infer.c
${LITE_DIR}/nnacl/infer/tile_infer.c
${LITE_DIR}/nnacl/infer/topk_infer.c
${LITE_DIR}/nnacl/infer/transpose_infer.c
${LITE_DIR}/nnacl/infer/uniform_real_infer.c
${LITE_DIR}/nnacl/infer/unique_infer.c
${LITE_DIR}/nnacl/infer/unsorted_segment_sum_infer.c
${LITE_DIR}/nnacl/infer/unsqueeze_infer.c
${LITE_DIR}/nnacl/infer/unstack_infer.c
${LITE_DIR}/nnacl/infer/where_infer.c
${LITE_DIR}/nnacl/infer/while_infer.c
${LITE_DIR}/nnacl/infer/splice_infer.c

View File

@ -2,7 +2,6 @@ if(NOT PLATFORM_ARM64 AND NOT PLATFORM_ARM32)
add_definitions(-DUSE_GLOG)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections ")
set(3RD_DIR ${TOP_DIR}/third_party)
set(LITE_DIR ${TOP_DIR}/mindspore/lite)
set(MICRO_DIR ${LITE_DIR}/micro)

View File

@ -121,7 +121,7 @@ int Coder::Init(const CoderFlags &flags) const {
parsers.emplace_back([&flags, config]() -> bool {
if (!FileExists(flags.model_path_)) {
MS_LOG(ERROR) << "code_gen model_path " << flags.model_path_ << " is not valid";
MS_LOG(ERROR) << "model_path \"" << flags.model_path_ << "\" is not valid";
return false;
}
if (flags.code_module_name_.empty() || isdigit(flags.code_module_name_.at(0))) {
@ -194,12 +194,12 @@ int RunCoder(int argc, const char **argv) {
Coder code_gen;
STATUS status = code_gen.Init(flags);
if (status != RET_OK) {
MS_LOG(ERROR) << "Coder init Error : " << status;
MS_LOG(ERROR) << "Coder init Error";
return status;
}
status = code_gen.Run(flags.model_path_);
if (status != RET_OK) {
MS_LOG(ERROR) << "Run Coder Error : " << status;
MS_LOG(ERROR) << "Coder Run Error.";
return status;
}
MS_LOG(INFO) << "end of Coder";

View File

@ -22,7 +22,11 @@ const char *bench_cmake_lists_txt = R"RAW(
cmake_minimum_required(VERSION 3.14)
project(benchmark)
message("project name: ${MODEL_LIB_PATH}")
if(NOT DEFINED MODEL_LIB)
message(FATAL_ERROR "MODEL_LIB 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)
@ -35,6 +39,8 @@ endfunction(parse_lib_info)
parse_lib_info(${MODEL_LIB} MODEL_LIB_NAME MODEL_LIB_PATH)
message("project name: ${MODEL_LIB_NAME}")
option(MICRO_BUILD_ARM64 "build android arm64" OFF)
option(MICRO_BUILD_ARM32A "build android arm32" OFF)
@ -74,6 +80,17 @@ 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")
endif()
if(NOT DEFINED OP_HEADER_PATH)
message(FATAL_ERROR "OP_HEADER_PATH not set")
endif()
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})
message("operator lib path: ${OP_LIB}")
message("operator header path: ${OP_HEADER_PATH}")

View File

@ -173,7 +173,10 @@ int CoderSession::Init(const std::string &model_path) {
MS_LOG(DEBUG) << "start reading model file";
size_t size = 0;
char *graph_buf = ReadFile(model_path.c_str(), &size);
MS_CHECK_PTR(graph_buf);
if (graph_buf == nullptr) {
MS_LOG(ERROR) << "read model file from path \"" << model_path << "\" failed.";
return RET_ERROR;
}
// new a context for session
if (size >= UINT_MAX) {
MS_LOG(ERROR) << "the size is invalid";