From d0067352d4ccd5e6511a176d581de21b676e3756 Mon Sep 17 00:00:00 2001 From: yefeng Date: Fri, 10 Oct 2025 11:35:31 +0800 Subject: [PATCH] del code --- mindspore-lite/providers/dpico/CMakeLists.txt | 33 - .../providers/dpico/common/check_base.h | 87 -- .../providers/dpico/common/custom_enum.h | 36 - .../providers/dpico/common/infer_util.cc | 154 --- .../providers/dpico/common/infer_util.h | 50 - .../providers/dpico/common/log_util.cc | 74 -- .../providers/dpico/common/log_util.h | 100 -- .../providers/dpico/common/op_attr.h | 40 - .../providers/dpico/common/string_util.cc | 59 -- .../providers/dpico/common/string_util.h | 36 - .../providers/dpico/infer/custom_infer.cc | 217 ---- .../providers/dpico/infer/custom_infer.h | 37 - .../dpico/manager/acl_buf_manager.cc | 81 -- .../providers/dpico/manager/acl_buf_manager.h | 46 - .../dpico/manager/acl_context_manager.cc | 57 - .../dpico/manager/acl_context_manager.h | 43 - .../dpico/manager/acl_model_helper.cc | 238 ----- .../dpico/manager/acl_model_helper.h | 53 - .../dpico/manager/acl_model_manager.cc | 619 ----------- .../dpico/manager/acl_model_manager.h | 92 -- .../dpico/manager/custom_config_manager.cc | 118 --- .../dpico/manager/custom_config_manager.h | 68 -- .../providers/dpico/src/custom_allocator.cc | 198 ---- .../providers/dpico/src/custom_allocator.h | 76 -- .../providers/dpico/src/custom_fp32.cc | 297 ------ .../providers/dpico/src/custom_fp32.h | 59 -- mindspore-lite/providers/nnie/CMakeLists.txt | 29 - .../providers/nnie/src/custom_allocator.h | 47 - .../providers/nnie/src/custom_fp32.cc | 198 ---- .../providers/nnie/src/custom_fp32.h | 71 -- .../providers/nnie/src/custom_infer.cc | 166 --- .../providers/nnie/src/custom_infer.h | 35 - .../providers/nnie/src/nnie_cfg_parser.cc | 117 --- .../providers/nnie/src/nnie_cfg_parser.h | 57 - .../providers/nnie/src/nnie_common.cc | 972 ------------------ .../providers/nnie/src/nnie_common.h | 121 --- .../providers/nnie/src/nnie_manager.cc | 548 ---------- .../providers/nnie/src/nnie_manager.h | 117 --- .../providers/nnie/src/nnie_memory.cc | 45 - .../providers/nnie/src/nnie_memory.h | 50 - .../providers/nnie/src/nnie_print.cc | 176 ---- .../providers/nnie/src/nnie_print.h | 58 -- .../providers/nnie_proposal/CMakeLists.txt | 13 - .../providers/nnie_proposal/src/proposal.cc | 622 ----------- .../providers/nnie_proposal/src/proposal.h | 93 -- .../nnie_proposal/src/proposal_fp32.cc | 236 ----- .../nnie_proposal/src/proposal_fp32.h | 50 - .../nnie_proposal/src/proposal_infer.cc | 72 -- .../nnie_proposal/src/proposal_infer.h | 35 - .../converter/adapter/dpico/CMakeLists.txt | 62 -- .../tools/converter/adapter/dpico/OWNERS | 8 - .../dpico/checker/activation_checker.cc | 56 - .../dpico/checker/activation_checker.h | 34 - .../adapter/dpico/checker/argmax_checker.cc | 64 -- .../adapter/dpico/checker/argmax_checker.h | 34 - .../dpico/checker/arithmetic_checker.cc | 97 -- .../dpico/checker/arithmetic_checker.h | 34 - .../dpico/checker/batchnorm_checker.cc | 49 - .../adapter/dpico/checker/batchnorm_checker.h | 34 - .../adapter/dpico/checker/common_checker.cc | 71 -- .../adapter/dpico/checker/common_checker.h | 34 - .../adapter/dpico/checker/concat_checker.cc | 89 -- .../adapter/dpico/checker/concat_checker.h | 34 - .../adapter/dpico/checker/conv2d_checker.cc | 200 ---- .../adapter/dpico/checker/conv2d_checker.h | 34 - .../dpico/checker/custom_op_checker.cc | 37 - .../adapter/dpico/checker/custom_op_checker.h | 34 - .../adapter/dpico/checker/eltwise_checker.cc | 61 -- .../adapter/dpico/checker/eltwise_checker.h | 34 - .../adapter/dpico/checker/exp_checker.cc | 49 - .../adapter/dpico/checker/exp_checker.h | 34 - .../adapter/dpico/checker/flatten_checker.cc | 57 - .../adapter/dpico/checker/flatten_checker.h | 34 - .../dpico/checker/full_connection_checker.cc | 65 -- .../dpico/checker/full_connection_checker.h | 34 - .../adapter/dpico/checker/log_checker.cc | 51 - .../adapter/dpico/checker/log_checker.h | 34 - .../adapter/dpico/checker/lrn_checker.cc | 61 -- .../adapter/dpico/checker/lrn_checker.h | 34 - .../adapter/dpico/checker/lstm_checker.cc | 46 - .../adapter/dpico/checker/lstm_checker.h | 34 - .../adapter/dpico/checker/mat_mul_checker.cc | 113 -- .../adapter/dpico/checker/mat_mul_checker.h | 34 - .../adapter/dpico/checker/mvn_checker.cc | 50 - .../adapter/dpico/checker/mvn_checker.h | 34 - .../adapter/dpico/checker/op_checker.cc | 133 --- .../adapter/dpico/checker/op_checker.h | 75 -- .../adapter/dpico/checker/pooling_checker.cc | 138 --- .../adapter/dpico/checker/pooling_checker.h | 34 - .../adapter/dpico/checker/pow_checker.cc | 66 -- .../adapter/dpico/checker/pow_checker.h | 34 - .../adapter/dpico/checker/reduce_checker.cc | 133 --- .../adapter/dpico/checker/reduce_checker.h | 34 - .../adapter/dpico/checker/reshape_checker.cc | 98 -- .../adapter/dpico/checker/reshape_checker.h | 34 - .../adapter/dpico/checker/resize_checker.cc | 178 ---- .../adapter/dpico/checker/resize_checker.h | 34 - .../adapter/dpico/checker/reverse_checker.cc | 48 - .../adapter/dpico/checker/reverse_checker.h | 34 - .../adapter/dpico/checker/scale_checker.cc | 54 - .../adapter/dpico/checker/scale_checker.h | 34 - .../adapter/dpico/checker/slice_checker.cc | 60 -- .../adapter/dpico/checker/slice_checker.h | 34 - .../adapter/dpico/checker/softmax_checker.cc | 92 -- .../adapter/dpico/checker/softmax_checker.h | 34 - .../adapter/dpico/checker/split_checker.cc | 37 - .../adapter/dpico/checker/split_checker.h | 34 - .../adapter/dpico/checker/spp_checker.cc | 41 - .../adapter/dpico/checker/spp_checker.h | 34 - .../adapter/dpico/checker/squeeze_checker.cc | 44 - .../adapter/dpico/checker/squeeze_checker.h | 34 - .../dpico/checker/strided_slice_checker.cc | 42 - .../dpico/checker/strided_slice_checker.h | 34 - .../dpico/checker/transpose_checker.cc | 76 -- .../adapter/dpico/checker/transpose_checker.h | 34 - .../adapter/dpico/common/anf_util.cc | 801 --------------- .../converter/adapter/dpico/common/anf_util.h | 80 -- .../adapter/dpico/common/check_base.h | 65 -- .../dpico/common/data_transpose_utils.cc | 224 ---- .../dpico/common/data_transpose_utils.h | 88 -- .../adapter/dpico/common/fetch_content.cc | 109 -- .../adapter/dpico/common/fetch_content.h | 41 - .../adapter/dpico/common/file_util.cc | 174 ---- .../adapter/dpico/common/file_util.h | 81 -- .../converter/adapter/dpico/common/float16.h | 311 ------ .../adapter/dpico/common/format_utils.cc | 90 -- .../adapter/dpico/common/format_utils.h | 34 - .../dpico/common/graph_output_name_keeper.cc | 152 --- .../dpico/common/graph_output_name_keeper.h | 50 - .../adapter/dpico/common/infer_util.cc | 114 -- .../adapter/dpico/common/infer_util.h | 35 - .../converter/adapter/dpico/common/op_attr.h | 129 --- .../converter/adapter/dpico/common/op_enum.h | 50 - .../adapter/dpico/common/string_util.cc | 100 -- .../adapter/dpico/common/string_util.h | 41 - .../adapter/dpico/infer/dpico_common_infer.cc | 86 -- .../adapter/dpico/infer/dpico_common_infer.h | 37 - .../adapter/dpico/infer/dpico_custom_infer.cc | 245 ----- .../adapter/dpico/infer/dpico_custom_infer.h | 36 - .../dpico/infer/dpico_decbbox_infer.cc | 100 -- .../adapter/dpico/infer/dpico_decbbox_infer.h | 37 - .../infer/dpico_detection_output_infer.cc | 63 -- .../infer/dpico_detection_output_infer.h | 37 - .../dpico/infer/dpico_extract_infer.cc | 118 --- .../adapter/dpico/infer/dpico_extract_infer.h | 36 - .../adapter/dpico/infer/dpico_lstm_infer.cc | 77 -- .../adapter/dpico/infer/dpico_lstm_infer.h | 36 - .../dpico/infer/dpico_lstm_onnx_infer.cc | 101 -- .../dpico/infer/dpico_lstm_onnx_infer.h | 36 - .../dpico/infer/dpico_maxunpool_infer.cc | 124 --- .../dpico/infer/dpico_maxunpool_infer.h | 36 - .../dpico/infer/dpico_passthrough_infer.cc | 129 --- .../dpico/infer/dpico_passthrough_infer.h | 36 - .../dpico/infer/dpico_psroi_pool_infer.cc | 117 --- .../dpico/infer/dpico_psroi_pool_infer.h | 36 - .../dpico/infer/dpico_recurrent_infer.cc | 86 -- .../dpico/infer/dpico_recurrent_infer.h | 37 - .../dpico/infer/dpico_roi_align_infer.cc | 128 --- .../dpico/infer/dpico_roi_align_infer.h | 36 - .../adapter/dpico/infer/dpico_spp_infer.cc | 110 -- .../adapter/dpico/infer/dpico_spp_infer.h | 36 - .../dpico/infer/dpico_upsample_infer.cc | 131 --- .../dpico/infer/dpico_upsample_infer.h | 36 - .../dpico/legacy_ops/bi_lstm_mapper.cc | 64 -- .../adapter/dpico/legacy_ops/bi_lstm_mapper.h | 37 - .../adapter/dpico/legacy_ops/nop_mapper.cc | 49 - .../adapter/dpico/legacy_ops/nop_mapper.h | 37 - .../dpico/legacy_ops/reverse_mapper.cc | 61 -- .../adapter/dpico/legacy_ops/reverse_mapper.h | 37 - .../dpico/legacy_ops/roi_align_mapper.cc | 77 -- .../dpico/legacy_ops/roi_align_mapper.h | 37 - .../adapter/dpico/legacy_ops/spp_mapper.cc | 67 -- .../adapter/dpico/legacy_ops/spp_mapper.h | 37 - .../adapter/dpico/mapper/abs_mapper.cc | 55 - .../adapter/dpico/mapper/abs_mapper.h | 37 - .../adapter/dpico/mapper/acos_mapper.cc | 47 - .../adapter/dpico/mapper/acos_mapper.h | 37 - .../adapter/dpico/mapper/acosh_mapper.cc | 47 - .../adapter/dpico/mapper/acosh_mapper.h | 37 - .../adapter/dpico/mapper/activation_mapper.cc | 172 ---- .../adapter/dpico/mapper/activation_mapper.h | 37 - .../adapter/dpico/mapper/argmax_mapper.cc | 70 -- .../adapter/dpico/mapper/argmax_mapper.h | 37 - .../adapter/dpico/mapper/arithmetic_mapper.cc | 100 -- .../adapter/dpico/mapper/arithmetic_mapper.h | 37 - .../adapter/dpico/mapper/asinh_mapper.cc | 47 - .../adapter/dpico/mapper/asinh_mapper.h | 37 - .../adapter/dpico/mapper/atanh_mapper.cc | 47 - .../adapter/dpico/mapper/atanh_mapper.h | 37 - .../adapter/dpico/mapper/batch_norm_mapper.cc | 164 --- .../adapter/dpico/mapper/batch_norm_mapper.h | 37 - .../adapter/dpico/mapper/bias_mapper.cc | 114 -- .../adapter/dpico/mapper/bias_mapper.h | 36 - .../adapter/dpico/mapper/bitshift_mapper.cc | 58 -- .../adapter/dpico/mapper/bitshift_mapper.h | 37 - .../adapter/dpico/mapper/bnll_mapper.cc | 50 - .../adapter/dpico/mapper/bnll_mapper.h | 36 - .../adapter/dpico/mapper/cast_mapper.cc | 49 - .../adapter/dpico/mapper/cast_mapper.h | 36 - .../adapter/dpico/mapper/clip_mapper.cc | 61 -- .../adapter/dpico/mapper/clip_mapper.h | 37 - .../adapter/dpico/mapper/concat_mapper.cc | 56 - .../adapter/dpico/mapper/concat_mapper.h | 37 - .../adapter/dpico/mapper/conv_mapper.cc | 175 ---- .../adapter/dpico/mapper/conv_mapper.h | 37 - .../adapter/dpico/mapper/cosh_mapper.cc | 47 - .../adapter/dpico/mapper/cosh_mapper.h | 37 - .../adapter/dpico/mapper/crop_mapper.cc | 64 -- .../adapter/dpico/mapper/crop_mapper.h | 37 - .../adapter/dpico/mapper/custom_mapper.cc | 113 -- .../adapter/dpico/mapper/custom_mapper.h | 37 - .../adapter/dpico/mapper/decbbox_mapper.cc | 81 -- .../adapter/dpico/mapper/decbbox_mapper.h | 38 - .../adapter/dpico/mapper/deconv_mapper.cc | 106 -- .../adapter/dpico/mapper/deconv_mapper.h | 37 - .../dpico/mapper/detection_output_mapper.cc | 81 -- .../dpico/mapper/detection_output_mapper.h | 37 - .../adapter/dpico/mapper/eltwise_mapper.cc | 76 -- .../adapter/dpico/mapper/eltwise_mapper.h | 36 - .../adapter/dpico/mapper/exp_mapper.cc | 67 -- .../adapter/dpico/mapper/exp_mapper.h | 37 - .../adapter/dpico/mapper/extract_mapper.cc | 61 -- .../adapter/dpico/mapper/extract_mapper.h | 37 - .../adapter/dpico/mapper/fc_mapper.cc | 96 -- .../adapter/dpico/mapper/fc_mapper.h | 37 - .../adapter/dpico/mapper/flatten_mapper.cc | 62 -- .../adapter/dpico/mapper/flatten_mapper.h | 37 - .../adapter/dpico/mapper/gather_mapper.cc | 78 -- .../adapter/dpico/mapper/gather_mapper.h | 37 - .../dpico/mapper/gatherelements_mapper.cc | 51 - .../dpico/mapper/gatherelements_mapper.h | 37 - .../dpico/mapper/greaterorequal_mapper.cc | 55 - .../dpico/mapper/greaterorequal_mapper.h | 37 - .../adapter/dpico/mapper/gru_mapper.cc | 55 - .../adapter/dpico/mapper/gru_mapper.h | 36 - .../adapter/dpico/mapper/hardmax_mapper.cc | 68 -- .../adapter/dpico/mapper/hardmax_mapper.h | 37 - .../adapter/dpico/mapper/hardsigmod_mapper.cc | 52 - .../adapter/dpico/mapper/hardsigmod_mapper.h | 37 - .../adapter/dpico/mapper/interp_mapper.cc | 73 -- .../adapter/dpico/mapper/interp_mapper.h | 37 - .../dpico/mapper/lessorequal_mapper.cc | 55 - .../adapter/dpico/mapper/lessorequal_mapper.h | 37 - .../adapter/dpico/mapper/log_mapper.cc | 64 -- .../adapter/dpico/mapper/log_mapper.h | 37 - .../adapter/dpico/mapper/lrn_mapper.cc | 67 -- .../adapter/dpico/mapper/lrn_mapper.h | 37 - .../adapter/dpico/mapper/lstm_mapper.cc | 99 -- .../adapter/dpico/mapper/lstm_mapper.h | 37 - .../adapter/dpico/mapper/mat_mul_mapper.cc | 97 -- .../adapter/dpico/mapper/mat_mul_mapper.h | 36 - .../adapter/dpico/mapper/maxunpool_mapper.cc | 72 -- .../adapter/dpico/mapper/maxunpool_mapper.h | 37 - .../adapter/dpico/mapper/mish_mapper.cc | 51 - .../adapter/dpico/mapper/mish_mapper.h | 37 - .../adapter/dpico/mapper/mod_mapper.cc | 53 - .../adapter/dpico/mapper/mod_mapper.h | 37 - .../adapter/dpico/mapper/mvn_mapper.cc | 70 -- .../adapter/dpico/mapper/mvn_mapper.h | 37 - .../adapter/dpico/mapper/normalize_mapper.cc | 105 -- .../adapter/dpico/mapper/normalize_mapper.h | 37 - .../adapter/dpico/mapper/op_mapper.cc | 403 -------- .../adapter/dpico/mapper/op_mapper.h | 66 -- .../dpico/mapper/op_mapper_registry.cc | 37 - .../adapter/dpico/mapper/op_mapper_registry.h | 53 - .../adapter/dpico/mapper/pad_mapper.cc | 99 -- .../adapter/dpico/mapper/pad_mapper.h | 39 - .../dpico/mapper/passthrough_mapper.cc | 64 -- .../adapter/dpico/mapper/passthrough_mapper.h | 37 - .../adapter/dpico/mapper/permute_mapper.cc | 98 -- .../adapter/dpico/mapper/permute_mapper.h | 37 - .../adapter/dpico/mapper/pool_mapper.cc | 140 --- .../adapter/dpico/mapper/pool_mapper.h | 39 - .../adapter/dpico/mapper/power_mapper.cc | 81 -- .../adapter/dpico/mapper/power_mapper.h | 37 - .../adapter/dpico/mapper/prelu_mapper.cc | 90 -- .../adapter/dpico/mapper/prelu_mapper.h | 37 - .../adapter/dpico/mapper/psroi_pool_mapper.cc | 61 -- .../adapter/dpico/mapper/psroi_pool_mapper.h | 37 - .../adapter/dpico/mapper/reduction_mapper.cc | 136 --- .../adapter/dpico/mapper/reduction_mapper.h | 37 - .../adapter/dpico/mapper/reshape_mapper.cc | 101 -- .../adapter/dpico/mapper/reshape_mapper.h | 37 - .../adapter/dpico/mapper/resize_mapper.cc | 215 ---- .../adapter/dpico/mapper/resize_mapper.h | 37 - .../adapter/dpico/mapper/rnn_mapper.cc | 60 -- .../adapter/dpico/mapper/rnn_mapper.h | 37 - .../adapter/dpico/mapper/roi_pool_mapper.cc | 62 -- .../adapter/dpico/mapper/roi_pool_mapper.h | 37 - .../adapter/dpico/mapper/scale_mapper.cc | 114 -- .../adapter/dpico/mapper/scale_mapper.h | 37 - .../adapter/dpico/mapper/shape_mapper.cc | 50 - .../adapter/dpico/mapper/shape_mapper.h | 37 - .../adapter/dpico/mapper/shrink_mapper.cc | 53 - .../adapter/dpico/mapper/shrink_mapper.h | 37 - .../dpico/mapper/shuffle_channel_mapper.cc | 55 - .../dpico/mapper/shuffle_channel_mapper.h | 37 - .../adapter/dpico/mapper/sinh_mapper.cc | 47 - .../adapter/dpico/mapper/sinh_mapper.h | 37 - .../adapter/dpico/mapper/slice_mapper.cc | 116 --- .../adapter/dpico/mapper/slice_mapper.h | 36 - .../adapter/dpico/mapper/softmax_mapper.cc | 65 -- .../adapter/dpico/mapper/softmax_mapper.h | 37 - .../adapter/dpico/mapper/softsign_mapper.cc | 50 - .../adapter/dpico/mapper/softsign_mapper.h | 37 - .../adapter/dpico/mapper/sqrt_mapper.cc | 50 - .../adapter/dpico/mapper/sqrt_mapper.h | 37 - .../adapter/dpico/mapper/squeeze_mapper.cc | 65 -- .../adapter/dpico/mapper/squeeze_mapper.h | 37 - .../dpico/mapper/strided_slice_mapper.cc | 94 -- .../dpico/mapper/strided_slice_mapper.h | 36 - .../adapter/dpico/mapper/threshold_mapper.cc | 55 - .../adapter/dpico/mapper/threshold_mapper.h | 37 - .../adapter/dpico/mapper/tile_mapper.cc | 101 -- .../adapter/dpico/mapper/tile_mapper.h | 37 - .../adapter/dpico/mapper/unsqueeze_mapper.cc | 69 -- .../adapter/dpico/mapper/unsqueeze_mapper.h | 37 - .../adapter/dpico/mapper/upsample_mapper.cc | 66 -- .../adapter/dpico/mapper/upsample_mapper.h | 37 - .../adapter/dpico/mapper/xor_mapper.cc | 59 -- .../adapter/dpico/mapper/xor_mapper.h | 37 - .../dpico/parser/caffe/caffe_absval_parser.cc | 35 - .../dpico/parser/caffe/caffe_absval_parser.h | 36 - .../parser/caffe/caffe_activation_parser.cc | 124 --- .../parser/caffe/caffe_activation_parser.h | 76 -- .../dpico/parser/caffe/caffe_argmax_parser.cc | 49 - .../dpico/parser/caffe/caffe_argmax_parser.h | 36 - .../parser/caffe/caffe_batchnorm_parser.cc | 62 -- .../parser/caffe/caffe_batchnorm_parser.h | 36 - .../parser/caffe/caffe_bi_lstm_parser.cc | 49 - .../dpico/parser/caffe/caffe_bi_lstm_parser.h | 36 - .../dpico/parser/caffe/caffe_bias_parser.cc | 46 - .../dpico/parser/caffe/caffe_bias_parser.h | 36 - .../parser/caffe/caffe_binary_math_parser.cc | 91 -- .../parser/caffe/caffe_binary_math_parser.h | 36 - .../dpico/parser/caffe/caffe_bnll_parser.cc | 38 - .../dpico/parser/caffe/caffe_bnll_parser.h | 36 - .../dpico/parser/caffe/caffe_clip_parser.cc | 42 - .../dpico/parser/caffe/caffe_clip_parser.h | 35 - .../dpico/parser/caffe/caffe_concat_parser.cc | 54 - .../dpico/parser/caffe/caffe_concat_parser.h | 35 - .../parser/caffe/caffe_conv_base_parser.cc | 164 --- .../parser/caffe/caffe_conv_base_parser.h | 48 - .../parser/caffe/caffe_convolution_parser.cc | 116 --- .../parser/caffe/caffe_convolution_parser.h | 38 - .../dpico/parser/caffe/caffe_crop_parser.cc | 60 -- .../dpico/parser/caffe/caffe_crop_parser.h | 36 - .../dpico/parser/caffe/caffe_custom_parser.cc | 162 --- .../dpico/parser/caffe/caffe_custom_parser.h | 36 - .../parser/caffe/caffe_decbbox_parser.cc | 75 -- .../dpico/parser/caffe/caffe_decbbox_parser.h | 35 - .../caffe/caffe_deconvolution_parser.cc | 116 --- .../parser/caffe/caffe_deconvolution_parser.h | 35 - .../caffe/caffe_depthwise_conv_parser.cc | 35 - .../caffe/caffe_depthwise_conv_parser.h | 35 - .../caffe/caffe_detection_output_parser.cc | 62 -- .../caffe/caffe_detection_output_parser.h | 37 - .../parser/caffe/caffe_eltwise_parser.cc | 113 -- .../dpico/parser/caffe/caffe_eltwise_parser.h | 35 - .../dpico/parser/caffe/caffe_exp_parser.cc | 52 - .../dpico/parser/caffe/caffe_exp_parser.h | 36 - .../parser/caffe/caffe_extract_parser.cc | 121 --- .../dpico/parser/caffe/caffe_extract_parser.h | 36 - .../parser/caffe/caffe_flatten_parser.cc | 45 - .../dpico/parser/caffe/caffe_flatten_parser.h | 34 - .../dpico/parser/caffe/caffe_gru_parser.cc | 61 -- .../dpico/parser/caffe/caffe_gru_parser.h | 36 - .../parser/caffe/caffe_innerproduct_parser.cc | 102 -- .../parser/caffe/caffe_innerproduct_parser.h | 36 - .../dpico/parser/caffe/caffe_inspector.cc | 90 -- .../dpico/parser/caffe/caffe_inspector.h | 57 - .../dpico/parser/caffe/caffe_interp_parser.cc | 76 -- .../dpico/parser/caffe/caffe_interp_parser.h | 36 - .../dpico/parser/caffe/caffe_log_parser.cc | 51 - .../dpico/parser/caffe/caffe_log_parser.h | 36 - .../dpico/parser/caffe/caffe_lrn_parser.cc | 78 -- .../dpico/parser/caffe/caffe_lrn_parser.h | 36 - .../dpico/parser/caffe/caffe_lstm_parser.cc | 59 -- .../dpico/parser/caffe/caffe_lstm_parser.h | 36 - .../dpico/parser/caffe/caffe_matmul_parser.cc | 49 - .../dpico/parser/caffe/caffe_matmul_parser.h | 36 - .../dpico/parser/caffe/caffe_mish_parser.cc | 38 - .../dpico/parser/caffe/caffe_mish_parser.h | 36 - .../dpico/parser/caffe/caffe_model_parser.cc | 587 ----------- .../dpico/parser/caffe/caffe_model_parser.h | 67 -- .../dpico/parser/caffe/caffe_mvn_parser.cc | 52 - .../dpico/parser/caffe/caffe_mvn_parser.h | 36 - .../dpico/parser/caffe/caffe_node_parser.cc | 42 - .../dpico/parser/caffe/caffe_node_parser.h | 55 - .../caffe/caffe_node_parser_registry.cc | 45 - .../parser/caffe/caffe_node_parser_registry.h | 47 - .../dpico/parser/caffe/caffe_nop_parser.cc | 38 - .../dpico/parser/caffe/caffe_nop_parser.h | 36 - .../parser/caffe/caffe_normalize_parser.cc | 55 - .../parser/caffe/caffe_normalize_parser.h | 36 - .../parser/caffe/caffe_pass_through_parser.cc | 82 -- .../parser/caffe/caffe_pass_through_parser.h | 36 - .../parser/caffe/caffe_permute_parser.cc | 44 - .../dpico/parser/caffe/caffe_permute_parser.h | 36 - .../parser/caffe/caffe_pooling_parser.cc | 175 ---- .../dpico/parser/caffe/caffe_pooling_parser.h | 45 - .../dpico/parser/caffe/caffe_power_parser.cc | 55 - .../dpico/parser/caffe/caffe_power_parser.h | 36 - .../dpico/parser/caffe/caffe_prelu_parser.cc | 41 - .../dpico/parser/caffe/caffe_prelu_parser.h | 36 - .../caffe/caffe_psroi_pooling_parser.cc | 83 -- .../parser/caffe/caffe_psroi_pooling_parser.h | 36 - .../dpico/parser/caffe/caffe_reduce_parser.cc | 71 -- .../dpico/parser/caffe/caffe_reduce_parser.h | 36 - .../parser/caffe/caffe_reshape_parser.cc | 56 - .../dpico/parser/caffe/caffe_reshape_parser.h | 36 - .../parser/caffe/caffe_reverse_parser.cc | 41 - .../dpico/parser/caffe/caffe_reverse_parser.h | 36 - .../dpico/parser/caffe/caffe_rnn_parser.cc | 56 - .../dpico/parser/caffe/caffe_rnn_parser.h | 36 - .../parser/caffe/caffe_roi_pooling_parser.cc | 47 - .../parser/caffe/caffe_roi_pooling_parser.h | 36 - .../dpico/parser/caffe/caffe_scale_parser.cc | 78 -- .../dpico/parser/caffe/caffe_scale_parser.h | 39 - .../caffe/caffe_shuffle_channel_parser.cc | 46 - .../caffe/caffe_shuffle_channel_parser.h | 36 - .../dpico/parser/caffe/caffe_slice_parser.cc | 61 -- .../dpico/parser/caffe/caffe_slice_parser.h | 36 - .../parser/caffe/caffe_softmax_parser.cc | 43 - .../dpico/parser/caffe/caffe_softmax_parser.h | 36 - .../dpico/parser/caffe/caffe_spp_parser.cc | 66 -- .../dpico/parser/caffe/caffe_spp_parser.h | 36 - .../parser/caffe/caffe_threshold_parser.cc | 45 - .../parser/caffe/caffe_threshold_parser.h | 36 - .../dpico/parser/caffe/caffe_tile_parser.cc | 55 - .../dpico/parser/caffe/caffe_tile_parser.h | 36 - .../parser/caffe/caffe_upsample_parser.cc | 99 -- .../parser/caffe/caffe_upsample_parser.h | 36 - .../dpico/parser/caffe/inputs_adjust.cc | 158 --- .../dpico/parser/caffe/inputs_adjust.h | 39 - .../parser/detection_output_param_helper.cc | 264 ----- .../parser/detection_output_param_helper.h | 36 - .../dpico/parser/onnx/onnx_acos_parser.cc | 43 - .../dpico/parser/onnx/onnx_acos_parser.h | 37 - .../dpico/parser/onnx/onnx_acosh_parser.cc | 43 - .../dpico/parser/onnx/onnx_acosh_parser.h | 37 - .../dpico/parser/onnx/onnx_asinh_parser.cc | 43 - .../dpico/parser/onnx/onnx_asinh_parser.h | 37 - .../dpico/parser/onnx/onnx_atanh_parser.cc | 43 - .../dpico/parser/onnx/onnx_atanh_parser.h | 37 - .../dpico/parser/onnx/onnx_bitshift_parser.cc | 52 - .../dpico/parser/onnx/onnx_bitshift_parser.h | 37 - .../dpico/parser/onnx/onnx_cosh_parser.cc | 43 - .../dpico/parser/onnx/onnx_cosh_parser.h | 37 - .../dpico/parser/onnx/onnx_hardmax_parser.cc | 56 - .../dpico/parser/onnx/onnx_hardmax_parser.h | 37 - .../parser/onnx/onnx_hardsigmoid_parser.cc | 56 - .../parser/onnx/onnx_hardsigmoid_parser.h | 37 - .../dpico/parser/onnx/onnx_lstm_parser.cc | 87 -- .../dpico/parser/onnx/onnx_lstm_parser.h | 37 - .../parser/onnx/onnx_maxunpool_parser.cc | 103 -- .../dpico/parser/onnx/onnx_maxunpool_parser.h | 37 - .../dpico/parser/onnx/onnx_mish_parser.cc | 43 - .../dpico/parser/onnx/onnx_mish_parser.h | 37 - .../dpico/parser/onnx/onnx_mod_parser.cc | 51 - .../dpico/parser/onnx/onnx_mod_parser.h | 37 - .../parser/onnx/onnx_roi_align_parser.cc | 90 -- .../dpico/parser/onnx/onnx_roi_align_parser.h | 36 - .../dpico/parser/onnx/onnx_shrink_parser.cc | 55 - .../dpico/parser/onnx/onnx_shrink_parser.h | 37 - .../dpico/parser/onnx/onnx_sinh_parser.cc | 43 - .../dpico/parser/onnx/onnx_sinh_parser.h | 37 - .../dpico/parser/onnx/onnx_softsign_parser.cc | 43 - .../dpico/parser/onnx/onnx_softsign_parser.h | 37 - .../dpico/parser/onnx/onnx_xor_parser.cc | 43 - .../dpico/parser/onnx/onnx_xor_parser.h | 37 - .../adapter/dpico/parser/parser_utils.cc | 411 -------- .../adapter/dpico/parser/parser_utils.h | 46 - .../adapter/dpico/parser/unify_format.cc | 288 ------ .../adapter/dpico/parser/unify_format.h | 54 - .../adapter/dpico/src/calib_data_generator.cc | 312 ------ .../adapter/dpico/src/calib_data_generator.h | 162 --- .../adapter/dpico/src/custom_creator.cc | 466 --------- .../adapter/dpico/src/custom_creator.h | 67 -- .../adapter/dpico/src/data_preprocessor.cc | 358 ------- .../adapter/dpico/src/data_preprocessor.h | 139 --- .../converter/adapter/dpico/src/dpico_pass.cc | 564 ---------- .../converter/adapter/dpico/src/dpico_pass.h | 62 -- .../dpico/src/dpico_preprocess_pass.cc | 222 ---- .../adapter/dpico/src/dpico_preprocess_pass.h | 46 - .../adapter/dpico/src/graph_split_api.cc | 395 ------- .../adapter/dpico/src/graph_split_api.h | 36 - .../adapter/dpico/src/graph_split_info.h | 50 - .../adapter/dpico/src/mapper_config_parser.cc | 377 ------- .../adapter/dpico/src/mapper_config_parser.h | 92 -- .../adapter/dpico/src/om_generator.cc | 391 ------- .../adapter/dpico/src/om_generator.h | 49 - .../providers/NNIE/Hi3516D/compile_nnie.sh | 124 --- 493 files changed, 38121 deletions(-) delete mode 100644 mindspore-lite/providers/dpico/CMakeLists.txt delete mode 100644 mindspore-lite/providers/dpico/common/check_base.h delete mode 100644 mindspore-lite/providers/dpico/common/custom_enum.h delete mode 100644 mindspore-lite/providers/dpico/common/infer_util.cc delete mode 100644 mindspore-lite/providers/dpico/common/infer_util.h delete mode 100644 mindspore-lite/providers/dpico/common/log_util.cc delete mode 100644 mindspore-lite/providers/dpico/common/log_util.h delete mode 100644 mindspore-lite/providers/dpico/common/op_attr.h delete mode 100644 mindspore-lite/providers/dpico/common/string_util.cc delete mode 100644 mindspore-lite/providers/dpico/common/string_util.h delete mode 100644 mindspore-lite/providers/dpico/infer/custom_infer.cc delete mode 100644 mindspore-lite/providers/dpico/infer/custom_infer.h delete mode 100644 mindspore-lite/providers/dpico/manager/acl_buf_manager.cc delete mode 100644 mindspore-lite/providers/dpico/manager/acl_buf_manager.h delete mode 100644 mindspore-lite/providers/dpico/manager/acl_context_manager.cc delete mode 100644 mindspore-lite/providers/dpico/manager/acl_context_manager.h delete mode 100644 mindspore-lite/providers/dpico/manager/acl_model_helper.cc delete mode 100644 mindspore-lite/providers/dpico/manager/acl_model_helper.h delete mode 100644 mindspore-lite/providers/dpico/manager/acl_model_manager.cc delete mode 100644 mindspore-lite/providers/dpico/manager/acl_model_manager.h delete mode 100644 mindspore-lite/providers/dpico/manager/custom_config_manager.cc delete mode 100644 mindspore-lite/providers/dpico/manager/custom_config_manager.h delete mode 100644 mindspore-lite/providers/dpico/src/custom_allocator.cc delete mode 100644 mindspore-lite/providers/dpico/src/custom_allocator.h delete mode 100644 mindspore-lite/providers/dpico/src/custom_fp32.cc delete mode 100644 mindspore-lite/providers/dpico/src/custom_fp32.h delete mode 100644 mindspore-lite/providers/nnie/CMakeLists.txt delete mode 100644 mindspore-lite/providers/nnie/src/custom_allocator.h delete mode 100644 mindspore-lite/providers/nnie/src/custom_fp32.cc delete mode 100644 mindspore-lite/providers/nnie/src/custom_fp32.h delete mode 100644 mindspore-lite/providers/nnie/src/custom_infer.cc delete mode 100644 mindspore-lite/providers/nnie/src/custom_infer.h delete mode 100644 mindspore-lite/providers/nnie/src/nnie_cfg_parser.cc delete mode 100644 mindspore-lite/providers/nnie/src/nnie_cfg_parser.h delete mode 100644 mindspore-lite/providers/nnie/src/nnie_common.cc delete mode 100644 mindspore-lite/providers/nnie/src/nnie_common.h delete mode 100644 mindspore-lite/providers/nnie/src/nnie_manager.cc delete mode 100644 mindspore-lite/providers/nnie/src/nnie_manager.h delete mode 100644 mindspore-lite/providers/nnie/src/nnie_memory.cc delete mode 100644 mindspore-lite/providers/nnie/src/nnie_memory.h delete mode 100644 mindspore-lite/providers/nnie/src/nnie_print.cc delete mode 100644 mindspore-lite/providers/nnie/src/nnie_print.h delete mode 100644 mindspore-lite/providers/nnie_proposal/CMakeLists.txt delete mode 100644 mindspore-lite/providers/nnie_proposal/src/proposal.cc delete mode 100644 mindspore-lite/providers/nnie_proposal/src/proposal.h delete mode 100644 mindspore-lite/providers/nnie_proposal/src/proposal_fp32.cc delete mode 100644 mindspore-lite/providers/nnie_proposal/src/proposal_fp32.h delete mode 100644 mindspore-lite/providers/nnie_proposal/src/proposal_infer.cc delete mode 100644 mindspore-lite/providers/nnie_proposal/src/proposal_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/CMakeLists.txt delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/OWNERS delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/anf_util.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/anf_util.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/check_base.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/file_util.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/file_util.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/float16.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/format_utils.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/format_utils.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.cc delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/infer_util.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/infer_util.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/op_attr.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/op_enum.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/string_util.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/common/string_util.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.h delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.cc delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.h delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.cc delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.h delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.cc delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.h delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.cc delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.h delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.cc delete mode 100755 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/graph_split_info.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.h delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/om_generator.cc delete mode 100644 mindspore-lite/tools/converter/adapter/dpico/src/om_generator.h delete mode 100644 mindspore-lite/tools/providers/NNIE/Hi3516D/compile_nnie.sh diff --git a/mindspore-lite/providers/dpico/CMakeLists.txt b/mindspore-lite/providers/dpico/CMakeLists.txt deleted file mode 100644 index 63a2b029..00000000 --- a/mindspore-lite/providers/dpico/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -cmake_minimum_required(VERSION 3.12) -project(DPICO_Custom) - -if(DEFINED ENV{HISI_SDK_PATH}) - set(SD3403_SDK_PATH $ENV{HISI_SDK_PATH}/sd3403_sdk/dpico_acl_adapter/3403_sdk_0924) -else() - message(FATAL_ERROR "error, no sdk found") -endif() - -include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${SD3403_SDK_PATH}) -include_directories(${SD3403_SDK_PATH}/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime/include/third_party) -link_directories(${SD3403_SDK_PATH}/lib) - -set(DEPENDENCY_LIBS - ${SD3403_SDK_PATH}/lib/libsvp_acl.so - ${SD3403_SDK_PATH}/lib/libprotobuf-c.so.1 - ${SD3403_SDK_PATH}/lib/libsecurec.so) - -file(GLOB_RECURSE DPICO_RUNTIME_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/common/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/infer/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/manager/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/../../src/litert/cxx_api/kernel.cc - ${CMAKE_CURRENT_SOURCE_DIR}/../../src/registry/kernel_interface_registry.cc - ) - -add_library(dpico_acl_adapter SHARED ${DPICO_RUNTIME_SRC}) -target_link_libraries(dpico_acl_adapter ${DEPENDENCY_LIBS}) diff --git a/mindspore-lite/providers/dpico/common/check_base.h b/mindspore-lite/providers/dpico/common/check_base.h deleted file mode 100644 index 034d08fd..00000000 --- a/mindspore-lite/providers/dpico/common/check_base.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_COMMON_CHECK_BASE_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_CHECK_BASE_H_ - -#include -#include "common/log_util.h" - -#define UP_DIV(x, y) (((x) + (y) - (1)) / (y)) -#define UP_ROUND(x, y) (((x) + (y) - (1)) / (y) * (y)) -#define DOWN_DIV(x, y) ((x) / (y)) -#define DOWN_ROUND(x, y) ((x) / (y) * (y)) - -#define kNHWC_N 0 -#define kNHWC_H 1 -#define kNHWC_W 2 -#define kNHWC_C 3 -#define kNCHW_N 0 -#define kNCHW_C 1 -#define kNCHW_H 2 -#define kNCHW_W 3 -#define kInputSize1 1 -#define kInputSize2 2 -#define kInputSize3 3 -#ifdef Debug -#include -#define MS_ASSERT(f) assert(f) -#else -#define MS_ASSERT(f) ((void)0) -#endif - -#define SIZE_MUL_OVERFLOW(x, y) (((x) == 0) ? false : (SIZE_MAX / (x)) < (y)) -#define INT_MUL_OVERFLOW(x, y) \ - (((x) == 0) ? false \ - : ((x) > 0 ? (((y) >= 0) ? (INT_MAX / (x)) < (y) : (INT_MAX / (x)) < (-1 * (y))) \ - : (((y) >= 0) ? (INT_MAX / (x)) > (-1 * (y)) : (INT_MAX / (x)) > (y)))) - -#define INT_MUL_OVERFLOW_THRESHOLD(x, y, threshold) \ - (((x) == 0) ? false \ - : ((x) > 0 ? (((y) >= 0) ? ((threshold) / (x)) < (y) : ((threshold) / (x)) < (-1 * (y))) \ - : (((y) >= 0) ? ((threshold) / (x)) > (-1 * (y)) : ((threshold) / (x)) > (y)))) - -#define INT_ADD_OVERFLOW(x, y) (INT_MAX - (x)) < (y) - -#define CHECK_LESS_RETURN(size1, size2) \ - do { \ - if ((size1) < (size2)) { \ - MS_LOG(ERROR) << #size1 << " must not be less than " << #size2; \ - return mindspore::lite::RET_ERROR; \ - } \ - } while (0) - -// Check whether value is true, if not return 'errcode' -// and print error string msg -#define MS_CHECK_TRUE_MSG(value, errcode, msg) \ - do { \ - if (!(value)) { \ - MS_LOG(ERROR) << msg; \ - return errcode; \ - } \ - } while (0) - -// Check whether value is true, if not return void -// and print error string msg -#define MS_CHECK_TRUE_MSG_VOID(value, msg) \ - do { \ - if (!(value)) { \ - MS_LOG(ERROR) << msg; \ - return; \ - } \ - } while (0) - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_CHECK_BASE_H_ diff --git a/mindspore-lite/providers/dpico/common/custom_enum.h b/mindspore-lite/providers/dpico/common/custom_enum.h deleted file mode 100644 index 70fb932c..00000000 --- a/mindspore-lite/providers/dpico/common/custom_enum.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_COMMON_CUSTOM_ENUM_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_CUSTOM_ENUM_H_ - -namespace mindspore { -namespace lite { -enum AclModelType : size_t { kCnn = 0, kRoi = 1, kRecurrent = 2 }; -enum DetectParam : size_t { kNmsThreshold = 0, kScoreThreshold = 1, kMinHeight = 2, kMinWidth = 3 }; -enum DetectBoxParam : size_t { - kTopLeftX = 0, - kDetectBoxParamBegin = kTopLeftX, - kTopLeftY = 1, - kBottomRightX = 2, - kBottomRightY = 3, - kScore = 4, - kClassId = 5, - kDetectBoxParamEnd -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_CUSTOM_ENUM_H_ diff --git a/mindspore-lite/providers/dpico/common/infer_util.cc b/mindspore-lite/providers/dpico/common/infer_util.cc deleted file mode 100644 index 5326012a..00000000 --- a/mindspore-lite/providers/dpico/common/infer_util.cc +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Copyright 2022 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 "common/infer_util.h" -#include -#include -#include "common/log_util.h" -#include "include/errorcode.h" -#include "include/svp_acl_rt.h" -#include "include/svp_acl.h" -#include "include/svp_acl_ext.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace lite { -static bool kThreadRunning = true; - -Status FetchAttrs(const schema::Primitive &primitive, std::map *attrs) { - if (attrs == nullptr) { - MS_LOG(ERROR) << "function input parameter is nullptr."; - return kLiteError; - } - auto param = primitive.value_as_Custom(); - if (lite::CheckCustomParam(param, "DPICO") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param attr is nullptr."; - return kLiteError; - } - if (param->attr()->size() < 1) { - MS_LOG(ERROR) << "There are at least 1 attribute of Custom"; - return kLiteError; - } - for (size_t i = 0; i < param->attr()->size(); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - auto output_info = param->attr()->Get(i)->data(); - if (output_info == nullptr) { - MS_LOG(ERROR) << "output_info is nullptr"; - return kLiteError; - } - int buf_size = static_cast(output_info->size()); - std::string attr; - for (int j = 0; j < buf_size; j++) { - attr.push_back(static_cast(output_info->Get(j))); - } - auto attr_name = param->attr()->Get(i)->name()->str(); - attrs->emplace(attr_name, attr); - } - return kSuccess; -} - -int CheckCustomInputOutput(const std::vector *inputs, - const std::vector *outputs, const schema::Primitive *primitive) { - if (inputs == nullptr) { - MS_LOG(ERROR) << "inputs is nullptr."; - return RET_ERROR; - } - if (outputs == nullptr) { - MS_LOG(ERROR) << "outputs is nullptr."; - return RET_ERROR; - } - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr."; - return RET_ERROR; - } - if (inputs->empty()) { - MS_LOG(ERROR) << "Inputs size 0."; - return RET_ERROR; - } - if (outputs->empty()) { - MS_LOG(ERROR) << "Outputs size 0."; - return RET_ERROR; - } - if (primitive->value_type() != schema::PrimitiveType_Custom) { - MS_LOG(ERROR) << "Primitive type is not PrimitiveType_Custom."; - return RET_ERROR; - } - return RET_OK; -} - -int CheckCustomParam(const schema::Custom *param, const std::string ¶m_name) { - if (param == nullptr) { - MS_LOG(ERROR) << "param is nullptr"; - return RET_ERROR; - } - if (param->type() == nullptr) { - MS_LOG(ERROR) << "param->type() is nullptr"; - return RET_ERROR; - } - if (param->type()->str() != param_name) { - MS_LOG(ERROR) << "current custom node should be " << param_name << ", but in fact it's " << param->type()->str(); - return RET_ERROR; - } - return RET_OK; -} - -void AicpuThread() { - MS_LOG(INFO) << "create aicpu thread success"; - while (kThreadRunning) { - svp_acl_error ret = svp_acl_ext_process_aicpu_task(1000); // 1000 ms - if (ret != SVP_ACL_SUCCESS && ret != SVP_ACL_ERROR_RT_REPORT_TIMEOUT) { - MS_LOG(ERROR) << "create aicpu thread failed!"; - break; - } - } - MS_LOG(INFO) << "end to destroy aicpu thread"; -} - -int DpicoAicpuThreadManager::CreateAicpuThread(uint32_t model_id) { - uint32_t aicpu_task_num = 0; - svp_acl_ext_get_mdl_aicpu_task_num(model_id, &aicpu_task_num); - all_aicpu_task_num_ += aicpu_task_num; - if (all_aicpu_task_num_ > 0 && !is_aicpu_thread_activity_) { - g_threadExitFlag_ = true; - kThreadRunning = g_threadExitFlag_; - aicpu_thread_ = std::thread(AicpuThread); - is_aicpu_thread_activity_ = true; - } - return RET_OK; -} - -int DpicoAicpuThreadManager::DestroyAicpuThread() { - if (all_aicpu_task_num_ > 0 && is_aicpu_thread_activity_) { - g_threadExitFlag_ = false; - kThreadRunning = g_threadExitFlag_; - if (aicpu_thread_.joinable()) { - aicpu_thread_.join(); - } - all_aicpu_task_num_ = 0; - is_aicpu_thread_activity_ = false; - } - return RET_OK; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/common/infer_util.h b/mindspore-lite/providers/dpico/common/infer_util.h deleted file mode 100644 index 81f4cb6b..00000000 --- a/mindspore-lite/providers/dpico/common/infer_util.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_COMMON_INFER_UTIL_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_INFER_UTIL_H_ - -#include -#include -#include -#include -#include "include/api/status.h" -#include "include/api/types.h" -#include "schema/model_generated.h" - -namespace mindspore { -namespace lite { -Status FetchAttrs(const schema::Primitive &primitive, std::map *attrs); -int CheckCustomInputOutput(const std::vector *inputs, - const std::vector *outputs, const schema::Primitive *primitive); -int CheckCustomParam(const schema::Custom *param, const std::string ¶m_name); -class DpicoAicpuThreadManager { - public: - DpicoAicpuThreadManager() = default; - ~DpicoAicpuThreadManager() = default; - int CreateAicpuThread(uint32_t model_id); - int DestroyAicpuThread(); - bool g_threadExitFlag_{true}; - - private: - uint32_t all_aicpu_task_num_{0}; - bool is_aicpu_thread_activity_{false}; - std::thread aicpu_thread_; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_INFER_UTIL_H_ diff --git a/mindspore-lite/providers/dpico/common/log_util.cc b/mindspore-lite/providers/dpico/common/log_util.cc deleted file mode 100644 index aba00a4c..00000000 --- a/mindspore-lite/providers/dpico/common/log_util.cc +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2021-2022 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 "common/log_util.h" -#include -#include -namespace mindspore { -int StrToInt(const char *env) { - if (env == nullptr) { - return static_cast(mindspore::DpicoLogLevel::WARNING); - } - if (strcmp(env, "0") == 0) { - return static_cast(mindspore::DpicoLogLevel::DEBUG); - } - if (strcmp(env, "1") == 0) { - return static_cast(mindspore::DpicoLogLevel::INFO); - } - if (strcmp(env, "2") == 0) { - return static_cast(mindspore::DpicoLogLevel::WARNING); - } - if (strcmp(env, "3") == 0) { - return static_cast(mindspore::DpicoLogLevel::ERROR); - } - return static_cast(mindspore::DpicoLogLevel::WARNING); -} - -bool IsPrint(int level) { - static const char *const env = std::getenv("GLOG_v"); - static const int ms_level = StrToInt(env); - if (level < 0) { - level = static_cast(mindspore::DpicoLogLevel::WARNING); - } - return level >= ms_level; -} - -const char *EnumStrForMsLogLevel(DpicoLogLevel level) { - if (level == DpicoLogLevel::DEBUG) { - return "DEBUG"; - } else if (level == DpicoLogLevel::INFO) { - return "INFO"; - } else if (level == DpicoLogLevel::WARNING) { - return "WARNING"; - } else if (level == DpicoLogLevel::ERROR) { - return "ERROR"; - } else { - return "NO_LEVEL"; - } -} - -void DpicoLogWriter::OutputLog(const std::ostringstream &msg) const { - if (IsPrint(static_cast(log_level_))) { - printf("%s [%s:%d] %s] %s\n", EnumStrForMsLogLevel(log_level_), location_.file_, location_.line_, location_.func_, - msg.str().c_str()); - } -} - -void DpicoLogWriter::operator<(const DpicoLogStream &stream) const noexcept { - std::ostringstream msg; - msg << stream.sstream_->rdbuf(); - OutputLog(msg); -} -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/common/log_util.h b/mindspore-lite/providers/dpico/common/log_util.h deleted file mode 100644 index be234231..00000000 --- a/mindspore-lite/providers/dpico/common/log_util.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2021-2022 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_PROVIDERS_DPICO_COMMON_LOG_UTIL_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_LOG_UTIL_H_ - -#include -#include - -// NOTICE: when relative path of 'log.h' changed, macro 'DPICO_LOG_HEAR_FILE_REL_PATH' must be changed -#define DPICO_LOG_HEAR_FILE_REL_PATH "mindspore-lite/providers/dpico/common/log_util.h" - -// Get start index of file relative path in __FILE__ -static constexpr size_t GetRealPathPos() noexcept { - return sizeof(__FILE__) > sizeof(DPICO_LOG_HEAR_FILE_REL_PATH) - ? sizeof(__FILE__) - sizeof(DPICO_LOG_HEAR_FILE_REL_PATH) - : 0; -} - -namespace mindspore { -#define DPICO_FILE_NAME \ - (sizeof(__FILE__) > GetRealPathPos() ? static_cast(__FILE__) + GetRealPathPos() \ - : static_cast(__FILE__)) - -struct DpicoLocationInfo { - DpicoLocationInfo(const char *file, int line, const char *func) : file_(file), line_(line), func_(func) {} - - ~DpicoLocationInfo() = default; - - const char *file_; - int line_; - const char *func_; -}; - -class DpicoLogStream { - public: - DpicoLogStream() { sstream_ = std::make_shared(); } - - ~DpicoLogStream() = default; - - template - DpicoLogStream &operator<<(const T &val) noexcept { - (*sstream_) << val; - return *this; - } - - DpicoLogStream &operator<<(std::ostream &func(std::ostream &os)) noexcept { - (*sstream_) << func; - return *this; - } - friend class DpicoLogWriter; - - private: - std::shared_ptr sstream_; -}; - -enum class DpicoLogLevel : int { DEBUG = 0, INFO, WARNING, ERROR }; - -class DpicoLogWriter { - public: - DpicoLogWriter(const DpicoLocationInfo &location, mindspore::DpicoLogLevel log_level) - : location_(location), log_level_(log_level) {} - - ~DpicoLogWriter() = default; - - __attribute__((visibility("default"))) void operator<(const DpicoLogStream &stream) const noexcept; - - private: - void OutputLog(const std::ostringstream &msg) const; - - DpicoLocationInfo location_; - DpicoLogLevel log_level_; -}; - -#define MSLOG_IF(level) \ - mindspore::DpicoLogWriter(mindspore::DpicoLocationInfo(DPICO_FILE_NAME, __LINE__, __FUNCTION__), level) < \ - mindspore::DpicoLogStream() - -#define MS_LOG(level) MS_LOG_##level - -#define MS_LOG_DEBUG MSLOG_IF(mindspore::DpicoLogLevel::DEBUG) -#define MS_LOG_INFO MSLOG_IF(mindspore::DpicoLogLevel::INFO) -#define MS_LOG_WARNING MSLOG_IF(mindspore::DpicoLogLevel::WARNING) -#define MS_LOG_ERROR MSLOG_IF(mindspore::DpicoLogLevel::ERROR) -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_LOG_UTIL_H_ diff --git a/mindspore-lite/providers/dpico/common/op_attr.h b/mindspore-lite/providers/dpico/common/op_attr.h deleted file mode 100644 index a7e43e30..00000000 --- a/mindspore-lite/providers/dpico/common/op_attr.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_COMMON_OP_ATTR_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_OP_ATTR_H_ - -namespace mindspore { -constexpr auto kAclConfigPath = "AclConfigPath"; -constexpr auto kLastDimStride = "internal_stride"; -constexpr auto kSupportZeroCopy = "SupportZeroCopy"; -constexpr auto kDetectionPostProcess = "DetectionPostProcess"; -constexpr auto kDpico = "dpico"; -constexpr auto kInputsShape = "inputs_shape"; -constexpr auto kGTotalT = "GTotalT"; -constexpr auto kMaxRoiNum = "MaxRoiNum"; -constexpr auto kMinHeight = "MinHeight"; -constexpr auto kMinWidth = "MinWidth"; -constexpr auto kModelSharingKey = "multi_model_sharing_mem"; -constexpr auto kModelSharingPrepareKey = "multi_model_sharing_mem_prepare"; -constexpr auto kModelSharingSection = "common"; -constexpr auto kNetType = "net_type"; -constexpr auto kNmsThreshold = "NmsThreshold"; -constexpr auto kOutputsFormat = "outputs_format"; -constexpr auto kOutputsShape = "outputs_shape"; -constexpr auto kScoreThreshold = "ScoreThreshold"; -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_OP_ATTR_H_ diff --git a/mindspore-lite/providers/dpico/common/string_util.cc b/mindspore-lite/providers/dpico/common/string_util.cc deleted file mode 100644 index 7c6ca0d6..00000000 --- a/mindspore-lite/providers/dpico/common/string_util.cc +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2022 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 "common/string_util.h" -#include -#include -#include -#include "common/log_util.h" - -namespace mindspore { -namespace lite { -std::vector SplitString(const std::string &raw_str, char delimiter) { - if (raw_str.empty()) { - MS_LOG(ERROR) << "input string is empty."; - return {}; - } - std::vector res; - std::string::size_type last_pos = 0; - auto cur_pos = raw_str.find(delimiter); - while (cur_pos != std::string::npos) { - res.push_back(raw_str.substr(last_pos, cur_pos - last_pos)); - cur_pos++; - last_pos = cur_pos; - cur_pos = raw_str.find(delimiter, cur_pos); - } - if (last_pos < raw_str.size()) { - res.push_back(raw_str.substr(last_pos, raw_str.size() - last_pos + 1)); - } - return res; -} - -bool IsValidUnsignedNum(const std::string &num_str) { - return !num_str.empty() && std::all_of(num_str.begin(), num_str.end(), ::isdigit); -} - -bool IsValidDoubleNum(const std::string &num_str) { - if (num_str.empty()) { - return false; - } - std::istringstream iss(num_str); - double d; - iss >> std::noskipws >> d; - return iss.eof() && !iss.fail(); -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/common/string_util.h b/mindspore-lite/providers/dpico/common/string_util.h deleted file mode 100644 index 6fbbc3b6..00000000 --- a/mindspore-lite/providers/dpico/common/string_util.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_COMMON_STRING_UTIL_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_STRING_UTIL_H_ - -#include -#include -#include -#include -#include "include/errorcode.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace lite { -std::vector SplitString(const std::string &raw_str, char delimiter); -bool IsValidUnsignedNum(const std::string &num_str); -bool IsValidDoubleNum(const std::string &num_str); -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_COMMON_STRING_UTIL_H_ diff --git a/mindspore-lite/providers/dpico/infer/custom_infer.cc b/mindspore-lite/providers/dpico/infer/custom_infer.cc deleted file mode 100644 index 0cb655d6..00000000 --- a/mindspore-lite/providers/dpico/infer/custom_infer.cc +++ /dev/null @@ -1,217 +0,0 @@ -/** - * Copyright 2021-2022 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 "infer/custom_infer.h" -#include -#include -#include -#include -#include "manager/acl_model_helper.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" -#include "common/log_util.h" -#include "common/op_attr.h" -#include "common/string_util.h" -#include "common/infer_util.h" - -using mindspore::dpico::CustomInterface; -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kOmParameterNum = 1; -Status GetCustomShape(const std::map &attrs, const std::string &attr_name, size_t tensor_num, - std::vector> *shapes) { - if (shapes == nullptr) { - MS_LOG(ERROR) << "the function input parameter is nullptr."; - return kLiteError; - } - if (attrs.find(attr_name) == attrs.end()) { - MS_LOG(ERROR) << "custom node should have " << attr_name << " val."; - return kLiteError; - } - auto attr = attrs.at(attr_name); - if (attr.empty()) { - MS_LOG(ERROR) << "custom node should have " << attr_name << " val."; - return kLiteError; - } - auto split_shape_str = lite::SplitString(attr, ','); - size_t index = 0; - for (size_t i = 0; i < split_shape_str.size(); i++) { - auto dim_size = std::stoul(split_shape_str.at(i)); - std::vector shape; - for (size_t j = i + 1; j < i + 1 + dim_size; j++) { - if (j >= split_shape_str.size()) { - MS_LOG(ERROR) << "split_shape_str val is invalid. "; - return kLiteError; - } - shape.push_back(std::stoul(split_shape_str.at(j))); - } - i += dim_size; - if (tensor_num <= index) { - MS_LOG(ERROR) << "shape index " << index << " is greater than custom tensor_num " << tensor_num; - return kLiteError; - } - shapes->push_back(shape); - index++; - } - return kSuccess; -} - -Status SetOutputFormat(const std::map &attrs, std::vector *outputs) { - if (outputs == nullptr) { - MS_LOG(ERROR) << "the function input parameter is nullptr."; - return kLiteError; - } - if (attrs.find(kOutputsFormat) == attrs.end()) { - MS_LOG(ERROR) << "custom node should have " << kOutputsFormat << " val."; - return kLiteError; - } - auto output_format_str = attrs.at(kOutputsFormat); - auto output_format = lite::SplitString(output_format_str, ','); - if (output_format.size() == 0) { - MS_LOG(ERROR) << "output format size is 0."; - return kLiteError; - } - if (output_format.size() > outputs->size()) { - MS_LOG(ERROR) << "output format attr is invalid, the number of which is out of range."; - return kLiteError; - } - for (size_t i = 0; i < output_format.size(); ++i) { - if (!lite::IsValidUnsignedNum(output_format[i])) { - MS_LOG(ERROR) << "output format must be an unsigned int"; - return kLiteError; - } - auto format = std::stoi(output_format[i]); - if (format != NHWC && format != NCHW) { - MS_LOG(ERROR) << "output format is invalid, which should be NHWC or NCHW."; - return kLiteError; - } - outputs->at(i).SetFormat(static_cast(format)); - } - return kSuccess; -} - -bool InferDone(const std::vector &tensors) { - for (auto &tensor : tensors) { - auto shape = tensor.Shape(); - if (std::find(shape.begin(), shape.end(), -1) != shape.end()) { - return false; - } - } - return true; -} -} // namespace - -Status CustomInterface::Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = lite::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - for (auto &output : *outputs) { - output.SetDataType(DataType::kNumberTypeFloat32); - output.SetFormat(inputs->front().format()); - } - std::map attrs; - if (lite::FetchAttrs(*primitive, &attrs) != kSuccess) { - MS_LOG(ERROR) << "fetch attrs from primitive failed."; - return kLiteError; - } - if (SetOutputFormat(attrs, outputs) != kSuccess) { - MS_LOG(ERROR) << "set output format failed."; - return kLiteError; - } - if (!InferDone(*inputs)) { - return kLiteInferInvalid; - } - std::vector> inputs_shape; - if (GetCustomShape(attrs, kInputsShape, inputs->size(), &inputs_shape) != kSuccess) { - MS_LOG(ERROR) << "parser inputs_shape attribute failed."; - return kLiteError; - } - std::vector> outputs_shape; - if (GetCustomShape(attrs, kOutputsShape, outputs->size(), &outputs_shape) != kSuccess) { - MS_LOG(ERROR) << "parser outputs_shape attribute failed."; - return kLiteError; - } - if (inputs_shape.size() != inputs->size() - kOmParameterNum) { - MS_LOG(ERROR) << "inputs num:" << (inputs->size() - kOmParameterNum) - << "should be equal to inputs_shape num:" << inputs_shape.size(); - return kLiteError; - } - if (inputs_shape[0].size() != (*inputs)[0].Shape().size()) { - MS_LOG(ERROR) << "input[0] shape dim size is invalid. " << inputs_shape[0].size() - << "!=" << (*inputs)[0].Shape().size(); - return kLiteError; - } - - lite::AclModelType acl_model_type{lite::AclModelType::kCnn}; - if (lite::GetAclModelType(primitive, &acl_model_type) != RET_OK) { - MS_LOG(ERROR) << "get acl model type failed."; - return kLiteError; - } - - bool resize_flag = false; - int resize_num = 1; - for (size_t i = 0; i < inputs_shape[0].size(); i++) { - if (inputs_shape[0][i] != (*inputs)[0].Shape()[i]) { - if (i == 0) { - resize_flag = true; - resize_num = (*inputs)[0].Shape()[i]; - } else { - MS_LOG(ERROR) << "Custom of DPICO only support batch_num resize."; - return kLiteError; - } - } - } - - if (resize_flag) { - for (auto &output_shape : outputs_shape) { - output_shape[0] = resize_num * output_shape[0]; - if (acl_model_type == lite::AclModelType::kRecurrent) { - MS_LOG(INFO) << "only output_0 has the information about time steps."; - break; - } - } - } - - for (size_t i = 0; i < outputs->size(); i++) { - (*outputs)[i].SetShape(outputs_shape[i]); - } - return kSuccess; -} - -std::shared_ptr CustomInferCreator() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -} // namespace dpico -} // namespace mindspore -namespace mindspore { -namespace kernel { -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, DPICO, dpico::CustomInferCreator); -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/infer/custom_infer.h b/mindspore-lite/providers/dpico/infer/custom_infer.h deleted file mode 100644 index 1dec5cb0..00000000 --- a/mindspore-lite/providers/dpico/infer/custom_infer.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2021-2022 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_PROVIDERS_DPICO_INFER_CUSTOM_INFER_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_INFER_CUSTOM_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace dpico { -class CustomInterface : public kernel::KernelInterface { - public: - CustomInterface() {} - - ~CustomInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_INFER_CUSTOM_INFER_H_ diff --git a/mindspore-lite/providers/dpico/manager/acl_buf_manager.cc b/mindspore-lite/providers/dpico/manager/acl_buf_manager.cc deleted file mode 100644 index 3058eea0..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_buf_manager.cc +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright 2022 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 "manager/acl_buf_manager.h" -#include "manager/acl_model_helper.h" -#include "common/op_attr.h" - -namespace mindspore { -namespace lite { -AclBufManager *AclBufManager::GetInstance() { - static AclBufManager instance; - return &instance; -} - -void *AclBufManager::GetTaskBufPtr() { - if (task_buf_ptr_ == nullptr) { - int ret = AclMalloc(&task_buf_ptr_, task_buf_size_); - MS_LOG(INFO) << "task_buf_size is " << task_buf_size_; - MS_CHECK_TRUE_MSG(ret == RET_OK, nullptr, "svp acl rt malloc task buf failed."); - } - return task_buf_ptr_; -} - -void *AclBufManager::GetWorkBufPtr() { - if (work_buf_ptr_ == nullptr) { - int ret = AclMalloc(&work_buf_ptr_, work_buf_size_); - MS_LOG(INFO) << "work_buf_size is " << work_buf_size_; - MS_CHECK_TRUE_MSG(ret == RET_OK, nullptr, "svp acl rt malloc work buf failed."); - } - return work_buf_ptr_; -} - -int AclBufManager::UpdateTaskBufSize(int task_buf_size) { - if (task_buf_size <= task_buf_size_) { - MS_LOG(INFO) << "new task_buf_size is " << task_buf_size << ", old task_buf_size_ is " << task_buf_size_ - << ", no need to update task buf"; - return RET_OK; - } - MS_LOG(INFO) << "new task_buf_size is " << task_buf_size << ", old task_buf_size_ is " << task_buf_size_ - << ", will update task buf"; - task_buf_size_ = task_buf_size; - return RET_OK; -} - -int AclBufManager::UpdateWorkBufSize(int work_buf_size) { - if (work_buf_size <= work_buf_size_) { - MS_LOG(INFO) << "new work_size is " << work_buf_size << ", old work_buf_size_ is " << work_buf_size_ - << ", no need to update work buf"; - return RET_OK; - } - MS_LOG(INFO) << "new work_buf_size is " << work_buf_size << ", old work_buf_size_ is " << work_buf_size_ - << ", will update work buf"; - work_buf_size_ = work_buf_size; - return RET_OK; -} - -AclBufManager::~AclBufManager() { - if (task_buf_ptr_ != nullptr) { - int ret = AclFree(&task_buf_ptr_); - MS_CHECK_TRUE_MSG_VOID(ret == RET_OK, "acl free task_buf_ptr_ failed."); - } - if (work_buf_ptr_ != nullptr) { - int ret = AclFree(&work_buf_ptr_); - MS_CHECK_TRUE_MSG_VOID(ret == RET_OK, "acl free work_buf_ptr_ failed."); - } -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/manager/acl_buf_manager.h b/mindspore-lite/providers/dpico/manager/acl_buf_manager.h deleted file mode 100644 index 972d13c9..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_buf_manager.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_MANAGER_ACL_BUF_MANAGER_H -#define MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_BUF_MANAGER_H - -#include "manager/acl_model_helper.h" -#include "include/errorcode.h" -#include "common/check_base.h" - -namespace mindspore { -namespace lite { -class AclBufManager { - public: - static AclBufManager *GetInstance(); - const int &GetTaskBufSize() const { return task_buf_size_; } - const int &GetWorkBufSize() const { return work_buf_size_; } - void *GetTaskBufPtr(); - void *GetWorkBufPtr(); - int UpdateTaskBufSize(int task_buf_size); - int UpdateWorkBufSize(int work_buf_size); - - private: - AclBufManager() = default; - ~AclBufManager(); - int task_buf_size_{0}; - int work_buf_size_{0}; - void *task_buf_ptr_{nullptr}; - void *work_buf_ptr_{nullptr}; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_BUF_MANAGER_H diff --git a/mindspore-lite/providers/dpico/manager/acl_context_manager.cc b/mindspore-lite/providers/dpico/manager/acl_context_manager.cc deleted file mode 100644 index 0e4823cb..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_context_manager.cc +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2022 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 "manager/acl_context_manager.h" -#include -#include -#include "include/svp_acl.h" -#include "include/errorcode.h" -#include "common/check_base.h" -namespace mindspore { -namespace lite { -std::mutex acl_context_mutex; -AclContextManager::~AclContextManager() { - if (!acl_init_flag_) { - return; - } - std::unique_lock lock(acl_context_mutex); - auto ret = svp_acl_finalize(); - MS_CHECK_TRUE_MSG_VOID(ret == SVP_ACL_SUCCESS, "finalize acl failed."); - acl_init_flag_ = false; -} - -int AclContextManager::Init(const std::string &acl_config_path) { - std::unique_lock lock(acl_context_mutex); - if (acl_init_flag_) { - MS_LOG(INFO) << "device only needs to init once."; - return RET_OK; - } - int ret; - if (acl_config_path.empty()) { - ret = svp_acl_init(nullptr); - } else { - ret = svp_acl_init(acl_config_path.c_str()); - } - acl_init_flag_ = true; - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp acl init failed."); - svp_acl_rt_run_mode acl_run_mode; - ret = svp_acl_rt_get_run_mode(&acl_run_mode); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp acl rt get run mode failed."); - MS_CHECK_TRUE_MSG(acl_run_mode == SVP_ACL_DEVICE, RET_ERROR, "svp acl run mode is invalid."); - return RET_OK; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/manager/acl_context_manager.h b/mindspore-lite/providers/dpico/manager/acl_context_manager.h deleted file mode 100644 index b127e34b..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_context_manager.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_MANAGER_ACL_CONTEXT_MANAGER_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_CONTEXT_MANAGER_H_ - -#include -#include -#include -#include "include/svp_acl_base.h" -namespace mindspore { -namespace lite { -class AclContextManager { - public: - AclContextManager() = default; - ~AclContextManager(); - - int Init(const std::string &acl_config_path); - const svp_acl_rt_context GetAclRuntimeContext() const { return acl_rt_context_; } - - private: - /** acl related variables */ - bool acl_init_flag_{false}; - svp_acl_rt_context acl_rt_context_{nullptr}; - svp_acl_rt_stream acl_rt_stream_{nullptr}; -}; -using AclContextManagerPtr = std::shared_ptr; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_CONTEXT_MANAGER_H_ diff --git a/mindspore-lite/providers/dpico/manager/acl_model_helper.cc b/mindspore-lite/providers/dpico/manager/acl_model_helper.cc deleted file mode 100644 index 2a431cd6..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_model_helper.cc +++ /dev/null @@ -1,238 +0,0 @@ -/** - * Copyright 2022 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 "manager/acl_model_helper.h" -#include -#include -#include -#include -#include -#include "include/errorcode.h" -#include "common/check_base.h" -#include "src/custom_allocator.h" -#include "common/string_util.h" -#include "common/op_attr.h" - -namespace mindspore { -namespace lite { -namespace { -constexpr size_t kByteSize = 8; // 1 byte = 8 bits -bool Cmp(const std::vector &lhs, const std::vector &rhs) { - if (lhs[kClassId] < rhs[kClassId]) { - return true; - } else if (lhs[kClassId] == rhs[kClassId]) { - return lhs[kScore] > rhs[kScore]; - } - return false; -} -} // namespace -int GetAclModelType(const schema::Primitive *primitive, AclModelType *acl_model_type) { - MS_CHECK_TRUE_MSG(primitive != nullptr && acl_model_type != nullptr, RET_ERROR, "input params contain nullptr."); - auto op = primitive->value_as_Custom(); - MS_CHECK_TRUE_MSG(op != nullptr, RET_ERROR, "custom op is nullptr."); - auto attrs = op->attr(); - MS_CHECK_TRUE_MSG(attrs != nullptr && attrs->size() >= 1, RET_ERROR, "custom op attr is invalid."); - std::string acl_model_type_str; - for (size_t i = 0; i < attrs->size(); i++) { - auto attr = attrs->Get(i); - MS_CHECK_TRUE_MSG(attr != nullptr && attr->name() != nullptr, RET_ERROR, "invalid attr."); - if (attr->name()->str() != kNetType) { - continue; - } - auto data_info = attr->data(); - MS_CHECK_TRUE_MSG(data_info != nullptr, RET_ERROR, "attr data is nullptr"); - int data_size = static_cast(data_info->size()); - for (int j = 0; j < data_size; j++) { - acl_model_type_str.push_back(static_cast(data_info->Get(j))); - } - break; - } - if (acl_model_type_str.empty()) { - *acl_model_type = AclModelType::kCnn; - return RET_OK; - } - if (!IsValidUnsignedNum(acl_model_type_str)) { - MS_LOG(ERROR) << "net_type attr data is invalid num."; - return RET_ERROR; - } - int acl_model_type_val = stoi(acl_model_type_str); - if (acl_model_type_val < static_cast(AclModelType::kCnn) || - acl_model_type_val > static_cast(AclModelType::kRecurrent)) { - MS_LOG(ERROR) << "net_type val is invalid. " << acl_model_type_val; - return RET_ERROR; - } - *acl_model_type = static_cast(acl_model_type_val); - return RET_OK; -} - -int GetAclDataInfo(struct AclDataInfo *acl_data_info, svp_acl_mdl_desc *acl_mdl_desc, int index) { - MS_CHECK_TRUE_MSG(acl_data_info != nullptr && acl_mdl_desc != nullptr, RET_ERROR, "input params contain nullptr"); - int ret; - if (acl_data_info->data_mode == AclDataInfo::Input) { - ret = svp_acl_mdl_get_input_dims(acl_mdl_desc, index, &(acl_data_info->dim_info)); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl get input dims failed."); - acl_data_info->stride = svp_acl_mdl_get_input_default_stride(acl_mdl_desc, index); - MS_CHECK_TRUE_MSG(acl_data_info->stride != 0, RET_ERROR, "acl get input default stride failed."); - acl_data_info->data_size = svp_acl_mdl_get_input_size_by_index(acl_mdl_desc, index); - MS_CHECK_TRUE_MSG(acl_data_info->data_size != 0, RET_ERROR, "acl get input size by index failed."); - } else { - ret = svp_acl_mdl_get_output_dims(acl_mdl_desc, index, &(acl_data_info->dim_info)); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl get output dims failed."); - acl_data_info->stride = svp_acl_mdl_get_output_default_stride(acl_mdl_desc, index); - MS_CHECK_TRUE_MSG(acl_data_info->stride != 0, RET_ERROR, "acl get output default stride failed."); - acl_data_info->data_size = svp_acl_mdl_get_output_size_by_index(acl_mdl_desc, index); - MS_CHECK_TRUE_MSG(acl_data_info->data_size != 0, RET_ERROR, "acl get output size by index failed."); - } - return RET_OK; -} - -int AddDatasetBuffer(svp_acl_mdl_dataset *acl_mdl_dataset, size_t data_buffer_size, size_t stride, void *data) { - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - MS_CHECK_TRUE_MSG(acl_mdl_dataset != nullptr, RET_ERROR, "acl_mdl_dataset is nullptr."); - auto *data_buffer = svp_acl_create_data_buffer(data, data_buffer_size, stride); - MS_CHECK_TRUE_MSG(data_buffer != nullptr, RET_ERROR, "create data buffer failed."); - int ret = svp_acl_mdl_add_dataset_buffer(acl_mdl_dataset, data_buffer); - if (ret != SVP_ACL_SUCCESS) { - MS_LOG(ERROR) << "add dataset buffer failed."; - ret = svp_acl_destroy_data_buffer(data_buffer); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "destroy data buffer failed."); - data_buffer = nullptr; - return RET_ERROR; - } - return RET_OK; -} - -int DestroyAclDataset(svp_acl_mdl_dataset **acl_mdl_dataset, - const std::unordered_map &mem_managed_by_tensor, const AllocatorPtr &allocator) { - if (*acl_mdl_dataset == nullptr) { - MS_LOG(INFO) << "acl_mdl_dataset is nullptr, no need to destroy"; - return RET_OK; - } - int ret; - auto dataset_buffer_size = svp_acl_mdl_get_dataset_num_buffers(*acl_mdl_dataset); - MS_CHECK_TRUE_MSG(dataset_buffer_size == mem_managed_by_tensor.size(), RET_ERROR, - "dataset_buffer_size:" << dataset_buffer_size << " is not equal to mem_managed_by_tensor.size():" - << mem_managed_by_tensor.size()); - for (size_t i = 0; i < dataset_buffer_size; i++) { - MS_CHECK_TRUE_MSG(mem_managed_by_tensor.find(i) != mem_managed_by_tensor.end(), RET_ERROR, - "invalid dataset buffer index"); - svp_acl_data_buffer *acl_data_buffer = svp_acl_mdl_get_dataset_buffer(*acl_mdl_dataset, i); - MS_CHECK_TRUE_MSG(acl_data_buffer != nullptr, RET_ERROR, "get acl data buffer failed."); - if (!mem_managed_by_tensor.at(i)) { - void *tmp = svp_acl_get_data_buffer_addr(acl_data_buffer); - ret = AclFree(&tmp); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "AclFree tmp failed"); - tmp = nullptr; - } - ret = svp_acl_destroy_data_buffer(acl_data_buffer); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl destroy data buffer failed."); - acl_data_buffer = nullptr; - } - ret = svp_acl_mdl_destroy_dataset(*acl_mdl_dataset); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl destroy dataset failed."); - *acl_mdl_dataset = nullptr; - return RET_OK; -} - -size_t GetDataTypeSize(svp_acl_mdl_desc *acl_mdl_desc, size_t index, AclDataInfo::DataMode data_mode) { - svp_acl_data_type data_type; - if (data_mode == AclDataInfo::Input) { - data_type = svp_acl_mdl_get_input_data_type(acl_mdl_desc, index); - } else { - data_type = svp_acl_mdl_get_output_data_type(acl_mdl_desc, index); - } - return svp_acl_data_type_size(data_type) / kByteSize; -} - -int ComputeValidDetectBoxes(svp_acl_mdl_desc *acl_mdl_desc, svp_acl_mdl_dataset *acl_outputs, - std::vector> *det_boxes) { - MS_CHECK_TRUE_MSG(acl_mdl_desc != nullptr && acl_outputs != nullptr && det_boxes != nullptr, RET_ERROR, - "input params contain nullptr."); - // yolo/ssd output 0 is num, output 1 is bbox - enum InputOutputId { kInputImgId = 0, kOutputNumId = 0, kOutputBboxId = 1 }; - // get valid box number - svp_acl_mdl_io_dims acl_dims; - std::vector valid_box_num; - int ret = svp_acl_mdl_get_output_dims(acl_mdl_desc, kOutputNumId, &acl_dims); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS && acl_dims.dim_count >= 1, RET_ERROR, "svp get output dims failed."); - svp_acl_data_buffer *data_buffer = svp_acl_mdl_get_dataset_buffer(acl_outputs, kOutputNumId); - MS_CHECK_TRUE_MSG(data_buffer != nullptr, RET_ERROR, "get data buffer failed."); - auto output_data = reinterpret_cast(svp_acl_get_data_buffer_addr(data_buffer)); - MS_CHECK_TRUE_MSG(output_data != nullptr, RET_ERROR, "data is nullptr."); - for (uint32_t i = 0; i < static_cast(acl_dims.dims[acl_dims.dim_count - 1]); i++) { - valid_box_num.push_back(*(output_data + i)); - } - int total_valid_num = std::accumulate(valid_box_num.begin(), valid_box_num.end(), 0); - if (total_valid_num == 0) { - MS_LOG(INFO) << "total valid num is zero"; - return RET_OK; - } - // get x y score - data_buffer = svp_acl_mdl_get_dataset_buffer(acl_outputs, kOutputBboxId); - MS_CHECK_TRUE_MSG(data_buffer != nullptr, RET_ERROR, "get data buffer failed."); - output_data = reinterpret_cast(svp_acl_get_data_buffer_addr(data_buffer)); - MS_CHECK_TRUE_MSG(output_data != nullptr, RET_ERROR, "output_data is nullptr."); - svp_acl_mdl_get_output_dims(acl_mdl_desc, kOutputBboxId, &acl_dims); - size_t w_stride_offset = svp_acl_mdl_get_output_default_stride(acl_mdl_desc, kOutputBboxId) / sizeof(float); - - // box param include 6 part which is lx, ly, rx, ry, score, class id - auto bbox_pararm_size = DetectBoxParam::kDetectBoxParamEnd - DetectBoxParam::kDetectBoxParamBegin; - std::vector bbox(bbox_pararm_size, 0.0f); - for (int idx = 0; idx < total_valid_num; idx++) { - float class_id = *(output_data + idx + kClassId * w_stride_offset); - if (std::fabs(class_id) <= std::numeric_limits::epsilon()) { - continue; // skip class 0 back ground - } - for (size_t i = 0; i < bbox_pararm_size; i++) { - bbox[i] = (*(output_data + idx + i * w_stride_offset)); - } - det_boxes->push_back(bbox); - } - std::sort(det_boxes->begin(), det_boxes->end(), Cmp); - return RET_OK; -} - -int WriteDetBoxesToTensorData(const std::vector> &det_boxes, - mindspore::MSTensor *detect_boxes_tensor) { - size_t total_box_num = det_boxes.size(); - auto bbox_pararm_size = DetectBoxParam::kDetectBoxParamEnd - DetectBoxParam::kDetectBoxParamBegin; - MS_CHECK_TRUE_MSG(detect_boxes_tensor != nullptr, RET_ERROR, "detect_boxes_tensor is nullptr."); - MS_CHECK_TRUE_MSG(static_cast(detect_boxes_tensor->ElementNum()) >= total_box_num * bbox_pararm_size, - RET_ERROR, "detect box tensor element num is too few"); - auto *bbox_tensor_data = reinterpret_cast(detect_boxes_tensor->MutableData()); - MS_CHECK_TRUE_MSG(bbox_tensor_data != nullptr, RET_ERROR, "bbox_tensor_data is nullptr"); - MS_CHECK_TRUE_MSG(total_box_num != 0, RET_ERROR, "total_box_num is 0"); - for (size_t i = 0; i < total_box_num; i++) { - for (size_t bbox_param_idx = 0; bbox_param_idx < bbox_pararm_size; bbox_param_idx++) { - bbox_tensor_data[bbox_param_idx * total_box_num + i] = det_boxes[i][bbox_param_idx]; - } - } - detect_boxes_tensor->SetShape({1, static_cast(total_box_num * bbox_pararm_size)}); - return RET_OK; -} - -int AclMalloc(void **buf, size_t size) { - int ret = svp_acl_rt_malloc(buf, size, SVP_ACL_MEM_MALLOC_NORMAL_ONLY); - return ret; -} -int AclFree(void **buf) { - int ret = svp_acl_rt_free(*buf); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp_acl_rt_free failed"); - *buf = nullptr; - return ret; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/manager/acl_model_helper.h b/mindspore-lite/providers/dpico/manager/acl_model_helper.h deleted file mode 100644 index 15b9ae0d..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_model_helper.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_MANAGER_ACL_MODEL_HELPER_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_HELPER_H_ - -#include -#include -#include "include/svp_acl_mdl.h" -#include "include/api/types.h" -#include "include/schema/model_generated.h" -#include "common/custom_enum.h" -#include "include/lite_types.h" - -namespace mindspore { -namespace lite { -struct AclDataInfo { - enum DataMode { Input = 0, Output = 1 }; - DataMode data_mode{Input}; - size_t stride{0}; - size_t data_size{0}; - svp_acl_mdl_io_dims dim_info{}; - explicit AclDataInfo(DataMode input_mode) : data_mode(input_mode) {} -}; -int GetAclModelType(const schema::Primitive *primitive, AclModelType *acl_model_type); -int GetAclDataInfo(struct AclDataInfo *acl_data_info, svp_acl_mdl_desc *acl_mdl_desc, int index); -int AddDatasetBuffer(svp_acl_mdl_dataset *acl_mdl_dataset, size_t data_buffer_size, size_t stride, void *data); -int DestroyAclDataset(svp_acl_mdl_dataset **acl_mdl_dataset, - const std::unordered_map &mem_managed_by_tensor, const AllocatorPtr &allocator_ptr); -size_t GetDataTypeSize(svp_acl_mdl_desc *acl_mdl_desc, size_t index, AclDataInfo::DataMode data_mode); -int ComputeValidDetectBoxes(svp_acl_mdl_desc *acl_mdl_desc, svp_acl_mdl_dataset *acl_outputs, - std::vector> *boxes); -int WriteDetBoxesToTensorData(const std::vector> &det_boxes, - mindspore::MSTensor *detect_boxes_tensor); - -int AclMalloc(void **buf, size_t size); -int AclFree(void **buf); -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_HELPER_H_ diff --git a/mindspore-lite/providers/dpico/manager/acl_model_manager.cc b/mindspore-lite/providers/dpico/manager/acl_model_manager.cc deleted file mode 100644 index 235dd07a..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_model_manager.cc +++ /dev/null @@ -1,619 +0,0 @@ -/** - * Copyright 2022-2023 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 "manager/acl_model_manager.h" -#include -#include -#include -#include -#include "include/errorcode.h" -#include "common/check_base.h" -#include "common/infer_util.h" -#include "common/op_attr.h" -#include "src/custom_allocator.h" -#include "manager/acl_model_helper.h" -#include "manager/acl_buf_manager.h" -namespace mindspore { -namespace lite { -AllocatorPtr AclModelManager::custom_allocator_ = std::make_shared(); -CustomConfigManagerPtr AclModelManager::custom_config_manager_ptr_ = std::make_shared(); -AclContextManagerPtr AclModelManager::acl_context_manager_ = std::make_shared(); -static std::mutex acl_run_mutex; -namespace { -constexpr size_t kNumOfInputOm = 1; // om parameter is the last input of MS Input tensor -constexpr size_t kMinAclInputSize = 2; // {work_buf, task_buf} -constexpr size_t kDetectParamNum = 4; // {nms_threshold, score_threshold,min_height,min_width} -} // namespace -AclModelManager::~AclModelManager() { - int ret = UnloadModel(); - MS_CHECK_TRUE_MSG_VOID(ret == RET_OK, "unload acl model failed."); - ret = DestroyAclDataset(&acl_inputs_, inputs_mem_managed_by_tensor, custom_allocator_); - MS_CHECK_TRUE_MSG_VOID(ret == RET_OK, "destroy acl inputs failed."); - ret = DestroyAclDataset(&acl_outputs_, outputs_mem_managed_by_tensor, custom_allocator_); - MS_CHECK_TRUE_MSG_VOID(ret == RET_OK, "destroy acl outputs failed."); - inputs_mem_managed_by_tensor.clear(); - outputs_mem_managed_by_tensor.clear(); -} - -int AclModelManager::LoadModel(const std::vector &input_tensors) { - MS_CHECK_TRUE_MSG(!input_tensors.empty(), RET_ERROR, "input tensors is empty."); - MS_CHECK_TRUE_MSG(acl_model_ptr_ == nullptr, RET_ERROR, "acl model ptr has been allocated."); - auto acl_model_tensor = input_tensors[input_tensors.size() - kNumOfInputOm]; - auto model_mem_ptr = acl_model_tensor.MutableData(); - MS_CHECK_TRUE_MSG(model_mem_ptr != nullptr, RET_ERROR, "model_mem_ptr is nullptr."); - int ret = AclMalloc(&acl_model_ptr_, acl_model_tensor.DataSize()); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc model buffer failed."); - memcpy(acl_model_ptr_, model_mem_ptr, acl_model_tensor.DataSize()); - ret = svp_acl_mdl_load_from_mem(acl_model_ptr_, acl_model_tensor.DataSize(), &acl_model_id_); - if (ret != SVP_ACL_SUCCESS) { - MS_LOG(ERROR) << "svp acl mdl load from mem failed."; - ret = AclFree(&acl_model_ptr_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "AclFree acl_model_ptr_ failed"); - return RET_ERROR; - } - return RET_OK; -} - -int AclModelManager::CreateModelDesc() { - MS_CHECK_TRUE_MSG(acl_model_desc_ == nullptr, RET_ERROR, "model_desc has been created."); - acl_model_desc_ = svp_acl_mdl_create_desc(); - MS_CHECK_TRUE_MSG(acl_model_desc_ != nullptr, RET_ERROR, "create model desc failed."); - int ret = svp_acl_mdl_get_desc(acl_model_desc_, acl_model_id_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "get model desc failed."); - return RET_OK; -} - -int AclModelManager::GetMaxTaskAndWorkBufSize() { - size_t input_size = svp_acl_mdl_get_num_inputs(acl_model_desc_); - MS_CHECK_TRUE_MSG(input_size > kMinAclInputSize, RET_ERROR, - "acl model input size should be greater than " << kMinAclInputSize); - AclDataInfo acl_data_info(AclDataInfo::Input); - int ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, input_size - 2); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - ret = AclBufManager::GetInstance()->UpdateTaskBufSize(acl_data_info.data_size); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "update task buf max size failed."); - ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, input_size - 1); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - ret = AclBufManager::GetInstance()->UpdateWorkBufSize(acl_data_info.data_size); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "update work buf max size failed."); - return RET_OK; -} - -int AclModelManager::SetDetectParams(void *data) { - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "detect param data is nullptr"); - auto param = reinterpret_cast(data); - param[kNmsThreshold] = custom_config_manager_ptr_->NmsThreshold(); - param[kScoreThreshold] = custom_config_manager_ptr_->ScoreThreshold(); - param[kMinHeight] = custom_config_manager_ptr_->MinHeight(); - param[kMinWidth] = custom_config_manager_ptr_->MinWidth(); - return RET_OK; -} - -int AclModelManager::AddDetectParamInput() { - void *data = nullptr; - size_t detect_param_stride = sizeof(float) * kDetectParamNum; - int ret = AclMalloc(&data, actual_batch_size_ * detect_param_stride); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc detect input buffer failed."); - for (size_t loop = 0; loop < actual_batch_size_; loop++) { - ret = SetDetectParams(reinterpret_cast(data) + loop * detect_param_stride); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "set detect params failed."); - } - AclDataInfo acl_data_info(AclDataInfo::Input); - acl_data_info.data_size = sizeof(float) * kDetectParamNum; - acl_data_info.stride = sizeof(float) * kDetectParamNum; - ret = AddDatasetBuffer(acl_inputs_, acl_data_info.data_size, acl_data_info.stride, data); - if (ret != RET_OK) { - MS_LOG(ERROR) << "add dataset buffer failed."; - ret = AclFree(&data); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "AclFree data failed"); - return RET_ERROR; - } - size_t cur_num_buffers = svp_acl_mdl_get_dataset_num_buffers(acl_inputs_); - MS_CHECK_TRUE_MSG(cur_num_buffers - 1 == inputs_mem_managed_by_tensor.size(), RET_ERROR, - "detect param index is invalid"); - inputs_mem_managed_by_tensor[cur_num_buffers - 1] = false; - return RET_OK; -} - -int AclModelManager::DetectPostProcess(mindspore::MSTensor *detect_output_tensor) { - MS_CHECK_TRUE_MSG(detect_output_tensor != nullptr, RET_ERROR, "detect_output_tensor is nullptr."); - std::vector> valid_det_boxes; - int ret = ComputeValidDetectBoxes(acl_model_desc_, acl_outputs_, &valid_det_boxes); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "compute valid detect boxes failed."); - ret = WriteDetBoxesToTensorData(valid_det_boxes, detect_output_tensor); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "write det boxes to detect output tensor data failed."); - return RET_OK; -} - -int AclModelManager::CreateTaskBufAndWorkBuf() { - size_t input_size = svp_acl_mdl_get_num_inputs(acl_model_desc_); - MS_CHECK_TRUE_MSG(input_size > kMinAclInputSize, RET_ERROR, - "acl model input size should be greater than " << kMinAclInputSize); - size_t cur_num_buffers = svp_acl_mdl_get_dataset_num_buffers(acl_inputs_); - MS_CHECK_TRUE_MSG(cur_num_buffers > 0, RET_ERROR, "acl model input size should be greater than 0"); - for (size_t i = cur_num_buffers; i < input_size; i++) { - AclDataInfo acl_data_info(AclDataInfo::Input); - int ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - if (i == cur_num_buffers) { - ret = AddDatasetBuffer(acl_inputs_, acl_data_info.data_size, acl_data_info.stride, - AclBufManager::GetInstance()->GetTaskBufPtr()); - if (ret != RET_OK) { - MS_LOG(ERROR) << "add dataset buffer failed."; - return RET_ERROR; - } - } else { - ret = AddDatasetBuffer(acl_inputs_, acl_data_info.data_size, acl_data_info.stride, - AclBufManager::GetInstance()->GetWorkBufPtr()); - if (ret != RET_OK) { - MS_LOG(ERROR) << "add dataset buffer failed."; - return RET_ERROR; - } - } - inputs_mem_managed_by_tensor[i] = true; - } - return RET_OK; -} - -int AclModelManager::CreateNoShareTaskBufAndWorkBuf() { - size_t input_size = svp_acl_mdl_get_num_inputs(acl_model_desc_); - MS_CHECK_TRUE_MSG(input_size > kMinAclInputSize, RET_ERROR, - "acl model input size should be greater than " << kMinAclInputSize); - size_t cur_num_buffers = svp_acl_mdl_get_dataset_num_buffers(acl_inputs_); - MS_CHECK_TRUE_MSG(cur_num_buffers > 0, RET_ERROR, "acl model input size should be greater than 0"); - for (size_t i = cur_num_buffers; i < input_size; i++) { - void *data = nullptr; - AclDataInfo acl_data_info(AclDataInfo::Input); - int ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - ret = AclMalloc(&data, acl_data_info.data_size); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc task and work buf failed."); - ret = AddDatasetBuffer(acl_inputs_, acl_data_info.data_size, acl_data_info.stride, data); - if (ret != RET_OK) { - MS_LOG(ERROR) << "add dataset buffer failed."; - ret = AclFree(&data); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "AclFree data failed"); - return RET_ERROR; - } - inputs_mem_managed_by_tensor[i] = false; - } - return RET_OK; -} - -int AclModelManager::CopyTensorDataToAclInputs(const std::vector &input_tensors) { - for (size_t i = 0; i + kNumOfInputOm < input_tensors.size(); i++) { - MS_CHECK_TRUE_MSG(inputs_mem_managed_by_tensor.find(i) != inputs_mem_managed_by_tensor.end(), RET_ERROR, - "invalid input index"); - if (inputs_mem_managed_by_tensor[i]) { - continue; - } - - auto input_tensor = input_tensors.at(i); - AclDataInfo acl_data_info{AclDataInfo::Input}; - int ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - auto *input_tensor_data = input_tensor.MutableData(); - MS_CHECK_TRUE_MSG(input_tensor_data != nullptr, RET_ERROR, "input tensor data is nullptr."); - - MS_CHECK_TRUE_MSG(!input_tensor.Shape().empty(), RET_ERROR, "input tensor shape is empty"); - size_t input_tensor_last_dim = input_tensor.Shape().back(); - size_t type_size = GetDataTypeSize(acl_model_desc_, i, acl_data_info.data_mode); - auto input_tensor_stride = input_tensor_last_dim * type_size; - - auto *acl_data_buffer = svp_acl_mdl_get_dataset_buffer(acl_inputs_, i); - MS_CHECK_TRUE_MSG(acl_data_buffer != nullptr, RET_ERROR, "get acl data buffer failed."); - auto *acl_data = svp_acl_get_data_buffer_addr(acl_data_buffer); - MS_CHECK_TRUE_MSG(acl_data != nullptr, RET_ERROR, "acl data is nullptr."); - - MS_CHECK_TRUE_MSG(acl_data_info.stride != 0, RET_ERROR, "acl stride cannot be 0"); - int64_t loop_times = acl_data_info.data_size * actual_batch_size_ / acl_data_info.stride; - if (acl_model_type_ == AclModelType::kRecurrent) { - if (i == 0) { // e.g: tensor shape is (3, 1, 29), acl dims is (1024, 1, 29) - loop_times = loop_times / acl_data_info.dim_info.dims[0] * custom_config_manager_ptr_->GTotalT(); - } else if (i == 1) { // e.g: tensor shape is (3, 1, 1), acl dims is (1, 1, 1024) - input_tensor_stride = custom_config_manager_ptr_->GTotalT() * type_size; - } - } - - // copy tensor data to acl inputs with the last dim(bytes) as a unit - for (int64_t loop = 0; loop < loop_times; loop++) { - memcpy(reinterpret_cast(acl_data) + loop * acl_data_info.stride, - reinterpret_cast(input_tensor_data) + loop * input_tensor_stride, input_tensor_stride); - } - } - return RET_OK; -} - -int AclModelManager::CopyAclOutputsToTensorData(const std::vector &output_tensors) { - for (size_t i = 0; i < output_tensors.size(); i++) { - MS_CHECK_TRUE_MSG(outputs_mem_managed_by_tensor.find(i) != outputs_mem_managed_by_tensor.end(), RET_ERROR, - "invalid output index"); - if (i == 1 && custom_config_manager_ptr_->NeedDetectPostProcess() && acl_model_type_ == kRoi) { - constexpr size_t kMinDetectOutputSize = 2; - MS_CHECK_TRUE_MSG(output_tensors.size() >= kMinDetectOutputSize, RET_ERROR, - "detection net output size shouldn't be less than " << kMinDetectOutputSize); - auto detect_boxes_tensor = output_tensors.at(i); - int ret = DetectPostProcess(&detect_boxes_tensor); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "detect net post process failed."); - continue; - } - - if (outputs_mem_managed_by_tensor[i]) { - continue; - } - auto output_tensor = output_tensors.at(i); - AclDataInfo acl_data_info{AclDataInfo::Output}; - int ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - auto *output_tensor_data = output_tensor.MutableData(); - MS_CHECK_TRUE_MSG(output_tensor_data != nullptr, RET_ERROR, "output tensor data is nullptr."); - - MS_CHECK_TRUE_MSG(!output_tensor.Shape().empty(), RET_ERROR, "output tensor shape is empty"); - size_t output_tensor_last_dim = output_tensor.Shape().back(); - size_t type_size = GetDataTypeSize(acl_model_desc_, i, acl_data_info.data_mode); - auto output_tensor_stride = output_tensor_last_dim * type_size; - - auto *acl_data_buffer = svp_acl_mdl_get_dataset_buffer(acl_outputs_, i); - MS_CHECK_TRUE_MSG(acl_data_buffer != nullptr, RET_ERROR, "get acl data buffer failed."); - auto *acl_data = svp_acl_get_data_buffer_addr(acl_data_buffer); - MS_CHECK_TRUE_MSG(acl_data != nullptr, RET_ERROR, "acl data is nullptr."); - - MS_CHECK_TRUE_MSG(acl_data_info.stride != 0, RET_ERROR, "acl stride cannot be 0"); - int64_t loop_times = acl_data_info.data_size * actual_batch_size_ / acl_data_info.stride; - if (acl_model_type_ == AclModelType::kRecurrent && i == 0) { // RNN input_0's dims[0] isn't equal to gTotalT - loop_times = loop_times / acl_data_info.dim_info.dims[0] * custom_config_manager_ptr_->GTotalT(); - } - for (int64_t loop = 0; loop < loop_times; loop++) { - memcpy(reinterpret_cast(output_tensor_data) + loop * output_tensor_stride, - reinterpret_cast(acl_data) + loop * acl_data_info.stride, output_tensor_stride); - } - } - return RET_OK; -} - -int AclModelManager::FlushAclInputsAndOutputs() { - // flush acl inputs - auto dataset_buffer_size = svp_acl_mdl_get_dataset_num_buffers(acl_inputs_); - for (size_t i = 0; i < dataset_buffer_size; i++) { - if (!inputs_mem_managed_by_tensor[i]) { - continue; - } - auto *acl_data_buffer = svp_acl_mdl_get_dataset_buffer(acl_inputs_, i); - MS_CHECK_TRUE_MSG(acl_data_buffer != nullptr, RET_ERROR, "get acl data buffer failed."); - auto input_size = svp_acl_get_data_buffer_size(acl_data_buffer); - void *data = svp_acl_get_data_buffer_addr(acl_data_buffer); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "acl data is nullptr"); - auto ret = svp_acl_rt_mem_flush(data, input_size); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "flush input tensor failed."); - } - - // flush acl outputs - dataset_buffer_size = svp_acl_mdl_get_dataset_num_buffers(acl_outputs_); - for (size_t i = 0; i < dataset_buffer_size; i++) { - if (!outputs_mem_managed_by_tensor[i]) { - continue; - } - auto *acl_data_buffer = svp_acl_mdl_get_dataset_buffer(acl_outputs_, i); - MS_CHECK_TRUE_MSG(acl_data_buffer != nullptr, RET_ERROR, "get acl data buffer failed."); - auto output_size = svp_acl_get_data_buffer_size(acl_data_buffer); - void *data = svp_acl_get_data_buffer_addr(acl_data_buffer); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "acl data is nullptr"); - auto ret = svp_acl_rt_mem_invalidate(data, output_size); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "invalidate input tensor failed."); - } - return RET_OK; -} - -int AclModelManager::AclModelRun(const std::vector &input_tensors) { - std::unique_lock lock(acl_run_mutex); - int ret = svp_acl_rt_set_device(acl_device_id_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp acl rt set device failed."); - if (acl_model_type_ != AclModelType::kRecurrent) { - size_t index; - ret = svp_acl_mdl_get_input_index_by_name(acl_model_desc_, SVP_ACL_DYNAMIC_TENSOR_NAME, &index); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl get input index by name failed."); - - ret = svp_acl_mdl_set_dynamic_batch_size(acl_model_id_, acl_inputs_, index, actual_batch_size_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl set dynamic batch size failed."); - } else { - ret = svp_acl_mdl_set_total_t(acl_model_id_, acl_inputs_, custom_config_manager_ptr_->GTotalT()); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl set total t failed."); - } - ret = svp_acl_mdl_execute(acl_model_id_, acl_inputs_, acl_outputs_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp acl execute failed."); - ret = svp_acl_rt_reset_device(acl_device_id_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl reset device failed."); - return RET_OK; -} - -int AclModelManager::UnloadModel() { - int ret = svp_acl_mdl_unload(acl_model_id_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp acl unload model failed"); - if (acl_model_desc_ != nullptr) { - ret = svp_acl_mdl_destroy_desc(acl_model_desc_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp acl destroy model desc failed."); - acl_model_desc_ = nullptr; - } - if (acl_model_ptr_ != nullptr) { - ret = AclFree(&acl_model_ptr_); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "AclFree acl_model_ptr_ failed"); - } - return RET_OK; -} - -int AclModelManager::Init(const std::map &dpico_config, - const std::map &model_share_config, - const schema::Primitive *primitive, const std::vector &input_tensors, - const std::vector &output_tensors) { - MS_CHECK_TRUE_MSG(acl_context_manager_ != nullptr, RET_ERROR, "acl_context_manager_ is nullptr."); - MS_CHECK_TRUE_MSG(custom_config_manager_ptr_ != nullptr, RET_ERROR, "custom_config_manager_ptr_ is nullptr."); - if (custom_config_manager_ptr_->Init(dpico_config) != RET_OK) { - MS_LOG(ERROR) << "custom config manager init failed"; - return RET_ERROR; - } - if (acl_context_manager_->Init(custom_config_manager_ptr_->AclConfigFile()) != RET_OK) { - MS_LOG(ERROR) << "acl context manager init failed."; - return RET_ERROR; - } - if (GetAclModelType(primitive, &acl_model_type_) != RET_OK) { - MS_LOG(ERROR) << "get acl model type failed."; - return RET_ERROR; - } - if (LoadModel(input_tensors) != RET_OK) { - MS_LOG(ERROR) << "load acl model failed."; - return RET_ERROR; - } - if (CreateModelDesc() != RET_OK) { - MS_LOG(ERROR) << "create model desc failed."; - return RET_ERROR; - } - if (!custom_config_manager_ptr_->IsEnableMultiModelSharingMemPrepare(model_share_config)) { - MS_LOG(INFO) << "MultiModelSharingMemPrepare function not open, do not need to model share."; - } else { - if (GetMaxTaskAndWorkBufSize() != RET_OK) { - MS_LOG(ERROR) << "get max task and work buffer size failed."; - return RET_ERROR; - } - } - - return RET_OK; -} - -int AclModelManager::UpdateBatchSize(const std::vector &input_tensors) { - auto input_tensor = input_tensors.front(); - auto input_shape = input_tensor.Shape(); - if (input_shape.empty()) { - MS_LOG(ERROR) << "input shape is empty. " << input_tensor.Name(); - return RET_ERROR; - } - - svp_acl_mdl_io_dims acl_mdl_input_0_dims; - int ret = svp_acl_mdl_get_input_dims(acl_model_desc_, 0, &acl_mdl_input_0_dims); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "acl get input dims failed."); - auto ms_input_batch = static_cast(input_shape.front()); - if (input_shape.size() == 1 && ms_input_batch > 1) { - MS_LOG(ERROR) << "When input dim is 1, batch size can't be more than 1"; - return RET_ERROR; - } - if (acl_model_type_ == AclModelType::kRecurrent) { - custom_config_manager_ptr_->SetGTotalT(ms_input_batch); - } else { - MS_CHECK_TRUE_MSG(acl_mdl_input_0_dims.dim_count > 0 && acl_mdl_input_0_dims.dims[0] != 0, RET_ERROR, - "acl input 0 dims is invalid."); - actual_batch_size_ = ms_input_batch / acl_mdl_input_0_dims.dims[0]; - } - return RET_OK; -} - -int AclModelManager::PrepareAclInputs(std::vector *input_tensors) { - MS_CHECK_TRUE_MSG(acl_model_desc_ != nullptr, RET_ERROR, "acl model desc is nullptr."); - MS_CHECK_TRUE_MSG(custom_allocator_ != nullptr, RET_ERROR, "custom allocator is nullptr."); - MS_CHECK_TRUE_MSG(input_tensors != nullptr, RET_ERROR, "input_tensors is nullptr."); - int ret; - if (acl_inputs_ != nullptr) { - ret = DestroyAclDataset(&acl_inputs_, inputs_mem_managed_by_tensor, custom_allocator_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "destroy acl input dataset failed."); - inputs_mem_managed_by_tensor.clear(); - } - acl_inputs_ = svp_acl_mdl_create_dataset(); - MS_CHECK_TRUE_MSG(acl_inputs_ != nullptr, RET_ERROR, "create acl model input dataset failed."); - for (size_t i = 0; i < input_tensors->size() - kNumOfInputOm; i++) { - AclDataInfo acl_data_info(AclDataInfo::Input); - ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - void *data = nullptr; - if (acl_data_info.data_size * actual_batch_size_ != input_tensors->at(i).DataSize()) { - inputs_mem_managed_by_tensor[i] = false; - MS_LOG(INFO) << "The size of the last dimension of the input tensor " - << "does not align with 'internal_stride' value, will memcpy"; - ret = AclMalloc(&data, acl_data_info.data_size * actual_batch_size_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc acl input buffer failed."); - } else { - inputs_mem_managed_by_tensor[i] = true; - MS_LOG(INFO) << "The size of the last dimension of the input tensor " - << "is equal to 'internal_stride' value, will not memcpy"; - input_tensors->at(i).SetAllocator(custom_allocator_); - data = input_tensors->at(i).MutableData(); // svp malloc memory for ms tensor - } - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "get data ptr failed."); - ret = AddDatasetBuffer(acl_inputs_, acl_data_info.data_size * actual_batch_size_, acl_data_info.stride, data); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "add dataset buffer failed."); - } - if (acl_model_type_ == AclModelType::kRoi) { - ret = AddDetectParamInput(); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "add detect param input failed."); - } - return RET_OK; -} - -int AclModelManager::PrepareAclOutputs(std::vector *output_tensors) { - MS_CHECK_TRUE_MSG(acl_model_desc_ != nullptr, RET_ERROR, "acl model desc is nullptr."); - MS_CHECK_TRUE_MSG(custom_allocator_ != nullptr, RET_ERROR, "custom allocator is nullptr."); - MS_CHECK_TRUE_MSG(output_tensors != nullptr, RET_ERROR, "output_tensors is nullptr."); - int ret; - if (acl_outputs_ != nullptr) { - ret = DestroyAclDataset(&acl_outputs_, outputs_mem_managed_by_tensor, custom_allocator_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "destroy acl output dataset failed."); - outputs_mem_managed_by_tensor.clear(); - } - acl_outputs_ = svp_acl_mdl_create_dataset(); - MS_CHECK_TRUE_MSG(acl_outputs_ != nullptr, RET_ERROR, "create acl model output dataset failed."); - size_t output_size = svp_acl_mdl_get_num_outputs(acl_model_desc_); - MS_CHECK_TRUE_MSG(output_size == output_tensors->size(), RET_ERROR, - "acl output size should be equal to ms output tensor size"); - for (size_t i = 0; i < output_size; i++) { - AclDataInfo acl_data_info(AclDataInfo::Output); - ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - void *data = nullptr; - if (acl_data_info.data_size * actual_batch_size_ != output_tensors->at(i).DataSize()) { - outputs_mem_managed_by_tensor[i] = false; - MS_LOG(INFO) << "The size of the last dimension of the output tensor " - << "does not align with 'internal_stride' value, will memcpy"; - ret = AclMalloc(&data, acl_data_info.data_size * actual_batch_size_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc acl output buffer failed."); - } else { - outputs_mem_managed_by_tensor[i] = true; - MS_LOG(INFO) << "The size of the last dimension of the output tensor " - << "aligns with 'internal_stride' value, will not memcpy"; - output_tensors->at(i).SetAllocator(custom_allocator_); - data = output_tensors->at(i).MutableData(); // svp malloc memory for ms tensor - } - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "get data ptr failed."); - ret = AddDatasetBuffer(acl_outputs_, acl_data_info.data_size * actual_batch_size_, acl_data_info.stride, data); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "add dataset buffer failed."); - } - return RET_OK; -} - -int AclModelManager::UpdateKernelConfig(const std::map &dpico_config) { - int ret = custom_config_manager_ptr_->UpdateConfig(dpico_config); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "update custom config success"); - return RET_OK; -} - -int AclModelManager::UpdateAclInputs(std::vector *input_tensors) { - MS_CHECK_TRUE_MSG(input_tensors != nullptr, RET_ERROR, "input_tensors is nullptr."); - for (size_t i = 0; i < input_tensors->size() - kNumOfInputOm; i++) { - MS_CHECK_TRUE_MSG(inputs_mem_managed_by_tensor.find(i) != inputs_mem_managed_by_tensor.end(), RET_ERROR, - "invalid input index: " << i); - auto input_tensor = input_tensors->at(i); - auto data_buffer = svp_acl_mdl_get_dataset_buffer(acl_inputs_, i); - MS_CHECK_TRUE_MSG(data_buffer != nullptr, RET_ERROR, "data_buffer is nullptr."); - auto stride = svp_acl_mdl_get_input_default_stride(acl_model_desc_, i); - if (!inputs_mem_managed_by_tensor[i]) { - MS_LOG(INFO) << "input data isn't managed by tensor." << input_tensor.Name(); - void *tmp_buffer = svp_acl_get_data_buffer_addr(data_buffer); - auto ret = AclFree(&tmp_buffer); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "execute AclFree failed"); - AclDataInfo acl_data_info(AclDataInfo::Input); - ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - void *data = nullptr; - ret = AclMalloc(&data, acl_data_info.data_size * actual_batch_size_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc acl input buffer failed."); - auto svp_ret = - svp_acl_update_data_buffer(data_buffer, data, acl_data_info.data_size * actual_batch_size_, stride); - MS_CHECK_TRUE_MSG(svp_ret == SVP_ACL_SUCCESS, RET_ERROR, - "svp update data buffer failed. " << input_tensor.Name()); - } else { - auto ret = svp_acl_update_data_buffer(data_buffer, input_tensors->at(i).MutableData(), - input_tensors->at(i).DataSize(), stride); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp update data buffer failed. " << input_tensor.Name()); - } - } - - if (acl_model_type_ == AclModelType::kRoi) { - size_t detect_param_index = input_tensors->size() - kNumOfInputOm; - auto data_buffer = svp_acl_mdl_get_dataset_buffer(acl_inputs_, detect_param_index); - MS_CHECK_TRUE_MSG(data_buffer != nullptr, RET_ERROR, "data_buffer is nullptr."); - void *data = svp_acl_get_data_buffer_addr(data_buffer); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "detect param data is nullptr."); - auto ret = AclFree(&data); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "execute AclFree failed"); - void *data_tmp = nullptr; - size_t detect_param_stride = sizeof(float) * kDetectParamNum; - ret = AclMalloc(&data_tmp, actual_batch_size_ * detect_param_stride); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc detect input buffer failed."); - for (size_t loop = 0; loop < actual_batch_size_; loop++) { - ret = SetDetectParams(reinterpret_cast(data_tmp) + loop * detect_param_stride); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "set detect params failed."); - } - auto svp_ret = - svp_acl_update_data_buffer(data_buffer, data_tmp, detect_param_stride * actual_batch_size_, detect_param_stride); - MS_CHECK_TRUE_MSG(svp_ret == SVP_ACL_SUCCESS, RET_ERROR, "svp update data buffer for detect_param failed. "); - } - return RET_OK; -} - -int AclModelManager::UpdateAclOutputs(std::vector *output_tensors) { - MS_CHECK_TRUE_MSG(output_tensors != nullptr, RET_ERROR, "output_tensors is nullptr."); - for (size_t i = 0; i < output_tensors->size(); i++) { - MS_CHECK_TRUE_MSG(outputs_mem_managed_by_tensor.find(i) != outputs_mem_managed_by_tensor.end(), RET_ERROR, - "invalid output index: " << i); - auto output_tensor = output_tensors->at(i); - auto data_buffer = svp_acl_mdl_get_dataset_buffer(acl_outputs_, i); - MS_CHECK_TRUE_MSG(data_buffer != nullptr, RET_ERROR, "data_buffer is nullptr."); - auto stride = svp_acl_mdl_get_output_default_stride(acl_model_desc_, i); - if (!outputs_mem_managed_by_tensor[i]) { - MS_LOG(INFO) << "output data isn't managed by tensor." << output_tensor.Name(); - void *tmp_buffer = svp_acl_get_data_buffer_addr(data_buffer); - auto ret = AclFree(&tmp_buffer); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "execute AclFree failed"); - AclDataInfo acl_data_info(AclDataInfo::Output); - ret = GetAclDataInfo(&acl_data_info, acl_model_desc_, i); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "get acl data info failed."); - void *data = nullptr; - ret = AclMalloc(&data, acl_data_info.data_size * actual_batch_size_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "svp acl rt malloc acl output buffer failed."); - auto svp_ret = - svp_acl_update_data_buffer(data_buffer, data, acl_data_info.data_size * actual_batch_size_, stride); - MS_CHECK_TRUE_MSG(svp_ret == SVP_ACL_SUCCESS, RET_ERROR, - "svp update data buffer failed. " << output_tensor.Name()); - } else { - auto ret = svp_acl_update_data_buffer(data_buffer, output_tensor.MutableData(), output_tensor.DataSize(), stride); - MS_CHECK_TRUE_MSG(ret == SVP_ACL_SUCCESS, RET_ERROR, "svp update data buffer failed. " << output_tensor.Name()); - } - } - return RET_OK; -} - -int AclModelManager::Execute(const std::vector &input_tensors, - const std::vector &output_tensors, - const std::map &model_share_config) { - int ret; - if (custom_config_manager_ptr_->IsEnableMultiModelSharingMem(model_share_config)) { - ret = CreateTaskBufAndWorkBuf(); - } else { - ret = CreateNoShareTaskBufAndWorkBuf(); - } - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "create task buf and work buf failed."); - - ret = CopyTensorDataToAclInputs(input_tensors); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "copy input tensor data to acl inputs failed."); - - ret = FlushAclInputsAndOutputs(); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "flush input and output tensor data failed."); - - ret = AclModelRun(input_tensors); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "acl model run failed."); - - ret = CopyAclOutputsToTensorData(output_tensors); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "copy acl outputs to output tensor data failed."); - return RET_OK; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/manager/acl_model_manager.h b/mindspore-lite/providers/dpico/manager/acl_model_manager.h deleted file mode 100644 index 84661dfc..00000000 --- a/mindspore-lite/providers/dpico/manager/acl_model_manager.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_MANAGER_ACL_MODEL_MANAGER_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_MANAGER_H_ - -#include -#include -#include -#include -#include -#include "include/api/types.h" -#include "include/svp_acl_base.h" -#include "include/svp_acl_mdl.h" -#include "manager/acl_context_manager.h" -#include "manager/custom_config_manager.h" -#include "common/custom_enum.h" -#include "include/schema/model_generated.h" -#include "include/lite_types.h" - -namespace mindspore { -namespace lite { -class AclModelManager { - public: - AclModelManager() = default; - ~AclModelManager(); - - int Init(const std::map &dpico_config, - const std::map &model_share_config, const schema::Primitive *primitive, - const std::vector &input_tensors, - const std::vector &output_tensors); - int UpdateBatchSize(const std::vector &input_tensors); - int PrepareAclInputs(std::vector *input_tensors); - int PrepareAclOutputs(std::vector *output_tensors); - int UpdateKernelConfig(const std::map &dpico_config); - int UpdateAclInputs(std::vector *input_tensors); - int UpdateAclOutputs(std::vector *output_tensors); - int Execute(const std::vector &input_tensors, - const std::vector &output_tensors, - const std::map &model_share_config); - - private: - int LoadModel(const std::vector &input_tensors); - int CreateModelDesc(); - int SetDetectParams(void *data); - int AddDetectParamInput(); - int DetectPostProcess(mindspore::MSTensor *output_tensors); - int CreateTaskBufAndWorkBuf(); - int CreateNoShareTaskBufAndWorkBuf(); - int GetMaxTaskAndWorkBufSize(); - int CopyTensorDataToAclInputs(const std::vector &input_tensors); - int CopyAclOutputsToTensorData(const std::vector &output_tensors); - int FlushAclInputsAndOutputs(); - int AclModelRun(const std::vector &input_tensors); - int UnloadModel(); - - private: - static AllocatorPtr custom_allocator_; - static CustomConfigManagerPtr custom_config_manager_ptr_; - static AclContextManagerPtr acl_context_manager_; - - std::unordered_map inputs_mem_managed_by_tensor; // - std::unordered_map outputs_mem_managed_by_tensor; // - - size_t actual_batch_size_{1}; - /** acl related variables */ - uint32_t acl_model_id_{0}; - int32_t acl_device_id_{0}; - size_t stride_align_size_{16}; - AclModelType acl_model_type_{kCnn}; - void *acl_model_ptr_{nullptr}; - svp_acl_mdl_desc *acl_model_desc_{nullptr}; - svp_acl_mdl_dataset *acl_inputs_{nullptr}; - svp_acl_mdl_dataset *acl_outputs_{nullptr}; -}; -using AclModelManagerPtr = std::shared_ptr; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_ACL_MODEL_MANAGER_H_ diff --git a/mindspore-lite/providers/dpico/manager/custom_config_manager.cc b/mindspore-lite/providers/dpico/manager/custom_config_manager.cc deleted file mode 100644 index 201db932..00000000 --- a/mindspore-lite/providers/dpico/manager/custom_config_manager.cc +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Copyright 2022 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 -#include -#include -#include -#include "common/string_util.h" -#include "common/op_attr.h" -#include "manager/custom_config_manager.h" -#include "common/log_util.h" -#include "include/errorcode.h" -namespace mindspore { -namespace lite { -int CustomConfigManager::Init(const std::map &dpico_config) { - if (inited_) { - MS_LOG(INFO) << "device only needs to init once."; - return RET_OK; - } - if (UpdateConfig(dpico_config) != RET_OK) { - MS_LOG(ERROR) << "init custom config failed."; - return RET_ERROR; - } - return RET_OK; -} -std::string CustomConfigManager::RealPath(const char *path) { - if (path == nullptr) { - MS_LOG(ERROR) << "path is nullptr"; - return ""; - } - if ((std::strlen(path)) >= PATH_MAX) { - MS_LOG(ERROR) << "path is too long"; - return ""; - } - auto resolved_path = std::make_unique(PATH_MAX); - if (resolved_path == nullptr) { - MS_LOG(ERROR) << "new resolved_path failed"; - return ""; - } - char *real_path = realpath(path, resolved_path.get()); - if (real_path == nullptr || strlen(real_path) == 0) { - MS_LOG(ERROR) << "file path is not valid"; - return ""; - } - std::string res = resolved_path.get(); - return res; -} -int CustomConfigManager::UpdateConfig(const std::map &dpico_config) { - // parse float params - std::map float_params = {{kNmsThreshold, &nms_threshold_}, - {kScoreThreshold, &score_threshold_}, - {kMinHeight, &min_height_}, - {kMinWidth, &min_width_}}; - for (const auto ¶m : float_params) { - if (dpico_config.find(param.first) != dpico_config.end()) { - if (IsValidDoubleNum(dpico_config.at(param.first))) { - *param.second = std::stof(dpico_config.at(param.first)); - } else { - MS_LOG(WARNING) << param.first << " param in config is invalid, will use default or last value."; - } - } else { - MS_LOG(INFO) << param.first << " param isn't configured, will use default or last value."; - } - } - - // parse bool params - if (dpico_config.find(kDetectionPostProcess) != dpico_config.end()) { - if (dpico_config.at(kDetectionPostProcess) == "on") { - detect_post_process_ = true; - } else if (dpico_config.at(kDetectionPostProcess) == "off") { - detect_post_process_ = false; - } else { - MS_LOG(WARNING) << kDetectionPostProcess - << " param in config is invalid, will use default or last value: " << detect_post_process_; - } - } else { - MS_LOG(INFO) << kDetectionPostProcess - << " param isn't configured, will use default or last value: " << detect_post_process_; - } - - // parse string params - if (dpico_config.find(kAclConfigPath) != dpico_config.end()) { - acl_config_file_ = dpico_config.at(kAclConfigPath); - if (AccessFile(acl_config_file_, F_OK) != 0) { - MS_LOG(ERROR) << " AclConfigPath not exist, please check."; - return RET_ERROR; - } - auto acl_config_file = RealPath(acl_config_file_.c_str()); - if (acl_config_file.empty()) { - MS_LOG(ERROR) << "Get realpath failed, please check your acl config file."; - return RET_ERROR; - } - } - return RET_OK; -} -bool CustomConfigManager::IsEnableMultiModelSharingMemPrepare( - const std::map &model_share_config) { - return model_share_config.find(kModelSharingPrepareKey) != model_share_config.end(); -} -bool CustomConfigManager::IsEnableMultiModelSharingMem(const std::map &model_share_config) { - return model_share_config.find(kModelSharingKey) != model_share_config.end(); -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/manager/custom_config_manager.h b/mindspore-lite/providers/dpico/manager/custom_config_manager.h deleted file mode 100644 index 6e54a1a8..00000000 --- a/mindspore-lite/providers/dpico/manager/custom_config_manager.h +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_DPICO_MANAGER_CUSTOM_CONFIG_MANAGER_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_CUSTOM_CONFIG_MANAGER_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace mindspore { -namespace lite { -class CustomConfigManager { - public: - CustomConfigManager() = default; - ~CustomConfigManager() = default; - - inline int AccessFile(const std::string &file_path, int access_mode) { - return access(file_path.c_str(), access_mode); - } - std::string RealPath(const char *path); - int Init(const std::map &dpico_config); - int UpdateConfig(const std::map &dpico_config); - bool IsEnableMultiModelSharingMemPrepare(const std::map &model_share_config); - bool IsEnableMultiModelSharingMem(const std::map &model_share_config); - float NmsThreshold() const { return nms_threshold_; } - float ScoreThreshold() const { return score_threshold_; } - float MinHeight() const { return min_height_; } - float MinWidth() const { return min_width_; } - int GTotalT() const { return g_total_t_; } - void SetGTotalT(size_t g_total_t) { g_total_t_ = g_total_t; } - bool NeedDetectPostProcess() const { return detect_post_process_; } - const std::string &AclConfigFile() const { return acl_config_file_; } - - private: - float nms_threshold_{0.9f}; - float score_threshold_{0.08f}; - float min_height_{1.0f}; - float min_width_{1.0f}; - size_t g_total_t_{0}; // user configuration is not supported - bool detect_post_process_{false}; - std::string acl_config_file_; - bool inited_{false}; -}; -using CustomConfigManagerPtr = std::shared_ptr; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_MANAGER_CUSTOM_CONFIG_MANAGER_H_ diff --git a/mindspore-lite/providers/dpico/src/custom_allocator.cc b/mindspore-lite/providers/dpico/src/custom_allocator.cc deleted file mode 100644 index 85c361bb..00000000 --- a/mindspore-lite/providers/dpico/src/custom_allocator.cc +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Copyright 2021-2022 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 "src/custom_allocator.h" -#include -#include -#include "include/svp_acl_rt.h" -#include "common/check_base.h" -#include "common/log_util.h" - -namespace mindspore { -namespace lite { -namespace { -size_t GetMaxMallocSize() { - static size_t max_malloc_size = - static_cast(sysconf(_SC_PHYS_PAGES)) * static_cast(sysconf(_SC_PAGESIZE)); - return max_malloc_size; -} -} // namespace -CustomAllocator::CustomAllocator(size_t aligned_size) { - aligned_size_ = aligned_size; - max_malloc_size_ = GetMaxMallocSize(); -} - -CustomAllocator::~CustomAllocator() { Clear(); } - -void CustomAllocator::SetContext(const AllocatorContext &ctx) { - lock_flag_ = ctx.lockFlag; - shift_factor_ = static_cast(ctx.shiftFactor); -} - -void CustomAllocator::Lock() { - if (lock_flag_) { - lock_.lock(); - } -} - -void CustomAllocator::UnLock() { - if (lock_flag_) { - lock_.unlock(); - } -} - -bool CustomAllocator::ReuseMemory(size_t free_size, size_t size) const { - return free_size >= size && - (free_size <= (size >= UINT32_MAX / (1ul << shift_factor_) ? UINT32_MAX : size << shift_factor_)); -} - -void *CustomAllocator::Malloc(size_t size) { - MS_CHECK_TRUE_MSG(size <= max_malloc_size_, nullptr, "MallocData out of max_size, size: " << size); - MS_CHECK_TRUE_MSG(total_size_ < max_malloc_size_, nullptr, "memory pool is exhausted"); - Lock(); - auto iter = free_list_.lower_bound(size); - if (iter != free_list_.end() && ReuseMemory(iter->second->size, size)) { - auto membuf = iter->second; - membuf->ref_count_ = 0; - (void)free_list_.erase(iter); - allocated_list_[membuf->buf] = membuf; - UnLock(); - return membuf->buf; - } - void *mem_ptr = nullptr; - int ret = svp_acl_rt_malloc_cached(&mem_ptr, sizeof(MemBuf) + size + aligned_size_, SVP_ACL_MEM_MALLOC_NORMAL_ONLY); - if (ret != SVP_ACL_SUCCESS) { - MS_LOG(ERROR) << "svp acl rt malloc cached failed."; - UnLock(); - return nullptr; - } - std::unique_ptr membuf(reinterpret_cast(mem_ptr)); - if (membuf == nullptr) { - MS_LOG(ERROR) << "malloc membuf return nullptr"; - UnLock(); - return nullptr; - } - this->total_size_ += size; - membuf->ref_count_ = 0; - membuf->size = size; - membuf->buf = reinterpret_cast( - (reinterpret_cast(membuf.get()) + sizeof(MemBuf) + aligned_size_ - 1) & (~(aligned_size_ - 1))); - auto buf_ptr = membuf->buf; - allocated_list_[buf_ptr] = membuf.release(); - UnLock(); - return buf_ptr; -} - -void CustomAllocator::Free(void *buf) { - if (buf == nullptr) { - return; - } - Lock(); - auto iter = allocated_list_.find(buf); - if (iter != allocated_list_.end()) { - auto membuf = iter->second; - membuf->ref_count_ = 0; - (void)allocated_list_.erase(iter); - (void)free_list_.insert(std::make_pair(membuf->size, membuf)); - UnLock(); - return; - } - UnLock(); - int ret = svp_acl_rt_free(buf); - MS_CHECK_TRUE_MSG_VOID(ret == SVP_ACL_SUCCESS, "svp acl rt free failed."); - buf = nullptr; -} - -int CustomAllocator::RefCount(void *buf) { - if (buf == nullptr) { - return -1; - } - Lock(); - auto iter = allocated_list_.find(buf); - if (iter != allocated_list_.end()) { - auto membuf = iter->second; - int ref_count = std::atomic_load(&membuf->ref_count_); - UnLock(); - return ref_count; - } - UnLock(); - return -1; -} -int CustomAllocator::SetRefCount(void *buf, int ref_count) { - if (buf == nullptr) { - return -1; - } - Lock(); - auto iter = allocated_list_.find(buf); - if (iter != allocated_list_.end()) { - auto membuf = iter->second; - std::atomic_store(&membuf->ref_count_, ref_count); - UnLock(); - return ref_count; - } - UnLock(); - return -1; -} -int CustomAllocator::IncRefCount(void *buf, int ref_count) { - if (buf == nullptr) { - return -1; - } - Lock(); - auto iter = allocated_list_.find(buf); - if (iter != allocated_list_.end()) { - auto membuf = iter->second; - auto ref = std::atomic_fetch_add(&membuf->ref_count_, ref_count); - UnLock(); - return (ref + ref_count); - } - UnLock(); - return -1; -} -int CustomAllocator::DecRefCount(void *buf, int ref_count) { - if (buf == nullptr) { - return -1; - } - Lock(); - auto iter = allocated_list_.find(buf); - if (iter != allocated_list_.end()) { - auto membuf = iter->second; - auto ref = std::atomic_fetch_sub(&membuf->ref_count_, ref_count); - UnLock(); - return (ref - ref_count); - } - UnLock(); - return -1; -} -void CustomAllocator::Clear() { - Lock(); - int ret; - for (auto &it : allocated_list_) { - ret = svp_acl_rt_free(it.second); - MS_CHECK_TRUE_MSG_VOID(ret == SVP_ACL_SUCCESS, "svp acl rt free failed."); - it.second = nullptr; - } - allocated_list_.clear(); - - for (auto &it : free_list_) { - ret = svp_acl_rt_free(it.second); - MS_CHECK_TRUE_MSG_VOID(ret == SVP_ACL_SUCCESS, "svp acl rt free failed."); - it.second = nullptr; - } - free_list_.clear(); - UnLock(); -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/src/custom_allocator.h b/mindspore-lite/providers/dpico/src/custom_allocator.h deleted file mode 100644 index dd6ec6d1..00000000 --- a/mindspore-lite/providers/dpico/src/custom_allocator.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright 2021-2022 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_PROVIDERS_DPICO_SRC_CUSTOM_ALLOCATOR_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_ALLOCATOR_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "include/api/allocator.h" - -namespace mindspore { -namespace lite { -struct AllocatorContext { - int shiftFactor; - bool lockFlag; -}; - -class CustomAllocator : public Allocator { - public: - explicit CustomAllocator(size_t aligned_size = 32); - ~CustomAllocator() override; - void SetContext(const AllocatorContext &ctx); - void *Malloc(size_t size) override; - void Free(void *ptr) override; - int RefCount(void *ptr) override; - int SetRefCount(void *ptr, int ref_count) override; - int DecRefCount(void *ptr, int ref_count) override; - int IncRefCount(void *ptr, int ref_count) override; - size_t total_size() const { return this->total_size_; } - void Clear(); - - private: - void Lock(); - void UnLock(); - bool ReuseMemory(size_t free_size, size_t size) const; - struct MemBuf { - std::atomic_int ref_count_ = {0}; - size_t size = 0; - void *buf = nullptr; - }; - - std::mutex lock_; - size_t total_size_ = 0; - // buf, membuf> - std::unordered_map allocated_list_; - std::multimap free_list_; - // 6 is empirical value - unsigned shift_factor_ = 6; - bool lock_flag_ = true; - size_t max_malloc_size_ = 0; -}; -using CustomAllocatorPtr = std::shared_ptr; -constexpr int64_t MAX_MALLOC_SIZE = static_cast(2000) * 1024 * 1024; -constexpr int64_t MAX_THREAD_POOL_SIZE = static_cast(3000) * 1024 * 1024; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_ALLOCATOR_H_ diff --git a/mindspore-lite/providers/dpico/src/custom_fp32.cc b/mindspore-lite/providers/dpico/src/custom_fp32.cc deleted file mode 100644 index 1781f051..00000000 --- a/mindspore-lite/providers/dpico/src/custom_fp32.cc +++ /dev/null @@ -1,297 +0,0 @@ -/** - * Copyright 2021-2023 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 "src/custom_fp32.h" -#include -#include -#include -#include -#include "common/check_base.h" -#include "common/infer_util.h" -#include "common/op_attr.h" -#include "include/api/data_type.h" -#include "include/registry/register_kernel.h" -#include "include/registry/register_kernel_interface.h" - -namespace mindspore { -namespace lite { -constexpr size_t kNumOfInputOm = 1; - -bool CustomCPUKernel::InferShapeDone() const { - if (std::any_of(inputs_.begin(), inputs_.end(), [](const MSTensor &input) { - return input.DataType() == mindspore::DataType::kObjectTypeTensorType; - })) { - return false; - } - auto shape = outputs_.front().Shape(); - return !(std::find(shape.begin(), shape.end(), -1) != shape.end()); -} - -size_t DataTypeSize(mindspore::DataType data_type) { - switch (data_type) { - case mindspore::DataType::kNumberTypeFloat64: - return sizeof(double); - case mindspore::DataType::kNumberTypeFloat32: - return sizeof(float); - case mindspore::DataType::kNumberTypeInt8: - return sizeof(int8_t); - case mindspore::DataType::kNumberTypeUInt8: - return sizeof(uint8_t); - case mindspore::DataType::kNumberTypeFloat16: - case mindspore::DataType::kNumberTypeInt16: - return sizeof(int16_t); - case mindspore::DataType::kNumberTypeInt32: - return sizeof(int32_t); - case mindspore::DataType::kNumberTypeInt64: - return sizeof(int64_t); - case mindspore::DataType::kNumberTypeUInt16: - return sizeof(uint16_t); - case mindspore::DataType::kNumberTypeUInt32: - return sizeof(uint32_t); - case mindspore::DataType::kNumberTypeUInt64: - return sizeof(uint64_t); - case mindspore::DataType::kNumberTypeBool: - return sizeof(bool); - case mindspore::DataType::kObjectTypeString: - return sizeof(char); - case mindspore::DataType::kObjectTypeTensorType: - return 0; - default: - MS_LOG(ERROR) << "Not support the type: " << static_cast(data_type); - return 0; - } -} - -void CustomCPUKernel::UpdateInputOutputTensor() { - if (custom_id_ == 0) { - for (size_t i = 0; i < inputs_.size() - kNumOfInputOm; i++) { - std::vector shape = inputs_[i].Shape(); - if (shape.empty()) { - MS_LOG(ERROR) << "Input[" << i << "]`s shape is empty."; - return; - } - size_t shape_len = shape.size(); - size_t data_type_size = DataTypeSize(inputs_[i].DataType()); - if (data_type_size == 0) { - MS_LOG(ERROR) << "data type size is 0."; - return; - } - int64_t last_dim_size = shape[shape_len - 1] * data_type_size; - MS_LOG(DEBUG) << "Input last_dim = " << shape[shape_len - 1]; - if (last_dim_size % stride_align_size_ != 0) { - last_dim_size = (last_dim_size + stride_align_size_ - 1) & (~(stride_align_size_ - 1)); - int64_t last_dim_new = last_dim_size / data_type_size; - MS_LOG(DEBUG) << "Input new last_dim = " << last_dim_new; - shape[shape_len - 1] = last_dim_new; - inputs_[i].SetShape(shape); - } - } - } - if (custom_id_ == custom_num_ - 1) { - for (size_t i = 0; i < outputs_.size(); i++) { - auto shape = outputs_[i].Shape(); - if (shape.empty()) { - MS_LOG(ERROR) << "Output[" << i << "]`s shape is empty."; - return; - } - size_t shape_len = shape.size(); - size_t data_type_size = DataTypeSize(outputs_[i].DataType()); - if (data_type_size == 0) { - MS_LOG(ERROR) << "data type size is 0."; - return; - } - int64_t last_dim_size = shape[shape_len - 1] * data_type_size; - MS_LOG(DEBUG) << "Output last_dim = " << shape[shape_len - 1]; - if (last_dim_size % stride_align_size_ != 0) { - last_dim_size = (last_dim_size + stride_align_size_ - 1) & (~(stride_align_size_ - 1)); - int64_t last_dim_new = last_dim_size / data_type_size; - MS_LOG(DEBUG) << "Output new last_dim = " << last_dim_new; - shape[shape_len - 1] = last_dim_new; - outputs_[i].SetShape(shape); - } - } - } -} - -int CustomCPUKernel::ParseAttrs() { - std::map attrs; - std::string internal_stride; - std::string custom_id; - std::string custom_num; - std::string head_tail_op_is_custom; - - if (FetchAttrs(*primitive_, &attrs) == kSuccess) { - if (attrs.find("head_tail_op_is_custom") != attrs.end()) { - head_tail_op_is_custom = attrs.at("head_tail_op_is_custom"); - if (head_tail_op_is_custom != "1") { - MS_LOG(ERROR) << "When setting 'SupportZeroCopy=on', " - << "you must ensure that the first and last operators are custom operators."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "Get head_tail_op_is_custom failed."; - return RET_ERROR; - } - if (attrs.find(kLastDimStride) != attrs.end()) { - internal_stride = attrs.at(kLastDimStride); - } else { - MS_LOG(ERROR) << "Get internal_stride failed."; - return RET_ERROR; - } - if (attrs.find("custom_id") != attrs.end()) { - custom_id = attrs.at("custom_id"); - } else { - MS_LOG(ERROR) << "Get custom_id failed."; - return RET_ERROR; - } - if (attrs.find("custom_num") != attrs.end()) { - custom_num = attrs.at("custom_num"); - } else { - MS_LOG(ERROR) << "Get custom_num failed."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "Fetch attrs failed."; - return RET_ERROR; - } - - stride_align_size_ = static_cast(stoi(internal_stride)); - custom_id_ = static_cast(stoi(custom_id)); - custom_num_ = static_cast(stoi(custom_num)); - return RET_OK; -} - -int CustomCPUKernel::Prepare() { - CHECK_LESS_RETURN(inputs_.size(), kInputSize2); - CHECK_LESS_RETURN(outputs_.size(), 1); - if (acl_model_manager_ == nullptr) { - acl_model_manager_ = std::make_shared(); - MS_CHECK_TRUE_MSG(acl_model_manager_ != nullptr, RET_ERROR, "Acl_model_manager_ is nullptr"); - } - - std::map config_info = this->GetConfig(kDpico); - // init model manager - if (acl_model_manager_->Init(config_info, this->GetConfig(kModelSharingSection), primitive_, inputs_, outputs_) != - RET_OK) { - MS_LOG(ERROR) << "Init acl model manager failed."; - return RET_ERROR; - } - - if (!InferShapeDone()) { - MS_LOG(INFO) << "Infershape isn't done, skip this procedure"; - return RET_OK; - } - - if (config_info.find(kSupportZeroCopy) != config_info.end()) { - if (config_info[kSupportZeroCopy] == "on") { - support_zero_copy_ = "on"; - MS_LOG(INFO) << "Set 'SupportZeroCopy=on', will support zero copy."; - } else { - MS_LOG(INFO) << "Do not set 'SupportZeroCopy=on', will not support zero copy."; - } - } else { - MS_LOG(INFO) << "Do not set 'SupportZeroCopy', will not support zero copy."; - } - - if (support_zero_copy_ == "on") { - if (ParseAttrs() != RET_OK) { - MS_LOG(ERROR) << "Parse attrs failed or the attr is invalid."; - return RET_ERROR; - } - UpdateInputOutputTensor(); - } - if (acl_model_manager_->UpdateBatchSize(inputs_) != RET_OK) { - MS_LOG(ERROR) << "Update batch size for acl model manager failed."; - return RET_ERROR; - } - if (acl_model_manager_->PrepareAclInputs(&inputs_) != RET_OK) { - MS_LOG(ERROR) << "Prepare inputs for acl model manager failed."; - return RET_ERROR; - } - if (acl_model_manager_->PrepareAclOutputs(&outputs_) != RET_OK) { - MS_LOG(ERROR) << "Prepare outputs for acl model manager failed."; - return RET_ERROR; - } - return RET_OK; -} - -int CustomCPUKernel::ReSize() { - if (!InferShapeDone()) { - auto custom_kernel_interface = registry::RegisterKernelInterface::GetKernelInterface("", primitive_, this); - MS_CHECK_TRUE_MSG(custom_kernel_interface != nullptr, RET_ERROR, "Get custom kernel interface failed."); - auto status = custom_kernel_interface->Infer(&inputs_, &outputs_, primitive_, this); - MS_CHECK_TRUE_MSG(status == kSuccess, RET_ERROR, "Custom op infershape failed. " << this->name()); - } - if (support_zero_copy_ == "on") { - UpdateInputOutputTensor(); - } - if (acl_model_manager_->UpdateBatchSize(inputs_) != RET_OK) { - MS_LOG(ERROR) << "Update batch size for acl model manager failed."; - return RET_ERROR; - } - - auto ret = acl_model_manager_->UpdateKernelConfig(this->GetConfig(kDpico)); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "Acl model manager update kernel config failed."); - ret = acl_model_manager_->UpdateAclInputs(&inputs_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "Acl model manager update inputs failed."); - ret = acl_model_manager_->UpdateAclOutputs(&outputs_); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "Acl model manager update outputs failed."); - return RET_OK; -} - -int CustomCPUKernel::Execute() { - // reallocate memory for output data - for (auto output : outputs_) { - auto data = output.MutableData(); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "Output tensor data is nullptr. " << output.Name()); - } - if (acl_model_manager_->Execute(inputs_, outputs_, this->GetConfig(kModelSharingSection)) != RET_OK) { - MS_LOG(ERROR) << "Acl model manager execute failed."; - return RET_ERROR; - } - return RET_OK; -} - -std::shared_ptr CustomCreateKernel(const std::vector &inputs, - const std::vector &outputs, - const mindspore::schema::Primitive *primitive, - const mindspore::Context *ctx) { - MS_CHECK_TRUE_MSG(primitive != nullptr, nullptr, "Primitive is nullptr"); - MS_CHECK_TRUE_MSG(ctx != nullptr, nullptr, "Ctx is nullptr"); - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - MS_LOG(ERROR) << "Primitive type is not PrimitiveType_Custom"; - return nullptr; - } - - auto op = primitive->value_as_Custom(); - MS_CHECK_TRUE_MSG(op != nullptr, nullptr, "Op is nullptr"); - MS_CHECK_TRUE_MSG(op->attr() != nullptr, nullptr, "Op attr is nullptr"); - MS_CHECK_TRUE_MSG(op->attr()->size() >= 1, nullptr, "There should be at least 1 attribute of Custom"); - auto kernel = std::make_shared(inputs, outputs, primitive, ctx); - MS_CHECK_TRUE_MSG(kernel != nullptr, nullptr, "New custom kernel is nullptr"); - return kernel; -} - -namespace { -const auto kFloat32 = DataType::kNumberTypeFloat32; -const auto kInt8 = DataType::kNumberTypeInt8; -const auto kUInt8 = DataType::kNumberTypeUInt8; -} // namespace -REGISTER_CUSTOM_KERNEL(CPU, DPICO, kFloat32, DPICO, CustomCreateKernel) -REGISTER_CUSTOM_KERNEL(CPU, DPICO, kInt8, DPICO, CustomCreateKernel) -REGISTER_CUSTOM_KERNEL(CPU, DPICO, kUInt8, DPICO, CustomCreateKernel) -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/providers/dpico/src/custom_fp32.h b/mindspore-lite/providers/dpico/src/custom_fp32.h deleted file mode 100644 index b5a53bb5..00000000 --- a/mindspore-lite/providers/dpico/src/custom_fp32.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2021-2022 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_PROVIDERS_DPICO_SRC_CUSTOM_FP32_H_ -#define MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_FP32_H_ - -#include -#include -#include "include/api/kernel.h" -#include "include/errorcode.h" -#include "manager/acl_model_manager.h" - -using mindspore::kernel::Kernel; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace lite { -class CustomCPUKernel : public Kernel { - public: - CustomCPUKernel(const std::vector &inputs, const std::vector &outputs, - const mindspore::schema::Primitive *primitive, const mindspore::Context *ctx) - : Kernel(inputs, outputs, primitive, ctx) {} - - ~CustomCPUKernel() = default; - - int Prepare() override; - int ReSize() override; - int Execute() override; - - private: - int ParseAttrs(); - bool InferShapeDone() const; - int PreProcess(); - void UpdateInputOutputTensor(); - - private: - AclModelManagerPtr acl_model_manager_{nullptr}; - std::string support_zero_copy_{"off"}; - size_t stride_align_size_{16}; - size_t custom_id_{0}; - size_t custom_num_{0}; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_DPICO_SRC_CUSTOM_FP32_H_ diff --git a/mindspore-lite/providers/nnie/CMakeLists.txt b/mindspore-lite/providers/nnie/CMakeLists.txt deleted file mode 100644 index dded6b8b..00000000 --- a/mindspore-lite/providers/nnie/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -cmake_minimum_required(VERSION 3.12) -project(NNIE_Custom) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -if(${MSLITE_REGISTRY_DEVICE} STREQUAL "Hi3516D") - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_patry/hi3516_sdk/) - link_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_patry/hi3516_sdk/lib) -elseif(${MSLITE_REGISTRY_DEVICE} STREQUAL "Hi3519A") - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_patry/hi3519_sdk/) - link_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_patry/hi3519_sdk/lib) -elseif(${MSLITE_REGISTRY_DEVICE} STREQUAL "Hi3559A") - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_patry/hi3559_sdk/) - link_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_patry/hi3559_sdk/lib) -endif() -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime/include/third_party) - - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src COMMON_SRC3) - -set(MSLITE_NNIE_LINK_LIB nnie mpi VoiceEngine upvqe dnvqe) - -add_library(mslite_nnie SHARED - ${COMMON_SRC3} - ${CMAKE_CURRENT_SOURCE_DIR}/../../src/litert/cxx_api/kernel.cc - ${CMAKE_CURRENT_SOURCE_DIR}/../../src/registry/kernel_interface_registry.cc) -target_link_libraries(mslite_nnie ${MSLITE_NNIE_LINK_LIB} mindspore::securec) - diff --git a/mindspore-lite/providers/nnie/src/custom_allocator.h b/mindspore-lite/providers/nnie/src/custom_allocator.h deleted file mode 100644 index 444552e8..00000000 --- a/mindspore-lite/providers/nnie/src/custom_allocator.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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_PROVIDERS_NNIE_SRC_CUSTOM_ALLOCATOR_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_ALLOCATOR_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "include/api/allocator.h" -#include "include/hi_type.h" - -namespace mindspore { -namespace nnie { -class CustomAllocator : public Allocator { - public: - CustomAllocator() {} - ~CustomAllocator() override{}; - void *Malloc(size_t size) override { return nullptr; } - void Free(void *ptr) override {} - int RefCount(void *ptr) override { return 1; } - int SetRefCount(void *ptr, int ref_count) override { return ref_count; } - int DecRefCount(void *ptr, int ref_count) override { return 1; } - int IncRefCount(void *ptr, int ref_count) override { return 1; } -}; -} // namespace nnie -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_ALLOCATOR_H_ diff --git a/mindspore-lite/providers/nnie/src/custom_fp32.cc b/mindspore-lite/providers/nnie/src/custom_fp32.cc deleted file mode 100644 index 5ddebc36..00000000 --- a/mindspore-lite/providers/nnie/src/custom_fp32.cc +++ /dev/null @@ -1,198 +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 "src/custom_fp32.h" -#include -#include -#include "schema/model_generated.h" -#include "include/registry/register_kernel.h" -#include "include/errorcode.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace nnie { -static std::shared_ptr kCustomAllocator = std::make_shared(); - -int CustomCPUKernel::Prepare() { - if ((manager_) == nullptr) { - LOGE("manager_ is nullptr."); - return RET_ERROR; - } - if (!manager_->GetLoadModel()) { - if (manager_->GetFlags()->Init(*this) != RET_OK) { - LOGE("Nnie config init fail."); - return RET_ERROR; - } - if (manager_->CfgInit(*manager_->GetFlags(), manager_->GetMaxSegId()) != RET_OK) { - LOGE("Nnie init cfg fail."); - return RET_ERROR; - } - - if (manager_->Init(reinterpret_cast(inputs_[inputs_.size() - 1].MutableData()), - static_cast(inputs_[inputs_.size() - 1].ElementNum()), inputs_)) { - LOGI("Load WK Model Fail."); - return RET_OK; - } - manager_->SetLoadModel(true); - } - outputs_shapes_.resize(outputs_.size()); - for (size_t i = 0; i < outputs_.size(); i++) { - outputs_shapes_[i] = outputs_[i].Shape(); - } - return RET_OK; -} - -int CustomCPUKernel::ReSize() { - if (manager_->GetLoadModel() && seg_id() == 0) { - manager_->Release(true); - manager_->SetLoadModel(false); - } - - return Prepare(); -} - -int CustomCPUKernel::Execute() { - if (!manager_->GetLoadModel()) { - LOGE("WK Model is not load."); - return RET_ERROR; - } - Flags *flags = manager_->GetFlags(); - if (flags->keep_origin_output_) { - if (seg_id_ == 0) { - if (manager_->LoadInputs(&inputs_, kCustomAllocator) != RET_OK) { - LOGE("Unable to find the physical address corresponding to the input tensor."); - return RET_ERROR; - } - } - if (seg_id_ == manager_->GetMaxSegId()) { - if (manager_->LoadOutputs(&outputs_, kCustomAllocator) != RET_OK) { - LOGE("Unable to find the physical address corresponding to the output tensor."); - return RET_ERROR; - } - } - } - - if (manager_->FillData(&inputs_, seg_id_) != RET_OK) { - LOGE("Fail Fill Data."); - return RET_ERROR; - } - - if (manager_->Run(&outputs_, seg_id_, outputs_shapes_) != RET_OK) { - LOGE("Fail WK Run."); - return RET_ERROR; - } - return RET_OK; -} - -CustomCPUKernel::~CustomCPUKernel() { - if (manager_->GetLoadModel()) { - manager_->Release(false); - manager_->SetLoadModel(false); - } -} - -bool GetCustomAttr(char *buf, int buf_size, const mindspore::schema::Custom *op, const std::string &attr) { - int attr_size; - for (size_t i = 0; i < op->attr()->size(); i++) { - if (op->attr()->Get(i)->name()->str() == attr) { - auto output_info = op->attr()->Get(i)->data(); - attr_size = static_cast(output_info->size()); - if (attr_size >= buf_size) { - LOGE("attr size too big."); - return false; - } - for (int j = 0; j < attr_size; j++) { - buf[j] = static_cast(output_info->Get(j)); - } - buf[attr_size] = 0; - return true; - } - } - return false; -} - -std::shared_ptr CustomCreateKernel(const std::vector &inputs, - const std::vector &outputs, - const mindspore::schema::Primitive *primitive, - const mindspore::Context *ctx) { - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - LOGE("Primitive type is not PrimitiveType_Custom."); - return nullptr; - } - - auto op = primitive->value_as_Custom(); - if (op->attr()->size() < 1) { - LOGE("There are at least 1 attribute of Custom."); - return nullptr; - } - - int64_t ndims; - bool forward_bbox = false; - char *res = nullptr; - char buf[kMaxSize]; - if (GetCustomAttr(buf, kMaxSize, op, "id")) { - res = nullptr; - ndims = strtol(buf, &res, kDecimal); - if ((*res) != 0) { - LOGE("Get attr id data fail"); - return nullptr; - } - } else { - LOGE("Custom op should have id"); - return nullptr; - } - - if (GetCustomAttr(buf, kMaxSize, op, "ForwardWithBbox")) { - res = nullptr; - int64_t temp_val = strtol(buf, &res, kDecimal); - if ((*res) != 0) { - LOGE("Get attr ForwardWithBbox data fail"); - return nullptr; - } - if (temp_val > 0) { - forward_bbox = true; - } - } - auto model_buf = static_cast(inputs[inputs.size() - 1].Data().get()); - auto manager = nnie::NNIEManager::GetInstance(model_buf); - if ((manager) == nullptr) { - LOGE("malloc NNIEManager failed."); - return nullptr; - } - auto kernel = std::make_shared(manager, ndims, forward_bbox, inputs, outputs, primitive, ctx); - if (kernel == nullptr) { - LOGE("new custom kernel is nullptr"); - return nullptr; - } - return kernel; -} -} // namespace nnie -} // namespace mindspore -namespace mindspore { -namespace registry { -namespace { -const auto kFloat32 = DataType::kNumberTypeFloat32; -const auto kInt8 = DataType::kNumberTypeInt8; -const auto kUint8 = DataType::kNumberTypeUInt8; -} // namespace -REGISTER_CUSTOM_KERNEL(CPU, NNIE, kFloat32, NNIE, nnie::CustomCreateKernel) -REGISTER_CUSTOM_KERNEL(CPU, NNIE, kInt8, NNIE, nnie::CustomCreateKernel) -REGISTER_CUSTOM_KERNEL(CPU, NNIE, kUint8, NNIE, nnie::CustomCreateKernel) -} // namespace registry -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/custom_fp32.h b/mindspore-lite/providers/nnie/src/custom_fp32.h deleted file mode 100644 index 4e4acf4e..00000000 --- a/mindspore-lite/providers/nnie/src/custom_fp32.h +++ /dev/null @@ -1,71 +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_PROVIDERS_NNIE_SRC_CUSTOM_FP32_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_FP32_H_ - -#include -#include -#include -#include "include/schema/model_generated.h" -#include "include/api/kernel.h" -#include "src/custom_infer.h" -#include "include/hi_type.h" -#include "src/nnie_cfg_parser.h" -#include "src/nnie_manager.h" -#include "src/nnie_print.h" -#include "src/custom_allocator.h" - -using mindspore::MSTensor; -using mindspore::kernel::Kernel; -namespace mindspore { -namespace nnie { -class CustomCPUKernel : public Kernel { - public: - CustomCPUKernel(nnie::NNIEManager *manager, int seg_id, bool forward_bbox, const std::vector &inputs, - const std::vector &outputs, const mindspore::schema::Primitive *primitive, - const mindspore::Context *ctx) - : Kernel(inputs, outputs, primitive, ctx), manager_(manager), seg_id_(seg_id), forward_bbox_(forward_bbox) { - if ((manager_) == nullptr) { - LOGE("manager_ is nullptr."); - } else { - manager_->SetMaxSegId(seg_id); - } - } - - ~CustomCPUKernel() override; - - int Prepare() override; - int ReSize() override; - int Execute() override; - - int seg_id(void) const { return seg_id_; } - - void set_seg_id(int id) { seg_id_ = id; } - - int forward_bbox(void) const { return forward_bbox_; } - - void set_forward_bbox(bool flag) { forward_bbox_ = flag; } - - private: - nnie::NNIEManager *manager_ = nullptr; - int seg_id_ = 0; - bool forward_bbox_ = false; - std::vector> outputs_shapes_; -}; -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_FP32_H_ diff --git a/mindspore-lite/providers/nnie/src/custom_infer.cc b/mindspore-lite/providers/nnie/src/custom_infer.cc deleted file mode 100644 index 08a58700..00000000 --- a/mindspore-lite/providers/nnie/src/custom_infer.cc +++ /dev/null @@ -1,166 +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 "src/custom_infer.h" -#include -#include -#include "include/errorcode.h" -#include "src/nnie_print.h" -#include "include/api/format.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace nnie { -std::shared_ptr CustomInferCreater() { - auto infer = new (std::nothrow) CustomInterface(); - if (infer == nullptr) { - LOGE("new custom infer is nullptr"); - return nullptr; - } - return std::shared_ptr(infer); -} - -int GetCustomShape(const mindspore::schema::Custom *op, const std::string &attr, - std::vector> *shapes) { - char buf[kMaxSize]; - bool has_outputs_shape = false; - - for (size_t i = 0; i < op->attr()->size(); i++) { - if (op->attr()->Get(i)->name()->str() == attr) { - auto output_info = op->attr()->Get(i)->data(); - int attr_size = static_cast(output_info->size()); - if (attr_size >= kMaxSize) { - LOGE("attr size too big"); - return RET_ERROR; - } - for (int j = 0; j < attr_size; j++) { - buf[j] = static_cast(output_info->Get(j)); - } - buf[attr_size] = 0; - has_outputs_shape = true; - break; - } - } - - if (!has_outputs_shape) { - LOGE("Custom op don't have %s attr.", attr.c_str()); - return RET_ERROR; - } - - char delims[] = ","; - char *res = nullptr; - char *save_ptr = nullptr; - res = strtok_r(buf, delims, &save_ptr); - while (res != nullptr) { - int64_t ndims = strtol(res, &res, kDecimal); - int j = 0; - std::vector shape; - shape.resize(ndims); - for (; j < ndims; j++) { - res = strtok_r(NULL, delims, &save_ptr); - shape[j] = static_cast(strtol(res, &res, kDecimal)); - } - shapes->push_back(shape); - - res = strtok_r(NULL, delims, &save_ptr); - } - return RET_OK; -} - -Status CustomInterface::Infer(std::vector *inputs, std::vector *outputs, - const mindspore::schema::Primitive *primitive) { - auto check_param = inputs != nullptr && outputs != nullptr && primitive != nullptr; - if (!check_param) { - LOGE("inputs, outputs or primitive is null"); - return kLiteError; - } - if (inputs->empty()) { - LOGE("Inputs size 0"); - return kLiteError; - } - if (outputs->empty()) { - LOGE("Outputs size 0"); - return kLiteError; - } - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - LOGE("Primitive type is not PrimitiveType_Custom"); - return kLiteError; - } - - auto op = primitive->value_as_Custom(); - if ((op == nullptr) || (op->attr() == nullptr)) { - LOGE("op or its attr is null"); - return kLiteError; - } - if (op->attr()->size() < 1) { - LOGE("There are at least 1 attribute of Custom"); - return kLiteError; - } - std::vector> inputs_shape; - if (GetCustomShape(op, "inputs_shape", &inputs_shape) != RET_OK) { - LOGE("parser inputs_shape attribute err."); - return kLiteError; - } - std::vector> outputs_shape; - if (GetCustomShape(op, "outputs_shape", &outputs_shape) != RET_OK) { - LOGE("parser outputs_shape attribute err."); - return kLiteError; - } - if (inputs_shape.size() != (inputs->size() - 1)) { - LOGE("inputs num diff inputs_shape num."); - return kLiteError; - } - if (inputs_shape[0].size() != (*inputs)[0].Shape().size()) { - LOGE("shape size err."); - return kLiteError; - } - bool resize_flag = false; - int resize_num = 1; - for (size_t i = 0; i < inputs_shape[0].size(); i++) { - if (inputs_shape[0][i] != (*inputs)[0].Shape()[i]) { - if (i == 0) { - resize_flag = true; - resize_num = (*inputs)[0].Shape()[i]; - } else { - LOGE("Custom of NNIE only support batch_num resize."); - return kLiteError; - } - } - } - if (resize_flag) { - for (auto &output_shape : outputs_shape) { - output_shape[0] = resize_num; - } - } - for (size_t i = 0; i < outputs->size(); i++) { - (*outputs)[i].SetShape(outputs_shape[i]); - (*outputs)[i].SetDataType(DataType::kNumberTypeFloat32); - (*outputs)[i].SetFormat(Format::NCHW); - } - return kSuccess; -} -} // namespace nnie -} // namespace mindspore -namespace mindspore { -namespace kernel { -REGISTER_CUSTOM_KERNEL_INTERFACE(NNIE, NNIE, nnie::CustomInferCreater); -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/custom_infer.h b/mindspore-lite/providers/nnie/src/custom_infer.h deleted file mode 100644 index ec9ddc0a..00000000 --- a/mindspore-lite/providers/nnie/src/custom_infer.h +++ /dev/null @@ -1,35 +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_PROVIDERS_NNIE_SRC_CUSTOM_INFER_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_INFER_H_ -#include -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace nnie { -class CustomInterface : public mindspore::kernel::KernelInterface { - public: - CustomInterface() {} - - ~CustomInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const mindspore::schema::Primitive *primitive) override; -}; -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_CUSTOM_INFER_H_ diff --git a/mindspore-lite/providers/nnie/src/nnie_cfg_parser.cc b/mindspore-lite/providers/nnie/src/nnie_cfg_parser.cc deleted file mode 100644 index c88a1312..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_cfg_parser.cc +++ /dev/null @@ -1,117 +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 "src/nnie_cfg_parser.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "include/errorcode.h" -#include "src/nnie_manager.h" -#include "src/nnie_print.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace nnie { -namespace { -constexpr auto kTimeStep = "TimeStep"; -constexpr auto kMazRoiNum = "MaxROINum"; -constexpr auto kCoreIds = "CoreIds"; -constexpr auto kKeepOrigin = "KeepOriginalOutput"; -constexpr auto DELIM = ","; -constexpr int MAX_CORE_ID = 7; -} // namespace -bool IsValidUnsignedNum(const std::string &num_str) { - return !num_str.empty() && std::all_of(num_str.begin(), num_str.end(), ::isdigit); -} - -void PrintInvalidChar(const std::string &key, const std::string &dat) { - auto message = key + " configuration contains invalid characters: \'" + dat + "\'"; - LOGE(message.c_str()); -} - -int Flags::ParserInt(const std::map &nnie_arg, const std::string key, int *val) { - auto iter = nnie_arg.find(key); - if (iter != nnie_arg.end()) { - auto str = iter->second; - if (IsValidUnsignedNum(str) == true) { - *val = stoi(str); - } else { - PrintInvalidChar(key, str); - return RET_ERROR; - } - } - return RET_OK; -} - -int Flags::ParserBool(const std::map &nnie_arg, const std::string key, bool *val) { - auto iter = nnie_arg.find(key); - if (iter != nnie_arg.end()) { - auto str = iter->second; - if (str == "on") { - *val = true; - } else if (str == "off") { - *val = false; - } else { - PrintInvalidChar(key, str); - return RET_ERROR; - } - } - return RET_OK; -} - -int Flags::Init(const kernel::Kernel &kernel) { - auto nnie_arg = kernel.GetConfig("nnie"); - if (ParserInt(nnie_arg, kTimeStep, &this->time_step_) != RET_OK) { - return RET_ERROR; - } - - if (ParserInt(nnie_arg, kMazRoiNum, &this->max_roi_num_) != RET_OK) { - return RET_ERROR; - } - - if (ParserBool(nnie_arg, kKeepOrigin, &this->keep_origin_output_) != RET_OK) { - return RET_ERROR; - } - - if (nnie_arg.find(kCoreIds) != nnie_arg.end()) { - auto ids = nnie_arg.at(kCoreIds); - if (!ids.empty() && std::all_of(ids.begin(), ids.end(), [](char val) { return ::isdigit(val) || val == ','; })) { - size_t index = 0; - std::vector core_ids; - while (!ids.empty()) { - core_ids.push_back(std::stoi(ids, &index)); - if (index < ids.length()) { - ids = ids.substr(index + 1); - } else { - break; - } - } - this->core_ids_ = core_ids; - } else { - PrintInvalidChar(kCoreIds, ids); - return RET_ERROR; - } - } - - return RET_OK; -} -} // namespace nnie -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/nnie_cfg_parser.h b/mindspore-lite/providers/nnie/src/nnie_cfg_parser.h deleted file mode 100644 index 92875bc1..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_cfg_parser.h +++ /dev/null @@ -1,57 +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_PROVIDERS_NNIE_SRC_NNIE_CFG_PARSER_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_CFG_PARSER_H_ -#include -#include -#include -#include "include/api/kernel.h" -#include "include/hi_type.h" - -namespace mindspore { -namespace nnie { -typedef struct { - HI_U64 phy_; - HI_U32 size_; -} MEM_ITEM; -/** - * Flags is a config container. - * Member objects: - * 1.time_step_: step num only for rnn or lstm model. Default is 1. - * 2.max_roi_num_: maximum number of ROI area, which is single picture supports, must be greater than 0.Default is 300. - * 3.core_ids_: running kernels' id, support multi-core, separated by commas when setting, such as {0, 1, 2}. - * each element must be an integer, wch meet such inequality 0 <= val < 8. - * Default is {0}. - */ -class Flags { - public: - Flags() = default; - ~Flags() = default; - int Init(const kernel::Kernel &kernel); - - public: - int time_step_{1}; - int max_roi_num_{300}; - std::vector core_ids_{0}; - bool keep_origin_output_{false}; - - private: - int ParserInt(const std::map &nnie_arg, const std::string key, int *val); - int ParserBool(const std::map &nnie_arg, const std::string key, bool *val); -}; -} // namespace nnie -} // namespace mindspore -#endif diff --git a/mindspore-lite/providers/nnie/src/nnie_common.cc b/mindspore-lite/providers/nnie/src/nnie_common.cc deleted file mode 100644 index 135bd899..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_common.cc +++ /dev/null @@ -1,972 +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 "src/nnie_common.h" -#include "include/mpi_nnie.h" -#include "include/hi_type.h" -#include "include/errorcode.h" -#include "src/nnie_print.h" -#include "src/nnie_memory.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace nnie { -constexpr int kSleepUs = 100; -constexpr int kCompressionWidth = 2; -static void NnieParamRelease(NnieParam *nnie_param) { - if (nnie_param == nullptr) { - return; - } - - if (nnie_param->task_buf_.u64PhyAddr != 0 && nnie_param->task_buf_.u64VirAddr != 0) { - NNIE_MEM_FREE(nnie_param->task_buf_.u64PhyAddr, nnie_param->task_buf_.u64VirAddr); - nnie_param->task_buf_.u64PhyAddr = 0; - nnie_param->task_buf_.u64VirAddr = 0; - } - - if (nnie_param->step_buf_.u64PhyAddr != 0 && nnie_param->step_buf_.u64VirAddr != 0) { - NNIE_MEM_FREE(nnie_param->step_buf_.u64PhyAddr, nnie_param->step_buf_.u64VirAddr); - nnie_param->step_buf_.u64PhyAddr = 0; - nnie_param->step_buf_.u64VirAddr = 0; - } -} - -bool CheckNnieInnerNode(const HI_CHAR *name, NnieParam *nnie_param) { - for (HI_U32 i = 0; i < nnie_param->model_->u32NetSegNum; i++) { - for (HI_U32 j = 0; j < nnie_param->model_->astSeg[i].u16DstNum; j++) - if (strncmp(name, nnie_param->model_->astSeg[i].astDstNode[j].szName, SVP_NNIE_NODE_NAME_LEN) == 0) { - nnie_param->mem_cfg_.seg_[i].dst_node_[j] = true; - return true; - } - } - return false; -} - -bool ConnectNnieInnerNode(const HI_CHAR *name, NnieParam *nnie_param, SVP_SRC_BLOB_S *blob) { - for (HI_U32 i = 0; i < nnie_param->model_->u32NetSegNum; i++) { - for (HI_U32 j = 0; j < nnie_param->model_->astSeg[i].u16DstNum; j++) - if (strncmp(name, nnie_param->model_->astSeg[i].astDstNode[j].szName, SVP_NNIE_NODE_NAME_LEN) == 0) { - blob->u64PhyAddr = nnie_param->seg_data_[i].dst_[j].u64PhyAddr; - blob->u64VirAddr = nnie_param->seg_data_[i].dst_[j].u64VirAddr; - return true; - } - } - return false; -} - -static void FillForwardInfo(NnieCfg *nnie_cfg, NnieParam *nnie_param) { - HI_U32 i, j; - HI_U32 num; - memset(&nnie_param->mem_cfg_, false, sizeof(NNIEMemCfg)); - for (i = 0; i < nnie_param->model_->u32NetSegNum; i++) { - if (SVP_NNIE_NET_TYPE_ROI == nnie_param->model_->astSeg[i].enNetType) { - nnie_param->forward_with_bbox_ctrl_[i].enNnieId = nnie_cfg->nnie_core_id_[i]; - nnie_param->forward_with_bbox_ctrl_[i].u32SrcNum = nnie_param->model_->astSeg[i].u16SrcNum; - nnie_param->forward_with_bbox_ctrl_[i].u32DstNum = nnie_param->model_->astSeg[i].u16DstNum; - nnie_param->forward_with_bbox_ctrl_[i].u32ProposalNum = 1; - nnie_param->forward_with_bbox_ctrl_[i].u32NetSegId = i; - } else if (SVP_NNIE_NET_TYPE_CNN == nnie_param->model_->astSeg[i].enNetType || - SVP_NNIE_NET_TYPE_RECURRENT == nnie_param->model_->astSeg[i].enNetType) { - nnie_param->forward_ctrl_[i].enNnieId = nnie_cfg->nnie_core_id_[i]; - nnie_param->forward_ctrl_[i].u32SrcNum = nnie_param->model_->astSeg[i].u16SrcNum; - nnie_param->forward_ctrl_[i].u32DstNum = nnie_param->model_->astSeg[i].u16DstNum; - nnie_param->forward_ctrl_[i].u32NetSegId = i; - } - - for (j = 0; j < nnie_param->model_->astSeg[i].u16SrcNum; j++) { - if (i > 0) { - if (CheckNnieInnerNode(nnie_param->model_->astSeg[i].astSrcNode[j].szName, nnie_param)) { - nnie_param->mem_cfg_.seg_[i].src_node_[j] = true; - } - } - - if (SVP_BLOB_TYPE_SEQ_S32 == nnie_param->model_->astSeg[i].astSrcNode[j].enType) { - nnie_param->seg_data_[i].src_[j].enType = nnie_param->model_->astSeg[i].astSrcNode[j].enType; - nnie_param->seg_data_[i].src_[j].unShape.stSeq.u32Dim = - nnie_param->model_->astSeg[i].astSrcNode[j].unShape.u32Dim; - nnie_param->seg_data_[i].src_[j].u32Num = nnie_cfg->max_input_num_; - nnie_param->seg_data_[i].src_[j].unShape.stSeq.u64VirAddrStep = - nnie_cfg->step_vir_addr_[i * NNIE_EACH_SEG_STEP_ADDR_NUM]; - } else { - nnie_param->seg_data_[i].src_[j].enType = nnie_param->model_->astSeg[i].astSrcNode[j].enType; - nnie_param->seg_data_[i].src_[j].unShape.stWhc.u32Chn = - nnie_param->model_->astSeg[i].astSrcNode[j].unShape.stWhc.u32Chn; - nnie_param->seg_data_[i].src_[j].unShape.stWhc.u32Height = - nnie_param->model_->astSeg[i].astSrcNode[j].unShape.stWhc.u32Height; - nnie_param->seg_data_[i].src_[j].unShape.stWhc.u32Width = - nnie_param->model_->astSeg[i].astSrcNode[j].unShape.stWhc.u32Width; - nnie_param->seg_data_[i].src_[j].u32Num = nnie_cfg->max_input_num_; - } - } - - if (SVP_NNIE_NET_TYPE_ROI == nnie_param->model_->astSeg[i].enNetType) { - num = nnie_cfg->max_roi_num_ * nnie_cfg->max_input_num_; - } else { - num = nnie_cfg->max_input_num_; - } - - for (j = 0; j < nnie_param->model_->astSeg[i].u16DstNum; j++) { - if (SVP_BLOB_TYPE_SEQ_S32 == nnie_param->model_->astSeg[i].astDstNode[j].enType) { - nnie_param->seg_data_[i].dst_[j].enType = nnie_param->model_->astSeg[i].astDstNode[j].enType; - nnie_param->seg_data_[i].dst_[j].unShape.stSeq.u32Dim = - nnie_param->model_->astSeg[i].astDstNode[j].unShape.u32Dim; - nnie_param->seg_data_[i].dst_[j].u32Num = num; - nnie_param->seg_data_[i].dst_[j].unShape.stSeq.u64VirAddrStep = - nnie_cfg->step_vir_addr_[i * NNIE_EACH_SEG_STEP_ADDR_NUM + 1]; - } else { - nnie_param->seg_data_[i].dst_[j].enType = nnie_param->model_->astSeg[i].astDstNode[j].enType; - nnie_param->seg_data_[i].dst_[j].unShape.stWhc.u32Chn = - nnie_param->model_->astSeg[i].astDstNode[j].unShape.stWhc.u32Chn; - nnie_param->seg_data_[i].dst_[j].unShape.stWhc.u32Height = - nnie_param->model_->astSeg[i].astDstNode[j].unShape.stWhc.u32Height; - nnie_param->seg_data_[i].dst_[j].unShape.stWhc.u32Width = - nnie_param->model_->astSeg[i].astDstNode[j].unShape.stWhc.u32Width; - nnie_param->seg_data_[i].dst_[j].u32Num = num; - } - } - } -} - -static void GetBlobMemSize(SVP_NNIE_NODE_S nnie_node[], HI_U32 node_num, HI_U32 total_step, SVP_BLOB_S blob[], - HI_U32 align32, HI_U32 *total_size, HI_U32 blob_size[], bool malloc_allow, - bool *mem_alloc = nullptr) { - HI_U32 i = 0; - HI_U32 size; - HI_U32 stride; - - for (i = 0; i < node_num; i++) { - if (SVP_BLOB_TYPE_S32 == nnie_node[i].enType || SVP_BLOB_TYPE_VEC_S32 == nnie_node[i].enType || - SVP_BLOB_TYPE_SEQ_S32 == nnie_node[i].enType) { - size = sizeof(HI_U32); - } else { - size = sizeof(HI_U8); - } - if (SVP_BLOB_TYPE_SEQ_S32 == nnie_node[i].enType) { - if (NNIE_ALIGN_16 == align32) { - stride = NNIE_ALIGN16(nnie_node[i].unShape.u32Dim * size); - } else { - stride = NNIE_ALIGN32(nnie_node[i].unShape.u32Dim * size); - } - blob_size[i] = total_step * stride; - } else { - if (NNIE_ALIGN_16 == align32) { - stride = NNIE_ALIGN16(nnie_node[i].unShape.stWhc.u32Width * size); - } else { - stride = NNIE_ALIGN32(nnie_node[i].unShape.stWhc.u32Width * size); - } - blob_size[i] = blob[i].u32Num * stride * nnie_node[i].unShape.stWhc.u32Height * nnie_node[i].unShape.stWhc.u32Chn; - } - if (mem_alloc != nullptr) { - if (mem_alloc[i]) { - blob_size[i] = 0; - } - } - if (malloc_allow) { - *total_size += blob_size[i]; - } - blob[i].u32Stride = stride; - } -} - -static int GetTaskAndBlobBufSize(NnieCfg *nnie_cfg, NnieParam *nnie_param, HI_U32 *total_task_buf_size, - HI_U32 *tmp_buf_size, NnieBlobSize blob_size[], HI_U32 blob_size_len, - HI_U32 *total_size) { - HI_S32 ret = HI_SUCCESS; - HI_U32 i, j; - HI_U32 total_step = 0; - - ret = HI_MPI_SVP_NNIE_GetTskBufSize(nnie_cfg->max_input_num_, nnie_cfg->max_roi_num_, nnie_param->model_, - nnie_param->task_buf_size_, nnie_param->model_->u32NetSegNum); - if (HI_SUCCESS != ret) { - LOGE("HI_MPI_SVP_NNIE_GetTskBufSize"); - return RET_ERROR; - } - - *total_task_buf_size = 0; - for (i = 0; i < nnie_param->model_->u32NetSegNum; i++) { - *total_task_buf_size += nnie_param->task_buf_size_[i]; - } - - *tmp_buf_size = nnie_param->model_->u32TmpBufSize; - *total_size += *total_task_buf_size + *tmp_buf_size; - - for (i = 0; i < nnie_param->model_->u32NetSegNum && i < blob_size_len; i++) { - if (SVP_NNIE_NET_TYPE_RECURRENT == nnie_param->model_->astSeg[i].enNetType) { - for (j = 0; j < nnie_param->seg_data_[i].src_[0].u32Num; j++) { - total_step += *(reinterpret_cast( - static_cast(nnie_param->seg_data_[i].src_[0].unShape.stSeq.u64VirAddrStep)) + - j); - } - } - bool malloc_allow = (!nnie_cfg->pass_align16_io_) || i != 0; - GetBlobMemSize(&(nnie_param->model_->astSeg[i].astSrcNode[0]), nnie_param->model_->astSeg[i].u16SrcNum, total_step, - &(nnie_param->seg_data_[i].src_[0]), NNIE_ALIGN_16, total_size, &(blob_size[i].src_size_[0]), - malloc_allow, &(nnie_param->mem_cfg_.seg_[i].src_node_[0])); - - malloc_allow = (!nnie_cfg->pass_align16_io_) || (i + 1) != nnie_param->model_->u32NetSegNum; - GetBlobMemSize(&(nnie_param->model_->astSeg[i].astDstNode[0]), nnie_param->model_->astSeg[i].u16DstNum, total_step, - &(nnie_param->seg_data_[i].dst_[0]), NNIE_ALIGN_16, total_size, &(blob_size[i].dst_size_[0]), - malloc_allow); - } - return RET_OK; -} - -static int NnieSetBlobAddr(HI_U64 *phy_addr, HI_U8 **vir_addr, NnieParam *nnie_param, NnieBlobSize *blob_size, - bool pass_align16_io) { - HI_U32 i, j; - for (i = 0; i < nnie_param->model_->u32NetSegNum; i++) { - if ((!pass_align16_io) || i != 0) { - for (j = 0; j < nnie_param->model_->astSeg[i].u16SrcNum; j++) { - if (j != 0) { - *phy_addr += blob_size[i].src_size_[j - 1]; - *vir_addr += blob_size[i].src_size_[j - 1]; - } - if (nnie_param->mem_cfg_.seg_[i].src_node_[j]) { - if (!ConnectNnieInnerNode(nnie_param->model_->astSeg[i].astSrcNode[j].szName, nnie_param, - &(nnie_param->seg_data_[i].src_[j]))) { - LOGE("ConnectNnieInnerNode failed! "); - return RET_ERROR; - } - } else { - nnie_param->seg_data_[i].src_[j].u64PhyAddr = *phy_addr; - nnie_param->seg_data_[i].src_[j].u64VirAddr = (HI_U64)(HI_UL)*vir_addr; - } - } - *phy_addr += blob_size[i].src_size_[j - 1]; - *vir_addr += blob_size[i].src_size_[j - 1]; - } else { - for (j = 0; j < nnie_param->model_->astSeg[i].u16SrcNum; j++) { - nnie_param->seg_data_[i].src_[j].u64PhyAddr = 0; - nnie_param->seg_data_[i].src_[j].u64VirAddr = 0; - } - } - if ((!pass_align16_io) || (i + 1) != nnie_param->model_->u32NetSegNum) { - for (j = 0; j < nnie_param->model_->astSeg[i].u16DstNum; j++) { - if (j != 0) { - *phy_addr += blob_size[i].dst_size_[j - 1]; - *vir_addr += blob_size[i].dst_size_[j - 1]; - } - nnie_param->seg_data_[i].dst_[j].u64PhyAddr = *phy_addr; - nnie_param->seg_data_[i].dst_[j].u64VirAddr = (HI_U64)(HI_UL)*vir_addr; - } - *phy_addr += blob_size[i].dst_size_[j - 1]; - *vir_addr += blob_size[i].dst_size_[j - 1]; - } else { - for (j = 0; j < nnie_param->model_->astSeg[i].u16SrcNum; j++) { - nnie_param->seg_data_[i].dst_[j].u64PhyAddr = 0; - nnie_param->seg_data_[i].dst_[j].u64VirAddr = 0; - } - } - } - return RET_OK; -} - -static int NnieParamInit(NnieCfg *nnie_cfg, NnieParam *nnie_param) { - HI_U32 i; - HI_U32 total_size = 0; - HI_U32 total_task_buf_size = 0; - HI_U32 tmp_buf_size_ = 0; - HI_S32 ret = HI_SUCCESS; - HI_U32 off_set = 0; - HI_U64 phy_addr = 0; - HI_U8 *vir_addr = nullptr; - NnieBlobSize blob_size[SVP_NNIE_MAX_NET_SEG_NUM] = {0}; - - FillForwardInfo(nnie_cfg, nnie_param); - - HI_U32 blob_size_len = sizeof(blob_size) / sizeof(blob_size[0]); - ret = GetTaskAndBlobBufSize(nnie_cfg, nnie_param, &total_task_buf_size, &tmp_buf_size_, blob_size, blob_size_len, - &total_size); - if (HI_SUCCESS != ret) { - LOGE("Error,Malloc memory failed! "); - return RET_ERROR; - } - bool has_roi = false; - for (i = 0; i < nnie_param->model_->u32NetSegNum; i++) { - if (SVP_NNIE_NET_TYPE_ROI == nnie_param->model_->astSeg[i].enNetType) { - has_roi = true; - } - } - if (has_roi) { - nnie_param->rpn_bbox_.enType = SVP_BLOB_TYPE_S32; - nnie_param->rpn_bbox_.unShape.stWhc.u32Chn = 1; - nnie_param->rpn_bbox_.unShape.stWhc.u32Height = nnie_cfg->max_roi_num_; - nnie_param->rpn_bbox_.unShape.stWhc.u32Width = NNIE_COORDI_NUM; - nnie_param->rpn_bbox_.u32Stride = NNIE_ALIGN16(NNIE_COORDI_NUM * sizeof(HI_U32)); - nnie_param->rpn_bbox_.u32Num = nnie_cfg->max_input_num_; - total_size += - nnie_param->rpn_bbox_.u32Num * nnie_param->rpn_bbox_.unShape.stWhc.u32Height * nnie_param->rpn_bbox_.u32Stride; - } - - ret = NnieMemMallocCached(std::string("NNIE_NNIE_TASK").data(), nullptr, reinterpret_cast(&phy_addr), - reinterpret_cast(&vir_addr), total_size); - if (HI_SUCCESS != ret) { - LOGE("Error,Malloc memory failed! "); - return RET_ERROR; - } - memset(vir_addr, 0, total_size); - NnieMemFlushCache(phy_addr, reinterpret_cast(vir_addr), total_size); - - nnie_param->task_buf_.u32Size = total_task_buf_size; - nnie_param->task_buf_.u64PhyAddr = phy_addr; - nnie_param->task_buf_.u64VirAddr = (HI_U64)(HI_UL)vir_addr; - - nnie_param->tmp_buf_.u32Size = tmp_buf_size_; - nnie_param->tmp_buf_.u64PhyAddr = phy_addr + total_task_buf_size; - nnie_param->tmp_buf_.u64VirAddr = (HI_U64)(HI_UL)vir_addr + total_task_buf_size; - - for (i = 0; i < nnie_param->model_->u32NetSegNum; i++) { - if (SVP_NNIE_NET_TYPE_ROI == nnie_param->model_->astSeg[i].enNetType) { - nnie_param->forward_with_bbox_ctrl_[i].stTmpBuf = nnie_param->tmp_buf_; - nnie_param->forward_with_bbox_ctrl_[i].stTskBuf.u64PhyAddr = nnie_param->task_buf_.u64PhyAddr + off_set; - nnie_param->forward_with_bbox_ctrl_[i].stTskBuf.u64VirAddr = nnie_param->task_buf_.u64VirAddr + off_set; - nnie_param->forward_with_bbox_ctrl_[i].stTskBuf.u32Size = nnie_param->task_buf_size_[i]; - } else if (SVP_NNIE_NET_TYPE_CNN == nnie_param->model_->astSeg[i].enNetType || - SVP_NNIE_NET_TYPE_RECURRENT == nnie_param->model_->astSeg[i].enNetType) { - nnie_param->forward_ctrl_[i].stTmpBuf = nnie_param->tmp_buf_; - nnie_param->forward_ctrl_[i].stTskBuf.u64PhyAddr = nnie_param->task_buf_.u64PhyAddr + off_set; - nnie_param->forward_ctrl_[i].stTskBuf.u64VirAddr = nnie_param->task_buf_.u64VirAddr + off_set; - nnie_param->forward_ctrl_[i].stTskBuf.u32Size = nnie_param->task_buf_size_[i]; - } - off_set += nnie_param->task_buf_size_[i]; - } - - phy_addr = phy_addr + total_task_buf_size + tmp_buf_size_; - vir_addr = vir_addr + total_task_buf_size + tmp_buf_size_; - if (NnieSetBlobAddr(&phy_addr, &vir_addr, nnie_param, blob_size, nnie_cfg->pass_align16_io_) != RET_OK) { - LOGE("SetBlobAddr failed!"); - return RET_ERROR; - } - if (has_roi) { - nnie_param->rpn_bbox_.u64PhyAddr = phy_addr; - nnie_param->rpn_bbox_.u64VirAddr = (HI_U64)((HI_UL)vir_addr); - } - return RET_OK; -} - -int NnieLoadModel(char *model_buf, int size, NnieModel *nnie_model) { - HI_S32 ret = HI_INVALID_VALUE; - HI_U64 phy_addr = 0; - HI_U8 *vir_addr = nullptr; - ret = NnieMemMalloc(std::string("NNIE_NNIE_MODEL").data(), nullptr, reinterpret_cast(&phy_addr), - reinterpret_cast(&vir_addr), size); - if (HI_SUCCESS != ret) { - LOGE("Error,Malloc memory failed! "); - return RET_ERROR; - } - nnie_model->model_buf_.u32Size = (HI_U32)size; - nnie_model->model_buf_.u64PhyAddr = phy_addr; - nnie_model->model_buf_.u64VirAddr = (HI_U64)(HI_UL)vir_addr; - memcpy(vir_addr, model_buf, size); - ret = HI_MPI_SVP_NNIE_LoadModel(&nnie_model->model_buf_, &nnie_model->model_); - if (HI_SUCCESS != ret) { - NNIE_MEM_FREE(nnie_model->model_buf_.u64PhyAddr, nnie_model->model_buf_.u64VirAddr); - nnie_model->model_buf_.u32Size = 0; - LOGE("HI_MPI_SVP_NNIE_LoadModel failed!"); - return RET_ERROR; - } - return RET_OK; -} - -static void NnieUnloadModel(NnieModel *nnie_model) { - if (nnie_model == nullptr) { - return; - } - - if (nnie_model->model_buf_.u64PhyAddr != 0 && nnie_model->model_buf_.u64VirAddr != 0) { - NNIE_MEM_FREE(nnie_model->model_buf_.u64PhyAddr, nnie_model->model_buf_.u64VirAddr); - nnie_model->model_buf_.u64PhyAddr = 0; - nnie_model->model_buf_.u64VirAddr = 0; - } -} - -static int NnieForward(NnieParam *nnie_param, NnieDataIndex *input_data_idx, HI_BOOL instant) { - HI_S32 ret = HI_SUCCESS; - HI_U32 i, j; - HI_BOOL finish = HI_FALSE; - SVP_NNIE_HANDLE svp_nnie_handle = 0; - HI_U32 total_step_num = 0; - SVP_NNIE_FORWARD_CTRL_S *forward_handle = &nnie_param->forward_ctrl_[input_data_idx->seg_idx_]; - NnieSegData *seg_data = &nnie_param->seg_data_[input_data_idx->seg_idx_]; - - NnieMemFlushCache(forward_handle->stTskBuf.u64PhyAddr, - NNIE_CONVERT_64BIT_ADDR(HI_VOID, forward_handle->stTskBuf.u64VirAddr), - forward_handle->stTskBuf.u32Size); - - for (i = 0; i < forward_handle->u32DstNum; i++) { - if (SVP_BLOB_TYPE_SEQ_S32 == seg_data->dst_[i].enType) { - for (j = 0; j < seg_data->dst_[i].u32Num; j++) { - total_step_num += *(NNIE_CONVERT_64BIT_ADDR(HI_U32, seg_data->dst_[i].unShape.stSeq.u64VirAddrStep) + j); - } - NnieMemFlushCache(seg_data->dst_[i].u64PhyAddr, NNIE_CONVERT_64BIT_ADDR(HI_VOID, seg_data->dst_[i].u64VirAddr), - total_step_num * seg_data->dst_[i].u32Stride); - } else { - NnieMemFlushCache(seg_data->dst_[i].u64PhyAddr, NNIE_CONVERT_64BIT_ADDR(HI_VOID, seg_data->dst_[i].u64VirAddr), - seg_data->dst_[i].u32Num * seg_data->dst_[i].unShape.stWhc.u32Chn * - seg_data->dst_[i].unShape.stWhc.u32Height * seg_data->dst_[i].u32Stride); - } - } - - ret = HI_MPI_SVP_NNIE_Forward(&svp_nnie_handle, seg_data->src_, nnie_param->model_, seg_data->dst_, forward_handle, - instant); - if (HI_SUCCESS != ret) { - LOGE("HI_MPI_SVP_NNIE_Forward failed!"); - return RET_ERROR; - } - - if (instant) { - while (HI_ERR_SVP_NNIE_QUERY_TIMEOUT == - (ret = HI_MPI_SVP_NNIE_Query(forward_handle->enNnieId, svp_nnie_handle, &finish, HI_TRUE))) { - usleep(kSleepUs); - } - } - - total_step_num = 0; - for (i = 0; i < forward_handle->u32DstNum; i++) { - if (SVP_BLOB_TYPE_SEQ_S32 == seg_data->dst_[i].enType) { - for (j = 0; j < seg_data->dst_[i].u32Num; j++) { - total_step_num += *(NNIE_CONVERT_64BIT_ADDR(HI_U32, seg_data->dst_[i].unShape.stSeq.u64VirAddrStep) + j); - } - NnieMemFlushCache(seg_data->dst_[i].u64PhyAddr, NNIE_CONVERT_64BIT_ADDR(HI_VOID, seg_data->dst_[i].u64VirAddr), - total_step_num * seg_data->dst_[i].u32Stride); - } else { - NnieMemFlushCache(seg_data->dst_[i].u64PhyAddr, NNIE_CONVERT_64BIT_ADDR(HI_VOID, seg_data->dst_[i].u64VirAddr), - seg_data->dst_[i].u32Num * seg_data->dst_[i].unShape.stWhc.u32Chn * - seg_data->dst_[i].unShape.stWhc.u32Height * seg_data->dst_[i].u32Stride); - } - } - - return RET_OK; -} - -static HI_S32 NNIE_ForwardWithBbox(NnieParam *pstNnieParam, NnieDataIndex *pstInputDataIdx, SVP_SRC_BLOB_S astBbox[], - HI_BOOL bInstant) { - HI_S32 ret = HI_SUCCESS; - HI_BOOL finish = HI_FALSE; - SVP_NNIE_HANDLE svp_nnie_handle = 0; - HI_U32 total_step_num = 0; - HI_U32 i, j; - - NnieMemFlushCache(pstNnieParam->forward_with_bbox_ctrl_[pstInputDataIdx->seg_idx_].stTskBuf.u64PhyAddr, - NNIE_CONVERT_64BIT_ADDR( - HI_VOID, pstNnieParam->forward_with_bbox_ctrl_[pstInputDataIdx->seg_idx_].stTskBuf.u64VirAddr), - pstNnieParam->forward_with_bbox_ctrl_[pstInputDataIdx->seg_idx_].stTskBuf.u32Size); - - for (i = 0; i < pstNnieParam->forward_with_bbox_ctrl_[pstInputDataIdx->seg_idx_].u32DstNum; i++) { - if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].enType) { - for (j = 0; j < pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Num; j++) { - total_step_num += - *(NNIE_CONVERT_64BIT_ADDR( - HI_U32, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].unShape.stSeq.u64VirAddrStep) + - j); - } - NnieMemFlushCache( - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64PhyAddr, - NNIE_CONVERT_64BIT_ADDR(HI_VOID, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64VirAddr), - total_step_num * pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Stride); - } else { - NnieMemFlushCache( - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64PhyAddr, - NNIE_CONVERT_64BIT_ADDR(HI_VOID, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64VirAddr), - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Num * - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].unShape.stWhc.u32Chn * - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].unShape.stWhc.u32Height * - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Stride); - } - } - - ret = - HI_MPI_SVP_NNIE_ForwardWithBbox(&svp_nnie_handle, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].src_, astBbox, - pstNnieParam->model_, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_, - &pstNnieParam->forward_with_bbox_ctrl_[pstInputDataIdx->seg_idx_], bInstant); - if (HI_SUCCESS != ret) { - LOGE("HI_MPI_SVP_NNIE_ForwardWithBbox failed!"); - return RET_ERROR; - } - - if (bInstant) { - while (HI_ERR_SVP_NNIE_QUERY_TIMEOUT == - (ret = HI_MPI_SVP_NNIE_Query(pstNnieParam->forward_with_bbox_ctrl_[pstInputDataIdx->seg_idx_].enNnieId, - svp_nnie_handle, &finish, HI_TRUE))) { - usleep(kSleepUs); - LOGE("HI_MPI_SVP_NNIE_Query Query timeout!"); - } - } - - total_step_num = 0; - - for (i = 0; i < pstNnieParam->forward_with_bbox_ctrl_[pstInputDataIdx->seg_idx_].u32DstNum; i++) { - if (SVP_BLOB_TYPE_SEQ_S32 == pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].enType) { - for (j = 0; j < pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Num; j++) { - total_step_num += - *(NNIE_CONVERT_64BIT_ADDR( - HI_U32, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].unShape.stSeq.u64VirAddrStep) + - j); - } - NnieMemFlushCache( - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64PhyAddr, - NNIE_CONVERT_64BIT_ADDR(HI_VOID, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64VirAddr), - total_step_num * pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Stride); - } else { - NnieMemFlushCache( - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64PhyAddr, - NNIE_CONVERT_64BIT_ADDR(HI_VOID, pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u64VirAddr), - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Num * - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].unShape.stWhc.u32Chn * - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].unShape.stWhc.u32Height * - pstNnieParam->seg_data_[pstInputDataIdx->seg_idx_].dst_[i].u32Stride); - } - } - - return ret; -} - -int FillByUnsignedChar(HI_U32 input_size, HI_U32 num, HI_U32 width, HI_U32 stride, HI_U8 *src, HI_U8 *dst) { - HI_U32 i, j; - if (input_size != num * width) { - LOGE("input size error:%d <-> %d.", input_size, num * width); - return RET_ERROR; - } - for (i = 0; i < num; i++) { - for (j = 0; j < width; j++) { - dst[j] = src[j]; - } - dst += stride; - src += width; - } - return RET_OK; -} - -int FillByFloat(HI_U32 input_size, HI_U32 num, HI_U32 width, HI_U32 stride, HI_FLOAT *src, HI_S32 *dst, HI_U8 *dst_u8) { - HI_U32 i, j; - if (input_size != num * width) { - LOGE("input size error:%d <-> %d.", input_size, num * width); - return RET_ERROR; - } - for (i = 0; i < num; i++) { - for (j = 0; j < width; j++) { - dst[j] = (src[j] * NNIE_QUANT_BASE); - } - dst_u8 += stride; - dst = reinterpret_cast(dst_u8); - src += width; - } - return RET_OK; -} - -static int NnieFillSrcDataSeq(NnieCfg *nnie_cfg, SVP_SRC_BLOB_S *blob, HI_U32 input_size) { - HI_U32 *step_addr_u32 = NNIE_CONVERT_64BIT_ADDR(HI_U32, blob->unShape.stSeq.u64VirAddrStep); - HI_U32 dim = blob->unShape.stSeq.u32Dim; - HI_U32 stride = blob->u32Stride; - HI_U32 i; - HI_U32 j; - HI_U32 n; - HI_U32 total_step_num = 0; - HI_U8 *input_addr_u8 = NNIE_CONVERT_64BIT_ADDR(HI_U8, blob->u64VirAddr); - HI_S32 *input_addr_s32 = NNIE_CONVERT_64BIT_ADDR(HI_S32, blob->u64VirAddr); - HI_FLOAT *float_src_data = reinterpret_cast(nnie_cfg->data_ptr_); - - for (n = 0; n < blob->u32Num; n++) { - total_step_num += *(step_addr_u32 + n); - } - - if (input_size != total_step_num * dim) { - LOGE("input size error:%d <-> %d.", input_size, total_step_num * dim); - return RET_ERROR; - } - for (n = 0; n < blob->u32Num; n++) { - for (i = 0; i < *(step_addr_u32 + n); i++) { - for (j = 0; j < dim; j++) { - input_addr_s32[j] = (float_src_data[j] * NNIE_QUANT_BASE); - } - input_addr_u8 += stride; - input_addr_s32 = reinterpret_cast(input_addr_u8); - float_src_data += dim; - } - } - NnieMemFlushCache(blob->u64PhyAddr, NNIE_CONVERT_64BIT_ADDR(HI_VOID, blob->u64VirAddr), total_step_num * stride); - return RET_OK; -} - -HI_U32 GetBlobSize(const SVP_SRC_BLOB_S &blob) { - if (SVP_BLOB_TYPE_SEQ_S32 == blob.enType) { - HI_U32 stride = blob.u32Stride; - HI_U32 total_step_num = 0; - HI_U32 *step_addr_u32 = NNIE_CONVERT_64BIT_ADDR(HI_U32, blob.unShape.stSeq.u64VirAddrStep); - size_t n; - for (n = 0; n < blob.u32Num; n++) { - total_step_num += *(step_addr_u32 + n); - } - return total_step_num * stride; - } - - HI_U32 stride = blob.u32Stride; - HI_U32 height = blob.unShape.stWhc.u32Height; - HI_U32 channel = blob.unShape.stWhc.u32Chn; - if (SVP_BLOB_TYPE_YVU420SP == blob.enType) { - return blob.u32Num * static_cast(channel * height / kCompressionWidth) * stride; - } else if (SVP_BLOB_TYPE_YVU422SP == blob.enType) { - return blob.u32Num * height * kCompressionWidth * stride; - } else { - return blob.u32Num * channel * height * stride; - } -} - -static int NnieFillSrcData(NnieCfg *nnie_cfg, NnieParam *nnie_param, NnieDataIndex *input_data_idx, HI_U32 input_size) { - HI_U32 i; - HI_U32 ret; - SVP_SRC_BLOB_S *blob = &nnie_param->seg_data_[input_data_idx->seg_idx_].src_[input_data_idx->node_idx_]; - - if (SVP_BLOB_TYPE_SEQ_S32 == blob->enType) { - return NnieFillSrcDataSeq(nnie_cfg, blob, input_size); - } else { - HI_U8 *input_addr_u8 = NNIE_CONVERT_64BIT_ADDR(HI_U8, blob->u64VirAddr); - HI_S32 *input_addr_s32 = NNIE_CONVERT_64BIT_ADDR(HI_S32, blob->u64VirAddr); - HI_FLOAT *float_src_data = reinterpret_cast(nnie_cfg->data_ptr_); - HI_U8 *u8_src_data = reinterpret_cast(nnie_cfg->data_ptr_); - HI_U32 height = blob->unShape.stWhc.u32Height; - HI_U32 width = blob->unShape.stWhc.u32Width; - HI_U32 channel = blob->unShape.stWhc.u32Chn; - HI_U32 stride = blob->u32Stride; - if (input_addr_u8 == u8_src_data) { - if (blob->enType == SVP_BLOB_TYPE_S32) { - for (i = 0; i < input_size; i++) { - input_addr_s32[i] = float_src_data[i] * NNIE_QUANT_BASE; - } - } else { - LOGI("\ninput no memcpy"); - } - } else { - if (SVP_BLOB_TYPE_YVU420SP == blob->enType) { - ret = FillByUnsignedChar(input_size, blob->u32Num * static_cast(channel * height / 2), width, stride, - u8_src_data, input_addr_u8); - } else if (SVP_BLOB_TYPE_YVU422SP == blob->enType) { - ret = FillByUnsignedChar(input_size, blob->u32Num * height * 2, width, stride, u8_src_data, input_addr_u8); - } else { - if (SVP_BLOB_TYPE_U8 == blob->enType) { - ret = - FillByUnsignedChar(input_size, blob->u32Num * channel * height, width, stride, u8_src_data, input_addr_u8); - } else { - ret = FillByFloat(input_size, blob->u32Num * channel * height, width, stride, float_src_data, input_addr_s32, - input_addr_u8); - } - } - if (ret != RET_OK) { - return ret; - } - } - NnieMemFlushCache(blob->u64PhyAddr, NNIE_CONVERT_64BIT_ADDR(HI_VOID, blob->u64VirAddr), - blob->u32Num * channel * height * stride); - } - - return RET_OK; -} - -static int NnieGetDstDataSEQ(SVP_SRC_BLOB_S *blob, HI_U32 input_num, NnieDataIndex *input_data_idx, - HI_FLOAT *float_dst_data) { - HI_U32 i, j, n; - HI_U32 dim = blob->unShape.stSeq.u32Dim; - HI_U32 stride = blob->u32Stride; - HI_U32 *step_addr_u32 = NNIE_CONVERT_64BIT_ADDR(HI_U32, blob->unShape.stSeq.u64VirAddrStep); - HI_U32 total_step_num = 0; - HI_U8 *output_addr_u8 = NNIE_CONVERT_64BIT_ADDR(HI_U8, blob->u64VirAddr); - HI_S32 *output_addr_s32 = NNIE_CONVERT_64BIT_ADDR(HI_S32, blob->u64VirAddr); - - for (n = 0; n < blob->u32Num; n++) { - total_step_num += *(step_addr_u32 + n); - } - if (input_num != total_step_num * dim) { - LOGE("input shape"); - return RET_ERROR; - } - if (input_data_idx->seg_idx_ == input_data_idx->max_seg_id_) { - for (n = 0; n < blob->u32Num; n++) { - for (i = 0; i < *(step_addr_u32 + n); i++) { - memcpy(float_dst_data, output_addr_u8, dim * sizeof(float)); - float_dst_data += dim; - output_addr_u8 += stride; - } - } - } else { - for (n = 0; n < blob->u32Num; n++) { - for (i = 0; i < *(step_addr_u32 + n); i++) { - for (j = 0; j < dim; j++) { - float_dst_data[j] = (HI_FLOAT)output_addr_s32[j] / NNIE_QUANT_BASE; - } - output_addr_u8 += stride; - output_addr_s32 = reinterpret_cast(output_addr_u8); - float_dst_data += dim; - } - } - } - return RET_OK; -} -static int NnieGetDstData(NnieCfg *nnie_cfg, NnieParam *nnie_param, NnieDataIndex *input_data_idx, HI_U32 input_num) { - SVP_SRC_BLOB_S *blob = &nnie_param->seg_data_[input_data_idx->seg_idx_ - 1].dst_[input_data_idx->node_idx_]; - if (SVP_BLOB_TYPE_U8 <= blob->enType && SVP_BLOB_TYPE_YVU422SP >= blob->enType) { - LOGE("Nnie output type error"); - return RET_ERROR; - } - HI_FLOAT *float_dst_data = reinterpret_cast(nnie_cfg->data_ptr_); - if (SVP_BLOB_TYPE_SEQ_S32 == blob->enType) { - if (NnieGetDstDataSEQ(blob, input_num, input_data_idx, float_dst_data) != RET_OK) { - LOGE("NnieGetDstDataSEQ error."); - return RET_ERROR; - } - } else { - HI_U8 *output_addr_u8 = NNIE_CONVERT_64BIT_ADDR(HI_U8, blob->u64VirAddr); - HI_S32 *output_addr_s32 = NNIE_CONVERT_64BIT_ADDR(HI_S32, blob->u64VirAddr); - if (float_dst_data == reinterpret_cast(output_addr_s32)) { - if (input_data_idx->seg_idx_ != input_data_idx->max_seg_id_) { - for (HI_U32 i = 0; i < input_num; i++) { - float_dst_data[i] = (HI_FLOAT)output_addr_s32[i] / NNIE_QUANT_BASE; - } - } else { - LOGI("\noutput no memcpy"); - } - } else { - HI_U32 height = blob->unShape.stWhc.u32Height; - HI_U32 width = blob->unShape.stWhc.u32Width; - HI_U32 channel = blob->unShape.stWhc.u32Chn; - HI_U32 stride = blob->u32Stride; - if (input_num != height * channel * width * blob->u32Num) { - LOGE("output shape diff:%d<->%d.", input_num, height * channel * width * blob->u32Num); - return RET_ERROR; - } - if (input_data_idx->seg_idx_ == input_data_idx->max_seg_id_) { - if (nnie_cfg->pass_align16_io_) { - memcpy(float_dst_data, output_addr_u8, blob->u32Num * channel * height * stride); - } else { - for (HI_U32 i = 0; i < (blob->u32Num * channel * height); i++) { - memcpy(float_dst_data, output_addr_u8, width * sizeof(float)); - float_dst_data += width; - output_addr_u8 += stride; - } - } - } else { - for (HI_U32 n = 0; n < blob->u32Num; n++) { - for (HI_U32 i = 0; i < channel * height; i++) { - for (HI_U32 j = 0; j < width; j++) { - float_dst_data[j] = (HI_FLOAT)output_addr_s32[j] / NNIE_QUANT_BASE; - } - output_addr_u8 += stride; - output_addr_s32 = reinterpret_cast(output_addr_u8); - float_dst_data += width; - } - } - } - } - } - return RET_OK; -} - -int CheckMsShapeN(NnieRunCfg *nnie_run_cfg, const std::vector &input_shape, const SVP_NNIE_NODE_S &nnie_node) { - size_t ms_input_size = 1, i; - for (i = 1; i < input_shape.size(); i++) { - ms_input_size *= input_shape[i]; - } - - size_t nnie_input_size; - if (SVP_BLOB_TYPE_SEQ_S32 == nnie_node.enType) { - if (nnie_run_cfg->cfg_.step_ == 0) { - LOGE("request time_step set! Please export NNIE_RUNTIME_CONFIG_PATH"); - return RET_ERROR; - } - if (ms_input_size != nnie_node.unShape.u32Dim) { - LOGE("The input data does not meet the required size %d <-> %d.", static_cast(ms_input_size), - nnie_node.unShape.u32Dim); - return RET_ERROR; - } - if ((input_shape[0] < static_cast(nnie_run_cfg->cfg_.step_)) || - (input_shape[0] % nnie_run_cfg->cfg_.step_ != 0)) { - LOGW("The num value(%d) of input must be an integer multiple of time_step(%d)", static_cast(input_shape[0]), - nnie_run_cfg->cfg_.step_); - return RET_ERROR; - } - nnie_input_size = nnie_node.unShape.u32Dim * nnie_run_cfg->cfg_.step_; - } else { - auto height = nnie_node.unShape.stWhc.u32Height; - auto width = nnie_node.unShape.stWhc.u32Width; - auto channel = nnie_node.unShape.stWhc.u32Chn; - if (SVP_BLOB_TYPE_YVU420SP == nnie_node.enType) { - nnie_input_size = static_cast(channel * height / 2) * width; - } else if (SVP_BLOB_TYPE_YVU422SP == nnie_node.enType) { - nnie_input_size = height * 2 * width; - } else { - nnie_input_size = channel * height * width; - } - if (ms_input_size != nnie_input_size) { - LOGE("The input data does not meet the required size %d <-> %d.", static_cast(ms_input_size), - static_cast(nnie_input_size)); - return RET_ERROR; - } - } - nnie_run_cfg->cfg_.max_input_num_ = (ms_input_size * input_shape[0]) / nnie_input_size; - fprintf(stdout, "The input num is %d.", nnie_run_cfg->cfg_.max_input_num_); - return RET_OK; -} - -int NnieCommCreate(NnieRunCfg *nnie_run_cfg, const std::vector &input_shape) { - HI_U8 *vir_addr = nullptr; - HI_U32 seg_num; - HI_U32 off_set; - HI_U32 total_size; - HI_U32 i, j; - HI_S32 ret = HI_SUCCESS; - NnieModel *model = &nnie_run_cfg->model_; - NnieParam *param = &nnie_run_cfg->param_; - NnieCfg *cfg = &nnie_run_cfg->cfg_; - HI_U32 step = cfg->step_; // time step - - if (input_shape.size() <= 1) { - LOGE("input shape size need greater than 1!"); - return RET_ERROR; - } - - if (CheckMsShapeN(nnie_run_cfg, input_shape, model->model_.astSeg[0].astSrcNode[0]) != RET_OK) { - return RET_ERROR; - } - - bool has_roi = false; - for (i = 0; i < model->model_.u32NetSegNum; i++) { - if (SVP_NNIE_NET_TYPE_ROI == model->model_.astSeg[i].enNetType) { - has_roi = true; - } - } - if (has_roi) { - if (cfg->max_roi_num_ == 0) { - LOGE("NNIE_RUNTIME_CONFIG_PATH: max_roi_num(0) should greater than 0!"); - return RET_ERROR; - } - } else { - if (cfg->max_roi_num_ != 0) { - LOGW("NNIE_RUNTIME_CONFIG_PATH: max_roi_num should euqal to 0!"); - cfg->max_roi_num_ = 0; - } - } - - if (model->model_.astSeg[0].enNetType == SVP_NNIE_NET_TYPE_RECURRENT) { - if (step == 0) { - LOGE("request time_step set! No NNIE_RUNTIME_CONFIG_PATH, please export NNIE_RUNTIME_CONFIG_PATH"); - return RET_ERROR; - } - seg_num = model->model_.u32NetSegNum; - total_size = cfg->max_input_num_ * sizeof(HI_S32) * seg_num * 2; - ret = NnieMemMalloc(std::string("SVP_NNIE_STEP").data(), nullptr, - reinterpret_cast(¶m->step_buf_.u64PhyAddr), reinterpret_cast(&vir_addr), - total_size); - if (HI_SUCCESS != ret) { - LOGE("Malloc memory failed:"); - return RET_ERROR; - } - - param->step_buf_.u64VirAddr = (HI_U64)((HI_UL)vir_addr); - for (i = 0; i < seg_num * NNIE_EACH_SEG_STEP_ADDR_NUM; i++) { - cfg->step_vir_addr_[i] = param->step_buf_.u64VirAddr + i * cfg->max_input_num_ * sizeof(HI_S32); - } - - for (i = 0; i < seg_num; i++) { - off_set = i * NNIE_EACH_SEG_STEP_ADDR_NUM; - for (j = 0; j < cfg->max_input_num_; j++) { - *(reinterpret_cast(static_cast(cfg->step_vir_addr_[off_set])) + j) = - step; // step of input x_t - *(reinterpret_cast(static_cast(cfg->step_vir_addr_[off_set + 1])) + j) = - step; // step of output h_t - } - } - } - param->model_ = &(model->model_); - ret = NnieParamInit(cfg, param); - if (ret != RET_OK) { - LOGE("NnieParamInit failed!"); - return RET_ERROR; - } - nnie_run_cfg->run_idx_.seg_idx_ = 0; - return RET_OK; -} - -void NnieCommDelete(NnieParam *pstNnieParamm, NnieModel *nnie_model) { - NnieParamRelease(pstNnieParamm); - NnieUnloadModel(nnie_model); -} - -int NnieCommGetOutputData(NnieRunCfg *nnie_run_cfg, float *data, HI_U32 output_size, int tensor_index) { - if (nnie_run_cfg->run_idx_.seg_idx_ <= 0) { - LOGE("output seg index error."); - return RET_ERROR; - } - HI_U32 ret = 0; - int id = tensor_index; - - nnie_run_cfg->run_idx_.node_idx_ = id; - nnie_run_cfg->cfg_.data_ptr_ = data; - ret = NnieGetDstData(&nnie_run_cfg->cfg_, &nnie_run_cfg->param_, &nnie_run_cfg->run_idx_, output_size); - if (ret != RET_OK) { - LOGE("NnieGetDstData failed!"); - return RET_ERROR; - } - return RET_OK; -} - -int NnieCommFillData(NnieRunCfg *nnie_run_cfg, void *data, HI_U32 input_size, int tensor_index) { - HI_U32 ret = 0; - int id = tensor_index; - HI_U32 seg_idx = nnie_run_cfg->run_idx_.seg_idx_; - - if (id >= nnie_run_cfg->param_.model_->astSeg[seg_idx].u16SrcNum) { - LOGE("Nnie input node index error!"); - return RET_ERROR; - } - nnie_run_cfg->run_idx_.node_idx_ = id; - nnie_run_cfg->cfg_.data_ptr_ = data; - ret = NnieFillSrcData(&nnie_run_cfg->cfg_, &nnie_run_cfg->param_, &nnie_run_cfg->run_idx_, input_size); - if (ret != RET_OK) { - LOGE("NnieFillSrcData failed!"); - return RET_ERROR; - } - return RET_OK; -} - -int NnieCommRun(NnieRunCfg *nnie_run_cfg, bool run_box) { - HI_U32 segidx = nnie_run_cfg->run_idx_.seg_idx_; - HI_U32 ret = 0; - - if (segidx >= nnie_run_cfg->param_.model_->u32NetSegNum) { - LOGE("seg num err!\n"); - return RET_ERROR; - } - nnie_run_cfg->run_idx_.node_idx_ = 0; - if (run_box) { - ret = - NNIE_ForwardWithBbox(&nnie_run_cfg->param_, &nnie_run_cfg->run_idx_, &nnie_run_cfg->param_.rpn_bbox_, HI_TRUE); - if (HI_SUCCESS != ret) { - LOGE("NnieForward failed!"); - return RET_ERROR; - } - } else { - ret = NnieForward(&nnie_run_cfg->param_, &nnie_run_cfg->run_idx_, HI_TRUE); - if (HI_SUCCESS != ret) { - LOGE("NnieForward failed!"); - return RET_ERROR; - } - } - - nnie_run_cfg->run_idx_.seg_idx_ = ++segidx; - return RET_OK; -} -} // namespace nnie -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/nnie_common.h b/mindspore-lite/providers/nnie/src/nnie_common.h deleted file mode 100644 index ddd6ddb2..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_common.h +++ /dev/null @@ -1,121 +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_PROVIDERS_NNIE_SRC_NNIE_COMMON_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_COMMON_H_ -#include -#include -#include -#include -#include "include/mpi_vb.h" -#include "include/hi_comm_svp.h" -#include "include/hi_nnie.h" -#include "include/mpi_nnie.h" -#include "include/ir/dtype/type_id.h" -#include "src/nnie_cfg_parser.h" - -namespace mindspore { -namespace nnie { -#define NNIE_ALIGN_16 16 -#define NNIE_ALIGN16(u32Num) ((u32Num + NNIE_ALIGN_16 - 1) / NNIE_ALIGN_16 * NNIE_ALIGN_16) - -#define NNIE_ALIGN_32 32 -#define NNIE_ALIGN32(u32Num) ((u32Num + NNIE_ALIGN_32 - 1) / NNIE_ALIGN_32 * NNIE_ALIGN_32) - -#define NNIE_CONVERT_64BIT_ADDR(Type, Addr) reinterpret_cast((HI_UL)(Addr)) -#define NNIE_QUANT_BASE 4096 - -#define NNIE_COORDI_NUM 4 -#define NNIE_EACH_SEG_STEP_ADDR_NUM 2 -#define NNIE_REPORT_NAME_LENGTH 64 - -typedef struct { - SVP_NNIE_MODEL_S model_; - SVP_MEM_INFO_S model_buf_; // store Model file -} NnieModel; -typedef struct { - SVP_SRC_BLOB_S src_[SVP_NNIE_MAX_INPUT_NUM]; - SVP_DST_BLOB_S dst_[SVP_NNIE_MAX_OUTPUT_NUM]; -} NnieSegData; - -typedef struct { - bool src_node_[SVP_NNIE_MAX_INPUT_NUM]; - bool dst_node_[SVP_NNIE_MAX_OUTPUT_NUM]; -} NNIEMemSegInfo; - -typedef struct { - NNIEMemSegInfo seg_[SVP_NNIE_MAX_NET_SEG_NUM]; -} NNIEMemCfg; - -typedef struct { - SVP_NNIE_MODEL_S *model_; - HI_U32 task_buf_size_[SVP_NNIE_MAX_NET_SEG_NUM]; - SVP_MEM_INFO_S task_buf_; - SVP_MEM_INFO_S tmp_buf_; - SVP_MEM_INFO_S step_buf_; // store Lstm step info - SVP_SRC_BLOB_S rpn_bbox_; - NnieSegData seg_data_[SVP_NNIE_MAX_NET_SEG_NUM]; // each seg's input and output blob - SVP_NNIE_FORWARD_CTRL_S forward_ctrl_[SVP_NNIE_MAX_NET_SEG_NUM]; - SVP_NNIE_FORWARD_WITHBBOX_CTRL_S forward_with_bbox_ctrl_[SVP_NNIE_MAX_NET_SEG_NUM]; - NNIEMemCfg mem_cfg_; - bool get_mem_strong; -} NnieParam; - -typedef struct { - bool pass_align16_io_; - HI_VOID *data_ptr_; - HI_U32 max_input_num_; - HI_U32 max_roi_num_; - HI_U32 step_; - HI_U64 step_vir_addr_[NNIE_EACH_SEG_STEP_ADDR_NUM * - SVP_NNIE_MAX_NET_SEG_NUM]; // virtual addr of LSTM's or RNN's step buffer - SVP_NNIE_ID_E nnie_core_id_[SVP_NNIE_MAX_NET_SEG_NUM]; -} NnieCfg; - -typedef struct { - HI_U32 seg_idx_; - HI_U32 node_idx_; - HI_U32 max_seg_id_; -} NnieDataIndex; - -typedef struct { - HI_U32 src_size_[SVP_NNIE_MAX_INPUT_NUM]; - HI_U32 dst_size_[SVP_NNIE_MAX_OUTPUT_NUM]; -} NnieBlobSize; - -typedef struct { - NnieModel model_; - NnieParam param_; - NnieCfg cfg_; - NnieDataIndex run_idx_; -} NnieRunCfg; - -int NnieLoadModel(char *model_buf, int size, NnieModel *nnie_model); - -int NnieCommCreate(NnieRunCfg *nnie_run_cfg, const std::vector &input_shape); - -void NnieCommDelete(NnieParam *pstNnieParamm, NnieModel *nnie_model); - -int NnieCommRun(NnieRunCfg *nnie_run_cfg, bool run_box); - -int NnieCommFillData(NnieRunCfg *nnie_run_cfg, void *data, HI_U32 input_size, int id); - -int NnieCommGetOutputData(NnieRunCfg *nnie_run_cfg, float *data, HI_U32 output_size, int tensor_index); - -HI_U32 GetBlobSize(const SVP_SRC_BLOB_S &blob); -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_COMMON_H_ diff --git a/mindspore-lite/providers/nnie/src/nnie_manager.cc b/mindspore-lite/providers/nnie/src/nnie_manager.cc deleted file mode 100644 index 48ae58f2..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_manager.cc +++ /dev/null @@ -1,548 +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 -#include -#include -#include "src/nnie_manager.h" -#include "src/nnie_common.h" -#include "src/nnie_print.h" -#include "src/nnie_memory.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace nnie { -constexpr int kUINT16_MAX = 65535; -constexpr int kNumInput2 = 2; -constexpr int kPreSize = 4; -constexpr int kPostSize = 5; - -static size_t GetFillIndex(const std::vector &inputs, size_t input_size, const HI_CHAR *name) { - size_t j; - for (j = 0; j < input_size; j++) { - auto input_str = inputs[j].Name(); - if (input_str.length() > kPreSize) { - if (input_str.substr(input_str.length() - kPreSize) == "_pre") { - input_str = input_str.substr(0, input_str.length() - kPreSize); - } else if (input_str.length() > kPostSize) { - if (input_str.substr(input_str.length() - kPostSize) == "_post") { - input_str = input_str.substr(0, input_str.length() - kPostSize); - } - } - } - - if (strcmp(input_str.c_str(), name) == 0) { - break; - } - } - if (j == input_size) { - for (j = 0; j < input_size; j++) { - auto input_str = inputs[j].Name(); - if (input_str.length() > kPreSize) { - if (input_str.substr(input_str.length() - kPreSize) == "_pre") { - input_str = input_str.substr(0, input_str.length() - kPreSize); - } else if (input_str.length() > kPostSize) { - if (input_str.substr(input_str.length() - kPostSize) == "_post") { - input_str = input_str.substr(0, input_str.length() - kPostSize); - } - } - } - - if (strncmp(input_str.c_str(), name, input_str.length()) == 0) { - break; - } - } - } - return j; -} - -int NNIEManager::CfgInit(const Flags &flags, int max_seg_id) { - memset(&nnie_cfg_, 0, sizeof(NnieRunCfg)); - - nnie_cfg_.cfg_.pass_align16_io_ = flags.keep_origin_output_; - nnie_cfg_.param_.get_mem_strong = false; - nnie_cfg_.run_idx_.max_seg_id_ = flags.keep_origin_output_ ? max_seg_id + 1 : kUINT16_MAX; - nnie_cfg_.cfg_.max_roi_num_ = flags.max_roi_num_; - nnie_cfg_.cfg_.step_ = flags.time_step_; - if (flags.core_ids_.size() == 1) { - for (size_t i = 0; i < SVP_NNIE_MAX_NET_SEG_NUM; i++) { - if (flags.core_ids_[0] < SVP_NNIE_ID_BUTT) { - nnie_cfg_.cfg_.nnie_core_id_[i] = (SVP_NNIE_ID_E)flags.core_ids_[0]; - } else { - LOGE("nnie core num toobig.\n"); - return RET_ERROR; - } - } - } - for (size_t i = 0; i < SVP_NNIE_MAX_NET_SEG_NUM && i < flags.core_ids_.size(); i++) { - if (flags.core_ids_[i] < SVP_NNIE_ID_BUTT) { - nnie_cfg_.cfg_.nnie_core_id_[i] = (SVP_NNIE_ID_E)flags.core_ids_[i]; - } else { - LOGE("nnie core num toobig.\n"); - return RET_ERROR; - } - } - return RET_OK; -} - -int NNIEManager::MallocBlobData(SVP_SRC_BLOB_S *blob, mindspore::MSTensor *tensor, HI_U32 blob_size) { - auto ret = NnieMemMallocCached(tensor->Name().c_str(), nullptr, reinterpret_cast(&blob->u64PhyAddr), - reinterpret_cast(&blob->u64VirAddr), blob_size); - if (HI_SUCCESS != ret) { - LOGE("Error,MallocBlobData failed!"); - return RET_ERROR; - } - blobs_.push_back(blob); - tensors_.push_back(tensor); - return RET_OK; -} - -int NNIEManager::SetBlobAddr(SVP_SRC_BLOB_S *blob, HI_U64 virt, mindspore::MSTensor *tensor, - std::shared_ptr allocator) { - HI_U32 blob_size = GetBlobSize(*blob); - if (virt == 0) { - auto iter = std::find(blobs_.begin(), blobs_.end(), blob); - if (iter == blobs_.end()) { - if (MallocBlobData(blob, tensor, blob_size) != RET_OK) { - LOGE("Failed to malloc."); - return RET_ERROR; - } - } - tensor->SetAllocator(allocator); - tensor->SetData(reinterpret_cast(blob->u64VirAddr)); - LOGI("\nSet %s allocator!", tensor->Name().c_str()); - } else { - auto ret = NnieGetVirMemInfo(virt, &blob->u64PhyAddr); - if (ret == HI_SUCCESS) { - blob->u64VirAddr = virt; - LOGI("Get physical address %llu.", blob->u64PhyAddr); - } else { - auto iter = std::find(blobs_.begin(), blobs_.end(), blob); - if (iter == blobs_.end()) { - if (MallocBlobData(blob, tensor, blob_size) != RET_OK) { - LOGE("Error, tensor data pointer is not MMZ memory, failed to malloc."); - return RET_ERROR; - } - } - } - } - return RET_OK; -} - -int NNIEManager::LoadInputs(std::vector *inputs, std::shared_ptr allocator) { - size_t input_size = inputs->size(); - if ((input_size < kNumInput2) || (input_size - 1) != nnie_cfg_.param_.model_->astSeg[0].u16SrcNum) { - LOGE("Input Size Err!"); - return RET_ERROR; - } - - for (size_t i = 0; i < nnie_cfg_.param_.model_->astSeg[0].u16SrcNum; i++) { - size_t j = GetFillIndex(*inputs, input_size - 1, nnie_cfg_.param_.model_->astSeg[0].astSrcNode[i].szName); - if (j == (input_size - 1)) { - j = i; - LOGI("input tensor name(%s) can't match wk node name(%s).", (*inputs)[j].Name().c_str(), - nnie_cfg_.param_.model_->astSeg[0].astSrcNode[i].szName); - } - HI_U64 virt = (HI_U64)(HI_UL)((*inputs)[j].Data().get()); - auto blob = &nnie_cfg_.param_.seg_data_[0].src_[i]; - if (SetBlobAddr(blob, virt, &(*inputs)[j], allocator) != RET_OK) { - return RET_ERROR; - } - } - return RET_OK; -} - -int NNIEManager::LoadOutputs(std::vector *outputs, std::shared_ptr allocator) { - int output_size = outputs->size(); - HI_U32 seg_id = nnie_cfg_.model_.model_.u32NetSegNum - 1; - if (output_size != nnie_cfg_.param_.model_->astSeg[seg_id].u16DstNum) { - LOGE("seg%d: %d output tensors are required, but there are %d outputs.", nnie_cfg_.run_idx_.seg_idx_ - 1, - nnie_cfg_.param_.model_->astSeg[nnie_cfg_.run_idx_.seg_idx_ - 1].u16DstNum, output_size); - return RET_ERROR; - } - if (nnie_cfg_.param_.model_->astSeg[seg_id].enNetType == SVP_NNIE_NET_TYPE_ROI) { - LOGE("Unsupported use PassAlign16InOutput!"); - return RET_ERROR; - } - - for (int i = 0; i < nnie_cfg_.param_.model_->astSeg[seg_id].u16DstNum; i++) { - int j = GetFillIndex(*outputs, output_size, nnie_cfg_.param_.model_->astSeg[seg_id].astDstNode[i].szName); - if (j == output_size) { - j = i; - LOGI("output tensor name(%s) can't match wk node name(%s).", (*outputs)[j].Name().c_str(), - nnie_cfg_.param_.model_->astSeg[seg_id].astDstNode[i].szName); - } - - SVP_SRC_BLOB_S *blob = &nnie_cfg_.param_.seg_data_[seg_id].dst_[i]; - if (SVP_BLOB_TYPE_U8 <= blob->enType && SVP_BLOB_TYPE_YVU422SP >= blob->enType) { - LOGE("Nnie output type error"); - return RET_ERROR; - } - HI_U64 virt = (HI_U64)(HI_UL)((*outputs)[j].Data().get()); - if (SetBlobAddr(blob, virt, &(*outputs)[j], allocator) != RET_OK) { - return RET_ERROR; - } - } - return RET_OK; -} - -void NNIEManager::SetInputNum(int max_input_num) { nnie_cfg_.cfg_.max_input_num_ = max_input_num; } - -int NNIEManager::Init(char *model_buf, int size, const std::vector &inputs) { - NnieModel *model = &nnie_cfg_.model_; - - if (inputs.size() <= 1) { - LOGE("inputs size need greater than 1!"); - return RET_ERROR; - } - auto ret = NnieLoadModel(model_buf, size, model); - if (ret != RET_OK) { - LOGE("NnieLoadModel failed!"); - return RET_ERROR; - } - auto j = GetFillIndex(inputs, inputs.size() - 1, model->model_.astSeg[0].astSrcNode[0].szName); - if (j == (inputs.size() - 1)) { - j = 0; - LOGI("input tensor name(%s) can't match wk node name(%s).", inputs[0].Name().c_str(), - model->model_.astSeg[0].astSrcNode[0].szName); - } - - if (NnieCommCreate(&nnie_cfg_, inputs[j].Shape()) != RET_OK) { - NnieCommDelete(&nnie_cfg_.param_, &nnie_cfg_.model_); - return RET_ERROR; - } - return RET_OK; -} - -int NNIEManager::Run(std::vector *outputs, unsigned int seg_id, - const std::vector> &outputs_shape) { - bool run_box = false; - nnie_cfg_.run_idx_.seg_idx_ = seg_id; - if (nnie_cfg_.param_.model_->astSeg[seg_id].enNetType == SVP_NNIE_NET_TYPE_ROI) { - run_box = true; - } - - if (NnieCommRun(&nnie_cfg_, run_box)) { - LOGE("Nnie Run Fail!"); - return RET_ERROR; - } - if (GetOutputData(outputs, outputs_shape, run_box)) { - LOGE("Get Output Data Fail!"); - return RET_ERROR; - } - return RET_OK; -} - -void NNIEManager::Release(bool resize_flag) { - for (auto &blob : blobs_) { - NNIE_MEM_FREE(blob->u64PhyAddr, blob->u64VirAddr); - blob->u64VirAddr = 0; - blob->u64PhyAddr = 0; - } - blobs_.clear(); - if (resize_flag) { - for (auto &tensor : tensors_) { - tensor->SetData(nullptr); - tensor->SetAllocator(nullptr); - } - } - tensors_.clear(); - NnieCommDelete(&nnie_cfg_.param_, &nnie_cfg_.model_); -} - -int NNIEManager::GetOutputData(std::vector *outputs, - const std::vector> &outputs_shape, bool run_box) { - int output_size = outputs->size(); - if (output_size != nnie_cfg_.param_.model_->astSeg[nnie_cfg_.run_idx_.seg_idx_ - 1].u16DstNum) { - LOGE("seg%d: %d output tensors are required, but there are %d outputs.", nnie_cfg_.run_idx_.seg_idx_ - 1, - nnie_cfg_.param_.model_->astSeg[nnie_cfg_.run_idx_.seg_idx_ - 1].u16DstNum, output_size); - return RET_ERROR; - } - - int i; - int j; - if (run_box) { - for (i = 0; i < output_size; i++) { - auto input_data_type = (*outputs)[i].DataType(); - if (input_data_type == DataType::kNumberTypeFloat32) { - auto ptr_shape = outputs_shape[i]; - int max_roi_num = nnie_cfg_.param_.seg_data_[nnie_cfg_.run_idx_.seg_idx_ - 1].dst_[0].u32Num; - ptr_shape.insert(ptr_shape.begin(), max_roi_num); - (*outputs)[i].SetShape(ptr_shape); - } else { - LOGE("Unsupported DataType!"); - return RET_ERROR; - } - } - } - HI_U32 seg_idx = nnie_cfg_.run_idx_.seg_idx_ - 1; - for (i = 0; i < nnie_cfg_.param_.model_->astSeg[seg_idx].u16DstNum; i++) { - if (nnie_cfg_.param_.mem_cfg_.seg_[seg_idx].dst_node_[i]) { - continue; - } - - j = GetFillIndex(*outputs, output_size, nnie_cfg_.param_.model_->astSeg[seg_idx].astDstNode[i].szName); - if (j == output_size) { - j = i; - LOGI("output tensor name(%s) can't match wk node name(%s).", (*outputs)[j].Name().c_str(), - nnie_cfg_.param_.model_->astSeg[seg_idx].astDstNode[i].szName); - } - - auto input_data_type = (*outputs)[j].DataType(); - if (input_data_type == DataType::kNumberTypeFloat32) { - HI_U32 output_element = static_cast((*outputs)[j].ElementNum()); - auto ptr = reinterpret_cast((*outputs)[j].MutableData()); - if (NnieCommGetOutputData(&nnie_cfg_, ptr, output_element, i) != RET_OK) { - return RET_ERROR; - } - } else { - LOGE("Unsupported DataType!"); - return RET_ERROR; - } - } - - return RET_OK; -} - -int NNIEManager::FillRoiPooling(mindspore::MSTensor *input) { - auto roi_shape = input->Shape(); - if (roi_shape[1] != NNIE_COORDI_NUM) { - LOGE("Roi shape err!"); - return RET_ERROR; - } - - if (roi_shape[0] > static_cast(nnie_cfg_.cfg_.max_roi_num_)) { - LOGE("NNIE_RUNTIME_CONFIG_PATH: The maximum [max_roi_num] value set is less than the actual value: %d < %d.", - nnie_cfg_.cfg_.max_roi_num_, static_cast(roi_shape[0])); - return RET_ERROR; - } - nnie_cfg_.param_.rpn_bbox_.unShape.stWhc.u32Height = roi_shape[0]; - HI_U32 dst_stride = nnie_cfg_.param_.rpn_bbox_.u32Stride; - auto proposal_result = NNIE_CONVERT_64BIT_ADDR(HI_S32, nnie_cfg_.param_.rpn_bbox_.u64VirAddr); - auto float_src_data = reinterpret_cast(input->MutableData()); - - for (size_t j = 0; j < nnie_cfg_.param_.rpn_bbox_.unShape.stWhc.u32Height; j++) { - proposal_result[dst_stride / sizeof(HI_U32) * j] = *(float_src_data++) * NNIE_QUANT_BASE; - proposal_result[dst_stride / sizeof(HI_U32) * j + 1] = *(float_src_data++) * NNIE_QUANT_BASE; - proposal_result[dst_stride / sizeof(HI_U32) * j + 2] = *(float_src_data++) * NNIE_QUANT_BASE; - proposal_result[dst_stride / sizeof(HI_U32) * j + 3] = *(float_src_data++) * NNIE_QUANT_BASE; - } - NnieMemFlushCache(nnie_cfg_.param_.rpn_bbox_.u64PhyAddr, - NNIE_CONVERT_64BIT_ADDR(HI_VOID, nnie_cfg_.param_.rpn_bbox_.u64VirAddr), - dst_stride * nnie_cfg_.param_.rpn_bbox_.unShape.stWhc.u32Height); - - return RET_OK; -} - -int NNIEManager::SetAllocatorTensor(mindspore::MSTensor *tensor, SVP_SRC_BLOB_S *blob, - std::shared_ptr allocator) { - int step; - auto data_type = tensor->DataType(); - if (data_type == DataType::kNumberTypeFloat32) { - step = sizeof(float); - } else if ((data_type == DataType::kNumberTypeUInt8) || (data_type == DataType::kNumberTypeInt8)) { - step = sizeof(unsigned char); - } else { - LOGE("Unsupported DataType!"); - return RET_ERROR; - } - LOGI("\ninput %s :%d * %d = %d <-> %d", tensor->Name().c_str(), step, blob->unShape.stWhc.u32Width, - step * blob->unShape.stWhc.u32Width, blob->u32Stride); - - if (blob->unShape.stWhc.u32Width * step == blob->u32Stride) { - if (((tensor->Data() == nullptr) || tensor->allocator() == allocator) && (blob->u64VirAddr != 0)) { - tensor->SetAllocator(allocator); - tensor->SetData(reinterpret_cast(blob->u64VirAddr)); - LOGI("\nSet input %s allocator!", tensor->Name().c_str()); - } - } - return RET_OK; -} - -int NNIEManager::SetAllocatorInputs(std::vector *inputs, bool run_box, - std::shared_ptr allocator, unsigned int seg_id) { - size_t i; - size_t j; - size_t input_size = inputs->size(); - if (seg_id >= nnie_cfg_.param_.model_->u32NetSegNum) { - LOGE("seg num err!"); - return RET_ERROR; - } - - if (!run_box) { - if ((input_size < kNumInput2) || (input_size - 1) != nnie_cfg_.param_.model_->astSeg[seg_id].u16SrcNum) { - LOGE("Input Size Err!"); - return RET_ERROR; - } - } - - for (i = 0; i < nnie_cfg_.param_.model_->astSeg[seg_id].u16SrcNum; i++) { - if (nnie_cfg_.param_.mem_cfg_.seg_[seg_id].src_node_[i]) { - continue; - } - j = GetFillIndex(*inputs, input_size - 1, nnie_cfg_.param_.model_->astSeg[seg_id].astSrcNode[i].szName); - if (j == (input_size - 1)) { - if (run_box && (*inputs)[i].Name() == "proposal") { - continue; - } else { - j = i; - LOGI("input tensor name(%s) can't match wk node name(%s).", (*inputs)[i].Name().c_str(), - nnie_cfg_.param_.model_->astSeg[seg_id].astSrcNode[i].szName); - } - } - SVP_SRC_BLOB_S *blob = &nnie_cfg_.param_.seg_data_[seg_id].src_[i]; - SVP_BLOB_TYPE_E src_type = blob->enType; - - if (src_type != SVP_BLOB_TYPE_SEQ_S32) { - SetAllocatorTensor(&(*inputs)[j], blob, allocator); - } - } - return RET_OK; -} - -int NNIEManager::SetAllocatorOutputs(std::vector *outputs, bool run_box, - std::shared_ptr allocator, unsigned int seg_id) { - size_t i; - size_t j; - size_t output_size = outputs->size(); - if (output_size != nnie_cfg_.param_.model_->astSeg[seg_id].u16DstNum) { - LOGE("seg%d: %d output tensors are required.", seg_id, nnie_cfg_.param_.model_->astSeg[seg_id].u16DstNum); - return RET_ERROR; - } - - for (i = 0; i < nnie_cfg_.param_.model_->astSeg[seg_id].u16DstNum; i++) { - if (nnie_cfg_.param_.mem_cfg_.seg_[seg_id].dst_node_[i]) { - continue; - } - - j = GetFillIndex(*outputs, output_size, nnie_cfg_.param_.model_->astSeg[seg_id].astDstNode[i].szName); - if (j == output_size) { - j = i; - LOGI("output tensor name(%s) can't match wk node name(%s).", (*outputs)[j].Name().c_str(), - nnie_cfg_.param_.model_->astSeg[seg_id].astDstNode[i].szName); - } - - auto output_data_type = (*outputs)[j].DataType(); - if (output_data_type == DataType::kNumberTypeFloat32) { - SVP_SRC_BLOB_S *blob = &nnie_cfg_.param_.seg_data_[seg_id].dst_[i]; - if (SVP_BLOB_TYPE_U8 <= blob->enType && SVP_BLOB_TYPE_YVU422SP >= blob->enType) { - LOGE("Nnie output type error"); - return RET_ERROR; - } else if (SVP_BLOB_TYPE_SEQ_S32 != blob->enType) { - if ((blob->unShape.stWhc.u32Width * sizeof(float) == blob->u32Stride)) { - if ((((*outputs)[j].Data() == nullptr) || (*outputs)[j].allocator() == allocator) && - (blob->u64VirAddr != 0)) { - (*outputs)[j].SetAllocator(allocator); - (*outputs)[j].SetData(reinterpret_cast(blob->u64VirAddr)); - LOGI("\nSet output %s allocator!", (*outputs)[j].Name().c_str()); - } - } - } - } else { - LOGE("Unsupported DataType!"); - return RET_ERROR; - } - } - return RET_OK; -} - -int NNIEManager::SetAllocator(std::vector *inputs, std::vector *outputs, - std::shared_ptr allocator, unsigned int seg_id) { - bool run_box = false; - if (nnie_cfg_.param_.model_->astSeg[seg_id].enNetType == SVP_NNIE_NET_TYPE_ROI) { - run_box = true; - } - if (SetAllocatorInputs(inputs, run_box, allocator, seg_id) != RET_OK) { - LOGE("SetAllocatorInputs failed!"); - return RET_ERROR; - } - if (SetAllocatorOutputs(outputs, run_box, allocator, seg_id) != RET_OK) { - LOGE("SetAllocatorOutputs failed!"); - return RET_ERROR; - } - return RET_OK; -} - -int NNIEManager::FillData(std::vector *inputs, unsigned int seg_id) { - bool run_box = false; - size_t i, j; - size_t input_size = inputs->size(); - if (seg_id >= nnie_cfg_.param_.model_->u32NetSegNum) { - LOGE("seg num err!"); - return RET_ERROR; - } - - nnie_cfg_.run_idx_.seg_idx_ = seg_id; - - if (nnie_cfg_.param_.model_->astSeg[nnie_cfg_.run_idx_.seg_idx_].enNetType == SVP_NNIE_NET_TYPE_ROI) { - run_box = true; - auto it = - std::find_if(inputs->begin(), inputs->end(), [](mindspore::MSTensor t) { return t.Name() == "proposal"; }); - size_t distance = std::distance(inputs->begin(), it); - if (distance >= input_size - 1) { - LOGE("Can't find proposal out!"); - return RET_ERROR; - } - FillRoiPooling(&(*inputs)[distance]); - } else if ((input_size < kNumInput2) || - (input_size - 1) != nnie_cfg_.param_.model_->astSeg[nnie_cfg_.run_idx_.seg_idx_].u16SrcNum) { - LOGE("Input Size Err!"); - return RET_ERROR; - } - - for (i = 0; i < nnie_cfg_.param_.model_->astSeg[seg_id].u16SrcNum; i++) { - if (nnie_cfg_.param_.mem_cfg_.seg_[seg_id].src_node_[i]) { - continue; - } - j = GetFillIndex(*inputs, input_size - 1, nnie_cfg_.param_.model_->astSeg[seg_id].astSrcNode[i].szName); - if (j == (input_size - 1)) { - if (run_box && (*inputs)[i].Name() == "proposal") { - continue; - } else { - j = i; - LOGI("input tensor name(%s) can't match wk node name(%s).", (*inputs)[i].Name().c_str(), - nnie_cfg_.param_.model_->astSeg[seg_id].astSrcNode[i].szName); - } - } - - auto input_data_type = (*inputs)[j].DataType(); - SVP_BLOB_TYPE_E src_type = nnie_cfg_.param_.seg_data_[seg_id].src_[i].enType; - bool need_i8_or_u8 = SVP_BLOB_TYPE_U8 <= src_type && src_type <= SVP_BLOB_TYPE_YVU422SP; - bool real_i8_or_u8 = input_data_type == DataType::kNumberTypeUInt8 || input_data_type == DataType::kNumberTypeInt8; - if (need_i8_or_u8) { - if (!real_i8_or_u8) { - LOGE("Nnie input node type error!"); - return RET_ERROR; - } - } else { - if (input_data_type != DataType::kNumberTypeFloat32) { - LOGE("Nnie input node type error!"); - return RET_ERROR; - } - } - HI_U32 input_element = static_cast((*inputs)[j].ElementNum()); - if (NnieCommFillData(&nnie_cfg_, (*inputs)[j].MutableData(), input_element, i) != RET_OK) { - LOGE("FillData failed!"); - return RET_ERROR; - } - } - - return RET_OK; -} -} // namespace nnie -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/nnie_manager.h b/mindspore-lite/providers/nnie/src/nnie_manager.h deleted file mode 100644 index b0fdc8ce..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_manager.h +++ /dev/null @@ -1,117 +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_PROVIDERS_NNIE_SRC_NNIE_MANAGER_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_MANAGER_H_ -#include -#include -#include -#include -#include "include/errorcode.h" -#include "include/api/types.h" -#include "include/api/allocator.h" -#include "src/nnie_common.h" -#include "src/nnie_cfg_parser.h" - -namespace mindspore { -namespace nnie { -class NNIEManager { - public: - static NNIEManager *GetInstance(const void *model_buf) { - static std::map managers_; - auto iter = managers_.find(model_buf); - if (iter != managers_.end()) { - return iter->second; - } else { - auto manager = new (std::nothrow) NNIEManager(); - if (manager == nullptr) { - return manager; - } else { - managers_[model_buf] = manager; - return manager; - } - } - } - - NNIEManager() {} - - ~NNIEManager() {} - - int Init(char *model_buf, int size, const std::vector &inputs); - - int CfgInit(const Flags &flags, int max_seg_id); - - void SetInputNum(int max_input_num); - - int SetAllocatorInputs(std::vector *inputs, bool run_box, std::shared_ptr allocator, - unsigned int seg_id); - - int SetAllocatorOutputs(std::vector *outputs, bool run_box, std::shared_ptr allocator, - unsigned int seg_id); - - int SetAllocator(std::vector *inputs, std::vector *outputs, - std::shared_ptr allocator, unsigned int seg_id); - - int FillData(std::vector *inputs, unsigned int seg_id); - - int Run(std::vector *outputs, unsigned int seg_id, - const std::vector> &outputs_shape); - - void Release(bool resize_flag); - - int LoadInputs(std::vector *inputs, std::shared_ptr allocator); - - int LoadOutputs(std::vector *outputs, std::shared_ptr allocator); - - int SetBlobAddr(SVP_SRC_BLOB_S *blob, HI_U64 virt, mindspore::MSTensor *tensor, std::shared_ptr allocator); - - void SetMaxSegId(int max_id) { - if (max_id > max_seg_id_) { - max_seg_id_ = max_id; - } - } - - inline int GetMaxSegId() { return max_seg_id_; } - - inline Flags *GetFlags() { return &flags_; } - - inline bool GetLoadModel() { return load_model_; } - - void SetLoadModel(bool flag) { load_model_ = flag; } - - private: - int SetAllocatorTensor(mindspore::MSTensor *tensor, SVP_SRC_BLOB_S *blob, std::shared_ptr allocator); - - int GetOutputData(std::vector *outputs, const std::vector> &outputs_shape, - bool run_box = false); - - int MallocBlobData(SVP_SRC_BLOB_S *blob, mindspore::MSTensor *tensor, HI_U32 blob_size); - - int FillRoiPooling(mindspore::MSTensor *input); - char *wk_model_ = nullptr; - - int model_size_ = 0; - - NnieRunCfg nnie_cfg_; - int max_seg_id_ = 0; - Flags flags_; - bool load_model_ = false; - std::vector blobs_; - std::vector tensors_; -}; -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_MANAGER_H_ diff --git a/mindspore-lite/providers/nnie/src/nnie_memory.cc b/mindspore-lite/providers/nnie/src/nnie_memory.cc deleted file mode 100644 index 4f80dacf..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_memory.cc +++ /dev/null @@ -1,45 +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 "src/nnie_memory.h" -#include "include/hi_common.h" -#include "include/mpi_sys.h" -#include "src/nnie_common.h" - -namespace mindspore { -namespace nnie { -HI_S32 NnieMemMalloc(const HI_CHAR *mmb, HI_CHAR *zone, HI_U64 *pu_phy_addr, HI_VOID **ppv_vir_addr, HI_U32 size) { - return HI_MPI_SYS_MmzAlloc(pu_phy_addr, ppv_vir_addr, mmb, zone, size); -} - -HI_S32 NnieMemMallocCached(const HI_CHAR *mmb, HI_CHAR *zone, HI_U64 *pu_phy_addr, HI_VOID **ppv_vir_addr, - HI_U32 size) { - return HI_MPI_SYS_MmzAlloc_Cached(pu_phy_addr, ppv_vir_addr, mmb, zone, size); -} - -HI_S32 NnieMemFlushCache(HI_U64 phy_addr, HI_VOID *pv_vir_addr, HI_U32 size) { - return HI_MPI_SYS_MmzFlushCache(phy_addr, pv_vir_addr, size); -} - -HI_S32 NnieGetVirMemInfo(HI_U64 pv_vir_addr, HI_U64 *phy_addr) { - SYS_VIRMEM_INFO_S mem_info; - HI_S32 ret = HI_MPI_SYS_GetVirMemInfo(NNIE_CONVERT_64BIT_ADDR(HI_VOID, pv_vir_addr), &mem_info); - if (ret == HI_SUCCESS) { - *phy_addr = mem_info.u64PhyAddr; - } - return ret; -} -} // namespace nnie -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/nnie_memory.h b/mindspore-lite/providers/nnie/src/nnie_memory.h deleted file mode 100644 index 7c72499a..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_memory.h +++ /dev/null @@ -1,50 +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_PROVIDERS_NNIE_SRC_NNIE_MEMORY_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_MEMORY_H_ -#include -#include -#include -#include -#include -#include "include/hi_common.h" -#include "include/hi_debug.h" -#include "include/hi_comm_svp.h" -#include "include/hi_nnie.h" -#include "include/mpi_nnie.h" -#include "include/mpi_sys.h" - -namespace mindspore { -namespace nnie { -#define NNIE_MEM_FREE(phy, vir) \ - do { \ - if ((0 != (phy)) && (0 != (vir))) { \ - HI_MPI_SYS_MmzFree((phy), reinterpret_cast(static_cast(vir))); \ - (phy) = 0; \ - (vir) = 0; \ - } \ - } while (0) - -HI_S32 NnieMemMalloc(const HI_CHAR *mmb, HI_CHAR *zone, HI_U64 *pu_phy_addr, HI_VOID **ppv_vir_addr, HI_U32 size); - -HI_S32 NnieMemMallocCached(const HI_CHAR *mmb, HI_CHAR *zone, HI_U64 *pu_phy_addr, HI_VOID **ppv_vir_addr, HI_U32 size); - -HI_S32 NnieMemFlushCache(HI_U64 phy_addr, HI_VOID *pv_vir_addr, HI_U32 size); - -HI_S32 NnieGetVirMemInfo(HI_U64 pv_vir_addr, HI_U64 *phy_addr); -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_MEMORY_H_ diff --git a/mindspore-lite/providers/nnie/src/nnie_print.cc b/mindspore-lite/providers/nnie/src/nnie_print.cc deleted file mode 100644 index dc1d2c5b..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_print.cc +++ /dev/null @@ -1,176 +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 "src/nnie_print.h" - -namespace mindspore { -namespace nnie { -HI_S32 NniePrintReportResult(NnieParam *pst_nnie_param) { - HI_U32 u32seg_num = pst_nnie_param->model_->u32NetSegNum; - HI_U32 i, j, k, n; - HI_U32 seg_idx_, node_idx_; - HI_S32 ret; - HI_CHAR acReportFileName[NNIE_REPORT_NAME_LENGTH] = {'\0'}; - FILE *fp = nullptr; - HI_U32 *pu32StepAddr = nullptr; - HI_S32 *ps32ResultAddr = nullptr; - HI_U32 u32Height, u32Width, u32Chn, u32Stride, u32Dim; - - for (seg_idx_ = 0; seg_idx_ < u32seg_num; seg_idx_++) { - for (node_idx_ = 0; node_idx_ < pst_nnie_param->model_->astSeg[seg_idx_].u16DstNum; node_idx_++) { - ret = snprintf(acReportFileName, NNIE_REPORT_NAME_LENGTH, "./ms/fseg%d(%d,%d)_%s.txt", seg_idx_, node_idx_, - pst_nnie_param->model_->astSeg[seg_idx_].astDstNode[node_idx_].u32NodeId, - pst_nnie_param->model_->astSeg[seg_idx_].astDstNode[node_idx_].szName); - if (ret < 0) { - LOGE("Error,create file name failed!"); - return HI_FAILURE; - } - - fp = fopen(acReportFileName, "w"); - if (fp == nullptr) { - LOGE("Error,open file failed!"); - return HI_FAILURE; - } - - if (SVP_BLOB_TYPE_SEQ_S32 == pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].enType) { - u32Dim = pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].unShape.stSeq.u32Dim; - u32Stride = pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].u32Stride; - pu32StepAddr = NNIE_CONVERT_64BIT_ADDR( - HI_U32, pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].unShape.stSeq.u64VirAddrStep); - ps32ResultAddr = - NNIE_CONVERT_64BIT_ADDR(HI_S32, pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].u64VirAddr); - - for (n = 0; n < pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].u32Num; n++) { - for (i = 0; i < *(pu32StepAddr + n); i++) { - for (j = 0; j < u32Dim; j++) { - fprintf(fp, "%f ", static_cast(*(ps32ResultAddr + j)) / NNIE_QUANT_BASE); - } - ps32ResultAddr += u32Stride / sizeof(HI_U32); - } - } - } else { - u32Height = pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].unShape.stWhc.u32Height; - u32Width = pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].unShape.stWhc.u32Width; - u32Chn = pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].unShape.stWhc.u32Chn; - u32Stride = pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].u32Stride; - ps32ResultAddr = - NNIE_CONVERT_64BIT_ADDR(HI_S32, pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].u64VirAddr); - fprintf(fp, "%s 4 1 %d %d %d\n", pst_nnie_param->model_->astSeg[seg_idx_].astDstNode[node_idx_].szName, - u32Height, u32Width, u32Chn); - for (n = 0; n < pst_nnie_param->seg_data_[seg_idx_].dst_[node_idx_].u32Num; n++) { - for (i = 0; i < u32Chn; i++) { - for (j = 0; j < u32Height; j++) { - for (k = 0; k < u32Width; k++) { - ret = fprintf(fp, "%f ", static_cast(*(ps32ResultAddr + k)) / NNIE_QUANT_BASE); - if (ret < 0) { - fclose(fp); - return HI_FAILURE; - } - } - ps32ResultAddr += u32Stride / sizeof(HI_U32); - } - } - } - } - fclose(fp); - } - } - return HI_SUCCESS; -} - -HI_S32 NniePrintReportResultInputSeg(NnieParam *pst_nnie_param, int segnum) { - HI_U32 i, j, k, n; - HI_U32 seg_idx_ = segnum, node_idx_; - HI_S32 ret; - HI_CHAR acReportFileName[NNIE_REPORT_NAME_LENGTH] = {'\0'}; - FILE *fp = nullptr; - HI_U32 *pu32StepAddr = nullptr; - HI_S32 *ps32ResultAddr = nullptr; - HI_U8 *pu8ResultAddr = nullptr; - HI_U32 u32Height, u32Width, u32Chn, u32Stride, u32Dim; - - for (node_idx_ = 0; node_idx_ < pst_nnie_param->model_->astSeg[seg_idx_].u16SrcNum; node_idx_++) { - ret = snprintf(acReportFileName, NNIE_REPORT_NAME_LENGTH, "seg%d_layer%d_input(%s)_inst.linear.hex", seg_idx_, - pst_nnie_param->model_->astSeg[seg_idx_].astSrcNode[node_idx_].u32NodeId, - pst_nnie_param->model_->astSeg[seg_idx_].astSrcNode[node_idx_].szName); - if (ret < 0) { - LOGE("Error,create file name failed!\n"); - return HI_FAILURE; - } - - fp = fopen(acReportFileName, "w"); - if (fp == nullptr) { - LOGE("Error,open file failed!"); - return HI_FAILURE; - } - - if (SVP_BLOB_TYPE_SEQ_S32 == pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].enType) { - u32Dim = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stSeq.u32Dim; - u32Stride = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u32Stride; - pu32StepAddr = NNIE_CONVERT_64BIT_ADDR( - HI_U32, pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stSeq.u64VirAddrStep); - ps32ResultAddr = NNIE_CONVERT_64BIT_ADDR(HI_S32, pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u64VirAddr); - - for (n = 0; n < pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u32Num; n++) { - for (i = 0; i < *(pu32StepAddr + n); i++) { - for (j = 0; j < u32Dim; j++) { - fprintf(fp, "%d ", *(ps32ResultAddr + j)); - } - ps32ResultAddr += u32Stride / sizeof(HI_U32); - } - } - } else if (pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].enType == SVP_BLOB_TYPE_U8) { - u32Height = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stWhc.u32Height; - u32Width = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stWhc.u32Width; - u32Chn = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stWhc.u32Chn; - u32Stride = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u32Stride; - pu8ResultAddr = NNIE_CONVERT_64BIT_ADDR(HI_U8, pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u64VirAddr); - for (n = 0; n < pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u32Num; n++) { - for (i = 0; i < u32Chn; i++) { - for (j = 0; j < u32Height; j++) { - for (k = 0; k < u32Width; k++) { - fprintf(fp, "%d ", *(pu8ResultAddr + k)); - } - pu8ResultAddr += u32Stride / sizeof(HI_U8); - } - } - } - } else { - u32Height = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stWhc.u32Height; - u32Width = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stWhc.u32Width; - u32Chn = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].unShape.stWhc.u32Chn; - u32Stride = pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u32Stride; - ps32ResultAddr = NNIE_CONVERT_64BIT_ADDR(HI_S32, pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u64VirAddr); - fprintf(fp, "%s 4 1 %d %d %d\n", pst_nnie_param->model_->astSeg[seg_idx_].astSrcNode[node_idx_].szName, u32Height, - u32Width, u32Chn); - for (n = 0; n < pst_nnie_param->seg_data_[seg_idx_].src_[node_idx_].u32Num; n++) { - for (i = 0; i < u32Chn; i++) { - for (j = 0; j < u32Height; j++) { - for (k = 0; k < u32Width; k++) { - fprintf(fp, "%f ", static_cast(*(ps32ResultAddr + k) / NNIE_QUANT_BASE)); - } - ps32ResultAddr += u32Stride / sizeof(HI_U32); - } - } - } - } - fclose(fp); - } - - return HI_SUCCESS; -} -} // namespace nnie -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie/src/nnie_print.h b/mindspore-lite/providers/nnie/src/nnie_print.h deleted file mode 100644 index 389716df..00000000 --- a/mindspore-lite/providers/nnie/src/nnie_print.h +++ /dev/null @@ -1,58 +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_PROVIDERS_NNIE_SRC_NNIE_PRINT_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_PRINT_H_ -#include "include/mpi_nnie.h" -#include "include/hi_type.h" -#include "src/nnie_common.h" -#include "src/nnie_memory.h" - -#define LOG_TAG1 "NNIE" -#define LOGE(format, ...) \ - do { \ - if (1) { \ - fprintf(stderr, "\n[ERROR] " LOG_TAG1 " [" __FILE__ ":%d] %s] ", __LINE__, __FUNCTION__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - } \ - } while (0) - -#define LOGW(format, ...) \ - do { \ - if (1) { \ - fprintf(stderr, "\n[Warning] " LOG_TAG1 " [" __FILE__ ":%d] %s] ", __LINE__, __FUNCTION__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - } \ - } while (0) - -#define LOGI(format, ...) \ - do { \ - if (0) { \ - fprintf(stderr, "\n[Warning] " LOG_TAG1 " [" __FILE__ ":%d] %s] ", __LINE__, __FUNCTION__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - } \ - } while (0) - -constexpr int kMaxSize = 1024; -constexpr int kDecimal = 10; - -namespace mindspore { -namespace nnie { -HI_S32 NniePrintReportResult(NnieParam *pst_nnie_param); - -HI_S32 NniePrintReportResultInputSeg(NnieParam *pst_nnie_param, int segnum); -} // namespace nnie -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_SRC_NNIE_PRINT_H_ diff --git a/mindspore-lite/providers/nnie_proposal/CMakeLists.txt b/mindspore-lite/providers/nnie_proposal/CMakeLists.txt deleted file mode 100644 index af3f6e03..00000000 --- a/mindspore-lite/providers/nnie_proposal/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.12) -project(NNIE_proposal) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime/include) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../runtime/include/third_party) - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src COMMON_SRC3) - -add_library(mslite_proposal SHARED ${COMMON_SRC3} - ${CMAKE_CURRENT_SOURCE_DIR}/../../src/litert/cxx_api/kernel.cc - ${CMAKE_CURRENT_SOURCE_DIR}/../../src/registry/kernel_interface_registry.cc) -target_link_libraries(mslite_proposal ${LINK_LOCAT_LIB}) diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal.cc b/mindspore-lite/providers/nnie_proposal/src/proposal.cc deleted file mode 100644 index 240558db..00000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal.cc +++ /dev/null @@ -1,622 +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 "src/proposal.h" -#include -#include -#include -#include "include/errorcode.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace proposal { -constexpr int kNumInput2 = 2; -constexpr int kScoreSizeIndex = 2; -constexpr int kKeyConfidenceIndex = 4; -constexpr int kPredWeightIndex = 2; -constexpr int KPredHeightIndex = 3; -uint32_t RpnTmpBufSize(uint32_t num_ratio_anchors, uint32_t num_scale_anchors, uint32_t input_height, - uint32_t input_width) { - uint32_t anchors_num = num_ratio_anchors * num_scale_anchors * input_height * input_width; - uint32_t anchors_size = sizeof(uint32_t) * COORDI_NUM * anchors_num; - uint32_t bbox_delta_size = anchors_size; - uint32_t proposal_size = sizeof(uint32_t) * PROPOSAL_WIDTH * anchors_num; - uint32_t ratio_anchors_size = sizeof(float) * num_ratio_anchors * COORDI_NUM; - uint32_t scale_anchors_size = sizeof(float) * num_ratio_anchors * num_scale_anchors * COORDI_NUM; - uint32_t score_size = sizeof(float) * anchors_num * kScoreSizeIndex; - uint32_t stack_size = sizeof(Stack) * anchors_num; - uint32_t total_size = - anchors_size + bbox_delta_size + proposal_size + ratio_anchors_size + scale_anchors_size + score_size + stack_size; - return total_size; -} - -static float exp_coef[10][16] = { - {1.0f, 1.00024f, 1.00049f, 1.00073f, 1.00098f, 1.00122f, 1.00147f, 1.00171f, 1.00196f, 1.0022f, 1.00244f, 1.00269f, - 1.00293f, 1.00318f, 1.00342f, 1.00367f}, - {1.0f, 1.00391f, 1.00784f, 1.01179f, 1.01575f, 1.01972f, 1.02371f, 1.02772f, 1.03174f, 1.03578f, 1.03984f, 1.04391f, - 1.04799f, 1.05209f, 1.05621f, 1.06034f}, - {1.0f, 1.06449f, 1.13315f, 1.20623f, 1.28403f, 1.36684f, 1.45499f, 1.54883f, 1.64872f, 1.75505f, 1.86825f, 1.98874f, - 2.117f, 2.25353f, 2.39888f, 2.55359f}, - {1.0f, 2.71828f, 7.38906f, 20.0855f, 54.5981f, 148.413f, 403.429f, 1096.63f, 2980.96f, 8103.08f, 22026.5f, 59874.1f, - 162755.0f, 442413.0f, 1.2026e+006f, 3.26902e+006f}, - {1.0f, 8.88611e+006f, 7.8963e+013f, 7.01674e+020f, 6.23515e+027f, 5.54062e+034f, 5.54062e+034f, 5.54062e+034f, - 5.54062e+034f, 5.54062e+034f, 5.54062e+034f, 5.54062e+034f, 5.54062e+034f, 5.54062e+034f, 5.54062e+034f, - 5.54062e+034f}, - {1.0f, 0.999756f, 0.999512f, 0.999268f, 0.999024f, 0.99878f, 0.998536f, 0.998292f, 0.998049f, 0.997805f, 0.997562f, - 0.997318f, 0.997075f, 0.996831f, 0.996588f, 0.996345f}, - {1.0f, 0.996101f, 0.992218f, 0.98835f, 0.984496f, 0.980658f, 0.976835f, 0.973027f, 0.969233f, 0.965455f, 0.961691f, - 0.957941f, 0.954207f, 0.950487f, 0.946781f, 0.94309f}, - {1.0f, 0.939413f, 0.882497f, 0.829029f, 0.778801f, 0.731616f, 0.687289f, 0.645649f, 0.606531f, 0.569783f, 0.535261f, - 0.502832f, 0.472367f, 0.443747f, 0.416862f, 0.391606f}, - {1.0f, 0.367879f, 0.135335f, 0.0497871f, 0.0183156f, 0.00673795f, 0.00247875f, 0.000911882f, 0.000335463f, - 0.00012341f, 4.53999e-005f, 1.67017e-005f, 6.14421e-006f, 2.26033e-006f, 8.31529e-007f, 3.05902e-007f}, - {1.0f, 1.12535e-007f, 1.26642e-014f, 1.42516e-021f, 1.60381e-028f, 1.80485e-035f, 2.03048e-042f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}; -static float QuickExp(int32_t value) { - if (value & 0x80000000) { - value = ~value + 0x00000001; - return exp_coef[5][value & 0x0000000F] * exp_coef[6][(value >> 4) & 0x0000000F] * - exp_coef[7][(value >> 8) & 0x0000000F] * exp_coef[8][(value >> 12) & 0x0000000F] * - exp_coef[9][(value >> 16) & 0x0000000F]; - } else { - return exp_coef[0][value & 0x0000000F] * exp_coef[1][(value >> 4) & 0x0000000F] * - exp_coef[2][(value >> 8) & 0x0000000F] * exp_coef[3][(value >> 12) & 0x0000000F] * - exp_coef[4][(value >> 16) & 0x0000000F]; - } -} - -static int32_t SoftMax(float *src, uint32_t num) { - float max = 0; - float sum = 0; - uint32_t i = 0; - - for (i = 0; i < num; ++i) { - if (max < src[i]) { - max = src[i]; - } - } - - for (i = 0; i < num; ++i) { - src[i] = QuickExp(static_cast((src[i] - max) * QUANT_BASE)); - sum += src[i]; - } - - for (i = 0; i < num; ++i) { - src[i] /= sum; - } - return RET_OK; -} -static void Argswap(int32_t *src1, int32_t *src2) { - for (uint32_t i = 0; i < PROPOSAL_WIDTH; i++) { - int32_t tmp = src1[i]; - src1[i] = src2[i]; - src2[i] = tmp; - } -} - -static int32_t NonRecursiveArgQuickSort(int32_t *array, int32_t low, int32_t high, Stack *stack, int32_t max_num) { - int32_t top = 0; - stack[top].min_ = low; - stack[top].max_ = high; - - while (top > -1) { - low = stack[top].min_; - high = stack[top].max_; - int32_t i = low; - int32_t j = high; - - int32_t key_confidence = array[PROPOSAL_WIDTH * low + kKeyConfidenceIndex]; - top--; - while (i < j) { - while ((i < j) && (key_confidence > array[j * PROPOSAL_WIDTH + 4])) { - j--; - } - if (i < j) { - Argswap(&array[i * PROPOSAL_WIDTH], &array[j * PROPOSAL_WIDTH]); - i++; - } - - while ((i < j) && (key_confidence < array[i * PROPOSAL_WIDTH + 4])) { - i++; - } - if (i < j) { - Argswap(&array[i * PROPOSAL_WIDTH], &array[j * PROPOSAL_WIDTH]); - j--; - } - } - - if (low <= max_num) { - if (low < i - 1) { - top++; - stack[top].min_ = low; - stack[top].max_ = i - 1; - } - - if (high > i + 1) { - top++; - stack[top].min_ = i + 1; - stack[top].max_ = high; - } - } - } - return RET_OK; -} - -static int32_t FilterLowScoreBbox(int32_t *proposals, uint32_t anchors_num, uint32_t filter_thresh, - uint32_t *num_after_filter) { - if (proposals == nullptr) { - LOGE("inputs proposals is nullptr"); - return RET_ERROR; - } - uint32_t proposal_cnt = anchors_num; - - if (filter_thresh > 0) { - uint32_t i; - for (i = 0; i < anchors_num; i++) { - if (proposals[PROPOSAL_WIDTH * i + 4] < static_cast(filter_thresh)) { - proposals[PROPOSAL_WIDTH * i + 5] = 1; - } - } - - proposal_cnt = 0; - for (i = 0; i < anchors_num; i++) { - if (proposals[PROPOSAL_WIDTH * i + 5] == 0) { - proposals[PROPOSAL_WIDTH * proposal_cnt] = proposals[PROPOSAL_WIDTH * i]; - proposals[PROPOSAL_WIDTH * proposal_cnt + 1] = proposals[PROPOSAL_WIDTH * i + 1]; - proposals[PROPOSAL_WIDTH * proposal_cnt + 2] = proposals[PROPOSAL_WIDTH * i + 2]; - proposals[PROPOSAL_WIDTH * proposal_cnt + 3] = proposals[PROPOSAL_WIDTH * i + 3]; - proposals[PROPOSAL_WIDTH * proposal_cnt + 4] = proposals[PROPOSAL_WIDTH * i + 4]; - proposals[PROPOSAL_WIDTH * proposal_cnt + 5] = proposals[PROPOSAL_WIDTH * i + 5]; - proposal_cnt++; - } - } - } - *num_after_filter = proposal_cnt; - return RET_OK; -} - -static int32_t SVP_NNIE_Overlap(int32_t x_min1, int32_t y_min1, int32_t x_max1, int32_t y_max1, int32_t x_min2, - int32_t y_min2, int32_t x_max2, int32_t y_max2, int32_t *area_sum, - int32_t *area_inter) { - /*** Check the input, and change the Return value ***/ - int32_t inter = 0; - int32_t total = 0; - int32_t x_min = 0; - int32_t y_min = 0; - int32_t x_max = 0; - int32_t y_max = 0; - int32_t area1 = 0; - int32_t area2 = 0; - int32_t inter_width = 0; - int32_t inter_height = 0; - - x_min = MAX(x_min1, x_min2); - y_min = MAX(y_min1, y_min2); - x_max = MIN(x_max1, x_max2); - y_max = MIN(y_max1, y_max2); - - inter_width = x_max - x_min + 1; - inter_height = y_max - y_min + 1; - - inter_width = (inter_width >= 0) ? inter_width : 0; - inter_height = (inter_height >= 0) ? inter_height : 0; - - inter = inter_width * inter_height; - area1 = (x_max1 - x_min1 + 1) * (y_max1 - y_min1 + 1); - area2 = (x_max2 - x_min2 + 1) * (y_max2 - y_min2 + 1); - - total = area1 + area2 - inter; - - *area_sum = total; - *area_inter = inter; - return RET_OK; -} - -static int32_t SVP_NNIE_NonMaxSuppression(int32_t *proposals, uint32_t anchors_num, uint32_t nms_thresh, - uint32_t max_roi_num) { - if (proposals == nullptr) { - LOGE("inputs proposals is nullptr"); - return RET_ERROR; - } - /****** define variables *******/ - int32_t x_min1; - int32_t y_min1; - int32_t x_max1; - int32_t y_max1; - int32_t x_min2; - int32_t y_min2; - int32_t x_max2; - int32_t y_max2; - int32_t s32AreaTotal = 0; - int32_t area_inter = 0; - uint32_t i; - uint32_t j; - uint32_t num = 0; - bool bNoOverlap; - for (i = 0; i < anchors_num && num < max_roi_num; i++) { - if (proposals[PROPOSAL_WIDTH * i + 5] == 0) { - num++; - x_min1 = proposals[PROPOSAL_WIDTH * i]; - y_min1 = proposals[PROPOSAL_WIDTH * i + 1]; - x_max1 = proposals[PROPOSAL_WIDTH * i + 2]; - y_max1 = proposals[PROPOSAL_WIDTH * i + 3]; - for (j = i + 1; j < anchors_num; j++) { - if (proposals[PROPOSAL_WIDTH * j + 5] == 0) { - x_min2 = proposals[PROPOSAL_WIDTH * j]; - y_min2 = proposals[PROPOSAL_WIDTH * j + 1]; - x_max2 = proposals[PROPOSAL_WIDTH * j + 2]; - y_max2 = proposals[PROPOSAL_WIDTH * j + 3]; - bNoOverlap = (x_min2 > x_max1) || (x_max2 < x_min1) || (y_min2 > y_max1) || (y_max2 < y_min1); - if (bNoOverlap) { - continue; - } - (void)SVP_NNIE_Overlap(x_min1, y_min1, x_max1, y_max1, x_min2, y_min2, x_max2, y_max2, &s32AreaTotal, - &area_inter); - if (area_inter * QUANT_BASE > static_cast(nms_thresh * s32AreaTotal)) { - if (proposals[PROPOSAL_WIDTH * i + 4] >= proposals[PROPOSAL_WIDTH * j + 4]) { - proposals[PROPOSAL_WIDTH * j + 5] = 1; - } else { - proposals[PROPOSAL_WIDTH * i + 5] = 1; - } - } - } - } - } - } - return RET_OK; -} - -static void Rpn(float **inputs, uint32_t num_ratio_anchors, uint32_t num_scale_anchors, uint32_t *scales, - uint32_t *ratios, uint32_t ori_image_height, uint32_t ori_image_width, uint32_t *inputs_height, - uint32_t *inputs_width, uint32_t *inputs_channel, uint32_t inputs_stride, uint32_t max_rois, - uint32_t min_size, uint32_t spatial_scale, uint32_t nms_thresh, uint32_t filter_thresh, - uint32_t num_before_nms, char *pu32MemPool, float *proposal_result, uint32_t dst_stride, - uint32_t *num_rois) { - /******************** define parameters ****************/ - uint32_t size; - int32_t *anchors = nullptr; - int32_t *bbox_delta = nullptr; - int32_t *proposals = nullptr; - int32_t *ptr1 = nullptr; - int32_t *ptr2 = nullptr; - int32_t *ptr3 = nullptr; - uint32_t num_after_filter = 0; - uint32_t num_anchors; - float base_w; - float base_h; - float base_x_ctr; - float base_y_ctr; - float *ratio_anchors = nullptr; - float *f32_ptr = nullptr; - float *f32_ptr2 = nullptr; - float *scale_anchors = nullptr; - float *scores = nullptr; - float f32_size; - uint32_t pixel_interval; - uint32_t src_bbox_index; - uint32_t src_fg_prob_index; - uint32_t src_bg_prob_index; - uint32_t src_bbox_bias; - uint32_t src_prob_bias; - uint32_t des_box; - uint32_t bg_blob_size; - uint32_t anchors_per_pixel; - uint32_t map_size; - uint32_t line_size; - int32_t proposal_width; - int32_t proposal_height; - uint32_t roi_count; - Stack *stack = nullptr; - uint32_t c; - uint32_t h; - uint32_t w; - uint32_t i; - uint32_t j; - uint32_t p; - uint32_t q; - uint32_t z; - uint32_t base_anchor[4] = {0, 0, (min_size - 1), (min_size - 1)}; - - /*********************************** Faster RCNN *********************************************/ - /********* calculate the start pointer of each part in MemPool *********/ - anchors = reinterpret_cast(pu32MemPool); - num_anchors = num_ratio_anchors * num_scale_anchors * (inputs_height[0] * inputs_width[0]); - size = COORDI_NUM * num_anchors; - pu32MemPool += size * sizeof(int32_t); - - bbox_delta = reinterpret_cast(pu32MemPool); - pu32MemPool += size * sizeof(int32_t); - - proposals = reinterpret_cast(pu32MemPool); - size = PROPOSAL_WIDTH * num_anchors; - pu32MemPool += size * sizeof(int32_t); - - ratio_anchors = reinterpret_cast(static_cast(pu32MemPool)); - f32_ptr = reinterpret_cast(static_cast(pu32MemPool)); - size = num_ratio_anchors * COORDI_NUM; - f32_ptr = f32_ptr + size; - - scale_anchors = f32_ptr; - size = num_scale_anchors * num_ratio_anchors * COORDI_NUM; - f32_ptr = f32_ptr + size; - - scores = f32_ptr; - size = num_anchors * SCORE_NUM; - f32_ptr = f32_ptr + size; - - stack = reinterpret_cast(f32_ptr); - - /********************* Generate the base anchor ***********************/ - base_w = static_cast(base_anchor[2] - base_anchor[0] + 1); - base_h = static_cast(base_anchor[3] - base_anchor[1] + 1); - base_x_ctr = static_cast(base_anchor[0] + ((base_w - 1) * 0.5)); - base_y_ctr = static_cast(base_anchor[1] + ((base_h - 1) * 0.5)); - - /*************** Generate Ratio Anchors for the base anchor ***********/ - f32_ptr = ratio_anchors; - f32_size = base_w * base_h; - for (i = 0; i < num_ratio_anchors; i++) { - float f32_ratios = static_cast(ratios[i]) / QUANT_BASE; - base_w = sqrt(f32_size / f32_ratios); - base_w = static_cast( - 1.0 * ((base_w) >= 0 ? static_cast(base_w + HALF_VAL) : static_cast(base_w - HALF_VAL))); - base_h = base_w * f32_ratios; - base_h = static_cast( - 1.0 * ((base_h) >= 0 ? static_cast(base_h + HALF_VAL) : static_cast(base_h - HALF_VAL))); - - *f32_ptr++ = static_cast(base_x_ctr - ((base_w - 1) * HALF_VAL)); - *(f32_ptr++) = static_cast(base_y_ctr - ((base_h - 1) * HALF_VAL)); - *(f32_ptr++) = static_cast(base_x_ctr + ((base_w - 1) * HALF_VAL)); - *(f32_ptr++) = static_cast(base_y_ctr + ((base_h - 1) * HALF_VAL)); - } - - /********* Generate Scale Anchors for each Ratio Anchor **********/ - f32_ptr = ratio_anchors; - f32_ptr2 = scale_anchors; - /* Generate Scale Anchors for one pixel */ - for (i = 0; i < num_ratio_anchors; i++) { - for (j = 0; j < num_scale_anchors; j++) { - base_w = *(f32_ptr + 2) - *(f32_ptr) + 1; - base_h = *(f32_ptr + 3) - *(f32_ptr + 1) + 1; - base_x_ctr = static_cast(*(f32_ptr) + ((base_w - 1) * HALF_VAL)); - base_y_ctr = static_cast(*(f32_ptr + 1) + ((base_h - 1) * HALF_VAL)); - - *(f32_ptr2++) = - static_cast(base_x_ctr - ((base_w * (static_cast(scales[j]) / QUANT_BASE) - 1) * HALF_VAL)); - *(f32_ptr2++) = - static_cast(base_y_ctr - ((base_h * (static_cast(scales[j]) / QUANT_BASE) - 1) * HALF_VAL)); - *(f32_ptr2++) = - static_cast(base_x_ctr + ((base_w * (static_cast(scales[j]) / QUANT_BASE) - 1) * HALF_VAL)); - *(f32_ptr2++) = - static_cast(base_y_ctr + ((base_h * (static_cast(scales[j]) / QUANT_BASE) - 1) * HALF_VAL)); - } - f32_ptr += COORDI_NUM; - } - - /******************* Copy the anchors to every pixel in the feature map ******************/ - ptr1 = anchors; - if (spatial_scale == 0) { - LOGE("inputs spatial_scale is zero."); - return; - } - pixel_interval = QUANT_BASE / spatial_scale; - - for (p = 0; p < inputs_height[0]; p++) { - for (q = 0; q < inputs_width[0]; q++) { - f32_ptr2 = scale_anchors; - for (z = 0; z < num_scale_anchors * num_ratio_anchors; z++) { - *(ptr1++) = static_cast(q * pixel_interval + *(f32_ptr2++)); - *(ptr1++) = static_cast(p * pixel_interval + *(f32_ptr2++)); - *(ptr1++) = static_cast(q * pixel_interval + *(f32_ptr2++)); - *(ptr1++) = static_cast(p * pixel_interval + *(f32_ptr2++)); - } - } - } - - /********** do transpose, convert the blob from (M,C,H,W) to (M,H,W,C) **********/ - map_size = inputs_height[1] * inputs_stride / sizeof(uint32_t); - anchors_per_pixel = num_ratio_anchors * num_scale_anchors; - bg_blob_size = anchors_per_pixel * map_size; - line_size = inputs_stride / sizeof(uint32_t); - src_prob_bias = 0; - src_bbox_bias = 0; - - for (c = 0; c < inputs_channel[1]; c++) { - for (h = 0; h < inputs_height[1]; h++) { - for (w = 0; w < inputs_width[1]; w++) { - src_bbox_index = src_bbox_bias + c * map_size + h * line_size + w; - src_bg_prob_index = src_prob_bias + (c / COORDI_NUM) * map_size + h * line_size + w; - src_fg_prob_index = bg_blob_size + src_bg_prob_index; - - des_box = (anchors_per_pixel) * (h * inputs_width[1] + w) + c / COORDI_NUM; - - uint32_t des_bbox_delta_index = COORDI_NUM * des_box + c % COORDI_NUM; - bbox_delta[des_bbox_delta_index] = static_cast(inputs[1][src_bbox_index] * QUANT_BASE); - - uint32_t des_score_index = (SCORE_NUM)*des_box; - scores[des_score_index] = inputs[0][src_bg_prob_index]; - scores[des_score_index + 1] = inputs[0][src_fg_prob_index]; - } - } - } - - /************************* do softmax ****************************/ - f32_ptr = scores; - for (i = 0; i < num_anchors; i++) { - SoftMax(f32_ptr, SCORE_NUM); - f32_ptr += SCORE_NUM; - } - - /************************* BBox Transform *****************************/ - for (i = 0; i < num_anchors; i++) { - ptr1 = anchors; - ptr1 = ptr1 + COORDI_NUM * i; - ptr2 = proposals; - ptr2 = ptr2 + PROPOSAL_WIDTH * i; - ptr3 = bbox_delta; - ptr3 = ptr3 + COORDI_NUM * i; - f32_ptr = scores; - f32_ptr = f32_ptr + i * (SCORE_NUM); - - proposal_width = *(ptr1 + 2) - *(ptr1) + 1; - proposal_height = *(ptr1 + 3) - *(ptr1 + 1) + 1; - int32_t proposal_center_x = *(ptr1) + static_cast(proposal_width * HALF_VAL); - int32_t proposal_center_y = *(ptr1 + 1) + static_cast(proposal_height * HALF_VAL); - int32_t pred_center_x = - static_cast((static_cast(*(ptr3)) / QUANT_BASE) * proposal_width + proposal_center_x); - int32_t pred_center_y = - static_cast((static_cast(*(ptr3 + 1)) / QUANT_BASE) * proposal_height + proposal_center_y); - - int32_t pred_w = static_cast(proposal_width * QuickExp(static_cast(*(ptr3 + kPredWeightIndex)))); - int32_t pred_h = static_cast(proposal_height * QuickExp(static_cast(*(ptr3 + KPredHeightIndex)))); - *(ptr2) = static_cast(pred_center_x - HALF_VAL * pred_w); - *(ptr2 + 1) = static_cast(pred_center_y - HALF_VAL * pred_h); - *(ptr2 + 2) = static_cast(pred_center_x + HALF_VAL * pred_w); - *(ptr2 + 3) = static_cast(pred_center_y + HALF_VAL * pred_h); - *(ptr2 + 4) = static_cast(*(f32_ptr + 1) * QUANT_BASE); - *(ptr2 + 5) = 0; - } - - /************************ clip bbox *****************************/ - for (i = 0; i < num_anchors; i++) { - ptr1 = proposals; - ptr1 = ptr1 + PROPOSAL_WIDTH * i; - *ptr1 = MAX(MIN(*ptr1, static_cast(ori_image_width) - 1), 0); - *(ptr1 + 1) = MAX(MIN(*(ptr1 + 1), static_cast(ori_image_height) - 1), 0); - *(ptr1 + 2) = MAX(MIN(*(ptr1 + 2), static_cast(ori_image_width) - 1), 0); - *(ptr1 + 3) = MAX(MIN(*(ptr1 + 3), static_cast(ori_image_height) - 1), 0); - } - - /************ remove the bboxes which are too small *************/ - for (i = 0; i < num_anchors; i++) { - ptr1 = proposals; - ptr1 = ptr1 + PROPOSAL_WIDTH * i; - proposal_width = *(ptr1 + 2) - *(ptr1) + 1; - proposal_height = *(ptr1 + 3) - *(ptr1 + 1) + 1; - if (proposal_width < static_cast(min_size) || proposal_height < static_cast(min_size)) { - *(ptr1 + 5) = 1; - } - } - - /********** remove low score bboxes ************/ - (void)FilterLowScoreBbox(proposals, num_anchors, filter_thresh, &num_after_filter); - - /********** sort ***********/ - (void)NonRecursiveArgQuickSort(proposals, 0, num_after_filter - 1, stack, static_cast(num_before_nms)); - num_after_filter = (num_after_filter < num_before_nms) ? num_after_filter : num_before_nms; - - /* do nms to remove highly overlapped bbox */ - (void)SVP_NNIE_NonMaxSuppression(proposals, num_after_filter, nms_thresh, max_rois); /* function NMS */ - - /************** write the final result to output ***************/ - roi_count = 0; - for (i = 0; i < num_after_filter; i++) { - ptr1 = proposals; - ptr1 = ptr1 + PROPOSAL_WIDTH * i; - if (*(ptr1 + 5) == 0) { - proposal_result[dst_stride / sizeof(uint32_t) * roi_count] = *ptr1; - proposal_result[dst_stride / sizeof(uint32_t) * roi_count + 1] = *(ptr1 + 1); - proposal_result[dst_stride / sizeof(uint32_t) * roi_count + 2] = *(ptr1 + 2); - proposal_result[dst_stride / sizeof(uint32_t) * roi_count + 3] = *(ptr1 + 3); - roi_count++; - } - if (roi_count >= max_rois) { - break; - } - } - - *num_rois = roi_count; -} - -int32_t ProposalInit(ProposalParam *param, uint32_t max_roi_num, uint32_t ori_image_height, uint32_t ori_image_width) { - uint32_t tmp_buf_size = 0; - uint32_t bbox_buf_size = 0; - uint32_t total_size = 0; - param->max_roi_num_ = max_roi_num; - - param->num_ratio_anchors_ = 1; - param->num_scale_anchors_ = NUM_SCALE_ANCHORS; - param->scales_[0] = 1.5 * QUANT_BASE; - param->scales_[1] = 2.1 * QUANT_BASE; - param->scales_[2] = 2.9 * QUANT_BASE; - param->scales_[3] = 4.1 * QUANT_BASE; - param->scales_[4] = 5.8 * QUANT_BASE; - param->scales_[5] = 8.0 * QUANT_BASE; - param->scales_[6] = 11.3 * QUANT_BASE; - param->scales_[7] = 15.8 * QUANT_BASE; - param->scales_[8] = 22.1 * QUANT_BASE; - param->ratios_[0] = 2.44 * QUANT_BASE; - - param->ori_image_height_ = ori_image_height; - param->ori_image_width_ = ori_image_width; - param->min_size_ = MIN_SIZE; - param->spatial_scale_ = (uint32_t)(0.0625 * QUANT_BASE); - param->nms_thresh_ = (uint32_t)(0.7 * QUANT_BASE); - param->filter_thresh_ = 0; - param->num_before_nms_ = NUM_NMS; - - param->rpn_bounding_box_.chn_ = 1; - param->rpn_bounding_box_.height_ = max_roi_num; - param->rpn_bounding_box_.width_ = COORDI_NUM; - param->rpn_bounding_box_.stride_ = COORDI_NUM * sizeof(float); - param->rpn_bounding_box_.num_ = 1; - - tmp_buf_size = RpnTmpBufSize(param->num_ratio_anchors_, param->num_scale_anchors_, param->inputs_height_[0], - param->inputs_width_[0]); - - bbox_buf_size = param->rpn_bounding_box_.num_ * param->rpn_bounding_box_.height_ * param->rpn_bounding_box_.stride_; - total_size = tmp_buf_size + bbox_buf_size; - - if (param->rpn_tmp_buf_ != nullptr) { - free(param->rpn_tmp_buf_); - param->rpn_tmp_buf_ = nullptr; - } - param->rpn_tmp_buf_ = malloc(total_size); - if (param->rpn_tmp_buf_ == nullptr) { - LOGE("malloc buf fail."); - return RET_ERROR; - } - param->rpn_bounding_box_.data_ = reinterpret_cast(param->rpn_tmp_buf_) + tmp_buf_size; - - return RET_OK; -} - -int32_t ProposalRun(ProposalParam *param) { - for (int i = 0; i < kNumInput2; i++) { - if (param->inputs_[i] == nullptr) { - LOGE("inputs is nullptr."); - return RET_ERROR; - } - } - Rpn(param->inputs_, param->num_ratio_anchors_, param->num_scale_anchors_, param->scales_, param->ratios_, - param->ori_image_height_, param->ori_image_width_, param->inputs_height_, param->inputs_width_, - param->inputs_channel_, param->inputs_stride_, param->max_roi_num_, param->min_size_, param->spatial_scale_, - param->nms_thresh_, param->filter_thresh_, param->num_before_nms_, reinterpret_cast(param->rpn_tmp_buf_), - reinterpret_cast(param->rpn_bounding_box_.data_), param->rpn_bounding_box_.stride_, - ¶m->rpn_bounding_box_.height_); - return RET_OK; -} - -void ProposalDeInit(ProposalParam *param) { - if (param->rpn_tmp_buf_ != 0) { - free(param->rpn_tmp_buf_); - param->rpn_tmp_buf_ = 0; - } -} -} // namespace proposal -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal.h b/mindspore-lite/providers/nnie_proposal/src/proposal.h deleted file mode 100644 index 41b23c42..00000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal.h +++ /dev/null @@ -1,93 +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_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_H_ -#include -#include "include/api/types.h" - -#define LOG_TAG1 "Proposal" -#define LOGE(format, ...) \ - do { \ - if (1) { \ - fprintf(stderr, "\n[ERROR] " LOG_TAG1 " [" __FILE__ ":%d] %s] ", __LINE__, __FUNCTION__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - } \ - } while (0) - -#define LOGW(format, ...) \ - do { \ - if (1) { \ - fprintf(stderr, "\n[Warning] " LOG_TAG1 " [" __FILE__ ":%d] %s] ", __LINE__, __FUNCTION__); \ - fprintf(stderr, format, ##__VA_ARGS__); \ - } \ - } while (0) - -namespace mindspore { -namespace proposal { -typedef struct { - uint32_t stride_; - void *data_; - uint32_t num_; - uint32_t width_; - uint32_t height_; - uint32_t chn_; -} RpnBoundingBox; - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define HALF_VAL 0.5f // the half value -#define COORDI_NUM 4 // coordinate numbers -#define PROPOSAL_WIDTH 6 // the number of proposal values -#define QUANT_BASE 4096 // the base value -#define SCORE_NUM 2 // the num of RPN scores -#define NUM_SCALE_ANCHORS 9 -#define NUM_NMS 6000 -#define MIN_SIZE 16 - -typedef struct { - uint32_t scales_[9]; - uint32_t ratios_[9]; - uint32_t inputs_height_[2]; - uint32_t inputs_width_[2]; - uint32_t inputs_channel_[2]; - uint32_t inputs_stride_; - uint32_t num_ratio_anchors_; - uint32_t num_scale_anchors_; - uint32_t ori_image_height_; - uint32_t ori_image_width_; - uint32_t min_size_; - uint32_t spatial_scale_; - uint32_t nms_thresh_; - uint32_t filter_thresh_; - uint32_t max_roi_num_; - uint32_t num_before_nms_; - float *inputs_[2]; - void *rpn_tmp_buf_; - RpnBoundingBox rpn_bounding_box_; -} ProposalParam; - -typedef struct { - int32_t min_; - int32_t max_; -} Stack; - -int32_t ProposalInit(ProposalParam *param, uint32_t max_roi_num, uint32_t ori_image_height, uint32_t ori_image_width); -int32_t ProposalRun(ProposalParam *param); -void ProposalDeInit(ProposalParam *param); -} // namespace proposal -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_H_ diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.cc b/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.cc deleted file mode 100644 index c87b5ece..00000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.cc +++ /dev/null @@ -1,236 +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 "src/proposal_fp32.h" -#include -#include -#include -#include "schema/model_generated.h" -#include "include/registry/register_kernel.h" -#include "include/errorcode.h" -#include "src/common/utils.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace proposal { -constexpr int kMaxSize = 1024; -constexpr int kNumInput2 = 2; -constexpr int kDecimal = 10; -constexpr auto kMazRoiNum = "MaxROINum"; -constexpr int kNCHWDims = 4; -constexpr int kNCHWFormatH = 2; -constexpr int kNCHWFormatW = 3; -constexpr int kNCHWFormatC = 1; -bool IsValidUnsignedNum(const std::string &num_str) { - return !num_str.empty() && std::all_of(num_str.begin(), num_str.end(), ::isdigit); -} - -void PrintInvalidChar(const std::string &key, const std::string &dat) { - auto message = key + " configuration contains invalid characters: \'" + dat + "\'"; - LOGE(message.c_str()); -} - -int ProposalCPUKernel::Prepare() { - if (inputs_.size() < kNumInput2) { - LOGE("inputs tensor num error."); - return RET_ERROR; - } - if (outputs_.size() != 1) { - LOGE("outputs tensor num error."); - return RET_ERROR; - } - std::vector inputs_name = {"rpn_cls_score", "rpn_bbox_pred"}; - std::vector inputs; - for (size_t i = 0; i < inputs_name.size(); i++) { - bool find_flag = false; - for (auto &input : inputs_) { - if (input.Name() == inputs_name[i]) { - inputs.push_back(input); - find_flag = true; - break; - } - } - if (!find_flag) { - for (auto &input : inputs_) { - if (std::find(inputs.begin(), inputs.end(), input) != inputs.end()) { - continue; - } - inputs.push_back(input); - LOGW("input tensor name diff '%s' vs '%s'.", inputs_name[i].c_str(), input.Name().c_str()); - break; - } - } - } - if (inputs.size() != inputs_name.size()) { - LOGE("inputs size error."); - return RET_ERROR; - } - this->set_inputs(inputs); - if (inputs[0].Shape()[0] != 1) { - LOGE("proposal only support input num == 1."); - return RET_ERROR; - } - - outputs_[0].SetTensorName("proposal"); - - int max_roi_num_int = 300; - auto nnie_arg = GetConfig("nnie"); - if (nnie_arg.find(kMazRoiNum) != nnie_arg.end()) { - if (!lite::ConvertStrToInt(nnie_arg.at(kMazRoiNum), &max_roi_num_int)) { - PrintInvalidChar(kMazRoiNum, nnie_arg.at(kMazRoiNum)); - return RET_ERROR; - } - } - - for (size_t i = 0; i < inputs.size(); i++) { - auto ptr_shape = inputs[i].Shape(); - if ((ptr_shape.size() == kNCHWDims)) { - proposal_param_.inputs_height_[i] = ptr_shape[kNCHWFormatH]; - proposal_param_.inputs_width_[i] = ptr_shape[kNCHWFormatW]; - proposal_param_.inputs_channel_[i] = ptr_shape[kNCHWFormatC]; - if (i == 0) { - proposal_param_.inputs_stride_ = ptr_shape[kNCHWFormatW] * sizeof(float); - } - } else { - LOGE("proposal only support input shape size == 4."); - return RET_ERROR; - } - } - return ProposalInit(&proposal_param_, max_roi_num_int, image_height_, image_weight_); -} - -int ProposalCPUKernel::ReSize() { - if (inputs_[0].Shape()[0] != 1) { - LOGE("proposal only support input num == 1."); - return RET_ERROR; - } - return RET_OK; -} - -int ProposalCPUKernel::Execute() { - for (int i = 0; i < kNumInput2; i++) { - proposal_param_.inputs_[i] = reinterpret_cast(inputs_[i].MutableData()); - } - if (ProposalRun(&proposal_param_) != RET_OK) { - LOGE("ProposalRun error."); - return RET_ERROR; - } - std::vector shape{static_cast(proposal_param_.rpn_bounding_box_.height_), COORDI_NUM}; - outputs_[0].SetShape(shape); - auto output_data = outputs_[0].MutableData(); - memcpy(output_data, proposal_param_.rpn_bounding_box_.data_, - proposal_param_.rpn_bounding_box_.height_ * COORDI_NUM * sizeof(float)); - return RET_OK; -} - -ProposalCPUKernel::~ProposalCPUKernel() { ProposalDeInit(&proposal_param_); } - -bool GetCustomAttr(char *buf, int buf_size, const mindspore::schema::Custom *op, const std::string &attr) { - int attr_size; - for (size_t i = 0; i < op->attr()->size(); i++) { - if (op->attr()->Get(i)->name()->str() == attr) { - auto output_info = op->attr()->Get(i)->data(); - attr_size = static_cast(output_info->size()); - if (attr_size >= buf_size) { - LOGE("attr size too big"); - return false; - } - for (int j = 0; j < attr_size; j++) { - buf[j] = static_cast(output_info->Get(j)); - } - buf[attr_size] = 0; - return true; - } - } - return false; -} - -std::shared_ptr ProposalCreateKernel(const std::vector &inputs, - const std::vector &outputs, - const mindspore::schema::Primitive *primitive, - const mindspore::Context *ctx) { - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - LOGE("Primitive type is not PrimitiveType_Custom"); - return nullptr; - } - - auto op = primitive->value_as_Custom(); - if (op->attr()->size() < 1) { - LOGE("There are at least 1 attribute of Custom"); - return nullptr; - } - int64_t ndims; - int64_t image_height; - int64_t image_width; - - char *res = nullptr; - char buf[kMaxSize]; - if (GetCustomAttr(buf, kMaxSize, op, "proposal_id")) { - res = nullptr; - ndims = strtol(buf, &res, kDecimal); - if ((*res) != 0) { - LOGE("Get attr id data fail"); - return nullptr; - } - } else { - LOGE("Proposal Custom op should have id"); - return nullptr; - } - - if (GetCustomAttr(buf, kMaxSize, op, "image_height")) { - res = nullptr; - image_height = strtol(buf, &res, kDecimal); - if ((*res) != 0) { - LOGE("Get attr id data fail"); - return nullptr; - } - } else { - LOGE("Proposal Custom op should have image_height"); - return nullptr; - } - if (GetCustomAttr(buf, kMaxSize, op, "image_width")) { - res = nullptr; - image_width = strtol(buf, &res, kDecimal); - if ((*res) != 0) { - LOGE("Get attr id data fail"); - return nullptr; - } - } else { - LOGE("Proposal Custom op should have image_width"); - return nullptr; - } - - auto kernel = std::make_shared(inputs, outputs, primitive, ctx, ndims, image_height, image_width); - if (kernel == nullptr) { - LOGE("new custom kernel is nullptr"); - return nullptr; - } - return kernel; -} -} // namespace proposal -} // namespace mindspore - -namespace mindspore { -namespace kernel { -namespace { -const auto kFloat32 = DataType::kNumberTypeFloat32; -} -REGISTER_CUSTOM_KERNEL(CPU, NNIE, kFloat32, Proposal, proposal::ProposalCreateKernel) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.h b/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.h deleted file mode 100644 index e46d618e..00000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal_fp32.h +++ /dev/null @@ -1,50 +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_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_FP32_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_FP32_H_ - -#include -#include "schema/model_generated.h" -#include "include/api/kernel.h" -#include "src/proposal.h" - -using mindspore::kernel::Kernel; -namespace mindspore { -namespace proposal { -class ProposalCPUKernel : public Kernel { - public: - ProposalCPUKernel(const std::vector &inputs, const std::vector &outputs, - const mindspore::schema::Primitive *primitive, const mindspore::Context *ctx, int id, - int image_height, int image_width) - : Kernel(inputs, outputs, primitive, ctx), id_(id), image_height_(image_height), image_weight_(image_width) {} - - ~ProposalCPUKernel() override; - - int Prepare() override; - int ReSize() override; - int Execute() override; - - private: - proposal::ProposalParam proposal_param_ = {0}; - int64_t id_; - int64_t image_height_; - int64_t image_weight_; -}; -} // namespace proposal -} // namespace mindspore - -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_FP32_H_ diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal_infer.cc b/mindspore-lite/providers/nnie_proposal/src/proposal_infer.cc deleted file mode 100644 index 58e4a6d0..00000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal_infer.cc +++ /dev/null @@ -1,72 +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 "src/proposal_infer.h" -#include -#include -#include "include/errorcode.h" -#include "src/proposal.h" -#include "include/api/format.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace proposal { -std::shared_ptr ProposalInferCreater() { - auto infer = std::make_shared(); - if (infer == nullptr) { - LOGE("new custom infer is nullptr"); - return nullptr; - } - - return infer; -} -Status ProposalInterface::Infer(std::vector *inputs, std::vector *outputs, - const mindspore::schema::Primitive *primitive) { - if (inputs->size() != 2) { - LOGE("Inputs size less 2"); - return kLiteError; - } - if (outputs->size() == 0) { - LOGE("Outputs size 0"); - return kLiteError; - } - if (primitive->value_type() != mindspore::schema::PrimitiveType_Custom) { - LOGE("Primitive type is not PrimitiveType_Custom"); - return kLiteError; - } - - size_t id = 0; - while (id < outputs->size()) { - std::vector shape{-1, COORDI_NUM}; - (*outputs)[id].SetShape(shape); - (*outputs)[id].SetDataType(DataType::kNumberTypeFloat32); - (*outputs)[id].SetFormat(Format::NCHW); - id++; - } - return kSuccess; -} -} // namespace proposal -} // namespace mindspore -namespace mindspore { -namespace kernel { -REGISTER_CUSTOM_KERNEL_INTERFACE(NNIE, Proposal, proposal::ProposalInferCreater); -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/providers/nnie_proposal/src/proposal_infer.h b/mindspore-lite/providers/nnie_proposal/src/proposal_infer.h deleted file mode 100644 index fe81d8b7..00000000 --- a/mindspore-lite/providers/nnie_proposal/src/proposal_infer.h +++ /dev/null @@ -1,35 +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_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_INFER_H_ -#define MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_INFER_H_ -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace proposal { -class ProposalInterface : public mindspore::kernel::KernelInterface { - public: - ProposalInterface() {} - - ~ProposalInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const mindspore::schema::Primitive *primitive) override; -}; -} // namespace proposal -} // namespace mindspore -#endif // MINDSPORE_LITE_PROVIDERS_NNIE_PROPOSAL_SRC_PROPOSAL_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/CMakeLists.txt b/mindspore-lite/tools/converter/adapter/dpico/CMakeLists.txt deleted file mode 100644 index 4e7d8aa7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/CMakeLists.txt +++ /dev/null @@ -1,62 +0,0 @@ -cmake_minimum_required(VERSION 3.14) -project(DPICO_CONVERTER) - -if(DEFINED ENV{HISI_SDK_PATH}) - set(SD3403_ATC_LIB_PATH $ENV{HISI_SDK_PATH}/sd3403_sdk/dpico_atc_adapter) -else() - message(FATAL_ERROR "error, HISI_SDK_PATH env not found") -endif() - -set(OPENCV_PATH ${SD3403_ATC_LIB_PATH}/opencv-4.5.2) -set(PROTOBUF_PATH ${SD3403_ATC_LIB_PATH}/protobuf-3.13.0) -set(PICO_PROTO_PATH ${SD3403_ATC_LIB_PATH}/pico_proto_0924) -set(PICO_MAPPER_PATH ${SD3403_ATC_LIB_PATH}/pico_mapper_0924) - -set(PROTOC ${PROTOBUF_PATH}/bin/protoc) -set(PROTO_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/pico_proto) -file(MAKE_DIRECTORY ${PROTO_OUTPUT_PATH}) -execute_process(COMMAND chmod +x ${PROTOC}) -execute_process(COMMAND - ${PROTOC} -I=${PICO_PROTO_PATH} --cpp_out=${PROTO_OUTPUT_PATH} pico_caffe.proto) -execute_process(COMMAND - ${PROTOC} -I=${TOP_DIR}/third_party/proto/onnx --cpp_out=${PROTO_OUTPUT_PATH} onnx.proto) - -file(GLOB_RECURSE DPICO_SRC - ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/common/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/parser/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/checker/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/infer/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/mapper/*.cc - ${PROTO_OUTPUT_PATH}/onnx.pb.cc - ${PROTO_OUTPUT_PATH}/pico_caffe.pb.cc - ) - -set(DPICO_SRC ${DPICO_SRC} ${TOOLS_DIR}/converter/adapter/utils.cc) - -include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(BEFORE ${OPENCV_PATH}include/opencv4) -include_directories(BEFORE ${PROTOBUF_PATH}/include) -include_directories(${PICO_MAPPER_PATH}/include) -include_directories(${PROTO_OUTPUT_PATH}) -include_directories(${TOOLS_DIR}/converter) - -link_directories(${pico_mapper_SOURCE_DIR}/lib) -set_property(SOURCE ${DPICO_SRC} PROPERTY COMPILE_DEFINITIONS - LOG_HDR_FILE_REL_PATH="mindspore-lite/../mindspore/mindspore/core/include/utils/log_adapter.h" - SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) - -add_library(dpico_atc_adapter SHARED ${DPICO_SRC}) -add_dependencies(dpico_atc_adapter fbs_src fbs_inner_src) -target_link_libraries(dpico_atc_adapter - ${PICO_MAPPER_PATH}/lib/libsvp_atc_api.so - ${PROTOBUF_PATH}/lib/libprotobuf.so.3.13.0.0 - ${OPENCV_PATH}/lib/libopencv_core.so.4.11.0 - ${OPENCV_PATH}/lib/libopencv_imgcodecs.so.4.11.0 - ${OPENCV_PATH}/lib/libopencv_imgproc.so.4.11.0 - stdc++fs) - -if((NOT WIN32) AND ${CMAKE_BUILD_TYPE} STREQUAL "Release") - add_custom_command(TARGET dpico_atc_adapter POST_BUILD COMMAND strip - ${CMAKE_CURRENT_BINARY_DIR}/libdpico_atc_adapter.so) -endif() diff --git a/mindspore-lite/tools/converter/adapter/dpico/OWNERS b/mindspore-lite/tools/converter/adapter/dpico/OWNERS deleted file mode 100644 index f7bfd7af..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/OWNERS +++ /dev/null @@ -1,8 +0,0 @@ -approvers: -- jjfeing -- YeFeng_24 -- fatmouse007fatmouse007 -- xu_anyue - -options: - no_parent_owners: true diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.cc deleted file mode 100644 index affa9c26..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.cc +++ /dev/null @@ -1,56 +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 "checker/activation_checker.h" -#include -#include -#include "mindapi/base/types.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -const std::unordered_set kSupportedActivationTypes = { - ActivationType::RELU, ActivationType::RELU6, ActivationType::LEAKY_RELU, ActivationType::SIGMOID, - ActivationType::TANH, ActivationType::HSWISH, ActivationType::HARD_TANH, ActivationType::ELU}; -} // namespace -bool ActivationChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(INFO) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto value_ptr = primitive->GetAttr(ops::kActivationType); - if (value_ptr == nullptr) { - MS_LOG(ERROR) << "kActivationType attr is nullptr."; - return false; - } - auto activation_type = static_cast(api::GetValue(value_ptr)); - if (kSupportedActivationTypes.find(activation_type) == kSupportedActivationTypes.end()) { - MS_LOG(WARNING) << "Not supported activation type: " << activation_type << ", will turn it to custom op. " - << op->fullname_with_scope(); - return false; - } - return true; -} - -OpCheckerRegistrar g_ActivationChecker("Activation", new ActivationChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.h deleted file mode 100644 index aac5a3d0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/activation_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ACTIVATION_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ACTIVATION_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ActivationChecker : public OpChecker { - public: - ActivationChecker() : OpChecker("Activation") {} - ~ActivationChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ACTIVATION_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.cc deleted file mode 100644 index f4b573fc..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.cc +++ /dev/null @@ -1,64 +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 "checker/argmax_checker.h" -#include -#include -#include "common/fetch_content.h" -#include "common/op_attr.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool ArgMaxChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr." << op->fullname_with_scope(); - return false; - } - if (primitive->GetAttr(ops::kTopK) != nullptr) { - auto top_k = static_cast(api::GetValue(primitive->GetAttr(ops::kTopK))); - if (top_k != 1) { - MS_LOG(WARNING) << "top_k value only supports 1 for dpico. " << op->fullname_with_scope(); - return false; - } - } - - if (primitive->GetAttr(ops::kAxis) != nullptr) { - auto axis = api::GetValue(primitive->GetAttr(ops::kAxis)); - if (axis <= kAxisLowerBound || axis > kAxisUpperBound || axis == 0) { - MS_LOG(WARNING) << op->fullname_with_scope() << "'s axis should in range (-4, 0) and (0, 3], but in fact it's " - << axis; - return false; - } - } - if (primitive->GetAttr(dpico::kSelectLastIndex) != nullptr) { - auto select_last_index = api::GetValue(primitive->GetAttr(dpico::kSelectLastIndex)); - if (!select_last_index) { - MS_LOG(WARNING) << "select_last_index value only supports true for dpico. " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_ArgMaxChecker("ArgMaxFusion", new ArgMaxChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.h deleted file mode 100644 index 4ab803ed..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/argmax_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ARGMAX_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ARGMAX_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ArgMaxChecker : public OpChecker { - public: - ArgMaxChecker() : OpChecker("ArgMax") {} - ~ArgMaxChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ARGMAX_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.cc deleted file mode 100644 index 364b6234..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.cc +++ /dev/null @@ -1,97 +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 "checker/arithmetic_checker.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/check_base.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool ArithmeticChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - auto prim = api::GetValueNode(op->input(0)); - MS_CHECK_TRUE_MSG(prim != nullptr, false, "prim is nullptr." << op->fullname_with_scope()); - - if (op->size() != kDims3) { - MS_LOG(ERROR) << op->fullname_with_scope() << " only supports 2 inputs."; - return false; - } - - if (HasOfflineData(op->input(kInputIndex1)) || HasOfflineData(op->input(kInputIndex2))) { - MS_LOG(DEBUG) << "parameter node don't need to check. " << op->fullname_with_scope(); - return true; - } - - ShapeVector input_1_shape; - ShapeVector input_2_shape; - if (GetInputShapeFromCNode(op, kInputIndex1, &input_1_shape) != RET_OK || - GetInputShapeFromCNode(op, kInputIndex2, &input_2_shape) != RET_OK) { - MS_LOG(ERROR) << "get input shape failed. " << op->fullname_with_scope(); - return false; - } - - if (input_1_shape == input_2_shape) { - return true; - } - - std::unordered_set supported_broadcast_ops = {"AddFusion", "SubFusion", "MulFusion"}; - std::string op_type_name; - if (GetPrimitiveType(op, &op_type_name) != RET_OK) { - MS_LOG(ERROR) << "get cnode primitive type failed:" << op->fullname_with_scope(); - return false; - } - if (supported_broadcast_ops.find(op_type_name) == supported_broadcast_ops.end()) { - MS_LOG(WARNING) << op->fullname_with_scope() << " don't support broadcast by dpico."; - return false; - } - if (input_1_shape.size() != input_2_shape.size()) { - MS_LOG(WARNING) << op->fullname_with_scope() << " input dim_size should be the same."; - return false; - } - if (input_1_shape.size() == kDims4) { - bool has_same_val = false; - for (size_t i = 1; i < kDims4; i++) { - if (input_1_shape.at(i) == input_2_shape.at(i)) { - has_same_val = true; - } - } - if (!has_same_val) { - MS_LOG(WARNING) << "don't support broadcast chw by dpico. " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_AddFusionChecker("AddFusion", new ArithmeticChecker()); -OpCheckerRegistrar g_SubFusionChecker("SubFusion", new ArithmeticChecker()); -OpCheckerRegistrar g_MulFusionChecker("MulFusion", new ArithmeticChecker()); -OpCheckerRegistrar g_DivFusionChecker("DivFusion", new ArithmeticChecker()); -OpCheckerRegistrar g_MaximumChecker("Maximum", new ArithmeticChecker()); -OpCheckerRegistrar g_MinimumChecker("Minimum", new ArithmeticChecker()); -OpCheckerRegistrar g_SquaredDifferenceChecker("SquaredDifference", new ArithmeticChecker()); -OpCheckerRegistrar g_X_DIV_YChecker("X_DIV_Y", new ArithmeticChecker()); -OpCheckerRegistrar g_X_LOG_YChecker("X_LOG_Y", new ArithmeticChecker()); -OpCheckerRegistrar g_BiasAddChecker("BiasAdd", new ArithmeticChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.h deleted file mode 100644 index eaae8519..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/arithmetic_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ARITHMETIC_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ARITHMETIC_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ArithmeticChecker : public OpChecker { - public: - ArithmeticChecker() : OpChecker("Arithmetic") {} - ~ArithmeticChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ARITHMETIC_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.cc deleted file mode 100644 index 3fd49e12..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.cc +++ /dev/null @@ -1,49 +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 -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "checker/batchnorm_checker.h" - -namespace mindspore { -namespace dpico { -bool BatchNormChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive_c is nullptr." << op->fullname_with_scope(); - return false; - } - if (primitive->GetAttr(kUseGlobalStats) != nullptr) { - auto use_global_stats = api::GetValue(primitive->GetAttr(kUseGlobalStats)); - if (!use_global_stats) { - MS_LOG(WARNING) << "use global stats attr is false, which is not supported by dpico. " - << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_BatchNormChecker("BatchNorm", new BatchNormChecker()); -OpCheckerRegistrar g_FusedBatchNormChecker("FusedBatchNorm", new BatchNormChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.h deleted file mode 100644 index b7b9f798..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/batchnorm_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_BATCHNORM_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_BATCHNORM_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class BatchNormChecker : public OpChecker { - public: - BatchNormChecker() : OpChecker("BatchNorm") {} - ~BatchNormChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_BATCHNORM_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.cc deleted file mode 100644 index de1c226f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.cc +++ /dev/null @@ -1,71 +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 "checker/common_checker.h" -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool CommonChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - return true; -} - -OpCheckerRegistrar g_AbsChecker("Abs", new CommonChecker()); -OpCheckerRegistrar g_NegChecker("Neg", new CommonChecker()); -OpCheckerRegistrar g_EluChecker("Elu", new CommonChecker()); -OpCheckerRegistrar g_NormalizeChecker("Normalize", new CommonChecker()); -OpCheckerRegistrar g_PreluChecker("PReLUFusion", new CommonChecker()); -OpCheckerRegistrar g_UpsampleChecker("Upsample", new CommonChecker()); -OpCheckerRegistrar g_GatherChecker("Gather", new CommonChecker()); -OpCheckerRegistrar g_ClipChecker("Clip", new CommonChecker()); -OpCheckerRegistrar g_ShapeChecker("Shape", new CommonChecker()); -OpCheckerRegistrar g_TileChecker("TileFusion", new CommonChecker()); -OpCheckerRegistrar g_UnSqueezeChecker("Unsqueeze", new CommonChecker()); -OpCheckerRegistrar g_BnllChecker("Bnll", new CommonChecker()); -OpCheckerRegistrar g_CropChecker("Crop", new CommonChecker()); -OpCheckerRegistrar g_RoiAlignChecker("RoiAlign", new CommonChecker()); -OpCheckerRegistrar g_CastChecker("Cast", new CommonChecker()); -OpCheckerRegistrar g_BiasChecker("Bias", new CommonChecker()); -OpCheckerRegistrar g_CoshChecker("Cosh", new CommonChecker()); -OpCheckerRegistrar g_AcosChecker("Acos", new CommonChecker()); -OpCheckerRegistrar g_AcoshChecker("Acosh", new CommonChecker()); -OpCheckerRegistrar g_SinhChecker("Sinh", new CommonChecker()); -OpCheckerRegistrar g_AsinhChecker("Asinh", new CommonChecker()); -OpCheckerRegistrar g_AtanhChecker("Atanh", new CommonChecker()); -OpCheckerRegistrar g_BitShiftChecker("BitShift", new CommonChecker()); -OpCheckerRegistrar g_GreaterOrEqualChecker("GreaterEqual", new CommonChecker()); -OpCheckerRegistrar g_LessOrEqualChecker("LessEqual", new CommonChecker()); -OpCheckerRegistrar g_SoftsignChecker("Softsign", new CommonChecker()); -OpCheckerRegistrar g_HardmaxChecker("Hardmax", new CommonChecker()); -OpCheckerRegistrar g_ModChecker("Mod", new CommonChecker()); -OpCheckerRegistrar g_SqrtChecker("Sqrt", new CommonChecker()); -OpCheckerRegistrar g_ShrinkChecker("Shrink", new CommonChecker()); -OpCheckerRegistrar g_GatherElementsChecker("GatherD", new CommonChecker()); -OpCheckerRegistrar g_XorChecker("Xor", new CommonChecker()); -OpCheckerRegistrar g_HardSigmoidChecker("HardSigmoid", new CommonChecker()); -OpCheckerRegistrar g_PadChecker("PadFusion", new CommonChecker()); -OpCheckerRegistrar g_MishChecker("Mish", new CommonChecker()); -OpCheckerRegistrar g_MaxUnPoolChecker("MaxUnpool", new CommonChecker()); -OpCheckerRegistrar g_CustomChecker("Custom", new CommonChecker()); -OpCheckerRegistrar g_LSTMChecker("LSTM", new CommonChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.h deleted file mode 100644 index 5a11b94e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/common_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_COMMON_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_COMMON_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class CommonChecker : public OpChecker { - public: - CommonChecker() : OpChecker("Common") {} - ~CommonChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_COMMON_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.cc deleted file mode 100644 index b82bf508..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.cc +++ /dev/null @@ -1,89 +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 "checker/concat_checker.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -bool CheckConcatInputW(const ShapeVector &input_shape, int64_t axis, int64_t input_w) { - bool supported = true; - if (input_shape.size() == kDims2 && input_w > UINT_MAX) { - supported = false; - } else if (static_cast(axis) == kAxis1 && input_w > UINT_MAX) { - supported = false; - } else if (static_cast(axis) == kAxis2 && input_w > kMaxInputWOf2Dims) { - supported = false; - } else if (static_cast(axis) == kAxis3 && input_w > kMaxInputWOf4Dims) { - supported = false; - } - if (!supported) { - MS_LOG(WARNING) << "input_w " << input_w << " is unsupported by dpico."; - } - return supported; -} -} // namespace -bool ConcatChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr." << op->fullname_with_scope(); - return false; - } - int64_t axis = 0; - auto axis_ptr = primitive->GetAttr(ops::kAxis); - if (axis_ptr != nullptr) { - axis = api::GetValue(axis_ptr); - if (axis < kAxisLowerBound || axis > kAxisUpperBound) { - MS_LOG(WARNING) << op->fullname_with_scope() << "'s axis should in range [-4, 3], but in fact it's " << axis; - return false; - } - } - - if (op->size() - 1 > static_cast(kMaxBottomNum)) { - MS_LOG(WARNING) << op->fullname_with_scope() << "'s bottom size:" << (op->size() - 1) << " is greater than " - << kMaxBottomNum; - return false; - } - - std::vector input_shape; - for (size_t i = 1; i < op->size(); i++) { - auto input = op->input(i); - if (input->cast() != nullptr && input->cast()->has_default()) { - MS_LOG(WARNING) << "there is offline data in concat, which dpico is unsupported. " << op->fullname_with_scope(); - return false; - } - if (GetInputShapeFromCNode(op, i, &input_shape) == RET_OK && !input_shape.empty()) { - int64_t input_w; - if (GetWidth(input_shape, format, &input_w) != RET_OK) { - MS_LOG(ERROR) << "get input_w failed." << op->fullname_with_scope(); - return false; - } - if (!CheckConcatInputW(input_shape, axis, input_w)) { - return false; - } - } - } - return true; -} - -OpCheckerRegistrar g_ConcatChecker("Concat", new ConcatChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.h deleted file mode 100644 index d63695ec..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/concat_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CONCAT_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CONCAT_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ConcatChecker : public OpChecker { - public: - ConcatChecker() : OpChecker("Concat") {} - ~ConcatChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CONCAT_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.cc deleted file mode 100644 index e60845ca..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.cc +++ /dev/null @@ -1,200 +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 "checker/conv2d_checker.h" -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "common/check_base.h" -#include "infer/cxx_api/conv2d_fusion.h" -#include "infer/cxx_api/conv2d_transpose_fusion.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kMaxGroupNum = 2048; -constexpr int kMaxPadSize = 7; -constexpr int kMaxKernelSize = 15; -constexpr int kMaxStrideSize = 7; -constexpr int kMaxDilationSize = 5; -constexpr int kMaxDilationAndKernelProd = 15; -constexpr int kConvUpperBound = 2048; -constexpr float kCoefficient = 16.0; - -bool CheckOutChannel(const api::PrimitivePtr &primitive) { - auto out_channel_ptr = primitive->GetAttr(ops::kOutChannel); - if (out_channel_ptr != nullptr) { - auto out_channel_data = api::GetValue(out_channel_ptr); - if (out_channel_data < 1 || out_channel_data > kMaxNumOutput) { - MS_LOG(WARNING) << "out_channel:" << out_channel_data << " is unsupported by dpico."; - return false; - } - } - return true; -} -bool CheckGroup(const api::PrimitivePtr &primitive) { - auto group_ptr = primitive->GetAttr(ops::kGroup); - if (group_ptr != nullptr) { - auto group_data = api::GetValue(group_ptr); - if (group_data < 1 || group_data > kMaxGroupNum) { - MS_LOG(WARNING) << "group:" << group_data << " is unsupported by dpico."; - return false; - } - } - return true; -} -bool CheckPadList(const api::PrimitivePtr &primitive) { - auto pad_ptr = primitive->GetAttr(ops::kPadList); - if (pad_ptr != nullptr) { - auto pad_data = api::GetValue>(pad_ptr); - if (pad_data.size() > kDims3) { - if (pad_data[0] < 0 || pad_data[0] > kMaxPadSize || pad_data[1] < 0 || pad_data[1] > kMaxPadSize || - pad_data[kAxis2] < 0 || pad_data[kAxis2] > kMaxPadSize || pad_data[kAxis3] < 0 || - pad_data[kAxis3] > kMaxPadSize) { - MS_LOG(WARNING) << "pad size exceed the maximum pad size:" << kMaxPadSize; - return false; - } - } - } - return true; -} -bool CheckKernelSize(const api::PrimitivePtr &primitive) { - auto kernel_ptr = primitive->GetAttr(ops::kKernelSize); - if (kernel_ptr != nullptr) { - auto kernel_data = api::GetValue>(kernel_ptr); - if (kernel_data.size() > 1) { - if (kernel_data[0] < 1 || kernel_data[0] > kMaxKernelSize || kernel_data[1] < 1 || - kernel_data[1] > kMaxKernelSize) { - MS_LOG(WARNING) << "kernel size exceed the maximum kernel size:" << kMaxKernelSize; - return false; - } - } - } - return true; -} -bool CheckStride(const api::PrimitivePtr &primitive) { - auto stride_ptr = primitive->GetAttr(ops::kStride); - if (stride_ptr != nullptr) { - auto stride_data = api::GetValue>(stride_ptr); - if (stride_data.size() > 1) { - if (stride_data[0] < 1 || stride_data[0] > kMaxStrideSize || stride_data[1] < 1 || - stride_data[1] > kMaxStrideSize) { - MS_LOG(WARNING) << "stride[0]:" << stride_data[0] << " or stride[1]:" << stride_data[1] - << "is out of range [1,7]" << kMaxStrideSize; - return false; - } - } - } - return true; -} -bool CheckDilation(const api::PrimitivePtr &primitive) { - auto dilation_ptr = primitive->GetAttr(ops::kDilation); - if (dilation_ptr != nullptr) { - auto dilation_data = api::GetValue>(dilation_ptr); - if (dilation_data.size() > 1) { - if (dilation_data[0] < 1 || dilation_data[0] > kMaxDilationSize || dilation_data[1] < 1 || - dilation_data[1] > kMaxDilationSize) { - MS_LOG(WARNING) << "dilation[0]:" << dilation_data[0] << " or dilation[1]:" << dilation_data[1] - << "is out of range [1,5]" << kMaxDilationSize; - return false; - } - } - } - return true; -} -bool CheckAttr(const api::CNodePtr &op, const api::PrimitivePtr &primitive, int64_t input_w) { - auto dilation_ptr = primitive->GetAttr(ops::kDilation); - auto kernel_ptr = primitive->GetAttr(ops::kKernelSize); - auto stride_ptr = primitive->GetAttr(ops::kStride); - auto output_paddings_ptr = primitive->GetAttr(ops::kOutputPaddings); - - if (dilation_ptr != nullptr && kernel_ptr != nullptr) { - auto kernel_data = api::GetValue>(kernel_ptr); - auto dilation_data = api::GetValue>(dilation_ptr); - if ((kernel_data[0] - 1) * dilation_data[0] + 1 > kMaxDilationAndKernelProd || - (kernel_data[1] - 1) * dilation_data[1] + 1 > kMaxDilationAndKernelProd) { - MS_LOG(WARNING) << "kernel should satisfy ((kernel - 1) * dilation + 1) less than 15"; - return false; - } - } - if (stride_ptr != nullptr && kernel_ptr != nullptr) { - auto kernel_data = api::GetValue>(kernel_ptr); - auto stride_data = api::GetValue>(stride_ptr); - if (CheckPrimitiveType(op, api::MakeShared())) { - MS_CHECK_TRUE_MSG(kCoefficient * stride_data[1] != 0, false, "kCoefficient * stride_data[1] should not be 0."); - if (kernel_data[0] > kConvUpperBound / (input_w / (kCoefficient * stride_data[1]) * stride_data[1])) { - MS_LOG(WARNING) << "kernel and stride should satisfy kernel_h <= 2048 / (w / (16 * stride) * stride) " - << op->fullname_with_scope(); - return false; - } - } else if (CheckPrimitiveType(op, api::MakeShared())) { - MS_CHECK_TRUE_MSG(input_w != 0, false, "input_w should not be 0."); - if (kernel_data[0] > (kMaxNumOutput / input_w - 1) * stride_data[0] + 1) { - MS_LOG(WARNING) << "kernel and stride should satisfy kernel_h <= (32768 / w - 1) * stride + 1 " - << op->fullname_with_scope(); - return false; - } - } - } - - if (output_paddings_ptr != nullptr && CheckPrimitiveType(op, api::MakeShared())) { - auto output_paddings = api::GetValue>(output_paddings_ptr); - if (std::find_if_not(output_paddings.begin(), output_paddings.end(), - [](int64_t output_padding) { return output_padding == 0; }) != output_paddings.end()) { - MS_LOG(WARNING) << "output_padding attr only support 0 by dpico. " << op->fullname_with_scope(); - return false; - } - } - return true; -} -} // namespace - -bool Conv2DFusionChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - - std::vector input_shape; - if (GetInputShapeFromCNode(op, kInputIndex1, &input_shape) == RET_OK && !input_shape.empty()) { - if (input_shape.size() != kDims4) { - MS_LOG(ERROR) << "Error conv2d input, which size should be 4"; - return false; - } - int64_t input_w; - if (GetWidth(input_shape, format, &input_w) != RET_OK) { - MS_LOG(ERROR) << "get input_w failed"; - return false; - } - if (input_w > kMaxInputWOf4Dims) { - MS_LOG(WARNING) << "input_w " << input_w << " is greater than " << kMaxInputWOf4Dims << " " - << op->fullname_with_scope(); - return false; - } - if (!CheckAttr(op, primitive, input_w)) { - return false; - } - } - return CheckOutChannel(primitive) && CheckGroup(primitive) && CheckPadList(primitive) && CheckKernelSize(primitive) && - CheckStride(primitive) && CheckDilation(primitive); -} - -OpCheckerRegistrar g_Conv2DFusionChecker("Conv2DFusion", new Conv2DFusionChecker()); -OpCheckerRegistrar g_Conv2dTransposeFusionChecker("Conv2dTransposeFusion", new Conv2DFusionChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.h deleted file mode 100644 index beb057ad..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/conv2d_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CONV2D_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CONV2D_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class Conv2DFusionChecker : public OpChecker { - public: - Conv2DFusionChecker() : OpChecker("Conv2DFusion") {} - ~Conv2DFusionChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CONV2D_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.cc deleted file mode 100644 index cc025c9e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.cc +++ /dev/null @@ -1,37 +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 "checker/custom_op_checker.h" -#include -#include - -namespace mindspore { -namespace dpico { -bool CustomOpChecker::Check(api::CNodePtr, int32_t output_num, mindspore::Format) { return true; } -OpCheckerRegistrar g_DecBboxChecker("DecBBox", new CustomOpChecker()); -OpCheckerRegistrar g_DetectionOutputChecker("DetectionOutput", new CustomOpChecker()); -OpCheckerRegistrar g_ExtractChecker("Extract", new CustomOpChecker()); -OpCheckerRegistrar g_PassThroughChecker("PassThrough", new CustomOpChecker()); -OpCheckerRegistrar g_PSROIPoolingChecker("PsRoiPool", new CustomOpChecker()); -OpCheckerRegistrar g_ROIPoolingChecker("ROIPooling", new CustomOpChecker()); -OpCheckerRegistrar g_ShuffleChannelChecker("ShuffleChannel", new CustomOpChecker()); -OpCheckerRegistrar g_ThresholdChecker("Threshold", new CustomOpChecker()); -OpCheckerRegistrar g_RNNChecker("Rnn", new CustomOpChecker()); -OpCheckerRegistrar g_BiLstmChecker("BiLstm", new CustomOpChecker()); -OpCheckerRegistrar g_GruChecker("Gru", new CustomOpChecker()); -OpCheckerRegistrar g_NopChecker("Nop", new CustomOpChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.h deleted file mode 100644 index d2609c1e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/custom_op_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CUSTOM_OP_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CUSTOM_OP_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class CustomOpChecker : public OpChecker { - public: - CustomOpChecker() : OpChecker("CustomOp") {} - ~CustomOpChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_CUSTOM_OP_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.cc deleted file mode 100644 index 86f6d239..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.cc +++ /dev/null @@ -1,61 +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 "checker/eltwise_checker.h" -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kModeSize = 3; -} // namespace -bool EltwiseChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto mode_ptr = primitive->GetAttr(ops::kMode); - if (mode_ptr != nullptr) { - auto mode_data = api::GetValue(mode_ptr); - if (mode_data >= kModeSize) { // only prod(0), sum(1), max(2) is supported - MS_LOG(WARNING) << "mode only supports 0/1/2 " << op->fullname_with_scope(); - return false; - } - } - - if (op->size() - 1 > kMaxBottomNum) { - MS_LOG(WARNING) << "op inputs size:" << op->size() << " is greater than max_bottom num:" << kMaxBottomNum << " " - << op->fullname_with_scope(); - return false; - } - - std::vector input_shape; - for (size_t i = 1; i < op->size(); i++) { - if (!CheckInputW(op, i, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - input_shape.clear(); - } - return true; -} - -OpCheckerRegistrar g_EltwiseChecker("Eltwise", new EltwiseChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.h deleted file mode 100644 index c59ccbbe..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/eltwise_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ELTWISE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ELTWISE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class EltwiseChecker : public OpChecker { - public: - EltwiseChecker() : OpChecker("Eltwise") {} - ~EltwiseChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_ELTWISE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.cc deleted file mode 100644 index b925894a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.cc +++ /dev/null @@ -1,49 +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 "checker/exp_checker.h" -#include -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool ExpFusionChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, kInputIndex1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto base_ptr = primitive->GetAttr(ops::kBase); - if (base_ptr != nullptr) { - auto base_data = api::GetValue(base_ptr); - if (base_data < 0 && std::fabs(base_data + 1.0) > std::numeric_limits::epsilon()) { - MS_LOG(WARNING) << "base val only supports -1 or positive num. " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_ExpFusionChecker("ExpFusion", new ExpFusionChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.h deleted file mode 100644 index 101730e3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/exp_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_EXP_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_EXP_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ExpFusionChecker : public OpChecker { - public: - ExpFusionChecker() : OpChecker("ExpFusion") {} - ~ExpFusionChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_EXP_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.cc deleted file mode 100644 index 5471ccf6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.cc +++ /dev/null @@ -1,57 +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 "checker/flatten_checker.h" -#include -#include -#include "common/op_attr.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kMaxFlattenInputW = 65536; -} // namespace -bool FlattenChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr." << op->fullname_with_scope(); - return false; - } - if (primitive->GetAttr(kStartAxis) != nullptr) { - auto axis = api::GetValue(primitive->GetAttr(kStartAxis)); - if (axis < kAxisLowerBound || axis > kAxisUpperBound) { - MS_LOG(WARNING) << "start_axis val should in range [-4, 3] " << op->fullname_with_scope(); - return false; - } - } - if (primitive->GetAttr(kEndAxis) != nullptr) { - auto end_axis = api::GetValue(primitive->GetAttr(kEndAxis)); - if (end_axis < kAxisLowerBound || end_axis > kAxisUpperBound) { - MS_LOG(WARNING) << "end_axis val should in range [-4, 3] " << op->fullname_with_scope(); - return false; - } - } - - if (!CheckInputW(op, 1, format, kMaxFlattenInputW)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - return true; -} -OpCheckerRegistrar g_FlattenChecker("Flatten", new FlattenChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.h deleted file mode 100644 index f2135467..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/flatten_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_FLATTEN_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_FLATTEN_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class FlattenChecker : public OpChecker { - public: - FlattenChecker() : OpChecker("Flatten") {} - ~FlattenChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_FLATTEN_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.cc deleted file mode 100644 index 9fdadf28..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.cc +++ /dev/null @@ -1,65 +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 "checker/full_connection_checker.h" -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool FullConnectionChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - - if (op->size() < kInputIndex3) { - MS_LOG(ERROR) << "FullConnection should have 2 inputs at least, but is " << (op->size() - 1); - return false; - } - std::vector weight_shape; - if (GetInputShapeFromCNode(op, kInputIndex2, &weight_shape) != RET_OK) { - MS_LOG(ERROR) << "get weight shape failed"; - return false; - } - if (weight_shape.empty()) { - MS_LOG(ERROR) << "weight shape is empty."; - return false; - } - - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - if (primitive->GetAttr(kNumOutput) != nullptr) { - auto num_output = api::GetValue(primitive->GetAttr(kNumOutput)); - if (num_output > kMaxNumOutput) { - MS_LOG(WARNING) << "num_output val:" << num_output << " should be less than " << kMaxNumOutput << " " - << op->fullname_with_scope(); - return false; - } - } - - return true; -} - -OpCheckerRegistrar g_FullConnectionChecker("FullConnection", new FullConnectionChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.h deleted file mode 100644 index 23394162..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/full_connection_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_FULL_CONNECTION_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_FULL_CONNECTION_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class FullConnectionChecker : public OpChecker { - public: - FullConnectionChecker() : OpChecker("FullConnection") {} - ~FullConnectionChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_FULL_CONNECTION_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.cc deleted file mode 100644 index 09eb4ba0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.cc +++ /dev/null @@ -1,51 +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 "checker/log_checker.h" -#include -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool LogChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, kInputIndex1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto base_ptr = primitive->GetAttr(ops::kBase); - if (base_ptr != nullptr) { - auto base_data = api::GetValue(base_ptr); // support -1.0 && any positive num but 1.0 - if (std::fabs(base_data + 1.0) <= std::numeric_limits::epsilon() || - (base_data > 0 && std::fabs(base_data - 1.0) > std::numeric_limits::epsilon())) { - return true; - } else { - MS_LOG(WARNING) << "base val only supports -1.0 or any positive num but 1.0 " << op->fullname_with_scope(); - return false; - } - } - return true; -} -OpCheckerRegistrar g_LogChecker("Log", new LogChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.h deleted file mode 100644 index 3d591e30..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/log_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LOG_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LOG_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class LogChecker : public OpChecker { - public: - LogChecker() : OpChecker("Log") {} - ~LogChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LOG_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.cc deleted file mode 100644 index 2e139c2e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.cc +++ /dev/null @@ -1,61 +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 "checker/lrn_checker.h" -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int local_size_3 = 3; -constexpr int local_size_5 = 5; -constexpr int local_size_7 = 7; -} // namespace -bool LRNChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto r_ptr = primitive->GetAttr(ops::kDepthRadius); - if (r_ptr != nullptr) { - auto r_data = api::GetValue(r_ptr) * 2 + 1; - if (r_data != local_size_3 && r_data != local_size_5 && r_data != local_size_7) { - MS_LOG(WARNING) << "local size only supports 3/5/7 " << op->fullname_with_scope(); - return false; - } - } - auto norm_region_ptr = primitive->GetAttr(ops::kNormRegion); - if (norm_region_ptr != nullptr) { - auto norm_region_data = api::GetValue(norm_region_ptr); - if (norm_region_data != "ACROSS_CHANNEL") { - MS_LOG(WARNING) << "norm region only supports ACROSS_CHANNEL " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_LRNChecker("LRN", new LRNChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.h deleted file mode 100644 index 7ff17df6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/lrn_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LRN_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LRN_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class LRNChecker : public OpChecker { - public: - LRNChecker() : OpChecker("LRN") {} - ~LRNChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LRN_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.cc deleted file mode 100644 index 3ee423ab..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.cc +++ /dev/null @@ -1,46 +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 "checker/lstm_checker.h" -#include -#include "common/op_attr.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr uint32_t kLstmMaxNumOutput = 5456; -} // namespace - -bool LstmChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto num_outputs_ptr = primitive->GetAttr(dpico::kNumOutput); - if (num_outputs_ptr != nullptr) { - auto num_outputs_data = static_cast(api::GetValue(num_outputs_ptr)); - if (num_outputs_data > kLstmMaxNumOutput) { - MS_LOG(WARNING) << "num_output should less than " << kLstmMaxNumOutput; - return false; - } - } - return true; -} - -OpCheckerRegistrar g_LstmChecker("Lstm", new LstmChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.h deleted file mode 100644 index 7a59deb3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/lstm_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LSTM_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LSTM_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class LstmChecker : public OpChecker { - public: - LstmChecker() : OpChecker("Lstm") {} - ~LstmChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_LSTM_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.cc deleted file mode 100644 index 569326f7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.cc +++ /dev/null @@ -1,113 +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 "checker/mat_mul_checker.h" -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -bool CheckInputShapeForMatrix(const api::CNodePtr &cnode, const api::PrimitivePtr &primitive) { - ShapeVector input_1_shape; - ShapeVector input_2_shape; - if (GetInputShapeFromCNode(cnode, kInputIndex1, &input_1_shape) != RET_OK || - GetInputShapeFromCNode(cnode, kInputIndex2, &input_2_shape) != RET_OK) { - MS_LOG(ERROR) << "get input shape failed. " << cnode->fullname_with_scope(); - return false; - } - if (!input_1_shape.empty() && !input_2_shape.empty()) { - if (input_1_shape.size() != input_2_shape.size()) { - return false; - } - if (input_1_shape.size() > kDims2) { - for (size_t i = 0; i < input_1_shape.size() - kInputIndex2; i++) { - if (input_1_shape.at(i) != 1 || input_2_shape.at(i) != 1) { - return false; - } - } - } - (void)primitive->AddAttr(kDim1, api::MakeValue(input_1_shape.at(input_1_shape.size() - kInputIndex2))); - (void)primitive->AddAttr(kDim2, api::MakeValue(input_1_shape.at(input_1_shape.size() - 1))); - (void)primitive->AddAttr(kDim3, api::MakeValue(input_2_shape.at(input_2_shape.size() - kInputIndex2))); - } - return true; -} -bool CheckInputShapeForFc(const api::CNodePtr &cnode) { - ShapeVector input_shape; - if (GetInputShapeFromCNode(cnode, kInputIndex1, &input_shape) == RET_OK) { - return input_shape.size() == dpico::kDims2 && input_shape.at(0) == 1; - } - return false; -} -} // namespace -bool MatMulChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr." << op->fullname_with_scope(); - return false; - } - if (primitive->GetAttr(ops::kTransposeA) != nullptr) { - auto transpose_a = api::GetValue(primitive->GetAttr(ops::kTransposeA)); - if (transpose_a) { - return false; - } - } - if (op->size() < kInputIndex3) { - MS_LOG(ERROR) << "Matmul should have 2 inputs at least, but is " << (op->size() - 1); - return false; - } - bool transpose_b = false; - if (primitive->GetAttr(ops::kTransposeB) != nullptr) { - transpose_b = api::GetValue(primitive->GetAttr(ops::kTransposeB)); - } else { - (void)primitive->AddAttr(ops::kTransposeB, api::MakeValue(false)); - } - if (!HasOfflineData(op->input(kInputIndex1))) { - if (!HasOfflineData(op->input(kInputIndex2))) { - if (transpose_b) { - if (!CheckInputShapeForMatrix(op, primitive)) { - return false; - } - (void)primitive->AddAttr(kOperatorType, api::MakeValue("Matrix")); - return true; - } else { - return false; - } - } else { - if (CheckInputShapeForFc(op)) { - (void)primitive->AddAttr(kOperatorType, api::MakeValue("FullConnection")); - return true; - } else { - MS_LOG(WARNING) << "only supports input N = 1 by dpico. " << op->fullname_with_scope(); - return false; - } - } - } - return false; -} - -OpCheckerRegistrar g_GemmChecker("Gemm", new MatMulChecker()); -OpCheckerRegistrar g_MatMulChecker("MatMulFusion", new MatMulChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.h deleted file mode 100644 index 1d807795..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/mat_mul_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_MAT_MUL_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_MAT_MUL_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class MatMulChecker : public OpChecker { - public: - MatMulChecker() : OpChecker("MatMul") {} - ~MatMulChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_MAT_MUL_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.cc deleted file mode 100644 index 37438101..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.cc +++ /dev/null @@ -1,50 +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 "checker/mvn_checker.h" -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "common/fetch_content.h" - -namespace mindspore { -namespace dpico { -bool MvnChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, kInputIndex1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - - if (primitive->GetAttr(ops::kAxes) != nullptr) { - auto axes = api::GetValue>(primitive->GetAttr(ops::kAxes)); - if (axes != std::vector{0, kAxis2, kAxis3} && axes != std::vector{0, 1, kAxis2, kAxis3}) { - MS_LOG(WARNING) << "axes only supports [0,2,3] or [0,1,2,3] " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_MvnChecker("Mvn", new MvnChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.h deleted file mode 100644 index f2d0cb8a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/mvn_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_MVN_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_MVN_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class MvnChecker : public OpChecker { - public: - MvnChecker() : OpChecker("Mvn") {} - ~MvnChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_MVN_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.cc deleted file mode 100644 index ce337f32..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.cc +++ /dev/null @@ -1,133 +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 -#include -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -OpCheckerRegistry::~OpCheckerRegistry() { - for (auto ite : checkers) { - if (ite.second != nullptr) { - delete ite.second; - ite.second = nullptr; - } - } -} - -OpCheckerRegistry *OpCheckerRegistry::GetInstance() { - static OpCheckerRegistry instance; - return &instance; -} - -OpChecker *OpCheckerRegistry::GetOpChecker(const std::string &type) { - auto it = checkers.find(type); - if (it != checkers.end()) { - return it->second; - } - return nullptr; -} - -STATUS GetWidth(const std::vector &shape, mindspore::Format format, int64_t *width) { - if (width == nullptr) { - MS_LOG(ERROR) << "width is nullptr."; - return RET_ERROR; - } - if (shape.size() == kDims4) { - if (format == mindspore::Format::NCHW) { - *width = shape.at(kInputIndex3); - } else if (format == mindspore::Format::NHWC) { - *width = shape.at(kInputIndex2); - } else { - MS_LOG(ERROR) << "format should be NCHW or NHWC"; - return RET_ERROR; - } - } else { - *width = shape.back(); - } - return RET_OK; -} - -STATUS GetTensorChannel(const std::vector &shape, mindspore::Format format, int64_t *channel) { - if (channel == nullptr) { - MS_LOG(ERROR) << "channel is nullptr."; - return RET_ERROR; - } - if (shape.size() != kDims4) { - MS_LOG(ERROR) << "shape size should be 4, but is " << shape.size(); - return RET_ERROR; - } else { - if (format == mindspore::Format::NCHW) { - *channel = shape.at(kInputIndex1); - } else if (format == mindspore::Format::NHWC) { - *channel = shape.at(kInputIndex3); - } else { - MS_LOG(ERROR) << "format should be NCHW or NHWC"; - return RET_ERROR; - } - } - return RET_OK; -} - -STATUS GetVectorChannel(const std::vector &shape, int64_t *channel) { - if (channel == nullptr) { - MS_LOG(ERROR) << "channel is nullptr."; - return RET_ERROR; - } - if (shape.size() != kDims2) { - MS_LOG(ERROR) << "shape size should be 2, but is " << shape.size(); - return RET_ERROR; - } - *channel = shape.back(); - return RET_OK; -} - -bool HasOfflineData(const api::AnfNodePtr &node) { - if (node == nullptr) { - MS_LOG(ERROR) << "node is nullptr."; - return false; - } - auto param = node->cast(); - - return param != nullptr && param->has_default(); -} - -bool CheckInputW(const api::CNodePtr &op, size_t index, mindspore::Format format, int limit_w) { - if (index >= op->size()) { - MS_LOG(ERROR) << "index:" << index << " is greater than " << op->fullname_with_scope() - << " inputs size:" << op->size(); - return false; - } - std::vector input_shape; - if (GetInputShapeFromCNode(op, index, &input_shape) == RET_OK && !input_shape.empty()) { - int64_t input_w; - if (GetWidth(input_shape, format, &input_w) != RET_OK) { - MS_LOG(ERROR) << "get input_w failed " << op->fullname_with_scope(); - return false; - } - if (input_shape.size() == kDims4 && input_w > limit_w) { - MS_LOG(INFO) << op->fullname_with_scope() << "'s input_w:" << input_w << " exceed the maximum limit " << limit_w; - return false; - } - } - return true; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.h deleted file mode 100644 index 56815a0d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/op_checker.h +++ /dev/null @@ -1,75 +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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_OP_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_OP_CHECKER_H_ - -#include -#include -#include -#include -#include -#include -#include "mindapi/base/format.h" -#include "include/errorcode.h" -#include "mindapi/ir/anf.h" -#include "mindapi/base/logging.h" -#include "mindspore/ops/op_def/op_name.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::lite::STATUS; -namespace mindspore { -namespace dpico { -class OpChecker { - public: - explicit OpChecker(std::string node_name) : name(std::move(node_name)) {} - virtual ~OpChecker() = default; - virtual bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) = 0; - - protected: - const std::string name; -}; - -STATUS GetWidth(const std::vector &shape, mindspore::Format format, int64_t *width); -STATUS GetTensorChannel(const std::vector &shape, mindspore::Format format, int64_t *channel); -STATUS GetVectorChannel(const std::vector &shape, int64_t *channel); -bool HasOfflineData(const api::AnfNodePtr &node); -bool CheckInputW(const api::CNodePtr &op, size_t index, mindspore::Format format, int limit_w); - -class OpCheckerRegistry { - public: - OpCheckerRegistry() = default; - ~OpCheckerRegistry(); - - static OpCheckerRegistry *GetInstance(); - - OpChecker *GetOpChecker(const std::string &type); - - std::unordered_map checkers; -}; - -class OpCheckerRegistrar { - public: - OpCheckerRegistrar(const std::string &type, OpChecker *parser) { - OpCheckerRegistry::GetInstance()->checkers[type] = parser; - } - ~OpCheckerRegistrar() = default; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_OP_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.cc deleted file mode 100644 index 1b9a5f18..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.cc +++ /dev/null @@ -1,138 +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 "checker/pooling_checker.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kMaxGroupNum = 2048; -constexpr int kMaxPoolUpperBound = 2048; -constexpr int kMaxPadSize = 7; -constexpr int kMaxKernelSize = 255; -constexpr int kMaxStrideSize = 255; -constexpr int kMaxDilationSize = 5; -constexpr int kMaxDilationAndKernelProd = 15; -constexpr float kCoefficient = 16.0; - -bool CheckPad(const api::PrimitivePtr &primitive) { - auto pad_ptr = primitive->GetAttr(ops::kPad); - if (pad_ptr != nullptr) { - auto pad_data = api::GetValue>(pad_ptr); - if (pad_data.size() > kDims3) { - if (pad_data[0] < 0 || pad_data[0] > kMaxPadSize || pad_data[1] < 0 || pad_data[1] > kMaxPadSize || - pad_data[kAxis2] < 0 || pad_data[kAxis2] > kMaxPadSize || pad_data[kAxis3] < 0 || - pad_data[kAxis3] > kMaxPadSize) { - MS_LOG(WARNING) << "pad should in range [1,7]"; - return false; - } - } - } - return true; -} -bool CheckKernelSize(const api::PrimitivePtr &primitive) { - auto is_global_ptr = primitive->GetAttr(ops::kGlobal); - auto kernel_ptr = primitive->GetAttr(ops::kKernelSize); - if (kernel_ptr != nullptr) { - auto kernel_data = api::GetValue>(kernel_ptr); - if (is_global_ptr != nullptr) { - auto is_global = api::GetValue(is_global_ptr); - if (!is_global && (kernel_data[0] < 1 || kernel_data[0] > kMaxKernelSize || kernel_data[1] < 1 || - kernel_data[1] > kMaxKernelSize)) { - MS_LOG(WARNING) << "kernel should in range [1,255]"; - return false; - } - } - } - return true; -} -bool CheckStride(const api::PrimitivePtr &primitive) { - auto stride_ptr = primitive->GetAttr(ops::kStrides); - if (stride_ptr != nullptr) { - auto stride_data = api::GetValue>(stride_ptr); - if (stride_data[0] < 1 || stride_data[0] > kMaxStrideSize || stride_data[1] < 1 || - stride_data[1] > kMaxStrideSize) { - MS_LOG(WARNING) << "stride should in range [1,255]"; - return false; - } - } - return true; -} -bool CheckRoundMode(const api::PrimitivePtr &primitive) { - auto round_mode_ptr = primitive->GetAttr(ops::kRoundMode); - if (round_mode_ptr != nullptr) { - auto round_mode_data = api::GetValue(round_mode_ptr); - if (round_mode_data != 0 && round_mode_data != 1) { - MS_LOG(WARNING) << "round mode only supports CEIL or FLOOR"; - return false; - } - } - return true; -} -bool CheckAttr(const api::PrimitivePtr &primitive, int64_t input_w) { - auto kernel_ptr = primitive->GetAttr(ops::kKernelSize); - auto stride_ptr = primitive->GetAttr(ops::kStride); - if (stride_ptr != nullptr && kernel_ptr != nullptr) { - auto kernel_data = api::GetValue>(kernel_ptr); - auto stride_data = api::GetValue>(stride_ptr); - if (kernel_data[0] > kMaxPoolUpperBound / (input_w / (kCoefficient * stride_data[1]) * stride_data[1])) { - MS_LOG(WARNING) << "kernel and stride should satisfy kernel_h <= 2048 / (w / (16 * stride) * stride) "; - return false; - } - } - return true; -} -} // namespace - -bool PoolingChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - std::vector input_shape; - if (GetInputShapeFromCNode(op, kInputIndex1, &input_shape) == RET_OK) { - if (input_shape.size() != kDims4) { - MS_LOG(ERROR) << "Error Pooling input, which should be 4 dims."; - return false; - } - int64_t input_w; - if (GetWidth(input_shape, format, &input_w) != RET_OK) { - MS_LOG(ERROR) << "get input_w failed"; - return false; - } - if (input_w > kMaxInputWOf4Dims) { - MS_LOG(WARNING) << "input_w " << input_w << " is greater than " << kMaxInputWOf4Dims << " " - << op->fullname_with_scope(); - return false; - } - if (!CheckAttr(primitive, input_w)) { - return false; - } - } - - return CheckPad(primitive) && CheckRoundMode(primitive) && CheckKernelSize(primitive) && CheckStride(primitive); -} - -OpCheckerRegistrar g_AvgPoolFusionChecker("AvgPoolFusion", new PoolingChecker()); -OpCheckerRegistrar g_MaxPoolFusionChecker("MaxPoolFusion", new PoolingChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.h deleted file mode 100644 index a28a9c5e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/pooling_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_POOLING_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_POOLING_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class PoolingChecker : public OpChecker { - public: - PoolingChecker() : OpChecker("Pooling") {} - ~PoolingChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_POOLING_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.cc deleted file mode 100644 index 2e713335..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.cc +++ /dev/null @@ -1,66 +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 "checker/pow_checker.h" -#include -#include -#include -#include "common/fetch_content.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool PowFusionChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, kInputIndex1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - float power; - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - DataInfo data_info; - if (op->size() > kInputIndex2 && FetchDataFromParameterNode(op, kInputIndex2, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeFloat32)) { - MS_LOG(ERROR) << "data_type not correct"; - return false; - } - if (data_info.data_.data() == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << op->fullname_with_scope(); - return false; - } - power = *(reinterpret_cast(data_info.data_.data())); - } else if (primitive->GetAttr(ops::kPower) != nullptr) { - power = api::GetValue(primitive->GetAttr(ops::kPower)); - } else { - MS_LOG(ERROR) << "null param"; - return false; - } - if (!(std::fmod(std::fabs(power), 1.0) > - std::numeric_limits::epsilon() && // support power: -0.5, 0.5, integers - std::fabs(std::fabs(power) - 0.5) > std::numeric_limits::epsilon())) { - return true; - } else { - MS_LOG(WARNING) << "power val only supports -0.5, 0.5, integers " << op->fullname_with_scope(); - return false; - } -} - -OpCheckerRegistrar g_PowFusionChecker("PowFusion", new PowFusionChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.h deleted file mode 100644 index 1fa9cac3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/pow_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_POW_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_POW_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class PowFusionChecker : public OpChecker { - public: - PowFusionChecker() : OpChecker("PowFusion") {} - ~PowFusionChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_POW_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.cc deleted file mode 100644 index a68a7da1..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.cc +++ /dev/null @@ -1,133 +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 "checker/reduce_checker.h" -#include -#include -#include -#include "mindapi/base/types.h" -#include "include/registry/converter_context.h" -#include "common/fetch_content.h" -#include "common/anf_util.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS GetAxesSet(const api::CNodePtr &op, const ShapeVector &input_shape, const api::PrimitivePtr &primitive, - std::set *axes_set) { - if (axes_set == nullptr) { - MS_LOG(ERROR) << "axes_set is nullptr. " << op->fullname_with_scope(); - return RET_ERROR; - } - DataInfo data_info; - if (op->size() > kInputIndex2 && FetchDataFromParameterNode(op, kInputIndex2, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeInt32)) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info.data_.data()); - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << op->fullname_with_scope(); - return RET_ERROR; - } - int data_size; - if (GetDataSizeFromTensor(&data_info, &data_size) != RET_OK) { - MS_LOG(ERROR) << "get data size from tensor failed."; - return RET_ERROR; - } - (void)std::transform( - data, data + data_size, std::inserter(*axes_set, axes_set->begin()), - [input_shape](int32_t value) { return (value + static_cast(input_shape.size())) % input_shape.size(); }); - } else if (primitive->GetAttr(ops::kAxes) != nullptr) { - auto axes = api::GetValue>(primitive->GetAttr(ops::kAxes)); - (void)std::transform( - axes.begin(), axes.end(), std::inserter(*axes_set, axes_set->begin()), - [input_shape](int64_t value) { return (value + static_cast(input_shape.size())) % input_shape.size(); }); - } - return RET_OK; -} - -bool CheckAttr(const api::CNodePtr &op, mindspore::Format format, const api::PrimitivePtr &primitive, - const ShapeVector &input_shape) { - bool keep_dims = true; - if (primitive->GetAttr(ops::kKeepDims) != nullptr) { - keep_dims = api::GetValue(primitive->GetAttr(ops::kKeepDims)); - } - std::set axes_set; - if (GetAxesSet(op, input_shape, primitive, &axes_set) != RET_OK) { - MS_LOG(ERROR) << "get axes set failed. " << op->fullname_with_scope(); - return false; - } - // special process when cnode is from caffe - if (primitive->GetAttr(ops::kFmkType) != nullptr) { - auto fmk_type = static_cast(api::GetValue(primitive->GetAttr(ops::kFmkType))); - if (fmk_type == converter::kFmkTypeCaffe) { - return true; - } - } - - if (format == Format::NCHW && !input_shape.empty() && input_shape.at(0) == 1) { - return (axes_set == std::set{kAxis3} && keep_dims) || - (axes_set == std::set{kAxis2, kAxis3} && !keep_dims); - } else if (input_shape.size() == kDims3 && axes_set == std::set{kAxis2}) { - return ((!keep_dims && input_shape.at(0) == 1) || keep_dims); - } - return false; -} -} // namespace -bool ReduceChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto mode_ptr = primitive->GetAttr(ops::kMode); - if (mode_ptr != nullptr) { - auto reduce_mode = static_cast(api::GetValue(mode_ptr)); - if (reduce_mode < ReduceMode::Reduce_Mean || reduce_mode >= ReduceMode::Reduce_All) { - MS_LOG(WARNING) << "unsupported reduce mode " << reduce_mode << " " << op->fullname_with_scope(); - return false; - } - } - - std::vector input_shape; - if (GetInputShapeFromCNode(op, kInputIndex1, &input_shape) == RET_OK && !input_shape.empty()) { - int64_t input_w; - if (GetWidth(input_shape, format, &input_w) != RET_OK) { - MS_LOG(ERROR) << "get input_w failed " << op->fullname_with_scope(); - return false; - } - if (input_shape.size() <= kDims2) { - MS_LOG(WARNING) << "reduce op input_shape size need to be greater than 2"; - return false; - } - if (input_shape.size() == kDims4 && input_w > kMaxInputWOf4Dims) { - MS_LOG(WARNING) << op->fullname_with_scope() << "'s input_w:" << input_w << " exceed the maximum limit " - << kMaxInputWOf4Dims; - return false; - } - if (!CheckAttr(op, format, primitive, input_shape)) { - MS_LOG(WARNING) << "axes_set or keep_dims val is unsupported by dpico. " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_ReduceChecker("ReduceFusion", new ReduceChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.h deleted file mode 100644 index ae001b34..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/reduce_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_REDUCE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_REDUCE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ReduceChecker : public OpChecker { - public: - ReduceChecker() : OpChecker("Reduce") {} - ~ReduceChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_REDUCE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.cc deleted file mode 100644 index 55d95d05..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.cc +++ /dev/null @@ -1,98 +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 "checker/reshape_checker.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "common/fetch_content.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kMaxReshapeInputW = 65536; -} // namespace -bool ReshapeChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - std::vector input_shape; - if (GetInputShapeFromCNode(op, kInputIndex1, &input_shape) == RET_OK && !input_shape.empty()) { - int64_t input_w; - if (GetWidth(input_shape, format, &input_w) != RET_OK) { - MS_LOG(ERROR) << "get input_w failed"; - return false; - } - - if (input_shape.size() == kDims4 && input_w > kMaxReshapeInputW) { - return false; - } - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - - if (op->size() < kInputIndex3) { - MS_LOG(ERROR) << "There should be at least 2 inputs, but is " << (op->size() - 1); - return false; - } - - DataInfo data_info; - std::vector shape_data; - auto shape_ptr = primitive->GetAttr(ops::kShape); - if (op->size() > kInputIndex2 && FetchDataFromParameterNode(op, kInputIndex2, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeInt32)) { - MS_LOG(ERROR) << "data_type not correct"; - return false; - } - auto data = reinterpret_cast(data_info.data_.data()); - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << op->fullname_with_scope(); - return false; - } - int data_size; - if (GetDataSizeFromTensor(&data_info, &data_size) != RET_OK) { - MS_LOG(ERROR) << "get data size from tensor failed."; - return false; - } - (void)std::transform(data, data + data_size, std::back_inserter(shape_data), - [](const int32_t &value) { return static_cast(value); }); - } else if (shape_ptr != nullptr) { - shape_data = api::GetValue>(shape_ptr); - } else { - MS_LOG(ERROR) << "can't get shape value. " << op->fullname_with_scope(); - return false; - } - (void)primitive->AddAttr(ops::kShape, api::MakeValue(shape_data)); - - auto param_ptr = op->input(kInputIndex2)->cast(); - if (param_ptr == nullptr) { - MS_LOG(ERROR) << "param_ptr is nullptr. " << op->fullname_with_scope(); - return false; - } - auto param_value = param_ptr->default_param()->cast(); - if (param_value == nullptr) { - MS_LOG(ERROR) << "param_value is nullptr." << op->fullname_with_scope(); - return false; - } - return !(static_cast(param_value->DataSize()) < kDims1 || - static_cast(param_value->DataSize()) > kDims4); -} - -OpCheckerRegistrar g_ReshapeChecker("Reshape", new ReshapeChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.h deleted file mode 100644 index 38e3a1c2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/reshape_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_RESHAPE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_RESHAPE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ReshapeChecker : public OpChecker { - public: - ReshapeChecker() : OpChecker("Reshape") {} - ~ReshapeChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_RESHAPE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.cc deleted file mode 100644 index 53dab666..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.cc +++ /dev/null @@ -1,178 +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 "checker/resize_checker.h" -#include -#include -#include "common/op_attr.h" -#include "common/check_base.h" -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "mindapi/base/types.h" -#include "include/registry/converter_context.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kMaxOutputWOf4Dims = 2048; -bool IsFromCaffe(const api::PrimitivePtr &primitive) { - if (primitive->GetAttr(ops::kFmkType) != nullptr) { - auto fmk_type = static_cast(api::GetValue(primitive->GetAttr(ops::kFmkType))); - if (fmk_type == converter::kFmkTypeCaffe) { - return true; - } - } - return false; -} -bool CheckInterpOp(const api::CNodePtr &op, const ShapeVector &input_shape, const ShapeVector &output_shape, - size_t index_h, size_t index_w) { - auto prim = api::GetValueNode(op->input(0)); - MS_CHECK_TRUE_MSG(prim != nullptr, false, "prim is nullptr."); - if (input_shape.at(index_w) > kMaxInputWOf4Dims || output_shape.at(index_w) >= kMaxOutputWOf4Dims) { - MS_LOG(WARNING) << op->fullname_with_scope() << "'s input_w should be less than " << kMaxInputWOf4Dims - << " and output_w should be less than " << kMaxOutputWOf4Dims; - return false; - } - int64_t pad_beg = 0; - int64_t pad_end = 0; - if (prim->GetAttr(dpico::kPadBeg) != nullptr) { - pad_beg = static_cast(api::GetValue(prim->GetAttr(dpico::kPadBeg))); - } - if (prim->GetAttr(dpico::kPadEnd) != nullptr) { - pad_end = api::GetValue(prim->GetAttr(dpico::kPadEnd)); - } - if (pad_beg > 0 || pad_end > 0) { - MS_LOG(WARNING) << "pad_beg or pad_end only supports non-negative integer by dpico. " << op->fullname_with_scope(); - return false; - } - int64_t valid_input_h = input_shape.at(index_h) + pad_beg + pad_end; - int64_t valid_input_w = input_shape.at(index_w) + pad_beg + pad_end; - int64_t output_h = output_shape.at(index_h); - int64_t output_w = output_shape.at(index_w); - if (output_h == 0) { - MS_LOG(WARNING) << "output_h should not be 0"; - return false; - } - if (output_w == 0) { - MS_LOG(WARNING) << "output_w should not be 0"; - return false; - } - auto ratio_h = valid_input_h / output_h; - auto ratio_w = valid_input_w / output_w; - return ((ratio_h == 1) && (ratio_w == 1)) || ((ratio_h != 1) && (ratio_w != 1)); -} -bool IsDoubleResize(const api::CNodePtr &, const ShapeVector &input_shape, const ShapeVector &output_shape, - size_t index_h, size_t index_w) { - const int64_t nums2 = 2; - return input_shape.at(index_h) * nums2 == output_shape.at(index_h) && - input_shape.at(index_w) * nums2 == output_shape.at(index_w); -} -bool CheckResizeOp(const api::CNodePtr &op, const ShapeVector &input_shape, const ShapeVector &output_shape, - size_t index_h, size_t index_w) { - auto prim = api::GetValueNode(op->input(0)); - MS_CHECK_TRUE_MSG(prim != nullptr, false, "prim is nullptr."); - if (prim->GetAttr(ops::kCoordinateTransformMode) != nullptr) { - auto coordinate_transform_mode = - static_cast(api::GetValue(prim->GetAttr(ops::kCoordinateTransformMode))); - if (coordinate_transform_mode != CoordinateTransformMode::ASYMMETRIC) { - MS_LOG(WARNING) << "resize only supports CoordinateTransformMode::ASYMMETRIC by dpico. " - << op->fullname_with_scope(); - return false; - } - } - if (prim->GetAttr(ops::kMethod) != nullptr) { - auto interpolation_mode = static_cast(api::GetValue(prim->GetAttr(ops::kMethod))); - if (interpolation_mode != ResizeMethod::NEAREST) { - MS_LOG(WARNING) << "resize only supports ResizeMethod::NEAREST by dpico. " << op->fullname_with_scope(); - return false; - } - } - if (prim->GetAttr(ops::kNearestMode) != nullptr) { - auto nearest_mode = static_cast(api::GetValue(prim->GetAttr(ops::kNearestMode))); - if (nearest_mode != mindspore::NearestMode::FLOOR) { - MS_LOG(WARNING) << "resize only supports NearestMode::FLOOR by dpico. " << op->fullname_with_scope(); - return false; - } - } else { - MS_LOG(WARNING) << ops::kNearestMode << " attr is needed. " << op->fullname_with_scope(); - return false; - } - if (!IsDoubleResize(op, input_shape, output_shape, index_h, index_w)) { - MS_LOG(WARNING) << "resize only supports doubling expansion of [h,w] by dpico. " << op->fullname_with_scope(); - return false; - } - return true; -} -} // namespace -bool ResizeChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format) { - auto primitive = api::GetValueNode(op->input(0)); - MS_CHECK_TRUE_MSG(primitive != nullptr, false, "prim is nullptr."); - ShapeVector input_shape; - auto abstract = GetCNodeInputAbstract(op, 1); - if (abstract == nullptr) { - MS_LOG(ERROR) << "get cnode input abstract failed."; - return false; - } - if (FetchShapeFromAbstract(abstract, &input_shape) != RET_OK) { - MS_LOG(ERROR) << "fetch input shape failed. " << op->fullname_with_scope(); - return false; - } - if (input_shape.size() != kDims4) { - MS_LOG(ERROR) << "resize cnode input shape should be 4 dims. " << op->fullname_with_scope(); - return false; - } - - std::vector output_shapes; - if (GetOutputShapesFromCNode(op, &output_shapes) != RET_OK) { - MS_LOG(ERROR) << "get node shape failed"; - return false; - } - if (output_shapes.size() != 1) { - MS_LOG(ERROR) << "resize should have single output, but in fact it has " << output_shapes.size() << " outputs."; - return false; - } - auto output_shape = output_shapes.at(0); - - Format input_format; - if (primitive->GetAttr(ops::kFormat) != nullptr) { - input_format = static_cast(api::GetValue(primitive->GetAttr(ops::kFormat))); - } else { - MS_LOG(ERROR) << ops::kFormat << " attr is needed."; - return false; - } - size_t index_h; - size_t index_w; - if (input_format == Format::NHWC) { - index_h = 1; - index_w = kAxis2; - } else if (input_format == Format::NCHW) { - index_h = kAxis2; - index_w = kAxis3; - } else { - MS_LOG(ERROR) << "resize cnode input format is invalid. " << op->fullname_with_scope(); - return false; - } - - if (IsFromCaffe(primitive)) { - return CheckInterpOp(op, input_shape, output_shape, index_h, index_w); - } else { - return CheckResizeOp(op, input_shape, output_shape, index_h, index_w); - } -} - -OpCheckerRegistrar g_ResizeChecker("Resize", new ResizeChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.h deleted file mode 100644 index 21cca6f2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/resize_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_RESIZE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_RESIZE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ResizeChecker : public OpChecker { - public: - ResizeChecker() : OpChecker("Resize") {} - ~ResizeChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_RESIZE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.cc deleted file mode 100644 index ff720f75..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.cc +++ /dev/null @@ -1,48 +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 "checker/reverse_checker.h" -#include -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool ReverseChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, kInputIndex1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - if (primitive->GetAttr(ops::kAxis) != nullptr) { - auto axis = api::GetValue>(primitive->GetAttr(ops::kAxis)); - if (axis.size() != 1) { - MS_LOG(WARNING) << "reverse's axis size only supports 1 by dpico. " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_ReverseChecker("ReverseV2", new ReverseChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.h deleted file mode 100644 index e5fcf17d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/reverse_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_REVERSE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_REVERSE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ReverseChecker : public OpChecker { - public: - ReverseChecker() : OpChecker("Reverse") {} - ~ReverseChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_REVERSE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.cc deleted file mode 100644 index 9d6da8b4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.cc +++ /dev/null @@ -1,54 +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 "checker/scale_checker.h" -#include -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kNegativeAxisCorrespondZero = -4; -constexpr int kNegativeAxisCorrespondOne = -3; -} // namespace -bool ScaleChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, 1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto axis_ptr = primitive->GetAttr(ops::kAxis); - if (axis_ptr != nullptr) { - auto axis_data = api::GetValue(axis_ptr); - std::unordered_set range = {1, kNegativeAxisCorrespondOne, 0, kNegativeAxisCorrespondZero}; - if (range.find(axis_data) == range.end()) { - MS_LOG(WARNING) << "axis val only supports 1/-3/0/-4 by dpico. " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_ScaleChecker("ScaleFusion", new ScaleChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.h deleted file mode 100644 index 65aa51b9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/scale_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SCALE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SCALE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class ScaleChecker : public OpChecker { - public: - ScaleChecker() : OpChecker("Scale") {} - ~ScaleChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SCALE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.cc deleted file mode 100644 index 900f4d3c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.cc +++ /dev/null @@ -1,60 +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 "checker/slice_checker.h" -#include -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kMaxSplitSize = 31; -} // namespace - -bool SliceChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (output_num > kMaxTopNum) { - MS_LOG(WARNING) << "output num " << output_num << " is greater than " << kMaxNumOutput << " " - << op->fullname_with_scope(); - return false; - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - auto axis_ptr = primitive->GetAttr(ops::kAxes); - if (axis_ptr != nullptr) { - auto axis_data = api::GetValue>(axis_ptr); - if (axis_data[0] < kAxisLowerBound || axis_data[0] > kAxisUpperBound) { - MS_LOG(WARNING) << "axis val should in range [-4, 3]. " << op->fullname_with_scope(); - return false; - } - } - - if (primitive->GetAttr(ops::kSizeSplits) != nullptr) { - auto splits = api::GetValue>(primitive->GetAttr(ops::kSizeSplits)); - if (splits.size() > kMaxSplitSize) { - MS_LOG(WARNING) << "split size should be less than " << kMaxSplitSize << " " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_SliceChecker("SliceFusion", new SliceChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.h deleted file mode 100644 index a72c1c69..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/slice_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SLICE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SLICE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class SliceChecker : public OpChecker { - public: - SliceChecker() : OpChecker("Slice") {} - ~SliceChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SLICE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.cc deleted file mode 100644 index ce8c0b6e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.cc +++ /dev/null @@ -1,92 +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 "checker/softmax_checker.h" -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "common/check_base.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kMaxVectorC = 65536; -bool CheckVectorAndTensorChannel(const std::vector &input_shape, mindspore::Format format) { - if (input_shape.size() == kDims2) { - int64_t vec_channel; - if (GetVectorChannel(input_shape, &vec_channel) != RET_OK) { - MS_LOG(ERROR) << "get vector channel failed"; - return false; - } - if (vec_channel > kMaxVectorC) { - return false; - } - } else if (input_shape.size() == kDims4) { - int64_t tensor_channel; - if (GetTensorChannel(input_shape, format, &tensor_channel) != RET_OK) { - MS_LOG(ERROR) << "get tensor channel failed"; - return false; - } - if (tensor_channel > kMaxInputWOf4Dims) { - return false; - } - } - return true; -} -} // namespace -bool SoftmaxChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - std::vector input_shape; - if (GetInputShapeFromCNode(op, kInputIndex1, &input_shape) == RET_OK && !input_shape.empty()) { - auto primitive = api::GetValueNode(op->input(0)); - MS_CHECK_TRUE_MSG(primitive != nullptr, false, "primitive is nullptr."); - auto axis_ptr = primitive->GetAttr(ops::kAxis); - if (axis_ptr != nullptr) { - auto axis_data = api::GetValue>(axis_ptr); - auto axis = axis_data[0]; - if (axis < 0) { - int64_t input_shape_len = static_cast(input_shape.size()); - axis = (axis + input_shape_len) % input_shape_len; - std::vector axes = {axis}; - (void)primitive->AddAttr(ops::kAxis, api::MakeValue(axes)); - } - if (static_cast(axis) != kAxis1 && static_cast(axis) != kAxis2 && - static_cast(axis) != kAxis3) { - MS_LOG(WARNING) << "axis val only supports 1/2/3 by dpico. " << op->fullname_with_scope(); - return false; - } - if (axis == 1) { - if (!CheckVectorAndTensorChannel(input_shape, format)) { - return false; - } - } else if (static_cast(axis) == kAxis3) { - int64_t input_w; - if (GetWidth(input_shape, format, &input_w) != RET_OK) { - MS_LOG(ERROR) << "get input_w failed"; - return false; - } - if (input_w > kMaxInputWOf4Dims) { - return false; - } - } - } - } - return true; -} - -OpCheckerRegistrar g_SoftmaxChecker("Softmax", new SoftmaxChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.h deleted file mode 100644 index 1386d487..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/softmax_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SOFTMAX_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SOFTMAX_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class SoftmaxChecker : public OpChecker { - public: - SoftmaxChecker() : OpChecker("Softmax") {} - ~SoftmaxChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SOFTMAX_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.cc deleted file mode 100644 index 55124a92..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.cc +++ /dev/null @@ -1,37 +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 "checker/split_checker.h" -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool SplitChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (output_num > kMaxTopNum) { - MS_LOG(WARNING) << op->fullname_with_scope() << "'s output num " << output_num << " is greater than " << kMaxTopNum; - return false; - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - return false; - } - return primitive->GetAttr(ops::kAxis) != nullptr && api::GetValue(primitive->GetAttr(ops::kAxis)) != 0; -} - -OpCheckerRegistrar g_SplitChecker("Split", new SplitChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.h deleted file mode 100644 index 140beec5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/split_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SPLIT_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SPLIT_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class SplitChecker : public OpChecker { - public: - SplitChecker() : OpChecker("Split") {} - ~SplitChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SPLIT_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.cc deleted file mode 100644 index 223feedb..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.cc +++ /dev/null @@ -1,41 +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 "checker/spp_checker.h" -#include -#include "common/op_attr.h" - -namespace mindspore { -namespace dpico { -bool SppChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - if (primitive->GetAttr(dpico::kPoolMethod) != nullptr) { - auto pool_method = api::GetValue(primitive->GetAttr(dpico::kPoolMethod)); - if (pool_method != 0 && pool_method != 1) { - MS_LOG(WARNING) << "only supports max && ave pool by dpico. " << op->fullname_with_scope(); - return false; - } - } - return true; -} - -OpCheckerRegistrar g_SppChecker("Spp", new SppChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.h deleted file mode 100644 index 09c97507..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/spp_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SPP_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SPP_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class SppChecker : public OpChecker { - public: - SppChecker() : OpChecker("Spp") {} - ~SppChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SPP_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.cc deleted file mode 100644 index 11a243f5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.cc +++ /dev/null @@ -1,44 +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 "checker/squeeze_checker.h" -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" - -namespace mindspore { -namespace dpico { -bool SqueezeChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format) { - std::vector output_shapes; - if (GetBoolAttr(op, dpico::kInferDone)) { - if (GetOutputShapesFromCNode(op, &output_shapes) != RET_OK) { - MS_LOG(ERROR) << "get node shape failed. " << op->fullname_with_scope(); - return false; - } - if (output_shapes.size() != 1) { - MS_LOG(ERROR) << "squeeze should have single output, but in fact it has " << output_shapes.size() << " outputs."; - return false; - } - auto output_shape = output_shapes.at(0); - return output_shape.size() > 1; - } - return true; -} - -OpCheckerRegistrar g_SqueezeChecker("Squeeze", new SqueezeChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.h deleted file mode 100644 index cc092833..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/squeeze_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SQUEEZE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SQUEEZE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class SqueezeChecker : public OpChecker { - public: - SqueezeChecker() : OpChecker("Squeeze") {} - ~SqueezeChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_SQUEEZE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.cc deleted file mode 100644 index 40908570..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.cc +++ /dev/null @@ -1,42 +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 "checker/strided_slice_checker.h" -#include -#include -#include "include/registry/converter_context.h" - -namespace mindspore { -namespace dpico { -bool StridedSliceChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format) { - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - if (primitive->GetAttr(ops::kFmkType) != nullptr) { - auto fmk_type = static_cast(api::GetValue(primitive->GetAttr(ops::kFmkType))); - if (fmk_type == converter::kFmkTypeOnnx) { - return true; - } - } - MS_LOG(WARNING) << "only support onnx slice op for now. " << op->fullname_with_scope(); - return false; -} - -OpCheckerRegistrar g_StridedSliceChecker("StridedSlice", new StridedSliceChecker()); -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.h deleted file mode 100644 index 6e698aeb..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/strided_slice_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_STRIDED_SLICE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_STRIDED_SLICE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class StridedSliceChecker : public OpChecker { - public: - StridedSliceChecker() : OpChecker("StridedSlice") {} - ~StridedSliceChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_STRIDED_SLICE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.cc b/mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.cc deleted file mode 100644 index 61cef9c2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.cc +++ /dev/null @@ -1,76 +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 "checker/transpose_checker.h" -#include -#include -#include -#include "common/data_transpose_utils.h" -#include "common/fetch_content.h" -#include "common/op_attr.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace dpico { -bool TransposeChecker::Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) { - if (!CheckInputW(op, kInputIndex1, format, kMaxInputWOf4Dims)) { - MS_LOG(WARNING) << "input_w is not supported. " << op->fullname_with_scope(); - return false; - } - auto primitive = api::GetValueNode(op->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr"; - return false; - } - DataInfo data_info; - std::vector perm_val; - if (op->size() > kInputIndex2 && FetchDataFromParameterNode(op, kInputIndex2, &data_info) == lite::RET_OK) { - auto data = reinterpret_cast(data_info.data_.data()); - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << op->fullname_with_scope(); - return false; - } - int data_size; - if (GetDataSizeFromTensor(&data_info, &data_size) != RET_OK) { - MS_LOG(ERROR) << "get data size from tensor failed."; - return false; - } - if (static_cast(data_size) != kDims4) { - return false; - } - perm_val = {data[0], data[kAxis1], data[kAxis2], data[kAxis3]}; - } else if (primitive->GetAttr(kPerm) != nullptr) { - auto perm_vec = api::GetValue>(primitive->GetAttr(kPerm)); - (void)std::transform(perm_vec.begin(), perm_vec.end(), std::back_inserter(perm_val), - [](int64_t p) { return static_cast(p); }); - } else { - MS_LOG(ERROR) << "transpose param invalid" << op->fullname_with_scope(); - return false; - } - if (perm_val.empty()) { - MS_LOG(WARNING) << "perm val is empty." << op->fullname_with_scope(); - return false; - } - if (perm_val != kNC2NH && perm_val != kNH2NC) { - MS_LOG(WARNING) << "perm val is unsupported. " << op->fullname_with_scope(); - return false; - } - return true; -} - -OpCheckerRegistrar g_TransposeChecker("Transpose", new TransposeChecker()); // Permute -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.h b/mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.h deleted file mode 100644 index d62271e9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/checker/transpose_checker.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_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_TRANSPOSE_CHECKER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_TRANSPOSE_CHECKER_H_ - -#include -#include "checker/op_checker.h" - -namespace mindspore { -namespace dpico { -class TransposeChecker : public OpChecker { - public: - TransposeChecker() : OpChecker("Transpose") {} - ~TransposeChecker() override = default; - bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_TRANSPOSE_CHECKER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/anf_util.cc b/mindspore-lite/tools/converter/adapter/dpico/common/anf_util.cc deleted file mode 100644 index f9bb0c8a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/anf_util.cc +++ /dev/null @@ -1,801 +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 "common/anf_util.h" -#include -#include -#include -#include -#include -#include -#include "include/securec.h" -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "common/string_util.h" -#include "infer/custom.h" -#include "infer/tuple_get_item.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "common/check_base.h" -namespace mindspore { -namespace ops { -class PrimitiveC; -} -} // namespace mindspore -namespace mindspore { -namespace dpico { -namespace { -const std::map kTypeMap = { - {kNumberTypeBool, 1}, {kNumberTypeInt, 4}, {kNumberTypeInt8, 1}, {kNumberTypeInt16, 2}, - {kNumberTypeInt32, 4}, {kNumberTypeInt64, 8}, {kNumberTypeUInt, 4}, {kNumberTypeUInt8, 1}, - {kNumberTypeUInt16, 2}, {kNumberTypeUInt32, 4}, {kNumberTypeUInt64, 8}, {kNumberTypeFloat, 4}, - {kNumberTypeFloat16, 2}, {kNumberTypeFloat32, 4}, {kNumberTypeFloat64, 8}, {kNumberTypeComplex64, 8}, - {kNumberTypeComplex128, 16}}; -constexpr size_t kTupleGetItemInputSize = 3; -constexpr size_t kInputNodeOutputIndexInTupleGetItem = 2; -using PrimitiveCPtr = std::shared_ptr; -size_t TypeIdSize(const TypeId data_type) { - const size_t unsupported_type_error = 0; - auto iter = kTypeMap.find(data_type); - if (iter != kTypeMap.end()) { - return iter->second; - } - return unsupported_type_error; -} -} // namespace -bool CheckPrimitiveType(const api::AnfNodePtr &node, const api::PrimitivePtr &primitive_type) { - if (node == nullptr) { - return false; - } - if (node->isa()) { - auto cnode = node->cast(); - return IsPrimitive(cnode->input(0), primitive_type); - } else if (node->isa()) { - return IsPrimitive(node, primitive_type); - } - return false; -} - -STATUS GetPrimitiveType(const api::AnfNodePtr &node, std::string *name) { - if (name == nullptr) { - MS_LOG(ERROR) << "name is nulltr."; - return RET_ERROR; - } - if (node == nullptr) { - MS_LOG(ERROR) << "node is nullptr."; - return RET_ERROR; - } - if (node->isa()) { - auto cnode = node->cast(); - auto primitive = api::GetValueNode(cnode->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (CheckPrimitiveType(node, api::MakeShared())) { - auto custom_prim = api::utils::cast>(primitive); - MS_CHECK_TRUE_MSG(custom_prim != nullptr, RET_ERROR, "custom op is nullptr."); - *name = custom_prim->get_type(); - return RET_OK; - } else { - *name = primitive->name(); - return RET_OK; - } - } else if (node->isa()) { - auto fn_value = api::GetValueNode(node); - if (fn_value == nullptr) { - MS_LOG(ERROR) << "fn_value is nullptr."; - return RET_ERROR; - } - *name = fn_value->name(); - return RET_OK; - } - MS_LOG(ERROR) << "There is no name for this node"; - return RET_ERROR; -} -STATUS GetShapeVectorFromParameter(const api::AnfNodePtr &anode, ShapeVector *shape_vector) { - if (shape_vector == nullptr) { - MS_LOG(ERROR) << "shape vector is nullptr."; - return RET_ERROR; - } - if (!api::utils::isa(anode)) { - MS_LOG(ERROR) << "anode should be parameter node. "; - return RET_ERROR; - } - auto param_node = anode->cast(); - auto abstract_base = param_node->abstract(); - if (abstract_base == nullptr) { - MS_LOG(ERROR) << "Abstract of parameter is nullptr, " << param_node->name(); - return lite::RET_PARAM_INVALID; - } - if (!api::utils::isa(abstract_base)) { - MS_LOG(ERROR) << "Abstract of parameter should be abstract tensor, " << param_node->name(); - return lite::RET_INPUT_TENSOR_ERROR; - } - auto abstract_tensor = api::utils::cast(abstract_base); - MS_CHECK_TRUE_MSG(abstract_tensor != nullptr, RET_ERROR, "Cast to abstract tensor failed!"); - if (!api::utils::isa(abstract_tensor->shape())) { - MS_LOG(ERROR) << "Shape of Abstract of parameter should be ShapePtr, " << param_node->name(); - return lite::RET_PARAM_INVALID; - } - *shape_vector = api::utils::cast(abstract_tensor->shape())->shape(); - return RET_OK; -} -std::vector CastToInt(const api::ValuePtr &value) { - if (value == nullptr) { - MS_LOG(WARNING) << "valueptr is nullptr."; - return {}; - } - std::vector cur_value = {}; - if (api::utils::isa(value)) { - if (!value->cast()->value().empty()) { - auto origin_value = api::GetValue>(value); - (void)std::transform(origin_value.begin(), origin_value.end(), std::back_inserter(cur_value), - [](int64_t index) { return static_cast(index); }); - } - } else { - cur_value.push_back(static_cast(api::GetValue(value))); - } - return cur_value; -} -size_t GetTupleGetItemOutIndex(const api::CNodePtr &tuple_get_item) { - MS_ASSERT(tuple_get_item != nullptr); - if (tuple_get_item->size() != kTupleGetItemInputSize) { - MS_LOG(ERROR) << "The node tuple_get_item must have 2 inputs!"; - return SIZE_MAX; - } - auto output_index_value_node = tuple_get_item->input(kInputNodeOutputIndexInTupleGetItem); - MS_ASSERT(output_index_value_node != nullptr); - auto value_node = output_index_value_node->cast(); - MS_ASSERT(value_node != nullptr); - auto value_vec = CastToInt(value_node->value()); - if (value_vec.empty()) { - MS_LOG(ERROR) << "value vec is empty."; - return SIZE_MAX; - } - return IntToSize(value_vec.front()); -} -STATUS GetOutputShapesFromCNode(const api::CNodePtr &cnode, std::vector *output_shapes) { - api::AbstractBasePtr abstract = nullptr; - if (output_shapes == nullptr) { - MS_LOG(ERROR) << "output_shapes is nullptr."; - return RET_ERROR; - } - if (CheckPrimitiveType(cnode, api::MakeShared())) { - auto tuple_inputs = cnode->inputs(); - MS_ASSERT(tuple_inputs.size() == kTupleGetItemInputSize); - auto get_item_input_cnode = tuple_inputs.at(1); - MS_ASSERT(get_item_input_cnode != nullptr); - auto idx = GetTupleGetItemOutIndex(cnode); - if (!api::utils::isa(get_item_input_cnode->abstract())) { - MS_LOG(ERROR) << "TupleGetItem's abstract is not AbstractTuple"; - return RET_ERROR; - } - auto abstract_tuple = api::utils::cast(get_item_input_cnode->abstract()); - auto abstract_list = abstract_tuple->elements(); - if (abstract_list.size() <= idx) { - MS_LOG(ERROR) << "AbstractTuple's size is smaller than expect"; - return RET_ERROR; - } - abstract = abstract_list[idx]; - } else { - abstract = cnode->abstract(); - } - if (abstract == nullptr) { - MS_LOG(ERROR) << "abstract cnode is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (api::utils::isa(abstract)) { - auto abstract_tuple = api::utils::cast(abstract); - auto abstract_list = abstract_tuple->elements(); - for (const auto &elem : abstract_list) { - ShapeVector shape_vector; - if (FetchShapeFromAbstract(elem, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "fetch shape from abstract tuple elem failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (shape_vector.empty()) { - MS_LOG(ERROR) << "shape_vector is empty." << cnode->fullname_with_scope(); - return RET_ERROR; - } - (void)output_shapes->emplace_back(shape_vector); - } - return RET_OK; - } else { - ShapeVector shape_vector; - if (FetchShapeFromAbstract(abstract, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "fetch shape from abstract failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (shape_vector.empty()) { - MS_LOG(ERROR) << "shape_vector is empty." << cnode->fullname_with_scope(); - return RET_ERROR; - } - (void)output_shapes->emplace_back(shape_vector); - } - return RET_OK; -} - -STATUS GetInputShapeFromCNode(const api::CNodePtr &cnode, size_t input_idx, ShapeVector *shape) { - if (shape == nullptr) { - MS_LOG(ERROR) << "shape is nullptr."; - return RET_ERROR; - } - auto input_abstract = GetCNodeInputAbstract(cnode, input_idx); - if (input_abstract == nullptr) { - MS_LOG(ERROR) << "input_abstract is nullptr."; - return RET_ERROR; - } - if (FetchShapeFromAbstract(input_abstract, shape) != RET_OK) { - MS_LOG(ERROR) << "fetch shape from abstract failed."; - return RET_ERROR; - } - return RET_OK; -} - -STATUS FetchShapeFromAbstract(const api::AbstractBasePtr &abstract, ShapeVector *shape) { - if (shape == nullptr) { - MS_LOG(ERROR) << "shape is nullptr."; - return RET_ERROR; - } - if (abstract == nullptr) { - MS_LOG(ERROR) << "abstract of cnode is invalid."; - return RET_ERROR; - } - if (!api::utils::isa(abstract)) { - MS_LOG(ERROR) << "abstract of cnode is invalid."; - return RET_ERROR; - } - auto abstract_tensor = abstract->cast(); - if (!api::utils::isa(abstract_tensor->shape())) { - MS_LOG(ERROR) << "shape of cnode's output is invalid."; - return RET_ERROR; - } - *shape = api::utils::cast(abstract_tensor->shape())->shape(); - return RET_OK; -} -STATUS FetchTypeIdFromAbstract(const api::AbstractBasePtr &abstract, TypeId *type_id) { - if (type_id == nullptr) { - MS_LOG(ERROR) << "type id is nullptr."; - return RET_ERROR; - } - if (abstract == nullptr) { - MS_LOG(ERROR) << "abstract of cnode is invalid."; - return RET_ERROR; - } - if (!api::utils::isa(abstract)) { - MS_LOG(ERROR) << "abstract of cnode is invalid."; - return RET_ERROR; - } - auto abstract_tensor = abstract->cast(); - if (abstract_tensor->element() == nullptr) { - MS_LOG(ERROR) << "element of abstract_tensor is nullptr."; - return RET_ERROR; - } - auto type_ptr = abstract_tensor->element()->type(); - if (type_ptr == nullptr) { - MS_LOG(ERROR) << "type_ptr of abstract_tensor is nullptr."; - return RET_ERROR; - } - *type_id = type_ptr->type_id(); - return RET_OK; -} - -int GetAnfNodeOutputShape(const api::AnfNodePtr &input, ShapeVector *shape_vector) { - if (shape_vector == nullptr) { - MS_LOG(ERROR) << "shape vector is nullptr." << input->fullname_with_scope(); - return RET_ERROR; - } - if (api::utils::isa(input)) { - if (GetShapeVectorFromParameter(input, shape_vector) != RET_OK) { - MS_LOG(ERROR) << "get output shape for preprocessor failed. " << input->fullname_with_scope(); - return RET_ERROR; - } - } else if (api::utils::isa(input)) { - auto input_cnode = input->cast(); - std::vector output_shapes; - if (GetOutputShapesFromCNode(input_cnode, &output_shapes) != RET_OK) { - MS_LOG(ERROR) << "get output shapes from cnode failed. " << input_cnode->fullname_with_scope(); - return RET_ERROR; - } - if (output_shapes.size() == 1) { - *shape_vector = output_shapes.at(0); - } else { - MS_LOG(ERROR) << input_cnode->fullname_with_scope() << " has " << output_shapes.size() - << " output, which should be 1."; - return RET_ERROR; - } - } - if (shape_vector->empty()) { - MS_LOG(ERROR) << "subgraph input shape shouldn't be empty. " << input->fullname_with_scope(); - return RET_ERROR; - } else if (shape_vector->at(0) < 0) { - MS_LOG(WARNING) << " the N axis of " << input->fullname_with_scope() << "'s output shape is " << shape_vector->at(0) - << ", which will be set to 1."; - shape_vector->at(0) = 1; - } - return RET_OK; -} - -std::string TypeIdToString(TypeId type_id) { - const std::unordered_map kTypeIdMap{ - {kNumberTypeFloat16, "Float16"}, {kNumberTypeFloat, "Float32"}, {kNumberTypeFloat32, "Float32"}, - {kNumberTypeInt8, "Int8"}, {kNumberTypeInt16, "Int16"}, {kNumberTypeInt, "Int32"}, - {kNumberTypeInt32, "Int32"}, {kNumberTypeUInt8, "UInt8"}, {kNumberTypeUInt16, "UInt16"}, - {kNumberTypeUInt, "UInt32"}, {kNumberTypeUInt32, "UInt32"}, {kObjectTypeString, "String"}, - {kNumberTypeBool, "Bool"}, {kObjectTypeTensorType, "Tensor"}}; - std::string type_str = "Unknown"; - if (kTypeIdMap.find(static_cast(type_id)) != kTypeIdMap.end()) { - type_str = kTypeIdMap.at(static_cast(type_id)); - } - return type_str; -} - -bool CheckInputs(const api::CNodePtr &cnode) { - if (cnode == nullptr) { - MS_LOG(ERROR) << "cnode is nullptr."; - return false; - } - auto inputs = cnode->inputs(); - if (std::any_of(inputs.begin(), inputs.end(), [](const api::AnfNodePtr &anf_node) { return anf_node == nullptr; })) { - MS_LOG(ERROR) << "input is nullptr."; - return false; - } - return true; -} -std::string GetCustomOutputName(const api::AnfNodePtr &node) { - std::string output_name; - auto input_cnode = node->cast(); - if (input_cnode == nullptr) { - MS_LOG(ERROR) << "custom node should be cnode. " << node->fullname_with_scope(); - return ""; - } - if (input_cnode->GetAttr(kOutputsNames) != nullptr) { - auto output_names = api::GetValue>(input_cnode->GetAttr(kOutputsNames)); - if (output_names.size() == 1) { - output_name = output_names.at(0); - } else { - MS_LOG(ERROR) << "multi-output's custom node shouldn't be a subgraph's input cnode. " - << node->fullname_with_scope(); - return ""; - } - } - return output_name; -} -api::TensorPtr CreateTensorInfo(const void *data, size_t data_size, const std::vector &shape, - TypeId data_type) { - api::TensorPtr tensor_info = nullptr; - if (shape.empty() && data_size == TypeIdSize(data_type)) { - ShapeVector scalar_shape = {1}; - tensor_info = api::MakeShared(data_type, scalar_shape); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "new tensor init failed"; - return nullptr; - } - tensor_info->set_shape({}); - } else { - tensor_info = api::MakeShared(data_type, shape); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "new tensor init failed"; - return nullptr; - } - } - if (data_size == 0) { - return tensor_info; - } - if (data == nullptr) { - MS_LOG(ERROR) << "input tensor data is nullptr"; - return nullptr; - } - auto ret = memcpy_s(tensor_info->data(), tensor_info->Size(), data, data_size); - if (ret != EOK) { - MS_LOG(ERROR) << "memcpy_s error : " << ret; - return nullptr; - } - return tensor_info; -} - -api::AbstractBasePtr CreateTensorAbstract(const std::vector &shape, TypeId data_type) { - auto tensor_info = dpico::CreateTensorInfo(nullptr, 0, shape, data_type); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "Create tensor info failed"; - return nullptr; - } - auto abstract = tensor_info->ToAbstract(); - if (abstract == nullptr) { - MS_LOG(ERROR) << "Create tensor abstarct failed"; - return nullptr; - } - return abstract; -} - -int InitParameterFromTensorInfo(const api::ParameterPtr ¶m_node, const api::TensorPtr &tensor_info) { - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "tensor info is nullptr."; - return RET_ERROR; - } - auto abstract_tensor = tensor_info->ToAbstract(); - if (abstract_tensor == nullptr) { - MS_LOG(ERROR) << "Create abstract tensor failed."; - return RET_ERROR; - } - param_node->set_abstract(abstract_tensor); - param_node->set_default_param(tensor_info); - return RET_OK; -} - -api::AbstractBasePtr GetCNodeInputAbstract(const api::CNodePtr &cnode, size_t index) { - if (cnode == nullptr) { - MS_LOG(ERROR) << "CNodePtr is nullptr"; - return nullptr; - } - auto inputs = cnode->inputs(); - if (index >= inputs.size()) { - MS_LOG(ERROR) << "index: " << index << " is greater than inputs size " << inputs.size(); - return nullptr; - } - auto input = inputs[index]; - if (input == nullptr) { - MS_LOG(ERROR) << "CNode input is nullptr"; - return nullptr; - } - - api::AbstractBasePtr abstract = nullptr; - if (api::utils::isa(input)) { - auto parameter = input->cast(); - abstract = parameter->abstract(); - } else if (api::utils::isa(input)) { - auto input_cnode = input->cast(); - if (CheckPrimitiveType(input_cnode, api::MakeShared())) { - auto tuple_inputs = input_cnode->inputs(); - MS_ASSERT(tuple_inputs.size() == kTupleGetItemInputSize); - auto get_item_input_cnode = tuple_inputs.at(1); - MS_ASSERT(get_item_input_cnode != nullptr); - auto idx = GetTupleGetItemOutIndex(input_cnode); - if (!api::utils::isa(get_item_input_cnode->abstract())) { - MS_LOG(ERROR) << "TupleGetItem's abstract is not AbstractTuple"; - return nullptr; - } - auto abstract_tuple = api::utils::cast(get_item_input_cnode->abstract()); - auto abstract_list = abstract_tuple->elements(); - if (abstract_list.size() <= idx) { - MS_LOG(ERROR) << "AbstractTuple's size is smaller than expect"; - return nullptr; - } - abstract = abstract_list[idx]; - } else { - abstract = input_cnode->abstract(); - } - } else { - MS_LOG(ERROR) << "unsupported input node type"; - return nullptr; - } - return abstract; -} - -api::AbstractBasePtr GetAbstractFromAnfNode(const api::AnfNodePtr &node) { - api::AbstractBasePtr abstract = nullptr; - if (api::utils::isa(node)) { - auto parameter = node->cast(); - abstract = parameter->abstract(); - } else if (api::utils::isa(node)) { - auto cnode = node->cast(); - if (CheckPrimitiveType(cnode, api::MakeShared())) { - auto tuple_inputs = cnode->inputs(); - MS_ASSERT(tuple_inputs.size() == kTupleGetItemInputSize); - auto get_item_input_cnode = tuple_inputs.at(1); - MS_ASSERT(get_item_input_cnode != nullptr); - auto idx = GetTupleGetItemOutIndex(cnode); - if (!api::utils::isa(get_item_input_cnode->abstract())) { - MS_LOG(ERROR) << "TupleGetItem's abstract is not AbstractTuple"; - return nullptr; - } - auto abstract_tuple = api::utils::cast(get_item_input_cnode->abstract()); - auto abstract_list = abstract_tuple->elements(); - if (abstract_list.size() <= idx) { - MS_LOG(ERROR) << "AbstractTuple's size is smaller than expect"; - return nullptr; - } - abstract = abstract_list[idx]; - } else { - abstract = cnode->abstract(); - } - } - return abstract; -} - -api::ParameterPtr BuildIntValueParameterNode(const api::FuncGraphPtr &func_graph, const int32_t &data, - const std::string &node_name) { - MS_ASSERT(func_graph != nullptr); - auto param_node = func_graph->add_parameter(); - param_node->set_name(node_name); - - auto tensor_info = CreateTensorInfo(&data, sizeof(int32_t), {1}, kNumberTypeInt32); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "Create tensor info failed"; - return nullptr; - } - - auto status = InitParameterFromTensorInfo(param_node, tensor_info); - if (status != RET_OK) { - MS_LOG(ERROR) << "init parameter from tensor info failed"; - return nullptr; - } - return param_node; -} - -api::ParameterPtr BuildIntVecParameterNode(const api::FuncGraphPtr &func_graph, const std::vector &data, - const std::string &node_name) { - MS_ASSERT(func_graph != nullptr); - MS_CHECK_TRUE_MSG(data.size() != 0, nullptr, "Data size is 0"); - auto param_node = func_graph->add_parameter(); - param_node->set_name(node_name); - - std::vector shape_vector{static_cast(data.size())}; - auto tensor_info = CreateTensorInfo(data.data(), data.size() * sizeof(int32_t), shape_vector, kNumberTypeInt32); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "Create tensor info failed"; - return nullptr; - } - - auto status = InitParameterFromTensorInfo(param_node, tensor_info); - if (status != RET_OK) { - MS_LOG(ERROR) << "init parameter from tensor info failed"; - return nullptr; - } - - return param_node; -} - -api::ParameterPtr BuildIntVec2DParameterNode(const api::FuncGraphPtr &func_graph, - const std::vector> &data, - const std::string &node_name) { - MS_ASSERT(func_graph != nullptr); - MS_CHECK_TRUE_MSG(data.size() != 0, nullptr, "Data size is 0"); - auto param_node = func_graph->add_parameter(); - param_node->set_name(node_name); - - std::vector shape_vector; - shape_vector.push_back(data.size()); - shape_vector.push_back(kDims2); - - std::vector data_1d; - for (auto pair : data) { - (void)data_1d.insert(data_1d.end(), pair.begin(), pair.end()); - } - - auto size = data_1d.size() * sizeof(int32_t); - auto tensor_info = CreateTensorInfo(data_1d.data(), size, shape_vector, kNumberTypeInt32); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "Create tensor info failed"; - return nullptr; - } - auto status = InitParameterFromTensorInfo(param_node, tensor_info); - if (status != RET_OK) { - MS_LOG(ERROR) << "init parameter from tensor info failed"; - return nullptr; - } - return param_node; -} - -api::ParameterPtr BuildFloatValueParameterNode(const api::FuncGraphPtr &func_graph, const float &data, - const std::string &node_name) { - MS_ASSERT(func_graph != nullptr); - auto param_node = func_graph->add_parameter(); - param_node->set_name(node_name); - - auto tensor_info = CreateTensorInfo(&data, sizeof(float), {1}, kNumberTypeFloat32); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "Create tensor info failed"; - return nullptr; - } - auto status = InitParameterFromTensorInfo(param_node, tensor_info); - if (status != RET_OK) { - MS_LOG(ERROR) << "init parameter from tensor info failed"; - return nullptr; - } - return param_node; -} - -api::CNodePtr GenTransposeNode(const api::FuncGraphPtr &func_graph, const api::AnfNodePtr &input_node, - const std::vector &perm, const std::string &cnode_name) { - MS_ASSERT(func_graph != nullptr && input_node != nullptr); - auto perm_node = BuildIntVecParameterNode(func_graph, perm, cnode_name + "_perm"); - if (perm_node == nullptr) { - MS_LOG(ERROR) << "new perm_node error"; - return nullptr; - } - auto trans_prim = api::MakeShared(); - if (trans_prim == nullptr) { - MS_LOG(ERROR) << "new trans_prim failed"; - return nullptr; - } - auto cnode = func_graph->NewCNode(trans_prim, {input_node, perm_node}); - if (cnode == nullptr) { - MS_LOG(ERROR) << "new cnode error"; - return nullptr; - } - auto manager = api::FuncGraphManager::Manage(func_graph); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr."; - return nullptr; - } - manager->SetEdge(cnode, 1, input_node); - manager->SetEdge(cnode, kInputIndex2, perm_node); - cnode->set_fullname_with_scope(cnode_name); - return cnode; -} - -api::TensorPtr GetTensorInfo(const api::AnfNodePtr &node) { - MS_ASSERT(node != nullptr); - if (!api::utils::isa(node)) { - if (api::utils::isa(node)) { - auto valueNode = node->cast(); - auto value = valueNode->value()->cast(); - if (value != nullptr) { - return value; - } - } - MS_LOG(DEBUG) << "get lite param value node neither parameter node or value node"; - return nullptr; - } - auto param = node->cast(); - if (param == nullptr) { - MS_LOG(ERROR) << "param is nullptr."; - return nullptr; - } - auto tensor_info = param->default_param()->cast(); - return tensor_info; -} - -std::vector> CastToVec2DInt(const api::ValuePtr &value) { - if (value == nullptr) { - MS_LOG(WARNING) << "valueptr is nullptr."; - return {}; - } - - std::vector> result_value; - if (api::utils::isa(value)) { - auto origin_value = api::GetValue>>(value); - for (auto &vec : origin_value) { - std::vector cur_value; - for (size_t j = 0; j < vec.size(); ++j) { - cur_value.push_back(static_cast(vec[j])); - } - result_value.push_back(cur_value); - } - } - return result_value; -} - -bool GetBoolAttr(const api::AnfNodePtr &node, const std::string &attr_name) { - auto cnode = node->cast(); - if (cnode == nullptr) { - MS_LOG(ERROR) << "cur node is not a cnode. " << node->fullname_with_scope(); - return false; - } - auto primitive = api::GetValueNode(cnode->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr:" << cnode->fullname_with_scope(); - return false; - } - auto value_ptr = primitive->GetAttr(attr_name); - if (value_ptr == nullptr) { - MS_LOG(ERROR) << "There is no attr named " << attr_name << " for node " << cnode->fullname_with_scope(); - return false; - } - return api::GetValue(value_ptr); -} - -STATUS GetDataTypeAndShape(const api::ParameterPtr ¶m_node, TypeId *data_type, ShapeVector *shape_vector) { - if (param_node == nullptr) { - MS_LOG(ERROR) << "param node is nullptr."; - return RET_ERROR; - } - if (data_type == nullptr) { - MS_LOG(ERROR) << "data type is nullptr."; - return RET_ERROR; - } - if (shape_vector == nullptr) { - MS_LOG(ERROR) << "shape vector is nullptr."; - return RET_ERROR; - } - auto abstract_base = param_node->abstract(); - if (abstract_base == nullptr) { - MS_LOG(ERROR) << "Abstract of parameter is nullptr, " << param_node->name(); - return RET_ERROR; - } - if (!api::utils::isa(abstract_base)) { - MS_LOG(ERROR) << "Abstract of parameter should be abstract tensor, " << param_node->name(); - return RET_ERROR; - } - auto abstract_tensor = api::utils::cast(abstract_base); - MS_CHECK_TRUE_MSG(abstract_tensor != nullptr, RET_ERROR, "Cast to abstract tensor failed!"); - auto typePtr = abstract_tensor->element()->type(); - MS_ASSERT(typePtr != nullptr); - *data_type = typePtr->type_id(); - if (!api::utils::isa(abstract_tensor->shape())) { - MS_LOG(ERROR) << "Shape of Abstract of parameter should be ShapePtr, " << param_node->name(); - return RET_ERROR; - } - *shape_vector = api::utils::cast(abstract_tensor->shape())->shape(); - return RET_OK; -} - -STATUS GetShapeVectorFromStringTensor(const api::TensorPtr &tensor_info, ShapeVector *shape_vector, size_t *offset) { - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "tensor info is nullptr."; - return RET_ERROR; - } - if (shape_vector == nullptr) { - MS_LOG(ERROR) << "shape vector is nullptr."; - return RET_ERROR; - } - if (offset == nullptr) { - MS_LOG(ERROR) << "offset is nullptr."; - return RET_ERROR; - } - auto data_type = tensor_info->data_type(); - if (data_type != kObjectTypeString) { - MS_LOG(ERROR) << "This function only used for string tensor."; - return RET_ERROR; - } - shape_vector->clear(); - auto tensor_data = reinterpret_cast(tensor_info->data()); - std::string shape_str; - std::string shape_size_str; - *offset = 0; - size_t cnt = 0; - for (; *offset < tensor_info->Size(); (*offset)++) { - if (tensor_data[*offset] == ',') { - (*offset)++; - break; - } - shape_size_str.push_back(static_cast(tensor_data[*offset])); - } - if (*offset == 0) { - MS_LOG(ERROR) << "string tensor's dim size not found."; - return RET_ERROR; - } - if (!IsValidUnsignedNum(shape_size_str)) { - MS_LOG(ERROR) << "shape_size str must an unsigned int."; - return RET_ERROR; - } - size_t shape_size = std::stoi(shape_size_str); - for (; *offset < tensor_info->Size(); (*offset)++) { - if (tensor_data[*offset] == ',') { - cnt++; - if (!IsValidUnsignedNum(shape_str)) { - MS_LOG(ERROR) << "shape str must an unsigned int."; - return RET_ERROR; - } - shape_vector->push_back(std::stoi(shape_str)); - shape_str.clear(); - } else { - shape_str.push_back(static_cast(tensor_data[*offset])); - } - if (cnt == shape_size) { - (*offset)++; - break; - } - } - if (shape_vector->empty()) { - MS_LOG(ERROR) << "string tensor's shape shouldn't be empty."; - return RET_ERROR; - } - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/anf_util.h b/mindspore-lite/tools/converter/adapter/dpico/common/anf_util.h deleted file mode 100644 index 2651a4c0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/anf_util.h +++ /dev/null @@ -1,80 +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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_ANF_UTIL_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_ANF_UTIL_H_ - -#include -#include -#include "mindapi/ir/tensor.h" -#include "include/errorcode.h" -#include "mindapi/base/logging.h" -#include "mindapi/ir/anf.h" -#include "mindapi/ir/func_graph.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_NO_CHANGE; -using mindspore::lite::RET_OK; -using mindspore::lite::STATUS; - -namespace mindspore { -namespace dpico { -bool CheckPrimitiveType(const api::AnfNodePtr &node, const api::PrimitivePtr &primitive_type); -STATUS GetPrimitiveType(const api::AnfNodePtr &node, std::string *name); -STATUS GetShapeVectorFromParameter(const api::AnfNodePtr &weight, ShapeVector *shape_vector); -std::vector CastToInt(const api::ValuePtr &value); -size_t GetTupleGetItemOutIndex(const api::CNodePtr &tuple_get_item); -STATUS GetOutputShapesFromCNode(const api::CNodePtr &cnode, std::vector *output_shapes); -STATUS GetInputShapeFromCNode(const api::CNodePtr &cnode, size_t input_idx, ShapeVector *shape); -STATUS FetchShapeFromAbstract(const api::AbstractBasePtr &abstract, ShapeVector *shape); -STATUS FetchTypeIdFromAbstract(const api::AbstractBasePtr &abstract, TypeId *type_id); -int GetAnfNodeOutputShape(const api::AnfNodePtr &input, ShapeVector *shape_vector); -std::string TypeIdToString(TypeId type_id); -bool CheckInputs(const api::CNodePtr &cnode); -std::string GetCustomOutputName(const api::AnfNodePtr &node); -api::TensorPtr CreateTensorInfo(const void *data, size_t data_size, const std::vector &shape, - TypeId data_type); -api::AbstractBasePtr CreateTensorAbstract(const std::vector &shape, TypeId data_type); -int InitParameterFromTensorInfo(const api::ParameterPtr ¶m_node, const api::TensorPtr &tensor_info); -api::AbstractBasePtr GetCNodeInputAbstract(const api::CNodePtr &cnode, size_t index); -api::AbstractBasePtr GetAbstractFromAnfNode(const api::AnfNodePtr &cnode); -api::ParameterPtr BuildIntValueParameterNode(const api::FuncGraphPtr &func_graph, const int32_t &data, - const std::string &node_name); -api::ParameterPtr BuildIntVecParameterNode(const api::FuncGraphPtr &func_graph, const std::vector &data, - const std::string &node_name); -api::ParameterPtr BuildIntVec2DParameterNode(const api::FuncGraphPtr &func_graph, - const std::vector> &data, - const std::string &node_name); -api::ParameterPtr BuildFloatValueParameterNode(const api::FuncGraphPtr &func_graph, const float &data, - const std::string &node_name); -api::CNodePtr GenTransposeNode(const api::FuncGraphPtr &func_graph, const api::AnfNodePtr &input_node, - const std::vector &perm, const std::string &cnode_name); -api::TensorPtr GetTensorInfo(const api::AnfNodePtr &node); -std::vector> CastToVec2DInt(const api::ValuePtr &value); -bool GetBoolAttr(const api::AnfNodePtr &node, const std::string &attr_name); -STATUS GetDataTypeAndShape(const api::ParameterPtr ¶m_node, TypeId *data_type, ShapeVector *shape_vector); -STATUS GetShapeVectorFromStringTensor(const api::TensorPtr &tensor_info, ShapeVector *shape_vector, size_t *offset); -inline size_t IntToSize(int u) { - if (u < 0) { - MS_LOG(WARNING) << "The int value(" << u << ") is less than 0."; - return SIZE_MAX; - } - return static_cast(u); -} -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_ANF_UTIL_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/check_base.h b/mindspore-lite/tools/converter/adapter/dpico/common/check_base.h deleted file mode 100644 index b57c40f3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/check_base.h +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright 2021-2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_CHECK_BASE_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_CHECK_BASE_H_ - -#include - -#define UP_DIV(x, y) (((x) + (y) - (1)) / (y)) -#define UP_ROUND(x, y) (((x) + (y) - (1)) / (y) * (y)) -#define DOWN_DIV(x, y) ((x) / (y)) -#define DOWN_ROUND(x, y) ((x) / (y) * (y)) - -#define kNHWC_N 0 -#define kNHWC_H 1 -#define kNHWC_W 2 -#define kNHWC_C 3 -#define kNCHW_N 0 -#define kNCHW_C 1 -#define kNCHW_H 2 -#define kNCHW_W 3 -#ifdef Debug -#include -#define MS_ASSERT(f) assert(f) -#else -#define MS_ASSERT(f) ((void)0) -#endif - -#define SIZE_MUL_OVERFLOW(x, y) (((x) == 0) ? false : (SIZE_MAX / (x)) < (y)) -#define INT_MUL_OVERFLOW(x, y) \ - (((x) == 0) ? false \ - : ((x) > 0 ? (((y) >= 0) ? (INT_MAX / (x)) < (y) : (INT_MAX / (x)) < (-1 * (y))) \ - : (((y) >= 0) ? (INT_MAX / (x)) > (-1 * (y)) : (INT_MAX / (x)) > (y)))) - -#define INT_MUL_OVERFLOW_THRESHOLD(x, y, threshold) \ - (((x) == 0) ? false \ - : ((x) > 0 ? (((y) >= 0) ? ((threshold) / (x)) < (y) : ((threshold) / (x)) < (-1 * (y))) \ - : (((y) >= 0) ? ((threshold) / (x)) > (-1 * (y)) : ((threshold) / (x)) > (y)))) - -#define INT_ADD_OVERFLOW(x, y) ((INT_MAX - (x)) < (y)) - -// Check whether value is true, if not return 'errcode' -// and print error string msg -#define MS_CHECK_TRUE_MSG(value, errcode, msg) \ - do { \ - if (!(value)) { \ - MS_LOG(ERROR) << msg; \ - return errcode; \ - } \ - } while (0) - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_CHECK_BASE_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.cc b/mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.cc deleted file mode 100644 index 9b3f7c5e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.cc +++ /dev/null @@ -1,224 +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 "common/data_transpose_utils.h" -#include -#include -#include -#include -#include -#include "include/securec.h" -#include "common/check_base.h" -#include "common/float16.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace dpico { -namespace { -const std::unordered_map kTensorFormatMap{ - {mindspore::Format::NCHW, "NCHW"}, {mindspore::Format::NHWC, "NHWC"}, {mindspore::Format::NHWC4, "NHWC4"}, - {mindspore::Format::HWKC, "HWKC"}, {mindspore::Format::HWCK, "HWCK"}, {mindspore::Format::KCHW, "KCHW"}, - {mindspore::Format::CKHW, "CKHW"}, {mindspore::Format::KHWC, "KHWC"}, {mindspore::Format::CHWK, "CHWK"}, - {mindspore::Format::HW, "HW"}, {mindspore::Format::HW4, "HW4"}, {mindspore::Format::NC, "NC"}, - {mindspore::Format::NC4, "NC4"}, {mindspore::Format::NC4HW4, "NC4HW4"}, {mindspore::Format::NCDHW, "NCDHW"}, - {mindspore::Format::NCW, "NCW"}, {mindspore::Format::NWC, "NWC"}}; -int GetPre(int idx, int row, int col) { // computer before transpose the position that current element was - if (row == 0 || col == 0) { - return -1; - } - return (idx % row) * col + idx / row; -} -void MoveData(float *matrix, int idx, int row, int col) { // idx is from the new matrix - float tmp = matrix[idx]; - int cur = idx; - int pre = GetPre(idx, row, col); - while (pre != idx) { - matrix[cur] = matrix[pre]; - cur = pre; - pre = GetPre(cur, row, col); - } - matrix[cur] = tmp; -} -} // namespace - -int DeduceDimConvertion(mindspore::Format src_format, mindspore::Format dst_format, std::vector *perm) { - MS_CHECK_TRUE_MSG(perm != nullptr, RET_ERROR, "perm is nullptr."); - if (kTensorFormatMap.find(src_format) == kTensorFormatMap.end() || - kTensorFormatMap.find(dst_format) == kTensorFormatMap.end()) { - MS_LOG(ERROR) << "src_format or dst_format is error."; - return RET_ERROR; - } - auto src_format_str = kTensorFormatMap.at(src_format); - auto dst_format_str = kTensorFormatMap.at(dst_format); - if (src_format_str.size() != dst_format_str.size()) { - MS_LOG(ERROR) << "src_format or dst_format is error."; - return RET_ERROR; - } - std::replace(src_format_str.begin(), src_format_str.end(), 'K', 'N'); - std::replace(dst_format_str.begin(), dst_format_str.end(), 'K', 'N'); - perm->clear(); - std::unordered_map dim_map; - for (size_t i = 0; i < src_format_str.size(); ++i) { - dim_map[src_format_str[i]] = static_cast(i); - } - for (size_t i = 0; i < dst_format_str.size(); ++i) { - if (dim_map.find(dst_format_str[i]) == dim_map.end()) { - MS_LOG(ERROR) << "src_format and dst_format cannot match, please check."; - return RET_ERROR; - } - perm->push_back(dim_map[dst_format_str[i]]); - } - return RET_OK; -} - -template -STATUS TransposeData(const ShapeVector &origin_shape, const ShapeVector &cur_shape, const std::vector &perm, - T *weight_data, std::vector *buf) { - MS_ASSERT(weight_data != nullptr && buf != nullptr); - MS_ASSERT(origin_shape.size() == cur_shape.size() && cur_shape.size() == perm.size()); - int count = 1; - for (size_t i = 0; i < origin_shape.size(); i++) { - if (INT_MUL_OVERFLOW(count, static_cast(origin_shape.at(i)))) { - MS_LOG(ERROR) << "int mul overflow."; - return RET_ERROR; - } - count *= static_cast(origin_shape.at(i)); - } - ShapeVector post_multiply(cur_shape.size()); - std::unordered_map dim_map; - for (int i = static_cast(cur_shape.size()) - 1; i >= 0; --i) { - if (i == static_cast(cur_shape.size() - 1)) { - post_multiply[i] = 1; - } else { - post_multiply[i] = cur_shape[i + 1] * post_multiply[i + 1]; - } - dim_map[perm[i]] = i; - } - std::unordered_map position_map; - for (int i = 0; i < count; ++i) { - int temp = i; - for (int j = static_cast(origin_shape.size()) - 1; j >= 0; --j) { - MS_ASSERT(origin_shape[j] > 0); - position_map[j] = temp % origin_shape[j]; - temp /= static_cast(origin_shape[j]); - } - int64_t new_pos = std::accumulate(position_map.begin(), position_map.end(), 0, - [&post_multiply, &dim_map](int64_t res, const std::pair &pair_y) { - return res + post_multiply[dim_map[pair_y.first]] * pair_y.second; - }); - buf->at(new_pos) = weight_data[i]; - } - return RET_OK; -} - -template -STATUS DoTransposeData(const api::TensorPtr &tensor, mindspore::Format src_format, mindspore::Format dst_format) { - MS_ASSERT(tensor != nullptr); - auto origin_shape = tensor->shape(); - if (origin_shape.size() != kDims4) { - MS_LOG(ERROR) << "Filter dim-num is not supported, dim-num: " << origin_shape.size(); - return lite::RET_ERROR; - } - if (std::any_of(origin_shape.begin(), origin_shape.end(), [](int64_t val) { return val <= 0; })) { - MS_LOG(ERROR) << "the tensor's shape is invalid."; - return lite::RET_ERROR; - } - std::vector perm; - if (DeduceDimConvertion(src_format, dst_format, &perm) != RET_OK) { - MS_LOG(ERROR) << "deduce perm failed."; - return lite::RET_ERROR; - } - ShapeVector new_shape; - for (auto &val : perm) { - if (val < 0 || static_cast(val) >= origin_shape.size()) { - MS_LOG(ERROR) << "deduce perm is invalid."; - return lite::RET_ERROR; - } - new_shape.push_back(origin_shape[val]); - } - int64_t count = 1; - for (size_t i = 0; i < origin_shape.size(); i++) { - if (INT_MUL_OVERFLOW(count, origin_shape.at(i))) { - MS_LOG(ERROR) << "int mul overflow."; - return RET_ERROR; - } - count *= origin_shape.at(i); - } - if (count <= 0 || count > static_cast(INT32_MAX)) { - MS_LOG(ERROR) << "tensor element num is too big, which should be smaller than int32_max."; - return RET_ERROR; - } - std::vector buf(count); - - auto origin_weight_data = tensor->data(); - if (origin_weight_data == nullptr) { - MS_LOG(ERROR) << "origin_weight_data is nullptr."; - return RET_ERROR; - } - T *weightData = static_cast(origin_weight_data); - if (TransposeData(origin_shape, new_shape, perm, weightData, &buf) != RET_OK) { - MS_LOG(ERROR) << "transpose data failed."; - return RET_ERROR; - } - if (tensor->Size() == 0) { - MS_LOG(ERROR) << "tensor size shouldn't be 0"; - return RET_ERROR; - } - if (memcpy_s(tensor->data(), tensor->Size(), buf.data(), static_cast(count) * sizeof(T)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return RET_ERROR; - } - tensor->set_shape(new_shape); - return RET_OK; -} - -STATUS TransFilterFormat(const api::TensorPtr &tensor, mindspore::Format src_format, mindspore::Format dst_format) { - if (tensor == nullptr) { - MS_LOG(ERROR) << "tensor is nullptr."; - return RET_ERROR; - } - std::unordered_map> - trans_func = {{kNumberTypeFloat32, DoTransposeData}, - {kNumberTypeUInt8, DoTransposeData}, - {kNumberTypeInt8, DoTransposeData}, - {kNumberTypeFloat16, DoTransposeData}}; - auto data_type = tensor->data_type(); - auto iter = trans_func.find(data_type); - if (iter == trans_func.end()) { - MS_LOG(ERROR) << "Unsupported data_type: " << data_type; - return RET_ERROR; - } - return iter->second(tensor, src_format, dst_format); -} -int GetNext(int idx, int row, int col) { // compute after transpose the position that current element will move to - if (col == 0) { - return -1; - } - return (idx % col) * row + - idx / col; // (idx / col, idx % col) -> (idx % col, idx / col) -> (idx % col) * row + idx / col -} -void TransposeMatrix(float *matrix, int row, int col) { - for (int i = 0; i < row * col; i++) { - int next = GetNext(i, row, col); - while (next > i) { - next = GetNext(next, row, col); - } - if (next == i) { // otherwise, current element has been moved. - MoveData(matrix, i, row, col); - } - } -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.h b/mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.h deleted file mode 100644 index ac0e9562..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/data_transpose_utils.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 MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_DATA_TRANSPOSE_UTILS_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_DATA_TRANSPOSE_UTILS_H_ - -#include -#include "mindapi/base/format.h" -#include "mindapi/ir/tensor.h" -#include "mindapi/base/logging.h" -#include "include/errorcode.h" -#include "common/op_enum.h" -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_NO_CHANGE; -using mindspore::lite::RET_OK; -using mindspore::lite::STATUS; -namespace mindspore { -namespace dpico { -inline const std::vector kNH2NC = {0, 3, 1, 2}; -inline const std::vector kNC2NH = {0, 2, 3, 1}; -enum FormatTransNodeType { kNCHW2NHWC, kNHWC2NCHW, kNONE }; -struct TransTypePair { - FormatTransNodeType pre_; - FormatTransNodeType post_; - TransTypePair() : pre_(kNONE), post_(kNONE) {} -}; -template -STATUS NHWC2NCHW(T *src_data, T *dst_data, std::vector shape) { - if (shape.size() != kDims4) { - MS_LOG(ERROR) << "The dim should be 4."; - return RET_ERROR; - } - int32_t batch = shape.at(0); - int32_t plane = shape.at(kAxis1) * shape.at(kAxis2); - int32_t channel = shape.at(kAxis3); - for (int32_t b = 0; b < batch; b++) { - for (int32_t p = 0; p < plane; p++) { - for (int32_t c = 0; c < channel; c++) { - int32_t src_idx = b * plane * channel + p * channel + c; - int32_t dst_idx = b * channel * plane + c * plane + p; - dst_data[dst_idx] = src_data[src_idx]; - } - } - } - return RET_OK; -} - -template -STATUS NCHW2NHWC(T *src_data, T *dst_data, std::vector shape) { - if (shape.size() != kDims4) { - MS_LOG(ERROR) << "The dim should be 4."; - return RET_ERROR; - } - int32_t batch = shape.at(0); - int32_t channel = shape.at(1); - int32_t plane = shape.at(kAxis2) * shape.at(kAxis3); - for (int32_t b = 0; b < batch; b++) { - for (int32_t c = 0; c < channel; c++) { - for (int32_t p = 0; p < plane; p++) { - int32_t src_idx = b * channel * plane + c * plane + p; - int32_t dst_idx = b * plane * channel + p * channel + c; - dst_data[dst_idx] = src_data[src_idx]; - } - } - } - return RET_OK; -} - -STATUS TransFilterFormat(const mindspore::api::TensorPtr &tensor, mindspore::Format src_format, - mindspore::Format dst_format); - -void TransposeMatrix(float *matrix, int row, int col); -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_DATA_TRANSPOSE_UTILS_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.cc b/mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.cc deleted file mode 100644 index 806285d3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.cc +++ /dev/null @@ -1,109 +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 "common/fetch_content.h" -#include -#include -#include "common/anf_util.h" -#include "common/check_base.h" -#include "include/securec.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr size_t kTensorListMinSize = 3 * sizeof(int32_t); -} // namespace - -int FetchFromDefaultParam(const api::ParameterPtr ¶m_node, DataInfo *data_info) { - MS_ASSERT(param_node != nullptr && data_info != nullptr); - ShapeVector shape_vector; - TypeId data_type; - auto status = GetDataTypeAndShape(param_node, &data_type, &shape_vector); - if (status != RET_OK) { - MS_LOG(ERROR) << "get data type and shape from param node failed."; - return RET_ERROR; - } - data_info->data_type_ = data_type; - auto tensor_info = param_node->default_param()->cast(); - size_t offset = 0; - if (!shape_vector.empty() && data_type == kObjectTypeString) { - status = GetShapeVectorFromStringTensor(tensor_info, &shape_vector, &offset); - if (status != RET_OK) { - MS_LOG(ERROR) << "get shape vector from string tensor failed."; - return RET_ERROR; - } - } - std::vector dims(shape_vector.begin(), shape_vector.end()); - data_info->shape_ = dims; - if (tensor_info != nullptr && tensor_info->Size() != 0) { - if (data_type != kObjectTypeTensorType || tensor_info->Size() >= kTensorListMinSize) { - if (tensor_info->Size() < offset) { - MS_LOG(ERROR) << "tensor_info elem size should be greater than offset."; - return RET_ERROR; - } - data_info->data_.resize(tensor_info->Size() - offset); - if (EOK != memcpy_s(data_info->data_.data(), data_info->data_.size(), - static_cast(tensor_info->data()) + offset, tensor_info->Size() - offset)) { - MS_LOG(ERROR) << "memcpy_s failed."; - return RET_ERROR; - } - } - } - - return RET_OK; -} - -int FetchDataFromParameterNode(const api::CNodePtr &cnode, size_t index, DataInfo *data_info) { - MS_ASSERT(cnode != nullptr && data_info != nullptr); - if (index >= cnode->size()) { - MS_LOG(ERROR) << "input index: " << index << " is greater than cnode inputs size " << cnode->size(); - return RET_ERROR; - } - auto param_node = cnode->input(index)->cast(); - if (param_node == nullptr) { - MS_LOG(ERROR) << "input node is not parameter node."; - return RET_ERROR; - } - - if (FetchFromDefaultParam(param_node, data_info) != RET_OK) { - MS_LOG(ERROR) << "fetch information from default param failed."; - return RET_ERROR; - } - - return RET_OK; -} - -int GetDataSizeFromTensor(DataInfo *data_info, int *data_size) { - if (data_info == nullptr) { - MS_LOG(ERROR) << "data info is nullptr. "; - return RET_ERROR; - } - if (data_size == nullptr) { - MS_LOG(ERROR) << "elem size is nullptr"; - return RET_ERROR; - } - *data_size = 1; - for (size_t i = 0; i < data_info->shape_.size(); i++) { - if (INT_MUL_OVERFLOW(*data_size, data_info->shape_.at(i))) { - MS_LOG(ERROR) << "int mul overflow."; - return RET_ERROR; - } - *data_size *= data_info->shape_.at(i); - } - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.h b/mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.h deleted file mode 100644 index b1c3cba2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/fetch_content.h +++ /dev/null @@ -1,41 +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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FETCH_CONTENT_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FETCH_CONTENT_H_ - -#include -#include -#include "mindapi/ir/primitive.h" -#include "mindapi/ir/func_graph.h" - -namespace mindspore { -namespace dpico { -struct DataInfo { - int data_type_; - std::vector shape_; - std::vector data_; - DataInfo() : data_type_(0) {} -}; - -int FetchFromDefaultParam(const api::ParameterPtr ¶m_node, DataInfo *data_info); - -int FetchDataFromParameterNode(const api::CNodePtr &cnode, size_t index, DataInfo *data_info); - -int GetDataSizeFromTensor(DataInfo *data_info, int *data_size); -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FETCH_CONTENT_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/file_util.cc b/mindspore-lite/tools/converter/adapter/dpico/common/file_util.cc deleted file mode 100644 index 67e73354..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/file_util.cc +++ /dev/null @@ -1,174 +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 "common/file_util.h" -#include -#include -#include -#include -#include -#include -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace dpico { -namespace { -#ifdef _WIN32 -constexpr size_t kMaxPathLen = 1024; -#endif -} // namespace -int CreateDir(std::string *file_path) { // support multi-level directory generated. - if (file_path == nullptr) { - MS_LOG(ERROR) << "file_path is nullptr."; - return RET_ERROR; - } - if (file_path->empty()) { - MS_LOG(ERROR) << "input file path is empty."; - return RET_ERROR; - } else if (file_path->size() >= PATH_MAX) { - MS_LOG(ERROR) << "input file path is too long"; - return RET_ERROR; - } - - if (file_path->back() != '\\' && file_path->back() != '/') { -#ifdef _WIN32 - *file_path += "\\"; -#else - *file_path += "/"; -#endif - } - for (size_t i = 0; i < file_path->size(); i++) { - if (file_path->at(i) == '\\' || file_path->at(i) == '/') { - if (AccessFile(file_path->substr(0, i + 1), F_OK) != 0) { - int ret = Mkdir(file_path->substr(0, i + 1)); - if (ret != RET_OK) { - MS_LOG(ERROR) << "mkdir failed. " << file_path->substr(0, i + 1); - return RET_ERROR; - } - } - } - } - - return RET_OK; -} - -std::string RealPath(const char *path) { - if (path == nullptr) { - MS_LOG(ERROR) << "path is nullptr"; - return ""; - } - if ((std::strlen(path)) >= PATH_MAX) { - MS_LOG(ERROR) << "path is too long"; - return ""; - } - auto resolved_path = std::make_unique(PATH_MAX); - if (resolved_path == nullptr) { - MS_LOG(ERROR) << "new resolved_path failed"; - return ""; - } -#ifdef _WIN32 - char *real_path = _fullpath(resolved_path.get(), path, kMaxPathLen); -#else - char *real_path = realpath(path, resolved_path.get()); -#endif - if (real_path == nullptr || strlen(real_path) == 0) { - MS_LOG(ERROR) << "file path is not valid : " << path; - return ""; - } - std::string res = resolved_path.get(); - return res; -} - -int ReadFileToIfstream(const std::string &file_path, std::ifstream *ifstream) { - if (file_path.empty()) { - MS_LOG(ERROR) << "file path is empty."; - return RET_ERROR; - } - auto real_file_path = RealPath(file_path.c_str()); - if (real_file_path.empty()) { - MS_LOG(ERROR) << "get real path failed."; - return RET_ERROR; - } - ifstream->open(real_file_path, std::ios::in); - if (!ifstream->good()) { - MS_LOG(ERROR) << "file: " << real_file_path << " is not exist."; - return RET_ERROR; - } - if (!ifstream->is_open()) { - MS_LOG(ERROR) << "file: " << real_file_path << " open failed."; - return RET_ERROR; - } - return RET_OK; -} - -int RemoveDir(const std::string &path) { - if (path.empty()) { - MS_LOG(ERROR) << "input path is empty."; - return RET_ERROR; - } - std::string str_path = path; -#ifdef _WIN32 - struct _finddata_t fb; - if (str_path.at(str_path.length() - 1) != '\\') { - (void)str_path.append("\\"); - } - std::string find_path = str_path + "*"; - intptr_t handle = _findfirst(find_path.c_str(), &fb); - if (handle != -1L) { - std::string tmp_path; - do { - if (strcmp(fb.name, "..") != 0 && strcmp(fb.name, ".") != 0) { - tmp_path.clear(); - tmp_path = str_path + std::string(fb.name); - if (fb.attrib == _A_SUBDIR) { - (void)RemoveDir(tmp_path.c_str()); - } else { - remove(tmp_path.c_str()); - } - } - } while (_findnext(handle, &fb) == 0); - _findclose(handle); - } - return RMDIR(str_path.c_str()) == 0 ? RET_OK : RET_ERROR; - -#else - if (str_path.at(str_path.length() - 1) != '/') { - (void)str_path.append("/"); - } - DIR *d = opendir(str_path.c_str()); - if (d != nullptr) { - struct dirent *dt = nullptr; - dt = readdir(d); - while (dt != nullptr) { - if (std::strcmp(dt->d_name, "..") != 0 && std::strcmp(dt->d_name, ".") != 0) { - struct stat st {}; - auto file_name = str_path + std::string(dt->d_name); - (void)stat(file_name.c_str(), &st); - if (S_ISDIR(st.st_mode)) { - (void)RemoveDir(file_name); - } else { - (void)remove(file_name.c_str()); - } - } - dt = readdir(d); - } - (void)closedir(d); - } - return rmdir(str_path.c_str()) == 0 ? RET_OK : RET_ERROR; -#endif -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/file_util.h b/mindspore-lite/tools/converter/adapter/dpico/common/file_util.h deleted file mode 100644 index e1eea461..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/file_util.h +++ /dev/null @@ -1,81 +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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FILE_UTIL_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FILE_UTIL_H_ - -#ifdef _WIN32 -#include -#include -#else -#include -#include -#include -#include -#endif -#include -#include -#include -#include -#include "include/errorcode.h" -#include "mindapi/base/logging.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::lite::STATUS; - -namespace mindspore { -namespace dpico { -constexpr size_t kMaximumNumOfFolders = 1000; - -inline int AccessFile(const std::string &file_path, int access_mode) { -#ifdef _WIN32 - return _access(file_path.c_str(), access_mode); -#else - return access(file_path.c_str(), access_mode); -#endif -} - -inline int Mkdir(const std::string &file_path) { -#ifdef _WIN32 - return _mkdir(file_path.c_str()); -#else - return mkdir(file_path.c_str(), S_IRWXU); -#endif -} - -inline int WriteToBin(const std::string &file_path, void *data, const size_t size) { - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr."; - return RET_ERROR; - } - std::ofstream out_file; - out_file.open(file_path.c_str(), std::ios::binary); - if (!out_file.good() || !out_file.is_open()) { - return RET_ERROR; - } - (void)out_file.write(reinterpret_cast(data), size); - out_file.close(); - return RET_OK; -} - -std::string RealPath(const char *path); -int CreateDir(std::string *file_path); -int ReadFileToIfstream(const std::string &file_path, std::ifstream *ifstream); -int RemoveDir(const std::string &path); -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FILE_UTIL_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/float16.h b/mindspore-lite/tools/converter/adapter/dpico/common/float16.h deleted file mode 100644 index f7b970ff..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/float16.h +++ /dev/null @@ -1,311 +0,0 @@ -/** - * Copyright 2020-2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FLOAT16_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FLOAT16_H_ - -#if defined(ENABLE_ARM32) || defined(ENABLE_ARM64) -// Built for lite and ARM -#include - -using float16 = float16_t; - -#else -#include -#include -#include -#include -#include -#include - -// Implement Float16 for mindspore, inspired by Eigen::half. -namespace mindspore { -class Float16 { - public: - static constexpr uint16_t value_mask = 0x7fff; - static constexpr uint16_t nan_value = 0x7e00; - static constexpr uint16_t inf_value = 0x7c00; - static constexpr uint16_t true_value = 0x3c00; - - union Union32 { - uint32_t u; - float f; - }; - - Float16() = default; - ~Float16() = default; - - Float16(const Float16 &other) noexcept = default; - Float16(Float16 &&other) noexcept = default; - - Float16 &operator=(const Float16 &other) noexcept = default; - Float16 &operator=(Float16 &&other) noexcept = default; - - static Float16 FromRaw(uint16_t v) { - Float16 f; - f.value_ = v; - return f; - } - - explicit Float16(float f) : value_(FromFloat32(f)) {} - explicit Float16(bool b) : value_(b ? true_value : 0) {} - template - explicit Float16(const T &v) : value_(FromFloat32(static_cast(v))) {} - - uint16_t int_value() const { return value_; } - - explicit operator bool() const { return (value_ & value_mask) != 0; } - explicit operator float() const { return ToFloat32(*this); } - explicit operator double() const { return static_cast(ToFloat32(*this)); } - explicit operator int8_t() const { return static_cast(ToFloat32(*this)); } - explicit operator uint8_t() const { return static_cast(ToFloat32(*this)); } - explicit operator int16_t() const { return static_cast(ToFloat32(*this)); } - explicit operator uint16_t() const { return static_cast(ToFloat32(*this)); } - explicit operator int32_t() const { return static_cast(ToFloat32(*this)); } - explicit operator uint32_t() const { return static_cast(ToFloat32(*this)); } - explicit operator int64_t() const { return static_cast(ToFloat32(*this)); } - explicit operator uint64_t() const { return static_cast(ToFloat32(*this)); } - - Float16 &operator+=(const Float16 &b) { - value_ = FromFloat32(ToFloat32(*this) + ToFloat32(b)); - return *this; - } - - Float16 &operator-=(const Float16 &b) { - value_ = FromFloat32(ToFloat32(*this) - ToFloat32(b)); - return *this; - } - - Float16 &operator*=(const Float16 &b) { - value_ = FromFloat32(ToFloat32(*this) * ToFloat32(b)); - return *this; - } - - Float16 &operator/=(const Float16 &b) { - value_ = FromFloat32(ToFloat32(*this) / ToFloat32(b)); - return *this; - } - - static float ToFloat32(const Float16 &f16) { - constexpr Union32 magic = {.u = 113 << 23}; - constexpr uint32_t exponent_adjust = ((127 - 15) << 23); - constexpr uint32_t inf_extra_exp_adjust = ((128 - 16) << 23); - constexpr uint32_t zero_extra_exp_adjust = (1 << 23); - constexpr uint32_t sign_mask = 0x8000; - constexpr unsigned int shifted_exp = (0x7c00 << 13); // Exponent mask after shift. - constexpr unsigned int exponent_bits = 13; - constexpr unsigned int sign_bit_shift = 16; - // Exponent/mantissa bits. - Union32 f32; - f32.u = (static_cast(f16.value_ & value_mask) << exponent_bits); - // Just the exponent. - unsigned int exp = (shifted_exp & f32.u); - f32.u += exponent_adjust; - // Handle exponent special cases. - if (exp == shifted_exp) { - // Inf/NaN, extra exp adjust. - f32.u += inf_extra_exp_adjust; - } else if (exp == 0) { - // Zero/Denormal, extra exp adjust and renormalize. - f32.u += zero_extra_exp_adjust; - f32.f -= magic.f; - } - // Set sign bit. - f32.u |= ((f16.value_ & sign_mask) << sign_bit_shift); - return f32.f; - } - - private: - static uint16_t FromFloat32(float f32) { - constexpr uint32_t magic = {113 << 23}; - constexpr Union32 f32infty = {.u = 255 << 23}; - constexpr Union32 f16max = {.u = (127 + 16) << 23}; - constexpr Union32 denorm_magic = {.u = ((127 - 15) + (23 - 10) + 1) << 23}; - constexpr unsigned int exponent_bits = 13; - constexpr unsigned int sign_bit_shift = 16; - constexpr unsigned int sign_mask = 0x80000000u; - constexpr uint32_t rouding_bias_part1 = ((unsigned int)(15 - 127) << 23) + 0xfff; - - Union32 f; - f.f = f32; - unsigned int sign = f.u & sign_mask; - f.u ^= sign; - uint16_t result = 0; - - // NOTE all the integer compares in this function can be safely - // compiled into signed compares since all operands are below - // 0x80000000. Important if you want fast straight SSE2 code - // (since there's no unsigned PCMPGTD). - if (f.u >= f16max.u) { - // Result is Inf or NaN (all exponent bits set). - result = (f.u > f32infty.u) ? nan_value : inf_value; - } else if (f.u < magic) { - // (De)normalized number or zero; resulting FP16 is subnormal or zero. - // Use a magic value to align our 10 mantissa bits at the bottom of - // the float. as long as FP addition is round-to-nearest-even this - // just works. - f.f += denorm_magic.f; - // And one integer subtract of the bias later, we have our final float! - result = static_cast(f.u - denorm_magic.u); - } else { - // Resulting mantissa is odd. - unsigned int mant_odd = (f.u >> exponent_bits) & 1; - // Update exponent, rounding bias part 1; - f.u += rouding_bias_part1; - // Rounding bias part 2; - f.u += mant_odd; - // Take the bits! - result = static_cast(f.u >> exponent_bits); - } - // Set sign bit. - result |= static_cast(sign >> sign_bit_shift); - return result; - } - - uint16_t value_; -}; - -inline Float16 operator+(const Float16 &a, const Float16 &b) { - return Float16(static_cast(a) + static_cast(b)); -} - -inline Float16 operator*(const Float16 &a, const Float16 &b) { - return Float16(static_cast(a) * static_cast(b)); -} - -inline Float16 operator-(const Float16 &a, const Float16 &b) { - return Float16(static_cast(a) - static_cast(b)); -} - -inline Float16 operator/(const Float16 &a, const Float16 &b) { - return Float16(static_cast(a) / static_cast(b)); -} - -// Division by an size_t. Do it in full float precision to avoid -// accuracy issues in converting the denominator to float16. -inline Float16 operator/(const Float16 &a, size_t b) { return Float16(static_cast(a) / static_cast(b)); } - -inline Float16 operator-(const Float16 &a) { - constexpr uint16_t sign_mask = 0x8000; - return Float16::FromRaw(a.int_value() ^ sign_mask); -} - -inline bool operator==(const Float16 &a, const Float16 &b) { - return std::equal_to()(static_cast(a), static_cast(b)); -} - -inline bool operator!=(const Float16 &a, const Float16 &b) { - return std::not_equal_to()(static_cast(a), static_cast(b)); -} - -inline bool operator<(const Float16 &a, const Float16 &b) { return static_cast(a) < static_cast(b); } -inline bool operator<=(const Float16 &a, const Float16 &b) { return static_cast(a) <= static_cast(b); } -inline bool operator>(const Float16 &a, const Float16 &b) { return static_cast(a) > static_cast(b); } -inline bool operator>=(const Float16 &a, const Float16 &b) { return static_cast(a) >= static_cast(b); } - -inline std::ostream &operator<<(std::ostream &os, const Float16 &v) { return (os << static_cast(v)); } - -} // namespace mindspore - -using float16 = mindspore::Float16; - -namespace std { -template <> -struct hash { - std::size_t operator()(const float16 &f16) const noexcept { return static_cast(f16.int_value()); } -}; - -template <> -struct numeric_limits { - static constexpr bool is_specialized = true; - static constexpr bool is_signed = true; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr std::float_denorm_style has_denorm = std::denorm_present; - static constexpr bool has_denorm_loss = false; - static constexpr std::float_round_style round_style = std::round_to_nearest; - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - static constexpr int digits = 11; - static constexpr int digits10 = 3; - static constexpr int max_digits10 = 5; - static constexpr int radix = 2; - static constexpr int min_exponent = -13; - static constexpr int min_exponent10 = -4; - static constexpr int max_exponent = 16; - static constexpr int max_exponent10 = 4; - static constexpr bool traps = true; - static constexpr bool tinyness_before = false; - - static constexpr uint16_t raw_min = 0x400; - static constexpr uint16_t raw_max = 0x7bff; - static constexpr uint16_t raw_lowest = 0xfbff; - static constexpr uint16_t raw_epsilon = 0x0800; - static constexpr float round_error_value = 0.5; - - static float16(min)() noexcept { return float16::FromRaw(raw_min); } - static float16(max)() noexcept { return float16::FromRaw(raw_max); } - static float16 lowest() noexcept { return float16::FromRaw(raw_lowest); } - static float16 epsilon() noexcept { return float16::FromRaw(raw_epsilon); } - static float16 round_error() noexcept { return float16(round_error_value); } - static float16 infinity() noexcept { return float16::FromRaw(float16::inf_value); } - static float16 quiet_NaN() noexcept { return float16::FromRaw(float16::nan_value); } - static float16 signaling_NaN() noexcept { return float16::FromRaw(float16::nan_value); } - static float16 denorm_min() noexcept { return float16::FromRaw(1); } -}; - -// If std::numeric_limits is specialized, should also specialize -// std::numeric_limits, std::numeric_limits, and -// std::numeric_limits -// https://stackoverflow.com/a/16519653/ -template <> -struct numeric_limits : private numeric_limits {}; -template <> -struct numeric_limits : private numeric_limits {}; -template <> -struct numeric_limits : private numeric_limits {}; -} // namespace std - -// Implements standard math functions for float16. -inline bool(isinf)(const float16 &a) { return (a.int_value() & float16::value_mask) == float16::inf_value; } -inline bool(isnan)(const float16 &a) { return (a.int_value() & float16::value_mask) > float16::inf_value; } -inline bool(isfinite)(const float16 &a) { return !(isinf(a)) && !(isnan(a)); } -inline float16 abs(const float16 &a) { return float16::FromRaw(a.int_value() & float16::value_mask); } -inline float16 exp(const float16 &a) { return float16(::expf(static_cast(a))); } -inline float16 log(const float16 &a) { return float16(::logf(static_cast(a))); } -inline float16 log1p(const float16 &a) { return float16(::log1pf(static_cast(a))); } -inline float16 log10(const float16 &a) { return float16(::log10f(static_cast(a))); } -inline float16 sqrt(const float16 &a) { return float16(::sqrtf(static_cast(a))); } -inline float16 sin(const float16 &a) { return float16(::sinf(static_cast(a))); } -inline float16 cos(const float16 &a) { return float16(::cosf(static_cast(a))); } -inline float16 tan(const float16 &a) { return float16(::tanf(static_cast(a))); } -inline float16 tanh(const float16 &a) { return float16(::tanhf(static_cast(a))); } -inline float16 floor(const float16 &a) { return float16(::floorf(static_cast(a))); } -inline float16 ceil(const float16 &a) { return float16(::ceilf(static_cast(a))); } -inline float16(min)(const float16 &a, const float16 &b) { return b < a ? b : a; } -inline float16(max)(const float16 &a, const float16 &b) { return a < b ? b : a; } -inline float16 pow(const float16 &a, const float16 &b) { - return float16(::powf(static_cast(a), static_cast(b))); -} - -#endif // ENABLE_ARM32 || ENABLE_ARM64 - -inline float half_to_float(const float16 &h) { return static_cast(h); } - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FLOAT16_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/format_utils.cc b/mindspore-lite/tools/converter/adapter/dpico/common/format_utils.cc deleted file mode 100644 index 85acb304..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/format_utils.cc +++ /dev/null @@ -1,90 +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 "common/format_utils.h" -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "infer/tuple_get_item.h" -#include "infer/depend.h" -#include "infer/make_tuple.h" -#include "infer/return.h" -#include "infer/batch_to_space.h" -#include "infer/depth_to_space.h" -#include "infer/fused_batch_norm.h" -#include "infer/cxx_api/avg_pool_fusion.h" -#include "infer/cxx_api/conv2d_fusion.h" -#include "infer/cxx_api/conv2d_transpose_fusion.h" -#include "infer/cxx_api/max_pool_fusion.h" -#include "infer/cxx_api/prelu_fusion.h" -#include "infer/cxx_api/topk_fusion.h" -#include "infer/instance_norm.h" -#include "infer/lrn.h" -#include "infer/resize.h" -#include "infer/roi_pooling.h" -#include "infer/space_to_batch.h" -#include "infer/space_to_batch_nd.h" -#include "infer/space_to_depth.h" -#include "common/anf_util.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_a.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_b.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_c.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_d.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_f.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_i.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_l.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_m.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_p.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_r.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_s.h" -#include "mindspore/ops/op_def/auto_generate/gen_ops_name_t.h" - -namespace mindspore { -namespace dpico { -namespace { -const std::set kAssignedFormatOpSet = { - mindspore::ops::kNameAvgPoolFusion, mindspore::ops::kNameBatchNorm, - mindspore::ops::kNameBatchToSpace, mindspore::ops::kNameBiasAdd, - mindspore::ops::kNameConv2DFusion, mindspore::ops::kNameConv2dTransposeFusion, - mindspore::ops::kNameDepthToSpace, mindspore::ops::kNameFusedBatchNorm, - mindspore::ops::kNameInstanceNorm, mindspore::ops::kNameLRN, - mindspore::ops::kNameMaxPoolFusion, mindspore::ops::kNamePReLUFusion, - mindspore::ops::kNameResize, mindspore::ops::kNameROIPooling, - mindspore::ops::kNameSpaceToBatch, mindspore::ops::kNameSpaceToBatchND, - mindspore::ops::kNameSpaceToDepth, mindspore::ops::kNameTopKFusion}; -} // namespace - -const std::set &GetAssignedFormatOpSet() { return kAssignedFormatOpSet; } - -bool IsSpecialType(const api::CNodePtr &cnode) { - return CheckPrimitiveType(cnode, api::MakeShared()) || - CheckPrimitiveType(cnode, api::MakeShared()) || - CheckPrimitiveType(cnode, api::MakeShared()) || - CheckPrimitiveType(cnode, api::MakeShared()); -} - -std::string FormatEnumToString(mindspore::Format format) { - static std::vector names = { - "NCHW", "NHWC", "NHWC4", "HWKC", "HWCK", "KCHW", "CKHW", "KHWC", "CHWK", - "HW", "HW4", "NC", "NC4", "NC4HW4", "NUM_OF_FORMAT", "NCDHW", "NWC", "NCW", - }; - if (format < mindspore::NCHW || format > mindspore::NCW) { - return ""; - } - return names[static_cast(format)]; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/format_utils.h b/mindspore-lite/tools/converter/adapter/dpico/common/format_utils.h deleted file mode 100644 index 9cc91b3e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/format_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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FORMAT_UTILS_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FORMAT_UTILS_H_ - -#include -#include -#include -#include "include/api/format.h" -#include "common/anf_util.h" - -namespace mindspore { -namespace dpico { -const std::set &GetAssignedFormatOpSet(); -bool IsSpecialType(const api::CNodePtr &cnode); -std::string FormatEnumToString(mindspore::Format format); -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_FORMAT_UTILS_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.cc b/mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.cc deleted file mode 100644 index fac3072f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.cc +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Copyright 2022 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 "common/graph_output_name_keeper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/check_base.h" -#include "common/op_enum.h" -#include "infer/make_tuple.h" -#include "infer/depend.h" -#include "include/registry/converter_context.h" - -namespace mindspore { -namespace dpico { -GraphOutputNameKeeper *GraphOutputNameKeeper::GetInstance() { - static GraphOutputNameKeeper instance; - return &instance; -} - -int GraphOutputNameKeeper::SaveOriginalOutputs(const api::FuncGraphPtr &func_graph) { - MS_CHECK_TRUE_MSG(func_graph != nullptr, RET_ERROR, "func's input parameter is a nullptr."); - auto return_cnode = func_graph->get_return(); - MS_CHECK_TRUE_MSG(return_cnode != nullptr, RET_ERROR, "func_graph's return node is invalid."); - original_outputs_ = return_cnode->inputs(); - original_outputs_.erase(original_outputs_.begin()); - bool change{true}; - while (change) { - change = false; - std::vector outputs_tmp; - for (size_t j = 0; j < original_outputs_.size(); ++j) { - auto output_node = original_outputs_[j]; - MS_CHECK_TRUE_MSG(output_node != nullptr, RET_ERROR, "existing node is a nullptr."); - if (dpico::CheckPrimitiveType(output_node, api::MakeShared())) { - auto make_tuple_cnode = output_node->cast(); - MS_CHECK_TRUE_MSG(make_tuple_cnode != nullptr, RET_ERROR, "make tuple node is invalid."); - auto make_tuple_inputs = make_tuple_cnode->inputs(); - outputs_tmp.insert(outputs_tmp.end(), make_tuple_inputs.begin() + 1, make_tuple_inputs.end()); - change = true; - continue; - } - if (dpico::CheckPrimitiveType(output_node, api::MakeShared())) { - auto depend_cnode = output_node->cast(); - MS_CHECK_TRUE_MSG(depend_cnode != nullptr, RET_ERROR, "depend node is invalid."); - MS_CHECK_TRUE_MSG(depend_cnode->size() == kInputIndex3, RET_ERROR, "depend node's input size should be 3."); - outputs_tmp.push_back(depend_cnode->input(1)); - change = true; - continue; - } - outputs_tmp.push_back(output_node); - } - original_outputs_ = outputs_tmp; - } - - auto origin_outputs_name = converter::ConverterContext::GetGraphOutputTensorNames(); - for (auto &output_name : origin_outputs_name) { - const std::string top_name_suffix = "duplicate"; - const size_t max_loop = 1000; - for (size_t i = 0; i < max_loop; i++) { - std::string top_name_tmp = output_name + "_" + top_name_suffix + std::to_string(i); - auto attr = func_graph->get_attr(top_name_tmp); - if (attr != nullptr) { - auto op_name = api::GetValue(attr); - ori_output_info_[op_name] = output_name; - } else { - break; - } - } - } - return RET_OK; -} - -int GraphOutputNameKeeper::DetermineOmOpInputName(const api::AnfNodePtr &in_node, std::string *input_name) { - if (original_outputs_.empty()) { - return RET_OK; - } - MS_CHECK_TRUE_MSG(in_node != nullptr && input_name != nullptr, RET_ERROR, "func's input parameter is a nullptr."); - if (ori_output_info_.find(in_node->fullname_with_scope()) != ori_output_info_.end()) { - *input_name = ori_output_info_[in_node->fullname_with_scope()]; - return RET_OK; - } - auto iter = std::find(original_outputs_.begin(), original_outputs_.end(), in_node); - if (iter == original_outputs_.end()) { - return RET_OK; - } - auto index = iter - original_outputs_.begin(); - auto origin_outputs_name = converter::ConverterContext::GetGraphOutputTensorNames(); - if (origin_outputs_name.size() <= static_cast(index)) { - return RET_OK; - } - input_name->swap(origin_outputs_name[index]); - return RET_OK; -} - -int GraphOutputNameKeeper::DetermineOmOpOutputName(const api::AnfNodePtr &node, std::string *output_name, - bool is_subgraph_input) { - MS_CHECK_TRUE_MSG(node != nullptr && output_name != nullptr, RET_ERROR, "func's input parameter is a nullptr."); - MS_CHECK_TRUE_MSG(!original_outputs_.empty(), RET_ERROR, "has no outputs."); - if (ori_output_info_.find(node->fullname_with_scope()) != ori_output_info_.end()) { - *output_name = ori_output_info_[node->fullname_with_scope()]; - return RET_OK; - } - auto iter = std::find(original_outputs_.begin(), original_outputs_.end(), node); - if (iter == original_outputs_.end()) { - return RET_OK; - } - auto index = iter - original_outputs_.begin(); - auto origin_outputs_name = converter::ConverterContext::GetGraphOutputTensorNames(); - if (origin_outputs_name.size() <= static_cast(index)) { - return RET_OK; - } - if (!is_subgraph_input) { - MS_CHECK_TRUE_MSG(om_to_anf_mapper_.find(origin_outputs_name[index]) == om_to_anf_mapper_.end(), RET_ERROR, - "find the output has been existed."); - om_to_anf_mapper_.emplace(origin_outputs_name[index], *output_name); - } - output_name->swap(origin_outputs_name[index]); - return RET_OK; -} - -bool GraphOutputNameKeeper::CanKeepOutputNames(const std::vector &om_outputs) { - size_t has_find{0}; - for (const auto &output : om_outputs) { - if (om_to_anf_mapper_.find(output) != om_to_anf_mapper_.end()) { - ++has_find; - } - } - return has_find == om_to_anf_mapper_.size(); -} - -std::string GraphOutputNameKeeper::GetAnfOutputNameFromOm(const std::string &om_out_name) { - if (om_to_anf_mapper_.find(om_out_name) != om_to_anf_mapper_.end()) { - return om_to_anf_mapper_[om_out_name]; - } - return om_out_name; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.h b/mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.h deleted file mode 100755 index e36d4183..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/graph_output_name_keeper.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_DPICO_COMMON_GRAPH_OUTPUT_NAME_KEEPER_H -#define MINDSPORE_LITE_TOOLS_CONVERTER_DPICO_COMMON_GRAPH_OUTPUT_NAME_KEEPER_H - -#include -#include -#include -#include "mindapi/ir/func_graph.h" - -namespace mindspore { -namespace dpico { -class GraphOutputNameKeeper { - public: - static GraphOutputNameKeeper *GetInstance(); - int SaveOriginalOutputs(const api::FuncGraphPtr &func_graph); - void RecycleResource() { - original_outputs_.clear(); - om_to_anf_mapper_.clear(); - } - void ResetOutputNameMapper() { om_to_anf_mapper_.clear(); } - int DetermineOmOpInputName(const api::AnfNodePtr &in_node, std::string *input_name); - int DetermineOmOpOutputName(const api::AnfNodePtr &node, std::string *output_name, bool is_subgraph_input = false); - bool CanKeepOutputNames(const std::vector &om_outputs); - std::string GetAnfOutputNameFromOm(const std::string &om_out_name); - - private: - GraphOutputNameKeeper() = default; - ~GraphOutputNameKeeper() = default; - api::AnfNodePtrList original_outputs_; - std::map om_to_anf_mapper_; - std::map ori_output_info_; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_DPICO_COMMON_GRAPH_OUTPUT_NAME_KEEPER_H diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/infer_util.cc b/mindspore-lite/tools/converter/adapter/dpico/common/infer_util.cc deleted file mode 100644 index 71b1c07d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/infer_util.cc +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Copyright 2021-2022 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 "common/infer_util.h" -#include -#include -#include "mindapi/base/logging.h" -#include "include/errorcode.h" -#include "common/check_base.h" -#include "common/string_util.h" -#include "common/op_attr.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace dpico { -int CheckCustomInputOutput(const std::vector *inputs, - const std::vector *outputs, const schema::Primitive *primitive) { - if (inputs == nullptr) { - MS_LOG(ERROR) << "inputs is nullptr."; - return RET_ERROR; - } - if (outputs == nullptr) { - MS_LOG(ERROR) << "outputs is nullptr."; - return RET_ERROR; - } - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr."; - return RET_ERROR; - } - if (inputs->empty()) { - MS_LOG(ERROR) << "Inputs size 0."; - return RET_ERROR; - } - if (outputs->empty()) { - MS_LOG(ERROR) << "Outputs size 0."; - return RET_ERROR; - } - if (primitive->value_type() != schema::PrimitiveType_Custom) { - MS_LOG(ERROR) << "Primitive type is not PrimitiveType_Custom."; - return RET_ERROR; - } - return RET_OK; -} - -int CheckCustomParam(const schema::Custom *param, const std::string ¶m_name) { - if (param == nullptr) { - MS_LOG(ERROR) << "param is nullptr"; - return RET_ERROR; - } - if (param->type() == nullptr) { - MS_LOG(ERROR) << "param->type() is nullptr"; - return RET_ERROR; - } - if (param->type()->str() != param_name) { - MS_LOG(ERROR) << "current custom node should be " << param_name << ", but in fact it's " << param->type()->str(); - return RET_ERROR; - } - return RET_OK; -} - -int GetOmNetType(const schema::Primitive *primitive, OmNetType *om_net_type) { - MS_CHECK_TRUE_MSG(primitive != nullptr && om_net_type != nullptr, RET_ERROR, "input params contain nullptr."); - auto op = primitive->value_as_Custom(); - MS_CHECK_TRUE_MSG(op != nullptr, RET_ERROR, "custom op is nullptr."); - auto attrs = op->attr(); - MS_CHECK_TRUE_MSG(attrs != nullptr && attrs->size() >= 1, RET_ERROR, "custom op attr is invalid."); - std::string om_net_type_str; - for (size_t i = 0; i < attrs->size(); i++) { - auto attr = attrs->Get(i); - MS_CHECK_TRUE_MSG(attr != nullptr && attr->name() != nullptr, RET_ERROR, "invalid attr."); - if (attr->name()->str() != kNetType) { - continue; - } - auto data_info = attr->data(); - MS_CHECK_TRUE_MSG(data_info != nullptr, RET_ERROR, "attr data is nullptr"); - int data_size = static_cast(data_info->size()); - for (int j = 0; j < data_size; j++) { - om_net_type_str.push_back(static_cast(data_info->Get(j))); - } - break; - } - if (om_net_type_str.empty()) { - *om_net_type = OmNetType::kCnn; - return RET_OK; - } - if (!IsValidUnsignedNum(om_net_type_str)) { - MS_LOG(ERROR) << "net_type attr data is invalid num."; - return RET_ERROR; - } - int om_net_type_val = stoi(om_net_type_str); - if (om_net_type_val < static_cast(OmNetType::kCnn) || - om_net_type_val > static_cast(OmNetType::kRecurrent)) { - MS_LOG(ERROR) << "net_type val is invalid. " << om_net_type_val; - return RET_ERROR; - } - *om_net_type = static_cast(om_net_type_val); - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/infer_util.h b/mindspore-lite/tools/converter/adapter/dpico/common/infer_util.h deleted file mode 100644 index a0629949..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/infer_util.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2021-2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_INFER_UTIL_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_INFER_UTIL_H_ - -#include -#include -#include "include/api/types.h" -#include "schema/model_generated.h" -#include "src/graph_split_info.h" - -namespace mindspore { -namespace dpico { -int CheckCustomInputOutput(const std::vector *inputs, - const std::vector *outputs, const schema::Primitive *primitive); -int CheckCustomParam(const schema::Custom *param, const std::string ¶m_name); -int GetOmNetType(const schema::Primitive *primitive, OmNetType *om_net_type); -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_INFER_UTIL_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/op_attr.h b/mindspore-lite/tools/converter/adapter/dpico/common/op_attr.h deleted file mode 100644 index 5fc55c9f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/op_attr.h +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright 2021-2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_OP_ATTR_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_OP_ATTR_H_ - -namespace mindspore { -namespace dpico { -constexpr auto kAcrossSpatial = "across_spatial"; -constexpr auto kAcrossChannels = "across_channels"; -constexpr auto kActivateAlpha = "activate_alpha"; -constexpr auto kActivateBeta = "activate_beta"; -constexpr auto kActivateType = "activate_type"; -constexpr auto kAfClip = "af_clip"; -constexpr auto kBiasTerm = "bias_term"; -constexpr auto kBilinear = "bilinear"; -constexpr auto kBlockHeight = "block_height"; -constexpr auto kBlockWidth = "block_width"; -constexpr auto kChannelShared = "channel_shared"; -constexpr auto kClip = "clip"; -constexpr auto kCoeffs = "coeffs"; -constexpr auto kCustomName = "custom_"; -constexpr auto kCustomParamSize = "custom_param_size"; -constexpr auto kDetectionBackgroundLabelId = "detection_background_label_id"; -constexpr auto kDetectionBiasVec = "detection_bias_vec"; -constexpr auto kDetectionCalcMode = "detection_calc_mode"; -constexpr auto kDetectionClipBbox = "detection_clip_bbox"; -constexpr auto kDetectionCodeType = "detection_code_type"; -constexpr auto kDetectionMultiClassSorting = "detection_multi_class_sorting"; -constexpr auto kDetectionOutputParam = "detection_output_param"; -constexpr auto kDetectionOutputParamSize = "detection_output_param_size"; -constexpr auto kDetectionProposalParamType = "detection_proposal_param_type"; -constexpr auto kDetectionReportFlag = "detection_report_flag"; -constexpr auto kDetectionShareLocation = "detection_share_location"; -constexpr auto kDetectionShareVariance = "detection_share_variance"; -constexpr auto kDetectionTop = "detection_top"; -constexpr auto kDetectionTopK = "detection_top_k"; -constexpr auto kDetectionVarianceVec = "detection_variance_vec"; -constexpr auto kDecBBoxParam = "decbbox_param"; -constexpr auto kDim1 = "dim_1"; -constexpr auto kDim2 = "dim_2"; -constexpr auto kDim3 = "dim_3"; -constexpr auto kDirection = "direction"; -constexpr auto kEndAxis = "end_axis"; -constexpr auto kExposeHidden = "expose_hidden"; -constexpr auto kExtendedOpType = "extended_op_type"; -constexpr auto kFmod = "fmod"; -constexpr auto kGraphName = "graph_name"; -constexpr auto kGroupSize = "group_size"; -constexpr auto kGruWeightOrderZrhFlag = "gru_weight_order_zrh_flag"; -constexpr auto kHasOutputGateFlag = "has_output_gate_flag"; -constexpr auto kHasSplitBiasFlag = "has_split_bias_flag"; -constexpr auto kHasSplitHWeightFlag = "has_split_h_weight_flag"; -constexpr auto kHiddenSize = "hidden_size"; -constexpr auto kInferDone = "infer_done"; -constexpr auto kInitialCOnlineFlag = "initial_c_online_flag"; -constexpr auto kInitialHOnlineFlag = "initial_h_online_flag"; -constexpr auto kInputsShape = "inputs_shape"; -constexpr auto kInterpolationMode = "interpolation_mode"; -constexpr auto kIsMainGraph = "is_main_graph"; -constexpr auto kIsMapperSupported = "is_mapper_supported"; -constexpr auto kKeepDirectionDimFlag = "keep_direction_dim_flag"; -constexpr auto kKernelShape = "kernel_shape"; -constexpr auto kLrnK = "lrn_k"; -constexpr auto kLstmWeightOrderIofcFlag = "lstm_weight_order_iofc_flag"; -constexpr auto kMultiples = "multiples"; -constexpr auto kNearest = "nearest"; -constexpr auto kNegativeSlope = "negative_slope"; -constexpr auto kNetType = "net_type"; -constexpr auto kNormalizeVariance = "normalize_variance"; -constexpr auto kNumAnchors = "num_anchors"; -constexpr auto kNumAxes = "num_axes"; -constexpr auto kNumBboxesPerGrid = "num_bboxes_per_grid"; -constexpr auto kNumClasses = "num_classes"; -constexpr auto kNumCoords = "num_coords"; -constexpr auto kNumGridsWidth = "num_grid_width"; -constexpr auto kNumGridsHeight = "num_grid_height"; -constexpr auto kNumOutput = "num_output"; -constexpr auto kOnnxModeOutFlag = "onnx_model_out_flag"; -constexpr auto kOperatorType = "operator_type"; -constexpr auto kOutputChannel = "output_channel"; -constexpr auto kOutputDim = "output_dim"; -constexpr auto kOutputHeight = "output_height"; -constexpr auto kOutputWidth = "output_width"; -constexpr auto kOutputsNames = "outputs_names"; -constexpr auto kOutputsShape = "outputs_shape"; -constexpr auto kOutputsFormat = "outputs_format"; -constexpr auto kLastDimStride = "internal_stride"; -constexpr auto kOutputLastFrameFlag = "output_last_frame_flag"; -constexpr auto kPadBeg = "pad_beg"; -constexpr auto kPadEnd = "pad_end"; -constexpr auto kPads = "pads"; -constexpr auto kPeepHoleFlag = "peep_hole_flag"; -constexpr auto kPerm = "perm"; -constexpr auto kPoolMethod = "pool_method"; -constexpr auto kPyramidHeight = "pyramid_height"; -constexpr auto kRecurrentDirection = "recurrent_direction"; -constexpr auto kSamplingRatio = "sampling_ratio"; -constexpr auto kSelectLastIndex = "select_last_index"; -constexpr auto kSequenceLensOnlineFlag = "sequence_lens_online_flag"; -constexpr auto kShrinkFactor = "shrink_factor"; -constexpr auto kSlicePointBegin = "slice_point_begin"; -constexpr auto kSlicePointEnd = "slice_point_end"; -constexpr auto kSpatialScale = "spatial_scale"; -constexpr auto kSqrtA = "sqrt_a"; -constexpr auto kStartAxis = "start_axis"; -constexpr auto kThreshold = "threshold"; -constexpr auto kUpsampleH = "upsample_h"; -constexpr auto kUpsampleW = "upsample_w"; -constexpr auto kUseDefaultInitialCFlag = "use_default_initial_c_flag"; -constexpr auto kUseDefaultInitialHFlag = "use_default_initial_h_flag"; -constexpr auto kUseGlobalStats = "use_global_stats"; -constexpr auto kZoomFactor = "zoom_factor"; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_OP_ATTR_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/op_enum.h b/mindspore-lite/tools/converter/adapter/dpico/common/op_enum.h deleted file mode 100644 index 4d4e9df4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/op_enum.h +++ /dev/null @@ -1,50 +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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_OP_ENUM_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_OP_ENUM_H_ - -namespace mindspore { -namespace dpico { -constexpr size_t kDims1 = 1; -constexpr size_t kDims2 = 2; -constexpr size_t kDims3 = 3; -constexpr size_t kDims4 = 4; -constexpr size_t kDims5 = 5; -constexpr size_t kDims6 = 6; -constexpr size_t kDims7 = 7; -constexpr size_t kDims8 = 8; -constexpr size_t kAxis1 = 1; -constexpr size_t kAxis2 = 2; -constexpr size_t kAxis3 = 3; -constexpr size_t kInputIndex1 = 1; -constexpr size_t kInputIndex2 = 2; -constexpr size_t kInputIndex3 = 3; -constexpr size_t kInputIndex4 = 4; -constexpr size_t kInputIndex5 = 5; -constexpr size_t kInputSize2 = 2; -constexpr int kMaxInputWOf4Dims = 4096; -constexpr int kMaxInputWOf2Dims = 16384; -constexpr int kMaxNumOutput = 32768; -constexpr int kMaxTopNum = 32; -constexpr int kMaxBottomNum = 32; -constexpr int kAxisLowerBound = -4; -constexpr int kAxisUpperBound = 3; -constexpr size_t kMaxLineCount = 9999; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_OP_ENUM_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/string_util.cc b/mindspore-lite/tools/converter/adapter/dpico/common/string_util.cc deleted file mode 100644 index 5d790f1d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/string_util.cc +++ /dev/null @@ -1,100 +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 "common/string_util.h" -#include -#include -#include -#include -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace dpico { -int EraseBlankSpace(std::string *input_string) { - if (input_string == nullptr) { - MS_LOG(ERROR) << "input string is nullptr"; - return RET_ERROR; - } - if (!input_string->empty()) { - std::string::size_type pos = 0; - pos = input_string->find(' ', pos); - while (pos != std::string::npos) { - (void)input_string->erase(pos, 1); - pos = input_string->find(' ', pos); - } - } - return RET_OK; -} - -int EraseHeadTailSpace(std::string *input_string) { - if (input_string == nullptr) { - MS_LOG(ERROR) << "input string is nullptr"; - return RET_ERROR; - } - if (!input_string->empty()) { - (void)input_string->erase(0, input_string->find_first_not_of(' ')); - (void)input_string->erase(input_string->find_last_not_of(' ') + 1); - } - return RET_OK; -} - -std::vector SplitString(const std::string &raw_str, char delimiter) { - if (raw_str.empty()) { - MS_LOG(ERROR) << "input string is empty."; - return {}; - } - std::vector res; - std::string::size_type last_pos = 0; - auto cur_pos = raw_str.find(delimiter); - while (cur_pos != std::string::npos) { - res.push_back(raw_str.substr(last_pos, cur_pos - last_pos)); - cur_pos++; - last_pos = cur_pos; - cur_pos = raw_str.find(delimiter, cur_pos); - } - if (last_pos < raw_str.size()) { - res.push_back(raw_str.substr(last_pos, raw_str.size() - last_pos + 1)); - } - return res; -} - -std::string RemoveSpecifiedChar(const std::string &origin_str, char specified_ch) { - std::string res = origin_str; - (void)res.erase(std::remove(res.begin(), res.end(), specified_ch), res.end()); - return res; -} - -std::string ReplaceSpecifiedChar(const std::string &origin_str, char origin_ch, char target_ch) { - std::string res = origin_str; - std::replace(res.begin(), res.end(), origin_ch, target_ch); - return res; -} - -bool IsValidUnsignedNum(const std::string &num_str) { - return !num_str.empty() && std::all_of(num_str.begin(), num_str.end(), ::isdigit); -} - -bool IsValidDoubleNum(const std::string &num_str) { - if (num_str.empty()) { - return false; - } - std::istringstream iss(num_str); - double d; - iss >> std::noskipws >> d; - return iss.eof() && !iss.fail(); -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/common/string_util.h b/mindspore-lite/tools/converter/adapter/dpico/common/string_util.h deleted file mode 100644 index 89386a54..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/common/string_util.h +++ /dev/null @@ -1,41 +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_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_STRING_UTIL_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_STRING_UTIL_H_ - -#include -#include -#include -#include -#include "include/errorcode.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::lite::STATUS; - -namespace mindspore { -namespace dpico { -int EraseBlankSpace(std::string *input_string); -int EraseHeadTailSpace(std::string *input_string); -std::vector SplitString(const std::string &raw_str, char delimiter); -std::string RemoveSpecifiedChar(const std::string &origin_str, char specified_ch); -std::string ReplaceSpecifiedChar(const std::string &origin_str, char origin_ch, char target_ch); -bool IsValidUnsignedNum(const std::string &num_str); -bool IsValidDoubleNum(const std::string &num_str); -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_COMMON_STRING_UTIL_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.cc deleted file mode 100644 index 72acfc01..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.cc +++ /dev/null @@ -1,86 +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 "infer/dpico_common_infer.h" -#include -#include -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoCommonInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoCommonInterface::Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (param == nullptr) { - MS_LOG(ERROR) << "param is nullptr"; - return kLiteError; - } - if (param->type() == nullptr) { - MS_LOG(ERROR) << "param type is nullptr"; - return kLiteError; - } - - const auto &input = (*inputs)[0]; - auto &output = (*outputs)[0]; - output.SetShape(input.Shape()); - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Normalize, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Threshold, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, X_LOG_Y, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, X_DIV_Y, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Bnll, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, ShuffleChannel, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Mvn, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Nop, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Bias, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Eltwise, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Hardmax, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Mod, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Shrink, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, BitShift, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Acos, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Acosh, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Asinh, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Atanh, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Cosh, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Sinh, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, HardSigmoid, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Softsign, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Xor, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Mish, DpicoCommonInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Custom, DpicoCommonInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.h deleted file mode 100644 index c79734a5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_common_infer.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_COMMON_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_COMMON_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoCommonInterface : public KernelInterface { - public: - DpicoCommonInterface() {} - - ~DpicoCommonInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_COMMON_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.cc deleted file mode 100644 index cdabbaa9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.cc +++ /dev/null @@ -1,245 +0,0 @@ -/** - * Copyright 2021-2022 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 "infer/dpico_custom_infer.h" -#include -#include -#include -#include -#include "common/string_util.h" -#include "common/op_attr.h" -#include "common/infer_util.h" -#include "src/common/log_adapter.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::CustomInterface; -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::schema::PrimitiveType_Custom; - -namespace mindspore { -namespace kernel { -namespace { -constexpr int kOmParameterNum = 1; -Status FetchAttrs(const schema::Primitive &primitive, std::map *attrs) { - if (attrs == nullptr) { - MS_LOG(ERROR) << "function input parameter is nullptr."; - return kLiteError; - } - auto param = primitive.value_as_Custom(); - if (dpico::CheckCustomParam(param, "DPICO") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param attr is nullptr."; - return kLiteError; - } - if (param->attr()->size() < 1) { - MS_LOG(ERROR) << "There are at least 1 attribute of Custom"; - return kLiteError; - } - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - auto output_info = param->attr()->Get(i)->data(); - if (output_info == nullptr) { - return kLiteError; - } - int buf_size = static_cast(output_info->size()); - std::string attr; - for (int j = 0; j < buf_size; j++) { - attr.push_back(static_cast(output_info->Get(j))); - } - auto attr_name = param->attr()->Get(i)->name()->str(); - (void)attrs->emplace(attr_name, attr); - } - return kSuccess; -} - -Status GetCustomShape(const std::map &attrs, const std::string &attr_name, size_t tensor_num, - std::vector> *shapes) { - if (shapes == nullptr) { - MS_LOG(ERROR) << "the function input parameter is nullptr."; - return kLiteError; - } - if (attrs.find(attr_name) == attrs.end()) { - MS_LOG(ERROR) << "custom node should have " << attr_name << " val."; - return kLiteError; - } - auto attr = attrs.at(attr_name); - if (attr.empty()) { - MS_LOG(ERROR) << "custom node should have " << attr_name << " val."; - return kLiteError; - } - auto split_shape_str = dpico::SplitString(attr, ','); - size_t index = 0; - for (size_t i = 0; i < split_shape_str.size(); i++) { - auto dim_size = std::stoul(split_shape_str.at(i)); - std::vector shape; - for (size_t j = i + 1; j < i + 1 + dim_size; j++) { - if (j >= split_shape_str.size()) { - MS_LOG(ERROR) << "split_shape_str val is invalid. "; - return kLiteError; - } - shape.push_back(std::stoul(split_shape_str.at(j))); - } - i += dim_size; - if (tensor_num < index) { - MS_LOG(ERROR) << "shape index " << index << " is greater than custom tensor_num " << tensor_num; - return kLiteError; - } - shapes->push_back(shape); - index++; - } - return kSuccess; -} - -Status SetOutputFormat(const std::map &attrs, std::vector *outputs) { - if (outputs == nullptr) { - MS_LOG(ERROR) << "the function input parameter is nullptr."; - return kLiteError; - } - if (attrs.find(dpico::kOutputsFormat) == attrs.end()) { - MS_LOG(ERROR) << "custom node should have " << dpico::kOutputsFormat << " val."; - return kLiteError; - } - auto output_format_str = attrs.at(dpico::kOutputsFormat); - auto output_format = dpico::SplitString(output_format_str, ','); - if (output_format.size() > outputs->size()) { - MS_LOG(ERROR) << "output format attr is invalid, the number of which is out of range."; - return kLiteError; - } - for (size_t i = 0; i < output_format.size(); ++i) { - if (!dpico::IsValidUnsignedNum(output_format[i])) { - MS_LOG(ERROR) << "output format must be an unsigned int"; - return kLiteError; - } - auto format = std::stoi(output_format[i]); - if (format != static_cast(NHWC) && format != static_cast(NCHW)) { - MS_LOG(ERROR) << "output format is invalid, which should be NHWC or NCHW."; - return kLiteError; - } - outputs->at(i).SetFormat(static_cast(format)); - } - return kSuccess; -} - -bool InferDone(const std::vector &tensors) { - for (auto &tensor : tensors) { - auto shape = tensor.Shape(); - if (std::find(shape.begin(), shape.end(), -1) != shape.end()) { - return false; - } - } - return true; -} -} // namespace - -Status CustomInterface::Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - for (auto &output : *outputs) { - output.SetDataType(DataType::kNumberTypeFloat32); - output.SetFormat(inputs->front().format()); - } - std::map attrs; - if (FetchAttrs(*primitive, &attrs) != kSuccess) { - MS_LOG(ERROR) << "fetch attrs from primitive failed."; - return kLiteError; - } - if (SetOutputFormat(attrs, outputs) != kSuccess) { - MS_LOG(ERROR) << "set output format failed."; - return kLiteError; - } - if (!InferDone(*inputs)) { - return kLiteInferInvalid; - } - std::vector> inputs_shape; - if (GetCustomShape(attrs, dpico::kInputsShape, inputs->size(), &inputs_shape) != kSuccess) { - MS_LOG(ERROR) << "parser inputs_shape attribute failed."; - return kLiteError; - } - std::vector> outputs_shape; - if (GetCustomShape(attrs, dpico::kOutputsShape, outputs->size(), &outputs_shape) != kSuccess) { - MS_LOG(ERROR) << "parser outputs_shape attribute failed."; - return kLiteError; - } - if (inputs_shape.size() != inputs->size() - kOmParameterNum) { - MS_LOG(ERROR) << "inputs num:" << (inputs->size() - kOmParameterNum) - << "should be equal to inputs_shape num:" << inputs_shape.size(); - return kLiteError; - } - if (inputs_shape[0].size() != (*inputs)[0].Shape().size()) { - MS_LOG(ERROR) << "input[0] shape dim size is invalid. " << inputs_shape[0].size() - << "!=" << (*inputs)[0].Shape().size(); - return kLiteError; - } - - dpico::OmNetType om_net_type; - if (dpico::GetOmNetType(primitive, &om_net_type) != RET_OK) { - MS_LOG(ERROR) << "get om net type failed."; - return kLiteError; - } - - bool resize_flag = false; - int resize_num = 1; - for (size_t i = 0; i < inputs_shape[0].size(); i++) { - if (inputs_shape[0][i] != (*inputs)[0].Shape()[i]) { - if (i == 0) { - resize_flag = true; - resize_num = static_cast((*inputs)[0].Shape()[i]); - } else { - MS_LOG(ERROR) << "Custom of DPICO only support batch_num resize."; - return kLiteError; - } - } - } - if (resize_flag) { - for (auto &output_shape : outputs_shape) { - output_shape[0] = resize_num; - if (om_net_type == dpico::OmNetType::kRecurrent) { - MS_LOG(INFO) << "only output_0 has the information about time steps."; - break; - } - } - } - - for (size_t i = 0; i < outputs->size(); i++) { - (*outputs)[i].SetShape(outputs_shape[i]); - } - return kSuccess; -} - -std::shared_ptr CustomInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, DPICO, CustomInferCreater); -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.h deleted file mode 100644 index 07b176b9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_custom_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_CUSTOM_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_CUSTOM_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class CustomInterface : public KernelInterface { - public: - CustomInterface() {} - - ~CustomInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_CUSTOM_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.cc deleted file mode 100644 index 6d2e93a1..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.cc +++ /dev/null @@ -1,100 +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 "infer/dpico_decbbox_infer.h" -#include -#include -#include -#include "common/op_enum.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "common/op_attr.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -namespace { -constexpr int kDimsOfBbox = 6; // [xmin, ymin, xmax, ymax, score class_id] -} // namespace -std::shared_ptr DpicoDecBBoxInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoDecBBoxInterface::Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "DecBBox") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param attr is nullptr."; - return kLiteError; - } - bool has_num_classes = false; - uint32_t num_classes = 0; - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - if (param->attr()->Get(i)->name()->str() == dpico::kNumClasses) { - auto output_info = param->attr()->Get(i)->data(); - if (output_info == nullptr) { - MS_LOG(ERROR) << "output_shape is nullptr"; - return kLiteError; - } - if (memcpy_s(&num_classes, sizeof(uint32_t), output_info->data(), output_info->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - has_num_classes = true; - break; - } - } - if (!has_num_classes) { - MS_LOG(ERROR) << dpico::kNumClasses << " is needed for DecBBox"; - return kLiteError; - } - - const auto &input = (*inputs)[0]; - auto &output = (*outputs)[0]; - std::vector output_shape(input.Shape()); - if (output_shape.size() != dpico::kDims4) { - MS_LOG(ERROR) << "output_shape should be 4 dims, which is " << output_shape.size(); - return kLiteError; - } - output_shape.at(dpico::kAxis1) = num_classes; - output_shape.at(dpico::kAxis2) = kDimsOfBbox; - output.SetShape(output_shape); - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, DecBBox, DpicoDecBBoxInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.h deleted file mode 100644 index 77466fca..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_decbbox_infer.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_DECBBOX_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_DECBBOX_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoDecBBoxInterface : public KernelInterface { - public: - DpicoDecBBoxInterface() {} - - ~DpicoDecBBoxInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_DECBBOX_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.cc deleted file mode 100644 index 77c90b0f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.cc +++ /dev/null @@ -1,63 +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 "infer/dpico_detection_output_infer.h" -#include -#include -#include -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -namespace { -constexpr int kDimensionOfBbox = 7; // [image_id, label, confidence, xmin, ymin, xmax, ymax] -} // namespace -std::shared_ptr DpicoDetectionOutputInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoDetectionOutputInterface::Infer(std::vector *inputs, - std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "DetectionOutput") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - const auto &input = (*inputs)[0]; - auto &output = (*outputs)[0]; - output.SetShape(std::vector({input.Shape()[0], kDimensionOfBbox})); - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, DetectionOutput, DpicoDetectionOutputInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.h deleted file mode 100644 index c9cf4166..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_detection_output_infer.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_DETECTION_OUTPUT_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_DETECTION_OUTPUT_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoDetectionOutputInterface : public KernelInterface { - public: - DpicoDetectionOutputInterface() {} - - ~DpicoDetectionOutputInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_DETECTION_OUTPUT_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.cc deleted file mode 100644 index 45dbc079..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.cc +++ /dev/null @@ -1,118 +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 "infer/dpico_extract_infer.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "mindspore/ops/op_def/op_name.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoExtractInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoExtractInterface::Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "Extract") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - // get param value - std::map *> custom_attrs; - int raw_axis = 1; - uint32_t slice_begin = 0; - uint32_t slice_end = 1; - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param->attr() is nullptr"; - return kLiteError; - } - for (uint16_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - (void)custom_attrs.emplace(std::pair(param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data())); - } - if (custom_attrs.count(ops::kAxis) == 1) { - if (memcpy_s(&raw_axis, sizeof(int32_t), custom_attrs[ops::kAxis]->data(), custom_attrs[ops::kAxis]->size()) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - } - if (custom_attrs.count(dpico::kSlicePointBegin) == 1) { - if (memcpy_s(&slice_begin, sizeof(uint32_t), custom_attrs[dpico::kSlicePointBegin]->data(), - custom_attrs[dpico::kSlicePointBegin]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - } - if (custom_attrs.count(dpico::kSlicePointEnd) == 1) { - if (memcpy_s(&slice_end, sizeof(uint32_t), custom_attrs[dpico::kSlicePointEnd]->data(), - custom_attrs[dpico::kSlicePointEnd]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - } - - const auto &input = (*inputs)[0]; - auto &output = (*outputs)[0]; - - auto input_shape = input.Shape(); - if (input_shape.empty()) { - MS_LOG(ERROR) << "input shape is empty."; - return kLiteError; - } - size_t axis = (raw_axis + static_cast(input_shape.size())) % input_shape.size(); - if (input_shape.size() <= axis) { - MS_LOG(ERROR) << "input_shape size: " << input_shape.size() << " is less than axis: " << axis; - return kLiteError; - } - if (input_shape.at(axis) < slice_end) { - MS_LOG(ERROR) << "slice_point_end " << slice_end << " is greater than dim " << input_shape.at(axis); - return kLiteError; - } - std::vector output_shape(input_shape); - output_shape[axis] = slice_end - slice_begin; - output.SetShape(output_shape); - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Extract, DpicoExtractInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.h deleted file mode 100644 index b1885199..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_extract_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_EXTRACT_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_EXTRACT_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoExtractInterface : public KernelInterface { - public: - DpicoExtractInterface() {} - - ~DpicoExtractInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_EXTRACT_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.cc deleted file mode 100644 index 15993c65..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.cc +++ /dev/null @@ -1,77 +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 "infer/dpico_lstm_infer.h" -#include -#include -#include -#include "common/op_enum.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -namespace { -constexpr size_t kHiddenLayerSize = 4; -constexpr size_t kInputSize4 = 4; -} // namespace -std::shared_ptr DpicoLstmInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoLstmInterface::Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - if (inputs->size() < kInputSize4) { - MS_LOG(ERROR) << "inputs size is invalid: " << inputs->size(); - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "Lstm") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - const auto &input = (*inputs)[0]; - const auto &hidden_weight = (*inputs)[dpico::kInputIndex2]; - auto &output = (*outputs)[0]; - std::vector output_shape(input.Shape()); - if (output_shape.size() != dpico::kDims3) { - MS_LOG(ERROR) << "output_shape should be 3 dims, which is " << output_shape.size(); - return kLiteError; - } - output_shape[0] = 1; // bidirectional ? 2 : 1 - output_shape[dpico::kInputIndex2] = hidden_weight.Shape().at(0) / static_cast(kHiddenLayerSize); - output.SetShape(output_shape); - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Lstm, DpicoLstmInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.h deleted file mode 100644 index 24d41703..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_LSTM_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_LSTM_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoLstmInterface : public KernelInterface { - public: - DpicoLstmInterface() {} - - ~DpicoLstmInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_LSTM_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.cc deleted file mode 100755 index 60d4f0f0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.cc +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright 2023 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 "infer/dpico_lstm_onnx_infer.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "mindspore/ops/op_def/op_name.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoLSTMOnnxInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoLSTMOnnxInterface::Infer(std::vector *inputs, - std::vector *outputs, const schema::Primitive *primitive, - const kernel::Kernel *) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "LSTM") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - // get param value - std::map *> custom_attrs; - int32_t hidden_size = 0; - int32_t direction = 0; - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param->attr() is nullptr"; - return kLiteError; - } - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - (void)custom_attrs.emplace(std::pair(param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data())); - } - if (custom_attrs.count("hidden_size") == 1) { - if (memcpy_s(&hidden_size, sizeof(int32_t), custom_attrs["hidden_size"]->data(), - custom_attrs["hidden_size"]->size()) != EOK) { - MS_LOG(ERROR) << "hidden_size memcpy_s failed."; - return kLiteError; - } - } - if (custom_attrs.count("direction") == 1) { - if (memcpy_s(&direction, sizeof(int32_t), custom_attrs["direction"]->data(), custom_attrs["direction"]->size()) != - EOK) { - MS_LOG(ERROR) << "direction memcpy_s failed."; - return kLiteError; - } - } - - const auto &input = (*inputs)[0]; - auto &output = (*outputs)[0]; - std::vector output_shape(dpico::kDims4); - output_shape[0] = input.Shape().at(0); - output_shape[dpico::kAxis1] = direction; - output_shape[dpico::kAxis2] = input.Shape().at(1); - output_shape[dpico::kAxis3] = hidden_size; - output.SetShape(output_shape); - - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, LSTM, DpicoLSTMOnnxInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.h deleted file mode 100755 index 0f3ea3ff..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_lstm_onnx_infer.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2023 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 DPICO_INFER_DPICO_LSTM_ONNX_INFER_H_ -#define DPICO_INFER_DPICO_LSTM_ONNX_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoLSTMOnnxInterface : public KernelInterface { - public: - DpicoLSTMOnnxInterface() {} - - ~DpicoLSTMOnnxInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // DPICO_INFER_DPICO_LSTMONNX_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.cc deleted file mode 100755 index de0b3b8d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.cc +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Copyright 2023 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 "infer/dpico_maxunpool_infer.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "mindspore/ops/op_def/op_name.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoMaxunpoolInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoMaxunpoolInterface::Infer(std::vector *inputs, - std::vector *outputs, const schema::Primitive *primitive, - const kernel::Kernel *) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "MaxUnpool") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - // Get param value - std::map *> custom_attrs; - int32_t strides = 0; - int32_t kernel_shape = 0; - uint32_t maxunpool_h = 0; - uint32_t maxunpool_w = 0; - bool has_strides = false; - bool has_kernel_shape = false; - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param->attr() is nullptr"; - return kLiteError; - } - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr || - param->attr()->Get(i)->data() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get " << i << " is nullptr or param->attr()->Get(i)->name() or data is nullptr"; - return kLiteError; - } - (void)custom_attrs.emplace(std::pair(param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data())); - } - if (custom_attrs.count(ops::kStrides) == 1) { - if (memcpy_s(&strides, sizeof(int32_t), custom_attrs[ops::kStrides]->data(), custom_attrs[ops::kStrides]->size()) != - EOK) { - MS_LOG(ERROR) << "strides memcpy_s failed."; - return kLiteError; - } - has_strides = true; - } - if (custom_attrs.count(dpico::kKernelShape) == 1) { - if (memcpy_s(&kernel_shape, sizeof(int32_t), custom_attrs[dpico::kKernelShape]->data(), - custom_attrs[dpico::kKernelShape]->size()) != EOK) { - MS_LOG(ERROR) << "kernel_shape memcpy_s failed."; - return kLiteError; - } - has_kernel_shape = true; - } - - const auto &input = (*inputs)[0]; - if (input.Shape().size() != dpico::kDims4) { - MS_LOG(ERROR) << "inputs_0's shape should be 4 dims, but now it's " << input.Shape().size() << " dims"; - return kLiteError; - } - - if (has_strides && has_kernel_shape) { - maxunpool_h = (input.Shape().at(dpico::kAxis2) - 1) * strides + kernel_shape; - maxunpool_w = (input.Shape().at(dpico::kAxis3) - 1) * strides + kernel_shape; - } else if (!has_strides && has_kernel_shape) { - maxunpool_h = input.Shape().at(dpico::kAxis2) - 1 + kernel_shape; - maxunpool_w = input.Shape().at(dpico::kAxis3) - 1 + kernel_shape; - } else { - MS_LOG(ERROR) << "kernel_shape attr should be provided."; - return kLiteError; - } - - auto &output = (*outputs)[0]; - std::vector output_shape(dpico::kDims4); - output_shape[0] = input.Shape().at(0); - output_shape[dpico::kAxis1] = input.Shape().at(1); - output_shape[dpico::kAxis2] = maxunpool_h; - output_shape[dpico::kAxis3] = maxunpool_w; - output.SetShape(output_shape); - - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, MaxUnpool, DpicoMaxunpoolInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.h deleted file mode 100755 index f145726d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_maxunpool_infer.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2023 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 DPICO_INFER_DPICO_MAXUNPOOL_INFER_H_ -#define DPICO_INFER_DPICO_MAXUNPOOL_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoMaxunpoolInterface : public KernelInterface { - public: - DpicoMaxunpoolInterface() {} - - ~DpicoMaxunpoolInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // DPICO_INFER_DPICO_MAXUNPOOL_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.cc deleted file mode 100644 index 10fd61bc..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.cc +++ /dev/null @@ -1,129 +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 "infer/dpico_passthrough_infer.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoPassThroughInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoPassThroughInterface::Infer(std::vector *inputs, - std::vector *outputs, const schema::Primitive *primitive, - const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "PassThrough") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - // get param value - std::map *> custom_attrs; - int64_t num_output = 0; - int64_t block_height = 0; - int64_t block_width = 0; - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param->attr() is nullptr"; - return kLiteError; - } - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - (void)custom_attrs.emplace(std::pair(param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data())); - } - if (custom_attrs.count(dpico::kNumOutput) == 1) { - if (memcpy_s(&num_output, sizeof(uint32_t), custom_attrs[dpico::kNumOutput]->data(), - custom_attrs[dpico::kNumOutput]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - } else { - MS_LOG(ERROR) << "num_output attr doesn't exist."; - return kLiteError; - } - if (custom_attrs.count(dpico::kBlockHeight) == 1) { - if (memcpy_s(&block_height, sizeof(uint32_t), custom_attrs[dpico::kBlockHeight]->data(), - custom_attrs[dpico::kBlockHeight]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - if (block_height == 0) { - MS_LOG(ERROR) << "block_height shouldn't be 0."; - return kLiteError; - } - } else { - MS_LOG(ERROR) << "block_height attr doesn't exist."; - return kLiteError; - } - if (custom_attrs.count(dpico::kBlockWidth) == 1) { - if (memcpy_s(&block_width, sizeof(uint32_t), custom_attrs[dpico::kBlockWidth]->data(), - custom_attrs[dpico::kBlockWidth]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - if (block_width == 0) { - MS_LOG(ERROR) << "block_width shouldn't be 0."; - return kLiteError; - } - } else { - MS_LOG(ERROR) << "block_width attr doesn't exist."; - return kLiteError; - } - - const auto &input = (*inputs)[0]; - if (input.Shape().size() != dpico::kDims4) { - MS_LOG(ERROR) << "inputs_0's shape should be 4 dims, but now it's " << input.Shape().size() << " dims"; - return kLiteError; - } - auto &output = (*outputs)[0]; - std::vector output_shape(dpico::kDims4); - output_shape[0] = input.Shape().at(0); - output_shape[dpico::kAxis1] = num_output; - output_shape[dpico::kAxis2] = input.Shape().at(dpico::kAxis2) / block_height; - output_shape[dpico::kAxis3] = input.Shape().at(dpico::kAxis3) / block_width; - output.SetShape(output_shape); - - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, PassThrough, DpicoPassThroughInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.h deleted file mode 100644 index 99af6f14..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_passthrough_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_PASSTHROUGH_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_PASSTHROUGH_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoPassThroughInterface : public KernelInterface { - public: - DpicoPassThroughInterface() {} - - ~DpicoPassThroughInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_PASSTHROUGH_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.cc deleted file mode 100644 index 220c3a56..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.cc +++ /dev/null @@ -1,117 +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 "infer/dpico_psroi_pool_infer.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoPsRoiPoolInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoPsRoiPoolInterface::Infer(std::vector *inputs, - std::vector *outputs, const schema::Primitive *primitive, - const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "PsRoiPool") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - // get param value - std::map *> custom_attrs; - int32_t output_dim = 0; - int32_t group_size = 0; - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param->attr() is nullptr"; - return kLiteError; - } - for (size_t i = 0; i < param->attr()->size(); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - (void)custom_attrs.emplace(std::pair(param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data())); - } - if (custom_attrs.count(dpico::kGroupSize) == 1) { - if (memcpy_s(&group_size, sizeof(int32_t), custom_attrs[dpico::kGroupSize]->data(), - custom_attrs[dpico::kGroupSize]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - } else { - MS_LOG(ERROR) << "group_size attr doesn't exist."; - return kLiteError; - } - if (custom_attrs.count(dpico::kOutputDim) == 1) { - if (memcpy_s(&output_dim, sizeof(int32_t), custom_attrs[dpico::kOutputDim]->data(), - custom_attrs[dpico::kOutputDim]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - } else { - MS_LOG(ERROR) << "output_dim attr doesn't exist."; - return kLiteError; - } - - int pooled_h = group_size; - int pooled_w = group_size; - - if (inputs->size() != dpico::kDims2) { - MS_LOG(ERROR) << "psroi input size is invalid, which is " << inputs->size(); - return kLiteError; - } - const auto &psroi = (*inputs)[1]; - if (psroi.Shape().empty()) { - MS_LOG(ERROR) << "inputs_1 shape is empty."; - return kLiteError; - } - auto &output = (*outputs)[0]; - std::vector output_shape(dpico::kDims4); - output_shape[0] = psroi.Shape().at(0); - output_shape[dpico::kAxis1] = output_dim; - output_shape[dpico::kAxis2] = pooled_h; - output_shape[dpico::kAxis3] = pooled_w; - output.SetShape(output_shape); - - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, PsRoiPool, DpicoPsRoiPoolInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.h deleted file mode 100644 index 1468d25e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_psroi_pool_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_PSROI_POOL_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_PSROI_POOL_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoPsRoiPoolInterface : public KernelInterface { - public: - DpicoPsRoiPoolInterface() {} - - ~DpicoPsRoiPoolInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_PSROI_POOL_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.cc deleted file mode 100644 index bfcac01e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.cc +++ /dev/null @@ -1,86 +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 "infer/dpico_recurrent_infer.h" -#include -#include -#include -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "common/op_enum.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -namespace { -constexpr size_t kGateNum2 = 2; -} // namespace -std::shared_ptr DpicoRecurrentInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoRecurrentInterface::Infer(std::vector *inputs, - std::vector *outputs, const schema::Primitive *primitive, - const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (param == nullptr) { - MS_LOG(ERROR) << "param is nullptr"; - return kLiteError; - } - if (param->type() == nullptr) { - MS_LOG(ERROR) << "param->type() is nullptr"; - return kLiteError; - } - if (inputs->size() < dpico::kDims3) { - MS_LOG(ERROR) << "inputs size is invalid: " << inputs->size(); - return kLiteError; - } - - const auto &input = (*inputs)[0]; - const auto &hidden_weight = (*inputs)[dpico::kInputIndex2]; - auto &output = (*outputs)[0]; - std::vector output_shape(input.Shape()); - if (output_shape.size() != dpico::kDims3) { - MS_LOG(ERROR) << "output_shape should be 3 dims, which is " << output_shape.size(); - return kLiteError; - } - if (param->type()->str() != "BiLstm") { - output_shape[0] = 1; // bidirectional ? 2 : 1 - } else { - output_shape[0] = kGateNum2; // bidirectional ? 2 : 1 - } - output_shape[dpico::kAxis2] = hidden_weight.Shape().at(0); - output.SetShape(output_shape); - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Rnn, DpicoRecurrentInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Gru, DpicoRecurrentInferCreater) -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, BiLstm, DpicoRecurrentInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.h deleted file mode 100644 index 81572c0d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_recurrent_infer.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_RECURRENT_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_RECURRENT_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoRecurrentInterface : public KernelInterface { - public: - DpicoRecurrentInterface() {} - - ~DpicoRecurrentInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_RECURRENT_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.cc deleted file mode 100644 index 74be958a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.cc +++ /dev/null @@ -1,128 +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 "infer/dpico_roi_align_infer.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" -#include "include/securec.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoRoiAlignInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoRoiAlignInterface::Infer(std::vector *inputs, - std::vector *outputs, const schema::Primitive *primitive, - const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "RoiAlign") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - // get param value - std::map *> custom_attrs; - uint32_t output_height = 0; - uint32_t output_width = 0; - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param->attr() is nullptr"; - return kLiteError; - } - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - (void)custom_attrs.emplace(std::pair(param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data())); - } - if (custom_attrs.count(dpico::kOutputHeight) == 1) { - if (memcpy_s(&output_height, sizeof(uint32_t), custom_attrs[dpico::kOutputHeight]->data(), - custom_attrs[dpico::kOutputHeight]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - if (output_height == 0) { - MS_LOG(ERROR) << "output_height shouldn't be 0."; - return kLiteError; - } - } else { - MS_LOG(ERROR) << "output_height attr doesn't exist."; - return kLiteError; - } - if (custom_attrs.count(dpico::kOutputWidth) == 1) { - if (memcpy_s(&output_width, sizeof(uint32_t), custom_attrs[dpico::kOutputWidth]->data(), - custom_attrs[dpico::kOutputWidth]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - if (output_width == 0) { - MS_LOG(ERROR) << "output_width shouldn't be 0."; - return kLiteError; - } - } else { - MS_LOG(ERROR) << "output_width attr doesn't exist."; - return kLiteError; - } - - if (inputs->size() != dpico::kDims3) { - MS_LOG(ERROR) << "RoiAlign should have 3 inputs, but in fact it's " << inputs->size(); - return kLiteError; - } - const auto &input = (*inputs)[0]; - const auto &input_1 = (*inputs)[1]; - if (input.Shape().size() != dpico::kDims4) { - MS_LOG(ERROR) << "inputs_0's shape should be 4 dims, but now it's " << input.Shape().size() << " dims"; - return kLiteError; - } - if (input_1.Shape().size() != dpico::kDims2) { - MS_LOG(ERROR) << "inputs_1's shape should be 2 dims, but now it's " << input_1.Shape().size() << " dims"; - return kLiteError; - } - auto &output = (*outputs)[0]; - std::vector output_shape(dpico::kDims4); - output_shape[0] = input_1.Shape().at(0); - output_shape[dpico::kAxis1] = input.Shape().at(1); - output_shape[dpico::kAxis2] = output_height; - output_shape[dpico::kAxis3] = output_width; - output.SetShape(output_shape); - - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, RoiAlign, DpicoRoiAlignInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.h deleted file mode 100644 index 0f161423..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_roi_align_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_ROI_ALIGN_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_ROI_ALIGN_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoRoiAlignInterface : public KernelInterface { - public: - DpicoRoiAlignInterface() {} - - ~DpicoRoiAlignInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_ROI_ALIGN_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.cc deleted file mode 100644 index 2e8ae690..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.cc +++ /dev/null @@ -1,110 +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 "infer/dpico_spp_infer.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -namespace { -constexpr auto kSquareNum = 2; -constexpr auto kBaseNum = 2; -} // namespace -std::shared_ptr DpicoSppInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoSppInterface::Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "Spp") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param attr is nullptr."; - return kLiteError; - } - bool has_pyramid_height = false; - uint32_t pyramid_height = 0; - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - if (param->attr()->Get(i)->name()->str() == dpico::kPyramidHeight) { - auto output_info = param->attr()->Get(i)->data(); - if (output_info == nullptr) { - MS_LOG(ERROR) << "output_shape is nullptr"; - return kLiteError; - } - if (memcpy_s(&pyramid_height, sizeof(uint32_t), output_info->data(), output_info->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - has_pyramid_height = true; - break; - } - } - if (!has_pyramid_height) { - MS_LOG(ERROR) << dpico::kPyramidHeight << " attr is needed for spp"; - return kLiteError; - } - - const auto &input = (*inputs)[0]; - auto &output = (*outputs)[0]; - - auto input_shape = input.Shape(); - if (input_shape.size() != dpico::kDims4) { - MS_LOG(ERROR) << "input_shape should have 4 dims, but in fact it's " << input_shape.size(); - return kLiteError; - } - std::vector output_shape; - output_shape.push_back(input_shape.at(0)); - int64_t output_planes_size = 0; - for (int64_t i = 0; i < pyramid_height; i++) { // spp output plane size is 1 * 1, 2 * 2, 4 * 4, ... - output_planes_size += std::pow(kBaseNum, kSquareNum * i); - } - output_shape.push_back(input_shape.at(1) * output_planes_size); - output.SetShape(output_shape); - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Spp, DpicoSppInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.h deleted file mode 100644 index b378235a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_spp_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_SPP_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_SPP_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoSppInterface : public KernelInterface { - public: - DpicoSppInterface() {} - - ~DpicoSppInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_UPSAMPLE_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.cc b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.cc deleted file mode 100644 index 96579735..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.cc +++ /dev/null @@ -1,131 +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 "infer/dpico_upsample_infer.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "src/common/log_adapter.h" -#include "common/infer_util.h" -#include "include/errorcode.h" -#include "mindspore/ops/op_def/op_name.h" -#include "include/registry/register_kernel_interface.h" - -using mindspore::kernel::KernelInterface; -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; - -namespace mindspore { -namespace kernel { -std::shared_ptr DpicoUpsampleInferCreater() { - std::shared_ptr infer = std::make_shared(); - if (infer == nullptr) { - MS_LOG(ERROR) << "make shared failed, infer is nullptr."; - return nullptr; - } - return infer; -} -Status DpicoUpsampleInterface::Infer(std::vector *inputs, - std::vector *outputs, const schema::Primitive *primitive, - const kernel::Kernel *kernel) { - auto status = dpico::CheckCustomInputOutput(inputs, outputs, primitive); - if (status != RET_OK) { - MS_LOG(ERROR) << "Check custom input output failed."; - return kLiteError; - } - auto param = primitive->value_as_Custom(); - if (dpico::CheckCustomParam(param, "Upsample") != RET_OK) { - MS_LOG(ERROR) << "custom param is invalid."; - return kLiteError; - } - - // get param value - std::map *> custom_attrs; - float scale = 0; - uint32_t upsample_h = 0; - uint32_t upsample_w = 0; - bool has_scale = false; - bool has_upsample_h = false; - bool has_upsample_w = false; - if (param->attr() == nullptr) { - MS_LOG(ERROR) << "param->attr() is nullptr"; - return kLiteError; - } - for (uint32_t i = 0; i < static_cast(param->attr()->size()); i++) { - if (param->attr()->Get(i) == nullptr || param->attr()->Get(i)->name() == nullptr) { - MS_LOG(ERROR) << "param->attr()->Get(i) is nullptr or param->attr()->Get(i)->name() is nullptr"; - return kLiteError; - } - (void)custom_attrs.emplace(std::pair(param->attr()->Get(i)->name()->str(), param->attr()->Get(i)->data())); - } - if (custom_attrs.count(ops::kScale) == 1) { - if (memcpy_s(&scale, sizeof(float), custom_attrs[ops::kScale]->data(), custom_attrs[ops::kScale]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - has_scale = true; - } - if (custom_attrs.count(dpico::kUpsampleH) == 1) { - if (memcpy_s(&upsample_h, sizeof(uint32_t), custom_attrs[dpico::kUpsampleH]->data(), - custom_attrs[dpico::kUpsampleH]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - has_upsample_h = true; - } - if (custom_attrs.count(dpico::kUpsampleW) == 1) { - if (memcpy_s(&upsample_w, sizeof(uint32_t), custom_attrs[dpico::kUpsampleW]->data(), - custom_attrs[dpico::kUpsampleW]->size()) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return kLiteError; - } - has_upsample_w = true; - } - - const auto &input = (*inputs)[0]; - if (input.Shape().size() != dpico::kDims4) { - MS_LOG(ERROR) << "inputs_0's shape should be 4 dims, but now it's " << input.Shape().size() << " dims"; - return kLiteError; - } - - if (has_scale) { - if (!has_upsample_h) { - upsample_h = input.Shape().at(dpico::kAxis2) * scale; - } - if (!has_upsample_w) { - upsample_w = input.Shape().at(dpico::kAxis3) * scale; - } - } else if (!has_upsample_h || !has_upsample_w) { - MS_LOG(ERROR) << "scale attr or (upsample_h && upsample_w) attr should be provided."; - return kLiteError; - } - - auto &output = (*outputs)[0]; - std::vector output_shape(dpico::kDims4); - output_shape[0] = input.Shape().at(0); - output_shape[dpico::kAxis1] = input.Shape().at(1); - output_shape[dpico::kAxis2] = upsample_h; - output_shape[dpico::kAxis3] = upsample_w; - output.SetShape(output_shape); - - return kSuccess; -} -REGISTER_CUSTOM_KERNEL_INTERFACE(DPICO, Upsample, DpicoUpsampleInferCreater) -} // namespace kernel -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.h b/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.h deleted file mode 100644 index 1d56db6c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/infer/dpico_upsample_infer.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_UPSAMPLE_INFER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_UPSAMPLE_INFER_H_ - -#include -#include "include/kernel_interface.h" - -namespace mindspore { -namespace kernel { -class DpicoUpsampleInterface : public KernelInterface { - public: - DpicoUpsampleInterface() {} - - ~DpicoUpsampleInterface() = default; - - Status Infer(std::vector *inputs, std::vector *outputs, - const schema::Primitive *primitive, const kernel::Kernel *kernel) override; -}; -} // namespace kernel -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_INFER_DPICO_UPSAMPLE_INFER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.cc deleted file mode 100644 index c4ad6330..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.cc +++ /dev/null @@ -1,64 +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 "legacy_ops/bi_lstm_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/bi_lstm_operator.h" - -namespace mindspore { -namespace dpico { -STATUS BiLstmMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto bi_lstm_operator = std::make_unique(); - if (bi_lstm_operator == nullptr) { - MS_LOG(ERROR) << "bi_lstm_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, bi_lstm_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (prim->GetAttr(kNumOutput) != nullptr) { - bi_lstm_operator->SetRecurrentNumOutput(static_cast(api::GetValue(prim->GetAttr(kNumOutput)))); - } - if (prim->GetAttr(kExposeHidden) != nullptr) { - bi_lstm_operator->SetRecurrentExposeHidden(api::GetValue(prim->GetAttr(kExposeHidden))); - } - if (prim->GetAttr(kOutputChannel) != nullptr) { - bi_lstm_operator->SetOutputChannel(static_cast(api::GetValue(prim->GetAttr(kOutputChannel)))); - } - bi_lstm_operator->SetRecurrentContFlag(true); - if (SetRecurrentDataInfo(cnode, bi_lstm_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set bi_lstm data info failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(bi_lstm_operator)); - return RET_OK; -} -REG_MAPPER(BiLstm, BiLstmMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.h deleted file mode 100644 index 884636cf..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/bi_lstm_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BI_LSTM_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BI_LSTM_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class BiLstmMapper : public OpMapper { - public: - BiLstmMapper() : OpMapper("BiLstm") {} - ~BiLstmMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BI_LSTM_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.cc deleted file mode 100644 index a14e8bad..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.cc +++ /dev/null @@ -1,49 +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 "legacy_ops/nop_mapper.h" -#include -#include -#include -#include "op/nop_operator.h" - -namespace mindspore { -namespace dpico { -STATUS NopMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto nop_operator = std::make_unique(); - if (nop_operator == nullptr) { - MS_LOG(ERROR) << "nop_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, nop_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - nop_operator->SetOpType(mapper::OpType::NOP); - base_operators->push_back(std::move(nop_operator)); - return RET_OK; -} -REG_MAPPER(Nop, NopMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.h deleted file mode 100644 index 4466e38b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/nop_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_NOP_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_NOP_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class NopMapper : public OpMapper { - public: - NopMapper() : OpMapper("Nop") {} - ~NopMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_NOP_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.cc deleted file mode 100644 index 992d4c5c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.cc +++ /dev/null @@ -1,61 +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 "legacy_ops/reverse_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "infer/reverse_v2.h" -#include "op/reverse_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ReverseMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto reverse_prim = api::utils::cast>(prim); - MS_ASSERT(reverse_prim != nullptr); - - auto reverse_operator = std::make_unique(); - if (reverse_operator == nullptr) { - MS_LOG(ERROR) << "reverse_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, reverse_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - reverse_operator->SetOpType(mapper::OpType::REVERSE); - if (reverse_prim->GetAttr(ops::kAxis) != nullptr) { - auto axis = reverse_prim->get_axis(); - if (axis.size() != 1) { - MS_LOG(ERROR) << "reverse's axis size only supports 1 by dpico. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - reverse_operator->SetAxis(static_cast(axis.at(0))); - } - base_operators->push_back(std::move(reverse_operator)); - return RET_OK; -} -REG_MAPPER(ReverseV2, ReverseMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.h deleted file mode 100644 index 895547c5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/reverse_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_REVERSE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_REVERSE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ReverseMapper : public OpMapper { - public: - ReverseMapper() : OpMapper("Reverse") {} - ~ReverseMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_REVERSE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.cc deleted file mode 100644 index 57090fcd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.cc +++ /dev/null @@ -1,77 +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 "legacy_ops/roi_align_mapper.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "op/roi_align_operator.h" - -namespace mindspore { -namespace dpico { -STATUS RoiAlignMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto roi_align_operator = std::make_unique(); - if (roi_align_operator == nullptr) { - MS_LOG(ERROR) << "roi_align_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, roi_align_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - roi_align_operator->SetOpType(mapper::OpType::ROIALIGN); - if (prim->GetAttr(ops::kMode) != nullptr) { - auto pool_mode = api::GetValue(prim->GetAttr(ops::kMode)); - if (pool_mode == "avg") { - roi_align_operator->SetPoolMode(mapper::RoiAlignPoolMode::ROI_ALIGN_AVG); - } else if (pool_mode == "max") { - roi_align_operator->SetPoolMode(mapper::RoiAlignPoolMode::ROI_ALIGN_MAX); - } else { - MS_LOG(ERROR) << "unsupported pool mode:" << pool_mode << " by dpico. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } - if (prim->GetAttr(dpico::kOutputHeight) != nullptr) { - roi_align_operator->SetPooledHeight( - static_cast(api::GetValue(prim->GetAttr(dpico::kOutputHeight)))); - } - if (prim->GetAttr(dpico::kOutputWidth) != nullptr) { - roi_align_operator->SetPooledWidth( - static_cast(api::GetValue(prim->GetAttr(dpico::kOutputWidth)))); - } - if (prim->GetAttr(dpico::kSamplingRatio) != nullptr) { - roi_align_operator->SetSamplingRatio( - static_cast(api::GetValue(prim->GetAttr(dpico::kSamplingRatio)))); - } - if (prim->GetAttr(dpico::kSpatialScale) != nullptr) { - roi_align_operator->SetSpatialScale(api::GetValue(prim->GetAttr(dpico::kSpatialScale))); - } - base_operators->push_back(std::move(roi_align_operator)); - return RET_OK; -} -REG_MAPPER(RoiAlign, RoiAlignMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.h deleted file mode 100644 index f0796a81..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/roi_align_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ROI_ALIGN_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ROI_ALIGN_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class RoiAlignMapper : public OpMapper { - public: - RoiAlignMapper() : OpMapper("RoiAlign") {} - ~RoiAlignMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ROI_ALIGN_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.cc deleted file mode 100644 index 89abd040..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.cc +++ /dev/null @@ -1,67 +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 "legacy_ops/spp_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/spp_operator.h" - -namespace mindspore { -namespace dpico { -STATUS SppMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto spp_operator = std::make_unique(); - if (spp_operator == nullptr) { - MS_LOG(ERROR) << "spp_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, spp_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - spp_operator->SetOpType(mapper::OpType::SPPPOOLING); - - if (prim->GetAttr(dpico::kPyramidHeight) != nullptr) { - spp_operator->SetPyramidHeight(static_cast(api::GetValue(prim->GetAttr(dpico::kPyramidHeight)))); - } - if (prim->GetAttr(dpico::kPoolMethod) != nullptr) { - auto pool_method = api::GetValue(prim->GetAttr(dpico::kPoolMethod)); - if (pool_method == 0) { - spp_operator->SetSppType(mapper::OpType::POOLINGMAX); - } else if (pool_method == 1) { - spp_operator->SetSppType(mapper::OpType::POOLINGAVE); - } else { - MS_LOG(ERROR) << "only supports max && ave pool by dpico. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } - - base_operators->push_back(std::move(spp_operator)); - return RET_OK; -} -REG_MAPPER(Spp, SppMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.h deleted file mode 100644 index a2fa02d7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/legacy_ops/spp_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SPP_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SPP_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class SppMapper : public OpMapper { - public: - SppMapper() : OpMapper("Spp") {} - ~SppMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SPP_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.cc deleted file mode 100644 index 7ef54dbc..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.cc +++ /dev/null @@ -1,55 +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 "mapper/abs_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/absval_operator.h" - -namespace mindspore { -namespace dpico { -STATUS AbsMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto abs_operator = std::make_unique(); - if (abs_operator == nullptr) { - MS_LOG(ERROR) << "abs_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, abs_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - abs_operator->SetOpType(mapper::OpType::ABSAF); - if (PushOfflineArgs(cnode, abs_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(abs_operator)); - return RET_OK; -} -REG_MAPPER(Abs, AbsMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.h deleted file mode 100644 index fff4d4b0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/abs_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ABS_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ABS_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class AbsMapper : public OpMapper { - public: - AbsMapper() : OpMapper("Abs") {} - ~AbsMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ABS_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.cc deleted file mode 100644 index 04469952..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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 "mapper/acos_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/acos_operator.h" -#include "parser/onnx/onnx_acos_parser.h" - -namespace mindspore { -namespace dpico { -STATUS AcosMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto acos_operator = std::make_unique(); - if (SetCommonAttr(cnode, acos_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - acos_operator->SetOpType(mapper::OpType::ACOSAF); - - base_operators->push_back(std::move(acos_operator)); - return RET_OK; -} -REG_MAPPER(Acos, AcosMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.h deleted file mode 100644 index e831ebe5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/acos_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACOS_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACOS_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class AcosMapper : public OpMapper { - public: - AcosMapper() : OpMapper("Acos") {} - ~AcosMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACOS_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.cc deleted file mode 100644 index a1d5f91f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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 "mapper/acosh_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/acosh_operator.h" -#include "parser/onnx/onnx_acosh_parser.h" - -namespace mindspore { -namespace dpico { -STATUS AcoshMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto acosh_operator = std::make_unique(); - if (SetCommonAttr(cnode, acosh_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - acosh_operator->SetOpType(mapper::OpType::ACOSHAF); - - base_operators->push_back(std::move(acosh_operator)); - return RET_OK; -} -REG_MAPPER(Acosh, AcoshMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.h deleted file mode 100644 index 6c37f141..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/acosh_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACOSH_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACOSH_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class AcoshMapper : public OpMapper { - public: - AcoshMapper() : OpMapper("Acosh") {} - ~AcoshMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACOSH_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.cc deleted file mode 100644 index 60eaa663..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.cc +++ /dev/null @@ -1,172 +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 "mapper/activation_mapper.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "infer/cxx_api/activation.h" -#include "op/relu_operator.h" -#include "op/sigmoid_operator.h" -#include "op/tanh_operator.h" -#include "op/hswish_operator.h" -#include "op/clip_operator.h" -#include "op/elu_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr float kNum6 = 6.0; -mapper::AfOperator *ReluMapFunc(const api::SharedPtr &activation_prim) { - auto activation_operator = new (std::nothrow) mapper::ReluOperator(); - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "relu operator is nullptr. "; - return nullptr; - } - activation_operator->SetOpType(mapper::OpType::RELUAF); - if (activation_prim->GetAttr(ops::kAlpha) != nullptr) { - static_cast(activation_operator)->SetAlpha(activation_prim->get_alpha()); - } - return activation_operator; -} - -mapper::AfOperator *Relu6MapFunc(const api::SharedPtr &activation_prim) { - auto activation_operator = new (std::nothrow) mapper::ClipOperator(); - - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "relu operator is nullptr. "; - return nullptr; - } - static_cast(activation_operator)->SetClipCeil(kNum6); - if (activation_prim->GetAttr(ops::kAlpha) != nullptr) { - static_cast(activation_operator)->SetAlpha(activation_prim->get_alpha()); - } else { - static_cast(activation_operator)->SetClipFloor(0.0); - } - return activation_operator; -} - -mapper::AfOperator *HardTanhMapFunc(const api::SharedPtr &activation_prim) { - auto activation_operator = new (std::nothrow) mapper::ClipOperator(); - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "relu operator is nullptr. "; - return nullptr; - } - static_cast(activation_operator)->SetClipFloor(activation_prim->get_min_val()); - static_cast(activation_operator)->SetClipCeil(activation_prim->get_max_val()); - return activation_operator; -} - -mapper::AfOperator *SigmoidMapFunc(const api::SharedPtr &) { - auto activation_operator = new (std::nothrow) mapper::SigmoidOperator(); - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "sigmoid operator is nullptr. "; - return nullptr; - } - activation_operator->SetOpType(mapper::OpType::SIGMOIDAF); - return activation_operator; -} - -mapper::AfOperator *TanhMapFunc(const api::SharedPtr &) { - auto activation_operator = new (std::nothrow) mapper::TanhOperator(); - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "tanh operator is nullptr. "; - return nullptr; - } - return activation_operator; -} - -mapper::AfOperator *HswishMapFunc(const api::SharedPtr &activation_prim) { - auto activation_operator = new (std::nothrow) mapper::HswishOperator(); - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "hswish operator is nullptr. "; - return nullptr; - } - activation_operator->SetOpType(mapper::OpType::HSWISH); - if (activation_prim->GetAttr(dpico::kNegativeSlope) != nullptr) { - static_cast(activation_operator) - ->SetHswishSlope(api::GetValue(activation_prim->GetAttr(dpico::kNegativeSlope))); - } - return activation_operator; -} - -mapper::AfOperator *EluMapFunc(const api::SharedPtr &activation_prim) { - auto activation_operator = new (std::nothrow) mapper::EluOperator(); - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "elu operator is nullptr. "; - return nullptr; - } - activation_operator->SetOpType(mapper::OpType::ELU); - if (activation_prim->GetAttr(ops::kAlpha) != nullptr) { - static_cast(activation_operator) - ->SetEluAlpha(api::GetValue(activation_prim->GetAttr(ops::kAlpha))); - } - return activation_operator; -} - -using ActivationMapFunc = mapper::AfOperator *(*)(const api::SharedPtr &activation_prim); -const std::unordered_map kActivationMapFuncs = { - {ActivationType::RELU, &ReluMapFunc}, {ActivationType::LEAKY_RELU, &ReluMapFunc}, - {ActivationType::RELU6, &Relu6MapFunc}, {ActivationType::HARD_TANH, &HardTanhMapFunc}, - {ActivationType::SIGMOID, &SigmoidMapFunc}, {ActivationType::TANH, &TanhMapFunc}, - {ActivationType::HSWISH, &HswishMapFunc}, {ActivationType::ELU, &EluMapFunc}}; -} // namespace - -STATUS ActivationMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto activation_prim = api::utils::cast>(prim); - MS_ASSERT(activation_prim != nullptr); - - auto activation_type = activation_prim->get_activation_type(); - if (kActivationMapFuncs.find(activation_type) == kActivationMapFuncs.end()) { - MS_LOG(ERROR) << "cur activation map is unsupported " << activation_type << ". node name is " - << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto activation_map_func = kActivationMapFuncs.at(activation_type); - if (activation_map_func == nullptr) { - MS_LOG(ERROR) << "activation_map_func is nullptr. " << activation_type << ". node name is " - << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto activation_operator = activation_map_func(activation_prim); - if (activation_operator == nullptr) { - MS_LOG(ERROR) << "map " << cnode->fullname_with_scope() << " to operator failed."; - return RET_ERROR; - } - if (SetCommonAttr(cnode, activation_operator, output_cnodes) != RET_OK) { - delete activation_operator; - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (PushOfflineArgs(cnode, activation_operator, 1) != RET_OK) { - delete activation_operator; - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::unique_ptr(activation_operator)); - - return RET_OK; -} -REG_MAPPER(Activation, ActivationMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.h deleted file mode 100644 index 95907bf0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/activation_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACTIVATION_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACTIVATION_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ActivationMapper : public OpMapper { - public: - ActivationMapper() : OpMapper("Activation") {} - ~ActivationMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ACTIVATION_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.cc deleted file mode 100644 index 9646acf1..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.cc +++ /dev/null @@ -1,70 +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 "mapper/argmax_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "infer/cxx_api/arg_max_fusion.h" -#include "op/argmax_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ArgMaxMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto argmax_prim = api::utils::cast>(prim); - MS_ASSERT(argmax_prim != nullptr); - - auto argmax_operator = std::make_unique(); - if (argmax_operator == nullptr) { - MS_LOG(ERROR) << "argmax_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, argmax_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - argmax_operator->SetOpType(mapper::OpType::ARGMAX); - if (prim->GetAttr(ops::kAxis) != nullptr) { - argmax_operator->SetAxis(static_cast(argmax_prim->get_axis())); - argmax_operator->SetArgMaxHasAxis(true); - } - if (prim->GetAttr(ops::kTopK) != nullptr) { - argmax_operator->SetArgMaxTopK(static_cast(argmax_prim->get_top_k())); - } - if (prim->GetAttr(ops::kOutMaxValue) != nullptr) { - argmax_operator->SetArgMaxOutMaxVal(argmax_prim->get_out_max_value()); - } - if (prim->GetAttr(ops::kKeepDims) != nullptr) { - argmax_operator->SetKeepDims(argmax_prim->get_keep_dims()); - } - if (PushOfflineArgs(cnode, argmax_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(argmax_operator)); - return RET_OK; -} -REG_MAPPER(ArgMaxFusion, ArgMaxMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.h deleted file mode 100644 index bbcc8964..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/argmax_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ARGMAX_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ARGMAX_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ArgMaxMapper : public OpMapper { - public: - ArgMaxMapper() : OpMapper("ArgMax") {} - ~ArgMaxMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ARGMAX_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.cc deleted file mode 100644 index e0807ea2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.cc +++ /dev/null @@ -1,100 +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 "mapper/arithmetic_mapper.h" -#include -#include -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "common/anf_util.h" -#include "op/binary_math_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -const size_t kOfflineArgSize2 = 2; -const std::unordered_map kArithmeticOpMap = { - {"AddFusion", mapper::BinaryMathOp::ADD_OP}, - {"BiasAdd", mapper::BinaryMathOp::ADD_OP}, - {"SubFusion", mapper::BinaryMathOp::SUB_OP}, - {"DivFusion", mapper::BinaryMathOp::DIV_OP}, - {"MulFusion", mapper::BinaryMathOp::MUL_OP}, - {"Neg", mapper::BinaryMathOp::MUL_OP}, - {"Maximum", mapper::BinaryMathOp::MAX_OP}, - {"Minimum", mapper::BinaryMathOp::MIN_OP}, - {"SquaredDifference", mapper::BinaryMathOp::SQUARE_DIFF_OP}, - {"X_DIV_Y", mapper::BinaryMathOp::X_DIV_Y_OP}, - {"X_LOG_Y", mapper::BinaryMathOp::X_LOG_Y_OP}}; -} // namespace -STATUS ArithmeticMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto arithmetic_operator = std::make_unique(); - if (arithmetic_operator == nullptr) { - MS_LOG(ERROR) << "arithmetic_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, arithmetic_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - std::string op_type_name; - if (GetPrimitiveType(cnode, &op_type_name) != RET_OK) { - MS_LOG(ERROR) << "get cnode primitive type failed:" << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (kArithmeticOpMap.find(op_type_name) == kArithmeticOpMap.end()) { - MS_LOG(ERROR) << op_type_name << " there isn't corresponding mapper of " << op_type_name << " for now."; - return RET_ERROR; - } - auto binary_math_op = kArithmeticOpMap.at(op_type_name); - arithmetic_operator->SetBinaryMathOp(binary_math_op); - - if (CheckPrimitiveType(cnode, api::MakeShared())) { - arithmetic_operator->PushOfflineArgs(std::make_pair(std::vector{-1.0}, std::vector{})); - arithmetic_operator->PushOfflineArgs(std::make_pair(std::vector{}, std::vector{})); - } else { - if (PushOfflineArgs(cnode, arithmetic_operator.get(), kOfflineArgSize2) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } - - base_operators->push_back(std::move(arithmetic_operator)); - return RET_OK; -} -REG_MAPPER(AddFusion, ArithmeticMapper) -REG_MAPPER(BiasAdd, ArithmeticMapper) -REG_MAPPER(SubFusion, ArithmeticMapper) -REG_MAPPER(MulFusion, ArithmeticMapper) -REG_MAPPER(DivFusion, ArithmeticMapper) -REG_MAPPER(Maximum, ArithmeticMapper) -REG_MAPPER(Minimum, ArithmeticMapper) -REG_MAPPER(SquaredDifference, ArithmeticMapper) -REG_MAPPER(X_DIV_Y, ArithmeticMapper) -REG_MAPPER(X_LOG_Y, ArithmeticMapper) -REG_MAPPER(Neg, ArithmeticMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.h deleted file mode 100644 index 40117173..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/arithmetic_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ARITHMETIC_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ARITHMETIC_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ArithmeticMapper : public OpMapper { - public: - ArithmeticMapper() : OpMapper("Arithmetic") {} - ~ArithmeticMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ARITHMETIC_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.cc deleted file mode 100644 index 92ff6368..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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 "mapper/asinh_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/asinh_operator.h" -#include "parser/onnx/onnx_asinh_parser.h" - -namespace mindspore { -namespace dpico { -STATUS AsinhMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto asinh_operator = std::make_unique(); - if (SetCommonAttr(cnode, asinh_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - asinh_operator->SetOpType(mapper::OpType::ASINHAF); - - base_operators->push_back(std::move(asinh_operator)); - return RET_OK; -} -REG_MAPPER(Asinh, AsinhMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.h deleted file mode 100644 index 20f9282a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/asinh_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ASINH_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ASINH_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class AsinhMapper : public OpMapper { - public: - AsinhMapper() : OpMapper("Asinh") {} - ~AsinhMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ASINH_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.cc deleted file mode 100644 index 7e75c390..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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 "mapper/atanh_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/atanh_operator.h" -#include "parser/onnx/onnx_atanh_parser.h" - -namespace mindspore { -namespace dpico { -STATUS AtanhMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto atanh_operator = std::make_unique(); - if (SetCommonAttr(cnode, atanh_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - atanh_operator->SetOpType(mapper::OpType::ATANHAF); - - base_operators->push_back(std::move(atanh_operator)); - return RET_OK; -} -REG_MAPPER(Atanh, AtanhMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.h deleted file mode 100644 index 07b28573..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/atanh_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ATANH_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ATANH_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class AtanhMapper : public OpMapper { - public: - AtanhMapper() : OpMapper("Atanh") {} - ~AtanhMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ATANH_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.cc deleted file mode 100644 index 255ab517..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.cc +++ /dev/null @@ -1,164 +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 "mapper/batch_norm_mapper.h" -#include -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "op/batch_norm_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -// BatchNorm: {BNMeanIndex:2, BNVarIndex:3, ScaleFactorIndex:4} -STATUS SetBnDataInfo(const api::CNodePtr &cnode, mapper::BatchNormOperator *batch_norm_operator) { - if (batch_norm_operator == nullptr) { - MS_LOG(ERROR) << "batch_norm_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 2; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - MS_ASSERT(input_node != nullptr); - auto param_node = input_node->cast(); - if (param_node == nullptr || !param_node->has_default()) { - continue; - } - auto tensor_info = param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - if (i == kInputIndex2) { - batch_norm_operator->SetBnMeanDataPtr(data); - batch_norm_operator->SetBnMeanSize(tensor_info->DataSize()); - } else if (i == kInputIndex3) { - batch_norm_operator->SetBnVarDataPtr(data); - batch_norm_operator->SetBnVarSize(tensor_info->DataSize()); - } else if (i == kInputIndex4) { - batch_norm_operator->SetBnScalePtr(data); - batch_norm_operator->SetBnScaleSize(tensor_info->DataSize()); - } else { - MS_LOG(ERROR) << "batch_norm only support 3 offline inputs at most, but " << cnode->fullname_with_scope() - << " has " << i << " offline inputs."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "param node's tensor info is invalid. " << input_node->fullname_with_scope(); - return RET_ERROR; - } - } - - return RET_OK; -} -// FusedBatchNorm: {ScaleIndex:2, BiasIndex:3, MeanIndex:4, VarIndex:5} -STATUS SetFusedBnDataInfo(const api::CNodePtr &cnode, mapper::BatchNormOperator *batch_norm_operator) { - if (batch_norm_operator == nullptr) { - MS_LOG(ERROR) << "batch_norm_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 2; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - MS_ASSERT(input_node != nullptr); - auto param_node = input_node->cast(); - if (param_node == nullptr || !param_node->has_default()) { - continue; - } - auto tensor_info = param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - if (i == kInputIndex2) { - batch_norm_operator->SetBnScalePtr(data); - batch_norm_operator->SetBnScaleSize(tensor_info->DataSize()); - } else if (i == kInputIndex3) { - batch_norm_operator->SetBnBiasPtr(data); - batch_norm_operator->SetBnBiasSize(tensor_info->DataSize()); - } else if (i == kInputIndex4) { - batch_norm_operator->SetBnMeanDataPtr(data); - batch_norm_operator->SetBnMeanSize(tensor_info->DataSize()); - } else if (i == kInputIndex5) { - batch_norm_operator->SetBnVarDataPtr(data); - batch_norm_operator->SetBnVarSize(tensor_info->DataSize()); - } else { - MS_LOG(ERROR) << "fused batch_norm only support 4 offline inputs at most, but " << cnode->fullname_with_scope() - << " has " << i << " offline inputs."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "param node's tensor info is invalid. " << input_node->fullname_with_scope(); - return RET_ERROR; - } - } - - return RET_OK; -} -} // namespace -STATUS BatchNormMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto batch_norm_operator = std::make_unique(); - if (batch_norm_operator == nullptr) { - MS_LOG(ERROR) << "batch_norm_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, batch_norm_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - batch_norm_operator->SetOpType(mapper::OpType::BN); - if (prim->GetAttr(ops::kEpsilon) != nullptr) { - batch_norm_operator->SetBnEps(api::GetValue(prim->GetAttr(ops::kEpsilon))); - } - - if (prim->GetAttr(ops::kMomentum) != nullptr) { - auto momentum = api::GetValue(prim->GetAttr(ops::kMomentum)); - const float default_momentum_value = 0.9; - if (std::fabs(momentum - default_momentum_value) > std::numeric_limits::epsilon()) { - MS_LOG(INFO) << cnode->fullname_with_scope() << "'s momentum attr value " << momentum - << " is not equal to mapper default value 0.9. Note that mapper will ignore this value."; - } - } - - if (CheckPrimitiveType(cnode, api::MakeShared())) { - if (SetBnDataInfo(cnode, batch_norm_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set bn data info failed."; - return RET_ERROR; - } - } else { - if (SetFusedBnDataInfo(cnode, batch_norm_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set fused bn data info failed."; - return RET_ERROR; - } - } - if (PushOfflineArgs(cnode, batch_norm_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(batch_norm_operator)); - return RET_OK; -} -REG_MAPPER(BatchNorm, BatchNormMapper) -REG_MAPPER(FusedBatchNorm, BatchNormMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.h deleted file mode 100644 index fcfa93a8..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/batch_norm_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BATCH_NORM_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BATCH_NORM_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class BatchNormMapper : public OpMapper { - public: - BatchNormMapper() : OpMapper("BatchNorm") {} - ~BatchNormMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BATCH_NORM_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.cc deleted file mode 100644 index 13aa19af..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.cc +++ /dev/null @@ -1,114 +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 "mapper/bias_mapper.h" -#include -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "op/bias_operator.h" -#include "include/api/format.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetBiasDataInfo(const api::CNodePtr &cnode, mapper::BiasOperator *bias_operator) { - if (bias_operator == nullptr) { - MS_LOG(ERROR) << "bias_operator is nullptr."; - return RET_ERROR; - } - if (cnode->size() == kInputIndex3) { - auto input_anode = cnode->input(kInputIndex2); - MS_ASSERT(input_anode != nullptr); - auto param_node = input_anode->cast(); - if (param_node == nullptr || !param_node->has_default()) { - MS_LOG(DEBUG) << "only parameter node needs to set BiasPtr"; - return RET_OK; - } - auto tensor_info = param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - bias_operator->SetBiasPtr(data); - ShapeVector shape_vector; - if (GetShapeVectorFromParameter(param_node, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "get shape vector from parameter failed. " << param_node->fullname_with_scope(); - return RET_ERROR; - } - std::vector shape; - (void)std::transform(shape_vector.begin(), shape_vector.end(), std::back_inserter(shape), - [](int64_t dim) { return static_cast(dim); }); - bias_operator->SetBiasShapeVec(shape); - } else { - MS_LOG(ERROR) << "param node's tensor info is invalid. " << param_node->fullname_with_scope(); - return RET_ERROR; - } - } - - return RET_OK; -} -} // namespace -STATUS BiasMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto bias_operator = std::make_unique(); - if (bias_operator == nullptr) { - MS_LOG(ERROR) << "bias_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, bias_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (prim->GetAttr(ops::kAxis) != nullptr) { - bias_operator->SetAxis(static_cast(api::GetValue(prim->GetAttr(ops::kAxis)))); - } else if (CheckPrimitiveType(cnode, api::MakeShared())) { - auto format = api::GetValue(prim->GetAttr(ops::kFormat)); - if (format == static_cast(mindspore::Format::NCHW)) { - bias_operator->SetAxis(1); - } else if (format == static_cast(mindspore::Format::NHWC)) { - bias_operator->SetAxis(-1); - } else { - MS_LOG(ERROR) << "invalid format: " << format; - return RET_ERROR; - } - } - if (prim->GetAttr(dpico::kNumAxes) != nullptr) { - bias_operator->SetBiasNumAxes(static_cast(api::GetValue(prim->GetAttr(dpico::kNumAxes)))); - } - - if (SetBiasDataInfo(cnode, bias_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set bias data info failed."; - return RET_ERROR; - } - - bias_operator->SetOpType(mapper::OpType::BIAS); - base_operators->push_back(std::move(bias_operator)); - return RET_OK; -} -REG_MAPPER(Bias, BiasMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.h deleted file mode 100644 index 5dc5b65e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/bias_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BIAS_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BIAS_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class BiasMapper : public OpMapper { - public: - BiasMapper() : OpMapper("Bias") {} - ~BiasMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BIAS_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.cc deleted file mode 100644 index b4e8bdfe..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.cc +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright 2022 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 "mapper/bitshift_mapper.h" -#include -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/bit_shift_operator.h" -#include "parser/onnx/onnx_bitshift_parser.h" - -namespace mindspore { -namespace dpico { -STATUS BitShiftMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto bitshift_operator = std::make_unique(); - if (SetCommonAttr(cnode, bitshift_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - bitshift_operator->SetOpType(mapper::OpType::BIT_SHIFT); - if (prim->GetAttr("direction") != nullptr) { - if (api::GetValue(prim->GetAttr("direction")) == "LEFT") { - bitshift_operator->SetBitShiftDirection(mapper::BIT_SHIFT_LEFT); - } else if (api::GetValue(prim->GetAttr("direction")) == "RIGHT") { - bitshift_operator->SetBitShiftDirection(mapper::BIT_SHIFT_RIGHT); - } else { - MS_LOG(ERROR) << "set bitshift direction failed"; - return RET_ERROR; - } - } - - base_operators->push_back(std::move(bitshift_operator)); - return RET_OK; -} -REG_MAPPER(BitShift, BitShiftMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.h deleted file mode 100644 index 95e8dbe0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/bitshift_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BITSHIFT_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BITSHIFT_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class BitShiftMapper : public OpMapper { - public: - BitShiftMapper() : OpMapper("BitShift") {} - ~BitShiftMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BITSHIFT_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.cc deleted file mode 100644 index cef1761b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.cc +++ /dev/null @@ -1,50 +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 "mapper/bnll_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "op/bnll_operator.h" - -namespace mindspore { -namespace dpico { -STATUS BnllMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto bnll_operator = std::make_unique(); - if (bnll_operator == nullptr) { - MS_LOG(ERROR) << "bnll_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, bnll_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - bnll_operator->SetOpType(mapper::OpType::BNLL); - base_operators->push_back(std::move(bnll_operator)); - return RET_OK; -} -REG_MAPPER(Bnll, BnllMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.h deleted file mode 100644 index d8f5846c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/bnll_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BNLL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BNLL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class BnllMapper : public OpMapper { - public: - BnllMapper() : OpMapper("Bnll") {} - ~BnllMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_BNLL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.cc deleted file mode 100644 index 749da2e2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.cc +++ /dev/null @@ -1,49 +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 "mapper/cast_mapper.h" -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/cast_operator.h" - -namespace mindspore { -namespace dpico { -STATUS CastMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto cast_operator = std::make_unique(); - if (cast_operator == nullptr) { - MS_LOG(ERROR) << "cast_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, cast_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - base_operators->push_back(std::move(cast_operator)); - return RET_OK; -} -REG_MAPPER(Cast, CastMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.h deleted file mode 100644 index 570835a2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/cast_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CAST_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CAST_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class CastMapper : public OpMapper { - public: - CastMapper() : OpMapper("Cast") {} - ~CastMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CAST_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.cc deleted file mode 100644 index 940270a6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.cc +++ /dev/null @@ -1,61 +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 "mapper/clip_mapper.h" -#include -#include -#include -#include "infer/clip.h" -#include "op/clip_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ClipMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto clip_prim = api::utils::cast>(prim); - MS_ASSERT(clip_prim != nullptr); - - auto clip_operator = std::make_unique(); - if (clip_operator == nullptr) { - MS_LOG(ERROR) << "clip_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, clip_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (prim->GetAttr(ops::kMax) != nullptr) { - clip_operator->SetClipCeil(clip_prim->get_max()); - } - if (prim->GetAttr(ops::kMin) != nullptr) { - clip_operator->SetClipFloor(clip_prim->get_min()); - } - if (PushOfflineArgs(cnode, clip_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(clip_operator)); - return RET_OK; -} -REG_MAPPER(Clip, ClipMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.h deleted file mode 100644 index c5165e6a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/clip_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CLIP_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CLIP_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ClipMapper : public OpMapper { - public: - ClipMapper() : OpMapper("Clip") {} - ~ClipMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CLIP_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.cc deleted file mode 100644 index a0b45a17..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2021-2023 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 "mapper/concat_mapper.h" -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/concat_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ConcatMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto concat_prim = api::utils::cast>(prim); - MS_ASSERT(concat_prim != nullptr); - - auto concat_operator = std::make_unique(); - if (concat_operator == nullptr) { - MS_LOG(ERROR) << "concat_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, concat_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - concat_operator->SetOpType(mapper::OpType::CONCAT); - if (concat_prim->GetAttr(ops::kAxis) != nullptr) { - concat_operator->SetAxis(static_cast(concat_prim->get_axis())); - } - - base_operators->push_back(std::move(concat_operator)); - return RET_OK; -} -REG_MAPPER(Concat, ConcatMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.h deleted file mode 100644 index a10b41f7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/concat_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CONCAT_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CONCAT_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ConcatMapper : public OpMapper { - public: - ConcatMapper() : OpMapper("Concat") {} - ~ConcatMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CONCAT_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.cc deleted file mode 100644 index 06e62864..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.cc +++ /dev/null @@ -1,175 +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 "mapper/conv_mapper.h" -#include -#include -#include -#include "common/op_enum.h" -#include "infer/cxx_api/conv2d_fusion.h" -#include "op/conv_operator.h" -#include "op/depthwiseconv_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr int kconvKernelSize = 2; -constexpr int kconvStrideSize = 2; -constexpr int kconvDilationSize = 2; -constexpr int kconvPadListSize = 4; -struct ConvAttr { - std::vector kernel_size; - std::vector stride; - std::vector dilation; - int64_t group{1}; - int64_t out_channel{1}; - PadMode pad_mode{PadMode::PAD}; -}; -STATUS GetConvAttrFromPrimitive(ConvAttr *conv_attr, const api::SharedPtr &conv_prim) { - if (conv_attr == nullptr) { - MS_LOG(ERROR) << "conv_attr is nullptr."; - return RET_ERROR; - } - if (conv_prim->GetAttr(ops::kKernelSize) != nullptr) { - conv_attr->kernel_size = conv_prim->get_kernel_size(); - } else { - MS_LOG(ERROR) << "kernel_size attr doesn't exist."; - return RET_ERROR; - } - if (conv_prim->GetAttr(ops::kStride) != nullptr) { - conv_attr->stride = conv_prim->get_stride(); - } else { - MS_LOG(ERROR) << "stride attr doesn't exist."; - return RET_ERROR; - } - if (conv_prim->GetAttr(ops::kDilation) != nullptr) { - conv_attr->dilation = conv_prim->get_dilation(); - } else { - MS_LOG(ERROR) << "dilation attr doesn't exist."; - return RET_ERROR; - } - if (conv_prim->GetAttr(ops::kGroup) != nullptr) { - conv_attr->group = conv_prim->get_group(); - } else { - MS_LOG(ERROR) << "group attr doesn't exist."; - return RET_ERROR; - } - if (conv_prim->GetAttr(ops::kPadMode) != nullptr) { - conv_attr->pad_mode = conv_prim->get_pad_mode(); - } else { - MS_LOG(ERROR) << "pad_mode attr doesn't exist."; - return RET_ERROR; - } - if (conv_prim->GetAttr(ops::kOutChannel) != nullptr) { - conv_attr->out_channel = conv_prim->get_out_channel(); - } else { - MS_LOG(ERROR) << "out_channel attr doesn't exist."; - return RET_ERROR; - } - return RET_OK; -} -} // namespace -STATUS ConvMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto conv_prim = api::utils::cast>(prim); - MS_ASSERT(conv_prim != nullptr); - ConvAttr conv_attr; - if (GetConvAttrFromPrimitive(&conv_attr, conv_prim) != RET_OK) { - MS_LOG(ERROR) << "get conv attr from primitive failed."; - return RET_ERROR; - } - - if (conv_attr.kernel_size.size() != kconvKernelSize) { - MS_LOG(ERROR) << "kernel_size should be 2 dims, which is " << conv_attr.kernel_size.size(); - return RET_ERROR; - } - if (conv_attr.stride.size() != kconvStrideSize) { - MS_LOG(ERROR) << "stride should be 2 dims, which is " << conv_attr.stride.size(); - return RET_ERROR; - } - if (conv_attr.dilation.size() != kconvDilationSize) { - MS_LOG(ERROR) << "dilation should be 2 dims, which is " << conv_attr.dilation.size(); - return RET_ERROR; - } - - std::unique_ptr conv_operator; - if (conv_prim->GetAttr(ops::kIsDepthWise) != nullptr && api::GetValue(conv_prim->GetAttr(ops::kIsDepthWise))) { - conv_operator = std::make_unique(); - if (conv_operator == nullptr) { - MS_LOG(ERROR) << "conv_operator is nullptr."; - return RET_ERROR; - } - conv_operator->SetGroup(static_cast(conv_attr.group)); - } else { - conv_operator = std::make_unique(); - if (conv_operator == nullptr) { - MS_LOG(ERROR) << "conv_operator is nullptr."; - return RET_ERROR; - } - conv_operator->SetGroup(static_cast(conv_attr.group)); - } - - if (SetCommonAttr(cnode, conv_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - conv_operator->SetOpType(mapper::OpType::CONVOLUTION); - - conv_operator->SetOutputChannel(static_cast(conv_attr.out_channel)); - conv_operator->SetKernelHeight(static_cast(conv_attr.kernel_size[0])); - conv_operator->SetKernelWidth(static_cast(conv_attr.kernel_size[1])); - conv_operator->SetStrideHeight(static_cast(conv_attr.stride[0])); - conv_operator->SetStrideWidth(static_cast(conv_attr.stride[1])); - conv_operator->SetDilationHeight(static_cast(conv_attr.dilation[0])); - conv_operator->SetDilationWidth(static_cast(conv_attr.dilation[1])); - if (conv_attr.pad_mode == PadMode::PAD) { - auto pad_list = conv_prim->get_pad_list(); - if (pad_list.size() != kconvPadListSize) { - MS_LOG(ERROR) << "pad_list size is invalid. " << pad_list.size(); - return RET_ERROR; - } - conv_operator->SetPadUp(static_cast(pad_list[0])); - conv_operator->SetPadDown(static_cast(pad_list[1])); - conv_operator->SetPadLeft(static_cast(pad_list[kAxis2])); - conv_operator->SetPadRight(static_cast(pad_list[kAxis3])); - } else if (conv_attr.pad_mode == PadMode::SAME) { - conv_operator->SetAutoPadType(mapper::AutoPadType::PAD_SAME_UPPER); - } else if (conv_attr.pad_mode == PadMode::VALID) { - conv_operator->SetAutoPadType(mapper::AutoPadType::PAD_VALID); - } else { - MS_LOG(ERROR) << "Non supported pad mode. " << conv_attr.pad_mode; - return RET_ERROR; - } - - if (SetConvFcDataInfo(cnode, conv_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set conv data info failed."; - return RET_ERROR; - } - if (PushOfflineArgs(cnode, conv_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(conv_operator)); - return RET_OK; -} -REG_MAPPER(Conv2DFusion, ConvMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.h deleted file mode 100644 index c08beace..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/conv_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CONV_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CONV_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ConvMapper : public OpMapper { - public: - ConvMapper() : OpMapper("Convolution") {} - ~ConvMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CONV_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.cc deleted file mode 100644 index b81e4085..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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 "mapper/cosh_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/cosh_operator.h" -#include "parser/onnx/onnx_cosh_parser.h" - -namespace mindspore { -namespace dpico { -STATUS CoshMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto cosh_operator = std::make_unique(); - if (SetCommonAttr(cnode, cosh_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - cosh_operator->SetOpType(mapper::OpType::COSHAF); - - base_operators->push_back(std::move(cosh_operator)); - return RET_OK; -} -REG_MAPPER(Cosh, CoshMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.h deleted file mode 100644 index 6831feb9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/cosh_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_COSH_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_COSH_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class CoshMapper : public OpMapper { - public: - CoshMapper() : OpMapper("Cosh") {} - ~CoshMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_COSH_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.cc deleted file mode 100644 index dd307708..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.cc +++ /dev/null @@ -1,64 +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 "mapper/crop_mapper.h" -#include -#include -#include -#include -#include "infer/crop.h" -#include "op/crop_operator.h" - -namespace mindspore { -namespace dpico { -STATUS CropMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto crop_prim = api::utils::cast>(prim); - MS_ASSERT(crop_prim != nullptr); - - auto crop_operator = std::make_unique(); - if (crop_operator == nullptr) { - MS_LOG(ERROR) << "crop_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, crop_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - crop_operator->SetOpType(mapper::OpType::CROP); - if (prim->GetAttr(ops::kAxis) != nullptr) { - crop_operator->SetAxis(static_cast(crop_prim->get_axis())); - } - if (prim->GetAttr(ops::kOffsets) != nullptr) { - auto offsets = crop_prim->get_offsets(); - std::vector offset_vec{}; - (void)std::transform(offsets.begin(), offsets.end(), std::back_inserter(offset_vec), - [](const int64_t offset) { return static_cast(offset); }); - crop_operator->SetOrigOffsetVec(offset_vec); - } - - base_operators->push_back(std::move(crop_operator)); - return RET_OK; -} -REG_MAPPER(Crop, CropMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.h deleted file mode 100644 index b43689e3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/crop_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CROP_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CROP_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class CropMapper : public OpMapper { - public: - CropMapper() : OpMapper("Crop") {} - ~CropMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CROP_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.cc deleted file mode 100644 index 997975b3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.cc +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Copyright 2022 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 "mapper/custom_mapper.h" -#include -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/custom_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace dpico { -namespace { -custom::ExtendedParam GetParamFromAttrs(const api::SharedPtr &custom_prim, int index) { - custom::ExtendedParam custom_param; - if (custom_prim == nullptr) { - MS_LOG(ERROR) << "custom_prim is nullptr."; - return custom_param; - } - auto name_ptr = custom_prim->GetAttr("name" + std::to_string(index)); - if (name_ptr != nullptr) { - custom_param.name = api::GetValue(name_ptr); - } - auto type_ptr = custom_prim->GetAttr("type" + std::to_string(index)); - if (type_ptr != nullptr) { - custom_param.type = static_cast(api::GetValue(type_ptr)); - } - auto f_ptr = custom_prim->GetAttr("f" + std::to_string(index)); - if (f_ptr != nullptr) { - custom_param.paramFloat = api::GetValue(f_ptr); - } - auto i_ptr = custom_prim->GetAttr("i" + std::to_string(index)); - if (i_ptr != nullptr) { - custom_param.paramInt = api::GetValue(i_ptr); - } - auto s_ptr = custom_prim->GetAttr("s" + std::to_string(index)); - if (s_ptr != nullptr) { - custom_param.paramString = api::GetValue(s_ptr); - } - auto floats_ptr = custom_prim->GetAttr("floats" + std::to_string(index)); - if (floats_ptr != nullptr) { - custom_param.paramFloats = api::GetValue>(floats_ptr); - } - auto ints_ptr = custom_prim->GetAttr("ints" + std::to_string(index)); - if (ints_ptr != nullptr) { - custom_param.paramInts = api::GetValue>(ints_ptr); - } - auto strings_ptr = custom_prim->GetAttr("strings" + std::to_string(index)); - if (strings_ptr != nullptr) { - custom_param.paramStrings = api::GetValue>(strings_ptr); - } - return custom_param; -} -} // namespace - -STATUS CustomMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto custom_prim = api::utils::cast>(prim); - MS_CHECK_TRUE_MSG(custom_prim != nullptr, RET_ERROR, "custom_prim is nullptr"); - auto custom_operator = std::make_unique(); - if (SetCommonAttr(cnode, custom_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - custom_operator->SetOpType(mapper::OpType::CUSTOM); - if (prim->GetAttr(kExtendedOpType) != nullptr) { - custom_operator->SetExtendedOpType(api::GetValue(prim->GetAttr(kExtendedOpType))); - } - - std::vector attr_vec; - custom::ExtendedAttr extended_attrs; - - int custom_param_size = 0; - auto custom_param_size_attr = custom_prim->GetAttr(kCustomParamSize); - if (custom_param_size_attr != nullptr) { - custom_param_size = static_cast(api::GetValue(custom_param_size_attr)); - } - if (custom_param_size == 0) { - MS_LOG(INFO) << "no custom param attr found."; - return RET_OK; - } - for (int i = 0; i < custom_param_size; i++) { - extended_attrs.SetExtendedParam(GetParamFromAttrs(custom_prim, i)); - attr_vec.emplace_back(extended_attrs); - } - custom_operator->SetExtendedAttrs(attr_vec); - base_operators->push_back(std::move(custom_operator)); - return RET_OK; -} -REG_MAPPER(Custom, CustomMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.h deleted file mode 100644 index a39a583f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/custom_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CUSTOM_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CUSTOM_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class CustomMapper : public OpMapper { - public: - CustomMapper() : OpMapper("Custom") {} - ~CustomMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_CUSTOM_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.cc deleted file mode 100644 index 1f75b92a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.cc +++ /dev/null @@ -1,81 +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 "mapper/decbbox_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/dec_bbox_operator.h" -#include "infer/custom.h" -#include "parser/detection_output_param_helper.h" - -namespace mindspore { -namespace dpico { -STATUS DecBBoxMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto custom_prim = api::utils::cast>(prim); - MS_CHECK_TRUE_MSG(custom_prim != nullptr, RET_ERROR, "custom_prim is nullptr"); - auto decbbox_operator = std::make_unique(); - if (decbbox_operator == nullptr) { - MS_LOG(ERROR) << "decbbox_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, decbbox_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - decbbox_operator->SetOpType(mapper::OpType::DECBBOX); - if (prim->GetAttr(kNumAnchors) != nullptr) { - decbbox_operator->SetNumAnchors(static_cast(api::GetValue(prim->GetAttr(kNumAnchors)))); - } - if (prim->GetAttr(kNumBboxesPerGrid) != nullptr) { - decbbox_operator->SetNumBboxesPerGrid( - static_cast(api::GetValue(prim->GetAttr(kNumBboxesPerGrid)))); - } - if (prim->GetAttr(kNumCoords) != nullptr) { - decbbox_operator->SetNumCoords(static_cast(api::GetValue(prim->GetAttr(kNumCoords)))); - } - if (prim->GetAttr(kNumClasses) != nullptr) { - decbbox_operator->SetNumClasses(static_cast(api::GetValue(prim->GetAttr(kNumClasses)))); - } - if (prim->GetAttr(kNumGridsHeight) != nullptr) { - decbbox_operator->SetNumGridsHeight(static_cast(api::GetValue(prim->GetAttr(kNumGridsHeight)))); - } - if (prim->GetAttr(kNumGridsWidth) != nullptr) { - decbbox_operator->SetNumGridsWidth(static_cast(api::GetValue(prim->GetAttr(kNumGridsWidth)))); - } - std::vector param_vec; - if (GetDetectionOutputParamFromAttrs(¶m_vec, custom_prim) != RET_OK) { - MS_LOG(ERROR) << "get detection output param from attrs failed."; - return RET_ERROR; - } - if (param_vec.size() == 1) { - decbbox_operator->SetDecBboxParam(param_vec.at(0)); - } - base_operators->push_back(std::move(decbbox_operator)); - return RET_OK; -} -REG_MAPPER(DecBBox, DecBBoxMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.h deleted file mode 100644 index b7f2c31a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/decbbox_mapper.h +++ /dev/null @@ -1,38 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DECBBOX_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DECBBOX_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" -#include "op/dec_bbox_operator.h" - -namespace mindspore { -namespace dpico { -class DecBBoxMapper : public OpMapper { - public: - DecBBoxMapper() : OpMapper("DecBBox") {} - ~DecBBoxMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DECBBOX_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.cc deleted file mode 100644 index 75ddb12a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.cc +++ /dev/null @@ -1,106 +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 "mapper/deconv_mapper.h" -#include -#include -#include -#include "common/op_enum.h" -#include "infer/cxx_api/conv2d_transpose_fusion.h" -#include "op/deconv_operator.h" - -namespace mindspore { -namespace dpico { -constexpr int kDeconvKernelSize = 2; -constexpr int kDeconvStrideSize = 2; -constexpr int kDeconvDilationSize = 2; -constexpr int kDeconvPadListSize = 4; -STATUS DeconvMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto deconv_prim = api::utils::cast>(prim); - MS_ASSERT(deconv_prim != nullptr); - auto kernel_size = deconv_prim->get_kernel_size(); - auto stride = deconv_prim->get_stride(); - auto dilation = deconv_prim->get_dilation(); - auto pad_mode = deconv_prim->get_pad_mode(); - - if (kernel_size.size() != kDeconvKernelSize) { - MS_LOG(ERROR) << "kernel_size should be 2 dims, which is " << kernel_size.size(); - return RET_ERROR; - } - if (stride.size() != kDeconvStrideSize) { - MS_LOG(ERROR) << "stride should be 2 dims, which is " << stride.size(); - return RET_ERROR; - } - if (dilation.size() != kDeconvDilationSize) { - MS_LOG(ERROR) << "dilation should be 2 dims, which is " << dilation.size(); - return RET_ERROR; - } - - auto deconv_operator = std::make_unique(); - if (deconv_operator == nullptr) { - MS_LOG(ERROR) << "deconv_operator is nullptr."; - return RET_ERROR; - } - deconv_operator->SetGroup(static_cast(deconv_prim->get_group())); - - if (SetCommonAttr(cnode, deconv_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - deconv_operator->SetOpType(mapper::OpType::DECONVOLUTION); - deconv_operator->SetOutputChannel(static_cast(deconv_prim->get_out_channel())); - deconv_operator->SetKernelHeight(static_cast(kernel_size[0])); - deconv_operator->SetKernelWidth(static_cast(kernel_size[1])); - deconv_operator->SetStrideHeight(static_cast(stride[0])); - deconv_operator->SetStrideWidth(static_cast(stride[1])); - deconv_operator->SetDilationHeight(static_cast(dilation[0])); - deconv_operator->SetDilationWidth(static_cast(dilation[1])); - if (pad_mode == PadMode::PAD) { - auto pad_list = deconv_prim->get_pad_list(); - if (pad_list.size() != kDeconvPadListSize) { - MS_LOG(ERROR) << "pad_list size is invalid. " << pad_list.size(); - return RET_ERROR; - } - deconv_operator->SetPadUp(static_cast(pad_list[0])); - deconv_operator->SetPadDown(static_cast(pad_list[1])); - deconv_operator->SetPadLeft(static_cast(pad_list[kAxis2])); - deconv_operator->SetPadRight(static_cast(pad_list[kAxis3])); - } else if (pad_mode == PadMode::SAME) { - deconv_operator->SetAutoPadType(mapper::AutoPadType::PAD_SAME_UPPER); - } else if (pad_mode == PadMode::VALID) { - deconv_operator->SetAutoPadType(mapper::AutoPadType::PAD_VALID); - } else { - MS_LOG(ERROR) << "Non supported pad mode. " << pad_mode; - return RET_ERROR; - } - - if (SetConvFcDataInfo(cnode, deconv_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set deconv data info failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(deconv_operator)); - return RET_OK; -} -REG_MAPPER(Conv2dTransposeFusion, DeconvMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.h deleted file mode 100644 index 09e28add..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/deconv_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DECONV_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DECONV_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class DeconvMapper : public OpMapper { - public: - DeconvMapper() : OpMapper("Deconvolution") {} - ~DeconvMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DECONV_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.cc deleted file mode 100644 index cbb1d1c3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.cc +++ /dev/null @@ -1,81 +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 "mapper/detection_output_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/detection_output_operator.h" -#include "parser/detection_output_param_helper.h" - -namespace mindspore { -namespace dpico { -STATUS DetectionOutputMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto custom_prim = api::utils::cast>(prim); - MS_CHECK_TRUE_MSG(custom_prim != nullptr, RET_ERROR, "custom_prim is nullptr"); - auto detection_output_operator = std::make_unique(); - if (detection_output_operator == nullptr) { - MS_LOG(ERROR) << "detection_output_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, detection_output_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - detection_output_operator->SetOpType(mapper::OpType::DETECTION_OUTPUT); - if (prim->GetAttr(kNumAnchors) != nullptr) { - detection_output_operator->SetNumAnchors(static_cast(api::GetValue(prim->GetAttr(kNumAnchors)))); - } - if (prim->GetAttr(kNumBboxesPerGrid) != nullptr) { - detection_output_operator->SetNumBboxesPerGrid( - static_cast(api::GetValue(prim->GetAttr(kNumBboxesPerGrid)))); - } - if (prim->GetAttr(kNumCoords) != nullptr) { - detection_output_operator->SetNumCoords(static_cast(api::GetValue(prim->GetAttr(kNumCoords)))); - } - if (prim->GetAttr(kNumClasses) != nullptr) { - detection_output_operator->SetNumClasses(static_cast(api::GetValue(prim->GetAttr(kNumClasses)))); - } - if (prim->GetAttr(kNumGridsHeight) != nullptr) { - detection_output_operator->SetNumGridsHeight( - static_cast(api::GetValue(prim->GetAttr(kNumGridsHeight)))); - } - if (prim->GetAttr(kNumGridsWidth) != nullptr) { - detection_output_operator->SetNumGridsWidth( - static_cast(api::GetValue(prim->GetAttr(kNumGridsWidth)))); - } - - std::vector param_vec; - if (GetDetectionOutputParamFromAttrs(¶m_vec, custom_prim) != RET_OK) { - MS_LOG(ERROR) << "get detection output param from attrs failed."; - return RET_ERROR; - } - detection_output_operator->SetDetectionOutputParamVec(param_vec); - base_operators->push_back(std::move(detection_output_operator)); - return RET_OK; -} -REG_MAPPER(DetectionOutput, DetectionOutputMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.h deleted file mode 100644 index d98d3973..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/detection_output_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DETECTION_OUTPUT_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DETECTION_OUTPUT_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class DetectionOutputMapper : public OpMapper { - public: - DetectionOutputMapper() : OpMapper("DetectionOutput") {} - ~DetectionOutputMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_DETECTION_OUTPUT_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.cc deleted file mode 100644 index 60bbb4b1..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.cc +++ /dev/null @@ -1,76 +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 "mapper/eltwise_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/eltwise_operator.h" -#include "mindapi/base/types.h" - -namespace mindspore { -namespace dpico { -STATUS EltwiseMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto eltwise_operator = std::make_unique(); - if (eltwise_operator == nullptr) { - MS_LOG(ERROR) << "eltwise_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, eltwise_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - eltwise_operator->SetOpType(mapper::OpType::ELTWISE); - if (prim->GetAttr(ops::kMode) == nullptr) { - MS_LOG(ERROR) << "eltwise op should have mode attr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto eltwise_mode = static_cast(api::GetValue(prim->GetAttr(ops::kMode))); - switch (eltwise_mode) { - case mindspore::EltwiseMode::PROD: - eltwise_operator->SetEltwiseOp(mapper::BinaryMathOp::MUL_OP); - break; - case mindspore::EltwiseMode::SUM: - eltwise_operator->SetEltwiseOp(mapper::BinaryMathOp::SUM_OP); - break; - case mindspore::EltwiseMode::MAXIMUM: - eltwise_operator->SetEltwiseOp(mapper::BinaryMathOp::MAX_OP); - break; - default: - MS_LOG(ERROR) << "Eltwise parse params fail, unsupported operation: " << eltwise_mode; - return RET_ERROR; - } - - if (prim->GetAttr(dpico::kCoeffs) != nullptr) { - eltwise_operator->SetEltCoeffVec(api::GetValue>(prim->GetAttr(dpico::kCoeffs))); - } - - base_operators->push_back(std::move(eltwise_operator)); - return RET_OK; -} -REG_MAPPER(Eltwise, EltwiseMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.h deleted file mode 100644 index c2d07900..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/eltwise_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ELTWISE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ELTWISE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class EltwiseMapper : public OpMapper { - public: - EltwiseMapper() : OpMapper("Eltwise") {} - ~EltwiseMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ELTWISE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.cc deleted file mode 100644 index ff4fc346..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.cc +++ /dev/null @@ -1,67 +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 "mapper/exp_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "infer/cxx_api/exp_fusion.h" -#include "op/exp_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ExpMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto exp_prim = api::utils::cast>(prim); - MS_ASSERT(exp_prim != nullptr); - - auto exp_operator = std::make_unique(); - if (exp_operator == nullptr) { - MS_LOG(ERROR) << "exp_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, exp_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - exp_operator->SetOpType(mapper::OpType::EXP); - if (prim->GetAttr(ops::kBase) != nullptr) { - exp_operator->SetExpBase(exp_prim->get_base()); - } - if (prim->GetAttr(ops::kScale) != nullptr) { - exp_operator->SetExpScale(exp_prim->get_scale()); - } - if (prim->GetAttr(ops::kShift) != nullptr) { - exp_operator->SetExpShift(exp_prim->get_shift()); - } - if (PushOfflineArgs(cnode, exp_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(exp_operator)); - return RET_OK; -} -REG_MAPPER(ExpFusion, ExpMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.h deleted file mode 100644 index c190c8df..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/exp_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_EXP_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_EXP_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ExpMapper : public OpMapper { - public: - ExpMapper() : OpMapper("Exp") {} - ~ExpMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_EXP_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.cc deleted file mode 100644 index 953005ce..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.cc +++ /dev/null @@ -1,61 +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 "mapper/extract_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/extract_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ExtractMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto extract_operator = std::make_unique(); - if (extract_operator == nullptr) { - MS_LOG(ERROR) << "extract_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, extract_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - extract_operator->SetOpType(mapper::OpType::EXTRACT); - if (prim->GetAttr(dpico::kSlicePointBegin) != nullptr) { - extract_operator->SetSlicePointBegin( - static_cast(api::GetValue(prim->GetAttr(dpico::kSlicePointBegin)))); - } - if (prim->GetAttr(dpico::kSlicePointEnd) != nullptr) { - extract_operator->SetSlicePointEnd( - static_cast(api::GetValue(prim->GetAttr(dpico::kSlicePointEnd)))); - } - if (prim->GetAttr(ops::kAxis) != nullptr) { - extract_operator->SetAxis(static_cast(api::GetValue(prim->GetAttr(ops::kAxis)))); - } - base_operators->push_back(std::move(extract_operator)); - return RET_OK; -} -REG_MAPPER(Extract, ExtractMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.h deleted file mode 100644 index 26192368..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/extract_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_EXTRACT_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_EXTRACT_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ExtractMapper : public OpMapper { - public: - ExtractMapper() : OpMapper("Extract") {} - ~ExtractMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_EXTRACT_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.cc deleted file mode 100644 index d057797a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.cc +++ /dev/null @@ -1,96 +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 "mapper/fc_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/fc_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetNumOutput(const api::CNodePtr &cnode, const api::PrimitivePtr &prim, mapper::FcOperator *fc_operator) { - if (fc_operator == nullptr) { - MS_LOG(ERROR) << "fc_operator is nullptr."; - return RET_ERROR; - } - std::vector output_shapes; - if (GetOutputShapesFromCNode(cnode, &output_shapes) != RET_OK) { - MS_LOG(ERROR) << "get node shape failed"; - return RET_ERROR; - } - if (output_shapes.size() != 1) { - MS_LOG(ERROR) << "fc should have single output, but in fact it has " << output_shapes.size() << " outputs."; - return RET_ERROR; - } - auto output_shape = output_shapes.at(0); - if (prim->GetAttr(kNumOutput) != nullptr) { - uint32_t num_output = static_cast(api::GetValue(prim->GetAttr(kNumOutput))); - if (output_shape.back() != num_output) { - MS_LOG(ERROR) << "num output attr isn't matched with fc output shape."; - return RET_ERROR; - } - fc_operator->SetNumOutput(num_output); - } else { - fc_operator->SetNumOutput(static_cast(output_shape.back())); - } - return RET_OK; -} -} // namespace -STATUS FCMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto fc_operator = std::make_unique(); - if (fc_operator == nullptr) { - MS_LOG(ERROR) << "fc_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, fc_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - fc_operator->SetOpType(mapper::OpType::INNERPRODUCT); - if (prim->GetAttr(ops::kAxis) != nullptr) { - fc_operator->SetAxis(static_cast(api::GetValue(prim->GetAttr(ops::kAxis)))); - } - if (prim->GetAttr(ops::kTransposeB) != nullptr) { - // note that this value of fc operator is opposite to kTransposeB - fc_operator->SetFcTransposeFlag(!api::GetValue(prim->GetAttr(ops::kTransposeB))); - } - if (SetNumOutput(cnode, prim, fc_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set num output failed."; - return RET_ERROR; - } - if (SetConvFcDataInfo(cnode, fc_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set fc data info failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(fc_operator)); - return RET_OK; -} -REG_MAPPER(FullConnection, FCMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.h deleted file mode 100644 index 5a028e02..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/fc_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_FC_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_FC_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class FCMapper : public OpMapper { - public: - FCMapper() : OpMapper("FC") {} - ~FCMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_FC_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.cc deleted file mode 100644 index 571b77a0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.cc +++ /dev/null @@ -1,62 +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 "mapper/flatten_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/flatten_operator.h" - -namespace mindspore { -namespace dpico { -STATUS FlattenMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto flatten_prim = api::utils::cast>(prim); - MS_ASSERT(flatten_prim != nullptr); - - auto flatten_operator = std::make_unique(); - if (flatten_operator == nullptr) { - MS_LOG(ERROR) << "flatten_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, flatten_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - flatten_operator->SetOpType(mapper::OpType::FLATTEN); - if (flatten_prim->GetAttr(kStartAxis) != nullptr) { - flatten_operator->SetFlattenStartAxis( - static_cast(api::GetValue(flatten_prim->GetAttr(kStartAxis)))); - } - if (flatten_prim->GetAttr(kEndAxis) != nullptr) { - flatten_operator->SetFlattenEndAxis(static_cast(api::GetValue(flatten_prim->GetAttr(kEndAxis)))); - } - - base_operators->push_back(std::move(flatten_operator)); - return RET_OK; -} -REG_MAPPER(Flatten, FlattenMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.h deleted file mode 100644 index e819cb54..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/flatten_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_FLATTEN_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_FLATTEN_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class FlattenMapper : public OpMapper { - public: - FlattenMapper() : OpMapper("Flatten") {} - ~FlattenMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_FLATTEN_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.cc deleted file mode 100644 index 5668d99b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.cc +++ /dev/null @@ -1,78 +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 "mapper/gather_mapper.h" -#include -#include -#include -#include -#include "common/fetch_content.h" -#include "common/op_enum.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/gather_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -const size_t kOfflineArgSize2 = 2; -} // namespace -STATUS GatherMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto gather_prim = api::utils::cast>(prim); - MS_ASSERT(gather_prim != nullptr); - - auto gather_operator = std::make_unique(); - if (gather_operator == nullptr) { - MS_LOG(ERROR) << "gather_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, gather_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - gather_operator->SetOpType(mapper::OpType::GATHER); - DataInfo data_info; - if (cnode->size() > kInputIndex3 && FetchDataFromParameterNode(cnode, kInputIndex3, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeInt32)) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info.data_.data()); - gather_operator->SetAxis(*data); - } else if (gather_prim->GetAttr(ops::kAxis) != nullptr) { - gather_operator->SetAxis(static_cast(api::GetValue(gather_prim->GetAttr(ops::kAxis)))); - } else { - MS_LOG(ERROR) << "null param"; - return RET_ERROR; - } - - if (PushOfflineArgs(cnode, gather_operator.get(), kOfflineArgSize2) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(gather_operator)); - return RET_OK; -} -REG_MAPPER(Gather, GatherMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.h deleted file mode 100644 index bc21a7ea..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/gather_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GATHER_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GATHER_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class GatherMapper : public OpMapper { - public: - GatherMapper() : OpMapper("Gather") {} - ~GatherMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GATHER_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.cc deleted file mode 100644 index 3148dc26..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.cc +++ /dev/null @@ -1,51 +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 "mapper/gatherelements_mapper.h" -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/gather_elements_operator.h" - -namespace mindspore { -namespace dpico { -STATUS GatherElementsMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto gather_elements_prim = api::utils::cast>(prim); - MS_ASSERT(gather_elements_prim != nullptr); - - auto gather_elements_operator = std::make_unique(); - if (SetCommonAttr(cnode, gather_elements_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - gather_elements_operator->SetOpType(mapper::OpType::GATHER_ELEMENTS); - if (gather_elements_prim->GetAttr("dims") != nullptr) { - gather_elements_operator->SetGatherElementsAxis(api::GetValue(gather_elements_prim->GetAttr("dims"))); - } - - base_operators->push_back(std::move(gather_elements_operator)); - return RET_OK; -} -REG_MAPPER(GatherD, GatherElementsMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.h deleted file mode 100644 index 18e02088..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/gatherelements_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GATHERELEMENTS_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GATHERELEMENTS_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class GatherElementsMapper : public OpMapper { - public: - GatherElementsMapper() : OpMapper("GatherElements") {} - ~GatherElementsMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GATHERELEMENTS_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.cc deleted file mode 100644 index 5ac3a7c9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.cc +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2022 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 "mapper/greaterorequal_mapper.h" -#include -#include -#include -#include "common/fetch_content.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/cmp_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -const size_t kOfflineArgSize2 = 2; -} // namespace -STATUS GreaterOrEqualMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto greaterequal_operator = std::make_unique(); - if (SetCommonAttr(cnode, greaterequal_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - greaterequal_operator->SetOpType(mapper::OpType::CMP); - greaterequal_operator->SetCompType(mapper::CompType::COND_GE); - - if (PushOfflineArgs(cnode, greaterequal_operator.get(), kOfflineArgSize2) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(greaterequal_operator)); - return RET_OK; -} -REG_MAPPER(GreaterEqual, GreaterOrEqualMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.h deleted file mode 100644 index 8f562c87..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/greaterorequal_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GREATEROREQUAL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GREATEROREQUAL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class GreaterOrEqualMapper : public OpMapper { - public: - GreaterOrEqualMapper() : OpMapper("GreaterOrEqual") {} - ~GreaterOrEqualMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GREATEROREQUAL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.cc deleted file mode 100644 index 80a2cdc8..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.cc +++ /dev/null @@ -1,55 +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 "mapper/gru_mapper.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/gru_operator.h" - -namespace mindspore { -namespace dpico { -STATUS GruMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - MS_CHECK_TRUE_MSG(base_operators != nullptr, RET_ERROR, "base_operators is nullptr."); - auto gru_operator = std::make_unique(); - MS_CHECK_TRUE_MSG(gru_operator != nullptr, RET_ERROR, "gru_operator is nullptr."); - - if (SetCommonAttr(cnode, gru_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (prim->GetAttr(kNumOutput) != nullptr) { - gru_operator->SetRecurrentNumOutput(static_cast(api::GetValue(prim->GetAttr(kNumOutput)))); - } - if (prim->GetAttr(kExposeHidden) != nullptr) { - gru_operator->SetRecurrentExposeHidden(api::GetValue(prim->GetAttr(kExposeHidden))); - } - if (SetRecurrentDataInfo(cnode, gru_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set gru data info failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(gru_operator)); - return RET_OK; -} -REG_MAPPER(Gru, GruMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.h deleted file mode 100644 index 09d5a64f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/gru_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GRU_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GRU_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" -namespace mindspore { -namespace dpico { -class GruMapper : public OpMapper { - public: - GruMapper() : OpMapper("Gru") {} - ~GruMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_GRU_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.cc deleted file mode 100644 index eb8a2b9f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.cc +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2022 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 "mapper/hardmax_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "op/hardmax_operator.h" -#include "parser/onnx/onnx_hardmax_parser.h" - -namespace mindspore { -namespace dpico { -STATUS HardmaxMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto custom_prim = api::utils::cast>(prim); - MS_CHECK_TRUE_MSG(custom_prim != nullptr, RET_ERROR, "custom_prim is nullptr"); - auto hard_max_operator = std::make_unique(); - if (SetCommonAttr(cnode, hard_max_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - hard_max_operator->SetOpType(mapper::OpType::HARDMAX); - DataInfo data_info; - if (cnode->size() > kInputIndex3 && FetchDataFromParameterNode(cnode, kInputIndex3, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeInt32)) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info.data_.data()); - hard_max_operator->SetHardmaxAxis(*data); - } else if (custom_prim->GetAttr(ops::kAxis) != nullptr) { - hard_max_operator->SetHardmaxAxis(static_cast(api::GetValue(custom_prim->GetAttr(ops::kAxis)))); - } else { - MS_LOG(ERROR) << "null param"; - return RET_ERROR; - } - - if (PushOfflineArgs(cnode, hard_max_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed."; - return RET_ERROR; - } - base_operators->push_back(std::move(hard_max_operator)); - return RET_OK; -} -REG_MAPPER(Hardmax, HardmaxMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.h deleted file mode 100644 index cbef40e1..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardmax_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_HARDMAX_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_HARDMAX_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class HardmaxMapper : public OpMapper { - public: - HardmaxMapper() : OpMapper("Hardmax") {} - ~HardmaxMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_HARDMAX_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.cc deleted file mode 100644 index 21c1f35b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.cc +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2022 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 "mapper/hardsigmod_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/hard_sigmoid_operator.h" -#include "parser/onnx/onnx_hardsigmoid_parser.h" - -namespace mindspore { -namespace dpico { -STATUS HardSigmoidMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto hard_sigmoid_operator = std::make_unique(); - if (SetCommonAttr(cnode, hard_sigmoid_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - hard_sigmoid_operator->SetOpType(mapper::OpType::HARD_SIGMOID); - if (prim->GetAttr("alpha") != nullptr) { - hard_sigmoid_operator->SetHardSigmoidAlpha(api::GetValue(prim->GetAttr("alpha"))); - } - if (prim->GetAttr("beta") != nullptr) { - hard_sigmoid_operator->SetHardSigmoidBeta(api::GetValue(prim->GetAttr("beta"))); - } - base_operators->push_back(std::move(hard_sigmoid_operator)); - return RET_OK; -} -REG_MAPPER(HardSigmoid, HardSigmoidMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.h deleted file mode 100644 index 1e98ce46..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/hardsigmod_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_ADAPTER_DPICO_MAPPER_HARDSIGMOID_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ADAPTER_DPICO_MAPPER_HARDSIGMOID_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class HardSigmoidMapper : public OpMapper { - public: - HardSigmoidMapper() : OpMapper("HardSigmoid") {} - ~HardSigmoidMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ADAPTER_DPICO_MAPPER_HARDSIGMOID_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.cc deleted file mode 100644 index d5b4f677..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.cc +++ /dev/null @@ -1,73 +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 "mapper/interp_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "infer/resize.h" -#include "op/interp_operator.h" - -namespace mindspore { -namespace dpico { -STATUS InterpMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto interp_prim = api::utils::cast>(prim); - MS_ASSERT(interp_prim != nullptr); - - auto interp_operator = std::make_unique(); - if (interp_operator == nullptr) { - MS_LOG(ERROR) << "interp_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, interp_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - interp_operator->SetOpType(mapper::OpType::INTERP); - if (prim->GetAttr(ops::kNewHeight) != nullptr) { - interp_operator->SetInterpHeight(static_cast(interp_prim->get_new_height())); - } - if (prim->GetAttr(ops::kNewWidth) != nullptr) { - interp_operator->SetInterpWidth(static_cast(interp_prim->get_new_width())); - } - if (prim->GetAttr(dpico::kZoomFactor) != nullptr) { - interp_operator->SetInterpZoom(static_cast(api::GetValue(prim->GetAttr(dpico::kZoomFactor)))); - } - if (prim->GetAttr(dpico::kShrinkFactor) != nullptr) { - interp_operator->SetInterpShrink(static_cast(api::GetValue(prim->GetAttr(dpico::kShrinkFactor)))); - } - if (prim->GetAttr(dpico::kPadBeg) != nullptr) { - interp_operator->SetInterpPadBeg(static_cast(api::GetValue(prim->GetAttr(dpico::kPadBeg)))); - } - if (prim->GetAttr(dpico::kPadEnd) != nullptr) { - interp_operator->SetInterpPadEnd(static_cast(api::GetValue(prim->GetAttr(dpico::kPadEnd)))); - } - - base_operators->push_back(std::move(interp_operator)); - return RET_OK; -} -REG_MAPPER(Interp, InterpMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.h deleted file mode 100644 index d52407dd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/interp_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_INTERP_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_INTERP_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class InterpMapper : public OpMapper { - public: - InterpMapper() : OpMapper("Interp") {} - ~InterpMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_INTERP_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.cc deleted file mode 100644 index a0e823fd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.cc +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2022 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 "mapper/lessorequal_mapper.h" -#include -#include -#include -#include "common/fetch_content.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/cmp_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -const size_t kOfflineArgSize2 = 2; -} // namespace -STATUS LessOrEqualMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto lessequal_operator = std::make_unique(); - if (SetCommonAttr(cnode, lessequal_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - lessequal_operator->SetOpType(mapper::OpType::CMP); - lessequal_operator->SetCompType(mapper::CompType::COND_LE); - - if (PushOfflineArgs(cnode, lessequal_operator.get(), kOfflineArgSize2) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(lessequal_operator)); - return RET_OK; -} -REG_MAPPER(LessEqual, LessOrEqualMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.h deleted file mode 100644 index 0bb7a3af..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/lessorequal_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LESSOREQUAL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LESSOREQUAL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class LessOrEqualMapper : public OpMapper { - public: - LessOrEqualMapper() : OpMapper("LessOrEqual") {} - ~LessOrEqualMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LESSOREQUAL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.cc deleted file mode 100644 index bfc57a85..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.cc +++ /dev/null @@ -1,64 +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 "mapper/log_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/log_operator.h" - -namespace mindspore { -namespace dpico { -STATUS LogMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto log_operator = std::make_unique(); - if (log_operator == nullptr) { - MS_LOG(ERROR) << "log_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, log_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - log_operator->SetOpType(mapper::OpType::LOG); - if (prim->GetAttr(ops::kBase) != nullptr) { - log_operator->SetLogBase(api::GetValue(prim->GetAttr(ops::kBase))); - } - if (prim->GetAttr(ops::kScale) != nullptr) { - log_operator->SetLogScale(api::GetValue(prim->GetAttr(ops::kScale))); - } - if (prim->GetAttr(ops::kShift) != nullptr) { - log_operator->SetLogShift(api::GetValue(prim->GetAttr(ops::kShift))); - } - if (PushOfflineArgs(cnode, log_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(log_operator)); - return RET_OK; -} -REG_MAPPER(Log, LogMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.h deleted file mode 100644 index 562788b6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/log_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LOG_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LOG_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class LogMapper : public OpMapper { - public: - LogMapper() : OpMapper("Log") {} - ~LogMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LOG_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.cc deleted file mode 100644 index 9f71a566..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.cc +++ /dev/null @@ -1,67 +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 "mapper/lrn_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "infer/lrn.h" -#include "op/lrn_operator.h" - -namespace mindspore { -namespace dpico { -STATUS LrnMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto lrn_prim = api::utils::cast>(prim); - MS_ASSERT(lrn_prim != nullptr); - - auto lrn_operator = std::make_unique(); - if (lrn_operator == nullptr) { - MS_LOG(ERROR) << "lrn_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, lrn_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - lrn_operator->SetOpType(mapper::OpType::LRN); - auto local_size = lrn_prim->get_depth_radius() * 2 + 1; - lrn_operator->SetLrnLocalSize(static_cast(local_size)); - lrn_operator->SetLrnAlpha(lrn_prim->get_alpha() * local_size); - lrn_operator->SetLrnBeta(lrn_prim->get_beta()); - if (lrn_prim->GetAttr(kLrnK) != nullptr) { - lrn_operator->SetLrnK(api::GetValue(lrn_prim->GetAttr(kLrnK))); - } else if (lrn_prim->GetAttr("bias") != nullptr) { - lrn_operator->SetLrnK(api::GetValue(lrn_prim->GetAttr("bias"))); - } - if (PushOfflineArgs(cnode, lrn_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(lrn_operator)); - return RET_OK; -} -REG_MAPPER(LRN, LrnMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.h deleted file mode 100644 index 15dcf4b7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/lrn_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LRN_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LRN_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class LrnMapper : public OpMapper { - public: - LrnMapper() : OpMapper("Lrn") {} - ~LrnMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LRN_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.cc deleted file mode 100644 index 31fd46d1..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.cc +++ /dev/null @@ -1,99 +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 "mapper/lstm_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/lstm_operator.h" - -namespace mindspore { -namespace dpico { -constexpr int kNums1 = 1; -constexpr int kNums2 = 2; -STATUS LstmMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto lstm_operator = std::make_unique(); - if (lstm_operator == nullptr) { - MS_LOG(ERROR) << "lstm_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, lstm_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - // Caffe - if (api::GetValue(prim->GetAttr("type")) == "Lstm") { - if (prim->GetAttr(kNumOutput) != nullptr) { - lstm_operator->SetRecurrentNumOutput(static_cast(api::GetValue(prim->GetAttr(kNumOutput)))); - } - if (prim->GetAttr(kExposeHidden) != nullptr) { - lstm_operator->SetRecurrentExposeHidden(api::GetValue(prim->GetAttr(kExposeHidden))); - } - if (SetRecurrentDataInfo(cnode, lstm_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set lstm data info failed."; - return RET_ERROR; - } - } - - // ONNX - if (api::GetValue(prim->GetAttr("type")) == "LSTM") { - lstm_operator->SetParserMode(mapper::PARSER_ONNX); - if (prim->GetAttr(kDirection) != nullptr) { - if (api::GetValue(prim->GetAttr(kDirection)) == "forward") { - lstm_operator->SetRecurrentDirection(mapper::RECURRENT_FORWARD); - lstm_operator->SetNumOfDirection(kNums1); - } - if (api::GetValue(prim->GetAttr(kDirection)) == "reverse") { - lstm_operator->SetRecurrentDirection(mapper::RECURRENT_REVERSE); - lstm_operator->SetNumOfDirection(kNums1); - } - if (api::GetValue(prim->GetAttr(kDirection)) == "bidirectional") { - lstm_operator->SetRecurrentDirection(mapper::RECURRENT_BIDIRECTIONAL); - lstm_operator->SetNumOfDirection(kNums2); - } - } - if (prim->GetAttr(kClip) != nullptr) { - lstm_operator->SetAfClip(api::GetValue(prim->GetAttr(kClip))); - } - if (prim->GetAttr(kHiddenSize) != nullptr) { - lstm_operator->SetRecurrentNumOutput(static_cast(api::GetValue(prim->GetAttr(kHiddenSize)))); - } - if (SetRecurrentOnnxInfo(cnode, lstm_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set lstm data info failed."; - return RET_ERROR; - } - if (PushOfflineArgs(cnode, lstm_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } - - base_operators->push_back(std::move(lstm_operator)); - return RET_OK; -} -REG_MAPPER(Lstm, LstmMapper) -REG_MAPPER(LSTM, LstmMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.h deleted file mode 100644 index 77f784ec..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/lstm_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LSTM_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LSTM_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class LstmMapper : public OpMapper { - public: - LstmMapper() : OpMapper("Lstm") {} - ~LstmMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_LSTM_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.cc deleted file mode 100644 index 63053488..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.cc +++ /dev/null @@ -1,97 +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 "mapper/mat_mul_mapper.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/matrix_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS DoMaxtixOperatorMap(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - auto matrix_operator = std::make_unique(); - if (matrix_operator == nullptr) { - MS_LOG(ERROR) << "matrix_operator is nullptr."; - return RET_ERROR; - } - if (SetCommonAttr(cnode, matrix_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (prim->GetAttr(kDim1) != nullptr) { - matrix_operator->SetMatMulDim1(static_cast(api::GetValue(prim->GetAttr(kDim1)))); - } else { - MS_LOG(ERROR) << kDim1 << " attr is missed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (prim->GetAttr(kDim2) != nullptr) { - matrix_operator->SetMatMulDim2(static_cast(api::GetValue(prim->GetAttr(kDim2)))); - } else { - MS_LOG(ERROR) << kDim2 << " attr is missed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (prim->GetAttr(kDim3) != nullptr) { - matrix_operator->SetMatMulDim3(static_cast(api::GetValue(prim->GetAttr(kDim3)))); - } else { - MS_LOG(ERROR) << kDim3 << " attr is missed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(matrix_operator)); - return RET_OK; -} -} // namespace -STATUS MatMulMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - if (prim->GetAttr(kOperatorType) != nullptr) { - auto op_type = api::GetValue(prim->GetAttr(kOperatorType)); - if (op_type == "FullConnection") { - if (OpMapperRegistry::GetInstance()->GetOpMapper(op_type) == nullptr) { - MS_LOG(ERROR) << "FullConnection get op mapper failed. "; - return RET_ERROR; - } - int ret = OpMapperRegistry::GetInstance()->GetOpMapper(op_type)->Map(cnode, base_operators, prim, output_cnodes); - if (ret != RET_OK) { - MS_LOG(ERROR) << "FullConnection mapper failed. "; - return RET_ERROR; - } - } else if (op_type == "Matrix") { - if (DoMaxtixOperatorMap(cnode, base_operators, prim, output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "map to matrix operator failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << op_type << " of MatMul op is invalid. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << kOperatorType << " attr is missed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - return RET_OK; -} -REG_MAPPER(MatMulFusion, MatMulMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.h deleted file mode 100644 index 3e80a0eb..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mat_mul_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MAT_MUL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MAT_MUL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class MatMulMapper : public OpMapper { - public: - MatMulMapper() : OpMapper("MatMul") {} - ~MatMulMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MAT_MUL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.cc deleted file mode 100755 index d2c40c39..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.cc +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2023 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 "mapper/maxunpool_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/max_unpool_operator.h" -#include "parser/onnx/onnx_maxunpool_parser.h" - -namespace mindspore { -namespace dpico { -STATUS MaxUnpoolMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto custom_prim = api::utils::cast>(prim); - MS_CHECK_TRUE_MSG(custom_prim != nullptr, RET_ERROR, "custom_prim is nullptr"); - auto maxunpool_operator = std::make_unique(); - if (maxunpool_operator == nullptr) { - MS_LOG(ERROR) << "maxunpool_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, maxunpool_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - vector kernels; - vector strides; - vector pads; - maxunpool_operator->SetOpType(mapper::OpType::MAX_UNPOOL); - if (prim->GetAttr(dpico::kKernelShape) != nullptr) { - auto kernel = static_cast(api::GetValue(prim->GetAttr(dpico::kKernelShape))); - kernels = {kernel, kernel}; - maxunpool_operator->SetKernelShapeVec(kernels); - } - if (prim->GetAttr("strides") != nullptr) { - auto stride = static_cast(api::GetValue(prim->GetAttr("strides"))); - strides = {stride, stride}; - maxunpool_operator->SetStridesVec(strides); - } - if (prim->GetAttr("pads") != nullptr) { - auto pad = static_cast(api::GetValue(prim->GetAttr("pads"))); - pads = {pad, pad, pad, pad}; - maxunpool_operator->SetPadsVec(pads); - } - - base_operators->push_back(std::move(maxunpool_operator)); - return RET_OK; -} -REG_MAPPER(MaxUnpool, MaxUnpoolMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.h deleted file mode 100755 index bfeed2ce..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/maxunpool_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2023 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 DPICO_MAPPER_MAXUNPOOL_MAPPER_H_ -#define DPICO_MAPPER_MAXUNPOOL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class MaxUnpoolMapper : public OpMapper { - public: - MaxUnpoolMapper() : OpMapper("MaxUnpool") {} - ~MaxUnpoolMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // DPICO_MAPPER_MAXUNPOOL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.cc deleted file mode 100644 index dd180c48..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.cc +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2022 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 "mapper/mish_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/mish_operator.h" -#include "parser/onnx/onnx_mish_parser.h" - -namespace mindspore { -namespace dpico { -STATUS MishMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto mish_operator = std::make_unique(); - if (mish_operator == nullptr) { - MS_LOG(ERROR) << "mish_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, mish_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - mish_operator->SetOpType(mapper::OpType::MISH); - base_operators->push_back(std::move(mish_operator)); - return RET_OK; -} -REG_MAPPER(Mish, MishMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.h deleted file mode 100644 index f41e7950..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mish_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MISH_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MISH_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class MishMapper : public OpMapper { - public: - MishMapper() : OpMapper("Mish") {} - ~MishMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MISH_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.cc deleted file mode 100644 index 1be94b9e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.cc +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2022 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 "mapper/mod_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/mod_operator.h" -#include "parser/onnx/onnx_mod_parser.h" - -namespace mindspore { -namespace dpico { -STATUS ModMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto mod_operator = std::make_unique(); - if (SetCommonAttr(cnode, mod_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - mod_operator->SetOpType(mapper::OpType::MOD_TYPE); - mod_operator->SetIsFmod(false); - if (prim->GetAttr(kFmod) != nullptr) { - if (api::GetValue(prim->GetAttr(kFmod)) == 1) { - mod_operator->SetIsFmod(true); - } - } - - base_operators->push_back(std::move(mod_operator)); - return RET_OK; -} -REG_MAPPER(Mod, ModMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.h deleted file mode 100644 index 83ff47b7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mod_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MOD_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MOD_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ModMapper : public OpMapper { - public: - ModMapper() : OpMapper("Mod") {} - ~ModMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MOD_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.cc deleted file mode 100644 index 832213ac..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.cc +++ /dev/null @@ -1,70 +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 "mapper/mvn_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/mvn_operator.h" - -namespace mindspore { -namespace dpico { -STATUS MvnMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto mvn_operator = std::make_unique(); - if (mvn_operator == nullptr) { - MS_LOG(ERROR) << "mvn_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, mvn_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - mvn_operator->SetOpType(mapper::OpType::MVN); - if (prim->GetAttr(ops::kEps) != nullptr) { - mvn_operator->SetMVNEps(api::GetValue(prim->GetAttr(ops::kEps))); - } - if (prim->GetAttr(dpico::kAcrossChannels) != nullptr) { - mvn_operator->SetMVNAcrossChannels(api::GetValue(prim->GetAttr(dpico::kAcrossChannels))); - } - if (prim->GetAttr(dpico::kNormalizeVariance) != nullptr) { - mvn_operator->SetMVNNormalizeVariance(api::GetValue(prim->GetAttr(dpico::kNormalizeVariance))); - } - if (prim->GetAttr(ops::kAxes) != nullptr) { - auto axes = api::GetValue>(prim->GetAttr(ops::kAxes)); - for (auto axis : axes) { - mvn_operator->PushMVNAxes(static_cast(axis)); - } - } - if (PushOfflineArgs(cnode, mvn_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(mvn_operator)); - return RET_OK; -} -REG_MAPPER(Mvn, MvnMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.h deleted file mode 100644 index 9d4d8b3d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/mvn_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MVN_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MVN_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class MvnMapper : public OpMapper { - public: - MvnMapper() : OpMapper("Mvn") {} - ~MvnMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_MVN_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.cc deleted file mode 100644 index 9e0dbfc7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.cc +++ /dev/null @@ -1,105 +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 "mapper/normalize_mapper.h" -#include -#include -#include -#include "mindapi/ir/tensor.h" -#include "common/op_attr.h" -#include "op/normalize_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetNormalizeDataInfo(const api::CNodePtr &cnode, mapper::NormalizeOperator *normalize_operator) { - if (normalize_operator == nullptr) { - MS_LOG(ERROR) << "normalize_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 1; i < cnode->size(); i++) { - api::AnfNodePtr input_node = cnode->input(i); - if (api::utils::isa(input_node)) { - MS_LOG(INFO) << "cnode don't have blobs"; - continue; - } - if (api::utils::isa(input_node)) { - auto input_param_node = input_node->cast(); - if (!input_param_node->has_default()) { - MS_LOG(INFO) << "graph input don't have blobs"; - continue; - } - if (input_param_node->default_param() == nullptr) { - MS_LOG(ERROR) << "input_param_node->default_param() is nullptr"; - return RET_ERROR; - } - auto tensor_info = input_param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto raw_datas = static_cast(tensor_info->data()); - auto elem_count = tensor_info->DataSize(); - normalize_operator->SetNormScaleVec(std::vector(raw_datas, raw_datas + elem_count)); - } else { - MS_LOG(ERROR) << "tensor_info is nullptr, or DataSize equals zero. " << input_param_node->fullname_with_scope(); - return RET_ERROR; - } - } - } - return RET_OK; -} -} // namespace -STATUS NormalizeMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto normalize_operator = std::make_unique(); - if (normalize_operator == nullptr) { - MS_LOG(ERROR) << "normalize_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, normalize_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - normalize_operator->SetOpType(mapper::OpType::NORMALIZE); - if (prim->GetAttr(dpico::kAcrossSpatial) != nullptr) { - normalize_operator->SetNormAcrossSpatial(api::GetValue(prim->GetAttr(dpico::kAcrossSpatial))); - } - if (prim->GetAttr(dpico::kChannelShared) != nullptr) { - normalize_operator->SetNormChannelShared(api::GetValue(prim->GetAttr(dpico::kChannelShared))); - } - if (prim->GetAttr(dpico::kSqrtA) != nullptr) { - normalize_operator->SetNormAlpha(api::GetValue(prim->GetAttr(dpico::kSqrtA))); - } - if (prim->GetAttr(ops::kEps) != nullptr) { - normalize_operator->SetNormEps(api::GetValue(prim->GetAttr(ops::kEps))); - } - - if (SetNormalizeDataInfo(cnode, normalize_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set normalize data info failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(normalize_operator)); - return RET_OK; -} -REG_MAPPER(Normalize, NormalizeMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.h deleted file mode 100644 index d0ec4844..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/normalize_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_NORMALIZE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_NORMALIZE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class NormalizeMapper : public OpMapper { - public: - NormalizeMapper() : OpMapper("Normalize") {} - ~NormalizeMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_NORMALIZE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.cc deleted file mode 100644 index 40637ba7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.cc +++ /dev/null @@ -1,403 +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 "mapper/op_mapper.h" -#include -#include -#include "infer/tuple_get_item.h" -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "common/string_util.h" -#include "common/graph_output_name_keeper.h" -#include "include/securec.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetOpInputs(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator) { - if (base_operator == nullptr) { - MS_LOG(ERROR) << "base_operator is nullptr."; - return RET_ERROR; - } - std::vector input_names; - for (size_t i = 1; i < cnode->size(); i++) { - auto input_anode = cnode->input(i); - MS_ASSERT(input_anode != nullptr); - if (api::utils::isa(input_anode)) { - auto param_node = input_anode->cast(); - if (param_node != nullptr && !param_node->has_default()) { // graph input - (void)input_names.emplace_back(input_anode->fullname_with_scope()); - } - } else if (api::utils::isa(input_anode)) { - auto input_cnode = input_anode->cast(); - if (input_cnode == nullptr) { - MS_LOG(ERROR) << "input node must be cnode."; - return RET_ERROR; - } - auto node_name = input_cnode->fullname_with_scope(); - if (input_cnode->GetAttr(kOutputsNames) != nullptr) { - auto output_names = api::GetValue>(input_cnode->GetAttr(kOutputsNames)); - if (output_names.size() == 1) { - node_name = output_names.at(0); - } - } - auto ret = dpico::GraphOutputNameKeeper::GetInstance()->DetermineOmOpInputName(input_cnode, &node_name); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "determine om op's input name failed."); - (void)input_names.emplace_back(node_name); - } - } - base_operator->SetInputNamesVec(input_names); - return RET_OK; -} - -STATUS FillMultiOutOpOutputs(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator, - const api::CNodePtrList &output_cnodes) { - MS_ASSERT(base_operator != nullptr); - if (std::any_of(output_cnodes.begin(), output_cnodes.end(), [](const api::CNodePtr &cnode) { - return !CheckPrimitiveType(cnode, api::MakeShared()); - })) { - MS_LOG(ERROR) << "multi-out op must be connected with tuple-get-item node."; - return RET_ERROR; - } - auto abstract = cnode->abstract(); - if (abstract == nullptr) { - MS_LOG(ERROR) << "each node's abstract must be not a nullptr."; - return RET_ERROR; - } - if (!abstract->isa()) { - MS_LOG(ERROR) << "multi-out op's abstract must be a tuple."; - return RET_ERROR; - } - auto abstract_tuple = abstract->cast(); - MS_ASSERT(abstract_tuple != nullptr); - auto output_num = abstract_tuple->elements().size(); - std::vector output_names; - // pre-fill the output names, because maybe there are unused outputs. - for (size_t i = 0; i < output_num; ++i) { - (void)output_names.emplace_back(cnode->fullname_with_scope() + "_unused_" + std::to_string(i)); - } - for (const auto &output_cnode : output_cnodes) { - if (output_cnode->size() != kInputIndex3) { - MS_LOG(ERROR) << "tuple-get_item's inputs size must be 3."; - return RET_ERROR; - } - auto index_node = output_cnode->input(kInputIndex2); - MS_CHECK_TRUE_MSG(index_node != nullptr, RET_ERROR, "node is nullptr."); - auto value_ptr = api::GetValueNode(index_node); - MS_CHECK_TRUE_MSG(value_ptr != nullptr, RET_ERROR, "tuple_get_item's second input must be a value."); - auto num_str = value_ptr->ToString(); - MS_CHECK_TRUE_MSG(IsValidUnsignedNum(num_str), RET_ERROR, "tuple_get_item's second input must be an unsigned int"); - auto index = stoi(num_str); - MS_CHECK_TRUE_MSG(index >= 0 && static_cast(index) < output_num, RET_ERROR, - "tuple_get_item index is invalid."); - std::string om_output_name = output_cnode->fullname_with_scope(); - auto ret = GraphOutputNameKeeper::GetInstance()->DetermineOmOpOutputName(cnode, &om_output_name); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "cannot determine the om op's output name."); - output_names[index] = om_output_name; - } - base_operator->SetOutputNamesVec(output_names); - return RET_OK; -} - -STATUS SetOpOutputs(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator, - const api::CNodePtrList &output_cnodes) { - if (cnode == nullptr || base_operator == nullptr || - std::any_of(output_cnodes.begin(), output_cnodes.end(), - [](const api::CNodePtr &cnode) { return cnode == nullptr; })) { - MS_LOG(ERROR) << "the function exist that input parameter is a nullptr."; - return RET_ERROR; - } - if (std::all_of(output_cnodes.begin(), output_cnodes.end(), [](const api::CNodePtr &cnode) { - return !CheckPrimitiveType(cnode, api::MakeShared()); - })) { - // single output op - std::vector output_names; - std::string om_output_name = cnode->fullname_with_scope(); - auto ret = GraphOutputNameKeeper::GetInstance()->DetermineOmOpOutputName(cnode, &om_output_name); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "cannot determine the om op's output name."); - (void)output_names.emplace_back(om_output_name); - base_operator->SetOutputNamesVec(output_names); - return RET_OK; - } - - // multi output op - if (FillMultiOutOpOutputs(cnode, base_operator, output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set multi-out op's output names failed."; - return RET_ERROR; - } - return RET_OK; -} -} // namespace - -STATUS SetCommonAttr(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator, - const api::CNodePtrList &output_cnodes) { - if (base_operator == nullptr) { - MS_LOG(ERROR) << "base operator is nullptr."; - return RET_ERROR; - } - base_operator->SetOpName(cnode->fullname_with_scope()); - if (SetOpInputs(cnode, base_operator) != RET_OK) { - MS_LOG(ERROR) << "set op inputs failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (SetOpOutputs(cnode, base_operator, output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set op outputs failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - return RET_OK; -} - -STATUS SetConvFcDataInfo(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator) { - if (base_operator == nullptr) { - MS_LOG(ERROR) << "base_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 2; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - MS_ASSERT(input_node != nullptr); - auto param_node = input_node->cast(); - if (param_node == nullptr || !param_node->has_default()) { - continue; - } - auto tensor_info = param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - if (i == kInputIndex2) { - base_operator->SetWeightDataPtr(data); - base_operator->SetWeightSize(tensor_info->DataSize()); - } else if (i == kInputIndex3) { - base_operator->SetBiasDataPtr(data); - base_operator->SetBiasSize(tensor_info->DataSize()); - } else { - MS_LOG(ERROR) << "conv or fc operator only support 2 offline inputs at most, but " - << cnode->fullname_with_scope() << " has " << i << " offline inputs."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "param node's tensor info is invalid. " << input_node->fullname_with_scope(); - return RET_ERROR; - } - } - - return RET_OK; -} -STATUS SetRecurrentDataInfo(const api::CNodePtr &cnode, mapper::RecurrentOperator *recurrent_operator) { - if (recurrent_operator == nullptr) { - MS_LOG(ERROR) << "recurrent_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 1; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - if (api::utils::isa(input_node)) { - MS_LOG(INFO) << "cnode don't have blobs"; - continue; - } - if (api::utils::isa(input_node)) { - auto input_param_node = input_node->cast(); - if (!input_param_node->has_default()) { - MS_LOG(INFO) << "graph input don't have blobs"; - continue; - } - auto tensor_info = input_param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto raw_datas = static_cast(tensor_info->data()); - auto elem_count = tensor_info->DataSize(); - auto weight_data = new (std::nothrow) float[tensor_info->DataSize()]; - if (weight_data == nullptr) { - MS_LOG(ERROR) << "new float[] failed."; - return RET_ERROR; - } - if (memcpy_s(weight_data, static_cast(tensor_info->DataSize()) * sizeof(float), raw_datas, - static_cast(tensor_info->DataSize()) * sizeof(float)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - delete[] weight_data; - return RET_ERROR; - } - recurrent_operator->AddRecurrentParamVec(weight_data); - recurrent_operator->AddRecurrentParamLengthVec(elem_count); - } else { - MS_LOG(ERROR) << "tensor_info is nullptr, or DataSize equals zero. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } - } - return RET_OK; -} -STATUS SetRecurrentOnnxInfo(const api::CNodePtr &cnode, mapper::RecurrentOperator *recurrent_operator) { - if (recurrent_operator == nullptr) { - MS_LOG(ERROR) << "recurrent_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 1; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - if (api::utils::isa(input_node)) { - MS_LOG(INFO) << "cnode don't have blobs"; - continue; - } - if (api::utils::isa(input_node)) { - auto input_param_node = input_node->cast(); - if (!input_param_node->has_default()) { - MS_LOG(INFO) << "graph input don't have blobs"; - continue; - } - auto tensor_info = input_param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto raw_datas = static_cast(tensor_info->data()); - auto shape = tensor_info->shape(); - vector shape_vec(shape.begin(), shape.end()); - auto weight_data = new (std::nothrow) float[tensor_info->DataSize()]; - if (weight_data == nullptr) { - MS_LOG(ERROR) << "new float[] failed."; - return RET_ERROR; - } - if (memcpy_s(weight_data, static_cast(tensor_info->DataSize()) * sizeof(float), raw_datas, - static_cast(tensor_info->DataSize()) * sizeof(float)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - delete[] weight_data; - return RET_ERROR; - } - if (SetOnnxLstmOffLineArgs(recurrent_operator, i, shape_vec, weight_data) != RET_OK) { - MS_LOG(ERROR) << "set offline args failed."; - return RET_ERROR; - } - if (i == kDims5) { - std::vector, std::vector>> offline_args; - std::vector offline_data; - recurrent_operator->PushOfflineArgs({}); - if (CheckTensorInfoType(tensor_info, &offline_data) != RET_OK) { - MS_LOG(ERROR) << "check tensor_info type failed."; - return RET_ERROR; - } - std::vector offline_shape; - ShapeVector shape_vector; - if (GetShapeVectorFromParameter(input_param_node, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "get shape vector from parameter failed. " << input_param_node->fullname_with_scope(); - return RET_ERROR; - } - (void)std::transform(shape_vector.begin(), shape_vector.end(), std::back_inserter(offline_shape), - [](const int64_t dim) { return static_cast(dim); }); - (void)offline_args.emplace_back(std::make_pair(offline_data, offline_shape)); - for (auto &offline_arg : offline_args) { - recurrent_operator->PushOfflineArgs(std::move(offline_arg)); - } - } - } else { - MS_LOG(ERROR) << "tensor_info is nullptr, or DataSize equals zero. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } - } - return RET_OK; -} -STATUS CheckTensorInfoType(const api::TensorPtr &tensor_info, std::vector *offline_data) { - auto elem_count = tensor_info->DataSize(); - if (tensor_info->data_type() == kNumberTypeInt32 || tensor_info->data_type() == kNumberTypeInt) { - auto raw_data = static_cast(tensor_info->data()); - *offline_data = std::vector(raw_data, raw_data + elem_count); - } else if (tensor_info->data_type() == kNumberTypeFloat32 || tensor_info->data_type() == kNumberTypeFloat) { - auto raw_data = static_cast(tensor_info->data()); - *offline_data = std::vector(raw_data, raw_data + elem_count); - } else { - MS_LOG(ERROR) << "unsupported param type. " << tensor_info->data_type(); - return RET_ERROR; - } - return RET_OK; -} -STATUS SetOnnxLstmOffLineArgs(mapper::RecurrentOperator *recurrent_operator, size_t index, - const vector &shape_vec, const float *data) { - if (index == kDims2) { - recurrent_operator->SetXtShapeVec(shape_vec); - recurrent_operator->SetXtWeightDataPtr(data); - } else if (index == kDims3) { - recurrent_operator->SetHtShapeVec(shape_vec); - recurrent_operator->SetHtWeightDataPtr(data); - } else if (index == kDims4) { - recurrent_operator->SetRecurrentBiasShapeVec(shape_vec); - recurrent_operator->SetRecurrentBiasDataPtr(data); - } else if (index == kDims8) { - recurrent_operator->SetPeepholesShapeVec(shape_vec); - recurrent_operator->SetPeepholesWeightDataPtr(data); - } - return RET_OK; -} -STATUS PushOfflineArgs(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator, size_t offline_args_size) { - if (base_operator == nullptr) { - MS_LOG(ERROR) << "base_operator is nullptr."; - return RET_ERROR; - } - if (offline_args_size > cnode->size()) { - MS_LOG(ERROR) << "input offline_args_size:" << offline_args_size - << " is greater than cnode input size:" << cnode->size() << " " << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto inputs_size = std::min(offline_args_size + 1, cnode->size()); - std::vector, std::vector>> offline_args; - bool has_offline_args = false; - for (size_t i = 1; i < inputs_size; i++) { - auto input_node = cnode->input(i); - if (api::utils::isa(input_node)) { - MS_LOG(INFO) << "cnode don't have blobs"; - (void)offline_args.emplace_back(); - continue; - } - if (api::utils::isa(input_node)) { - auto input_param_node = input_node->cast(); - if (!input_param_node->has_default()) { - MS_LOG(INFO) << "graph input don't have blobs"; - (void)offline_args.emplace_back(); - continue; - } - auto tensor_info = input_param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - has_offline_args = true; - std::vector offline_data; - auto elem_count = tensor_info->DataSize(); - if (tensor_info->data_type() == kNumberTypeInt32 || tensor_info->data_type() == kNumberTypeInt) { - auto raw_datas = static_cast(tensor_info->data()); - offline_data = std::vector(raw_datas, raw_datas + elem_count); - } else if (tensor_info->data_type() == kNumberTypeFloat32 || tensor_info->data_type() == kNumberTypeFloat) { - auto raw_datas = static_cast(tensor_info->data()); - offline_data = std::vector(raw_datas, raw_datas + elem_count); - } else { - MS_LOG(ERROR) << "unsupported param type. " << tensor_info->data_type(); - return RET_ERROR; - } - std::vector offline_shape; - ShapeVector shape_vector; - if (GetShapeVectorFromParameter(input_param_node, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "get shape vector from parameter failed. " << input_param_node->fullname_with_scope(); - return RET_ERROR; - } - (void)std::transform(shape_vector.begin(), shape_vector.end(), std::back_inserter(offline_shape), - [](const int64_t dim) { return static_cast(dim); }); - (void)offline_args.emplace_back(std::make_pair(offline_data, offline_shape)); - } else { - MS_LOG(ERROR) << "tensor_info is nullptr, or DataSize equals zero. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - } - } - if (has_offline_args) { - for (auto &offline_arg : offline_args) { - base_operator->PushOfflineArgs(std::move(offline_arg)); - } - } - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.h deleted file mode 100644 index a07eb0d5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper.h +++ /dev/null @@ -1,66 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_H_ - -#include -#include -#include -#include -#include -#include "common/check_base.h" -#include "common/fetch_content.h" -#include "mindapi/base/base.h" -#include "mindapi/ir/anf.h" -#include "include/errorcode.h" -#include "op/base_operator.h" -#include "op/recurrent_operator.h" -#include "mindapi/base/logging.h" -#include "mindapi/ir/tensor.h" -#include "mindspore/ops/op_def/op_name.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::lite::STATUS; -namespace mindspore { -namespace dpico { -using BaseOperatorPtr = std::unique_ptr; -class OpMapper { - public: - explicit OpMapper(std::string node_name) : name(std::move(node_name)) {} - virtual ~OpMapper() = default; - virtual STATUS Map(const api::CNodePtr &node, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) = 0; - - private: - const std::string name; -}; -using OpMapperPtr = std::shared_ptr; - -STATUS SetCommonAttr(const api::CNodePtr &node, mapper::BaseOperator *base_operator, - const api::CNodePtrList &output_cnodes); -STATUS SetConvFcDataInfo(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator); -STATUS SetRecurrentDataInfo(const api::CNodePtr &cnode, mapper::RecurrentOperator *recurrent_operator); -STATUS SetRecurrentOnnxInfo(const api::CNodePtr &cnode, mapper::RecurrentOperator *recurrent_operator); -STATUS CheckTensorInfoType(const api::TensorPtr &tensor_info, std::vector *offline_data); -STATUS SetOnnxLstmOffLineArgs(mapper::RecurrentOperator *recurrent_operator, size_t index, - const vector &shape_vec, const float *data); -STATUS PushOfflineArgs(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator, size_t offline_args_size); -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.cc deleted file mode 100644 index 51df42ca..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.cc +++ /dev/null @@ -1,37 +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 "mapper/op_mapper_registry.h" -#include - -namespace mindspore { -namespace dpico { -OpMapperRegistry::OpMapperRegistry() = default; - -OpMapperRegistry *OpMapperRegistry::GetInstance() { - static OpMapperRegistry instance; - return &instance; -} - -OpMapperPtr OpMapperRegistry::GetOpMapper(const std::string &name) { - auto it = op_mappers_.find(name); - if (it != op_mappers_.end()) { - return it->second; - } - return nullptr; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.h deleted file mode 100644 index c6eead7b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/op_mapper_registry.h +++ /dev/null @@ -1,53 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_REGISTRY_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_REGISTRY_H_ - -#include -#include -#include -#include -#include "mapper/op_mapper.h" - -namespace mindspore { -namespace dpico { -class OpMapperRegistry { - public: - OpMapperRegistry(); - - virtual ~OpMapperRegistry() = default; - - static OpMapperRegistry *GetInstance(); - - OpMapperPtr GetOpMapper(const std::string &name); - - std::unordered_map op_mappers_; -}; - -class OpMapperRegistrar { - public: - OpMapperRegistrar(const std::string &op_type_name, const OpMapperPtr &op_mapper) { - OpMapperRegistry::GetInstance()->op_mappers_[op_type_name] = op_mapper; - } - ~OpMapperRegistrar() = default; -}; - -#define REG_MAPPER(primitive_type, mapper) \ - static OpMapperRegistrar g_##primitive_type##MapperReg(#primitive_type, std::make_shared()); -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_REGISTRY_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.cc deleted file mode 100644 index b4ddee49..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.cc +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright 2022 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 "mapper/pad_mapper.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "op/pad_operator.h" -#include "infer/cxx_api/pad_fusion.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetPadDataInfo(const api::CNodePtr &cnode, mapper::PadOperator *pad_operator) { - if (pad_operator == nullptr) { - MS_LOG(ERROR) << "pad_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 2; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - MS_ASSERT(input_node != nullptr); - auto param_node = input_node->cast(); - if (param_node == nullptr || !param_node->has_default()) { - continue; - } - auto tensor_info = param_node->default_param()->cast(); - std::vector pad_vec; - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - if (i == kInputIndex2) { - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - pad_vec = std::vector(data, data + tensor_info->DataSize()); - std::swap(pad_vec[kInputIndex2], pad_vec[kInputIndex4]); - std::swap(pad_vec[kInputIndex3], pad_vec[kInputIndex5]); - pad_operator->SetPadsLocVec(pad_vec); - } else if (i == kInputIndex3) { - auto pad_value = reinterpret_cast(tensor_info->data()); - pad_operator->SetPadValue(static_cast(*pad_value)); - } else { - MS_LOG(ERROR) << "pad operator only support 2 offline inputs at most, but " << cnode->fullname_with_scope() - << " has " << i << " offline inputs."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "param node's tensor info is invalid. " << input_node->fullname_with_scope(); - return RET_ERROR; - } - } - - return RET_OK; -} -} // namespace - -STATUS PadMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto pad_prim = api::utils::cast>(prim); - MS_ASSERT(pad_prim != nullptr); - - auto pad_operator = std::make_unique(); - if (SetCommonAttr(cnode, pad_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - pad_operator->SetOpType(mapper::OpType::PAD); - if (pad_prim->GetAttr(ops::kPaddingMode) != nullptr) { - pad_operator->SetPadMode(static_cast(pad_prim->get_padding_mode())); - } - - if (SetPadDataInfo(cnode, pad_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set pad data info failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(pad_operator)); - return RET_OK; -} -REG_MAPPER(PadFusion, PadMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.h deleted file mode 100644 index 863cc3a4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/pad_mapper.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PAD_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PAD_MAPPER_H_ - -#include -#include -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class PadMapper : public OpMapper { - public: - PadMapper() : OpMapper("Pad") {} - ~PadMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PAD_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.cc deleted file mode 100644 index 19872272..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.cc +++ /dev/null @@ -1,64 +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 "mapper/passthrough_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/passthrough_operator.h" - -namespace mindspore { -namespace dpico { -STATUS PassThroughMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto pass_through_operator = std::make_unique(); - if (pass_through_operator == nullptr) { - MS_LOG(ERROR) << "pass_through_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, pass_through_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - pass_through_operator->SetOpType(mapper::OpType::PASS_THROUGH); - if (prim->GetAttr(kNumOutput) != nullptr) { - pass_through_operator->SetPassThroughNumOutput( - static_cast(api::GetValue(prim->GetAttr(kNumOutput)))); - } - if (prim->GetAttr(kBlockHeight) != nullptr) { - pass_through_operator->SetPassThroughBlockHeight( - static_cast(api::GetValue(prim->GetAttr(kBlockHeight)))); - } - if (prim->GetAttr(kBlockWidth) != nullptr) { - pass_through_operator->SetPassThroughBlockWidth( - static_cast(api::GetValue(prim->GetAttr(kBlockWidth)))); - } - - base_operators->push_back(std::move(pass_through_operator)); - return RET_OK; -} -REG_MAPPER(PassThrough, PassThroughMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.h deleted file mode 100644 index adb4a0a7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/passthrough_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PASSTHROUGH_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PASSTHROUGH_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class PassThroughMapper : public OpMapper { - public: - PassThroughMapper() : OpMapper("PassThrough") {} - ~PassThroughMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PASSTHROUGH_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.cc deleted file mode 100644 index 48799cc5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.cc +++ /dev/null @@ -1,98 +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 "mapper/permute_mapper.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/data_transpose_utils.h" -#include "common/fetch_content.h" -#include "common/op_attr.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/permute_operator.h" - -namespace mindspore { -namespace dpico { -STATUS PermuteMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto permute_prim = api::utils::cast>(prim); - MS_ASSERT(permute_prim != nullptr); - - auto permute_operator = std::make_unique(); - if (permute_operator == nullptr) { - MS_LOG(ERROR) << "permute_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, permute_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - permute_operator->SetOpType(mapper::OpType::PERMUTE); - std::vector perm_val; - DataInfo data_info; - if (cnode->size() > kInputIndex2 && FetchDataFromParameterNode(cnode, kInputIndex2, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeInt32)) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info.data_.data()); - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - int data_size; - if (GetDataSizeFromTensor(&data_info, &data_size) != RET_OK) { - MS_LOG(ERROR) << "get data size from tensor failed."; - return RET_ERROR; - } - if (static_cast(data_size) != kDims4) { - MS_LOG(ERROR) << "perm val size should be " << kDims4; - return RET_ERROR; - } - perm_val = {data[0], data[1], data[kAxis2], data[kAxis3]}; - } else if (permute_prim->GetAttr(kPerm) != nullptr) { - auto perm_vec = api::GetValue>(permute_prim->GetAttr(kPerm)); - (void)std::transform(perm_vec.begin(), perm_vec.end(), std::back_inserter(perm_val), - [](int64_t p) { return static_cast(p); }); - } else { - MS_LOG(ERROR) << "can't get perm value. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (perm_val == kNH2NC) { - permute_operator->SetOutputDimOrderFormat(mapper::DimOrderFormat::NCHW_FORMAT); - } else if (perm_val == kNC2NH) { - permute_operator->SetOutputDimOrderFormat(mapper::DimOrderFormat::NHWC_FORMAT); - } else { - MS_LOG(ERROR) << "invalid perm vec. " << perm_val[0] << " " << perm_val[1] << " " << perm_val[kAxis2] << " " - << perm_val[kAxis3]; - return RET_ERROR; - } - - base_operators->push_back(std::move(permute_operator)); - return RET_OK; -} -REG_MAPPER(Transpose, PermuteMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.h deleted file mode 100644 index 9cbafe81..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/permute_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PERMUTE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PERMUTE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class PermuteMapper : public OpMapper { - public: - PermuteMapper() : OpMapper("Permute") {} - ~PermuteMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PERMUTE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.cc deleted file mode 100644 index 087da50f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.cc +++ /dev/null @@ -1,140 +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 "mapper/pool_mapper.h" -#include -#include -#include -#include -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "op/pool_operator.h" -#include "infer/cxx_api/max_pool_fusion.h" -#include "infer/cxx_api/avg_pool_fusion.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetPadAttr(const api::PrimitivePtr &prim, mapper::PoolOperator *pool_operator) { - if (pool_operator == nullptr) { - MS_LOG(ERROR) << "pool_operator is nullptr. "; - return RET_ERROR; - } - if (prim->GetAttr(ops::kPadMode) != nullptr) { - auto pad_mode = PadMode(api::GetValue(prim->GetAttr(ops::kPadMode))); - if (pad_mode == PadMode::PAD) { - auto pad_list = api::GetValue>(prim->GetAttr(ops::kPad)); - if (pad_list.size() != kDims4) { - MS_LOG(ERROR) << "pad_list size is invalid. " << pad_list.size(); - return RET_ERROR; - } - pool_operator->SetPadUp(static_cast(pad_list[0])); - pool_operator->SetPadDown(static_cast(pad_list[1])); - pool_operator->SetPadLeft(static_cast(pad_list[kAxis2])); - pool_operator->SetPadRight(static_cast(pad_list[kAxis3])); - if (pad_list[0] == pad_list[1]) { - pool_operator->SetPadHeight(static_cast(pad_list[0])); - } - if (pad_list[kAxis2] == pad_list[kAxis3]) { - pool_operator->SetPadWidth(static_cast(pad_list[kAxis3])); - } - } else if (pad_mode == PadMode::SAME) { - pool_operator->SetAutoPadType(mapper::AutoPadType::PAD_SAME_UPPER); - } else if (pad_mode == PadMode::VALID) { - pool_operator->SetAutoPadType(mapper::AutoPadType::PAD_VALID); - } else { - MS_LOG(ERROR) << "Non supported pad mode. " << pad_mode; - return RET_ERROR; - } - } - return RET_OK; -} -} // namespace -STATUS PoolMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto pool_operator = std::make_unique(); - if (pool_operator == nullptr) { - MS_LOG(ERROR) << "pool_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, pool_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (CheckPrimitiveType(cnode, api::MakeShared())) { - pool_operator->SetOpType(mapper::OpType::POOLINGAVE); - } else if (CheckPrimitiveType(cnode, api::MakeShared())) { - pool_operator->SetOpType(mapper::OpType::POOLINGMAX); - } else { - auto primitive = api::GetValueNode(cnode->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - MS_LOG(ERROR) << "pool method is not supported. " << primitive->name(); - return RET_ERROR; - } - - if (prim->GetAttr(ops::kKernelSize)) { - auto kernel_size = api::GetValue>(prim->GetAttr(ops::kKernelSize)); - if (kernel_size.size() != kDims2) { - MS_LOG(ERROR) << "kernel_size should be 2 dims, which is " << kernel_size.size(); - return RET_ERROR; - } - pool_operator->SetKernelHeight(static_cast(kernel_size[0])); - pool_operator->SetKernelWidth(static_cast(kernel_size[1])); - } - - if (prim->GetAttr(ops::kStrides) != nullptr) { - auto stride = api::GetValue>(prim->GetAttr(ops::kStrides)); - if (stride.size() != kDims2) { - MS_LOG(ERROR) << "stride should be 2 dims, which is " << stride.size(); - return RET_ERROR; - } - pool_operator->SetStrideHeight(static_cast(stride[0])); - pool_operator->SetStrideWidth(static_cast(stride[1])); - } - - if (prim->GetAttr(ops::kGlobal) != nullptr) { - auto global_flag = api::GetValue(prim->GetAttr(ops::kGlobal)); - pool_operator->SetGlobalPoolingFlag(global_flag); - } - - if (prim->GetAttr(ops::kRoundMode) != nullptr) { - auto round_mode = api::GetValue(prim->GetAttr(ops::kRoundMode)); - if (round_mode == static_cast(RoundMode::CEIL)) { - pool_operator->SetRoundMode(mapper::POOLING_ROUND_MODE_CEIL); - } else if (round_mode == static_cast(RoundMode::FLOOR)) { - pool_operator->SetRoundMode(mapper::POOLING_ROUND_MODE_FLOOR); - } - } - if (SetPadAttr(prim, pool_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set pad attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - base_operators->push_back(std::move(pool_operator)); - return RET_OK; -} -REG_MAPPER(AvgPoolFusion, PoolMapper) -REG_MAPPER(MaxPoolFusion, PoolMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.h deleted file mode 100644 index f40203c4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/pool_mapper.h +++ /dev/null @@ -1,39 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_POOL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_POOL_MAPPER_H_ - -#include -#include -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class PoolMapper : public OpMapper { - public: - PoolMapper() : OpMapper("Pool") {} - ~PoolMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_POOL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.cc deleted file mode 100644 index 67823ad5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.cc +++ /dev/null @@ -1,81 +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 "mapper/power_mapper.h" -#include -#include -#include -#include "common/fetch_content.h" -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "infer/cxx_api/pow_fusion.h" -#include "op/power_operator.h" - -namespace mindspore { -namespace dpico { -STATUS PowerMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto power_operator = std::make_unique(); - if (power_operator == nullptr) { - MS_LOG(ERROR) << "power_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, power_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - power_operator->SetOpType(mapper::OpType::POWER); - DataInfo data_info; - if (cnode->size() > kInputIndex2 && FetchDataFromParameterNode(cnode, kInputIndex2, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeFloat32)) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info.data_.data()); - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - power_operator->SetPowerPower(*data); - } else if (prim->GetAttr(ops::kPower) != nullptr) { - power_operator->SetPowerPower(api::GetValue(prim->GetAttr(ops::kPower))); - } else { - MS_LOG(ERROR) << "null param"; - return RET_ERROR; - } - if (prim->GetAttr(ops::kScale) != nullptr) { - power_operator->SetPowerScale(api::GetValue(prim->GetAttr(ops::kScale))); - } - if (prim->GetAttr(ops::kShift) != nullptr) { - power_operator->SetPowerShift(api::GetValue(prim->GetAttr(ops::kShift))); - } - if (PushOfflineArgs(cnode, power_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(power_operator)); - return RET_OK; -} -REG_MAPPER(PowFusion, PowerMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.h deleted file mode 100644 index 7fec797f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/power_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_POWER_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_POWER_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class PowerMapper : public OpMapper { - public: - PowerMapper() : OpMapper("Power") {} - ~PowerMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_POWER_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.cc deleted file mode 100644 index 3fdf6e09..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.cc +++ /dev/null @@ -1,90 +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 "mapper/prelu_mapper.h" -#include -#include -#include -#include "common/op_enum.h" -#include "common/fetch_content.h" -#include "common/anf_util.h" -#include "infer/cxx_api/prelu_fusion.h" -#include "op/prelu_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetPReluDataInfo(const api::CNodePtr &cnode, const api::PrimitivePtr &prim, - mapper::PreluOperator *prelu_operator) { - if (cnode->size() > kInputIndex2) { - auto input_anode = cnode->input(kInputIndex2); - if (api::utils::isa(input_anode)) { - auto input_param_node = input_anode->cast(); - if (input_param_node == nullptr) { - MS_LOG(ERROR) << "input_param_node is nullptr."; - return RET_ERROR; - } - auto tensor_info = input_param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto raw_datas = static_cast(tensor_info->data()); - auto elem_count = tensor_info->DataSize(); - prelu_operator->SetAlphaNegVec(std::vector(raw_datas, raw_datas + elem_count)); - } else { - MS_LOG(ERROR) << "tensor_info is nullptr, or DataSize equals zero. " << input_param_node->fullname_with_scope(); - return RET_ERROR; - } - } - } else if (prim->GetAttr(ops::kSlope) != nullptr) { - prelu_operator->SetAlphaNegVec(api::GetValue>(prim->GetAttr(ops::kSlope))); - } - return RET_OK; -} -} // namespace -STATUS PReluMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto prelu_prim = api::utils::cast>(prim); - MS_ASSERT(prelu_prim != nullptr); - - auto prelu_operator = std::make_unique(); - if (prelu_operator == nullptr) { - MS_LOG(ERROR) << "prelu_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, prelu_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (prim->GetAttr(ops::kChannelShared) != nullptr) { - prelu_operator->SetPreluIsChannelShared(prelu_prim->get_channel_shared()); - } - - if (SetPReluDataInfo(cnode, prim, prelu_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set prelu data info failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - base_operators->push_back(std::move(prelu_operator)); - return RET_OK; -} -REG_MAPPER(PReLUFusion, PReluMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.h deleted file mode 100644 index 2d4dfcd2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/prelu_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PRELU_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PRELU_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class PReluMapper : public OpMapper { - public: - PReluMapper() : OpMapper("PRelu") {} - ~PReluMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PRELU_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.cc deleted file mode 100644 index 759e6341..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.cc +++ /dev/null @@ -1,61 +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 "mapper/psroi_pool_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/ps_roi_pool_operator.h" - -namespace mindspore { -namespace dpico { -STATUS PsRoiPoolMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto psroi_pool_operator = std::make_unique(); - if (psroi_pool_operator == nullptr) { - MS_LOG(ERROR) << "psroi_pool_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, psroi_pool_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - psroi_pool_operator->SetOpType(mapper::OpType::PSROI); - if (prim->GetAttr(kSpatialScale) != nullptr) { - psroi_pool_operator->SetPsroiSpatialScale(api::GetValue(prim->GetAttr(kSpatialScale))); - } - if (prim->GetAttr(kOutputDim) != nullptr) { - psroi_pool_operator->SetPsroiOutputDim(static_cast(api::GetValue(prim->GetAttr(kOutputDim)))); - } - if (prim->GetAttr(kGroupSize) != nullptr) { - psroi_pool_operator->SetPsroiGroupSize(static_cast(api::GetValue(prim->GetAttr(kGroupSize)))); - } - - base_operators->push_back(std::move(psroi_pool_operator)); - return RET_OK; -} -REG_MAPPER(PsRoiPool, PsRoiPoolMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.h deleted file mode 100644 index 36059ab6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/psroi_pool_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PSROI_POOL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PSROI_POOL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class PsRoiPoolMapper : public OpMapper { - public: - PsRoiPoolMapper() : OpMapper("PsRoiPool") {} - ~PsRoiPoolMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_PSROI_POOL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.cc deleted file mode 100644 index 31ed0f0c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.cc +++ /dev/null @@ -1,136 +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 "mapper/reduction_mapper.h" -#include -#include -#include -#include -#include -#include "include/registry/converter_context.h" -#include "common/op_enum.h" -#include "common/fetch_content.h" -#include "infer/cxx_api/reduce_fusion.h" -#include "op/reduction_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -int GetReductionAxes(const api::CNodePtr &cnode, const api::SharedPtr &reduction_prim, - DataInfo *data_info, std::set *axes) { - if (data_info == nullptr || axes == nullptr) { - MS_LOG(ERROR) << "input arg is nullptr." << cnode->fullname_with_scope(); - return RET_ERROR; - } - if ((cnode->size() > kInputIndex2 && FetchDataFromParameterNode(cnode, kInputIndex2, data_info) == lite::RET_OK)) { - if (data_info->data_type_ != kNumberTypeInt32) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info->data_.data()); - int data_size; - if (GetDataSizeFromTensor(data_info, &data_size) != RET_OK) { - MS_LOG(ERROR) << "get data size from tensor failed."; - return RET_ERROR; - } - (void)std::transform(data, data + data_size, std::inserter(*axes, (*axes).begin()), - [](const int32_t &value) { return static_cast(value); }); - } else if (reduction_prim->GetAttr(ops::kAxes) != nullptr) { - auto axes_vec = api::GetValue>(reduction_prim->GetAttr(ops::kAxes)); - (void)std::transform(axes_vec.begin(), axes_vec.end(), std::inserter(*axes, (*axes).begin()), - [](int64_t axis) { return static_cast(axis); }); - *axes = std::set(axes_vec.begin(), axes_vec.end()); - } - return RET_OK; -} -} // namespace -STATUS ReductionMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto reduction_prim = api::utils::cast>(prim); - MS_ASSERT(reduction_prim != nullptr); - - auto reduction_operator = std::make_unique(); - if (reduction_operator == nullptr) { - MS_LOG(ERROR) << "reduction_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, reduction_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - reduction_operator->SetOpType(mapper::OpType::REDUCTION); - if (reduction_prim->GetAttr(ops::kMode) != nullptr) { - auto reduce_mode = reduction_prim->get_mode(); - switch (reduce_mode) { - case ReduceMode::Reduce_Sum: - reduction_operator->SetReductionOp(mapper::ReductionOp::RD_SUM); - break; - case ReduceMode::Reduce_Sum_Square: - reduction_operator->SetReductionOp(mapper::ReductionOp::RD_SUMSQ); - break; - case ReduceMode::Reduce_Mean: - reduction_operator->SetReductionOp(mapper::ReductionOp::RD_MEAN); - break; - case ReduceMode::Reduce_ASum: - reduction_operator->SetReductionOp(mapper::ReductionOp::RD_ASUM); - break; - case ReduceMode::Reduce_Max: - reduction_operator->SetReductionOp(mapper::ReductionOp::RD_MAX); - break; - case ReduceMode::Reduce_Min: - reduction_operator->SetReductionOp(mapper::ReductionOp::RD_MIN); - break; - case ReduceMode::Reduce_Prod: - reduction_operator->SetReductionOp(mapper::ReductionOp::RD_PROD); - break; - default: - MS_LOG(ERROR) << "Unsupported reduction op " << reduce_mode; - return RET_ERROR; - } - } - - std::set axes; - DataInfo data_info; - if (GetReductionAxes(cnode, reduction_prim, &data_info, &axes) != RET_OK) { - MS_LOG(ERROR) << "get reduction axes val failed." << cnode->fullname_with_scope(); - return RET_ERROR; - } - reduction_operator->SetReduceAxesSet(axes); - reduction_operator->SetAxis(*axes.begin()); - - if (reduction_prim->GetAttr(ops::kCoeff) != nullptr) { - reduction_operator->SetReductionCoeff(api::GetValue(reduction_prim->GetAttr(ops::kCoeff))); - } - if (reduction_prim->GetAttr(ops::kKeepDims) != nullptr) { - reduction_operator->SetReduceKeepDims( - static_cast(api::GetValue(reduction_prim->GetAttr(ops::kKeepDims)))); - } - if (PushOfflineArgs(cnode, reduction_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(reduction_operator)); - return RET_OK; -} -REG_MAPPER(ReduceFusion, ReductionMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.h deleted file mode 100644 index 961a8a75..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/reduction_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_REDUCTION_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_REDUCTION_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ReductionMapper : public OpMapper { - public: - ReductionMapper() : OpMapper("Reduction") {} - ~ReductionMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_REDUCTION_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.cc deleted file mode 100644 index 63e9938d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.cc +++ /dev/null @@ -1,101 +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 "mapper/reshape_mapper.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "common/fetch_content.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/reshape_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ReshapeMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto reshape_prim = api::utils::cast>(prim); - MS_ASSERT(reshape_prim != nullptr); - - auto reshape_operator = std::make_unique(); - if (reshape_operator == nullptr) { - MS_LOG(ERROR) << "reshape_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, reshape_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - reshape_operator->SetOpType(mapper::OpType::RESHAPE); - - DataInfo data_info; - if (cnode->size() > kInputIndex2 && FetchDataFromParameterNode(cnode, kInputIndex2, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeInt32)) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info.data_.data()); - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - std::vector dims; - int data_size; - if (GetDataSizeFromTensor(&data_info, &data_size) != RET_OK) { - MS_LOG(ERROR) << "get data size from tensor failed."; - return RET_ERROR; - } - (void)std::transform(data, data + data_size, std::back_inserter(dims), - [](const int32_t &value) { return static_cast(value); }); - reshape_operator->SetReshapeDimVec(dims); - } else if (reshape_prim->GetAttr(ops::kShape) != nullptr) { - auto shape = api::GetValue>(reshape_prim->GetAttr(ops::kShape)); - std::vector dims; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(dims), - [](const int64_t &value) { return static_cast(value); }); - reshape_operator->SetReshapeDimVec(dims); - } else { - MS_LOG(ERROR) << "shape attr doesn't exist." << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (prim->GetAttr(ops::kAxis) != nullptr) { - auto axis = static_cast(api::GetValue(reshape_prim->GetAttr(ops::kAxis))); - reshape_operator->SetAxis(axis); - } else { - reshape_operator->SetAxis(0); - } - if (prim->GetAttr(kNumAxes) != nullptr) { - auto num_axes = static_cast(api::GetValue(reshape_prim->GetAttr(kNumAxes))); - reshape_operator->SetReshapeNumAxes(num_axes); - } - if (PushOfflineArgs(cnode, reshape_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(reshape_operator)); - return RET_OK; -} -REG_MAPPER(Reshape, ReshapeMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.h deleted file mode 100644 index bd64ab9b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/reshape_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RESHAPE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RESHAPE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ReshapeMapper : public OpMapper { - public: - ReshapeMapper() : OpMapper("Reshape") {} - ~ReshapeMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RESHAPE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.cc deleted file mode 100644 index 0c4b5505..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.cc +++ /dev/null @@ -1,215 +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 "mapper/resize_mapper.h" -#include -#include -#include -#include -#include "common/anf_util.h" -#include "include/registry/converter_context.h" -#include "common/op_enum.h" -#include "infer/resize.h" -#include "op/resize_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -const std::unordered_map kCoordinateModeMap = { - {CoordinateTransformMode::ASYMMETRIC, mapper::CoordinateTransMode::ASYMMETRIC}, - {CoordinateTransformMode::ALIGN_CORNERS, mapper::CoordinateTransMode::ALIGN_CORNERS}, - {CoordinateTransformMode::HALF_PIXEL, mapper::CoordinateTransMode::HALF_PIXEL}, - {CoordinateTransformMode::CROP_AND_RESIZE, mapper::CoordinateTransMode::TF_CROP_AND_RESIZE}}; -const std::unordered_map kInterpolationModeMap = { - {ResizeMethod::LINEAR, mapper::ResizeInterpolationMode::RESIZE_LINEAR}, - {ResizeMethod::NEAREST, mapper::ResizeInterpolationMode::RESIZE_NEAREST}, - {ResizeMethod::CUBIC, mapper::ResizeInterpolationMode::RESIZE_CUBIC}}; -const std::unordered_map kNearestModeMap = { - {mindspore::NearestMode::ROUND_HALF_DOWN, mapper::NearestMode::ROUND_PREFER_FLOOR}, - {mindspore::NearestMode::ROUND_HALF_UP, mapper::NearestMode::ROUND_PREFER_CEIL}, - {mindspore::NearestMode::CEIL, mapper::NearestMode::NEAREST_CEIL}, - {mindspore::NearestMode::FLOOR, mapper::NearestMode::NEAREST_FLOOR}}; - -STATUS GetShapeAndFormat(const api::CNodePtr &cnode, const api::PrimitivePtr &prim, std::vector *input_shape, - Format *input_format) { - MS_CHECK_TRUE_MSG(input_shape != nullptr, RET_ERROR, "input_shape is nullptr."); - MS_CHECK_TRUE_MSG(input_format != nullptr, RET_ERROR, "input_format is nullptr."); - auto abstract = GetCNodeInputAbstract(cnode, 1); - if (abstract == nullptr) { - MS_LOG(ERROR) << "get cnode input abstract failed."; - return RET_ERROR; - } - if (FetchShapeFromAbstract(abstract, input_shape) != RET_OK) { - MS_LOG(ERROR) << "fetch input shape failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (prim->GetAttr(ops::kFormat) != nullptr) { - *input_format = static_cast(api::GetValue(prim->GetAttr(ops::kFormat))); - } else { - MS_LOG(ERROR) << ops::kFormat << " attr is needed."; - return RET_ERROR; - } - return RET_OK; -} -STATUS SetResizeDataInfo(const api::CNodePtr &cnode, const api::PrimitivePtr &prim, - mapper::ResizeOperator *resize_operator) { - MS_CHECK_TRUE_MSG(resize_operator != nullptr, RET_ERROR, "resize_operator is nullptr."); - if (cnode->size() != dpico::kDims3) { - MS_LOG(DEBUG) << "only process two inputs. " << cnode->fullname_with_scope(); - return RET_OK; - } - auto input_node = cnode->input(kAxis2); - MS_CHECK_TRUE_MSG(input_node != nullptr, RET_ERROR, "input_node is nullptr."); - auto param_node = input_node->cast(); - if (param_node == nullptr || !param_node->has_default()) { - MS_LOG(ERROR) << "invalid parameter node. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto tensor_info = param_node->default_param()->cast(); - if (tensor_info == nullptr || tensor_info->DataSize() == 0) { - MS_LOG(ERROR) << "tensor_info is invalid. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - std::vector input_shape; - Format input_format; - if (GetShapeAndFormat(cnode, prim, &input_shape, &input_format) != RET_OK) { - MS_LOG(ERROR) << "get input shape and format failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (input_shape.size() != kDims4) { - MS_LOG(ERROR) << "resize cnode input shape should be 4 dims. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (input_format != Format::NHWC && input_format != Format::NCHW) { - MS_LOG(ERROR) << "resize cnode input format is invalid. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto elem_cnt = tensor_info->DataSize(); - MS_CHECK_TRUE_MSG(static_cast(elem_cnt) == kDims2, RET_ERROR, - "resize param element size should be 2. " << cnode->fullname_with_scope()); - if (tensor_info->data_type() == kNumberTypeInt32 || tensor_info->data_type() == kNumberTypeInt) { - std::vector size_vec; - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - if (input_format == Format::NCHW) { - size_vec = {static_cast(input_shape.at(0)), static_cast(input_shape.at(kNCHW_C)), *data, - *(data + 1)}; - } else { - size_vec = {static_cast(input_shape.at(0)), *data, *(data + 1), - static_cast(input_shape.at(kNHWC_C))}; - } - resize_operator->SetSizeVec(size_vec); - } else if (tensor_info->data_type() == kNumberTypeFloat32 || tensor_info->data_type() == kNumberTypeFloat) { - std::vector scale_vec; - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - if (input_format == Format::NCHW) { - scale_vec = {1.0, 1.0, *data, *(data + 1)}; - } else { - scale_vec = {1.0, *data, *(data + 1), 1.0}; - } - resize_operator->SetScaleVec(scale_vec); - } else { - MS_LOG(ERROR) << "unsupported param type. " << tensor_info->data_type(); - return RET_ERROR; - } - return RET_OK; -} -} // namespace -STATUS ResizeMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto resize_prim = api::utils::cast>(prim); - MS_ASSERT(resize_prim != nullptr); - - if (resize_prim->GetAttr(ops::kFmkType) != nullptr) { - auto fmk_type = static_cast(api::GetValue(resize_prim->GetAttr(ops::kFmkType))); - if (fmk_type == converter::kFmkTypeCaffe) { - MS_CHECK_TRUE_MSG(OpMapperRegistry::GetInstance()->GetOpMapper("Interp") != nullptr, RET_ERROR, - "mapper is nullptr."); - auto status = - OpMapperRegistry::GetInstance()->GetOpMapper("Interp")->Map(cnode, base_operators, prim, output_cnodes); - if (status != RET_OK) { - MS_LOG(ERROR) << cnode->fullname_with_scope() << " map to interp operator failed."; - return RET_ERROR; - } else { - return RET_OK; - } - } - } - - auto resize_operator = std::make_unique(); - if (resize_operator == nullptr) { - MS_LOG(ERROR) << "resize_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, resize_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - resize_operator->SetOpType(mapper::OpType::RESIZE); - if (prim->GetAttr(ops::kCubicCoeff) != nullptr) { - resize_operator->SetCubicCoeff(resize_prim->get_cubic_coeff()); - } - if (prim->GetAttr(ops::kExcludeOutside) != nullptr) { - resize_operator->SetExcludeOutsideFlag(static_cast(resize_prim->get_exclude_outside())); - } - if (prim->GetAttr(ops::kExtrapolationValue) != nullptr) { - resize_operator->SetExtrapolationValue(resize_prim->get_extrapolation_value()); - } - if (prim->GetAttr(ops::kCoordinateTransformMode) != nullptr) { - auto coordinate_transform_mode = static_cast(resize_prim->get_coordinate_transform_mode()); - if (kCoordinateModeMap.find(coordinate_transform_mode) == kCoordinateModeMap.end()) { - MS_LOG(ERROR) << "unsupported coordinate transform mode:" - << std::to_string(static_cast(coordinate_transform_mode)) << " " - << cnode->fullname_with_scope(); - return RET_ERROR; - } - resize_operator->SetCoordinateTransMode(kCoordinateModeMap.at(coordinate_transform_mode)); - } - if (prim->GetAttr(ops::kMethod) != nullptr) { - auto interpolation_mode = static_cast(resize_prim->get_method()); - if (kInterpolationModeMap.find(interpolation_mode) == kInterpolationModeMap.end()) { - MS_LOG(ERROR) << "unsupported interpolation mode:" << std::to_string(static_cast(interpolation_mode)) << " " - << cnode->fullname_with_scope(); - return RET_ERROR; - } - resize_operator->SetInterpolationMode(kInterpolationModeMap.at(interpolation_mode)); - } - if (prim->GetAttr(ops::kNearestMode) != nullptr) { - auto nearest_mode = static_cast(resize_prim->get_nearest_mode()); - if (kNearestModeMap.find(nearest_mode) == kNearestModeMap.end()) { - MS_LOG(ERROR) << "unsupported nearest mode:" << std::to_string(static_cast(nearest_mode)) << " " - << cnode->fullname_with_scope(); - return RET_ERROR; - } - resize_operator->SetNearestMode(kNearestModeMap.at(nearest_mode)); - } - if (SetResizeDataInfo(cnode, prim, resize_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set resize data failed."; - return RET_ERROR; - } - base_operators->push_back(std::move(resize_operator)); - return RET_OK; -} -REG_MAPPER(Resize, ResizeMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.h deleted file mode 100644 index 2c2318f0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/resize_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RESIZE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RESIZE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ResizeMapper : public OpMapper { - public: - ResizeMapper() : OpMapper("Resize") {} - ~ResizeMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RESIZE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.cc deleted file mode 100644 index a5442a0d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.cc +++ /dev/null @@ -1,60 +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 "mapper/rnn_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/rnn_operator.h" - -namespace mindspore { -namespace dpico { -STATUS RnnMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto rnn_operator = std::make_unique(); - if (rnn_operator == nullptr) { - MS_LOG(ERROR) << "rnn_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, rnn_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (prim->GetAttr(kNumOutput) != nullptr) { - rnn_operator->SetRecurrentNumOutput(static_cast(api::GetValue(prim->GetAttr(kNumOutput)))); - } - if (prim->GetAttr(kExposeHidden) != nullptr) { - rnn_operator->SetRecurrentExposeHidden(api::GetValue(prim->GetAttr(kExposeHidden))); - } - if (SetRecurrentDataInfo(cnode, rnn_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set rnn data info failed."; - return RET_ERROR; - } - - base_operators->push_back(std::move(rnn_operator)); - return RET_OK; -} -REG_MAPPER(Rnn, RnnMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.h deleted file mode 100644 index a2da0522..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/rnn_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RNN_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RNN_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class RnnMapper : public OpMapper { - public: - RnnMapper() : OpMapper("Rnn") {} - ~RnnMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_RNN_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.cc deleted file mode 100644 index 120ff8bf..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.cc +++ /dev/null @@ -1,62 +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 "mapper/roi_pool_mapper.h" -#include -#include -#include -#include "infer/roi_pooling.h" -#include "op/roi_pool_operator.h" - -namespace mindspore { -namespace dpico { -STATUS RoiPoolMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto roi_pool_prim = api::utils::cast>(prim); - MS_ASSERT(roi_pool_prim != nullptr); - - auto roi_pool_operator = std::make_unique(); - if (roi_pool_operator == nullptr) { - MS_LOG(ERROR) << "roi_pool_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, roi_pool_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - roi_pool_operator->SetOpType(mapper::OpType::ROIPOOLING); - if (roi_pool_prim->GetAttr(ops::kPooledH) != nullptr) { - roi_pool_operator->SetRoiPooledHeight(static_cast(roi_pool_prim->get_pooled_h())); - } - if (roi_pool_prim->GetAttr(ops::kPooledW) != nullptr) { - roi_pool_operator->SetRoiPooledWidth(static_cast(roi_pool_prim->get_pooled_w())); - } - if (roi_pool_prim->GetAttr(ops::kScale) != nullptr) { - roi_pool_operator->SetRoiScale(roi_pool_prim->get_scale()); - } - - base_operators->push_back(std::move(roi_pool_operator)); - return RET_OK; -} -REG_MAPPER(ROIPooling, RoiPoolMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.h deleted file mode 100644 index efaf2da5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/roi_pool_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ROI_POOL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ROI_POOL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class RoiPoolMapper : public OpMapper { - public: - RoiPoolMapper() : OpMapper("RoiPool") {} - ~RoiPoolMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_ROI_POOL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.cc deleted file mode 100644 index 0b4c2611..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.cc +++ /dev/null @@ -1,114 +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 "mapper/scale_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "infer/scale.h" -#include "op/scale_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetScaleDataInfo(const api::CNodePtr &cnode, mapper::ScaleOperator *scale_operator) { - if (scale_operator == nullptr) { - MS_LOG(ERROR) << "scale_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 2; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - MS_ASSERT(input_node != nullptr); - auto param_node = input_node->cast(); - if (param_node == nullptr || !param_node->has_default()) { - continue; - } - auto tensor_info = param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto data = reinterpret_cast(tensor_info->data()); - MS_CHECK_TRUE_MSG(data != nullptr, RET_ERROR, "data is nullptr."); - if (i == kInputIndex2) { - scale_operator->SetScaleWeightPtr(data); - scale_operator->SetScaleWeightSize(tensor_info->DataSize()); - DataInfo data_info; - if (FetchDataFromParameterNode(cnode, kInputIndex2, &data_info) != RET_OK) { - MS_LOG(ERROR) << "fetch data from param node failed." << cnode->fullname_with_scope(); - return RET_ERROR; - } - scale_operator->SetScaleShapeVec(data_info.shape_); - } else if (i == kInputIndex3) { - scale_operator->SetScaleBiasPtr(data); - scale_operator->SetScaleBiasSize(tensor_info->DataSize()); - } else { - MS_LOG(ERROR) << "scale operator only support 2 offline inputs at most, but " << cnode->fullname_with_scope() - << " has " << i << " offline inputs."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "param node's tensor info is invalid. " << input_node->fullname_with_scope(); - return RET_ERROR; - } - } - - return RET_OK; -} -} // namespace -STATUS ScaleMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto scale_prim = api::utils::cast>(prim); - MS_ASSERT(scale_prim != nullptr); - - auto scale_operator = std::make_unique(); - if (scale_operator == nullptr) { - MS_LOG(ERROR) << "scale_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, scale_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - scale_operator->SetOpType(mapper::OpType::SCALE); - scale_operator->SetAxis(static_cast(scale_prim->get_axis())); - if (scale_prim->GetAttr(kBiasTerm) != nullptr) { - scale_operator->SetScaleBiasFlag(api::GetValue(scale_prim->GetAttr(kBiasTerm))); - } - if (scale_prim->GetAttr(kNumAxes) != nullptr) { - scale_operator->SetScaleNumAxes(static_cast(api::GetValue(scale_prim->GetAttr(kNumAxes)))); - } - - if (SetScaleDataInfo(cnode, scale_operator.get()) != RET_OK) { - MS_LOG(ERROR) << "set scale data info failed."; - return RET_ERROR; - } - if (PushOfflineArgs(cnode, scale_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(scale_operator)); - return RET_OK; -} -REG_MAPPER(ScaleFusion, ScaleMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.h deleted file mode 100644 index e6e75266..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/scale_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SCALE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SCALE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ScaleMapper : public OpMapper { - public: - ScaleMapper() : OpMapper("Scale") {} - ~ScaleMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SCALE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.cc deleted file mode 100644 index 8c7d5b28..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.cc +++ /dev/null @@ -1,50 +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 "mapper/shape_mapper.h" -#include -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/shape_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ShapeMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto shape_operator = std::make_unique(); - if (shape_operator == nullptr) { - MS_LOG(ERROR) << "shape_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, shape_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - base_operators->push_back(std::move(shape_operator)); - return RET_OK; -} -REG_MAPPER(Shape, ShapeMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.h deleted file mode 100644 index 25fdf9d8..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/shape_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHAPE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHAPE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ShapeMapper : public OpMapper { - public: - ShapeMapper() : OpMapper("Shape") {} - ~ShapeMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHAPE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.cc deleted file mode 100644 index 3e1c64ac..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.cc +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2022 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 "mapper/shrink_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/shrink_operator.h" -#include "parser/onnx/onnx_shrink_parser.h" - -namespace mindspore { -namespace dpico { -STATUS ShrinkMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto shrink_operator = std::make_unique(); - if (SetCommonAttr(cnode, shrink_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - shrink_operator->SetOpType(mapper::OpType::SHRINK); - if (prim->GetAttr("bias") != nullptr) { - shrink_operator->SetShrinkBias(api::GetValue(prim->GetAttr("bias"))); - } - if (prim->GetAttr("lambd") != nullptr) { - shrink_operator->SetShrinkLambd(api::GetValue(prim->GetAttr("lambd"))); - } - - base_operators->push_back(std::move(shrink_operator)); - return RET_OK; -} -REG_MAPPER(Shrink, ShrinkMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.h deleted file mode 100644 index aa022544..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/shrink_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHRINK_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHRINK_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ShrinkMapper : public OpMapper { - public: - ShrinkMapper() : OpMapper("Shrink") {} - ~ShrinkMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHRINK_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.cc deleted file mode 100644 index 67eef081..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.cc +++ /dev/null @@ -1,55 +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 "mapper/shuffle_channel_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "op/shuffle_channel_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ShuffleChannelMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto shuffle_channel_operator = std::make_unique(); - if (shuffle_channel_operator == nullptr) { - MS_LOG(ERROR) << "shuffle_channel_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, shuffle_channel_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - shuffle_channel_operator->SetOpType(mapper::OpType::SHUFFLECHANNEL); - if (prim->GetAttr(ops::kGroup) != nullptr) { - shuffle_channel_operator->SetShuffleChannelGroup( - static_cast(api::GetValue(prim->GetAttr(ops::kGroup)))); - } - - base_operators->push_back(std::move(shuffle_channel_operator)); - return RET_OK; -} -REG_MAPPER(ShuffleChannel, ShuffleChannelMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.h deleted file mode 100644 index 0c6245d4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/shuffle_channel_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHUFFLE_CHANNEL_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHUFFLE_CHANNEL_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ShuffleChannelMapper : public OpMapper { - public: - ShuffleChannelMapper() : OpMapper("ShuffleChannel") {} - ~ShuffleChannelMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SHUFFLE_CHANNEL_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.cc deleted file mode 100644 index 5bc7fc53..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 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 "mapper/sinh_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/sinh_operator.h" -#include "parser/onnx/onnx_sinh_parser.h" - -namespace mindspore { -namespace dpico { -STATUS SinhMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto sinh_operator = std::make_unique(); - if (SetCommonAttr(cnode, sinh_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - sinh_operator->SetOpType(mapper::OpType::SINHAF); - - base_operators->push_back(std::move(sinh_operator)); - return RET_OK; -} -REG_MAPPER(Sinh, SinhMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.h deleted file mode 100644 index a51a08ea..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/sinh_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SINH_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SINH_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class SinhMapper : public OpMapper { - public: - SinhMapper() : OpMapper("Sinh") {} - ~SinhMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SINH_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.cc deleted file mode 100644 index 73def632..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.cc +++ /dev/null @@ -1,116 +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 "mapper/slice_mapper.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "common/check_base.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/slice_operator.h" - -namespace mindspore { -namespace dpico { -STATUS SliceMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto split_prim = api::utils::cast>(prim); - MS_ASSERT(split_prim != nullptr); - - auto slice_operator = std::make_unique(); - MS_CHECK_TRUE_MSG(slice_operator != nullptr, RET_ERROR, "slice_operator is nullptr."); - - if (SetCommonAttr(cnode, slice_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - slice_operator->SetOpType(mapper::OpType::SLICE); - ShapeVector shape; - if (GetInputShapeFromCNode(cnode, kInputIndex1, &shape) != RET_OK) { - MS_LOG(ERROR) << "fetch input shape failed."; - return RET_ERROR; - } - if (std::any_of(shape.begin(), shape.end(), - [](int64_t dim) { return dim <= 0 || dim > static_cast(UINT32_MAX); })) { - MS_LOG(ERROR) << "shape is invalid, which is not larger than 0 and less than uint32_max"; - return RET_ERROR; - } - MS_ASSERT(shape.size() <= kDims4); - if (split_prim->GetAttr(ops::kAxis) == nullptr) { - MS_LOG(ERROR) << "axis attr is nullptr, please check split_checker."; - return RET_ERROR; - } - auto split_axis = split_prim->get_axis(); - split_axis = split_axis < 0 ? split_axis + static_cast(shape.size()) : split_axis; - if (split_axis > static_cast(kDims4)) { - MS_LOG(ERROR) << "split axis is invalid."; - return RET_ERROR; - } - slice_operator->SetAxis(static_cast(split_axis)); - if (split_prim->GetAttr(ops::kSizeSplits) != nullptr) { - auto sizes = api::GetValue>(split_prim->GetAttr("size_splits")); - if (sizes.empty()) { - MS_LOG(ERROR) << "sizes shouldn't be empty." << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (std::any_of(sizes.begin(), sizes.end(), [](int64_t size) { return size > static_cast(UINT32_MAX); })) { - MS_LOG(ERROR) << "split sizes is invalid, which is not larger than 0 and less than uint32_max"; - return RET_ERROR; - } - std::vector sizes_u; - (void)std::transform(sizes.begin(), sizes.end(), std::back_inserter(sizes_u), - [](int64_t size) { return static_cast(size); }); - uint32_t slice_point_cnt = 0; - for (size_t i = 0; i < sizes_u.size() - 1; i++) { - if (sizes_u.at(i) >= (static_cast(shape[split_axis]) - slice_point_cnt)) { - MS_LOG(ERROR) << "split sizes is invalid, which is larger than the related dim."; - return RET_ERROR; - } - slice_operator->AddSlicePoint(sizes_u.at(i) + slice_point_cnt); - slice_point_cnt += sizes_u.at(i); - } - } - - if (slice_operator->GetSlicePointVec().empty()) { - if (split_prim->GetAttr(ops::kOutputNum) == nullptr) { - MS_LOG(ERROR) << "cannot determine split points."; - return RET_ERROR; - } - auto output_num = api::GetValue(split_prim->GetAttr(ops::kOutputNum)); - MS_CHECK_TRUE_MSG(output_num != 0, RET_ERROR, "output_num is 0."); - if (shape[split_axis] % output_num != 0) { - MS_LOG(ERROR) << "output_num is 0 or split op is invalid, which input shape cannot be splited."; - return RET_ERROR; - } - uint32_t size_of_each_out = static_cast(shape[split_axis] / output_num); - for (uint32_t i = 1; i < static_cast(output_num); ++i) { - slice_operator->AddSlicePoint(i * size_of_each_out); - } - } - base_operators->push_back(std::move(slice_operator)); - return RET_OK; -} -REG_MAPPER(Split, SliceMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.h deleted file mode 100644 index 75777440..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/slice_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SLICE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SLICE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class SliceMapper : public OpMapper { - public: - SliceMapper() : OpMapper("Slice") {} - ~SliceMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SLICE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.cc deleted file mode 100644 index 13b6cebc..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.cc +++ /dev/null @@ -1,65 +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 "mapper/softmax_mapper.h" -#include -#include -#include -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/softmax_operator.h" - -namespace mindspore { -namespace dpico { -STATUS SoftmaxMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto softmax_prim = api::utils::cast>(prim); - MS_ASSERT(softmax_prim != nullptr); - - auto softmax_operator = std::make_unique(); - if (softmax_operator == nullptr) { - MS_LOG(ERROR) << "softmax_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, softmax_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - softmax_operator->SetOpType(mapper::OpType::SOFTMAX); - auto axes = softmax_prim->get_axis(); - if (axes.empty()) { - MS_LOG(ERROR) << "axis attr is empty."; - return RET_ERROR; - } else { - softmax_operator->SetRealAxes(static_cast(axes.at(0))); - } - if (PushOfflineArgs(cnode, softmax_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(softmax_operator)); - return RET_OK; -} -REG_MAPPER(Softmax, SoftmaxMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.h deleted file mode 100644 index 6ec2122a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/softmax_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SOFTMAX_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SOFTMAX_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class SoftmaxMapper : public OpMapper { - public: - SoftmaxMapper() : OpMapper("Softmax") {} - ~SoftmaxMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SOFTMAX_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.cc deleted file mode 100644 index 270f05d3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.cc +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2022 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 "mapper/softsign_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "infer/softsign.h" -#include "op/softsign_operator.h" - -namespace mindspore { -namespace dpico { -STATUS SoftSignMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto softsign_operator = std::make_unique(); - if (SetCommonAttr(cnode, softsign_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - softsign_operator->SetOpType(mapper::OpType::SOFTSIGN); - if (PushOfflineArgs(cnode, softsign_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(softsign_operator)); - return RET_OK; -} -REG_MAPPER(Softsign, SoftSignMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.h deleted file mode 100644 index 49e31a85..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/softsign_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SOFTSIGN_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SOFTSIGN_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class SoftSignMapper : public OpMapper { - public: - SoftSignMapper() : OpMapper("Softsign") {} - ~SoftSignMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SOFTSIGN_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.cc deleted file mode 100644 index 99459303..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.cc +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2022 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 "mapper/sqrt_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/sqrt_operator.h" - -namespace mindspore { -namespace dpico { -STATUS SqrtMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto sqrt_operator = std::make_unique(); - if (SetCommonAttr(cnode, sqrt_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - sqrt_operator->SetOpType(mapper::OpType::SQRT); - if (PushOfflineArgs(cnode, sqrt_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(sqrt_operator)); - return RET_OK; -} -REG_MAPPER(Sqrt, SqrtMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.h deleted file mode 100644 index 56907526..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/sqrt_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SQRT_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SQRT_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class SqrtMapper : public OpMapper { - public: - SqrtMapper() : OpMapper("Sqrt") {} - ~SqrtMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SQRT_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.cc deleted file mode 100644 index c2ff3945..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.cc +++ /dev/null @@ -1,65 +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 "mapper/squeeze_mapper.h" -#include -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "op/squeeze_operator.h" - -namespace mindspore { -namespace dpico { -STATUS SqueezeMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto squeeze_prim = api::utils::cast>(prim); - MS_ASSERT(squeeze_prim != nullptr); - - auto squeeze_operator = std::make_unique(); - if (squeeze_operator == nullptr) { - MS_LOG(ERROR) << "squeeze_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, squeeze_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - squeeze_operator->SetOpType(mapper::OpType::SQUEEZE); - - if (squeeze_prim->GetAttr(ops::kAxis) != nullptr) { - auto axes = api::GetValue>(squeeze_prim->GetAttr(ops::kAxis)); - std::vector dims; - (void)std::transform(axes.begin(), axes.end(), std::back_inserter(dims), - [](const int64_t &value) { return static_cast(value); }); - squeeze_operator->SetSqueezeAxisVec(dims); - } - if (PushOfflineArgs(cnode, squeeze_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(squeeze_operator)); - return RET_OK; -} -REG_MAPPER(Squeeze, SqueezeMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.h deleted file mode 100644 index b9892b03..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/squeeze_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SQUEEZE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SQUEEZE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class SqueezeMapper : public OpMapper { - public: - SqueezeMapper() : OpMapper("Squeeze") {} - ~SqueezeMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_SQUEEZE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.cc deleted file mode 100644 index cb7fbcaa..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.cc +++ /dev/null @@ -1,94 +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 "mapper/strided_slice_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "op/extract_slice_operator.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS SetExtractSliceDataInfo(const api::CNodePtr &cnode, mapper::ExtractSliceOperator *extract_slice_operator) { - if (extract_slice_operator == nullptr) { - MS_LOG(ERROR) << "extract_slice_operator is nullptr."; - return RET_ERROR; - } - for (size_t i = 2; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - MS_ASSERT(input_node != nullptr); - auto param_node = input_node->cast(); - if (param_node == nullptr || !param_node->has_default()) { - continue; - } - auto tensor_info = param_node->default_param()->cast(); - if (tensor_info != nullptr && tensor_info->DataSize() != 0) { - auto data = reinterpret_cast(tensor_info->data()); - if (i == kInputIndex2) { - extract_slice_operator->SetStartsVec(std::vector(data, data + tensor_info->DataSize())); - } else if (i == kInputIndex3) { - extract_slice_operator->SetEndsVec(std::vector(data, data + tensor_info->DataSize())); - } else if (i == kInputIndex4) { - extract_slice_operator->SetAxesVec(std::vector(data, data + tensor_info->DataSize())); - } else if (i == kInputIndex5) { - extract_slice_operator->SetStepsVec(std::vector(data, data + tensor_info->DataSize())); - } else { - MS_LOG(ERROR) << "extract slice operator only support 4 offline inputs at most, but " - << cnode->fullname_with_scope() << " has " << i << " offline inputs."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "param node's tensor info is invalid. " << input_node->fullname_with_scope(); - return RET_ERROR; - } - } - - return RET_OK; -} -} // namespace -STATUS StridedSliceMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto extract_slice_operator = std::make_unique(); - if (extract_slice_operator == nullptr) { - MS_LOG(ERROR) << "extract_slice_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, extract_slice_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - extract_slice_operator->SetOpType(mapper::OpType::EXTRACT_SLICE); - - if (SetExtractSliceDataInfo(cnode, extract_slice_operator.get())) { - MS_LOG(ERROR) << "set strided slice data info failed." << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(extract_slice_operator)); - return RET_OK; -} -REG_MAPPER(StridedSlice, StridedSliceMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.h deleted file mode 100644 index 1eea69f1..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/strided_slice_mapper.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_STRIDED_SLICE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_STRIDED_SLICE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class StridedSliceMapper : public OpMapper { - public: - StridedSliceMapper() : OpMapper("StridedSlice") {} - ~StridedSliceMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_STRIDED_SLICE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.cc deleted file mode 100644 index 0ec68c05..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.cc +++ /dev/null @@ -1,55 +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 "mapper/threshold_mapper.h" -#include -#include -#include -#include "common/op_attr.h" -#include "common/anf_util.h" -#include "op/threshold_operator.h" - -namespace mindspore { -namespace dpico { -STATUS ThresholdMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto threshold_operator = std::make_unique(); - if (threshold_operator == nullptr) { - MS_LOG(ERROR) << "threshold_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, threshold_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - threshold_operator->SetOpType(mapper::OpType::THRESHOLD); - if (prim->GetAttr(dpico::kThreshold) != nullptr) { - threshold_operator->SetThreshold(api::GetValue(prim->GetAttr(dpico::kThreshold))); - } - - base_operators->push_back(std::move(threshold_operator)); - return RET_OK; -} -REG_MAPPER(Threshold, ThresholdMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.h deleted file mode 100644 index 3ef395ec..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/threshold_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_THRESHOLD_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_THRESHOLD_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class ThresholdMapper : public OpMapper { - public: - ThresholdMapper() : OpMapper("Threshold") {} - ~ThresholdMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_THRESHOLD_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.cc deleted file mode 100644 index 95830917..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.cc +++ /dev/null @@ -1,101 +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 "mapper/tile_mapper.h" -#include -#include -#include -#include -#include "common/fetch_content.h" -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "infer/cxx_api/tile_fusion.h" -#include "op/tile_operator.h" - -namespace mindspore { -namespace dpico { -STATUS TileMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto tile_prim = api::utils::cast>(prim); - MS_ASSERT(tile_prim != nullptr); - - auto tile_operator = std::make_unique(); - if (tile_operator == nullptr) { - MS_LOG(ERROR) << "tile_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, tile_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - tile_operator->SetOpType(mapper::OpType::TILE); - if (tile_prim->GetAttr(ops::kDims) != nullptr) { - auto dims = api::GetValue>(tile_prim->GetAttr(ops::kDims)); - if (dims.size() == 1) { // tf tile has multiple axis - tile_operator->SetAxis(static_cast(dims.at(0))); - } - } - - DataInfo data_info; - vector tiles; - if (cnode->size() > kInputIndex2 && FetchDataFromParameterNode(cnode, kInputIndex2, &data_info) == lite::RET_OK) { - if (data_info.data_type_ != static_cast(kNumberTypeInt32)) { - MS_LOG(ERROR) << "data_type not correct"; - return RET_ERROR; - } - auto data = reinterpret_cast(data_info.data_.data()); - if (data == nullptr) { - MS_LOG(ERROR) << "data is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - int data_size; - if (GetDataSizeFromTensor(&data_info, &data_size) != RET_OK) { - MS_LOG(ERROR) << "get data size from tensor failed."; - return RET_ERROR; - } - (void)std::transform(data, data + data_size, std::back_inserter(tiles), - [](const int64_t &value) { return static_cast(value); }); - } else if (tile_prim->GetAttr(dpico::kMultiples) != nullptr) { - if (tile_prim->GetAttr(ops::kDims) != nullptr) { - tiles = api::GetValue>(tile_prim->GetAttr(dpico::kMultiples)); - } - } else { - MS_LOG(ERROR) << "null param"; - return RET_ERROR; - } - - if (tiles.size() == 1) { - tile_operator->SetTileTiles(static_cast(tiles.at(0))); - } else { - tile_operator->SetTileRepeats(tiles); - } - if (PushOfflineArgs(cnode, tile_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(tile_operator)); - return RET_OK; -} -REG_MAPPER(TileFusion, TileMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.h deleted file mode 100644 index 6893726b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/tile_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_TILE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_TILE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class TileMapper : public OpMapper { - public: - TileMapper() : OpMapper("Tile") {} - ~TileMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_TILE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.cc deleted file mode 100644 index 8524880a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.cc +++ /dev/null @@ -1,69 +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 "mapper/unsqueeze_mapper.h" -#include -#include -#include -#include -#include "common/anf_util.h" -#include "infer/unsqueeze.h" -#include "op/unsqueeze_operator.h" - -namespace mindspore { -namespace dpico { -STATUS UnsqueezeMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto unsqueeze_prim = api::utils::cast>(prim); - MS_ASSERT(unsqueeze_prim != nullptr); - - auto unsqueeze_operator = std::make_unique(); - if (unsqueeze_operator == nullptr) { - MS_LOG(ERROR) << "unsqueeze_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, unsqueeze_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - unsqueeze_operator->SetOpType(mapper::OpType::UNSQUEEZE); - - if (unsqueeze_prim->GetAttr(ops::kAxis) != nullptr) { - auto axes = api::GetValue>(unsqueeze_prim->GetAttr(ops::kAxis)); - std::vector dims; - (void)std::transform(axes.begin(), axes.end(), std::back_inserter(dims), - [](const int64_t &value) { return static_cast(value); }); - unsqueeze_operator->SetUnsqueezeAxisVec(dims); - } else { - MS_LOG(ERROR) << "axis attr doesn't exist." << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (PushOfflineArgs(cnode, unsqueeze_operator.get(), 1) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(unsqueeze_operator)); - return RET_OK; -} -REG_MAPPER(Unsqueeze, UnsqueezeMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.h deleted file mode 100644 index f59863a0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/unsqueeze_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_UNSQUEEZE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_UNSQUEEZE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class UnsqueezeMapper : public OpMapper { - public: - UnsqueezeMapper() : OpMapper("Unsqueeze") {} - ~UnsqueezeMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_UNSQUEEZE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.cc deleted file mode 100644 index 42e8c322..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.cc +++ /dev/null @@ -1,66 +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 "mapper/upsample_mapper.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "op/upsample_operator.h" - -namespace mindspore { -namespace dpico { -STATUS UpsampleMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - - auto upsample_operator = std::make_unique(); - if (upsample_operator == nullptr) { - MS_LOG(ERROR) << "upsample_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, upsample_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - upsample_operator->SetOpType(mapper::OpType::UPSAMPLE); - if (prim->GetAttr(ops::kScale) != nullptr) { - upsample_operator->SetUpsampleScale(api::GetValue(prim->GetAttr(ops::kScale))); - } - if (prim->GetAttr(kInterpolationMode) != nullptr) { - auto mode = api::GetValue(prim->GetAttr(kInterpolationMode)); - if (mode == kNearest) { - upsample_operator->SetInterpolationMode(mapper::InterpolationMode::NEAREST); - } else if (mode == kBilinear) { - upsample_operator->SetInterpolationMode(mapper::InterpolationMode::BILINEAR); - } else { - MS_LOG(ERROR) << "current interpolation mode is not supported. " << mode; - return RET_ERROR; - } - } - - base_operators->push_back(std::move(upsample_operator)); - return RET_OK; -} -REG_MAPPER(Upsample, UpsampleMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.h deleted file mode 100644 index ba5ea23e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/upsample_mapper.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_UPSAMPLE_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_UPSAMPLE_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class UpsampleMapper : public OpMapper { - public: - UpsampleMapper() : OpMapper("Upsample") {} - ~UpsampleMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_UPSAMPLE_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.cc b/mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.cc deleted file mode 100644 index 71f178e2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.cc +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2022 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 "mapper/xor_mapper.h" -#include -#include -#include -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "op/logical_operator.h" -#include "parser/onnx/onnx_xor_parser.h" - -namespace mindspore { -namespace dpico { -const size_t kOfflineArgSize2 = 2; - -STATUS XorMapper::Map(const api::CNodePtr &cnode, std::vector *base_operators, - const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) { - if (base_operators == nullptr) { - MS_LOG(ERROR) << "base_operators is nullptr."; - return RET_ERROR; - } - auto xor_operator = std::make_unique(); - if (xor_operator == nullptr) { - MS_LOG(ERROR) << "xor_operator is nullptr."; - return RET_ERROR; - } - - if (SetCommonAttr(cnode, xor_operator.get(), output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "set common attr failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - xor_operator->SetOpType(mapper::OpType::LOGICAL); - xor_operator->SetLogicalOperator(mapper::LOGICAL_XOR); - - if (PushOfflineArgs(cnode, xor_operator.get(), kOfflineArgSize2) != RET_OK) { - MS_LOG(ERROR) << "push offline args failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - base_operators->push_back(std::move(xor_operator)); - return RET_OK; -} -REG_MAPPER(Xor, XorMapper) -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.h b/mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.h deleted file mode 100644 index 52e7f522..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/mapper/xor_mapper.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_XOR_MAPPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_XOR_MAPPER_H_ - -#include -#include -#include "mapper/op_mapper.h" -#include "mapper/op_mapper_registry.h" - -namespace mindspore { -namespace dpico { -class XorMapper : public OpMapper { - public: - XorMapper() : OpMapper("Xor") {} - ~XorMapper() override = default; - STATUS Map(const api::CNodePtr &node, std::vector *base_operators, const api::PrimitivePtr &prim, - const api::CNodePtrList &output_cnodes) override; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_XOR_MAPPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.cc deleted file mode 100644 index ea2ffc7a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.cc +++ /dev/null @@ -1,35 +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 "parser/caffe/caffe_absval_parser.h" -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeAbsvalParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - return prim; -} - -CaffeNodeRegistrar g_caffeAbsvalParser("AbsVal", new CaffeAbsvalParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.h deleted file mode 100644 index 6c0397fe..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_absval_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ABSVAL_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ABSVAL_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeAbsvalParser : public CaffeNodeParser { - public: - CaffeAbsvalParser() : CaffeNodeParser("Absval") {} - ~CaffeAbsvalParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ABSVAL_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.cc deleted file mode 100644 index d723adf5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.cc +++ /dev/null @@ -1,124 +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 "parser/caffe/caffe_activation_parser.h" -#include -#include -#include -#include "common/op_attr.h" -#include "infer/cxx_api/activation.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeReluParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_activation_type(mindspore::ActivationType::RELU); - - if (proto.has_relu_param() && proto.relu_param().has_negative_slope()) { - float negative_slope = proto.relu_param().negative_slope(); - if (std::fabs(negative_slope) > std::numeric_limits::epsilon()) { - prim->set_activation_type(mindspore::ActivationType::LEAKY_RELU); - prim->set_alpha(negative_slope); - } - } - - return prim; -} - -BaseOperatorPtr CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_activation_type(mindspore::ActivationType::RELU6); - if (proto.has_relu6_param() && proto.relu6_param().has_negative_slope()) { - float negative_slope = proto.relu6_param().negative_slope(); - if (std::fabs(negative_slope) > std::numeric_limits::epsilon()) { - prim->set_alpha(negative_slope); - } - } - return prim; -} - -BaseOperatorPtr CaffeSigmoidParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_activation_type(mindspore::ActivationType::SIGMOID); - - return prim; -} - -BaseOperatorPtr CaffeTanhParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_activation_type(mindspore::ActivationType::TANH); - - return prim; -} - -BaseOperatorPtr CaffeEluParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_activation_type(mindspore::ActivationType::ELU); - - if (proto.has_elu_param()) { - const caffe::ELUParameter &eluParameter = proto.elu_param(); - if (eluParameter.has_alpha()) { - prim->set_alpha(eluParameter.alpha()); - } - } - - return prim; -} - -BaseOperatorPtr CaffeHswishParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_activation_type(mindspore::ActivationType::HSWISH); - if (proto.has_hswish_param()) { - const caffe::HswishParameter &hswishParameter = proto.hswish_param(); - if (hswishParameter.has_negative_slope()) { - (void)prim->AddAttr(dpico::kNegativeSlope, api::MakeValue(hswishParameter.negative_slope())); - } - } - return prim; -} - -CaffeNodeRegistrar g_caffeReluParser("ReLU", new CaffeReluParser()); -CaffeNodeRegistrar g_caffeRelu6Parser("ReLU6", new CaffeRelu6Parser()); -CaffeNodeRegistrar g_caffeSigmoidParser("Sigmoid", new CaffeSigmoidParser()); -CaffeNodeRegistrar g_caffeTanhParser("TanH", new CaffeTanhParser()); -CaffeNodeRegistrar g_caffeEluParser("ELU", new CaffeEluParser()); -CaffeNodeRegistrar g_caffeHswishParser("Hswish", new CaffeHswishParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.h deleted file mode 100644 index 26b7edb5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_activation_parser.h +++ /dev/null @@ -1,76 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ACTIVATION_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ACTIVATION_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeReluParser : public CaffeNodeParser { - public: - CaffeReluParser() : CaffeNodeParser("relu") {} - ~CaffeReluParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; - -class CaffeRelu6Parser : public CaffeNodeParser { - public: - CaffeRelu6Parser() : CaffeNodeParser("relu6") {} - ~CaffeRelu6Parser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; - -class CaffeSigmoidParser : public CaffeNodeParser { - public: - CaffeSigmoidParser() : CaffeNodeParser("sigmoid") {} - ~CaffeSigmoidParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; - -class CaffeTanhParser : public CaffeNodeParser { - public: - CaffeTanhParser() : CaffeNodeParser("tanh") {} - ~CaffeTanhParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; - -class CaffeEluParser : public CaffeNodeParser { - public: - CaffeEluParser() : CaffeNodeParser("elu") {} - ~CaffeEluParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; - -class CaffeHswishParser : public CaffeNodeParser { - public: - CaffeHswishParser() : CaffeNodeParser("Hswish") {} - ~CaffeHswishParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ACTIVATION_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.cc deleted file mode 100644 index 82630fc5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.cc +++ /dev/null @@ -1,49 +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 "parser/caffe/caffe_argmax_parser.h" -#include -#include "infer/cxx_api/arg_max_fusion.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeArgMaxParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_keep_dims(true); - prim->set_out_max_value(false); - prim->set_top_k(1); - - const caffe::ArgMaxParameter &argmaxParam = proto.argmax_param(); - if (argmaxParam.has_out_max_val()) { - prim->set_out_max_value(argmaxParam.out_max_val()); - } - if (argmaxParam.has_top_k()) { - prim->set_top_k(argmaxParam.top_k()); - } - if (argmaxParam.has_axis()) { - prim->set_axis(argmaxParam.axis()); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeArgMaxParser("ArgMax", new CaffeArgMaxParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.h deleted file mode 100644 index d983dd58..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_argmax_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ARGMAX_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ARGMAX_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeArgMaxParser : public CaffeNodeParser { - public: - CaffeArgMaxParser() : CaffeNodeParser("argmax") {} - ~CaffeArgMaxParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ARGMAX_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.cc deleted file mode 100644 index 69942c03..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.cc +++ /dev/null @@ -1,62 +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 "parser/caffe/caffe_batchnorm_parser.h" -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "common/op_attr.h" -#include "mindapi/base/format.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeBatchNormParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_is_training(false); - prim->set_data_format(mindspore::Format::NCHW); - - const caffe::BatchNormParameter &batchNormParam = proto.batch_norm_param(); - if (proto.bottom_size() != 1) { - MS_LOG(ERROR) << "Layer " << proto.name().c_str() << "bottom numbers is error, it must be 1, but is " - << proto.bottom_size(); - return nullptr; - } - if (proto.top_size() != 1) { - MS_LOG(ERROR) << "Layer " << proto.name().c_str() << "top numbers is error, it must be 1, but is " - << proto.top_size(); - return nullptr; - } - - float epsilon = 1e-5; - if (batchNormParam.has_eps() && std::fabs(1e-5 - batchNormParam.eps()) >= 1e-9) { - epsilon = batchNormParam.eps(); - } - prim->set_epsilon(epsilon); - - if (batchNormParam.has_use_global_stats()) { - (void)prim->AddAttr(dpico::kUseGlobalStats, api::MakeValue(batchNormParam.use_global_stats())); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeBatchNormParser("BatchNorm", new CaffeBatchNormParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.h deleted file mode 100644 index a79be14f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_batchnorm_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BATCHNORM_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BATCHNORM_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeBatchNormParser : public CaffeNodeParser { - public: - CaffeBatchNormParser() : CaffeNodeParser("batchnorm") {} - ~CaffeBatchNormParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BATCHNORM_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.cc deleted file mode 100644 index 036b16a0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.cc +++ /dev/null @@ -1,49 +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 "parser/caffe/caffe_bi_lstm_parser.h" -#include -#include -#include -#include "infer/custom.h" -#include "common/op_attr.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeBiLstmParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("BiLstm"); - if (proto.has_recurrent_param()) { - const auto &bi_lstm_param = proto.recurrent_param(); - if (bi_lstm_param.has_num_output()) { - (void)prim->AddAttr(dpico::kNumOutput, api::MakeValue(bi_lstm_param.num_output())); - (void)prim->AddAttr(dpico::kOutputChannel, api::MakeValue(bi_lstm_param.num_output())); - } - if (bi_lstm_param.has_expose_hidden()) { - (void)prim->AddAttr(dpico::kExposeHidden, api::MakeValue(bi_lstm_param.expose_hidden())); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeBiLstmParser("BILSTM", new CaffeBiLstmParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.h deleted file mode 100644 index 9178d508..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bi_lstm_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BI_LSTM_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BI_LSTM_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeBiLstmParser : public CaffeNodeParser { - public: - CaffeBiLstmParser() : CaffeNodeParser("BiLstm") {} - ~CaffeBiLstmParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BI_LSTM_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.cc deleted file mode 100644 index 7966d5b6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.cc +++ /dev/null @@ -1,46 +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 "parser/caffe/caffe_bias_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeBiasParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Bias"); - const caffe::BiasParameter &biasParam = proto.bias_param(); - if (biasParam.has_axis()) { - (void)prim->AddAttr(ops::kAxis, api::MakeValue(biasParam.axis())); - } - if (biasParam.has_num_axes()) { - (void)prim->AddAttr(dpico::kNumAxes, api::MakeValue(biasParam.num_axes())); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeBiasParser("Bias", new CaffeBiasParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.h deleted file mode 100644 index 20c24a2d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bias_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BIAS_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BIAS_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeBiasParser : public CaffeNodeParser { - public: - CaffeBiasParser() : CaffeNodeParser("Bias") {} - ~CaffeBiasParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BIAS_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.cc deleted file mode 100644 index 925ec616..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.cc +++ /dev/null @@ -1,91 +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 "parser/caffe/caffe_binary_math_parser.h" -#include -#include -#include "infer/custom.h" -#include "infer/cxx_api/add_fusion.h" -#include "infer/cxx_api/sub_fusion.h" -#include "infer/cxx_api/mul_fusion.h" -#include "infer/cxx_api/div_fusion.h" -#include "infer/squared_difference.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeBinaryMathParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - const caffe::BinaryMathParameter &binary_math_param = proto.binary_math_param(); - BaseOperatorPtr prim; - if (binary_math_param.has_operation()) { - auto operation = binary_math_param.operation(); - switch (operation) { - case caffe::BinaryMathParameter_BinaryMathOp_ADD: - prim = std::make_shared(); - break; - case caffe::BinaryMathParameter_BinaryMathOp_SUB: - prim = std::make_shared(); - break; - case caffe::BinaryMathParameter_BinaryMathOp_MUL: - prim = std::make_shared(); - break; - case caffe::BinaryMathParameter_BinaryMathOp_DIV: - prim = std::make_shared(); - break; - case caffe::BinaryMathParameter_BinaryMathOp_MAX: - prim = std::make_shared(); - break; - case caffe::BinaryMathParameter_BinaryMathOp_MIN: - prim = std::make_shared(); - break; - case caffe::BinaryMathParameter_BinaryMathOp_SQUARE_DIFF: - prim = std::make_shared(); - break; - case caffe::BinaryMathParameter_BinaryMathOp_X_DIV_Y: { - prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr. " << proto.name(); - return nullptr; - } - static_cast(prim.get())->set_type("X_DIV_Y"); - break; - } - case caffe::BinaryMathParameter_BinaryMathOp_X_LOG_Y: { - prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr. " << proto.name(); - return nullptr; - } - static_cast(prim.get())->set_type("X_LOG_Y"); - break; - } - default: - MS_LOG(ERROR) << "unsupported binary math op type. " << operation; - return nullptr; - } - } else { - prim = std::make_shared(); - } - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr. " << proto.name(); - return nullptr; - } - return prim; -} - -CaffeNodeRegistrar g_caffeBinaryMathParser("BinaryMath", new CaffeBinaryMathParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.h deleted file mode 100644 index 9522a103..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_binary_math_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BINARY_MATH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BINARY_MATH_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeBinaryMathParser : public CaffeNodeParser { - public: - CaffeBinaryMathParser() : CaffeNodeParser("binary_math") {} - ~CaffeBinaryMathParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BINARY_MATH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.cc deleted file mode 100644 index b0ee7b33..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.cc +++ /dev/null @@ -1,38 +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 "parser/caffe/caffe_bnll_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeBnllParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Bnll"); - - return prim; -} - -CaffeNodeRegistrar g_caffeBnllParser("BNLL", new CaffeBnllParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.h deleted file mode 100644 index 318e200d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_bnll_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BNLL_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BNLL_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeBnllParser : public CaffeNodeParser { - public: - CaffeBnllParser() : CaffeNodeParser("Bnll") {} - ~CaffeBnllParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_BNLL_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.cc deleted file mode 100644 index 98e72760..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.cc +++ /dev/null @@ -1,42 +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 "parser/caffe/caffe_clip_parser.h" -#include -#include -#include "infer/clip.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeClipParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::ClipParameter &clipParam = proto.clip_param(); - if (clipParam.has_min()) { - prim->set_min(clipParam.min()); - } - if (clipParam.has_max()) { - prim->set_max(clipParam.max()); - } - return prim; -} - -CaffeNodeRegistrar g_caffeClipParser("Clip", new CaffeClipParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.h deleted file mode 100644 index f2915716..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_clip_parser.h +++ /dev/null @@ -1,35 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CLIP_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CLIP_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeClipParser : public CaffeNodeParser { - public: - CaffeClipParser() : CaffeNodeParser("Clip") {} - ~CaffeClipParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CLIP_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.cc deleted file mode 100644 index 76435dea..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.cc +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2021-2023 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 "parser/caffe/caffe_concat_parser.h" -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeConcatParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::ConcatParameter &concatParam = proto.concat_param(); - if (concatParam.has_axis() && concatParam.has_concat_dim()) { - MS_LOG(ERROR) << "Concat param in caffe have concat_dim and axis simultaneously, return fail"; - return nullptr; - } - - int64_t axis = 1; - if (concatParam.has_concat_dim()) { - MS_LOG(DEBUG) << "Concat dim , set axis: " << concatParam.concat_dim(); - axis = concatParam.concat_dim(); - if (axis < 0) { - MS_LOG(ERROR) << "concat_dim value in model is smaller than 0:" << axis; - return nullptr; - } - } else if (concatParam.has_axis()) { - MS_LOG(DEBUG) << "set axis: " << concatParam.axis(); - axis = concatParam.axis(); - } - prim->set_axis(axis); - - return prim; -} - -CaffeNodeRegistrar g_caffeConcatParser("Concat", new CaffeConcatParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.h deleted file mode 100644 index 06cf0fef..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_concat_parser.h +++ /dev/null @@ -1,35 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONCAT_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONCAT_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeConcatParser : public CaffeNodeParser { - public: - CaffeConcatParser() : CaffeNodeParser("concat") {} - ~CaffeConcatParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONCAT_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.cc deleted file mode 100644 index 291101dd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.cc +++ /dev/null @@ -1,164 +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 "parser/caffe/caffe_conv_base_parser.h" -#include -#include "common/op_enum.h" - -namespace mindspore { -namespace lite { -STATUS CaffeConvBaseParser::ParsePads(const caffe::ConvolutionParameter &convParam, std::vector *pad) { - /** - * padUp = padH; - * padDown = padH; - * padLeft = padW; - * padRight = padW; - */ - if (convParam.has_pad_h() || convParam.has_pad_w()) { - if (convParam.pad_size() != 0) { - MS_LOG(ERROR) << "Either pad or pad_h/w should be specified; not both."; - return RET_ERROR; - } - - if (!convParam.has_pad_h()) { - (*pad)[0] = 0; - (*pad)[1] = 0; - (*pad)[dpico::kAxis2] = convParam.pad_w(); - (*pad)[dpico::kAxis3] = convParam.pad_w(); - } else if (!convParam.has_pad_w()) { - (*pad)[0] = convParam.pad_h(); - (*pad)[1] = convParam.pad_h(); - (*pad)[dpico::kAxis2] = 0; - (*pad)[dpico::kAxis3] = 0; - } else { - (*pad)[0] = convParam.pad_h(); - (*pad)[1] = convParam.pad_h(); - (*pad)[dpico::kAxis2] = convParam.pad_w(); - (*pad)[dpico::kAxis3] = convParam.pad_w(); - } - } else { - const int num_pad_dims = convParam.pad_size(); - int num_spatial_dims = std::max(num_pad_dims, 2); - - std::vector vec; - vec.reserve(num_spatial_dims); - for (int i = 0; i < num_spatial_dims; ++i) { - vec.push_back((num_pad_dims == 0) ? 0 : convParam.pad((num_pad_dims == 1) ? 0 : i)); - } - (*pad)[0] = vec[0]; - (*pad)[1] = vec[0]; - (*pad)[dpico::kAxis2] = vec[1]; - (*pad)[dpico::kAxis3] = vec[1]; - } - return RET_OK; -} - -STATUS CaffeConvBaseParser::ParseStrides(const caffe::ConvolutionParameter &convParam, std::vector *stride) { - if (convParam.has_stride_h() || convParam.has_stride_w()) { - if (convParam.stride_size() != 0) { - MS_LOG(ERROR) << "Either stride or stride_h/w should be specified; not both"; - return RET_ERROR; - } - if (!convParam.has_stride_h() || !convParam.has_stride_w()) { - MS_LOG(ERROR) << "stride_h/w must appear at the same time!"; - return RET_ERROR; - } - (*stride)[0] = convParam.stride_h(); - (*stride)[1] = convParam.stride_w(); - } else { - const int num_stride_dims = convParam.stride_size(); - int num_spatial_dims = std::max(num_stride_dims, 2); - - std::vector vec; - vec.reserve(num_spatial_dims); - for (int i = 0; i < num_spatial_dims; ++i) { - vec.push_back((num_stride_dims == 0) ? 1 : convParam.stride((num_stride_dims == 1) ? 0 : i)); - } - (*stride)[0] = vec[0]; - (*stride)[1] = vec[1]; - } - return RET_OK; -} - -STATUS CaffeConvBaseParser::ParseDilations(const caffe::ConvolutionParameter &convParam, - std::vector *dilation) { - const int num_dilation_dims = convParam.dilation_size(); - int num_spatial_dims = std::max(num_dilation_dims, 2); - - std::vector vec; - vec.reserve(num_spatial_dims); - for (int i = 0; i < num_spatial_dims; ++i) { - vec.push_back((num_dilation_dims == 0) ? 1 : convParam.dilation((num_dilation_dims == 1) ? 0 : i)); - } - (*dilation)[0] = vec[0]; - (*dilation)[1] = vec[1]; - return RET_OK; -} - -STATUS CaffeConvBaseParser::ParseKernels(const caffe::ConvolutionParameter &convParam, std::vector *kernel) { - if (convParam.has_kernel_h() || convParam.has_kernel_w()) { - if (convParam.kernel_size_size() != 0) { - MS_LOG(ERROR) << "Either kernel_size or kernel_h/w should be specified; not both."; - return RET_ERROR; - } - if (convParam.has_kernel_h() && convParam.has_kernel_w()) { - (*kernel)[0] = convParam.kernel_h(); - (*kernel)[1] = convParam.kernel_w(); - } else { - MS_LOG(ERROR) << "kernel_h/w must appear at the same time!"; - return RET_ERROR; - } - } else if (convParam.kernel_size_size() != 0) { - const int kernel_size = convParam.kernel_size_size(); - int num_spatial_dims = std::max(kernel_size, 2); - - std::vector vec; - vec.reserve(num_spatial_dims); - for (int i = 0; i < num_spatial_dims; i++) { - vec.push_back(convParam.kernel_size((kernel_size == 1) ? 0 : i)); - } - // default 2D - (*kernel)[0] = vec[0]; - (*kernel)[1] = vec[1]; - } else { - MS_LOG(ERROR) << "conv does not have kernel info."; - return RET_ERROR; - } - return RET_OK; -} - -int CaffeConvBaseParser::ParseGroup(const caffe::ConvolutionParameter &convParam, const std::string &layerType) { - if (convParam.has_group()) { - return convParam.group(); - } else { - return layerType == "DepthwiseConv" ? static_cast(convParam.num_output()) : 1; - } -} - -int CaffeConvBaseParser::ParseChannelOut(const caffe::ConvolutionParameter &convParam, int32_t *channelOut) { - if (channelOut == nullptr) { - MS_LOG(ERROR) << "channelOut is null"; - return RET_NULL_PTR; - } - if (!convParam.has_num_output()) { - MS_LOG(ERROR) << "Parse num_output for failed."; - return RET_ERROR; - } - *channelOut = convParam.num_output(); - return RET_OK; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.h deleted file mode 100644 index ba013d0b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_conv_base_parser.h +++ /dev/null @@ -1,48 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONV_BASE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONV_BASE_PARSER_H_ - -#include -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeConvBaseParser { - public: - CaffeConvBaseParser() = default; - - virtual ~CaffeConvBaseParser() = default; - - static STATUS ParsePads(const caffe::ConvolutionParameter &conv_param, std::vector *pad); - - static STATUS ParseStrides(const caffe::ConvolutionParameter &conv_param, std::vector *stride); - - static STATUS ParseDilations(const caffe::ConvolutionParameter &conv_param, std::vector *dilation); - - static STATUS ParseKernels(const caffe::ConvolutionParameter &conv_param, std::vector *kernel); - - static int ParseGroup(const caffe::ConvolutionParameter &convParam, const std::string &layerType); - - static int ParseChannelOut(const caffe::ConvolutionParameter &convParam, int32_t *channelOut); -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONV_BASE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.cc deleted file mode 100644 index 7782f23f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.cc +++ /dev/null @@ -1,116 +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 "parser/caffe/caffe_convolution_parser.h" -#include -#include "common/check_base.h" -#include "common/op_attr.h" -#include "infer/cxx_api/conv2d_fusion.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeConvolutionParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_pad({0, 0, 0, 0}); - prim->set_pad_mode(mindspore::PadMode::PAD); - prim->set_format(mindspore::Format::NCHW); - prim->set_activation_type(mindspore::NO_ACTIVATION); - - const caffe::ConvolutionParameter &convParam = proto.convolution_param(); - // parse kernel - std::vector kernel(kNums2, 0); - if (CaffeConvBaseParser::ParseKernels(convParam, &kernel) != RET_OK) { - return nullptr; - } - prim->set_kernel_size(kernel); - - // parse stride - std::vector stride(kNums2, 0); - if (CaffeConvBaseParser::ParseStrides(convParam, &stride) != RET_OK) { - return nullptr; - } - prim->set_stride(stride); - - // parse dilation - std::vector dilation(kNums2, 0); - if (CaffeConvBaseParser::ParseDilations(convParam, &dilation) != RET_OK) { - return nullptr; - } - prim->set_dilation(dilation); - - // parse pad - std::vector pad(kNums4, 0); - if (CaffeConvBaseParser::ParsePads(convParam, &pad) != RET_OK) { - return nullptr; - } - prim->set_pad_list(pad); - - // parse channelOut - int channel_out = 0; - if (CaffeConvBaseParser::ParseChannelOut(convParam, &channel_out) != RET_OK) { - return nullptr; - } - prim->set_out_channel(channel_out); - - // parse group - int group = 1; - if (convParam.has_group()) { - group = convParam.group(); - } else { - if (proto.type() == "DepthwiseConv") { - group = static_cast(convParam.num_output()); - } - } - prim->set_group(group); - - // parse channelIn - if (weight.blobs_size() < 1) { - MS_LOG(ERROR) << "conv weight blob is empty"; - return nullptr; - } - auto &weightBlob = weight.blobs(0); - if (weightBlob.has_shape()) { - if (weightBlob.shape().dim_size() != kNums4) { - MS_LOG(ERROR) << "Dims of Kernel should be " << kNums4; - return nullptr; - } - if (INT_MUL_OVERFLOW(weightBlob.shape().dim(1), group)) { - MS_LOG(ERROR) << "int mul overflow."; - return nullptr; - } - prim->set_in_channel(weightBlob.shape().dim(1) * group); - } else { - if (INT_MUL_OVERFLOW(weightBlob.channels(), group)) { - MS_LOG(ERROR) << "int mul overflow."; - return nullptr; - } - prim->set_in_channel(weightBlob.channels() * group); - } - - if (convParam.has_bias_term()) { - (void)prim->AddAttr(dpico::kBiasTerm, api::MakeValue(convParam.bias_term())); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeConvolutionParser("Convolution", new CaffeConvolutionParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.h deleted file mode 100644 index 82f0fa77..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_convolution_parser.h +++ /dev/null @@ -1,38 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONVOLUTION_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONVOLUTION_PARSER_H_ - -#include -#include -#include -#include "parser/caffe/caffe_conv_base_parser.h" - -namespace mindspore { -namespace lite { -class CaffeConvolutionParser : public CaffeNodeParser { - public: - CaffeConvolutionParser() : CaffeNodeParser("convolution") {} - explicit CaffeConvolutionParser(std::string nodeName) : CaffeNodeParser(std::move(nodeName)) {} - ~CaffeConvolutionParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CONVOLUTION_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.cc deleted file mode 100644 index 5b7c346a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.cc +++ /dev/null @@ -1,60 +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 "parser/caffe/caffe_crop_parser.h" -#include -#include "infer/crop.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeCropParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - if (!proto.has_crop_param()) { - prim->set_axis(dpico::kAxis2); - std::vector offsets(dpico::kDims2, 0); - prim->set_offsets(offsets); - } else { - const caffe::CropParameter &cropParam = proto.crop_param(); - if (cropParam.has_axis()) { - if (cropParam.axis() == -1) { - MS_LOG(WARNING) << "axis with -1 may lead to calculation errors when input less than 4 dims."; - } - prim->set_axis(cropParam.axis()); - } else { - prim->set_axis(dpico::kAxis2); - } - - if (cropParam.offset_size() != 0) { - std::vector offsets; - offsets.reserve(cropParam.offset_size()); - for (int i = 0; i < cropParam.offset_size(); i++) { - offsets.push_back(cropParam.offset(i)); - } - prim->set_offsets(offsets); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeCropParser("Crop", new CaffeCropParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.h deleted file mode 100644 index 42a89881..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_crop_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CROP_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CROP_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeCropParser : public CaffeNodeParser { - public: - CaffeCropParser() : CaffeNodeParser("crop") {} - ~CaffeCropParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CROP_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.cc deleted file mode 100644 index 401333e4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.cc +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright 2022 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 "parser/caffe/caffe_custom_parser.h" -#include -#include -#include "infer/custom.h" -#include "common/op_attr.h" -#include "./extended_attr.h" -#include "./pico_caffe.pb.h" -#include "op/custom_operator.h" - -namespace mindspore { -namespace lite { -namespace { -int GetAttributeType(custom::AttributeType *attribue_type, const caffe::CustomAttribute_AttributeType ¶m_type) { - if (attribue_type == nullptr) { - MS_LOG(ERROR) << "input attribue_type is nullptr. "; - return RET_ERROR; - } - switch (param_type) { - case caffe::CustomAttribute_AttributeType_UNDEFINED: - *attribue_type = custom::AttributeType::UNDEFINED; - break; - case caffe::CustomAttribute_AttributeType_FLOAT: - *attribue_type = custom::AttributeType::FLOAT; - break; - case caffe::CustomAttribute_AttributeType_INT: - *attribue_type = custom::AttributeType::INT; - break; - case caffe::CustomAttribute_AttributeType_STRING: - *attribue_type = custom::AttributeType::STRING; - break; - case caffe::CustomAttribute_AttributeType_FLOATS: - *attribue_type = custom::AttributeType::FLOATS; - break; - case caffe::CustomAttribute_AttributeType_INTS: - *attribue_type = custom::AttributeType::INTS; - break; - case caffe::CustomAttribute_AttributeType_STRINGS: - *attribue_type = custom::AttributeType::STRINGS; - break; - default: - MS_LOG(ERROR) << "Unsupported Param Type: " << param_type; - return RET_ERROR; - } - return RET_OK; -} -int SetAttrsByParam(const std::shared_ptr &custom_prim, const ::caffe::CustomAttribute &custom_param, - int index) { - if (custom_prim == nullptr) { - MS_LOG(ERROR) << "custom_prim is nullptr."; - return RET_ERROR; - } - if (custom_param.has_name()) { - (void)custom_prim->AddAttr("name" + std::to_string(index), api::MakeValue(custom_param.name())); - } - if (custom_param.has_f()) { - (void)custom_prim->AddAttr("f" + std::to_string(index), api::MakeValue(custom_param.f())); - } - if (custom_param.has_i()) { - (void)custom_prim->AddAttr("i" + std::to_string(index), api::MakeValue(custom_param.i())); - } - if (custom_param.has_s()) { - (void)custom_prim->AddAttr("s" + std::to_string(index), api::MakeValue(custom_param.s())); - } - if (custom_param.floats_size() > 0) { - std::vector floats; - for (int i = 0; i < custom_param.floats_size(); i++) { - (void)floats.emplace_back(custom_param.floats(i)); - } - (void)custom_prim->AddAttr("floats" + std::to_string(index), api::MakeValue>(floats)); - } - if (custom_param.ints_size() > 0) { - std::vector ints; - for (int i = 0; i < custom_param.ints_size(); i++) { - (void)ints.emplace_back(custom_param.ints(i)); - } - (void)custom_prim->AddAttr("ints" + std::to_string(index), api::MakeValue>(ints)); - } - if (custom_param.strings_size() > 0) { - std::vector strings; - for (int i = 0; i < custom_param.strings_size(); i++) { - (void)strings.emplace_back(custom_param.strings(i)); - } - (void)custom_prim->AddAttr("strings" + std::to_string(index), api::MakeValue>(strings)); - } - - if (custom_param.has_type()) { - custom::AttributeType attribute_type; - if (GetAttributeType(&attribute_type, custom_param.type()) != RET_OK) { - MS_LOG(ERROR) << "get custom param type failed."; - return RET_ERROR; - } - (void)custom_prim->AddAttr("type" + std::to_string(index), api::MakeValue(static_cast(attribute_type))); - } - - return RET_OK; -} -int SetAttrsByCustomParam(const std::shared_ptr &custom_prim, const caffe::LayerParameter &proto) { - if (custom_prim == nullptr) { - MS_LOG(ERROR) << "custom_prim is nullptr."; - return RET_ERROR; - } - if (!proto.has_custom_param()) { - MS_LOG(INFO) << "no custom param found"; - return RET_OK; - } - const auto &custom_param = proto.custom_param(); - int custom_param_size = custom_param.attribute_size(); - (void)custom_prim->AddAttr(dpico::kCustomParamSize, api::MakeValue(custom_param_size)); - if (custom_param_size == 0) { - MS_LOG(INFO) << "no custom param found"; - return RET_OK; - } - for (int i = 0; i < custom_param_size; i++) { - const auto &custom_param_by_index = custom_param.attribute(i); - if (SetAttrsByParam(custom_prim, custom_param_by_index, i) != RET_OK) { - MS_LOG(ERROR) << "set prim attrs from custom param failed."; - return RET_ERROR; - } - } - return RET_OK; -} -} // namespace - -BaseOperatorPtr CaffeCustomParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Custom"); - if (proto.has_custom_param()) { - const auto &custom_param = proto.custom_param(); - if (custom_param.has_extended_op_type()) { - (void)prim->AddAttr(dpico::kExtendedOpType, api::MakeValue(custom_param.extended_op_type())); - } - if (SetAttrsByCustomParam(prim, proto) != RET_OK) { - MS_LOG(ERROR) << "set attrs by custom param failed."; - return nullptr; - } - } - return prim; -} - -CaffeNodeRegistrar g_caffeCustomParser("Custom", new CaffeCustomParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.h deleted file mode 100644 index 14a674bd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_custom_parser.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CUSTOM_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CUSTOM_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeCustomParser : public CaffeNodeParser { - public: - CaffeCustomParser() : CaffeNodeParser("Custom") {} - ~CaffeCustomParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_CUSTOM_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.cc deleted file mode 100644 index 8de6eac5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.cc +++ /dev/null @@ -1,75 +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 "parser/caffe/caffe_decbbox_parser.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "include/securec.h" -#include "parser/detection_output_param_helper.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeDecBBoxParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("DecBBox"); - - if (proto.has_num_anchors()) { - (void)prim->AddAttr(dpico::kNumAnchors, api::MakeValue(proto.num_anchors())); - } - if (proto.has_num_bboxes_per_grid()) { - (void)prim->AddAttr(dpico::kNumBboxesPerGrid, api::MakeValue(proto.num_bboxes_per_grid())); - } - if (proto.has_num_coords()) { - (void)prim->AddAttr(dpico::kNumCoords, api::MakeValue(proto.num_coords())); - } - if (proto.has_num_classes()) { - uint32_t num_classes = proto.num_classes(); - (void)prim->AddAttr(dpico::kNumClasses, api::MakeValue(num_classes)); - std::map> custom_attrs; - std::vector num_classes_attr(sizeof(uint32_t)); - if (memcpy_s(num_classes_attr.data(), num_classes_attr.size() * sizeof(uint8_t), &num_classes, sizeof(uint32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kNumClasses] = num_classes_attr; - prim->set_attr(custom_attrs); - } - if (proto.has_num_grids_height()) { - (void)prim->AddAttr(dpico::kNumGridsHeight, api::MakeValue(proto.num_grids_height())); - } - if (proto.has_num_grids_width()) { - (void)prim->AddAttr(dpico::kNumGridsWidth, api::MakeValue(proto.num_grids_width())); - } - - if (dpico::SetAttrsByDecBboxParam(prim, proto) != RET_OK) { - MS_LOG(ERROR) << "set attrs by dec bbox param"; - return nullptr; - } - return prim; -} - -CaffeNodeRegistrar g_caffeDecBBoxParser("DecBBox", new CaffeDecBBoxParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.h deleted file mode 100644 index 593d657e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_decbbox_parser.h +++ /dev/null @@ -1,35 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DECBBOX_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DECBBOX_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeDecBBoxParser : public CaffeNodeParser { - public: - CaffeDecBBoxParser() : CaffeNodeParser("decbbox") {} - ~CaffeDecBBoxParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DECBBOX_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.cc deleted file mode 100644 index 97e4a737..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.cc +++ /dev/null @@ -1,116 +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 "parser/caffe/caffe_deconvolution_parser.h" -#include -#include "common/op_enum.h" -#include "common/check_base.h" -#include "infer/cxx_api/conv2d_transpose_fusion.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeDeconvolutionParser::Parse(const caffe::LayerParameter &proto, - const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_pad({0, 0, 0, 0}); - prim->set_format(mindspore::Format::NCHW); - prim->set_pad_mode(mindspore::PadMode::PAD); - prim->set_output_paddings({0, 0}); - - const caffe::ConvolutionParameter &convParam = proto.convolution_param(); - // parse pad - std::vector pad(kNums4, 0); - if (CaffeConvBaseParser::ParsePads(convParam, &pad) != RET_OK) { - return nullptr; - } - prim->set_pad_list({pad[0], pad[1], pad[2], pad[3]}); - - // parse stride - std::vector stride(kNums2, 0); - if (CaffeConvBaseParser::ParseStrides(convParam, &stride) != RET_OK) { - return nullptr; - } - prim->set_stride({stride[0], stride[1]}); - - // parse dilation - std::vector dilation(kNums2, 0); - if (CaffeConvBaseParser::ParseDilations(convParam, &dilation) != RET_OK) { - return nullptr; - } - prim->set_dilation({dilation[0], dilation[1]}); - - // parse kernel - std::vector kernel(kNums2, 0); - if (CaffeConvBaseParser::ParseKernels(convParam, &kernel) != RET_OK) { - return nullptr; - } - prim->set_kernel_size({kernel[0], kernel[1]}); - - // parse group - auto group = CaffeConvBaseParser::ParseGroup(convParam, proto.type()); - prim->set_group(group); - - // parse channelOut - int32_t channelOut; - if (CaffeConvBaseParser::ParseChannelOut(convParam, &channelOut) != RET_OK) { - return nullptr; - } - prim->set_out_channel((int64_t)channelOut); - - // parse channelIN - auto &weightBlob = weight.blobs(0); - if (weightBlob.has_shape()) { - if (weightBlob.has_shape()) { - if (static_cast(weightBlob.shape().dim_size()) != dpico::kDims4) { - MS_LOG(ERROR) << "Dims of Kernel should be " << dpico::kDims4; - return nullptr; - } - if (group == 1) { - if (INT_MUL_OVERFLOW(weightBlob.shape().dim(0), group)) { - MS_LOG(ERROR) << "int mul overflow"; - return nullptr; - } - prim->set_in_channel(weightBlob.shape().dim(0) * group); - } else { - if (INT_MUL_OVERFLOW(weightBlob.shape().dim(1), group)) { - MS_LOG(ERROR) << "int mul overflow"; - return nullptr; - } - prim->set_in_channel(weightBlob.shape().dim(1) * group); - } - } else { - if (INT_MUL_OVERFLOW(weightBlob.num(), group)) { - MS_LOG(ERROR) << "int mul overflow"; - return nullptr; - } - prim->set_in_channel(weightBlob.num() * group); - } - } - if (group != 1) { - (void)prim->AddAttr(ops::kIsDepthWise, api::MakeValue(true)); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeDeconvolutionParser("Deconvolution", new CaffeDeconvolutionParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.h deleted file mode 100644 index 00e7d0e5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_deconvolution_parser.h +++ /dev/null @@ -1,35 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DECONVOLUTION_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DECONVOLUTION_PARSER_H_ - -#include -#include "parser/caffe/caffe_conv_base_parser.h" - -namespace mindspore { -namespace lite { -class CaffeDeconvolutionParser : public CaffeNodeParser { - public: - CaffeDeconvolutionParser() : CaffeNodeParser("deconvolution") {} - ~CaffeDeconvolutionParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DECONVOLUTION_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.cc deleted file mode 100644 index 29b53241..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.cc +++ /dev/null @@ -1,35 +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 "parser/caffe/caffe_depthwise_conv_parser.h" -#include -#include "infer/cxx_api/conv2d_fusion.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeDepthwiseConvolutionParser::Parse(const caffe::LayerParameter &proto, - const caffe::LayerParameter &weight) { - auto prim = CaffeConvolutionParser::Parse(proto, weight); - if (prim != nullptr) { - (void)prim->AddAttr(ops::kIsDepthWise, api::MakeValue(true)); - } - return prim; -} - -CaffeNodeRegistrar g_caffeDepthwiseConvParser("DepthwiseConv", new CaffeDepthwiseConvolutionParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.h deleted file mode 100644 index 67d96044..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_depthwise_conv_parser.h +++ /dev/null @@ -1,35 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DEPTHWISE_CONV_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DEPTHWISE_CONV_PARSER_H_ - -#include -#include "parser/caffe/caffe_convolution_parser.h" - -namespace mindspore { -namespace lite { -class CaffeDepthwiseConvolutionParser : public CaffeConvolutionParser { - public: - CaffeDepthwiseConvolutionParser() : CaffeConvolutionParser("depthwise_convolution") {} - ~CaffeDepthwiseConvolutionParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DEPTHWISE_CONV_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.cc deleted file mode 100644 index ea6414d7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.cc +++ /dev/null @@ -1,62 +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 "parser/caffe/caffe_detection_output_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "parser/detection_output_param_helper.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeDetectionOutputParser::Parse(const caffe::LayerParameter &proto, - const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("DetectionOutput"); - - if (proto.has_num_anchors()) { - (void)prim->AddAttr(dpico::kNumAnchors, api::MakeValue(proto.num_anchors())); - } - if (proto.has_num_bboxes_per_grid()) { - (void)prim->AddAttr(dpico::kNumBboxesPerGrid, api::MakeValue(proto.num_bboxes_per_grid())); - } - if (proto.has_num_coords()) { - (void)prim->AddAttr(dpico::kNumCoords, api::MakeValue(proto.num_coords())); - } - if (proto.has_num_classes()) { - (void)prim->AddAttr(dpico::kNumClasses, api::MakeValue(proto.num_classes())); - } - if (proto.has_num_grids_height()) { - (void)prim->AddAttr(dpico::kNumGridsHeight, api::MakeValue(proto.num_grids_height())); - } - if (proto.has_num_grids_width()) { - (void)prim->AddAttr(dpico::kNumGridsWidth, api::MakeValue(proto.num_grids_width())); - } - if (dpico::SetAttrsByDetectionOutputParam(prim, proto) != RET_OK) { - MS_LOG(ERROR) << "set attrs by detection output param failed."; - return nullptr; - } - return prim; -} - -CaffeNodeRegistrar g_caffeDetectionOutputParser("DetectionOutput", new CaffeDetectionOutputParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.h deleted file mode 100644 index 88c77d54..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_detection_output_parser.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DETECTION_OUTPUT_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DETECTION_OUTPUT_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" -#include "op/detection_output_operator.h" - -namespace mindspore { -namespace lite { -class CaffeDetectionOutputParser : public CaffeNodeParser { - public: - CaffeDetectionOutputParser() : CaffeNodeParser("detection_output") {} - ~CaffeDetectionOutputParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_DETECTION_OUTPUT_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.cc deleted file mode 100644 index c9a59d0c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.cc +++ /dev/null @@ -1,113 +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 "parser/caffe/caffe_eltwise_parser.h" -#include -#include -#include -#include "infer/cxx_api/sub_fusion.h" -#include "infer/eltwise.h" -#include "infer/custom.h" -#include "common/op_attr.h" -#include "common/check_base.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -namespace { -bool IsSubOp(const caffe::EltwiseParameter &eltwiseParam) { - return eltwiseParam.operation() == caffe::EltwiseParameter::SUM && eltwiseParam.coeff_size() != 0 && - (std::fabs(eltwiseParam.coeff(0) - 1) <= std::numeric_limits::epsilon() && - std::fabs(eltwiseParam.coeff(1) + 1) <= std::numeric_limits::epsilon()); -} -bool IsEltwiseOp(const caffe::EltwiseParameter &eltwiseParam) { - return eltwiseParam.coeff_size() == 0 || - (eltwiseParam.operation() != caffe::EltwiseParameter::PROD && - std::fabs(eltwiseParam.coeff(0) - 1) <= std::numeric_limits::epsilon() && - std::fabs(eltwiseParam.coeff(1) - 1) <= std::numeric_limits::epsilon()); -} -int SetEltwiseMode(const caffe::EltwiseParameter &eltwiseParam, const BaseOperatorPtr &prim) { - MS_CHECK_TRUE_MSG(prim != nullptr, RET_ERROR, "prim is nullptr."); - if (eltwiseParam.has_operation()) { - switch (eltwiseParam.operation()) { - case caffe::EltwiseParameter::PROD: - (void)prim->AddAttr(ops::kMode, api::MakeValue(static_cast(mindspore::EltwiseMode::PROD))); - break; - case caffe::EltwiseParameter::SUM: - (void)prim->AddAttr(ops::kMode, api::MakeValue(static_cast(mindspore::EltwiseMode::SUM))); - break; - case caffe::EltwiseParameter::MAX: - (void)prim->AddAttr(ops::kMode, api::MakeValue(static_cast(mindspore::EltwiseMode::MAXIMUM))); - break; - default: - MS_LOG(ERROR) << "Eltwise parse params fail, unsupported operation: " << eltwiseParam.operation(); - return RET_ERROR; - } - } else { - (void)prim->AddAttr(ops::kMode, api::MakeValue(static_cast(mindspore::EltwiseMode::SUM))); - } - return RET_OK; -} -BaseOperatorPtr ParseToCustomOp(const caffe::EltwiseParameter &eltwiseParam) { - auto prim = std::make_shared(); - MS_CHECK_TRUE_MSG(prim != nullptr, nullptr, "prim is nullptr."); - prim->set_type("Eltwise"); - if (eltwiseParam.coeff_size() != 0) { - auto coeff_vals = std::vector(eltwiseParam.coeff().begin(), eltwiseParam.coeff().end()); - (void)prim->AddAttr(dpico::kCoeffs, api::MakeValue(coeff_vals)); - } - if (SetEltwiseMode(eltwiseParam, prim) != RET_OK) { - MS_LOG(ERROR) << "set eltwise mode failed."; - return nullptr; - } - return prim; -} -} // namespace -BaseOperatorPtr CaffeEltwiseParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - const caffe::EltwiseParameter &eltwiseParam = proto.eltwise_param(); - if (eltwiseParam.coeff_size() != 0 && eltwiseParam.coeff_size() != proto.bottom_size()) { - MS_LOG(ERROR) << "Coeff size(" << eltwiseParam.coeff_size() - << ") check fail, Eltwise Layer takes one coefficient per bottom blob."; - return nullptr; - } - if (proto.bottom_size() < kNums2) { - MS_LOG(ERROR) << "Eltwise Op " << proto.name() << " need at least 2 inputs,but input size is " - << proto.bottom_size(); - return nullptr; - } else if (proto.bottom_size() == kNums2) { - if (IsSubOp(eltwiseParam)) { - auto prim = std::make_shared(); - MS_CHECK_TRUE_MSG(prim != nullptr, nullptr, "prim is nullptr."); - return prim; - } else if (IsEltwiseOp(eltwiseParam)) { - auto prim = std::make_shared(); - MS_CHECK_TRUE_MSG(prim != nullptr, nullptr, "prim is nullptr."); - if (SetEltwiseMode(eltwiseParam, prim) != RET_OK) { - MS_LOG(ERROR) << "set eltwise mode failed. " << proto.name(); - return nullptr; - } - return prim; - } else { - return ParseToCustomOp(eltwiseParam); - } - } else { - return ParseToCustomOp(eltwiseParam); - } -} - -CaffeNodeRegistrar g_caffeEltwiseParser("Eltwise", new CaffeEltwiseParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.h deleted file mode 100644 index aebbcee6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_eltwise_parser.h +++ /dev/null @@ -1,35 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ELTWISE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ELTWISE_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeEltwiseParser : public CaffeNodeParser { - public: - CaffeEltwiseParser() : CaffeNodeParser("eltwise") {} - ~CaffeEltwiseParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ELTWISE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.cc deleted file mode 100644 index 42c60e38..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.cc +++ /dev/null @@ -1,52 +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 "parser/caffe/caffe_exp_parser.h" -#include -#include -#include "infer/cxx_api/exp_fusion.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeExpParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::ExpParameter &exp_param = proto.exp_param(); - if (exp_param.has_base()) { - prim->set_base(exp_param.base()); - } else { - prim->set_base(-1); // -1 represent base = e - } - if (exp_param.has_scale()) { - prim->set_scale(exp_param.scale()); - } else { - prim->set_scale(1); - } - if (exp_param.has_shift()) { - prim->set_shift(exp_param.shift()); - } else { - prim->set_shift(0); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeExpParser("Exp", new CaffeExpParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.h deleted file mode 100644 index 61fa09c7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_exp_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_EXP_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_EXP_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeExpParser : public CaffeNodeParser { - public: - CaffeExpParser() : CaffeNodeParser("exp") {} - ~CaffeExpParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_EXP_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.cc deleted file mode 100644 index df0928ac..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.cc +++ /dev/null @@ -1,121 +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 "parser/caffe/caffe_extract_parser.h" -#include -#include -#include -#include -#include "common/check_base.h" -#include "common/op_attr.h" -#include "infer/custom.h" -#include "mindspore/ops/op_def/op_name.h" -#include "include/securec.h" - -namespace mindspore { -namespace lite { -namespace { -STATUS SetExtractAxis(const caffe::ExtractParameter &extract_param, ops::Custom *prim, - std::map> *custom_attrs) { - MS_ASSERT(prim != nullptr); - MS_ASSERT(custom_attrs != nullptr); - int32_t axis = 1; - if (extract_param.has_axis()) { - axis = extract_param.axis(); - } else if (extract_param.has_slice_dim()) { - axis = static_cast(extract_param.slice_dim()); - } - (void)prim->AddAttr(ops::kAxis, api::MakeValue(axis)); - - std::vector axis_attr(sizeof(int32_t)); - if (memcpy_s(axis_attr.data(), axis_attr.size() * sizeof(uint8_t), &axis, sizeof(int32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return RET_ERROR; - } - (*custom_attrs)[ops::kAxis] = axis_attr; - return RET_OK; -} - -STATUS SetExtractSlicePointBegin(const caffe::ExtractParameter &extract_param, ops::Custom *prim, - std::map> *custom_attrs) { - MS_ASSERT(prim != nullptr); - MS_ASSERT(custom_attrs != nullptr); - uint32_t slice_point_begin = 0; - if (extract_param.has_slice_point_begin()) { - slice_point_begin = extract_param.slice_point_begin(); - } - (void)prim->AddAttr(dpico::kSlicePointBegin, api::MakeValue(slice_point_begin)); - - std::vector slice_point_begin_attr(sizeof(uint32_t)); - if (memcpy_s(slice_point_begin_attr.data(), slice_point_begin_attr.size() * sizeof(uint8_t), &slice_point_begin, - sizeof(uint32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return RET_ERROR; - } - (*custom_attrs)[dpico::kSlicePointBegin] = slice_point_begin_attr; - return RET_OK; -} - -STATUS SetExtractSlicePointEnd(const caffe::ExtractParameter &extract_param, ops::Custom *prim, - std::map> *custom_attrs) { - MS_ASSERT(prim != nullptr); - MS_ASSERT(custom_attrs != nullptr); - uint32_t slice_point_end = 1; - if (extract_param.has_slice_point_end()) { - slice_point_end = extract_param.slice_point_end(); - } - (void)prim->AddAttr(dpico::kSlicePointEnd, api::MakeValue(slice_point_end)); - - std::vector slice_point_end_attr(sizeof(uint32_t)); - if (memcpy_s(slice_point_end_attr.data(), slice_point_end_attr.size() * sizeof(uint8_t), &slice_point_end, - sizeof(uint32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return RET_ERROR; - } - (*custom_attrs)[dpico::kSlicePointEnd] = slice_point_end_attr; - return RET_OK; -} -} // namespace -BaseOperatorPtr CaffeExtractParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Extract"); - - std::map> custom_attrs{}; - const caffe::ExtractParameter &extract_param = proto.extract_param(); - if (SetExtractAxis(extract_param, prim.get(), &custom_attrs) != RET_OK) { - MS_LOG(ERROR) << "set extract axis failed."; - return nullptr; - } - if (SetExtractSlicePointBegin(extract_param, prim.get(), &custom_attrs) != RET_OK) { - MS_LOG(ERROR) << "set extract slice point begin failed."; - return nullptr; - } - if (SetExtractSlicePointEnd(extract_param, prim.get(), &custom_attrs) != RET_OK) { - MS_LOG(ERROR) << "set extract slice point end failed."; - return nullptr; - } - - prim->set_attr(custom_attrs); - return prim; -} - -CaffeNodeRegistrar g_caffeExtractParser("Extract", new CaffeExtractParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.h deleted file mode 100644 index 1a5d282c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_extract_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_EXTRACT_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_EXTRACT_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeExtractParser : public CaffeNodeParser { - public: - CaffeExtractParser() : CaffeNodeParser("extract") {} - ~CaffeExtractParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_EXTRACT_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.cc deleted file mode 100644 index ac9456ce..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.cc +++ /dev/null @@ -1,45 +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 "parser/caffe/caffe_flatten_parser.h" -#include -#include "common/op_attr.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeFlattenParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::FlattenParameter &flatten_param = proto.flatten_param(); - - if (flatten_param.has_axis()) { - (void)prim->AddAttr(dpico::kStartAxis, api::MakeValue(flatten_param.axis())); - } - - if (flatten_param.has_end_axis()) { - (void)prim->AddAttr(dpico::kEndAxis, api::MakeValue(flatten_param.end_axis())); - } - - return prim; -} - -CaffeNodeRegistrar g_CaffeFlattenParser("Flatten", new CaffeFlattenParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.h deleted file mode 100644 index 0e4f7680..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_flatten_parser.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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_FLATTEN_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_FLATTEN_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore::lite { -class CaffeFlattenParser : public CaffeNodeParser { - public: - CaffeFlattenParser() : CaffeNodeParser("flatten") {} - ~CaffeFlattenParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace mindspore::lite - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_FLATTEN_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.cc deleted file mode 100644 index b4e1b157..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.cc +++ /dev/null @@ -1,61 +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 "parser/caffe/caffe_gru_parser.h" -#include -#include -#include -#include "infer/custom.h" -#include "common/op_attr.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeGruParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Gru"); - - if (proto.has_recurrent_param()) { - const auto &gru_param = proto.recurrent_param(); - if (gru_param.has_num_output()) { - (void)prim->AddAttr(dpico::kNumOutput, api::MakeValue(gru_param.num_output())); - } - if (gru_param.has_expose_hidden()) { - (void)prim->AddAttr(dpico::kExposeHidden, api::MakeValue(gru_param.expose_hidden())); - (void)prim->AddAttr(dpico::kOutputLastFrameFlag, api::MakeValue(gru_param.expose_hidden())); - (void)prim->AddAttr(dpico::kInitialHOnlineFlag, api::MakeValue(gru_param.expose_hidden())); - (void)prim->AddAttr(dpico::kUseDefaultInitialHFlag, api::MakeValue(!gru_param.expose_hidden())); - } else { - (void)prim->AddAttr(dpico::kUseDefaultInitialHFlag, api::MakeValue(true)); - } - } - - // set default value - (void)prim->AddAttr(dpico::kHasSplitHWeightFlag, api::MakeValue(true)); - (void)prim->AddAttr(dpico::kHasSplitBiasFlag, api::MakeValue(false)); - (void)prim->AddAttr(dpico::kGruWeightOrderZrhFlag, api::MakeValue(false)); - (void)prim->AddAttr(dpico::kOnnxModeOutFlag, api::MakeValue(false)); - (void)prim->AddAttr(dpico::kKeepDirectionDimFlag, api::MakeValue(false)); - - return prim; -} - -CaffeNodeRegistrar g_caffeGruParser("GRU", new CaffeGruParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.h deleted file mode 100644 index 66372162..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_gru_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_GRU_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_GRU_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeGruParser : public CaffeNodeParser { - public: - CaffeGruParser() : CaffeNodeParser("Gru") {} - ~CaffeGruParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_GRU_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.cc deleted file mode 100644 index c5c1d222..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.cc +++ /dev/null @@ -1,102 +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 "parser/caffe/caffe_innerproduct_parser.h" -#include -#include "common/op_enum.h" -#include "common/op_attr.h" -#include "common/data_transpose_utils.h" -#include "infer/cxx_api/full_connection.h" - -namespace mindspore { -namespace lite { -namespace { -constexpr int kInnerProductAxis = 2; -void TransformShape(caffe::BlobShape *shape) { - auto origin_row = shape->dim(0); - auto origin_col = shape->dim(1); - shape->clear_dim(); - shape->add_dim(origin_col); - shape->add_dim(origin_row); -} -} // namespace -BaseOperatorPtr CaffeInnerProductParser::Parse(const caffe::LayerParameter &proto, - const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_activation_type(mindspore::ActivationType::NO_ACTIVATION); - const caffe::InnerProductParameter &innerProductParam = proto.inner_product_param(); - - if (innerProductParam.has_transpose() && innerProductParam.transpose()) { - auto mutable_weight = const_cast(&weight); - if (mutable_weight == nullptr) { - MS_LOG(ERROR) << "weight is nullptr."; - return nullptr; - } - auto blob = mutable_weight->mutable_blobs(0); - if (blob == nullptr) { - MS_LOG(ERROR) << "blob is nullptr."; - return nullptr; - } - auto shape = blob->mutable_shape(); - if (shape == nullptr) { - MS_LOG(ERROR) << "shape is nullptr."; - return nullptr; - } - if (blob->mutable_data() == nullptr) { - MS_LOG(ERROR) << "blob mutable data is nullptr."; - return nullptr; - } - if (shape->dim_size() < kNums2) { - MS_LOG(ERROR) << "weight shape size " << shape->dim_size() << " should greater than 1"; - return nullptr; - } - if (shape->dim(0) == 0 || shape->dim(1) == 0) { - MS_LOG(ERROR) << "dim val can't be 0."; - return nullptr; - } - dpico::TransposeMatrix(blob->mutable_data()->mutable_data(), static_cast(shape->dim(0)), - static_cast(shape->dim(1))); - TransformShape(shape); - } - - if (!innerProductParam.has_num_output()) { - MS_LOG(ERROR) << "InnerProduct Parse num_output for " << proto.name().c_str() << " failed."; - return nullptr; - } else { - (void)prim->AddAttr(dpico::kNumOutput, api::MakeValue(static_cast(innerProductParam.num_output()))); - } - - if (innerProductParam.axis() == 1 || innerProductParam.axis() == kInnerProductAxis) { - prim->set_axis(innerProductParam.axis()); - prim->set_use_axis(true); - } else { - MS_LOG(ERROR) << "InnerProduct Parse axis only support default 1 OR 2, but actually " << innerProductParam.axis(); - return nullptr; - } - if (innerProductParam.bias_term()) { - prim->set_has_bias(true); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeInnerProductParser("InnerProduct", new CaffeInnerProductParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.h deleted file mode 100644 index ce2b8c67..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_innerproduct_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INNERPRODUCT_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INNERPRODUCT_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeInnerProductParser : public CaffeNodeParser { - public: - CaffeInnerProductParser() : CaffeNodeParser("innerproduct") {} - ~CaffeInnerProductParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INNERPRODUCT_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.cc deleted file mode 100644 index a480dc32..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.cc +++ /dev/null @@ -1,90 +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 "parser/caffe/caffe_inspector.h" -#include "src/common/log_adapter.h" - -namespace mindspore { -namespace lite { -STATUS CaffeInspector::InspectModel(const caffe::NetParameter &proto) { - net = proto; - - if (proto.layer_size() == 0) { - MS_LOG(ERROR) << "net layer num is zero, prototxt file may be invalid."; - return RET_ERROR; - } - - ParseInput(); - - SetLayerTopsAndBottoms(); - - FindGraphInputsAndOutputs(); - - return RET_OK; -} - -void CaffeInspector::ParseInput() { - if (net.input_size() > 0) { - MS_LOG(INFO) << "This net exist input."; - for (int i = 0; i < net.input_size(); i++) { - graphInput.insert(net.input(i)); - } - } -} - -void CaffeInspector::FindGraphInputsAndOutputs() { - for (const auto &iter : layerBottoms) { - if (std::find(layerTops.begin(), layerTops.end(), iter) == layerTops.end()) { - graphInput.insert(iter); - } - } - for (const auto &iter : layerTops) { - if (layerBottoms.find(iter) == layerBottoms.end()) { - auto top_name = iter; - std::string suffix = "_report"; - auto pos = top_name.rfind(suffix); - if (pos != std::string::npos && pos == top_name.size() - suffix.length()) { - (void)top_name.replace(pos, suffix.length(), ""); - if (layerBottoms.find(top_name) != layerBottoms.end()) { - continue; - } - } - graphOutput.push_back(iter); - } - } -} - -void CaffeInspector::SetLayerTopsAndBottoms() { - for (int32_t i = 0; i < net.layer_size(); i++) { - auto &layer = const_cast(net.layer(i)); - if (layer.top_size() == 1 && layer.bottom_size() == 1 && layer.top(0) == layer.bottom(0)) { - continue; - } - if (layer.top_size() == 1 && layer.bottom_size() == 0) { - graphInput.insert(layer.top(0)); - } - for (int j = 0; j < layer.top_size(); j++) { - if (std::find(layerTops.begin(), layerTops.end(), layer.top(j)) == layerTops.end()) { - layerTops.push_back(layer.top(j)); - } - } - for (int j = 0; j < layer.bottom_size(); j++) { - layerBottoms.insert(layer.bottom(j)); - } - } -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.h deleted file mode 100644 index 41d2752e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_inspector.h +++ /dev/null @@ -1,57 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INSPECTOR_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INSPECTOR_H_ - -#include -#include -#include -#include -#include -#include "./pico_caffe.pb.h" -#include "include/errorcode.h" - -namespace mindspore { -namespace lite { -class CaffeInspector { - public: - CaffeInspector() = default; - ~CaffeInspector() = default; - - STATUS InspectModel(const caffe::NetParameter &proto); - - std::set GetGraphInput() { return graphInput; } - std::vector GetGraphOutput() { return graphOutput; } - - private: - void ParseInput(); - void FindGraphInputsAndOutputs(); - void SetLayerTopsAndBottoms(); - caffe::NetParameter net; - - std::vector layerTops; - std::set layerBottoms; - - std::set graphInput; - std::vector graphOutput; -}; - -using CaffeInspectorPtr = std::shared_ptr; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INSPECTOR_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.cc deleted file mode 100644 index bcacb470..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.cc +++ /dev/null @@ -1,76 +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 "parser/caffe/caffe_interp_parser.h" -#include -#include "include/registry/converter_context.h" -#include "common/op_attr.h" -#include "infer/resize.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeInterpParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_method(mindspore::ResizeMethod::LINEAR); - prim->set_coordinate_transform_mode(mindspore::CoordinateTransformMode::ALIGN_CORNERS); - - const caffe::InterpParameter &interp_param = proto.interp_param(); - if (interp_param.has_height()) { - int64_t height = interp_param.height(); - if (height <= 0) { - MS_LOG(ERROR) << "Interp height can not <= 0"; - return nullptr; - } - prim->set_new_height(height); - } - - if (interp_param.has_width()) { - int64_t width = interp_param.width(); - if (width <= 0) { - MS_LOG(ERROR) << "Interp width can not <= 0"; - return nullptr; - } - prim->set_new_width(width); - } - - if (interp_param.has_zoom_factor()) { - (void)prim->AddAttr(dpico::kZoomFactor, api::MakeValue(interp_param.zoom_factor())); - } - - if (interp_param.has_shrink_factor()) { - (void)prim->AddAttr(dpico::kShrinkFactor, api::MakeValue(interp_param.shrink_factor())); - } - - if (interp_param.has_pad_beg()) { - (void)prim->AddAttr(dpico::kPadBeg, api::MakeValue(interp_param.pad_beg())); - } - - if (interp_param.has_pad_end()) { - (void)prim->AddAttr(dpico::kPadEnd, api::MakeValue(interp_param.pad_end())); - } - int fmk_type = static_cast(converter::FmkType::kFmkTypeCaffe); - (void)prim->AddAttr(ops::kFmkType, api::MakeValue(static_cast(fmk_type))); - return prim; -} - -CaffeNodeRegistrar g_caffeInterpParser("Interp", new CaffeInterpParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.h deleted file mode 100644 index aa1bb0dd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_interp_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INTERP_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INTERP_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeInterpParser : public CaffeNodeParser { - public: - CaffeInterpParser() : CaffeNodeParser("Interp") {} - ~CaffeInterpParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_INTERP_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.cc deleted file mode 100644 index 55d5afe3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.cc +++ /dev/null @@ -1,51 +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 "parser/caffe/caffe_log_parser.h" -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeLogParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - if (proto.has_log_param()) { - const caffe::LogParameter &log_param = proto.log_param(); - - if (log_param.has_base()) { - (void)prim->AddAttr(ops::kBase, api::MakeValue(log_param.base())); - } - - if (log_param.has_scale()) { - (void)prim->AddAttr(ops::kScale, api::MakeValue(log_param.scale())); - } - - if (log_param.has_shift()) { - (void)prim->AddAttr(ops::kShift, api::MakeValue(log_param.shift())); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeLogParser("Log", new CaffeLogParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.h deleted file mode 100644 index fc9e4494..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_log_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LOG_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LOG_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeLogParser : public CaffeNodeParser { - public: - CaffeLogParser() : CaffeNodeParser("Log") {} - ~CaffeLogParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LOG_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.cc deleted file mode 100644 index a557c0a0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.cc +++ /dev/null @@ -1,78 +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 "parser/caffe/caffe_lrn_parser.h" -#include -#include "common/op_attr.h" -#include "infer/lrn.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeLRNParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - int64_t size = 5; - float alpha = 1; - float beta = 0.75; - float k = 1; - - if (proto.has_lrn_param()) { - const caffe::LRNParameter &lrnParam = proto.lrn_param(); - if (lrnParam.has_local_size()) { - size = lrnParam.local_size(); - } - if (lrnParam.has_alpha()) { - alpha = lrnParam.alpha(); - } - if (lrnParam.has_beta()) { - beta = lrnParam.beta(); - } - if (lrnParam.has_k()) { - k = lrnParam.k(); - } - if (lrnParam.has_norm_region()) { - if (lrnParam.norm_region() == caffe::LRNParameter_NormRegion::LRNParameter_NormRegion_WITHIN_CHANNEL) { - (void)prim->AddAttr(ops::kNormRegion, api::MakeValue("WITHIN_CHANNEL")); - } else if (lrnParam.norm_region() == caffe::LRNParameter_NormRegion::LRNParameter_NormRegion_ACROSS_CHANNELS) { - (void)prim->AddAttr(ops::kNormRegion, api::MakeValue("ACROSS_CHANNELS")); - } else { - MS_LOG(ERROR) << "invalid norm region param. " << lrnParam.norm_region(); - return nullptr; - } - } - } - - if (size == 0) { - MS_LOG(ERROR) << "Divide-by-zero error."; - return nullptr; - } - alpha /= size; - - prim->set_beta(beta); - prim->set_alpha(alpha); - int two_sides = 2; - prim->set_depth_radius(size / two_sides); - (void)prim->AddAttr(dpico::kLrnK, api::MakeValue(k)); - return prim; -} - -CaffeNodeRegistrar g_caffeLRNParser("LRN", new CaffeLRNParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.h deleted file mode 100644 index eb296988..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lrn_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LRN_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LRN_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeLRNParser : public CaffeNodeParser { - public: - CaffeLRNParser() : CaffeNodeParser("LRN") {} - ~CaffeLRNParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LRN_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.cc deleted file mode 100644 index bad5e8d4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.cc +++ /dev/null @@ -1,59 +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 "parser/caffe/caffe_lstm_parser.h" -#include -#include -#include "infer/custom.h" -#include "common/op_attr.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeLstmParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Lstm"); - - if (proto.has_recurrent_param()) { - const auto &lstm_param = proto.recurrent_param(); - if (lstm_param.has_num_output()) { - (void)prim->AddAttr(dpico::kNumOutput, api::MakeValue(lstm_param.num_output())); - } - if (lstm_param.has_expose_hidden()) { - (void)prim->AddAttr(dpico::kExposeHidden, api::MakeValue(lstm_param.expose_hidden())); - (void)prim->AddAttr(dpico::kOutputLastFrameFlag, api::MakeValue(lstm_param.expose_hidden())); - (void)prim->AddAttr(dpico::kInitialHOnlineFlag, api::MakeValue(lstm_param.expose_hidden())); - (void)prim->AddAttr(dpico::kUseDefaultInitialHFlag, api::MakeValue(!lstm_param.expose_hidden())); - (void)prim->AddAttr(dpico::kInitialCOnlineFlag, api::MakeValue(lstm_param.expose_hidden())); - (void)prim->AddAttr(dpico::kUseDefaultInitialCFlag, api::MakeValue(!lstm_param.expose_hidden())); - } - } - - // set default value - (void)prim->AddAttr(dpico::kKeepDirectionDimFlag, api::MakeValue(false)); - (void)prim->AddAttr(dpico::kPeepHoleFlag, api::MakeValue(false)); - (void)prim->AddAttr(dpico::kLstmWeightOrderIofcFlag, api::MakeValue(false)); - (void)prim->AddAttr(dpico::kSequenceLensOnlineFlag, api::MakeValue(false)); - - return prim; -} - -CaffeNodeRegistrar g_caffeLSTMParser("LSTM", new CaffeLstmParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.h deleted file mode 100644 index 3e011a19..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_lstm_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LSTM_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LSTM_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeLstmParser : public CaffeNodeParser { - public: - CaffeLstmParser() : CaffeNodeParser("Lstm") {} - ~CaffeLstmParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_LSTM_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.cc deleted file mode 100644 index ed88f4d4..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.cc +++ /dev/null @@ -1,49 +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 "parser/caffe/caffe_matmul_parser.h" -#include -#include "common/op_attr.h" -#include "infer/cxx_api/mat_mul_fusion.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeMatmulParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - if (proto.has_matmul_param()) { - const caffe::MatMulParameter &matmul_param = proto.matmul_param(); - if (matmul_param.has_dim_1()) { - (void)prim->AddAttr(dpico::kDim1, api::MakeValue(matmul_param.dim_1())); - } - if (matmul_param.has_dim_2()) { - (void)prim->AddAttr(dpico::kDim2, api::MakeValue(matmul_param.dim_2())); - } - if (matmul_param.has_dim_3()) { - (void)prim->AddAttr(dpico::kDim3, api::MakeValue(matmul_param.dim_3())); - } - } - prim->set_transpose_a(false); - prim->set_transpose_b(true); - return prim; -} - -CaffeNodeRegistrar g_caffeMatmulParser("MatMul", new CaffeMatmulParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.h deleted file mode 100644 index 4c33be2f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_matmul_parser.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2020 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MATMUL_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MATMUL_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeMatmulParser : public CaffeNodeParser { - public: - CaffeMatmulParser() : CaffeNodeParser("Matmul") {} - ~CaffeMatmulParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MATMUL_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.cc deleted file mode 100644 index ea4c7159..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.cc +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2022 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 "parser/caffe/caffe_mish_parser.h" -#include -#include -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -namespace {} // namespace -BaseOperatorPtr CaffeMishParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Mish"); - - return prim; -} - -CaffeNodeRegistrar g_caffeMishParser("Mish", new CaffeMishParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.h deleted file mode 100644 index 5ef2c33b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mish_parser.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MISH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MISH_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeMishParser : public CaffeNodeParser { - public: - CaffeMishParser() : CaffeNodeParser("Mish") {} - ~CaffeMishParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MISH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.cc deleted file mode 100644 index ebc320b2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.cc +++ /dev/null @@ -1,587 +0,0 @@ -/** - * Copyright 2020 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 "parser/caffe/caffe_model_parser.h" -#include -#include -#include -#include -#include -#include -#include "parser/caffe/caffe_inspector.h" -#include "parser/caffe/caffe_node_parser_registry.h" -#include "common/anf_util.h" -#include "parser/parser_utils.h" -#include "common/op_enum.h" -#include "parser/unify_format.h" -#include "mindapi/ir/func_graph.h" -#include "include/registry/converter_context.h" -#include "infer/make_tuple.h" -#include "infer/return.h" -#include "infer/tuple_get_item.h" - -using mindspore::converter::kFmkTypeCaffe; -namespace mindspore { -namespace lite { -namespace { -bool IsSkipedLayer(const caffe::LayerParameter &layer) { - if (layer.type() == "Input" || layer.type() == "Dropout" || layer.type() == "Split") { - return true; - } - return layer.include_size() == 1 && layer.include(0).phase() == caffe::TRAIN; -} - -void FcSqueezeWeightBias(const caffe::LayerParameter &layer, int blob_index, std::vector *shape) { - if (layer.type() == "InnerProduct") { - if (blob_index == 0) { - if (shape->size() == dpico::kDims4 && shape->at(0) == 1 && shape->at(1) == 1) { - (void)shape->erase(shape->begin()); - (void)shape->erase(shape->begin()); - } - } else if (blob_index == 1) { - if (shape->size() == dpico::kDims4 && shape->at(0) == 1 && shape->at(1) == 1 && shape->at(dpico::kAxis2) == 1) { - (void)shape->erase(shape->begin()); - (void)shape->erase(shape->begin()); - (void)shape->erase(shape->begin()); - } - } - } -} -} // namespace - -CaffeModelParser::CaffeModelParser() = default; - -CaffeModelParser::~CaffeModelParser() = default; - -api::FuncGraphPtr CaffeModelParser::Parse(const converter::ConverterParameters &flag) { - auto model_file = flag.model_file; - auto weight_file = flag.weight_file; - STATUS status = InitOriginModel(model_file, weight_file); - if (status != RET_OK) { - MS_LOG(ERROR) << "init origin model failed."; - return nullptr; - } - res_graph_ = api::FuncGraph::Create(); - if (res_graph_ == nullptr) { - return nullptr; - } - status = ConvertGraphInputs(); - if (status != RET_OK) { - MS_LOG(ERROR) << "convert graph inputs failed."; - return nullptr; - } - - status = ConvertLayers(); - if (status != RET_OK) { - MS_LOG(ERROR) << "convert layers failed."; - return nullptr; - } - - status = ConvertGraphOutputs(); - if (status != RET_OK) { - MS_LOG(ERROR) << "convert graph outputs failed."; - return nullptr; - } - res_graph_->set_attr("graph_name", api::MakeValue("main_graph")); - res_graph_->set_attr("fmk", api::MakeValue(static_cast(kFmkTypeCaffe))); - std::set all_func_graphs = {}; - GetAllFuncGraph(res_graph_, &all_func_graphs); - if (PostAdjust(all_func_graphs) != RET_OK) { - MS_LOG(ERROR) << "AdjustForAnf failed."; - return nullptr; - } - auto unify_format = std::make_shared(); - if (unify_format == nullptr) { - MS_LOG(ERROR) << "unify format is nullptr."; - return nullptr; - } - if (!unify_format->Run(res_graph_)) { - MS_LOG(ERROR) << "Run insert transpose failed."; - return nullptr; - } - return res_graph_; -} - -STATUS CaffeModelParser::ConvertLayers() { - STATUS status = RET_OK; - std::map weight_layers; - for (int i = 0; i < caffe_weight_.layer_size(); i++) { - auto weight_layer = caffe_weight_.layer(i); - weight_layers[weight_layer.name()] = weight_layer; - } - for (int i = 0; i < caffe_model_.layer_size(); i++) { - auto layer = caffe_model_.layer(i); - // eliminate _cpu mark - auto layer_name = layer.mutable_name(); - std::string suffix = "_cpu"; - auto pos = layer_name->rfind(suffix); - if (pos != std::string::npos && pos == layer_name->size() - suffix.length()) { - MS_LOG(WARNING) << "Don't support \"_cpu\" mark for now, this mark will be eliminated."; - (void)layer_name->replace(pos, suffix.length(), ""); - } - - // save caffe layers - for (int top_idx = 0; top_idx < layer.top_size(); top_idx++) { - caffe_layers_[layer.top(top_idx)] = layer; - } - caffe::LayerParameter weight; - if (weight_layers.find(layer.name()) != weight_layers.end()) { - weight = weight_layers.find(layer.name())->second; - } - - if (IsSkipedLayer(layer)) { - continue; - } - - // parse primitive - MS_LOG(INFO) << "parse op : " << layer.type(); - auto node_parser = CaffeNodeParserRegistry::GetInstance()->GetNodeParser(layer.type()); - if (node_parser == nullptr) { - MS_LOG(ERROR) << "not support op: " << layer.type(); - status = (status == RET_OK ? RET_NOT_FIND_OP : status); - continue; - } - - if (status != RET_OK) { - continue; - } - - auto base_operator_ptr = node_parser->Parse(layer, weight); - if (base_operator_ptr == nullptr) { - MS_LOG(ERROR) << "parse node " << layer.name() << " failed."; - status = RET_ERROR; - continue; - } - - if (layer.top_size() == 1) { - auto top_name = layer.top(0); - if (top_name.size() > lite::kTopNameMaxSize) { // mapper don't support node name length > 31 - top_name = top_name.substr(top_name.size() - lite::kTopNameMaxSize, lite::kTopNameMaxSize); - } - (void)base_operator_ptr->AddAttr(lite::kTopName, mindspore::api::MakeValue(top_name)); - } - - // build inputs - std::vector input_nodes; - status = ConvertBottom(layer, &input_nodes); - if (status != RET_OK) { - MS_LOG(ERROR) << "Convert layer bottom for " << layer.name() << " failed."; - continue; - } - - // build weights - std::vector const_parameters; - status = ConvertBlobs(weight, &const_parameters); - if (status != RET_OK) { - MS_LOG(ERROR) << "Convert blobs for " << layer.name() << " failed."; - continue; - } - - // build cnode - api::SharedPtr primitive(std::move(base_operator_ptr)); - std::vector op_inputs = {api::NewValueNode(primitive)}; - (void)op_inputs.insert(op_inputs.end(), input_nodes.begin(), input_nodes.end()); - (void)op_inputs.insert(op_inputs.end(), const_parameters.begin(), const_parameters.end()); - auto new_cnode = res_graph_->NewCNode(op_inputs); - new_cnode->set_fullname_with_scope(layer.name()); - - // convert outputs - status = ConvertTop(layer, new_cnode); - if (status != RET_OK) { - MS_LOG(ERROR) << "Convert outputs for " << layer.name() << " failed."; - continue; - } - } - return status; -} - -STATUS CaffeModelParser::InitOriginModel(const std::string &model_file, const std::string &weight_file) { - int status = ValidateFileStr(model_file, ".prototxt"); - if (status != RET_OK) { - MS_LOG(ERROR) << "INPUT ILLEGAL: modelFile must be *.prototxt"; - return RET_INPUT_PARAM_INVALID; - } - - if (weight_file.empty()) { - MS_LOG(ERROR) << "INPUT MISSING: weightFile is necessary"; - return RET_INPUT_PARAM_INVALID; - } - - status = ValidateFileStr(weight_file, ".caffemodel"); - if (status != RET_OK) { - MS_LOG(ERROR) << "INPUT ILLEGAL: weightFile must be *.caffemodel"; - return RET_INPUT_PARAM_INVALID; - } - - status = ReadProtoFromText(model_file, &caffe_model_); - if (status != RET_OK) { - MS_LOG(ERROR) << "Read prototxt file failed, model path: " << model_file; - return RET_ERROR; - } - - status = ReadProtoFromBinaryFile(weight_file, &caffe_weight_); - if (status != RET_OK) { - MS_LOG(ERROR) << "Read caffemodel file failed, model path: " << weight_file; - return RET_ERROR; - } - return RET_OK; -} - -STATUS CaffeModelParser::ConvertInputLayers() { - for (int i = 0; i < caffe_model_.layer_size(); i++) { - auto layer = caffe_model_.layer(i); - if (layer.type() == "Input") { - auto parameter = res_graph_->add_parameter(); - std::vector shape; - for (int j = 0; j < layer.input_param().shape(0).dim_size(); j++) { - shape.push_back(layer.input_param().shape(0).dim(j)); - } - auto abstract = dpico::CreateTensorAbstract(shape, kNumberTypeFloat32); - if (abstract == nullptr) { - MS_LOG(ERROR) << "Create tensor abstarct failed"; - return RET_ERROR; - } - parameter->set_abstract(abstract); - parameter->set_name(layer.name()); - (void)nodes_.emplace(std::pair(layer.top(0), parameter)); - } - } - return RET_OK; -} - -STATUS CaffeModelParser::ConvertGraphInputs() { - if (ConvertInputLayers() != RET_OK) { - MS_LOG(ERROR) << "Convert input layers failed."; - return RET_ERROR; - } - - if (caffe_model_.input_dim_size() > 0) { - for (int i = 0; i < caffe_model_.input_size(); i++) { - std::vector shape; - if (static_cast(caffe_model_.input_dim_size()) > dpico::kDims4) { - int step = caffe_model_.input_dim_size() / caffe_model_.input_size(); - for (int j = i * step; j < (i + 1) * step; j++) { - shape.push_back(caffe_model_.input_dim(j)); - } - } else { - for (int j = 0; j < caffe_model_.input_dim_size(); j++) { - shape.push_back(caffe_model_.input_dim(j)); - } - } - auto parameter = res_graph_->add_parameter(); - auto abstract = dpico::CreateTensorAbstract(shape, kNumberTypeFloat32); - if (abstract == nullptr) { - MS_LOG(ERROR) << "Create tensor abstarct failed"; - return RET_ERROR; - } - parameter->set_abstract(abstract); - parameter->set_name(caffe_model_.input(i)); - (void)nodes_.emplace(std::pair(caffe_model_.input(i), parameter)); - } - } else { - for (int i = 0; i < caffe_model_.input_shape_size(); i++) { - auto shape = caffe_model_.input_shape(i); - std::vector shape_vector; - for (int j = 0; j < shape.dim_size(); j++) { - shape_vector.push_back(shape.dim(j)); - } - auto parameter = res_graph_->add_parameter(); - auto tensor_info = dpico::CreateTensorInfo(nullptr, 0, shape_vector, kNumberTypeFloat32); - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "Create tensor info failed"; - return RET_ERROR; - } - auto abstract = tensor_info->ToAbstract(); - if (abstract == nullptr) { - MS_LOG(ERROR) << "Create tensor abstarct failed"; - return RET_ERROR; - } - parameter->set_abstract(abstract); - parameter->set_name(caffe_model_.input(i)); - (void)nodes_.emplace(std::pair(caffe_model_.input(i), parameter)); - } - } - return RET_OK; -} - -STATUS CaffeModelParser::ConvertGraphOutputs() { - CaffeInspector caffeInspector; - (void)caffeInspector.InspectModel(caffe_model_); - if (caffeInspector.GetGraphOutput().size() > 1) { - std::vector make_tuple_inputs; - auto make_tuple_prim_ptr = api::MakeShared(); - if (make_tuple_prim_ptr == nullptr) { - MS_LOG(ERROR) << "new MakeTuple failed"; - return RET_NULL_PTR; - } - auto make_tuple_prim = api::NewValueNode(make_tuple_prim_ptr); - (void)make_tuple_inputs.emplace_back(make_tuple_prim); - for (const auto &output_node : caffeInspector.GetGraphOutput()) { - if (nodes_.find(output_node) == nodes_.end()) { - MS_LOG(ERROR) << "Can't find input node."; - return RET_NOT_FIND_OP; - } - auto cnode = nodes_.find(output_node)->second; - (void)make_tuple_inputs.emplace_back(cnode); - } - auto make_tuple_cnode = res_graph_->NewCNode(make_tuple_inputs); - make_tuple_cnode->set_fullname_with_scope("return tuple"); - - std::vector op_inputs; - auto return_prim_ptr = api::MakeShared(); - if (return_prim_ptr == nullptr) { - MS_LOG(ERROR) << "new Return failed"; - return RET_NULL_PTR; - } - auto value_node = api::NewValueNode(return_prim_ptr); - (void)op_inputs.emplace_back(value_node); - (void)op_inputs.emplace_back(make_tuple_cnode); - auto cnode = res_graph_->NewCNode(op_inputs); - cnode->set_fullname_with_scope("Return"); - res_graph_->set_return(cnode); - } else { - auto return_prim = api::MakeShared(); - if (return_prim == nullptr) { - MS_LOG(ERROR) << "new Return failed"; - return RET_NULL_PTR; - } - auto valueNode = api::NewValueNode(return_prim); - std::vector opInputs{valueNode}; - std::string top_name = *caffeInspector.GetGraphOutput().begin(); - if (nodes_.find(top_name) == nodes_.end()) { - MS_LOG(ERROR) << "Can't find input node."; - return RET_NOT_FIND_OP; - } - auto cnode = nodes_.find(top_name)->second; - if (cnode == nullptr) { - MS_LOG(ERROR) << "Can't find input node."; - return RET_NOT_FIND_OP; - } - (void)opInputs.emplace_back(cnode); - auto returnCnode = res_graph_->NewCNode(opInputs); - returnCnode->set_fullname_with_scope("Return"); - res_graph_->set_return(returnCnode); - - const std::string top_name_suffix = "duplicate"; - const size_t max_loop = 1000; - for (size_t i = 0; i < max_loop; i++) { - std::string top_name_tmp = top_name + "_" + top_name_suffix + std::to_string(i); - if (nodes_.find(top_name_tmp) != nodes_.end()) { - auto cnode_tmp = nodes_[top_name_tmp]; - if (cnode_tmp == nullptr) { - MS_LOG(ERROR) << "Can't find input node."; - return RET_NOT_FIND_OP; - } - res_graph_->set_attr(top_name_tmp, api::MakeValue(cnode_tmp->fullname_with_scope())); - } else { - break; - } - } - } - // save original output tensor names. - converter::ConverterContext::SetGraphOutputTensorNames(caffeInspector.GetGraphOutput()); - return RET_OK; -} - -STATUS CaffeModelParser::ConvertBlobs(const caffe::LayerParameter &layer, - std::vector *const_parameters) { - if (const_parameters == nullptr) { - MS_LOG(ERROR) << "const parameters are null"; - return RET_NULL_PTR; - } - - // Layer must have Filter - if (layer.blobs_size() == 0) { - MS_LOG(INFO) << "No filter data in layer " << layer.name().c_str(); - return RET_OK; - } - for (int i = 0; i < layer.blobs_size(); i++) { - std::vector shape; - (void)ConvertShape(layer.blobs(i), &shape); - - FcSqueezeWeightBias(layer, i, &shape); - - // cal Weight num - auto parameter = res_graph_->add_parameter(); - std::vector shape_vector; - (void)std::transform(shape.begin(), shape.end(), std::back_inserter(shape_vector), - [](const int32_t &value) { return static_cast(value); }); - if (layer.type() == "Convolution" || layer.type() == "Deconvolution") { - if (i == 0) { - parameter->set_name(layer.name() + "/weight"); - } else if (i == 1) { - parameter->set_name(layer.name() + "/bias"); - } - } else { - parameter->set_name(layer.name() + "/input-" + std::to_string(i + layer.top_size())); - } - - int count = 0; - api::TensorPtr tensor_info = nullptr; - if (layer.blobs(i).double_data_size() > 0) { - count = layer.blobs(i).double_data_size(); - auto buf = std::make_unique(count); - if (buf == nullptr) { - MS_LOG(ERROR) << "buf is nullptr."; - return RET_NULL_PTR; - } - for (int j = 0; j < count; ++j) { - buf[j] = layer.blobs(j).double_data(j); - } - tensor_info = dpico::CreateTensorInfo(buf.get(), static_cast(count) * sizeof(float), shape_vector, - TypeId::kNumberTypeFloat32); - } else { - count = layer.blobs(i).data_size(); - const float *data_ptr = layer.blobs(i).data().data(); - if (data_ptr == nullptr) { - MS_LOG(INFO) << "data of origin layer is nullptr"; - return RET_NULL_PTR; - } - tensor_info = dpico::CreateTensorInfo(data_ptr, static_cast(count) * sizeof(float), shape_vector, - TypeId::kNumberTypeFloat32); - } - if (tensor_info == nullptr) { - MS_LOG(ERROR) << "create tensor info failed"; - return RET_NULL_PTR; - } - auto status = dpico::InitParameterFromTensorInfo(parameter, tensor_info); - if (status != RET_OK) { - MS_LOG(ERROR) << "init parameter from tensor info failed"; - return RET_ERROR; - } - (void)const_parameters->emplace_back(parameter); - } - return RET_OK; -} - -STATUS CaffeModelParser::ConvertBottom(const caffe::LayerParameter &layer, std::vector *input_nodes) { - if (input_nodes == nullptr) { - MS_LOG(ERROR) << "input_nodes is null"; - return RET_NULL_PTR; - } - for (int i = 0; i < layer.bottom_size(); i++) { - std::string origin_layer = GetOriginLayerName(layer.bottom(i)); - if (origin_layer.empty()) { - MS_LOG(ERROR) << "layer not found"; - return RET_ERROR; - } - - if (nodes_.find(origin_layer) == nodes_.end()) { - if (nodes_.find(origin_layer + "_report") == nodes_.end()) { - MS_LOG(ERROR) << "layer bottom " << layer.bottom(i) << " is not found"; - return RET_NOT_FIND_OP; - } else { - (void)input_nodes->emplace_back(nodes_.find(origin_layer + "_report")->second); - } - } else { - (void)input_nodes->emplace_back(nodes_.find(origin_layer)->second); - } - } - return RET_OK; -} - -STATUS CaffeModelParser::ConvertTop(const caffe::LayerParameter &layer, const api::CNodePtr &cnode) { - if (layer.top_size() == 1) { - const std::string top_name_suffix = "duplicate"; - const size_t max_loop = 1000; - std::string top_name = layer.top(0); - if (nodes_.find(top_name) != nodes_.end()) { - std::string top_name_new = ""; - for (size_t i = 0; i < max_loop; i++) { - std::string top_name_tmp = top_name + "_" + top_name_suffix + std::to_string(i); - if (nodes_.find(top_name_tmp) == nodes_.end()) { - top_name_new = top_name_tmp; - break; - } - } - if (top_name_new.empty()) { - MS_LOG(ERROR) << "Create new top name failed"; - return RET_ERROR; - } - nodes_[top_name_new] = nodes_[top_name]; - } - auto abstract = dpico::CreateTensorAbstract({}, kNumberTypeFloat32); - if (abstract == nullptr) { - MS_LOG(ERROR) << "Create tensor abstarct failed"; - return RET_ERROR; - } - cnode->set_abstract(abstract); - nodes_[layer.top(0)] = cnode; - return RET_OK; - } - - api::AbstractBasePtrList abstract_list; - for (int i = 0; i < layer.top_size(); i++) { - auto abstract = dpico::CreateTensorAbstract({}, kNumberTypeFloat32); - if (abstract == nullptr) { - MS_LOG(ERROR) << "Create tensor abstarct failed"; - return RET_ERROR; - } - (void)abstract_list.emplace_back(abstract); - auto tuple_get_item_prim_ptr = api::MakeShared(); - if (tuple_get_item_prim_ptr == nullptr) { - MS_LOG(ERROR) << "new TupleGetItem failed"; - return RET_NULL_PTR; - } - auto tuple_get_item_prim = api::NewValueNode(tuple_get_item_prim_ptr); - auto get_item_value = api::NewValueNode(api::MakeValue(static_cast(i))); - std::vector inputs{tuple_get_item_prim, cnode, get_item_value}; - api::CNodePtr get_item_cnode = res_graph_->NewCNode(inputs); - get_item_cnode->set_fullname_with_scope(layer.top(i)); - auto top_name = layer.top(i); - if (top_name.size() > lite::kTopNameMaxSize) { - top_name = top_name.substr(top_name.size() - lite::kTopNameMaxSize, lite::kTopNameMaxSize); - } - (void)tuple_get_item_prim_ptr->AddAttr(lite::kTopName, api::MakeValue(top_name)); - nodes_[layer.top(i)] = get_item_cnode; - } - auto abstract_tuple = api::MakeShared(abstract_list); - if (abstract_tuple == nullptr) { - MS_LOG(ERROR) << "abstract_tuple is nullptr."; - return RET_ERROR; - } - cnode->set_abstract(abstract_tuple); - return RET_OK; -} - -std::string CaffeModelParser::GetOriginLayerName(const std::string &layer_name) { - if (caffe_layers_.find(layer_name) == caffe_layers_.end()) { - return layer_name; - } - auto layer = caffe_layers_.at(layer_name); - if (layer.type() != "Split") { - return layer_name; - } - while (layer.type() == "Split") { - std::string input_name = layer.bottom(0); - if (caffe_layers_.find(input_name) == caffe_layers_.end()) { - return input_name; - } - layer = caffe_layers_.at(input_name); - } - return layer.name(); -} - -converter::ModelParser *CaffeModelParserCreator() { - auto *parser = new (std::nothrow) CaffeModelParser(); - if (parser == nullptr) { - MS_LOG(ERROR) << "caffe model parser failed"; - return nullptr; - } - return parser; -} -REG_MODEL_PARSER(kFmkTypeCaffe, CaffeModelParserCreator) -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.h deleted file mode 100644 index 1e2b87f6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_model_parser.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright 2020 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MODEL_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MODEL_PARSER_H_ - -#include -#include -#include -#include -#include -#include "include/registry/model_parser.h" -#include "include/registry/model_parser_registry.h" -#include "./pico_caffe.pb.h" - -using STATUS = int; -namespace mindspore::lite { -constexpr auto kTopName = "top_name"; -constexpr size_t kTopNameMaxSize = 31; -class CaffeModelParser : public converter::ModelParser { - public: - CaffeModelParser(); - - ~CaffeModelParser() override; - - api::FuncGraphPtr Parse(const converter::ConverterParameters &flag) override; - - private: - STATUS InitOriginModel(const std::string &model_file, const std::string &weight_file); - - STATUS ConvertInputLayers(); - - STATUS ConvertGraphInputs(); - - STATUS ConvertGraphOutputs(); - - STATUS ConvertLayers(); - - STATUS ConvertBlobs(const caffe::LayerParameter &layer, std::vector *const_parameters); - - STATUS ConvertBottom(const caffe::LayerParameter &layer, std::vector *input_nodes); - - STATUS ConvertTop(const caffe::LayerParameter &layer, const api::CNodePtr &cnode); - - std::string GetOriginLayerName(const std::string &layer_name); - - caffe::NetParameter caffe_model_; - caffe::NetParameter caffe_weight_; - std::unordered_map caffe_layers_; - std::unordered_map nodes_; -}; -} // namespace mindspore::lite - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MODEL_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.cc deleted file mode 100644 index 01be7f03..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.cc +++ /dev/null @@ -1,52 +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 "parser/caffe/caffe_mvn_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeMvnParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Mvn"); - - if (proto.has_mvn_param()) { - const caffe::MVNParameter &mvn_parameter = proto.mvn_param(); - if (mvn_parameter.has_eps()) { - (void)prim->AddAttr(ops::kEps, api::MakeValue(mvn_parameter.eps())); - } - if (mvn_parameter.has_across_channels()) { - (void)prim->AddAttr(dpico::kAcrossChannels, api::MakeValue(mvn_parameter.across_channels())); - } - if (mvn_parameter.has_normalize_variance()) { - (void)prim->AddAttr(dpico::kNormalizeVariance, api::MakeValue(mvn_parameter.normalize_variance())); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeMvnParser("MVN", new CaffeMvnParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.h deleted file mode 100644 index cae0cf62..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_mvn_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MVN_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MVN_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeMvnParser : public CaffeNodeParser { - public: - CaffeMvnParser() : CaffeNodeParser("Mvn") {} - ~CaffeMvnParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_MVN_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.cc deleted file mode 100644 index e6cf0099..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.cc +++ /dev/null @@ -1,42 +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 "parser/caffe/caffe_node_parser.h" -#include - -namespace mindspore { -namespace lite { -STATUS ConvertShape(const caffe::BlobProto &proto, std::vector *shape) { - if (shape == nullptr) { - MS_LOG(ERROR) << "shape is null"; - return RET_ERROR; - } - - shape->clear(); - if (proto.has_num() || proto.has_channels() || proto.has_height() || proto.has_width()) { - shape->push_back(proto.num()); - shape->push_back(proto.channels()); - shape->push_back(proto.height()); - shape->push_back(proto.width()); - } else { - for (int i = 0; i < proto.shape().dim_size(); ++i) { - shape->push_back(proto.shape().dim(i)); - } - } - return RET_OK; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.h deleted file mode 100644 index f89c2c5e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser.h +++ /dev/null @@ -1,55 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NODE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NODE_PARSER_H_ - -#include -#include -#include -#include -#include -#include "google/protobuf/message.h" -#include "./pico_caffe.pb.h" -#include "common/anf_util.h" -#include "ops/base_operator.h" - -using mindspore::lite::STATUS; - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -constexpr int kNums2 = 2; -constexpr int kNums4 = 4; -class CaffeNodeParser { - public: - explicit CaffeNodeParser(std::string nodeName) : name(std::move(nodeName)) {} - - virtual ~CaffeNodeParser() = default; - - virtual BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - return nullptr; - } - - protected: - const std::string name; -}; - -STATUS ConvertShape(const caffe::BlobProto &proto, std::vector *shape); -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NODE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.cc deleted file mode 100644 index 4fc31901..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.cc +++ /dev/null @@ -1,45 +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 "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -CaffeNodeParserRegistry::CaffeNodeParserRegistry() = default; - -CaffeNodeParserRegistry::~CaffeNodeParserRegistry() { - for (auto ite : parsers) { - if (ite.second != nullptr) { - delete ite.second; - ite.second = nullptr; - } - } -} - -CaffeNodeParserRegistry *CaffeNodeParserRegistry::GetInstance() { - static CaffeNodeParserRegistry instance; - return &instance; -} - -CaffeNodeParser *CaffeNodeParserRegistry::GetNodeParser(const std::string &name) { - auto it = parsers.find(name); - if (it != parsers.end()) { - return it->second; - } - return nullptr; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.h deleted file mode 100644 index 6ce5fb8a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_node_parser_registry.h +++ /dev/null @@ -1,47 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NODE_PARSER_REGISTRY_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NODE_PARSER_REGISTRY_H_ - -#include -#include -#include "parser/caffe/caffe_node_parser.h" - -namespace mindspore::lite { -class CaffeNodeParserRegistry { - public: - CaffeNodeParserRegistry(); - - virtual ~CaffeNodeParserRegistry(); - - static CaffeNodeParserRegistry *GetInstance(); - - CaffeNodeParser *GetNodeParser(const std::string &name); - - std::unordered_map parsers; -}; - -class CaffeNodeRegistrar { - public: - CaffeNodeRegistrar(const std::string &name, CaffeNodeParser *parser) { - CaffeNodeParserRegistry::GetInstance()->parsers[name] = parser; - } - ~CaffeNodeRegistrar() = default; -}; -} // namespace mindspore::lite - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NODE_PARSER_REGISTRY_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.cc deleted file mode 100644 index 47f3f985..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.cc +++ /dev/null @@ -1,38 +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 "parser/caffe/caffe_nop_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeNopParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Nop"); - - return prim; -} - -CaffeNodeRegistrar g_caffeNopParser("Nop", new CaffeNopParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.h deleted file mode 100644 index 6d55c045..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_nop_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NOP_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NOP_PARSER_H_ - -#include "parser/caffe/caffe_node_parser.h" -#include -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeNopParser : public CaffeNodeParser { - public: - CaffeNopParser() : CaffeNodeParser("Nop") {} - ~CaffeNopParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NOP_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.cc deleted file mode 100644 index 463ff3fa..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.cc +++ /dev/null @@ -1,55 +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 "parser/caffe/caffe_normalize_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeNormalizeParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Normalize"); - - if (proto.has_norm_param()) { - const caffe::NormalizeParameter &normalize_param = proto.norm_param(); - if (normalize_param.has_across_spatial()) { - (void)prim->AddAttr(dpico::kAcrossSpatial, api::MakeValue(normalize_param.across_spatial())); - } - if (normalize_param.has_channel_shared()) { - (void)prim->AddAttr(dpico::kChannelShared, api::MakeValue(normalize_param.channel_shared())); - } - if (normalize_param.has_sqrt_a()) { - (void)prim->AddAttr(dpico::kSqrtA, api::MakeValue(normalize_param.sqrt_a())); - } - if (normalize_param.has_eps()) { - (void)prim->AddAttr(ops::kEps, api::MakeValue(normalize_param.eps())); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeNormalizeParser("Normalize", new CaffeNormalizeParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.h deleted file mode 100644 index ea80c7f2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_normalize_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NORMALIZE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NORMALIZE_PARSER_H_ - -#include "parser/caffe/caffe_node_parser.h" -#include -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeNormalizeParser : public CaffeNodeParser { - public: - CaffeNormalizeParser() : CaffeNodeParser("Normalize") {} - ~CaffeNormalizeParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_NORMALIZE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.cc deleted file mode 100644 index 785508c6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.cc +++ /dev/null @@ -1,82 +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 "parser/caffe/caffe_pass_through_parser.h" -#include -#include -#include -#include "infer/custom.h" -#include "common/op_attr.h" -#include "include/securec.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffePassThroughParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("PassThrough"); - - std::map> custom_attrs; - if (proto.has_pass_through_param()) { - const auto &pass_through_param = proto.pass_through_param(); - if (pass_through_param.has_num_output()) { - uint32_t num_output = pass_through_param.num_output(); - (void)prim->AddAttr(dpico::kNumOutput, api::MakeValue(num_output)); // for mapper - - std::vector num_output_attr(sizeof(uint32_t)); - if (memcpy_s(num_output_attr.data(), num_output_attr.size() * sizeof(uint8_t), &num_output, sizeof(uint32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kNumOutput] = num_output_attr; - } - if (pass_through_param.has_block_height()) { - uint32_t block_height = pass_through_param.block_height(); - (void)prim->AddAttr(dpico::kBlockHeight, api::MakeValue(block_height)); - - std::vector block_height_attr(sizeof(uint32_t)); - if (memcpy_s(block_height_attr.data(), block_height_attr.size() * sizeof(uint8_t), &block_height, - sizeof(uint32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kBlockHeight] = block_height_attr; - } - if (pass_through_param.has_block_width()) { - uint32_t block_width = pass_through_param.block_width(); - (void)prim->AddAttr(dpico::kBlockWidth, api::MakeValue(block_width)); - - std::vector block_width_attr(sizeof(uint32_t)); - if (memcpy_s(block_width_attr.data(), block_width_attr.size() * sizeof(uint8_t), &block_width, - sizeof(uint32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kBlockWidth] = block_width_attr; - } - } - - prim->set_attr(custom_attrs); - return prim; -} - -CaffeNodeRegistrar g_caffePassThroughParser("PassThrough", new CaffePassThroughParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.h deleted file mode 100644 index 684d7ccd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pass_through_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PASS_THROUGH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PASS_THROUGH_PARSER_H_ - -#include "parser/caffe/caffe_node_parser.h" -#include -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffePassThroughParser : public CaffeNodeParser { - public: - CaffePassThroughParser() : CaffeNodeParser("PassThrough") {} - ~CaffePassThroughParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PASS_THROUGH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.cc deleted file mode 100644 index ffef962b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.cc +++ /dev/null @@ -1,44 +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 "parser/caffe/caffe_permute_parser.h" -#include -#include "common/op_attr.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffePermuteParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - std::vector perm; - const caffe::PermuteParameter &permuteParam = proto.permute_param(); - const int num_order_dims = permuteParam.order_size(); - perm.resize(num_order_dims); - for (int i = 0; i < num_order_dims; ++i) { - perm[i] = permuteParam.order()[i]; - } - (void)prim->AddAttr(dpico::kPerm, api::MakeValue(perm)); - - return prim; -} - -CaffeNodeRegistrar g_caffePermuteParser("Permute", new CaffePermuteParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.h deleted file mode 100644 index c5d10ba3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_permute_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PERMUTE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PERMUTE_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffePermuteParser : public CaffeNodeParser { - public: - CaffePermuteParser() : CaffeNodeParser("Permute") {} - ~CaffePermuteParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PERMUTE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.cc deleted file mode 100644 index dbcd4eb7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.cc +++ /dev/null @@ -1,175 +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 "parser/caffe/caffe_pooling_parser.h" -#include -#include "infer/cxx_api/avg_pool_fusion.h" -#include "infer/cxx_api/max_pool_fusion.h" -#include "common/op_enum.h" - -namespace mindspore { -namespace lite { -STATUS CaffePoolingParser::ParsePads(const caffe::PoolingParameter &poolingParam, std::vector *pad) { - if (pad == nullptr) { - MS_LOG(ERROR) << "pad is nullptr."; - return RET_ERROR; - } - if (poolingParam.has_pad_h() && poolingParam.has_pad_w()) { - if (poolingParam.has_pad()) { - MS_LOG(ERROR) << "Either pad or pad_h/w should be specified; not both"; - return RET_ERROR; - } - (*pad)[0] = poolingParam.pad_h(); - (*pad)[1] = poolingParam.pad_h(); - (*pad)[dpico::kInputIndex2] = poolingParam.pad_w(); - (*pad)[dpico::kInputIndex3] = poolingParam.pad_w(); - } else { - (*pad)[0] = poolingParam.pad(); - (*pad)[1] = poolingParam.pad(); - (*pad)[dpico::kInputIndex2] = poolingParam.pad(); - (*pad)[dpico::kInputIndex3] = poolingParam.pad(); - } - return RET_OK; -} - -STATUS CaffePoolingParser::ParseStrides(const caffe::PoolingParameter &poolingParam, std::vector *strides) { - if (strides == nullptr) { - MS_LOG(ERROR) << "strides is nullptr."; - return RET_ERROR; - } - if (poolingParam.has_stride_h() && poolingParam.has_stride_w()) { - if (poolingParam.has_stride()) { - MS_LOG(ERROR) << "Either stride or stride_h/w should be specified; not both"; - return RET_ERROR; - } - (*strides)[0] = poolingParam.stride_h(); - (*strides)[1] = poolingParam.stride_w(); - } else { - (*strides)[0] = poolingParam.stride(); - (*strides)[1] = poolingParam.stride(); - } - return RET_OK; -} - -STATUS CaffePoolingParser::ParseWindows(const caffe::PoolingParameter &poolingParam, std::vector *windows) { - if (windows == nullptr) { - MS_LOG(ERROR) << "windows is nullptr."; - return RET_ERROR; - } - if (poolingParam.has_global_pooling() && poolingParam.global_pooling()) { - if (poolingParam.has_kernel_size() || poolingParam.has_kernel_h() || poolingParam.has_kernel_w()) { - MS_LOG(ERROR) << "With Global_pooling: true Filter size cannot specified"; - return RET_ERROR; - } - (*windows)[0] = 0; - (*windows)[1] = 0; - } else { - if (poolingParam.has_kernel_size() == (poolingParam.has_kernel_h() || poolingParam.has_kernel_w())) { - MS_LOG(ERROR) << "Filter size is kernel_size OR kernel_h and kernel_w; not both"; - return RET_ERROR; - } - if (!poolingParam.has_kernel_size() && !(poolingParam.has_kernel_h() && poolingParam.has_kernel_w())) { - MS_LOG(ERROR) << "For non-square filters both kernel_h and kernel_w are required."; - return RET_ERROR; - } - - if (poolingParam.has_kernel_h() && poolingParam.has_kernel_w()) { - (*windows)[0] = poolingParam.kernel_h(); - (*windows)[1] = poolingParam.kernel_w(); - } else { - (*windows)[0] = poolingParam.kernel_size(); - (*windows)[1] = poolingParam.kernel_size(); - } - } - return RET_OK; -} - -mindspore::RoundMode CaffePoolingParser::ParseRoundMode(const caffe::PoolingParameter &poolingParam) { - mindspore::RoundMode roundMode = mindspore::RoundMode::CEIL; - if (poolingParam.has_round_mode()) { - if (poolingParam.round_mode() == caffe::PoolingParameter_RoundMode_FLOOR) { - roundMode = mindspore::RoundMode::FLOOR; - } else if (poolingParam.round_mode() == caffe::PoolingParameter_RoundMode_CEIL) { - roundMode = mindspore::RoundMode::CEIL; - } - } - return roundMode; -} - -BaseOperatorPtr CaffePoolingParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - const caffe::PoolingParameter &poolingParam = proto.pooling_param(); - - // parse kernel params - std::vector windows(kNums2, 0); - if (ParseWindows(poolingParam, &windows) != RET_OK) { - MS_LOG(ERROR) << "ParseWindows for " << proto.name().c_str() << " failed"; - return nullptr; - } - - // parse strides params - std::vector strides(kNums2, 0); - if (ParseStrides(poolingParam, &strides) != RET_OK) { - MS_LOG(ERROR) << "ParseStrides for " << proto.name().c_str() << " failed"; - return nullptr; - } - - // parse pad params - std::vector pad(kNums4, 0); - if (ParsePads(poolingParam, &pad) != RET_OK) { - MS_LOG(ERROR) << "ParsePads for " << proto.name().c_str() << " failed"; - return nullptr; - } - - // parse round mode - auto roundMode = ParseRoundMode(poolingParam); - - if (poolingParam.pool() == caffe::PoolingParameter::MAX) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_format(mindspore::Format::NCHW); - prim->set_pad_mode(mindspore::PadMode::PAD); - prim->set_kernel_size(windows); - prim->set_strides(strides); - prim->set_pad(pad); - prim->set_round_mode(roundMode); - prim->set_global(poolingParam.global_pooling()); - return prim; - } else if (poolingParam.pool() == caffe::PoolingParameter::AVE) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_data_format(mindspore::Format::NCHW); - prim->set_pad_mode(mindspore::PadMode::PAD); - prim->set_kernel_size(windows); - prim->set_strides(strides); - prim->set_pad(pad); - prim->set_round_mode(roundMode); - prim->set_global(poolingParam.global_pooling()); - return prim; - } else { - MS_LOG(ERROR) << "poolingParam.pool() is not MAX or AVE"; - return nullptr; - } -} - -CaffeNodeRegistrar g_caffePoolingParser("Pooling", new CaffePoolingParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.h deleted file mode 100644 index f2e9b3fc..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_pooling_parser.h +++ /dev/null @@ -1,45 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_POOLING_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_POOLING_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" -#include "mindapi/base/types.h" - -namespace mindspore { -namespace lite { -class CaffePoolingParser : public CaffeNodeParser { - public: - CaffePoolingParser() : CaffeNodeParser("pooling") {} - ~CaffePoolingParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; - - static STATUS ParsePads(const caffe::PoolingParameter &poolingParam, std::vector *pad); - - static STATUS ParseStrides(const caffe::PoolingParameter &poolingParam, std::vector *strides); - - static STATUS ParseWindows(const caffe::PoolingParameter &poolingParam, std::vector *windows); - - mindspore::RoundMode ParseRoundMode(const caffe::PoolingParameter &poolingParam); -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_POOLING_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.cc deleted file mode 100644 index a63c4a17..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.cc +++ /dev/null @@ -1,55 +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 "parser/caffe/caffe_power_parser.h" -#include -#include -#include "infer/cxx_api/pow_fusion.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffePowerParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::PowerParameter &powerParam = proto.power_param(); - float power = 1.0; - float scale = 1.0; - float shift = 0.0; - if (proto.has_power_param()) { - if (powerParam.has_power()) { - power = powerParam.power(); - } - if (powerParam.has_scale()) { - scale = powerParam.scale(); - } - if (powerParam.has_shift()) { - shift = powerParam.shift(); - } - } - (void)prim->AddAttr(ops::kPower, api::MakeValue(power)); - prim->set_scale(scale); - prim->set_shift(shift); - - return prim; -} - -CaffeNodeRegistrar g_caffePowerParser("Power", new CaffePowerParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.h deleted file mode 100644 index b3680e81..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_power_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_POWER_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_POWER_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffePowerParser : public CaffeNodeParser { - public: - CaffePowerParser() : CaffeNodeParser("power") {} - ~CaffePowerParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_POWER_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.cc deleted file mode 100644 index 4b2b07d7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.cc +++ /dev/null @@ -1,41 +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 "parser/caffe/caffe_prelu_parser.h" -#include -#include "infer/cxx_api/prelu_fusion.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffePReluParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::PReLUParameter &prelu_param = proto.prelu_param(); - if (prelu_param.has_channel_shared()) { - prim->set_channel_shared(prelu_param.channel_shared()); - } else { - prim->set_channel_shared(false); - } - - return prim; -} - -CaffeNodeRegistrar g_caffePReluParser("PReLU", new CaffePReluParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.h deleted file mode 100644 index ccd46985..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_prelu_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PRELU_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PRELU_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffePReluParser : public CaffeNodeParser { - public: - CaffePReluParser() : CaffeNodeParser("pRelu") {} - ~CaffePReluParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PRELU_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.cc deleted file mode 100644 index ecf6f710..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.cc +++ /dev/null @@ -1,83 +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 "parser/caffe/caffe_psroi_pooling_parser.h" -#include -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "include/securec.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffePSROIPoolingParser::Parse(const caffe::LayerParameter &proto, - const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("PsRoiPool"); - - std::map> custom_attrs; - if (proto.has_psroi_pooling_param()) { - const auto &psroi_pooling_param = proto.psroi_pooling_param(); - if (psroi_pooling_param.has_spatial_scale()) { - float spatial_scale = psroi_pooling_param.spatial_scale(); - (void)prim->AddAttr(dpico::kSpatialScale, api::MakeValue(spatial_scale)); - - std::vector spatial_scale_attr(sizeof(float)); - if (memcpy_s(spatial_scale_attr.data(), spatial_scale_attr.size() * sizeof(uint8_t), &spatial_scale, - sizeof(float)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kSpatialScale] = spatial_scale_attr; - } - if (psroi_pooling_param.has_group_size()) { - int32_t group_size = psroi_pooling_param.group_size(); - (void)prim->AddAttr(dpico::kGroupSize, api::MakeValue(group_size)); - - std::vector group_size_attr(sizeof(int32_t)); - if (memcpy_s(group_size_attr.data(), group_size_attr.size() * sizeof(uint8_t), &group_size, sizeof(int32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kGroupSize] = group_size_attr; - } - if (psroi_pooling_param.has_output_dim()) { - int32_t output_dim = psroi_pooling_param.output_dim(); - (void)prim->AddAttr(dpico::kOutputDim, api::MakeValue(output_dim)); - - std::vector output_dim_attr(sizeof(int32_t)); - if (memcpy_s(output_dim_attr.data(), output_dim_attr.size() * sizeof(uint8_t), &output_dim, sizeof(int32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kOutputDim] = output_dim_attr; - } - } - - prim->set_attr(custom_attrs); - return prim; -} - -CaffeNodeRegistrar g_caffePSROIPoolingParser("PSROIPooling", new CaffePSROIPoolingParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.h deleted file mode 100644 index a8939a2c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_psroi_pooling_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PSROI_POOLING_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PSROI_POOLING_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffePSROIPoolingParser : public CaffeNodeParser { - public: - CaffePSROIPoolingParser() : CaffeNodeParser("PSROIPooling") {} - ~CaffePSROIPoolingParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_PSROI_POOLING_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.cc deleted file mode 100644 index 21da129f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.cc +++ /dev/null @@ -1,71 +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 "parser/caffe/caffe_reduce_parser.h" -#include -#include -#include "include/registry/converter_context.h" -#include "infer/cxx_api/reduce_fusion.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeReduceParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_keep_dims(false); - prim->set_reduce_to_end(true); - - const caffe::ReductionParameter &reduce_param = proto.reduction_param(); - if (reduce_param.has_operation()) { - if (reduce_param.operation() == caffe::ReductionParameter_ReductionOp_MEAN) { - prim->set_mode(mindspore::ReduceMode::Reduce_Mean); - } else if (reduce_param.operation() == caffe::ReductionParameter_ReductionOp_SUM) { - prim->set_mode(mindspore::ReduceMode::Reduce_Sum); - } else if (reduce_param.operation() == caffe::ReductionParameter_ReductionOp_SUMSQ) { - prim->set_mode(mindspore::ReduceMode::Reduce_Sum_Square); - } else if (reduce_param.operation() == caffe::ReductionParameter_ReductionOp_ASUM) { - prim->set_mode(mindspore::ReduceMode::Reduce_ASum); - } else { - MS_LOG(ERROR) << "unsupported reduce mode: " << reduce_param.operation(); - return nullptr; - } - } else { - prim->set_mode(mindspore::ReduceMode::Reduce_Sum); - } - - std::vector axes; - if (reduce_param.has_axis()) { - axes = std::vector(1, reduce_param.axis()); - } else { - axes = std::vector(1, 0); - } - (void)prim->AddAttr(ops::kAxes, api::MakeValue(axes)); - - if (reduce_param.has_coeff()) { - (void)prim->AddAttr(ops::kCoeff, api::MakeValue(reduce_param.coeff())); - } - int fmk_type = static_cast(converter::FmkType::kFmkTypeCaffe); - (void)prim->AddAttr(ops::kFmkType, api::MakeValue(static_cast(fmk_type))); - return prim; -} - -CaffeNodeRegistrar g_caffeReduceParser("Reduction", new CaffeReduceParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.h deleted file mode 100644 index 315bf479..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reduce_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_REDUCE_PARSER_H -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_REDUCE_PARSER_H - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeReduceParser : public CaffeNodeParser { - public: - CaffeReduceParser() : CaffeNodeParser("reduce") {} - ~CaffeReduceParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_REDUCE_PARSER_H diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.cc deleted file mode 100644 index 77c529c5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.cc +++ /dev/null @@ -1,56 +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 "parser/caffe/caffe_reshape_parser.h" -#include -#include "common/op_attr.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeReshapeParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::ReshapeParameter &reshapeParam = proto.reshape_param(); - if (!reshapeParam.has_shape()) { - MS_LOG(ERROR) << "Reshape has no shape info, ret fail"; - return nullptr; - } - std::vector shape; - const caffe::BlobShape &blob_shape = reshapeParam.shape(); - for (int i = 0; i < blob_shape.dim_size(); i++) { - shape.push_back(blob_shape.dim(i)); - } - (void)prim->AddAttr(ops::kShape, api::MakeValue(shape)); - - if (reshapeParam.has_axis()) { - (void)prim->AddAttr(ops::kAxis, api::MakeValue(reshapeParam.axis())); - } - - if (reshapeParam.has_num_axes()) { - (void)prim->AddAttr(dpico::kNumAxes, api::MakeValue(reshapeParam.num_axes())); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeReshapeParser("Reshape", new CaffeReshapeParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.h deleted file mode 100644 index 171c4b98..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reshape_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_RESHAPE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_RESHAPE_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeReshapeParser : public CaffeNodeParser { - public: - CaffeReshapeParser() : CaffeNodeParser("reshape") {} - ~CaffeReshapeParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_RESHAPE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.cc deleted file mode 100644 index 0c14fc2a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.cc +++ /dev/null @@ -1,41 +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 "parser/caffe/caffe_reverse_parser.h" -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeReverseParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - - if (proto.has_reverse_param() && proto.reverse_param().has_axis()) { - prim->set_axis({proto.reverse_param().axis()}); - } else { - prim->set_axis({0}); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeReverseParser("Reverse", new CaffeReverseParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.h deleted file mode 100644 index e0b5262f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_reverse_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_REVERSE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_REVERSE_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeReverseParser : public CaffeNodeParser { - public: - CaffeReverseParser() : CaffeNodeParser("reverse") {} - ~CaffeReverseParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_REVERSE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.cc deleted file mode 100644 index be03fe35..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.cc +++ /dev/null @@ -1,56 +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 "parser/caffe/caffe_rnn_parser.h" -#include -#include -#include -#include "infer/custom.h" -#include "common/op_attr.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeRnnParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Rnn"); - - if (proto.has_recurrent_param()) { - const auto &rnn_param = proto.recurrent_param(); - if (rnn_param.has_num_output()) { - (void)prim->AddAttr(dpico::kNumOutput, api::MakeValue(rnn_param.num_output())); - } - if (rnn_param.has_expose_hidden()) { - (void)prim->AddAttr(dpico::kExposeHidden, api::MakeValue(rnn_param.expose_hidden())); - (void)prim->AddAttr(dpico::kOutputLastFrameFlag, api::MakeValue(rnn_param.expose_hidden())); - (void)prim->AddAttr(dpico::kInitialHOnlineFlag, api::MakeValue(rnn_param.expose_hidden())); - (void)prim->AddAttr(dpico::kUseDefaultInitialHFlag, api::MakeValue(!rnn_param.expose_hidden())); - } - } - - // set default value - (void)prim->AddAttr(dpico::kKeepDirectionDimFlag, api::MakeValue(false)); - (void)prim->AddAttr(dpico::kHasOutputGateFlag, api::MakeValue(true)); - - return prim; -} - -CaffeNodeRegistrar g_caffeRnnParser("RNN", new CaffeRnnParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.h deleted file mode 100644 index 9d5c40da..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_rnn_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_RNN_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_RNN_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeRnnParser : public CaffeNodeParser { - public: - CaffeRnnParser() : CaffeNodeParser("Rnn") {} - ~CaffeRnnParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_RNN_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.cc deleted file mode 100644 index dd987f74..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.cc +++ /dev/null @@ -1,47 +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 "parser/caffe/caffe_roi_pooling_parser.h" -#include -#include "infer/roi_pooling.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeROIPoolingParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - if (proto.has_roi_pooling_param()) { - const auto &roi_pooling_param = proto.roi_pooling_param(); - if (roi_pooling_param.has_pooled_h()) { - prim->set_pooled_h(roi_pooling_param.pooled_h()); - } - if (roi_pooling_param.has_pooled_w()) { - prim->set_pooled_w(roi_pooling_param.pooled_w()); - } - if (roi_pooling_param.has_spatial_scale()) { - prim->set_scale(roi_pooling_param.spatial_scale()); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeROIPoolingParser("ROIPooling", new CaffeROIPoolingParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.h deleted file mode 100644 index 61f72a34..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_roi_pooling_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ROI_POOLING_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ROI_POOLING_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeROIPoolingParser : public CaffeNodeParser { - public: - CaffeROIPoolingParser() : CaffeNodeParser("ROIPooling") {} - ~CaffeROIPoolingParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_ROI_POOLING_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.cc deleted file mode 100644 index cc4c4e84..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.cc +++ /dev/null @@ -1,78 +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 "parser/caffe/caffe_scale_parser.h" -#include -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "infer/cxx_api/scale_fusion.h" - -namespace mindspore { -namespace lite { -STATUS CaffeScaleParser::GetAxisIndex(const int32_t &axis, uint32_t *axis_index) { - if (axis < dpico::kAxisLowerBound || axis > dpico::kAxisUpperBound) { - MS_LOG(ERROR) << "Scale axis value(" << axis << ") is not correct"; - return RET_ERROR; - } - - if (axis == -1) { - MS_LOG(WARNING) << "axis with -1 may lead to calculation errors when input less than 4 dims."; - } - - if (axis_index == nullptr) { - MS_LOG(ERROR) << "axis_index is nullptr."; - return RET_ERROR; - } - *axis_index = (static_cast(axis) + dpico::kDims4) % dpico::kDims4; - return RET_OK; -} - -BaseOperatorPtr CaffeScaleParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - if (weight.blobs_size() + weight.bottom_size() < kNums2) { - MS_LOG(ERROR) << "Scale bottom size:" << weight.bottom_size() << ", blobs size:" << weight.blobs_size() - << " invalid in layer " << weight.name().c_str(); - return nullptr; - } - - const caffe::ScaleParameter &scaleParam = weight.scale_param(); - prim->set_axis(1); - if (scaleParam.has_axis()) { - uint32_t axis_index = 1; - if (GetAxisIndex(scaleParam.axis(), &axis_index)) { - MS_LOG(ERROR) << "scale get axis failed for layer " << weight.name().c_str(); - return nullptr; - } - prim->set_axis(axis_index); - } - - if (scaleParam.has_bias_term()) { - (void)prim->AddAttr(dpico::kBiasTerm, api::MakeValue(scaleParam.bias_term())); - } - - if (scaleParam.has_num_axes()) { - (void)prim->AddAttr(dpico::kNumAxes, api::MakeValue(scaleParam.num_axes())); - } - return prim; -} - -CaffeNodeRegistrar g_caffeScaleParser("Scale", new CaffeScaleParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.h deleted file mode 100644 index 489c8143..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_scale_parser.h +++ /dev/null @@ -1,39 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SCALE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SCALE_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeScaleParser : public CaffeNodeParser { - public: - CaffeScaleParser() : CaffeNodeParser("scale") {} - ~CaffeScaleParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; - - private: - STATUS GetAxisIndex(const int32_t &axis, uint32_t *axis_index); -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SCALE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.cc deleted file mode 100644 index 76b9f608..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.cc +++ /dev/null @@ -1,46 +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 "parser/caffe/caffe_shuffle_channel_parser.h" -#include -#include -#include "infer/custom.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeShuffleChannelParser::Parse(const caffe::LayerParameter &proto, - const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("ShuffleChannel"); - - if (proto.has_shuffle_channel_param()) { - const caffe::ShuffleChannelParameter &shuffle_channel_parameter = proto.shuffle_channel_param(); - if (shuffle_channel_parameter.has_group()) { - (void)prim->AddAttr(ops::kGroup, api::MakeValue(shuffle_channel_parameter.group())); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeShuffleChannelParser("ShuffleChannel", new CaffeShuffleChannelParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.h deleted file mode 100644 index 6a946a7d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_shuffle_channel_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SHUFFLE_CHANNEL_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SHUFFLE_CHANNEL_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeShuffleChannelParser : public CaffeNodeParser { - public: - CaffeShuffleChannelParser() : CaffeNodeParser("ShuffleChannel") {} - ~CaffeShuffleChannelParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SHUFFLE_CHANNEL_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.cc deleted file mode 100644 index 01423604..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.cc +++ /dev/null @@ -1,61 +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 "parser/caffe/caffe_slice_parser.h" -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -namespace { -const int kDefaultAxis = 1; -} // namespace -BaseOperatorPtr CaffeSliceParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::SliceParameter &slice_param = proto.slice_param(); - prim->set_output_num(proto.top_size()); - if (!slice_param.slice_point().empty()) { - prim->set_output_num(slice_param.slice_point_size() + 1); - std::vector size_splits; - for (int i = 0; i < slice_param.slice_point_size(); ++i) { - if (i == 0) { - size_splits.push_back(slice_param.slice_point(i)); - } else { - size_splits.push_back(slice_param.slice_point(i) - slice_param.slice_point(i - 1)); - } - } - size_splits.push_back(-1); - prim->AddAttr("size_splits", api::MakeValue(size_splits)); - } - - if (slice_param.has_axis()) { - prim->set_axis(slice_param.axis()); - } else if (slice_param.has_slice_dim()) { - prim->set_axis(slice_param.slice_dim()); - } else { - prim->set_axis(kDefaultAxis); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeSliceParser("Slice", new CaffeSliceParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.h deleted file mode 100644 index 108f6a37..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_slice_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SLICE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SLICE_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeSliceParser : public CaffeNodeParser { - public: - CaffeSliceParser() : CaffeNodeParser("slice") {} - ~CaffeSliceParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SLICE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.cc deleted file mode 100644 index c102bf44..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.cc +++ /dev/null @@ -1,43 +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 "parser/caffe/caffe_softmax_parser.h" -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeSoftmaxParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - if (proto.has_softmax_param() && proto.softmax_param().has_axis()) { - if (proto.softmax_param().axis() == -1) { - MS_LOG(DEBUG) << "axis with -1 may lead to calculation errors when input less than 4 dims."; - } - prim->set_axis({proto.softmax_param().axis()}); - } else { - prim->set_axis({1}); - } - - return prim; -} - -CaffeNodeRegistrar g_caffeSoftmaxParser("Softmax", new CaffeSoftmaxParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.h deleted file mode 100644 index 077431dd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_softmax_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SOFTMAX_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SOFTMAX_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeSoftmaxParser : public CaffeNodeParser { - public: - CaffeSoftmaxParser() : CaffeNodeParser("softmax") {} - ~CaffeSoftmaxParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SOFTMAX_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.cc deleted file mode 100644 index ff546729..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.cc +++ /dev/null @@ -1,66 +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 "parser/caffe/caffe_spp_parser.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "include/securec.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeSppParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Spp"); - - int64_t pool_method = 0; - if (proto.has_spp_param()) { - const caffe::SPPParameter &spp_param = proto.spp_param(); - if (spp_param.has_pool()) { - pool_method = static_cast(spp_param.pool()); - } - if (spp_param.has_pyramid_height()) { - uint32_t pyramid_height = spp_param.pyramid_height(); - (void)prim->AddAttr(dpico::kPyramidHeight, api::MakeValue(static_cast(pyramid_height))); - std::map> custom_attrs; - std::vector pyramid_height_attr(sizeof(uint32_t)); - if (memcpy_s(pyramid_height_attr.data(), pyramid_height_attr.size() * sizeof(uint8_t), &pyramid_height, - sizeof(uint32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kPyramidHeight] = pyramid_height_attr; - prim->set_attr(custom_attrs); - } else { - MS_LOG(ERROR) << "can't find pyramid_height attr in origin model. " << proto.name(); - return nullptr; - } - } - (void)prim->AddAttr(dpico::kPoolMethod, api::MakeValue(pool_method)); - - return prim; -} - -CaffeNodeRegistrar g_caffeSppParser("SPP", new CaffeSppParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.h deleted file mode 100644 index 5a316684..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_spp_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SPP_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SPP_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeSppParser : public CaffeNodeParser { - public: - CaffeSppParser() : CaffeNodeParser("Spp") {} - ~CaffeSppParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_SPP_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.cc deleted file mode 100644 index 2062fdbc..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.cc +++ /dev/null @@ -1,45 +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 "parser/caffe/caffe_threshold_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeThresholdParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Threshold"); - - if (proto.has_threshold_param()) { - const caffe::ThresholdParameter &threshold_param = proto.threshold_param(); - if (threshold_param.has_threshold()) { - (void)prim->AddAttr(dpico::kThreshold, api::MakeValue(threshold_param.threshold())); - } - } - - return prim; -} - -CaffeNodeRegistrar g_caffeThresholdParser("Threshold", new CaffeThresholdParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.h deleted file mode 100644 index a5ef15ed..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_threshold_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_THRESHOLD_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_THRESHOLD_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeThresholdParser : public CaffeNodeParser { - public: - CaffeThresholdParser() : CaffeNodeParser("Threshold") {} - ~CaffeThresholdParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_THRESHOLD_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.cc deleted file mode 100644 index 8746d282..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.cc +++ /dev/null @@ -1,55 +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 "parser/caffe/caffe_tile_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/cxx_api/tile_fusion.h" - -namespace mindspore { -namespace lite { -BaseOperatorPtr CaffeTileParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - const caffe::TileParameter &tile_param = proto.tile_param(); - std::vector dims; - dims.clear(); - if (tile_param.has_axis()) { - dims.push_back(tile_param.axis()); - } else { - dims.push_back(1); - } - prim->set_dims(dims); - - std::vector multiples; - multiples.clear(); - if (tile_param.has_tiles()) { - multiples.push_back(tile_param.tiles()); - } else { - multiples.push_back(1); - } - (void)prim->AddAttr(dpico::kMultiples, api::MakeValue(multiples)); - - return prim; -} - -CaffeNodeRegistrar g_caffeTileParser("Tile", new CaffeTileParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.h deleted file mode 100644 index e69d8441..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_tile_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_TILE_PARSER_H -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_TILE_PARSER_H - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeTileParser : public CaffeNodeParser { - public: - CaffeTileParser() : CaffeNodeParser("tile") {} - ~CaffeTileParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_TILE_PARSER_H diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.cc deleted file mode 100644 index fc4e47fe..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.cc +++ /dev/null @@ -1,99 +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 "parser/caffe/caffe_upsample_parser.h" -#include -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "mindspore/ops/op_def/op_name.h" -#include "include/securec.h" - -namespace mindspore { -namespace lite { -namespace { -constexpr float kDefaultScaleVal = 2.0; -} // namespace -BaseOperatorPtr CaffeUpsampleParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) { - auto prim = std::make_shared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "prim is nullptr."; - return nullptr; - } - prim->set_type("Upsample"); - - float scale = kDefaultScaleVal; - std::map> custom_attrs; - if (proto.has_upsample_param()) { - const auto &upsample_param = proto.upsample_param(); - if (upsample_param.has_scale()) { - scale = upsample_param.scale(); - } - if (upsample_param.upsample_h()) { - uint32_t upsample_h = upsample_param.upsample_h(); - (void)prim->AddAttr(dpico::kUpsampleH, api::MakeValue(upsample_h)); - - std::vector upsample_h_attr(sizeof(uint32_t)); - if (memcpy_s(upsample_h_attr.data(), upsample_h_attr.size() * sizeof(uint8_t), &upsample_h, sizeof(uint32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kUpsampleH] = upsample_h_attr; - } - if (upsample_param.upsample_w()) { - uint32_t upsample_w = upsample_param.upsample_w(); - (void)prim->AddAttr(dpico::kUpsampleH, api::MakeValue(upsample_w)); - - std::vector upsample_w_attr(sizeof(uint32_t)); - if (memcpy_s(upsample_w_attr.data(), upsample_w_attr.size() * sizeof(uint8_t), &upsample_w, sizeof(uint32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kUpsampleW] = upsample_w_attr; - } - if (upsample_param.has_interpolation_mode()) { - auto mode = upsample_param.interpolation_mode(); - switch (mode) { - case caffe::UpsampleParameter_InterpolationMode_NEAREST: - (void)prim->AddAttr(dpico::kInterpolationMode, api::MakeValue(dpico::kNearest)); - break; - case caffe::UpsampleParameter_InterpolationMode_BILINEAR: - (void)prim->AddAttr(dpico::kInterpolationMode, api::MakeValue(dpico::kBilinear)); - break; - default: - MS_LOG(ERROR) << "current interpolation mode is not supported. " << mode; - return nullptr; - } - } - } - - (void)prim->AddAttr(ops::kScale, api::MakeValue(scale)); - std::vector scale_attr(sizeof(float)); - if (memcpy_s(scale_attr.data(), scale_attr.size() * sizeof(uint8_t), &scale, sizeof(float)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[ops::kScale] = scale_attr; - prim->set_attr(custom_attrs); - return prim; -} - -CaffeNodeRegistrar g_caffeUpsampleParser("Upsample", new CaffeUpsampleParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.h deleted file mode 100644 index 666bfd72..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/caffe_upsample_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_UPSAMPLE_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_UPSAMPLE_PARSER_H_ - -#include -#include "parser/caffe/caffe_node_parser.h" -#include "parser/caffe/caffe_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class CaffeUpsampleParser : public CaffeNodeParser { - public: - CaffeUpsampleParser() : CaffeNodeParser("Upsample") {} - ~CaffeUpsampleParser() override = default; - - BaseOperatorPtr Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_CAFFE_UPSAMPLE_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.cc deleted file mode 100644 index a01ce724..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.cc +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Copyright 2020-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 "parser/caffe/inputs_adjust.h" -#include -#include -#include "common/op_enum.h" -#include "common/anf_util.h" -#include "common/check_base.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "infer/cxx_api/topk_fusion.h" -#include "infer/cxx_api/tile_fusion.h" -#include "infer/cxx_api/reduce_fusion.h" -#include "infer/cxx_api/pad_fusion.h" -#include "infer/cxx_api/pow_fusion.h" -#include "infer/resize.h" -#include "mindspore/core/include/ir/graph_utils.h" - -namespace mindspore::lite { -namespace { -constexpr int kBuildInputFlagTwo = 2; -constexpr int kBuildInputFlagThree = 3; -constexpr int kBuildInputFlagFour = 4; -} // namespace -STATUS InputAdjust::AddAttrToInput(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, int input_num, - const std::string &attr_name, int flag) { - MS_CHECK_TRUE_MSG(cnode != nullptr, RET_ERROR, "cnode is nullptr"); - if (!dpico::CheckInputs(cnode)) { - MS_LOG(ERROR) << "input is invalid."; - return lite::RET_INPUT_TENSOR_ERROR; - } - auto primitive = api::GetValueNode(cnode->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr."; - return lite::RET_ERROR; - } - auto value_ptr = primitive->GetAttr(attr_name); - if (value_ptr == nullptr) { - MS_LOG(DEBUG) << "there is no attr :" << attr_name; - return lite::RET_NO_CHANGE; - } - auto inputs = cnode->inputs(); - if (inputs.empty()) { - MS_LOG(ERROR) << "inputs is empty."; - return lite::RET_ERROR; - } - if (static_cast(inputs.size()) > input_num) { - primitive->EraseAttr(attr_name); - MS_LOG(DEBUG) << "input num has been meet, which is " << inputs.size(); - return lite::RET_OK; - } else if (static_cast(inputs.size()) < input_num) { - MS_LOG(ERROR) << "input num is invalid."; - return lite::RET_ERROR; - } - api::AnfNodePtr param_node; - switch (flag) { - case 1: { - MS_CHECK_TRUE_MSG(!dpico::CastToInt(value_ptr).empty(), RET_ERROR, "value is empty"); - auto value_data_vec = dpico::CastToInt(value_ptr); - auto value_data = value_data_vec.front(); - param_node = - dpico::BuildIntValueParameterNode(func_graph, value_data, cnode->fullname_with_scope() + "_" + attr_name); - break; - } - case kBuildInputFlagTwo: { - auto value_data = dpico::CastToInt(value_ptr); - param_node = - dpico::BuildIntVecParameterNode(func_graph, value_data, cnode->fullname_with_scope() + "_" + attr_name); - break; - } - case kBuildInputFlagThree: { - auto value_data = dpico::CastToVec2DInt(value_ptr); - param_node = - dpico::BuildIntVec2DParameterNode(func_graph, value_data, cnode->fullname_with_scope() + "_" + attr_name); - break; - } - case kBuildInputFlagFour: { - auto value_data = api::GetValue(value_ptr); - param_node = - dpico::BuildFloatValueParameterNode(func_graph, value_data, cnode->fullname_with_scope() + "_" + attr_name); - break; - } - default: { - MS_LOG(ERROR) << "Error attr flag"; - return lite::RET_ERROR; - } - } - auto manager = func_graph->manager(); - MS_ASSERT(manager != nullptr); - manager->AddEdge(cnode, param_node); - - return lite::RET_OK; -} - -bool InputAdjust::Run(const api::FuncGraphPtr &func_graph) { - MS_ASSERT(func_graph != nullptr); - auto manager = api::FuncGraphManager::Manage(func_graph, true); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr."; - return false; - } - auto node_list = api::FuncGraph::TopoSort(func_graph->get_return()); - STATUS status = lite::RET_OK; - for (auto &node : node_list) { - auto cnode = node->cast(); - if (cnode == nullptr) { - continue; - } - if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust Transpose"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "perm", kBuildInputFlagTwo); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust Reshape"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "shape", kBuildInputFlagTwo); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust Gather"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex3, "axis", 1); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust Cast"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "to", 1); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust TopKFusion"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "k", 1); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust TileFusion"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "multiples", kBuildInputFlagTwo); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust ReduceFusion"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "axes", kBuildInputFlagTwo); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust PadFusion"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "paddings", kBuildInputFlagThree); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - MS_LOG(INFO) << "Adjust PowFuison"; - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "power", kBuildInputFlagFour); - } else if (dpico::CheckPrimitiveType(node, api::MakeShared())) { - status = AddAttrToInput(func_graph, cnode, dpico::kInputIndex2, "zoom_factor", 1); - } - if (status != lite::RET_OK && status != lite::RET_NO_CHANGE) { - MS_LOG(ERROR) << "adjust input pass is failed."; - return false; - } - } - return true; -} -} // namespace mindspore::lite diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.h b/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.h deleted file mode 100644 index c6f64cdb..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/caffe/inputs_adjust.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2020-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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_INPUTS_ADJUST_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_INPUTS_ADJUST_H_ - -#include -#include -#include -#include "mindapi/ir/anf.h" -#include "mindapi/ir/func_graph.h" -#include "include/errorcode.h" - -using mindspore::lite::STATUS; -namespace mindspore::lite { -class InputAdjust { - public: - InputAdjust() {} - ~InputAdjust() = default; - - STATUS AddAttrToInput(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, int input_num, - const std::string &attr_name, int flag); - bool Run(const api::FuncGraphPtr &func_graph); -}; -} // namespace mindspore::lite -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_CAFFE_INPUTS_ADJUST_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.cc deleted file mode 100644 index 702add48..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.cc +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Copyright 2022 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 "parser/detection_output_param_helper.h" -#include -#include -#include "mindapi/base/logging.h" -#include "common/op_attr.h" -#include "include/errorcode.h" -#include "infer/custom.h" -#include "./pico_caffe.pb.h" -#include "op/detection_output_operator.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace dpico { -namespace { -int GetProposalParamType(mapper::ProposalParamType *proposal_param_type, - const caffe::DetectionOutputParameter_ParamType ¶m_type) { - if (proposal_param_type == nullptr) { - MS_LOG(ERROR) << "input proposal_param_type is nullptr. "; - return RET_ERROR; - } - switch (param_type) { - case caffe::DetectionOutputParameter_ParamType_DecBBox: - *proposal_param_type = mapper::ProposalParamType::PROPOSAL_DECBBOX; - break; - case caffe::DetectionOutputParameter_ParamType_Sort: - *proposal_param_type = mapper::ProposalParamType::PROPOSAL_SORT; - break; - case caffe::DetectionOutputParameter_ParamType_Nms: - *proposal_param_type = mapper::ProposalParamType::PROPOSAL_NMS; - break; - case caffe::DetectionOutputParameter_ParamType_FilterBox: - *proposal_param_type = mapper::ProposalParamType::PROPOSAL_FILTERBOX; - break; - default: - MS_LOG(ERROR) << "Unsupported Param Type: " << param_type; - return RET_ERROR; - } - return RET_OK; -} -int GetCodeType(mapper::DecBboxCodeType *dec_bbox_code_type, const caffe::CodeType &code_type) { - if (dec_bbox_code_type == nullptr) { - MS_LOG(ERROR) << "input dec_bbox_code_type is nullptr. "; - return RET_ERROR; - } - if (code_type == caffe::CodeType::CENTER_SIZE) { - *dec_bbox_code_type = mapper::DecBboxCodeType::DECBBOX_CODE_TYPE_CENTER_SIZE; - } else { - MS_LOG(ERROR) << "Unsupported Code type: " << code_type; - return RET_ERROR; - } - return RET_OK; -} - -int SetAttrsByParam(const std::shared_ptr &custom_prim, - const caffe::DetectionOutputParameter &detection_param, int index) { - if (custom_prim == nullptr) { - MS_LOG(ERROR) << "custom_prim is nullptr."; - return RET_ERROR; - } - if (detection_param.has_top_k()) { - (void)custom_prim->AddAttr(kDetectionTopK + std::to_string(index), api::MakeValue(detection_param.top_k())); - } - if (detection_param.has_background_label_id()) { - (void)custom_prim->AddAttr(kDetectionBackgroundLabelId + std::to_string(index), - api::MakeValue(detection_param.background_label_id())); - } - if (detection_param.has_multi_class_sorting()) { - (void)custom_prim->AddAttr(kDetectionMultiClassSorting + std::to_string(index), - api::MakeValue(detection_param.multi_class_sorting())); - } - if (detection_param.has_share_location()) { - (void)custom_prim->AddAttr(kDetectionShareLocation + std::to_string(index), - api::MakeValue(detection_param.share_location())); - } - if (detection_param.has_clip_bbox()) { - (void)custom_prim->AddAttr(kDetectionClipBbox + std::to_string(index), - api::MakeValue(detection_param.clip_bbox())); - } - if (detection_param.has_calc_mode()) { - (void)custom_prim->AddAttr(kDetectionCalcMode + std::to_string(index), api::MakeValue(detection_param.calc_mode())); - } - if (detection_param.has_report_flag()) { - (void)custom_prim->AddAttr(kDetectionReportFlag + std::to_string(index), - api::MakeValue(detection_param.report_flag())); - } - if (detection_param.has_top()) { - (void)custom_prim->AddAttr(kDetectionTop + std::to_string(index), - api::MakeValue(detection_param.top())); - } - if (detection_param.has_share_variance()) { - (void)custom_prim->AddAttr(kDetectionShareVariance + std::to_string(index), - api::MakeValue(detection_param.share_variance())); - } - if (!detection_param.variance().empty()) { - (void)custom_prim->AddAttr(kDetectionVarianceVec + std::to_string(index), - api::MakeValue>(std::vector( - detection_param.variance().begin(), detection_param.variance().end()))); - } - if (!detection_param.bias().empty()) { - (void)custom_prim->AddAttr(kDetectionBiasVec + std::to_string(index), - api::MakeValue>( - std::vector(detection_param.bias().begin(), detection_param.bias().end()))); - } - - if (detection_param.has_param_type()) { - mapper::ProposalParamType proposal_param_type; - if (GetProposalParamType(&proposal_param_type, detection_param.param_type()) != RET_OK) { - MS_LOG(ERROR) << "get detection proposal param type failed."; - return RET_ERROR; - } - (void)custom_prim->AddAttr(kDetectionProposalParamType + std::to_string(index), - api::MakeValue(static_cast(proposal_param_type))); - } - - if (detection_param.has_code_type()) { - mapper::DecBboxCodeType dec_bbox_code_type; - if (GetCodeType(&dec_bbox_code_type, detection_param.code_type()) != RET_OK) { - MS_LOG(ERROR) << "get detection code type failed."; - return RET_ERROR; - } - (void)custom_prim->AddAttr(kDetectionCodeType + std::to_string(index), - api::MakeValue(static_cast(dec_bbox_code_type))); - } - return RET_OK; -} -mapper::DetectionOutputParam GetParamFromAttrs(const api::SharedPtr &custom_prim, int index) { - mapper::DetectionOutputParam detection_output_param; - if (custom_prim == nullptr) { - MS_LOG(ERROR) << "custom_prim is nullptr."; - return detection_output_param; - } - auto top_k_ptr = custom_prim->GetAttr(kDetectionTopK + std::to_string(index)); - if (top_k_ptr != nullptr) { - detection_output_param.topK = static_cast(api::GetValue(top_k_ptr)); - } - auto background_label_id_ptr = custom_prim->GetAttr(kDetectionBackgroundLabelId + std::to_string(index)); - if (background_label_id_ptr != nullptr) { - detection_output_param.backgroundLabelId = static_cast(api::GetValue(background_label_id_ptr)); - } - auto multi_class_sorting_ptr = custom_prim->GetAttr(kDetectionMultiClassSorting + std::to_string(index)); - if (multi_class_sorting_ptr != nullptr) { - detection_output_param.multiClassSorting = api::GetValue(multi_class_sorting_ptr); - } - auto share_location_ptr = custom_prim->GetAttr(kDetectionShareLocation + std::to_string(index)); - if (share_location_ptr != nullptr) { - detection_output_param.shareLocation = api::GetValue(share_location_ptr); - } - auto clip_bbox_ptr = custom_prim->GetAttr(kDetectionClipBbox + std::to_string(index)); - if (clip_bbox_ptr != nullptr) { - detection_output_param.clipBbox = api::GetValue(clip_bbox_ptr); - } - auto calc_mode_ptr = custom_prim->GetAttr(kDetectionCalcMode + std::to_string(index)); - if (calc_mode_ptr != nullptr) { - detection_output_param.calcMode = static_cast(api::GetValue(calc_mode_ptr)); - } - auto report_flag_ptr = custom_prim->GetAttr(kDetectionReportFlag + std::to_string(index)); - if (report_flag_ptr != nullptr) { - detection_output_param.reportFlag = api::GetValue(report_flag_ptr); - } - auto top_ptr = custom_prim->GetAttr(kDetectionTop + std::to_string(index)); - if (top_ptr != nullptr) { - detection_output_param.top = api::GetValue(top_ptr); - } - auto share_variance_ptr = custom_prim->GetAttr(kDetectionShareVariance + std::to_string(index)); - if (share_variance_ptr != nullptr) { - detection_output_param.shareVariance = api::GetValue(share_variance_ptr); - } - auto variance_vec_ptr = custom_prim->GetAttr(kDetectionVarianceVec + std::to_string(index)); - if (variance_vec_ptr != nullptr) { - detection_output_param.varianceVec = api::GetValue>(variance_vec_ptr); - } - auto bias_vec_ptr = custom_prim->GetAttr(kDetectionBiasVec + std::to_string(index)); - if (bias_vec_ptr != nullptr) { - detection_output_param.biasVec = api::GetValue>(bias_vec_ptr); - } - auto proposal_param_type_ptr = custom_prim->GetAttr(kDetectionProposalParamType + std::to_string(index)); - if (proposal_param_type_ptr != nullptr) { - detection_output_param.paramType = - static_cast(api::GetValue(proposal_param_type_ptr)); - } - auto code_type_ptr = custom_prim->GetAttr(kDetectionCodeType + std::to_string(index)); - if (code_type_ptr != nullptr) { - detection_output_param.codeType = static_cast(api::GetValue(code_type_ptr)); - } - return detection_output_param; -} -} // namespace -int SetAttrsByDetectionOutputParam(const std::shared_ptr &custom_prim, - const caffe::LayerParameter &proto) { - int detection_output_param_size = proto.detection_output_param_size(); - if (custom_prim == nullptr) { - MS_LOG(ERROR) << "custom_prim is nullptr."; - return RET_ERROR; - } - (void)custom_prim->AddAttr(kDetectionOutputParamSize, api::MakeValue(detection_output_param_size)); - if (detection_output_param_size == 0) { - MS_LOG(INFO) << "no detection param found"; - return RET_OK; - } - for (int i = 0; i < proto.detection_output_param_size(); i++) { - const auto &detect_param = proto.detection_output_param(i); - if (SetAttrsByParam(custom_prim, detect_param, i) != RET_OK) { - MS_LOG(ERROR) << "set prim attrs from detection param failed."; - return RET_ERROR; - } - } - return RET_OK; -} -int SetAttrsByDecBboxParam(const std::shared_ptr &custom_prim, const caffe::LayerParameter &proto) { - if (custom_prim == nullptr) { - MS_LOG(ERROR) << "custom_prim is nullptr."; - return RET_ERROR; - } - if (!proto.has_decbbox_param()) { - MS_LOG(INFO) << "no decbbox param found"; - return RET_OK; - } - (void)custom_prim->AddAttr(kDetectionOutputParamSize, api::MakeValue(1)); - const auto &detect_param = proto.decbbox_param(); - if (SetAttrsByParam(custom_prim, detect_param, 0) != RET_OK) { - MS_LOG(ERROR) << "set prim attrs from decbbox param failed."; - return RET_ERROR; - } - return RET_OK; -} -int GetDetectionOutputParamFromAttrs(std::vector *detection_params, - const api::SharedPtr &custom_prim) { - if (detection_params == nullptr) { - MS_LOG(ERROR) << "input detection_params is nullptr."; - return RET_ERROR; - } - int detection_output_param_size = 0; - auto detection_output_param_size_attr = custom_prim->GetAttr(kDetectionOutputParamSize); - if (detection_output_param_size_attr != nullptr) { - detection_output_param_size = static_cast(api::GetValue(detection_output_param_size_attr)); - } - if (detection_output_param_size == 0) { - MS_LOG(INFO) << "no detection param attr found."; - return RET_OK; - } - for (int i = 0; i < detection_output_param_size; i++) { - (void)detection_params->emplace_back(GetParamFromAttrs(custom_prim, i)); - } - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.h b/mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.h deleted file mode 100644 index 694e65fa..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/detection_output_param_helper.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_DETECTION_OUTPUT_PARAM_HELPER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_DETECTION_OUTPUT_PARAM_HELPER_H_ - -#include -#include -#include -#include -#include "op/detection_output_operator.h" -#include "infer/custom.h" -#include "./pico_caffe.pb.h" - -namespace mindspore { -namespace dpico { -int SetAttrsByDetectionOutputParam(const std::shared_ptr &custom_prim, const caffe::LayerParameter &proto); -int SetAttrsByDecBboxParam(const std::shared_ptr &custom_prim, const caffe::LayerParameter &proto); -int GetDetectionOutputParamFromAttrs(std::vector *detection_params, - const api::SharedPtr &custom_prim); -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_DETECTION_OUTPUT_PARAM_HELPER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.cc deleted file mode 100644 index 3e234db3..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_acos_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxAcosParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Acos"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Acos, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.h deleted file mode 100644 index ff8f5fcd..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acos_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ACOS_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ACOS_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxAcosParser : public converter::NodeParser { - public: - OnnxAcosParser() : NodeParser() {} - ~OnnxAcosParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ACOS_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.cc deleted file mode 100644 index aa60e2a8..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_acosh_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxAcoshParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Acosh"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Acosh, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.h deleted file mode 100644 index 23ee7e3d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_acosh_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ACOSH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ACOSH_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxAcoshParser : public converter::NodeParser { - public: - OnnxAcoshParser() : NodeParser() {} - ~OnnxAcoshParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ACOSH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.cc deleted file mode 100644 index 3e928814..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_asinh_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxAsinhParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Asinh"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Asinh, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.h deleted file mode 100644 index 9a14ef53..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_asinh_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ASINH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ASINH_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxAsinhParser : public converter::NodeParser { - public: - OnnxAsinhParser() : NodeParser() {} - ~OnnxAsinhParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ASINH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.cc deleted file mode 100644 index b9779c89..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_atanh_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxAtanhParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Atanh"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Atanh, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.h deleted file mode 100644 index caa6ccea..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_atanh_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ATANH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ATANH_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxAtanhParser : public converter::NodeParser { - public: - OnnxAtanhParser() : NodeParser() {} - ~OnnxAtanhParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ATANH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.cc deleted file mode 100644 index cbf5bf9f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.cc +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_bitshift_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxBitShiftParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("BitShift"); - std::string direction = "RIGHT"; - auto iter = - std::find_if(onnx_node.attribute().begin(), onnx_node.attribute().end(), - [](const onnx::AttributeProto onnx_node_attr) { return onnx_node_attr.name() == "direction"; }); - if (iter != onnx_node.attribute().end()) { - direction = (*iter).s(); - } - // set attr for mapper - (void)prim->AddAttr("direction", api::MakeValue(direction)); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, BitShift, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.h deleted file mode 100644 index 49a69c7d..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_bitshift_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_BITSHIFT_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_BITSHIFT_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxBitShiftParser : public converter::NodeParser { - public: - OnnxBitShiftParser() : NodeParser() {} - ~OnnxBitShiftParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_BITSHIFT_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.cc deleted file mode 100644 index 21d98e79..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_cosh_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxCoshParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Cosh"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Cosh, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.h deleted file mode 100644 index a90c47f2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_cosh_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_COSH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_COSH_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxCoshParser : public converter::NodeParser { - public: - OnnxCoshParser() : NodeParser() {} - ~OnnxCoshParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_COSH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.cc deleted file mode 100644 index a75646b9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.cc +++ /dev/null @@ -1,56 +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 "parser/onnx/onnx_hardmax_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "tools/converter/parser/onnx/onnx_node_parser.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxHardmaxParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Hardmax"); - int64_t axis = 0; - bool axis_is_def = true; - auto iter = std::find_if(onnx_node.attribute().begin(), onnx_node.attribute().end(), - [](const onnx::AttributeProto onnx_node_attr) { return onnx_node_attr.name() == "axis"; }); - if (iter != onnx_node.attribute().end()) { - axis = static_cast((*iter).i()); - axis_is_def = false; - } - if (axis_is_def) { - axis = OnnxNodeParser::opset_version() >= 13 ? -1 : 1; - } - // set attr for mapper - (void)prim->AddAttr("axis", api::MakeValue(axis)); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Hardmax, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.h deleted file mode 100644 index 40c84c8a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardmax_parser.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_HARDMAX_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_HARDMAX_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxHardmaxParser : public converter::NodeParser { - public: - OnnxHardmaxParser() : NodeParser() {} - ~OnnxHardmaxParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_HARDMAX_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.cc deleted file mode 100644 index cab24910..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.cc +++ /dev/null @@ -1,56 +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 "parser/onnx/onnx_hardsigmoid_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxHardSigmoidParser::Parse(const onnx::GraphProto &onnx_proto, - const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("HardSigmoid"); - float alpha = 0.2; - float beta = 0.5; - for (const auto &onnx_node_attr : onnx_node.attribute()) { - if (onnx_node_attr.name() == "alpha") { - alpha = static_cast(onnx_node_attr.f()); - } else if (onnx_node_attr.name() == "beta") { - beta = static_cast(onnx_node_attr.f()); - } - } - // set attr for mapper - (void)prim->AddAttr("alpha", api::MakeValue(alpha)); - (void)prim->AddAttr("beta", api::MakeValue(beta)); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, HardSigmoid, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.h deleted file mode 100644 index def07720..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_hardsigmoid_parser.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_HARDSIGMOID_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_HARDSIGMOID_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxHardSigmoidParser : public converter::NodeParser { - public: - OnnxHardSigmoidParser() : NodeParser() {} - ~OnnxHardSigmoidParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_HARDSIGMOID_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.cc deleted file mode 100755 index 92591709..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.cc +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright 2023 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 "parser/onnx/onnx_lstm_parser.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" -#include "include/securec.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -constexpr int kNums1 = 1; -constexpr int kNums2 = 2; -ops::BaseOperatorPtr OnnxLSTMParser::Parse(const onnx::GraphProto &, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("LSTM"); - int32_t hidden_size; - int32_t directions = 1; - float clip; - for (const auto &onnx_node_attr : onnx_node.attribute()) { - if (onnx_node_attr.name() == "direction") { - const auto &direction = onnx_node_attr.s(); - if (direction == "forward" || direction == "reverse") { - directions = kNums1; - } else if (direction == "bidirectional") { - directions = kNums2; - } - (void)prim->AddAttr(dpico::kDirection, api::MakeValue(direction)); - } else if (onnx_node_attr.name() == "hidden_size") { - hidden_size = onnx_node_attr.i(); - (void)prim->AddAttr(dpico::kHiddenSize, api::MakeValue(hidden_size)); - } else if (onnx_node_attr.name() == "clip") { - clip = onnx_node_attr.f(); - (void)prim->AddAttr(dpico::kClip, api::MakeValue(clip)); - } - } - // set attr for infershape - std::map> custom_attrs; - std::vector hidden_size_attr(sizeof(int32_t)); - std::vector direction_attr(sizeof(int32_t)); - - if (memcpy_s(hidden_size_attr.data(), hidden_size_attr.size() * sizeof(uint8_t), &hidden_size, sizeof(int32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs["hidden_size"] = hidden_size_attr; - - if (memcpy_s(direction_attr.data(), direction_attr.size() * sizeof(uint8_t), &directions, sizeof(int32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs["direction"] = direction_attr; - prim->set_attr(custom_attrs); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, LSTM, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.h deleted file mode 100755 index 78ba086b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_lstm_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2023 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 DPICO_PARSER_ONNX_LSTM_PARSER_H_ -#define DPICO_PARSER_ONNX_LSTM_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxLSTMParser : public converter::NodeParser { - public: - OnnxLSTMParser() : NodeParser() {} - ~OnnxLSTMParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // DPICO_PARSER_ONNX_LSTM_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.cc deleted file mode 100755 index e8c3dcf2..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.cc +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright 2023 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 "parser/onnx/onnx_maxunpool_parser.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" -#include "include/securec.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -constexpr int kNums2 = 2; -constexpr int kNums3 = 3; -constexpr int kNums4 = 4; -ops::BaseOperatorPtr OnnxMaxUnpoolParser::Parse(const onnx::GraphProto &, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("MaxUnpool"); - std::vector kernels; - std::vector strides; - std::vector pads; - for (const auto &onnx_node_attr : onnx_node.attribute()) { - if (onnx_node_attr.name() == "kernel_shape") { - if (onnx_node_attr.ints_size() == kNums2) { - kernels.push_back(onnx_node_attr.ints(0)); - kernels.push_back(onnx_node_attr.ints(1)); - } - } - if (onnx_node_attr.name() == "strides") { - if (onnx_node_attr.ints_size() == kNums2) { - strides.push_back(onnx_node_attr.ints(0)); - strides.push_back(onnx_node_attr.ints(1)); - } - } - if (onnx_node_attr.name() == "pads") { - if (onnx_node_attr.ints_size() == kNums4) { - pads.push_back(onnx_node_attr.ints(0)); - pads.push_back(onnx_node_attr.ints(kNums2)); - pads.push_back(onnx_node_attr.ints(1)); - pads.push_back(onnx_node_attr.ints(kNums3)); - } - } - } - if (pads.empty()) { - pads = {0, 0, 0, 0}; - } - if (strides.empty()) { - strides.push_back(1); - strides.push_back(1); - } - // set attr for mapper - (void)prim->AddAttr(ops::kStrides, api::MakeValue(strides.front())); - (void)prim->AddAttr(dpico::kKernelShape, api::MakeValue(kernels.front())); - (void)prim->AddAttr(dpico::kPads, api::MakeValue(pads.front())); - // set attr for infershape - std::map> custom_attrs; - std::vector kernel_shape_attr(sizeof(int32_t)); - if (memcpy_s(kernel_shape_attr.data(), kernel_shape_attr.size() * sizeof(uint8_t), &kernels.front(), - sizeof(int32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kKernelShape] = kernel_shape_attr; - - std::vector strides_attr(sizeof(int32_t)); - if (memcpy_s(strides_attr.data(), strides_attr.size() * sizeof(uint8_t), &strides.front(), sizeof(int32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[ops::kStrides] = strides_attr; - prim->set_attr(custom_attrs); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, MaxUnpool, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.h deleted file mode 100755 index 7b6f2e15..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_maxunpool_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2023 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 DPICO_PARSER_ONNX_MAXUNPOOL_PARSER_H_ -#define DPICO_PARSER_ONNX_MAXUNPOOL_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxMaxUnpoolParser : public converter::NodeParser { - public: - OnnxMaxUnpoolParser() : NodeParser() {} - ~OnnxMaxUnpoolParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // DPICO_PARSER_ONNX_MAXUNPOOL_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.cc deleted file mode 100644 index da119452..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_mish_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxMishParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Mish"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Mish, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.h deleted file mode 100644 index dd1b2847..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mish_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_MISH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_MISH_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxMishParser : public converter::NodeParser { - public: - OnnxMishParser() : NodeParser() {} - ~OnnxMishParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_MISH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.cc deleted file mode 100644 index dd3d3b1f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.cc +++ /dev/null @@ -1,51 +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 "parser/onnx/onnx_mod_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxModParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Mod"); - int64_t fmod = 0; - auto iter = std::find_if(onnx_node.attribute().begin(), onnx_node.attribute().end(), - [](const onnx::AttributeProto onnx_node_attr) { return onnx_node_attr.name() == "fmod"; }); - if (iter != onnx_node.attribute().end()) { - fmod = static_cast((*iter).i()); - } - // set attr for mapper - (void)prim->AddAttr(dpico::kFmod, api::MakeValue(fmod)); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Mod, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.h deleted file mode 100644 index 47879386..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_mod_parser.h +++ /dev/null @@ -1,37 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_MOD_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_MOD_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxModParser : public converter::NodeParser { - public: - OnnxModParser() : NodeParser() {} - ~OnnxModParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_MOD_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.cc deleted file mode 100644 index 8cf988db..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.cc +++ /dev/null @@ -1,90 +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 "parser/onnx/onnx_roi_align_parser.h" -#include -#include -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" -#include "include/securec.h" -#include "mindspore/ops/op_def/op_name.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxRoiAlignParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("RoiAlign"); - std::string pool_mode = "avg"; - uint32_t output_height = 1; - uint32_t output_width = 1; - uint32_t sampling_ratio = 0; - float spatial_scale = 1.0; - for (const auto &onnx_node_attr : onnx_node.attribute()) { - if (onnx_node_attr.name() == "mode") { - pool_mode = onnx_node_attr.s(); - } else if (onnx_node_attr.name() == "output_height") { - output_height = static_cast(onnx_node_attr.i()); - } else if (onnx_node_attr.name() == "output_width") { - output_width = static_cast(onnx_node_attr.i()); - } else if (onnx_node_attr.name() == "sampling_ratio") { - sampling_ratio = static_cast(onnx_node_attr.i()); - } else if (onnx_node_attr.name() == "spatial_scale") { - spatial_scale = onnx_node_attr.f(); - } - } - // set attr for mapper - (void)prim->AddAttr(ops::kMode, api::MakeValue(pool_mode)); - (void)prim->AddAttr(dpico::kOutputHeight, api::MakeValue(output_height)); - (void)prim->AddAttr(dpico::kOutputWidth, api::MakeValue(output_width)); - (void)prim->AddAttr(dpico::kSamplingRatio, api::MakeValue(sampling_ratio)); - (void)prim->AddAttr(dpico::kSpatialScale, api::MakeValue(spatial_scale)); - - // set attr for infershape - std::map> custom_attrs; - std::vector output_height_attr(sizeof(uint32_t)); - if (memcpy_s(output_height_attr.data(), output_height_attr.size() * sizeof(uint8_t), &output_height, - sizeof(uint32_t)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kOutputHeight] = output_height_attr; - - std::vector output_width_attr(sizeof(uint32_t)); - if (memcpy_s(output_width_attr.data(), output_width_attr.size() * sizeof(uint8_t), &output_width, sizeof(uint32_t)) != - EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - custom_attrs[dpico::kOutputWidth] = output_width_attr; - prim->set_attr(custom_attrs); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, RoiAlign, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.h deleted file mode 100644 index 55d3d293..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_roi_align_parser.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ROI_ALIGN_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ROI_ALIGN_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxRoiAlignParser : public converter::NodeParser { - public: - OnnxRoiAlignParser() : NodeParser() {} - ~OnnxRoiAlignParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_ROI_ALIGN_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.cc deleted file mode 100644 index e575c889..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.cc +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_shrink_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxShrinkParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Shrink"); - float bias = 0.0; - float lambd = 0.5; - for (const auto &onnx_node_attr : onnx_node.attribute()) { - if (onnx_node_attr.name() == "bias") { - bias = onnx_node_attr.f(); - } else if (onnx_node_attr.name() == "lambd") { - lambd = onnx_node_attr.f(); - } - } - // set attr for mapper - (void)prim->AddAttr("bias", api::MakeValue(bias)); - (void)prim->AddAttr("lambd", api::MakeValue(lambd)); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Shrink, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.h deleted file mode 100644 index eb7e8c0b..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_shrink_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SHRINK_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SHRINK_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxShrinkParser : public converter::NodeParser { - public: - OnnxShrinkParser() : NodeParser() {} - ~OnnxShrinkParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SHRINK_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.cc deleted file mode 100644 index 294ecc36..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_sinh_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxSinhParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Sinh"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Sinh, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.h deleted file mode 100644 index 400590a9..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_sinh_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SINH_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SINH_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxSinhParser : public converter::NodeParser { - public: - OnnxSinhParser() : NodeParser() {} - ~OnnxSinhParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SINH_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.cc deleted file mode 100644 index 88521f6c..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_softsign_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxSoftsignParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Softsign"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Softsign, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.h deleted file mode 100644 index cfb275df..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_softsign_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SOFTSIGN_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SOFTSIGN_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxSoftsignParser : public converter::NodeParser { - public: - OnnxSoftsignParser() : NodeParser() {} - ~OnnxSoftsignParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_SOFTSIGN_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.cc deleted file mode 100644 index cb41c1b6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2022 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 "parser/onnx/onnx_xor_parser.h" -#include -#include -#include "common/op_attr.h" -#include "infer/custom.h" -#include "./onnx.pb.h" -#include "include/registry/node_parser_registry.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace lite { -ops::BaseOperatorPtr OnnxXorParser::Parse(const onnx::GraphProto &onnx_proto, const onnx::NodeProto &onnx_node) { - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new Custom prim failed."; - return nullptr; - } - prim->set_type("Xor"); - - return prim; -} -} // namespace lite -} // namespace mindspore -using mindspore::converter::kFmkTypeOnnx; -namespace mindspore::registry { -REG_NODE_PARSER(kFmkTypeOnnx, Xor, std::make_shared()) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.h b/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.h deleted file mode 100644 index 606ea6d6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/onnx/onnx_xor_parser.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_XOR_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_XOR_PARSER_H_ - -#include -#include "include/registry/node_parser.h" -#include "ops/base_operator.h" -#include "infer/custom.h" - -namespace mindspore { -namespace lite { -using BaseOperatorPtr = std::shared_ptr; -class OnnxXorParser : public converter::NodeParser { - public: - OnnxXorParser() : NodeParser() {} - ~OnnxXorParser() override = default; - - ops::BaseOperatorPtr Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node) override; -}; -} // namespace lite -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_ONNX_ONNX_XOR_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.cc deleted file mode 100644 index b3802a80..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.cc +++ /dev/null @@ -1,411 +0,0 @@ -/** - * Copyright 2021-2022 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 "parser/parser_utils.h" -#include -#include -#include -#include -#include -#include "common/file_util.h" -#include "common/format_utils.h" -#include "common/anf_util.h" -#include "parser/caffe/inputs_adjust.h" -#include "common/data_transpose_utils.h" -#include "infer/cxx_api/conv2d_fusion.h" -#include "infer/cxx_api/conv2d_transpose_fusion.h" -#include "infer/adam.h" -#include "infer/apply_momentum.h" -#include "infer/sgd.h" -#include "mindspore/ops/op_def/op_name.h" -#include "common/check_base.h" - -namespace mindspore::lite { -namespace { -const int WARNING_THRESHOLD = 536870912 * 2; -bool IsWeightNodeSensitive(const api::AnfNodePtr &node) { - return dpico::CheckPrimitiveType(node, api::MakeShared()) || - dpico::CheckPrimitiveType(node, api::MakeShared()) || - dpico::CheckPrimitiveType(node, api::MakeShared()) || - dpico::CheckPrimitiveType(node, api::MakeShared()) || - dpico::CheckPrimitiveType(node, api::MakeShared()); -} - -int GetTransposePerm(mindspore::Format src_format, mindspore::Format dst_format, std::vector *perm) { - MS_ASSERT(perm != nullptr); - auto src_format_str = dpico::FormatEnumToString(src_format); - auto dst_format_str = dpico::FormatEnumToString(dst_format); - if (src_format_str.empty() || dst_format_str.empty() || src_format_str.size() != dst_format_str.size()) { - MS_LOG(ERROR) << "src_format or dst_format is error."; - return lite::RET_ERROR; - } - for (size_t i = 0; i < src_format_str.size(); ++i) { - auto pos = src_format_str.find(dst_format_str[i]); - if (pos == std::string::npos) { - MS_LOG(ERROR) << "src_format and dst_format don't match."; - return lite::RET_ERROR; - } - perm->push_back(static_cast(pos)); - } - return lite::RET_OK; -} - -int GetTransposePermSharing(mindspore::Format src_format, mindspore::Format dst_format, std::vector *perm) { - MS_ASSERT(perm != nullptr); - auto src_format_str = dpico::FormatEnumToString(src_format); - auto dst_format_str = dpico::FormatEnumToString(dst_format); - if (src_format_str.empty() || dst_format_str.empty() || src_format_str.size() != dst_format_str.size()) { - MS_LOG(ERROR) << "src_format or dst_format is error."; - return lite::RET_ERROR; - } - for (size_t i = 0; i < src_format_str.size(); ++i) { - auto pos = dst_format_str.find(src_format_str[i]); - if (pos == std::string::npos) { - MS_LOG(ERROR) << "src_format and dst_format don't match."; - return lite::RET_ERROR; - } - perm->push_back(static_cast(pos)); - } - return lite::RET_OK; -} - -int UnifyVariableConvWeight(const api::FuncGraphPtr &graph, const api::AnfNodePtr &weight_node, - mindspore::Format src_format, mindspore::Format dst_format, - std::set *has_visited) { - MS_CHECK_TRUE_MSG(graph != nullptr && weight_node != nullptr && has_visited != nullptr, RET_ERROR, - "input param contains nullptr."); - if (src_format == dst_format) { - return lite::RET_OK; - } - std::vector perm; - auto status = GetTransposePerm(src_format, dst_format, &perm); - if (status != lite::RET_OK) { - MS_LOG(ERROR) << "get perm failed."; - return status; - } - auto manager = api::FuncGraphManager::Manage(graph); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "manager is nullptr."); - api::CNodePtr trans_cnode = nullptr; - auto weight_node_users = manager->GetUsers(weight_node); - for (auto &weight_node_user : weight_node_users) { - auto post_node = weight_node_user.first; - if (!api::utils::isa(post_node)) { - MS_LOG(ERROR) << "post node is invalid."; - return RET_ERROR; - } - if (!IsWeightNodeSensitive(post_node)) { - continue; - } - has_visited->insert(post_node); - if (trans_cnode == nullptr) { - trans_cnode = - dpico::GenTransposeNode(graph, weight_node, perm, weight_node->fullname_with_scope() + "_post_perm"); - MS_ASSERT(trans_cnode != nullptr); - auto abstract = weight_node->abstract(); - ShapeVector shape; - if (abstract != nullptr) { - ShapeVector weight_shape; - if (dpico::FetchShapeFromAbstract(abstract, &weight_shape) != RET_OK) { - MS_LOG(ERROR) << "fetch shape from abstract failed."; - return RET_ERROR; - } - if (!weight_shape.empty()) { - if (weight_shape.size() != dpico::kDims4) { - MS_LOG(ERROR) << "conv weight shape is invalid, which is not 4D, now is " << weight_shape.size(); - return RET_ERROR; - } - (void)std::transform(perm.begin(), perm.end(), std::back_inserter(shape), - [&weight_shape](const int index) { return weight_shape[index]; }); - } - abstract = abstract->Clone(); - } else { - abstract = dpico::CreateTensorAbstract(shape, TypeId::kNumberTypeFloat32); - MS_ASSERT(abstract != nullptr); - } - auto shape_ptr = api::MakeShared(shape); - if (shape_ptr == nullptr) { - MS_LOG(ERROR) << "shape ptr is nullptr."; - return RET_ERROR; - } - abstract->set_shape(shape_ptr); - trans_cnode->set_abstract(abstract); - } - auto post_cnode = post_node->cast(); - manager->SetEdge(post_cnode, weight_node_user.second, trans_cnode); - } - return RET_OK; -} - -int HandleConstConvWeightShared(const api::FuncGraphPtr &graph, const api::AnfNodePtr &weight_node, - mindspore::Format src_format, mindspore::Format dst_format, - std::set *has_visited) { - MS_CHECK_TRUE_MSG(graph != nullptr && weight_node != nullptr && has_visited != nullptr, RET_ERROR, - "input param contains nullptr."); - if (src_format == dst_format) { - return RET_OK; - } - std::vector perm; - auto status = GetTransposePermSharing(src_format, dst_format, &perm); - if (status != RET_OK) { - MS_LOG(ERROR) << "get perm failed."; - return status; - } - auto manager = api::FuncGraphManager::Manage(graph); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "manager is nullptr."); - api::CNodePtr trans_cnode = nullptr; - auto weight_node_users = manager->GetUsers(weight_node); - for (auto &weight_node_user : weight_node_users) { - auto post_node = weight_node_user.first; - if (!api::utils::isa(post_node)) { - MS_LOG(ERROR) << "post node is invalid."; - return RET_ERROR; - } - if (IsWeightNodeSensitive(post_node)) { - has_visited->insert(post_node); - continue; - } - if (trans_cnode == nullptr) { - trans_cnode = - dpico::GenTransposeNode(graph, weight_node, perm, weight_node->fullname_with_scope() + "_post_perm"); - MS_ASSERT(trans_cnode != nullptr); - auto prim = api::GetValueNode(trans_cnode->input(0)); - MS_ASSERT(prim != nullptr); - (void)prim->AddAttr(ops::kFormat, api::MakeValue(dst_format)); - auto weight_value = dpico::GetTensorInfo(weight_node); - MS_ASSERT(weight_value != nullptr); - auto weight_shape = weight_value->shape(); - ShapeVector shape; - if (!weight_shape.empty()) { - if (weight_shape.size() != dpico::kDims4) { - MS_LOG(ERROR) << "conv weight shape is invalid, which is not 4D, now is " << weight_shape.size(); - return RET_ERROR; - } - (void)std::transform(perm.begin(), perm.end(), std::back_inserter(shape), - [&weight_shape](const int index) { return weight_shape[index]; }); - } - auto abstract = weight_node->abstract(); - MS_ASSERT(abstract != nullptr); - abstract = abstract->Clone(); - auto shape_ptr = api::MakeShared(shape); - if (shape_ptr == nullptr) { - MS_LOG(ERROR) << "shape ptr is nullptr."; - return RET_ERROR; - } - abstract->set_shape(shape_ptr); - trans_cnode->set_abstract(abstract); - } - auto post_cnode = post_node->cast(); - manager->SetEdge(post_cnode, weight_node_user.second, trans_cnode); - } - return RET_OK; -} - -int UnifyConstConvWeight(const api::FuncGraphPtr &graph, const api::AnfNodePtr &weight_node, - mindspore::Format src_format, mindspore::Format dst_format, - std::set *has_visited) { - MS_ASSERT(graph != nullptr && weight_node != nullptr && has_visited != nullptr); - if (src_format == dst_format) { - return lite::RET_OK; - } - auto weight_value = dpico::GetTensorInfo(weight_node); - if (weight_value == nullptr) { - MS_LOG(ERROR) << "conv weight is non-const."; - return RET_ERROR; - } - auto status = dpico::TransFilterFormat(weight_value, src_format, dst_format); - if (status != RET_OK) { - MS_LOG(ERROR) << "TransFilter " << dpico::FormatEnumToString(src_format) << "To" - << dpico::FormatEnumToString(dst_format) << " failed, node : " << weight_node->fullname_with_scope(); - return RET_ERROR; - } - auto type_id = static_cast(weight_value->data_type()); - auto shape = weight_value->shape(); - auto abstract = dpico::CreateTensorAbstract(shape, type_id); - if (abstract == nullptr) { - MS_LOG(ERROR) << "Create tensor abstarct failed"; - return RET_ERROR; - } - weight_node->set_abstract(abstract); - if (HandleConstConvWeightShared(graph, weight_node, src_format, dst_format, has_visited) != RET_OK) { - MS_LOG(ERROR) << "handle const conv weight-shared failed, node name is " << weight_node->fullname_with_scope(); - return RET_ERROR; - } - return RET_OK; -} -} // namespace - -void GetAllFuncGraph(const api::FuncGraphPtr &func_graph, std::set *all_func_graphs) { - MS_ASSERT(func_graph != nullptr && all_func_graphs != nullptr); - if (all_func_graphs->find(func_graph) == all_func_graphs->end()) { - all_func_graphs->insert(func_graph); - } else { - return; - } - - auto nodes = func_graph->nodes(); - for (auto &node : nodes) { - auto new_fg = api::GetValueNode(node); - if (new_fg != nullptr) { - GetAllFuncGraph(new_fg, all_func_graphs); - } - if (api::utils::isa(node)) { - auto cnode = node->cast(); - for (auto &input : cnode->inputs()) { - if (input == nullptr) { - MS_LOG(ERROR) << "input is nullptr."; - return; - } - if (input->isa()) { - new_fg = api::GetValueNode(node); - if (new_fg != nullptr) { - GetAllFuncGraph(new_fg, all_func_graphs); - } - } - } - } - } -} - -int PostAdjust(const std::set &all_func_graphs) { - for (const auto &func_graph : all_func_graphs) { - auto adjust_input = std::make_shared(); - if (adjust_input == nullptr) { - MS_LOG(ERROR) << "adjust input is nullptr."; - return RET_ERROR; - } - if (!adjust_input->Run(func_graph)) { - MS_LOG(ERROR) << "adjust input failed."; - return RET_ERROR; - } - } - return RET_OK; -} - -int UnifyConvWeightFormat(const api::FuncGraphPtr &graph, const api::CNodePtr &cnode, mindspore::Format src_format, - mindspore::Format dst_format, std::set *has_visited) { - MS_ASSERT(graph != nullptr && cnode != nullptr && has_visited != nullptr); - if (src_format == dst_format) { - return lite::RET_OK; - } - if (!dpico::CheckPrimitiveType(cnode, api::MakeShared()) && - !dpico::CheckPrimitiveType(cnode, api::MakeShared())) { - MS_LOG(ERROR) << "cnode is not a member of convolution's family."; - return RET_ERROR; - } - bool is_const_weight = true; - auto weight_node = cnode->input(dpico::kInputIndex2); - if (api::utils::isa(weight_node)) { - is_const_weight = false; - } else if (api::utils::isa(weight_node)) { - auto weight_param_node = weight_node->cast(); - if (!weight_param_node->has_default()) { - is_const_weight = false; - } - } - int status; - if (is_const_weight) { - status = UnifyConstConvWeight(graph, weight_node, src_format, dst_format, has_visited); - } else { - status = UnifyVariableConvWeight(graph, weight_node, src_format, dst_format, has_visited); - } - if (status != RET_OK) { - MS_LOG(ERROR) << "unfiy conv weight failed, cnode name is " << cnode->fullname_with_scope(); - } - return status; -} -bool ReadProtoFromCodedInputStream(google::protobuf::io::CodedInputStream *coded_stream, - google::protobuf::Message *proto) { - if (proto == nullptr) { - MS_LOG(ERROR) << "incorrect parameter. nullptr == proto"; - return false; - } - if (coded_stream == nullptr) { - MS_LOG(ERROR) << "coded_stream is nullptr."; - return false; - } - coded_stream->SetTotalBytesLimit(INT_MAX, WARNING_THRESHOLD); - return proto->ParseFromCodedStream(coded_stream); -} - -STATUS ReadProtoFromText(const std::string &file, google::protobuf::Message *message) { - if (message == nullptr) { - MS_LOG(ERROR) << "message is nullptr."; - return RET_ERROR; - } - - std::string realPath = dpico::RealPath(file.c_str()); - if (realPath.empty()) { - MS_LOG(ERROR) << "Proto file path " << file << " is not valid"; - return RET_ERROR; - } - - std::ifstream fs(realPath.c_str(), std::ifstream::in); - - if (!fs.is_open()) { - MS_LOG(ERROR) << "Open proto file " << file << " failed."; - return RET_ERROR; - } - - google::protobuf::io::IstreamInputStream input(&fs); - bool status = google::protobuf::TextFormat::Parse(&input, message); - if (!status) { - MS_LOG(ERROR) << "call [google::protobuf::TextFormat::Parse] func status fail, please check your text file."; - fs.close(); - return RET_ERROR; - } - - fs.close(); - return RET_OK; -} - -STATUS ReadProtoFromBinaryFile(const std::string &file, google::protobuf::Message *message) { - if (message == nullptr) { - MS_LOG(ERROR) << "message is nullptr."; - return RET_ERROR; - } - - std::string realPath = dpico::RealPath(file.c_str()); - if (realPath.empty()) { - MS_LOG(ERROR) << "Binary proto file path " << file << " is not valid"; - return RET_ERROR; - } - - std::ifstream fs(realPath, std::ifstream::in | std::ifstream::binary); - if (!fs.is_open()) { - MS_LOG(ERROR) << "Open binary proto file " << file << " failed."; - return RET_ERROR; - } - - google::protobuf::io::IstreamInputStream istream(&fs); - google::protobuf::io::CodedInputStream coded_stream(&istream); - - bool success = ReadProtoFromCodedInputStream(&coded_stream, message); - fs.close(); - - if (!success) { - MS_LOG(DEBUG) << "Parse " << file << " failed."; - return RET_ERROR; - } - - return RET_OK; -} -STATUS ValidateFileStr(const std::string &modelFile, const std::string &fileType) { - if (modelFile.size() > fileType.size() && modelFile.substr(modelFile.size() - fileType.size()) == fileType) { - return RET_OK; - } else { - return RET_ERROR; - } -} -} // namespace mindspore::lite diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.h b/mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.h deleted file mode 100644 index a11033f6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/parser_utils.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2021-2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_PARSER_UTILS_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_PARSER_UTILS_H_ - -#include -#include -#include "mindapi/ir/common.h" -#include "mindapi/ir/anf.h" -#include "include/api/format.h" -#include "mindapi/ir/func_graph.h" -#include "mindapi/base/logging.h" -#include "include/errorcode.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/io/coded_stream.h" -using mindspore::lite::STATUS; -namespace mindspore { -namespace lite { -void GetAllFuncGraph(const api::FuncGraphPtr &func_graph, std::set *all_func_graphs); -int PostAdjust(const std::set &all_func_graphs); -int UnifyConvWeightFormat(const api::FuncGraphPtr &graph, const api::CNodePtr &cnode, mindspore::Format src_format, - mindspore::Format dst_format, std::set *has_visited); -bool ReadProtoFromCodedInputStream(google::protobuf::io::CodedInputStream *coded_stream, - google::protobuf::Message *proto); -int ReadProtoFromText(const std::string &file, google::protobuf::Message *message); -int ReadProtoFromBinaryFile(const std::string &file, google::protobuf::Message *message); -STATUS ValidateFileStr(const std::string &modelFile, const std::string &fileType); -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_PARSER_UTILS_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.cc b/mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.cc deleted file mode 100644 index e2e2a3f0..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.cc +++ /dev/null @@ -1,288 +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 "parser/unify_format.h" -#include -#include "common/check_base.h" -#include "common/format_utils.h" -#include "parser/parser_utils.h" -#include "infer/tuple_get_item.h" -#include "infer/adam.h" -#include "infer/sgd.h" -#include "infer/cxx_api/conv2d_fusion.h" -#include "infer/cxx_api/conv2d_transpose_fusion.h" -#include "mindspore/ops/op_def/op_name.h" -#include "mindspore/core/include/ir/graph_utils.h" - -namespace mindspore { -namespace lite { -void UnifyFormatToNHWC::GetTransNodeFormatType(const api::CNodePtr &cnode, dpico::TransTypePair *trans_info) { - MS_ASSERT(cnode != nullptr && trans_info != nullptr); - auto prim_node = cnode->input(0); - auto prim = api::GetValueNode(prim_node); - MS_ASSERT(prim != nullptr); - auto &specify_ops = dpico::GetAssignedFormatOpSet(); - if (specify_ops.find(prim->name()) != specify_ops.end()) { - trans_info->pre_ = dpico::kNCHW2NHWC; - trans_info->post_ = dpico::kNHWC2NCHW; - } -} - -STATUS UnifyFormatToNHWC::GenNewInput(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const std::vector &perm, bool before, size_t index) { - MS_ASSERT(func_graph != nullptr && cnode != nullptr); - api::AnfNodePtr trans_input = before ? cnode->input(index) : cnode->cast(); - std::string trans_name = before ? cnode->fullname_with_scope() + "_pre_" + std::to_string(index - 1) - : cnode->fullname_with_scope() + "_post"; - auto trans_cnode = dpico::GenTransposeNode(func_graph, trans_input, perm, trans_name); - if (trans_cnode == nullptr) { - MS_LOG(ERROR) << "trans_cnode is nullptr."; - return RET_ERROR; - } - auto abstract = trans_input->abstract(); - if (abstract != nullptr) { - trans_cnode->set_abstract(abstract->Clone()); - } - auto trans_prim = api::GetValueNode(trans_cnode->input(0)); - if (trans_prim == nullptr) { - MS_LOG(ERROR) << "trans_prim is nullptr."; - return RET_ERROR; - } - if (perm == dpico::kNC2NH) { - (void)trans_prim->AddAttr(ops::kFormat, api::MakeValue(NCHW)); - } else if (perm == dpico::kNH2NC) { - (void)trans_prim->AddAttr(ops::kFormat, api::MakeValue(NHWC)); - } - auto manager = func_graph->manager(); - if (manager == nullptr) { - manager = api::FuncGraphManager::Manage(func_graph, true); - } - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "manager is nullptr"); - if (before) { - manager->SetEdge(cnode, index, trans_cnode); - } else { - (void)manager->Replace(cnode, trans_cnode); - } - return lite::RET_OK; -} - -STATUS UnifyFormatToNHWC::InsertPreTransNode(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const std::vector &perm) { - MS_ASSERT(func_graph != nullptr && cnode != nullptr); - auto prim_node = cnode->input(0); - auto prim = api::GetValueNode(prim_node); - MS_ASSERT(prim != nullptr); - auto &specify_ops = dpico::GetAssignedFormatOpSet(); - if (specify_ops.find(prim->name()) == specify_ops.end()) { - MS_LOG(ERROR) << "p don't meet nhwc condition."; - return lite::RET_ERROR; - } - if (GenNewInput(func_graph, cnode, perm, true, 1) != lite::RET_OK) { - MS_LOG(ERROR) << "generate a transpose node failed."; - return lite::RET_ERROR; - } - return lite::RET_OK; -} - -STATUS UnifyFormatToNHWC::InsertPostTransNode(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const std::vector &perm) { - MS_ASSERT(func_graph != nullptr && cnode != nullptr); - if (!cnode->abstract()->isa()) { - if (GenNewInput(func_graph, cnode, perm, false) != lite::RET_OK) { - MS_LOG(ERROR) << "generate a new input failed."; - return lite::RET_ERROR; - } - } else { - MS_CHECK_TRUE_MSG(func_graph->manager() != nullptr, RET_ERROR, "manager is nullptr"); - auto node_users = func_graph->manager()->GetUsers(cnode); - for (auto &node_user : node_users) { - auto post_node = node_user.first; - if (post_node == nullptr) { - MS_LOG(ERROR) << "post_node is nullptr."; - return RET_ERROR; - } - if (!dpico::CheckPrimitiveType(post_node, api::MakeShared())) { - MS_LOG(ERROR) << "post node is invalid."; - return lite::RET_ERROR; - } - if (func_graph->manager()->GetUsers(post_node).empty()) { - continue; - } - auto post_cnode = post_node->cast(); - if (GenNewInput(func_graph, post_cnode, perm, false) != lite::RET_OK) { - MS_LOG(ERROR) << "generate a new input failed."; - return lite::RET_ERROR; - } - } - } - return lite::RET_OK; -} - -STATUS UnifyFormatToNHWC::HandleGraphInput(const api::FuncGraphPtr &func_graph) { - MS_ASSERT(func_graph != nullptr); - auto graph_input = func_graph->get_inputs(); - for (auto &input : graph_input) { - if (input == nullptr) { - MS_LOG(ERROR) << "input is nullptr."; - return RET_ERROR; - } - auto input_param = input->cast(); - MS_ASSERT(input_param != nullptr); - auto abstract = input_param->abstract(); - MS_ASSERT(abstract != nullptr); - ShapeVector shape; - if (dpico::FetchShapeFromAbstract(abstract, &shape) != lite::RET_OK) { - MS_LOG(ERROR) << "fetch shape failed." << input->fullname_with_scope(); - return lite::RET_ERROR; - } - if (shape.size() != dpico::kDims4) { - continue; - } - ShapeVector transfer_shape = {shape[0], shape[dpico::kInputIndex2], shape[dpico::kInputIndex3], shape[1]}; - api::CNodePtr trans_cnode = - dpico::GenTransposeNode(func_graph, input, dpico::kNH2NC, input->fullname_with_scope() + "_nh2nc"); - if (trans_cnode == nullptr) { - MS_LOG(ERROR) << "create transpose cnode failed."; - return lite::RET_ERROR; - } - auto trans_prim = api::GetValueNode(trans_cnode->input(0)); - MS_ASSERT(trans_prim != nullptr); - (void)trans_prim->AddAttr(ops::kFormat, api::MakeValue(NHWC)); - trans_cnode->set_abstract(abstract->Clone()); - auto transfer_shape_ptr = api::MakeShared(transfer_shape); - if (transfer_shape_ptr == nullptr) { - MS_LOG(ERROR) << "transfer_shape_ptr is nullptr."; - return RET_ERROR; - } - abstract->set_shape(transfer_shape_ptr); - MS_CHECK_TRUE_MSG(func_graph->manager() != nullptr, RET_ERROR, "manager is nullptr"); - if (!func_graph->manager()->Replace(input, trans_cnode)) { - MS_LOG(ERROR) << "replace cnode failed."; - return RET_ERROR; - } - } - return lite::RET_OK; -} - -STATUS UnifyFormatToNHWC::HandleGraphNode(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode) { - MS_ASSERT(func_graph != nullptr && cnode != nullptr); - dpico::TransTypePair trans_info; - GetTransNodeFormatType(cnode, &trans_info); - if (trans_info.pre_ == dpico::kNONE || trans_info.post_ == dpico::kNONE) { - return lite::RET_NO_CHANGE; - } - auto before_perm = trans_info.pre_ == dpico::kNHWC2NCHW ? dpico::kNH2NC : dpico::kNC2NH; - auto after_perm = trans_info.post_ == dpico::kNCHW2NHWC ? dpico::kNC2NH : dpico::kNH2NC; - if (InsertPreTransNode(func_graph, cnode, before_perm) != lite::RET_OK) { - MS_LOG(ERROR) << "insert pre node failed." << cnode->fullname_with_scope(); - return lite::RET_ERROR; - } - if (dpico::CheckPrimitiveType(cnode, api::MakeShared()) || - dpico::CheckPrimitiveType(cnode, api::MakeShared())) { - return lite::RET_OK; - } - auto prim = api::GetValueNode(cnode->input(0)); - if (prim == nullptr) { - MS_LOG(ERROR) << "current node's prim is nullptr, " << cnode->fullname_with_scope(); - return lite::RET_ERROR; - } - (void)prim->AddAttr(ops::kFormat, api::MakeValue(mindspore::NHWC)); - if (InsertPostTransNode(func_graph, cnode, after_perm) != lite::RET_OK) { - MS_LOG(ERROR) << "insert post node failed." << cnode->fullname_with_scope(); - return lite::RET_ERROR; - } - return lite::RET_OK; -} - -bool UnifyFormatToNHWC::BasicProcess(const api::FuncGraphPtr &func_graph, bool main_graph) { - MS_ASSERT(func_graph != nullptr); - auto manager = api::FuncGraphManager::Manage(func_graph, true); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr."; - return false; - } - auto node_list = api::FuncGraph::TopoSort(func_graph->get_return()); - int status; - for (auto &node : node_list) { - if (!api::utils::isa(node)) { - continue; - } - auto cnode = node->cast(); - if (dpico::IsSpecialType(cnode)) { - continue; - } - status = HandleGraphNode(func_graph, cnode); - if (status != lite::RET_OK && status != lite::RET_NO_CHANGE) { - return false; - } - } - if (main_graph) { - if (HandleGraphInput(func_graph) != lite::RET_OK) { - return false; - } - } - return true; -} - -STATUS UnifyFormatToNHWC::ConvWeightFormatTrans(const api::FuncGraphPtr &graph, - std::set *has_visited) { - MS_ASSERT(graph != nullptr && has_visited != nullptr); - auto node_list = api::FuncGraph::TopoSort(graph->get_return()); - for (auto &node : node_list) { - if (!api::utils::isa(node)) { - continue; - } - auto cnode = node->cast(); - if (!dpico::CheckPrimitiveType(node, api::MakeShared()) && - !dpico::CheckPrimitiveType(node, api::MakeShared())) { - continue; - } - if (has_visited->find(node) != has_visited->end()) { - continue; - } - has_visited->insert(node); - auto status = lite::UnifyConvWeightFormat(graph, cnode, mindspore::KCHW, mindspore::KHWC, has_visited); - if (status != lite::RET_OK) { - MS_LOG(ERROR) << "unify conv weight failed, current node name is " << cnode->fullname_with_scope(); - return status; - } - } - return lite::RET_OK; -} - -bool UnifyFormatToNHWC::Run(const api::FuncGraphPtr &func_graph) { - MS_ASSERT(func_graph != nullptr); - auto node_list = api::FuncGraph::TopoSort(func_graph->get_return()); - for (auto &node : node_list) { - auto prim = api::GetValueNode(node); - if (prim == nullptr) { - continue; - } - } - std::set has_visited; - auto status = ConvWeightFormatTrans(func_graph, &has_visited); - if (status != lite::RET_OK) { - MS_LOG(ERROR) << "Conv2D weight FormatTrans failed: " << status; - return false; - } - if (!BasicProcess(func_graph, true)) { - MS_LOG(ERROR) << "run framework transpose unify failed."; - return false; - } - return true; -} -} // namespace lite -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.h b/mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.h deleted file mode 100644 index f64ee66f..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/parser/unify_format.h +++ /dev/null @@ -1,54 +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_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_UNIFY_FORMAT_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_UNIFY_FORMAT_H_ - -#include -#include -#include -#include -#include -#include "common/data_transpose_utils.h" -#include "common/anf_util.h" -#include "include/errorcode.h" - -namespace mindspore { -namespace lite { -class UnifyFormatToNHWC { - public: - UnifyFormatToNHWC() = default; - ~UnifyFormatToNHWC() = default; - bool Run(const api::FuncGraphPtr &func_graph); - - private: - STATUS InsertPostTransNode(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const std::vector &perm); - STATUS InsertPreTransNode(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const std::vector &perm); - STATUS GenNewInput(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, const std::vector &perm, - bool before, size_t index = 0); - bool BasicProcess(const api::FuncGraphPtr &func_graph, bool main_graph); - void GetTransNodeFormatType(const api::CNodePtr &cnode, dpico::TransTypePair *trans_info); - STATUS HandleGraphInput(const api::FuncGraphPtr &func_graph); - STATUS HandleGraphNode(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode); - STATUS ConvWeightFormatTrans(const api::FuncGraphPtr &graph, std::set *has_visited); - std::map> sub_inputs_map_; -}; -} // namespace lite -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_PARSER_UNIFY_FORMAT_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.cc b/mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.cc deleted file mode 100644 index 5a1f2270..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.cc +++ /dev/null @@ -1,312 +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 "src/calib_data_generator.h" -#include -#include -#include -#include -#include -#include -#include "infer/tuple_get_item.h" -#include "common/anf_util.h" -#include "common/string_util.h" -#include "common/file_util.h" -#include "src/mapper_config_parser.h" -#include "src/data_preprocessor.h" -#include "adapter/utils.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace dpico { -namespace { -constexpr size_t kMaxSize = 1024; -} // namespace -std::vector> CalibDataGenerator::GetInputShapes(const api::AnfNodePtrList &graph_inputs) { - std::vector> input_shapes; - for (const auto &input : graph_inputs) { - ShapeVector shape_vector; - if (GetShapeVectorFromParameter(input, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "get graph input shape failed. " << input->fullname_with_scope(); - return std::vector>(); - } - if (shape_vector.empty()) { - MS_LOG(ERROR) << input->fullname_with_scope() << " input shape is empty."; - return std::vector>(); - } - if (shape_vector.size() == kDims4) { // transform nchw to nhwc - shape_vector = std::vector{shape_vector[kNCHW_N], shape_vector[kNCHW_H], shape_vector[kNCHW_W], - shape_vector[kNCHW_C]}; - } - for (size_t i = 0; i < shape_vector.size(); i++) { - auto dim = shape_vector.at(i); - if (dim < 0) { - if (i == 0) { - dim = 1; - } else { - MS_LOG(ERROR) << input->fullname_with_scope() << "'s input shape[" << i << "] is " << dim - << ", which is unsupported by dpico."; - return std::vector>(); - } - } - } - input_shapes.emplace_back(shape_vector); - } - return input_shapes; -} - -std::vector CalibDataGenerator::GetInDataFileList(const api::AnfNodePtrList &graph_inputs) { - auto preprocessed_data_dir = DataPreprocessor::GetInstance()->GetPreprocessedDataDir(); - if (preprocessed_data_dir.empty()) { - MS_LOG(ERROR) << "preprocessed_data_dir is empty."; - return {}; - } - auto batch_size = DataPreprocessor::GetInstance()->GetBatchSize(); - if (batch_size == 0) { - MS_LOG(ERROR) << "input image list batch size is 0."; - return {}; - } - std::vector in_data_files_list; - for (size_t i = 0; i < batch_size; i++) { - std::string in_data_files; // such as /abs_path/op_1/1/input.bin,/abs_path/op_2/1/input.bin,..., - for (const auto &input : graph_inputs) { - auto op_name = input->fullname_with_scope(); - auto folder_name = ReplaceSpecifiedChar(op_name, '/', '_'); - std::string in_data_file = preprocessed_data_dir + folder_name + "/" + std::to_string(i) + "/input.bin"; - if (AccessFile(in_data_file, F_OK) == 0) { - in_data_files += in_data_file + ','; - } else { - MS_LOG(ERROR) << in_data_file << " is not existed."; - return {}; - } - } - (void)in_data_files_list.emplace_back(in_data_files); - } - return in_data_files_list; -} - -int CalibDataGenerator::DumpKernelsData(const std::string ¤t_path, - const std::vector &in_data_file_list, - const std::vector kernel_names, - const std::vector> &input_shapes) { - std::string model_file = "model.ms"; - for (auto in_data_file : in_data_file_list) { - auto ret = lite::converter::InnerPredict(model_file, in_data_file, kernel_names, current_path, input_shapes); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Execute InnerPredict failed."; - return RET_ERROR; - } - } - return RET_OK; -} -STATUS CalibDataGenerator::ParseAttrFromFilename(struct OpAttr *op_attr, const std::string &file_name, bool is_input) { - if (op_attr == nullptr) { - MS_LOG(ERROR) << "op attr is nullptr."; - return RET_ERROR; - } - // file name such as: conv1_output_1_shape_1_352_352_1_Float32_NHWC.bin; - std::string search_str = is_input ? "_input_" : "_output_"; - std::string shape_attr = "shape"; - std::string attrs_str = file_name.substr(file_name.find(search_str) + search_str.size(), - file_name.find(".bin") - file_name.find(search_str) - search_str.size()); - std::string idx = attrs_str.substr(0, attrs_str.find('_')); - if (!IsValidUnsignedNum(idx)) { - MS_LOG(ERROR) << idx << " is not a valid unsigned num."; - return RET_ERROR; - } - op_attr->input_output_idx = std::stoi(idx); - attrs_str = attrs_str.substr(attrs_str.find('_') + 1); - op_attr->format = attrs_str.substr(attrs_str.rfind('_') + 1); - attrs_str = attrs_str.substr(0, attrs_str.rfind('_')); - op_attr->data_type = attrs_str.substr(attrs_str.rfind('_') + 1); - attrs_str = attrs_str.substr(0, attrs_str.rfind('_')); - auto shape_str = attrs_str.substr(attrs_str.find(shape_attr) + shape_attr.size()); - if (!shape_str.empty()) { - auto dims = SplitString(shape_str, '_'); - for (const auto &dim : dims) { - if (IsValidUnsignedNum(dim)) { - op_attr->shape.push_back(std::stoi(dim)); - } - } - } - - return RET_OK; -} - -int CalibDataGenerator::TransBinsToTxt(const std::vector &dump_op_infos) { - auto batch_size = DataPreprocessor::GetInstance()->GetBatchSize(); - if (batch_size == 0) { - MS_LOG(ERROR) << "input image list batch size is 0."; - return RET_ERROR; - } - auto output_path = MapperConfigParser::GetInstance()->GetOutputPath(); - auto dump_data_dir = output_path + "dump_data/"; - auto calib_data_dir = output_path + "calib_data/"; - if (CreateDir(&calib_data_dir) != RET_OK) { - MS_LOG(ERROR) << "create dir failed. " << calib_data_dir; - return RET_ERROR; - } - for (const auto &dump_op_info : dump_op_infos) { - std::ofstream ofs; - std::string dump_op_txt_path = - calib_data_dir + ReplaceSpecifiedChar(dump_op_info.origin_op_name, '/', '_') + ".txt"; - ofs.open(dump_op_txt_path, std::ios::out); - if (!ofs.is_open()) { - MS_LOG(ERROR) << "file open failed. " << dump_op_txt_path; - return RET_ERROR; - } - (void)ofs.precision(kNumPrecision); - bool is_input = dump_op_info.input_index >= 0; - auto del_special_character = ReplaceSpecifiedChar(dump_op_info.dump_op_name, '/', '.'); - auto pattern = is_input - ? del_special_character + "_input_" + std::to_string(dump_op_info.input_index) + "_shape_" - : del_special_character + "_output_" + std::to_string(dump_op_info.output_index) + "_shape_"; - for (size_t i = 0; i < batch_size; i++) { - auto cur_dump_data_dir = dump_data_dir + std::to_string(i) + '/'; - if (AccessFile(cur_dump_data_dir, F_OK) == 0) { - std::string file_name; - for (const auto &entry : std::experimental::filesystem::directory_iterator(cur_dump_data_dir)) { - std::string cur_name = entry.path().filename(); - auto pos = cur_name.find(pattern); - if (pos == 0) { - file_name = cur_name; - break; - } - } - if (file_name.empty()) { - MS_LOG(ERROR) << "there is no corresponding bin file of " << pattern << " in " << cur_dump_data_dir; - return RET_ERROR; - } - struct OpAttr op_attr; - op_attr.input_format = dump_op_info.input_format; - if (ParseAttrFromFilename(&op_attr, file_name, is_input) != RET_OK) { - MS_LOG(ERROR) << "parse attr from file name failed."; - return RET_ERROR; - } - if (op_attr.data_type == "Float32") { - if (ReadBinToOfstream(cur_dump_data_dir + file_name, op_attr, ofs) != RET_OK) { - MS_LOG(ERROR) << "read bin to ofstream failed."; - ofs.close(); - return RET_ERROR; - } - } else if (op_attr.data_type == "Int32") { - if (ReadBinToOfstream(cur_dump_data_dir + file_name, op_attr, ofs) != RET_OK) { - ofs.close(); - MS_LOG(ERROR) << "read bin to ofstream failed."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << "unsupported data type."; - ofs.close(); - return RET_ERROR; - } - ofs << std::endl; - } else { - MS_LOG(ERROR) << cur_dump_data_dir << " doesn't exist."; - ofs.close(); - return RET_ERROR; - } - } - ofs.close(); // end of write data to txt - if (MapperConfigParser::GetInstance()->AddImageList(dump_op_info.origin_op_name, dump_op_txt_path) != RET_OK) { - MS_LOG(ERROR) << "add image list for " << dump_op_info.origin_op_name << "failed"; - return RET_ERROR; - } - } - - return RET_OK; -} - -int CalibDataGenerator::Run(const api::AnfNodePtrList &graph_inputs, const api::AnfNodePtrList &nodes, - const std::map &input_format_infos) { - if (graph_inputs.empty()) { - MS_LOG(ERROR) << "graph inputs shouldn't be empty."; - return RET_ERROR; - } - auto image_lists = MapperConfigParser::GetInstance()->GetImageLists(); - std::vector dump_op_infos; - std::set has_visited; - for (const auto &node : nodes) { - if (has_visited.find(node) != has_visited.end()) { - continue; - } - (void)has_visited.insert(node); - DumpOpInfo dump_op_info = {node->fullname_with_scope(), node->fullname_with_scope(), -1, -1, 0}; - if (control_flow_inputs_.find(node) != control_flow_inputs_.end()) { - dump_op_info.dump_op_name = control_flow_inputs_[node].first->fullname_with_scope(); - dump_op_info.input_index = control_flow_inputs_[node].second; - } else { - dump_op_info.output_index = 0; - if (CheckPrimitiveType(node, api::MakeShared())) { - auto tuple_get_item_cnode = node->cast(); - if (tuple_get_item_cnode == nullptr || tuple_get_item_cnode->size() < kInputIndex2) { - MS_LOG(ERROR) << "tuple_get_item_node is invalid. " << node->fullname_with_scope(); - return RET_ERROR; - } - if (tuple_get_item_cnode->input(1) == nullptr) { - MS_LOG(ERROR) << "tuple_get_item_node input 1 is invalid. "; - return RET_ERROR; - } - dump_op_info.dump_op_name = tuple_get_item_cnode->input(1)->fullname_with_scope(); - dump_op_info.output_index = static_cast(GetTupleGetItemOutIndex(tuple_get_item_cnode)); - } - } - auto iter = input_format_infos.find(dump_op_info.dump_op_name); - if (iter != input_format_infos.end()) { - dump_op_info.input_format = iter->second; - } else { - MS_LOG(WARNING) << "not find " << dump_op_info.dump_op_name << " in input_format_infos."; - } - if (image_lists.find(dump_op_info.dump_op_name) == image_lists.end()) { - (void)dump_op_infos.emplace_back(dump_op_info); - } - } - if (dump_op_infos.empty()) { - MS_LOG(ERROR) << "dumped ops shouldn't be empty when network is segmented"; - return RET_ERROR; - } - - auto in_data_file_list = GetInDataFileList(graph_inputs); - if (in_data_file_list.empty()) { - MS_LOG(ERROR) << "get in data file for benchmark failed."; - return RET_ERROR; - } - - auto input_shapes = GetInputShapes(graph_inputs); - if (input_shapes.empty()) { - MS_LOG(ERROR) << "get input shapes for benchmark failed."; - return RET_ERROR; - } - - std::vector kernel_names; - (void)std::transform(dump_op_infos.begin(), dump_op_infos.end(), std::back_inserter(kernel_names), - [](DumpOpInfo const &op_info) { return op_info.dump_op_name; }); - auto output_path = MapperConfigParser::GetInstance()->GetOutputPath(); - if (DumpKernelsData(output_path, in_data_file_list, kernel_names, input_shapes) != RET_OK) { - MS_LOG(ERROR) << "dump kernels data failed."; - return RET_ERROR; - } - - if (TransBinsToTxt(dump_op_infos) != RET_OK) { - MS_LOG(ERROR) << "transform dumped files to txt failed."; - return RET_ERROR; - } - - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.h b/mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.h deleted file mode 100644 index a1ae9358..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/calib_data_generator.h +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright 2021-2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_CALIB_DATA_GENERATOR_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_CALIB_DATA_GENERATOR_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "include/securec.h" -#include "include/registry/converter_context.h" -#include "common/data_transpose_utils.h" -#include "mindapi/ir/anf.h" -#include "include/errorcode.h" -#include "common/check_base.h" - -namespace mindspore { -namespace dpico { -constexpr auto kNchw2Nhwc = "nchw2nhwc"; -constexpr auto kNhwc2Nchw = "nhwc2nchw"; -enum DumpMode : int { kDumpInputOutput = 0, kDumpInput = 1, kDumpOutput = 2 }; -struct OpAttr { - std::string data_type; - size_t input_output_idx; - std::vector shape; - std::string format; - int input_format; -}; -struct DumpOpInfo { - std::string origin_op_name; - std::string dump_op_name; - int input_index; - int output_index; - int input_format; -}; -class CalibDataGenerator { - public: - explicit CalibDataGenerator(int dump_level = 0, - const std::map> &control_flow_inputs = {}) - : dump_level_(dump_level), control_flow_inputs_(control_flow_inputs) {} - ~CalibDataGenerator() = default; - int Run(const api::AnfNodePtrList &graph_inputs, const api::AnfNodePtrList &nodes, - const std::map &input_format_infos); - - private: - int GenerateDumpConfig(const std::string &dump_cfg_path, const std::vector &dump_infos); - std::vector> GetInputShapes(const api::AnfNodePtrList &graph_inputs); - std::vector GetInDataFileList(const api::AnfNodePtrList &graph_inputs); - int DumpKernelsData(const std::string &dump_cfg_path, const std::vector &in_data_file_list, - const std::vector kernel_names, - const std::vector> &input_shapes); - STATUS ParseAttrFromFilename(struct OpAttr *op_attr, const std::string &file_name, bool is_input); - int TransBinsToTxt(const std::vector &dump_infos); - - template - int CalibDataTranspose(const std::unique_ptr &raw_datas, const std::unique_ptr &dst_datas, - const std::vector &shape, const std::string &transpose) { - if (transpose == kNhwc2Nchw) { - if (NHWC2NCHW(raw_datas.get(), dst_datas.get(), shape) != RET_OK) { - MS_LOG(ERROR) << "NHWC to NCHW failed."; - return RET_ERROR; - } - } else if (transpose == kNchw2Nhwc) { - if (NCHW2NHWC(raw_datas.get(), dst_datas.get(), shape) != RET_OK) { - MS_LOG(ERROR) << "NCHW to NHWC failed."; - return RET_ERROR; - } - } - return RET_OK; - } - - template - int ReadBinToOfstream(const std::string &file_path, const struct OpAttr &op_attr, std::ofstream &ofs) { - std::ifstream ifs; - std::string real_path = lite::RealPath(file_path.c_str()); - if (real_path.empty()) { - MS_LOG(ERROR) << "Invalid realpath!"; - return RET_ERROR; - } - ifs.open(real_path, std::ifstream::in | std::ios::binary); - if (!ifs.is_open() || !ifs.good()) { - MS_LOG(ERROR) << "open file failed. " << file_path; - return RET_ERROR; - } - size_t shape_size = 1; - for (size_t i = 0; i < op_attr.shape.size(); i++) { - if (op_attr.shape.at(i) < 0) { - MS_LOG(ERROR) << "dim val should be equal or greater than 0"; - return RET_ERROR; - } - if (SIZE_MUL_OVERFLOW(shape_size, static_cast(op_attr.shape.at(i)))) { - MS_LOG(ERROR) << "size_t mul overflow."; - return RET_ERROR; - } - shape_size *= static_cast(op_attr.shape.at(i)); - } - (void)ifs.seekg(0, std::ios::end); - size_t file_size = static_cast(ifs.tellg()); - if (file_size != shape_size * sizeof(T)) { - MS_LOG(ERROR) << "file size " << file_size << " is not equal to shape size " << shape_size; - return RET_ERROR; - } - auto raw_datas = std::make_unique(shape_size); - if (raw_datas == nullptr) { - MS_LOG(ERROR) << "new T failed."; - return RET_ERROR; - } - (void)ifs.seekg(0, std::ios::beg); - (void)ifs.read(reinterpret_cast(raw_datas.get()), shape_size * sizeof(T)); - ifs.close(); - std::string transpose = ""; - if (op_attr.shape.size() == kDims4) { - if ((op_attr.format == "NHWC") && (op_attr.input_format == 0)) { - transpose = kNhwc2Nchw; - } else if ((op_attr.format == "NCHW") && (op_attr.input_format == 1)) { - transpose = kNchw2Nhwc; - } - } - auto dst_datas = std::make_unique(shape_size); - if (dst_datas == nullptr) { - MS_LOG(ERROR) << "new T failed."; - return RET_ERROR; - } - if (memcpy_s(dst_datas.get(), shape_size * sizeof(T), raw_datas.get(), shape_size * sizeof(T)) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return RET_ERROR; - } - if (CalibDataTranspose(raw_datas, dst_datas, op_attr.shape, transpose) != RET_OK) { - MS_LOG(ERROR) << "calib data transpose failed."; - return RET_ERROR; - } - - for (size_t i = 0; i < shape_size; i++) { - ofs << dst_datas.get()[i] << ' '; - } - return RET_OK; - } - int dump_level_; - std::map> control_flow_inputs_; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_CALIB_DATA_GENERATOR_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.cc b/mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.cc deleted file mode 100644 index 35224fd7..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.cc +++ /dev/null @@ -1,466 +0,0 @@ -/** - * Copyright 2021-2022 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 "src/custom_creator.h" -#include -#include -#include -#include -#include -#include "include/api/format.h" -#include "infer/make_tuple.h" -#include "common/anf_util.h" -#include "common/op_attr.h" -#include "common/op_enum.h" -#include "common/string_util.h" -#include "common/graph_output_name_keeper.h" -#include "src/mapper_config_parser.h" -#include "src/om_generator.h" -#include "src/graph_split_api.h" -#include "infer/tuple_get_item.h" -#include "include/securec.h" -#include "include/registry/converter_context.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace dpico { -namespace { -const int kMaxRoiFrameCnt = 300; -const std::map kDataTypeMap = { - {mapper::OpDataType::OP_DTYPE_S8, kNumberTypeInt8}, {mapper::OpDataType::OP_DTYPE_U8, kNumberTypeUInt8}, - {mapper::OpDataType::OP_DTYPE_S16, kNumberTypeInt16}, {mapper::OpDataType::OP_DTYPE_U16, kNumberTypeUInt16}, - {mapper::OpDataType::OP_DTYPE_S32, kNumberTypeInt32}, {mapper::OpDataType::OP_DTYPE_U32, kNumberTypeUInt32}, - {mapper::OpDataType::OP_DTYPE_F16, kNumberTypeFloat16}, {mapper::OpDataType::OP_DTYPE_F32, kNumberTypeFloat32}, -}; - -int CheckOmDataCoreInfo(const mapper::DataCoreInfo &data_core_info) { - MS_CHECK_TRUE_MSG(!data_core_info.name.empty(), RET_ERROR, "output name is empty."); - MS_CHECK_TRUE_MSG(kDataTypeMap.find(data_core_info.type) != kDataTypeMap.end(), RET_ERROR, - "unsupported data type, op data type is " << data_core_info.type); - MS_CHECK_TRUE_MSG(!data_core_info.shape.empty(), RET_ERROR, - "output shape shouldn't be empty. " << data_core_info.name); - return RET_OK; -} - -bool CheckInputCNodeSize(const api::CNodePtr &cnode, size_t *next_idx) { - int target_valid_input_size = 1; - for (size_t i = 1; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - if (api::utils::isa(cnode->input(i))) { - auto param_node = input_node->cast(); - if (param_node != nullptr && !param_node->has_default()) { // graph input - target_valid_input_size--; - } - } else if (api::utils::isa(input_node)) { - *next_idx = i; - target_valid_input_size--; - } - } - return target_valid_input_size == 0; -} - -bool IsCorrespondOutput(const api::AnfNodePtr &node, const std::string &target_name) { - if (node->fullname_with_scope() == target_name) { - return true; - } - auto cnode = node->cast(); - if (cnode == nullptr) { - MS_LOG(INFO) << "cur node isn't a cnode, will stop recursive search. " << node->fullname_with_scope(); - return false; - } - MS_CHECK_TRUE_MSG(cnode->size() >= kInputIndex2, false, - node->fullname_with_scope() << " inputs size " << cnode->size() << " is invalid."); - size_t next_idx = 1; - if (!CheckInputCNodeSize(cnode, &next_idx)) { - return false; - } else { - return IsCorrespondOutput(cnode->input(next_idx), target_name); - } -} -} // namespace - -api::CNodePtr CustomOpCreator::CreateCustomOp(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, - const ModelCoreInfoPtr &om_model_info) { - MS_CHECK_TRUE_MSG(func_graph != nullptr && subgraph != nullptr && om_model_info != nullptr, nullptr, - "obtain nullptr input parameter."); - auto om_parameter = CreateOmParameter(func_graph, om_model_info); - MS_CHECK_TRUE_MSG(om_parameter != nullptr, nullptr, "create om parameter failed."); - if (SetSubgraphInputOutputDims(subgraph, func_graph, om_model_info) != RET_OK) { - MS_LOG(ERROR) << "set subgraph input output dims failed."; - return nullptr; - } - - auto prim = api::MakeShared(); - MS_CHECK_TRUE_MSG(prim != nullptr, nullptr, "new Custom failed"); - prim->set_type("DPICO"); - - // set op inputs - auto subgraph_inputs = GetSubgraphInputs(*subgraph, func_graph); - MS_CHECK_TRUE_MSG(!subgraph_inputs.empty(), nullptr, - "get subgraph inputs failed. subgraph id is " << subgraph->graph_id); - auto custom_cnode = func_graph->NewCNode(prim, subgraph_inputs); - MS_CHECK_TRUE_MSG(custom_cnode != nullptr, nullptr, "new cnode error"); - custom_cnode->add_input(om_parameter); - - // build op outputs && replace origin subgraph with custom node - if (SetCustomOutputs(func_graph, subgraph, custom_cnode, om_model_info) != RET_OK) { - MS_LOG(ERROR) << "set supported custom op outputs failed"; - return nullptr; - } - - // set custom op names - std::string output_name; - auto output_names = api::GetValue>(custom_cnode->GetAttr(kOutputsNames)); - if (output_names.size() == 1) { - output_name = output_names.at(0); - custom_cnode->set_fullname_with_scope(kCustomName + std::to_string(custom_id_) + "_" + output_name); - } else { - output_name = output_names.at(0); - for (size_t i = 1; i < output_names.size(); ++i) { - output_name += '_' + output_names.at(i); - } - custom_cnode->set_fullname_with_scope(kCustomName + std::to_string(custom_id_) + "_" + output_name); - } - - // set attr for custom op. - if (SetCustomAttrs(*subgraph, func_graph, prim) != RET_OK) { - MS_LOG(ERROR) << "set supported custom op attrs failed"; - return nullptr; - } - ++custom_id_; - return custom_cnode; -} - -api::ParameterPtr CustomOpCreator::CreateOmParameter(const api::FuncGraphPtr &func_graph, - const ModelCoreInfoPtr &om_model_info) { - MS_CHECK_TRUE_MSG(func_graph != nullptr && om_model_info != nullptr, nullptr, "obtain nullptr input parameter."); - MS_CHECK_TRUE_MSG(om_model_info->modelSize != 0, nullptr, "om model size equals 0."); - auto om_parameter = func_graph->add_parameter(); - MS_CHECK_TRUE_MSG(om_parameter != nullptr, nullptr, "new parameter failed."); - om_parameter->set_name("DPICO_om_data"); - ShapeVector shape_vector = {static_cast(om_model_info->modelSize)}; - auto abstract_tensor = api::MakeShared(kNumberTypeUInt8, shape_vector); - MS_CHECK_TRUE_MSG(abstract_tensor != nullptr, nullptr, "abstract_tensor is nullptr."); - om_parameter->set_abstract(abstract_tensor); - - auto tensor_info = - api::MakeShared(kNumberTypeUInt8, ShapeVector({static_cast(om_model_info->modelSize)})); - MS_CHECK_TRUE_MSG(tensor_info != nullptr, nullptr, "tensor_info is nullptr."); - auto tensor_data = tensor_info->data(); - MS_CHECK_TRUE_MSG(tensor_data != nullptr, nullptr, "new api::Tensor failed."); - MS_CHECK_TRUE_MSG(tensor_info->Size() != 0, nullptr, "tensor size shouldn't be 0"); - if (om_model_info->modelBuffer == nullptr) { - MS_LOG(ERROR) << "model buffer is nullptr."; - return nullptr; - } - if (memcpy_s(tensor_data, tensor_info->Size(), om_model_info->modelBuffer, om_model_info->modelSize) != EOK) { - MS_LOG(ERROR) << "memcpy_s failed."; - return nullptr; - } - om_parameter->set_default_param(tensor_info); - - return om_parameter; -} - -STATUS CustomOpCreator::SetSubgraphInputOutputDims(Subgraph *subgraph, const api::FuncGraphPtr &func_graph, - const ModelCoreInfoPtr &om_model_info) { - MS_CHECK_TRUE_MSG(subgraph != nullptr && func_graph != nullptr && om_model_info != nullptr, RET_ERROR, - "obtain nullptr input parameter."); - auto subgraph_inputs = GetSubgraphInputs(*subgraph, func_graph); - for (const auto &input_info : om_model_info->inputInfos) { - if (CheckOmDataCoreInfo(input_info) != RET_OK) { - MS_LOG(ERROR) << "om input info is invalid."; - return RET_ERROR; - } - for (const auto &node : subgraph_inputs) { - auto in_name = RemoveSpecifiedChar(node->fullname_with_scope(), '\0'); - if (CheckPrimitiveType(node, api::MakeShared())) { - in_name = GetCustomOutputName(node); - MS_CHECK_TRUE_MSG(!in_name.empty(), RET_ERROR, - "get custom node output name failed." << node->fullname_with_scope()); - } - auto ret = GraphOutputNameKeeper::GetInstance()->DetermineOmOpOutputName(node, &in_name, true); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "determine sub-graph's input name failed."); - auto input_info_name = RemoveSpecifiedChar(input_info.name, '\0'); - if (in_name == input_info_name) { // DetectionOutput network has extra input, will filter it. - ShapeVector ori_shape_vector; - if (GetAnfNodeOutputShape(node, &ori_shape_vector)) { - MS_LOG(ERROR) << "get " << node->fullname_with_scope() << " output shape failed."; - return RET_ERROR; - } - if (ori_shape_vector.size() != input_info.shape.size()) { - MS_LOG(ERROR) << in_name << "'s input shape size " << ori_shape_vector.size() - << " is not equal to om input shape size " << input_info.shape.size(); - return RET_ERROR; - } - ShapeVector shape_vector(input_info.shape.begin(), input_info.shape.end()); - subgraph->inputs_dims.push_back(shape_vector); - break; - } - } - } - MS_CHECK_TRUE_MSG(!subgraph->inputs_dims.empty(), RET_ERROR, "subgraph input dims shouldn't be empty."); - for (const auto &output_info : om_model_info->outputInfos) { - if (CheckOmDataCoreInfo(output_info) != RET_OK) { - MS_LOG(ERROR) << "om output info is invalid."; - return RET_ERROR; - } - ShapeVector shape_vector(output_info.shape.begin(), output_info.shape.end()); - subgraph->outputs_dims.push_back(shape_vector); - } - MS_CHECK_TRUE_MSG(!subgraph->outputs_dims.empty(), RET_ERROR, "subgraph output dims shouldn't be empty."); - return RET_OK; -} - -STATUS CustomOpCreator::SetCustomAttrs(const Subgraph &subgraph, const api::FuncGraphPtr &func_graph, - const api::SharedPtr &prim) { - MS_CHECK_TRUE_MSG(func_graph != nullptr && prim != nullptr, RET_ERROR, "obtain nullptr input parameter."); - std::map> custom_attrs; - // add "input_shape " attr - std::string input_dims_attr_value_str; - for (auto &item : subgraph.inputs_dims) { - input_dims_attr_value_str += std::to_string(item.size()) + ","; - for (auto &v : item) { - input_dims_attr_value_str += std::to_string(v) + ","; - } - } - std::vector input_dims_attr_value(input_dims_attr_value_str.begin(), input_dims_attr_value_str.end()); - (void)custom_attrs.insert(std::make_pair(kInputsShape, input_dims_attr_value)); - - // add "output_shape " attr - std::string output_dims_attr_value_str; - for (auto &item : subgraph.outputs_dims) { - output_dims_attr_value_str += std::to_string(item.size()) + ","; - for (auto &v : item) { - output_dims_attr_value_str += std::to_string(v) + ","; - } - } - std::vector output_dims_attr_value(output_dims_attr_value_str.begin(), output_dims_attr_value_str.end()); - (void)custom_attrs.insert(std::make_pair(kOutputsShape, output_dims_attr_value)); - - // add "outputs_format" attr - std::string output_format_attr_str; - for (auto &item : subgraph.outputs_format) { - output_format_attr_str += std::to_string(item) + ","; - } - std::vector output_format_attr_value(output_format_attr_str.begin(), output_format_attr_str.end()); - (void)custom_attrs.insert(std::make_pair(kOutputsFormat, output_format_attr_value)); - - // add om net type attr - auto om_net_type_str = std::to_string(static_cast(subgraph.om_net_type)); - std::vector om_net_type_value(om_net_type_str.begin(), om_net_type_str.end()); - (void)custom_attrs.insert(std::make_pair(kNetType, om_net_type_value)); - - // add max_roi_fram_cnt attr - if (subgraph.om_net_type == OmNetType::kRoi) { - auto max_roi_frame_cnt_str = std::to_string(kMaxRoiFrameCnt); - std::vector max_roi_frame_cnt_value(max_roi_frame_cnt_str.begin(), max_roi_frame_cnt_str.end()); - (void)custom_attrs.insert(std::make_pair("max_roi_frame_cnt", max_roi_frame_cnt_value)); - } - - // add custom_num attr - auto custom_num_str = std::to_string(custom_num_); - std::vector custom_num_vec(custom_num_str.begin(), custom_num_str.end()); - (void)custom_attrs.insert(std::make_pair("custom_num", custom_num_vec)); - - // add custom_id attr - auto custom_id_str = std::to_string(custom_id_); - std::vector custom_id_vec(custom_id_str.begin(), custom_id_str.end()); - (void)custom_attrs.insert(std::make_pair("custom_id", custom_id_vec)); - - // add head_tail_op_is_custom attr - auto is_custom_str = std::to_string(head_tail_op_is_custom_); - std::vector head_tail_op_is_custom_vec(is_custom_str.begin(), is_custom_str.end()); - (void)custom_attrs.insert(std::make_pair("head_tail_op_is_custom", head_tail_op_is_custom_vec)); - - // add internal_stride attr - auto internal_stride = MapperConfigParser::GetInstance()->GetInternalStride(); - std::vector inter_stride_vec(internal_stride.begin(), internal_stride.end()); - (void)custom_attrs.insert(std::make_pair(kLastDimStride, inter_stride_vec)); - prim->set_attr(custom_attrs); - return RET_OK; -} - -STATUS CustomOpCreator::SetCustomOutputs(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, - const api::CNodePtr &custom_cnode, const ModelCoreInfoPtr &om_model_info) { - MS_CHECK_TRUE_MSG(subgraph != nullptr, RET_ERROR, "subgraph is nullptr."); - auto manager = func_graph->manager(); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "funcgraph manager is nullptr."); - auto subgraph_outputs = GetSubgraphOutputs(*subgraph, manager); - MS_CHECK_TRUE_MSG(subgraph->outputs_format.size() == subgraph_outputs.size(), RET_ERROR, - "subgraph's outputs_format may be empty, which should be pre-determined."); - if (om_model_info->outputInfos.size() < subgraph_outputs.size()) { - MS_LOG(ERROR) << "om output info size:" << om_model_info->outputInfos.size() - << " is less than subgraph outputs size:" << subgraph_outputs.size(); - return RET_ERROR; - } - std::vector custom_outputs_names; // used for anf exporter - MS_CHECK_TRUE_MSG(custom_outputs_names.empty(), RET_ERROR, "custom_outputs_names is not empty."); - if (om_model_info->outputInfos.size() == 1) { - if (SetCustomSingleOutput(func_graph, subgraph, custom_cnode, om_model_info, &custom_outputs_names) != RET_OK) { - MS_LOG(ERROR) << "set custom single output failed. " << custom_cnode->fullname_with_scope(); - return RET_ERROR; - } - } else { - if (SetCustomMultiOutput(func_graph, subgraph, custom_cnode, om_model_info, &custom_outputs_names) != RET_OK) { - MS_LOG(ERROR) << "set custom multi output failed. " << custom_cnode->fullname_with_scope(); - return RET_ERROR; - } - } - custom_cnode->AddAttr(kOutputsNames, api::MakeValue(custom_outputs_names)); - return RET_OK; -} - -STATUS CustomOpCreator::SetCustomSingleOutput(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, - const api::CNodePtr &custom_cnode, - const std::shared_ptr &om_model_info, - std::vector *custom_outputs_names) { - auto manager = func_graph->manager(); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "funcgraph manager is nullptr."); - auto subgraph_outputs = GetSubgraphOutputs(*subgraph, manager); - auto output_info = om_model_info->outputInfos.at(0); - if (CheckOmDataCoreInfo(output_info) != RET_OK) { - MS_LOG(ERROR) << "om output info is invalid."; - return RET_ERROR; - } - ShapeVector shape_vector(output_info.shape.begin(), output_info.shape.end()); - auto abstract_tensor = CreateTensorAbstract(shape_vector, kDataTypeMap.at(output_info.type)); - MS_CHECK_TRUE_MSG(abstract_tensor != nullptr, RET_ERROR, "abstract_tensor is nullptr."); - custom_cnode->set_abstract(abstract_tensor); - auto output_name = RemoveSpecifiedChar(output_info.name, '\0'); - custom_outputs_names->push_back(output_name); - subgraph->cnodes.clear(); - subgraph->cnodes.push_back(custom_cnode); - if (!manager->Replace(subgraph_outputs.at(0), custom_cnode)) { - MS_LOG(ERROR) << "replace node failed"; - return RET_ERROR; - } - auto image_lists = MapperConfigParser::GetInstance()->GetImageLists(); - auto origin_node_name = subgraph_outputs.at(0)->fullname_with_scope(); - if (image_lists.find(origin_node_name) != image_lists.end() && - origin_node_name != output_name) { // custom op could be a supported subgraph's input - (void)MapperConfigParser::GetInstance()->AddImageList(output_name, image_lists.at(origin_node_name)); - } - if (!GraphOutputNameKeeper::GetInstance()->CanKeepOutputNames(*custom_outputs_names)) { - converter::ConverterContext::SetGraphOutputTensorNames(std::vector{}); - } - return RET_OK; -} - -STATUS CustomOpCreator::SetCustomMultiOutput(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, - const api::CNodePtr &custom_cnode, - const std::shared_ptr &om_model_info, - std::vector *custom_outputs_names) { - auto manager = func_graph->manager(); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "funcgraph manager is nullptr."); - auto subgraph_outputs = GetSubgraphOutputs(*subgraph, manager); - MS_ASSERT(subgraph->outputs_format.size() == subgraph_outputs.size()); - MS_ASSERT(om_model_info->outputInfos.size() >= subgraph_outputs.size()); - api::AbstractBasePtrList abstract_list; - api::CNodePtrList subgraph_new_cnodes = {custom_cnode}; - auto output_formats = subgraph->outputs_format; - subgraph->outputs_format.resize(om_model_info->outputInfos.size(), static_cast(NCHW)); - size_t has_replace_num = 0; - for (size_t i = 0; i < om_model_info->outputInfos.size(); i++) { - auto output_info = om_model_info->outputInfos.at(i); - if (CheckOmDataCoreInfo(output_info) != RET_OK) { - MS_LOG(ERROR) << "om output info is invalid."; - return RET_ERROR; - } - ShapeVector shape_vector(output_info.shape.begin(), output_info.shape.end()); - auto abstract_tensor = CreateTensorAbstract(shape_vector, kDataTypeMap.at(output_info.type)); - MS_CHECK_TRUE_MSG(abstract_tensor != nullptr, RET_ERROR, "abstract_tensor is nullptr."); - (void)abstract_list.emplace_back(abstract_tensor); - auto tuple_get_item_prim_ptr = api::MakeShared(); - MS_CHECK_TRUE_MSG(tuple_get_item_prim_ptr != nullptr, RET_ERROR, "tuple_get_item_prim_ptr is nullptr."); - auto tuple_get_item_prim = NewValueNode(tuple_get_item_prim_ptr); - auto get_item_value = NewValueNode(api::MakeValue(i)); - api::AnfNodePtrList inputs{tuple_get_item_prim, custom_cnode, get_item_value}; - api::CNodePtr get_item_cnode = func_graph->NewCNode(inputs); - MS_CHECK_TRUE_MSG(get_item_cnode != nullptr, RET_ERROR, "get_item_cnode is nullptr."); - get_item_cnode->set_fullname_with_scope(custom_cnode->fullname_with_scope() + "_getitem_" + std::to_string(i)); - auto output_name = RemoveSpecifiedChar(output_info.name, '\0'); - custom_outputs_names->push_back(output_name); - subgraph_new_cnodes.push_back(get_item_cnode); - auto anf_name = GraphOutputNameKeeper::GetInstance()->GetAnfOutputNameFromOm(custom_outputs_names->at(i)); - if (has_unsupported_) { - auto ori_node_iter = std::find_if( // extra or inconsistent output will be found. - subgraph_outputs.begin(), subgraph_outputs.end(), - [anf_name](const api::AnfNodePtr &anf_node) { return IsCorrespondOutput(anf_node, anf_name); }); - if (ori_node_iter == subgraph_outputs.end()) { - continue; - } - has_replace_num++; - get_item_cnode->set_fullname_with_scope((*ori_node_iter)->fullname_with_scope()); - subgraph->outputs_format[i] = output_formats[ori_node_iter - subgraph_outputs.begin()]; - if (!manager->Replace(*ori_node_iter, get_item_cnode)) { - MS_LOG(ERROR) << "replace node failed. " << get_item_cnode->fullname_with_scope(); - return RET_ERROR; - } - continue; - } - get_item_cnode->set_fullname_with_scope(output_name); - // the whole network is not segmented - if (i < subgraph_outputs.size()) { - if (subgraph_outputs.size() < om_model_info->outputInfos.size()) { - subgraph->outputs_format[i] = output_formats[i]; - if (!manager->Replace(subgraph_outputs[i], get_item_cnode)) { - MS_LOG(ERROR) << "replace node failed. " << get_item_cnode->fullname_with_scope(); - return RET_ERROR; - } - } else { - auto ori_node_iter = std::find_if( // extra or inconsistent output will be found. - subgraph_outputs.begin(), subgraph_outputs.end(), - [anf_name](const api::AnfNodePtr &anf_node) { return IsCorrespondOutput(anf_node, anf_name); }); - if (ori_node_iter == subgraph_outputs.end()) { - continue; - } - subgraph->outputs_format[i] = output_formats[ori_node_iter - subgraph_outputs.begin()]; - if (!manager->Replace(*ori_node_iter, get_item_cnode)) { - MS_LOG(ERROR) << "replace node failed. " << get_item_cnode->fullname_with_scope(); - return RET_ERROR; - } - } - } else { - auto return_cnode = func_graph->get_return(); - if (CheckPrimitiveType(return_cnode->input(1), api::MakeShared())) { - manager->AddEdge(return_cnode->input(1), get_item_cnode); - } else { - manager->AddEdge(return_cnode, get_item_cnode); - } - } - has_replace_num++; - } - if (has_replace_num < subgraph_outputs.size()) { - MS_LOG(ERROR) << "origin outputs haven't been all replaced."; - return RET_ERROR; - } - std::vector outputDetectionName; - for (size_t i = 0; i < custom_outputs_names->size(); ++i) { - outputDetectionName.emplace_back((*custom_outputs_names)[i]); - } - if (subgraph_outputs.size() < custom_outputs_names->size()) { - converter::ConverterContext::SetGraphOutputTensorNames(outputDetectionName); - } - subgraph->cnodes = subgraph_new_cnodes; - auto abstract_tuple = api::MakeShared(abstract_list); - MS_CHECK_TRUE_MSG(abstract_tuple != nullptr, RET_ERROR, "abstract_tuple is nullptr."); - custom_cnode->set_abstract(abstract_tuple); - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.h b/mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.h deleted file mode 100644 index 2978844e..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/custom_creator.h +++ /dev/null @@ -1,67 +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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_CUSTOM_CREATOR_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_CUSTOM_CREATOR_H_ - -#include -#include -#include -#include "mindapi/ir/func_graph.h" -#include "infer/custom.h" -#include "src/graph_split_info.h" -#include "./op_enum_public.h" -#include "include/errorcode.h" - -using mindspore::lite::STATUS; -namespace mindspore { -namespace dpico { -using ModelCoreInfoPtr = std::shared_ptr; -class CustomOpCreator { - public: - explicit CustomOpCreator(int custom_id = 0, int custom_num = 1, int head_tail_op_is_custom = 0, - bool has_unsupported = false) - : custom_id_(custom_id), - custom_num_(custom_num), - head_tail_op_is_custom_(head_tail_op_is_custom), - has_unsupported_(has_unsupported) {} - int GetCustomId() const { return custom_id_; } - ~CustomOpCreator() = default; - api::CNodePtr CreateCustomOp(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, - const ModelCoreInfoPtr &om_model_info); - - private: - api::ParameterPtr CreateOmParameter(const api::FuncGraphPtr &func_graph, const ModelCoreInfoPtr &om_model_info); - STATUS SetSubgraphInputOutputDims(Subgraph *subgraph, const api::FuncGraphPtr &func_graph, - const ModelCoreInfoPtr &om_model_info); - STATUS SetCustomAttrs(const Subgraph &subgraph, const api::FuncGraphPtr &func_graph, - const api::SharedPtr &prim); - STATUS SetCustomOutputs(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, const api::CNodePtr &custom_cnode, - const ModelCoreInfoPtr &om_model_info); - STATUS SetCustomSingleOutput(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, - const api::CNodePtr &custom_cnode, const ModelCoreInfoPtr &om_model_info, - std::vector *output_names); - STATUS SetCustomMultiOutput(const api::FuncGraphPtr &func_graph, Subgraph *subgraph, - const api::CNodePtr &custom_cnode, const ModelCoreInfoPtr &om_model_info, - std::vector *output_names); - int custom_id_; - int custom_num_; - int head_tail_op_is_custom_; - bool has_unsupported_; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_CUSTOM_CREATOR_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.cc b/mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.cc deleted file mode 100644 index 3b6a4cee..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.cc +++ /dev/null @@ -1,358 +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 "src/data_preprocessor.h" -#include -#include -#include -#include -#include -#include "common/anf_util.h" -#include "common/file_util.h" -#include "common/op_enum.h" -#include "common/data_transpose_utils.h" -#include "common/string_util.h" -#include "src/mapper_config_parser.h" -#include "opencv2/opencv.hpp" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace dpico { -namespace { -const std::unordered_set kRgbInputFormats = {"BGR_PLANAR", "RGB_PLANAR", "RGB_PACKAGE", "BGR_PACKAGE"}; -const std::unordered_set kGrayInputFormats = {"RAW_RGGB", "RAW_GRBG", "RAW_GBRG", "RAW_BGGR"}; -std::vector GetImageRealPaths(const std::string &file_path) { - std::vector img_paths; - std::ifstream ifs; - if (ReadFileToIfstream(file_path, &ifs) != RET_OK) { - MS_LOG(ERROR) << "read file to ifstream failed."; - return {}; - } - size_t num_of_line = 0; - std::string raw_line; - while (getline(ifs, raw_line)) { - if (num_of_line > kMaxLineCount) { - MS_LOG(WARNING) << "the line count is exceeds the maximum range 9999."; - return img_paths; - } - num_of_line++; - if (EraseBlankSpace(&raw_line) != RET_OK) { - MS_LOG(ERROR) << "erase blank space failed. " << raw_line; - return {}; - } - if (raw_line.empty() || raw_line.at(0) == '#') { - continue; - } - auto img_path = RealPath(raw_line.c_str()); - if (img_path.empty()) { - MS_LOG(ERROR) << "cur image get realpath failed. " << raw_line; - return {}; - } else { - img_paths.push_back(img_path); - } - } - return img_paths; -} -int Normalize(cv::Mat *image, const std::map &mean, const std::map &var) { - if (image == nullptr) { - MS_LOG(ERROR) << "input image is nullptr."; - return RET_ERROR; - } - std::vector mean_vec; - std::vector var_vec; - if (image->channels() < 0) { - MS_LOG(ERROR) << "image channels should not be negative."; - return RET_ERROR; - } - size_t img_channel_size = image->channels(); - if (mean.empty()) { - mean_vec = std::vector(img_channel_size, 0.0); - } else { - if (mean.size() != img_channel_size) { - MS_LOG(ERROR) << "input mean_chn size " << mean.size() << " is not equal to image channels " << img_channel_size; - return RET_ERROR; - } - (void)std::transform(mean.begin(), mean.end(), std::back_inserter(mean_vec), - [](const std::pair &pair) { return pair.second; }); - } - if (var.empty()) { - var_vec = std::vector(img_channel_size, 0.0); - } else { - if (var.size() != img_channel_size) { - MS_LOG(ERROR) << "input var_reci_chn size " << var.size() << " is not equal to image channels " - << img_channel_size; - return RET_ERROR; - } - (void)std::transform(var.begin(), var.end(), std::back_inserter(var_vec), - [](const std::pair &pair) { return pair.second; }); - } - std::vector channels(img_channel_size); - cv::split(*image, channels); - for (size_t i = 0; i < channels.size(); i++) { - channels[i].convertTo(channels[i], CV_32FC1, var_vec.at(i), (0.0 - mean_vec.at(i)) * var_vec.at(i)); - } - cv::merge(channels, *image); - return RET_OK; -} -} // namespace - -DataPreprocessor *DataPreprocessor::GetInstance() { - static DataPreprocessor instance; - return &instance; -} - -int DataPreprocessor::ModifyDynamicInputShape(std::vector *input_shape) { - std::vector indexes; - for (size_t i = 0; i < input_shape->size(); i++) { - if (input_shape->at(i) < 0) { - indexes.push_back(i); - } - } - if (!indexes.empty()) { - if (indexes.size() == 1 && indexes.at(0) == 0) { - input_shape->at(0) = 1; - } else { - MS_LOG(ERROR) << "dynamic graph input is unsupported by dpico."; - return RET_NO_CHANGE; - } - } - return RET_OK; -} - -int DataPreprocessor::GetOutputBinDir(const std::string &op_name, std::string *output_bin_dir) { - auto folder_name = ReplaceSpecifiedChar(op_name, '/', '_'); - *output_bin_dir = preprocessed_data_dir_ + folder_name + "/"; - if (CreateDir(output_bin_dir) != RET_OK) { - MS_LOG(ERROR) << "Create directory failed. " << *output_bin_dir; - return RET_ERROR; - } - size_t count = 0; - while (AccessFile(*output_bin_dir + "/" + std::to_string(count), F_OK) == 0) { - MS_LOG(DEBUG) << "current file_path has existed, file_path cnt plus 1."; // such as: /xxx/0 ==> /xxx/1 - count++; - if (count > kMaximumNumOfFolders) { - MS_LOG(ERROR) << "the number of file folders exceeds the upper limit " << kMaximumNumOfFolders; - return RET_ERROR; - } - } - *output_bin_dir += std::to_string(count); - return RET_OK; -} - -int DataPreprocessor::WriteCvMatToBin(const cv::Mat &image, const std::string &op_name) { - std::string generated_bin_dir; - if (GetOutputBinDir(op_name, &generated_bin_dir) != RET_OK) { - MS_LOG(ERROR) << "get output bin dir failed."; - return RET_ERROR; - } - if (Mkdir(generated_bin_dir) != RET_OK) { - MS_LOG(ERROR) << "mkdir failed. " << generated_bin_dir; - return RET_ERROR; - } - std::string generated_bin_dir_realpath = lite::RealPath(generated_bin_dir.c_str()); - if (generated_bin_dir_realpath.empty()) { - MS_LOG(ERROR) << "Invalid realpath!"; - return RET_ERROR; - } - std::string output_bin_path = generated_bin_dir_realpath + "/input.bin"; - std::ofstream ofs; - ofs.open(output_bin_path, std::ios::binary); - if (!ofs.good() || !ofs.is_open()) { - MS_LOG(ERROR) << "open output bin file failed. " << output_bin_path; - return RET_ERROR; - } - for (int i = 0; i < image.rows; i++) { - (void)ofs.write(reinterpret_cast(image.ptr(i)), static_cast(image.cols) * image.elemSize()); - } - ofs.close(); - return RET_OK; -} - -int DataPreprocessor::GenerateInputBinFromTxt(const std::string &raw_data_path, const std::string &op_name, - const std::vector &op_shape, TypeId type_id) { - if (op_shape.empty()) { - MS_LOG(ERROR) << "op shape shouldn't be empty."; - return RET_ERROR; - } - std::ifstream ifs; - if (ReadFileToIfstream(raw_data_path, &ifs) != RET_OK) { - MS_LOG(ERROR) << "read file to ifstream failed."; - return RET_ERROR; - } - std::string raw_line; - batch_size_ = 0; - while (getline(ifs, raw_line)) { - if (batch_size_ > kMaxLineCount) { - MS_LOG(WARNING) << "the line count is exceeds the maximum range 9999."; - return RET_ERROR; - } - batch_size_++; - auto preprocessed_line = ReplaceSpecifiedChar(raw_line, ',', ' '); // uniformly separated by spaces - if (EraseHeadTailSpace(&preprocessed_line) != RET_OK) { - MS_LOG(ERROR) << "erase head & tail blank space failed. " << preprocessed_line; - return RET_ERROR; - } - if (preprocessed_line.empty() || preprocessed_line.at(0) == '#') { - continue; - } - int status; - switch (type_id) { - case kNumberTypeFloat: - case kNumberTypeFloat32: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - case kNumberTypeInt8: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - case kNumberTypeUInt8: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - case kNumberTypeInt16: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - case kNumberTypeUInt16: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - case kNumberTypeInt: - case kNumberTypeInt32: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - case kNumberTypeInt64: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - case kNumberTypeUInt64: - status = GenerateInputBin(preprocessed_line, op_shape, op_name); - break; - default: - MS_LOG(ERROR) << "unsupported data type " << dpico::TypeIdToString(type_id); - status = RET_ERROR; - } - if (status != RET_OK) { - MS_LOG(ERROR) << "generate input bin files failed."; - return RET_ERROR; - } - } - return RET_OK; -} -int DataPreprocessor::GenerateInputBinFromImages(const std::string &raw_data_path, const std::string &op_name, - const std::vector &op_shape, - const struct AippModule &aipp_module) { - auto img_paths = GetImageRealPaths(raw_data_path); - if (img_paths.empty()) { - MS_LOG(ERROR) << "[image_list] corresponding file is invalid. " << raw_data_path; - return RET_ERROR; - } - batch_size_ = img_paths.size(); - - if (op_shape.size() != kDims4) { - MS_LOG(ERROR) << "op shape should be 4 when input is image."; - return RET_ERROR; - } - for (const auto &img_path : img_paths) { // preprocess input image - cv::Mat image; - if (kRgbInputFormats.find(aipp_module.input_format) != kRgbInputFormats.end()) { - image = cv::imread(img_path, static_cast(cv::IMREAD_COLOR)); - } else if (kGrayInputFormats.find(aipp_module.input_format) != kGrayInputFormats.end()) { - image = cv::imread(img_path, static_cast(cv::IMREAD_GRAYSCALE)); - } - if (image.empty() || image.data == nullptr) { - MS_LOG(ERROR) << "missing file, improper permissions, unsupported or invalid format."; - return RET_ERROR; - } - if (aipp_module.model_format == "RGB") { - cv::cvtColor(image, image, static_cast(cv::COLOR_BGR2RGB)); - } - if (image.cols != op_shape[kAxis3] || image.rows != op_shape[kAxis2]) { - MS_LOG(INFO) << "input image shape don't match op shape, and it will be resized."; - cv::resize(image, image, cv::Size(op_shape[kAxis3], op_shape[kAxis2])); - } - - if (Normalize(&image, aipp_module.mean_map, aipp_module.val_map) != RET_OK) { - MS_LOG(ERROR) << "image normalize process failed."; - return RET_ERROR; - } - - if (WriteCvMatToBin(image, op_name) != RET_OK) { - MS_LOG(ERROR) << "write image to bin file failed." << op_name; - return RET_ERROR; - } - } - return RET_OK; -} -int DataPreprocessor::Run(const api::AnfNodePtrList &inputs) { - if (inputs.empty()) { - MS_LOG(ERROR) << "graph inputs shouldn't be empty."; - return RET_ERROR; - } - auto image_lists = MapperConfigParser::GetInstance()->GetImageLists(); - auto aipp_modules = MapperConfigParser::GetInstance()->GetAippModules(); - - for (const auto &input : inputs) { - auto op_name = input->fullname_with_scope(); - if (image_lists.find(op_name) == image_lists.end()) { - MS_LOG(ERROR) << "current op don't exist in image_lists. " << op_name; - return RET_ERROR; - } - auto param_node = input->cast(); - if (param_node == nullptr) { - MS_LOG(ERROR) << "graph input node should be parameter ptr. " << input->fullname_with_scope(); - return RET_ERROR; - } - auto abstract_base = param_node->abstract(); - if (abstract_base == nullptr) { - MS_LOG(ERROR) << "Abstract of parameter is nullptr, " << param_node->name(); - return lite::RET_PARAM_INVALID; - } - - ShapeVector op_shape; - if (FetchShapeFromAbstract(abstract_base, &op_shape) != RET_OK) { - MS_LOG(ERROR) << "get shape vector from graph input failed. " << op_name; - return RET_ERROR; - } - if (op_shape.empty()) { - MS_LOG(ERROR) << "shape is empty." << op_name; - return RET_ERROR; - } - if (ModifyDynamicInputShape(&op_shape) != RET_OK) { - MS_LOG(ERROR) << "modify dynamic input shape failed. " << op_name; - return RET_ERROR; - } - - TypeId op_type; - if (FetchTypeIdFromAbstract(abstract_base, &op_type) != RET_OK) { - MS_LOG(ERROR) << "get type id from graph input failed. " << op_name; - return RET_ERROR; - } - - auto raw_data_path = image_lists.at(op_name); - preprocessed_data_dir_ = MapperConfigParser::GetInstance()->GetOutputPath() + "preprocessed_data/"; - if (aipp_modules.find(op_name) == aipp_modules.end()) { - if (GenerateInputBinFromTxt(raw_data_path, op_name, op_shape, op_type) != RET_OK) { - MS_LOG(ERROR) << "generate input bin from txt failed."; - return RET_ERROR; - } - } else { - if (GenerateInputBinFromImages(raw_data_path, op_name, op_shape, aipp_modules.at(op_name)) != RET_OK) { - MS_LOG(ERROR) << "generate input bin from images failed."; - return RET_ERROR; - } - } - } - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.h b/mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.h deleted file mode 100644 index 159c1586..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/data_preprocessor.h +++ /dev/null @@ -1,139 +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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DATA_PREPROCESSOR_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DATA_PREPROCESSOR_H_ - -#include -#include -#include -#include -#include -#include "common/file_util.h" -#include "common/data_transpose_utils.h" -#include "include/errorcode.h" -#include "common/op_enum.h" -#include "mindapi/base/type_id.h" -#include "mindapi/ir/anf.h" -#include "src/mapper_config_parser.h" -#include "opencv2/core/mat.hpp" -#include "common/check_base.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace dpico { -class DataPreprocessor { - public: - static DataPreprocessor *GetInstance(); - int Run(const api::AnfNodePtrList &inputs); - const std::string &GetPreprocessedDataDir() const { return preprocessed_data_dir_; } - size_t GetBatchSize() const { return batch_size_; } - - private: - DataPreprocessor() = default; - ~DataPreprocessor() = default; - int ModifyDynamicInputShape(std::vector *input_shape); - int GetOutputBinDir(const std::string &op_name, std::string *output_bin_dir); - int WriteCvMatToBin(const cv::Mat &image, const std::string &op_name); - int GenerateInputBinFromTxt(const std::string &raw_data_path, const std::string &op_name, - const std::vector &op_shape, TypeId type_id); - int GenerateInputBinFromImages(const std::string &raw_data_path, const std::string &op_name, - const std::vector &op_shape, const struct AippModule &aipp_module); - - template - int WriteVectorToBin(std::vector *nums, const std::string &op_name) { - if (nums == nullptr) { - MS_LOG(ERROR) << "input vector is nullptr."; - return RET_ERROR; - } - std::string generated_bin_dir; - if (GetOutputBinDir(op_name, &generated_bin_dir) != RET_OK) { - MS_LOG(ERROR) << "get output bin dir failed."; - return RET_ERROR; - } - if (Mkdir(generated_bin_dir) != RET_OK) { - MS_LOG(ERROR) << "mkdir failed. " << generated_bin_dir; - return RET_ERROR; - } - std::string output_bin_path = generated_bin_dir + "/input.bin"; - if (WriteToBin(output_bin_path, reinterpret_cast(nums->data()), nums->size() * sizeof(T)) != RET_OK) { - MS_LOG(ERROR) << "write to bin failed."; - return RET_ERROR; - } - return RET_OK; - } - - template - int GenerateInputBin(const std::string &preprocessed_line, const std::vector &op_shape, - const std::string &op_name) { - size_t shape_size = 1; - for (size_t i = 0; i < op_shape.size(); i++) { - if (op_shape.at(i) < 0) { - MS_LOG(ERROR) << "dim val should be equal or greater than 0"; - return RET_ERROR; - } - if (SIZE_MUL_OVERFLOW(shape_size, static_cast(op_shape.at(i)))) { - MS_LOG(ERROR) << "size_t mul overflow."; - return RET_ERROR; - } - shape_size *= static_cast(op_shape.at(i)); - } - std::stringstream ss(preprocessed_line); - std::vector nums; - U num; - while (ss >> num) { - (void)nums.emplace_back(num); - } - if (nums.size() != shape_size) { - MS_LOG(ERROR) << op_name << "'s input size " << nums.size() << " is not equal to origin input shape size " - << shape_size; - return RET_ERROR; - } - if (op_shape.size() < kDims4) { - MS_LOG(WARNING) << op_name << "'s input shape is " << op_shape.size() - << " dims, and its data will not be transposed."; - if (WriteVectorToBin(&nums, op_name) != RET_OK) { - MS_LOG(ERROR) << "write vector to bin failed."; - return RET_ERROR; - } - } else if (op_shape.size() == kDims4) { - std::vector nhwc_nums(nums.size()); - std::vector shape; - (void)std::transform(op_shape.begin(), op_shape.end(), std::back_inserter(shape), - [](const int64_t dim) { return static_cast(dim); }); - if (NCHW2NHWC(nums.data(), nhwc_nums.data(), shape) != RET_OK) { - MS_LOG(ERROR) << "nchw to nhwc failed. " << op_name; - return RET_ERROR; - } - if (WriteVectorToBin(&nhwc_nums, op_name) != RET_OK) { - MS_LOG(ERROR) << "write vector to bin failed."; - return RET_ERROR; - } - } else { - MS_LOG(ERROR) << op_name << "'s input shape is " << op_shape.size() << " dims, which is not supported for now."; - return RET_ERROR; - } - return RET_OK; - } - - std::string preprocessed_data_dir_; - size_t batch_size_{0}; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DATA_PREPROCESSOR_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.cc b/mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.cc deleted file mode 100644 index a36f1025..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.cc +++ /dev/null @@ -1,564 +0,0 @@ -/** - * Copyright 2021-2022 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 "src/dpico_pass.h" -#include -#include -#include -#include -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "infer/return.h" -#include "infer/depend.h" -#include "common/format_utils.h" -#include "common/file_util.h" -#include "common/anf_util.h" -#include "common/string_util.h" -#include "common/op_attr.h" -#include "common/graph_output_name_keeper.h" -#include "checker/op_checker.h" -#include "src/om_generator.h" -#include "include/registry/pass_registry.h" -#include "src/data_preprocessor.h" -#include "src/mapper_config_parser.h" -#include "src/calib_data_generator.h" -#include "src/custom_creator.h" -#include "mindspore/core/include/ir/graph_utils.h" - -namespace mindspore { -namespace dpico { -namespace { -const size_t kMinimumNumbOfSegments = 1; -bool CheckInputDimSize(const api::CNodePtr &cnode) { - for (size_t i = 0; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - if (!api::utils::isa(input_node) && - (input_node->cast() == nullptr || input_node->cast()->has_default())) { - continue; - } - ShapeVector shape_vector; - if (GetInputShapeFromCNode(cnode, i, &shape_vector) == RET_OK) { - if (shape_vector.size() < 1 || shape_vector.size() > kDims4) { - MS_LOG(DEBUG) << cnode->fullname_with_scope() << " input:" << i << " 's input shape size " - << shape_vector.size() << " should be in range [1, 4]."; - return false; - } - if (shape_vector.size() == 1 && shape_vector.front() > 1) { - MS_LOG(ERROR) << "When input dim is 1, batch size can't be more than 1"; - return false; - } - } - } - return true; -} - -bool CheckOpHasInferred(const api::CNodePtr &cnode) { - MS_ASSERT(cnode != nullptr); - if (GetBoolAttr(cnode, kInferDone)) { - return true; - } - if (!CheckPrimitiveType(cnode, api::MakeShared())) { - return false; - } - auto abstract = cnode->abstract(); - MS_CHECK_TRUE_MSG(abstract != nullptr, false, "abstract is nullptr."); - ShapeVector shape; - if (FetchShapeFromAbstract(abstract, &shape) != lite::RET_OK) { - return false; - } - return !shape.empty() && std::all_of(shape.begin(), shape.end(), [](int64_t dim) { return dim > 0; }); -} - -STATUS AddDumpKernels(const api::FuncGraphPtr &func_graph, const Subgraph &subgraph, api::AnfNodePtrList *dump_kernels, - std::map> *param_to_cnode, - std::map *input_fomat_infos) { - MS_ASSERT(func_graph != nullptr && dump_kernels != nullptr && param_to_cnode != nullptr); - auto subgraph_inputs = GetSubgraphInputs(subgraph, func_graph); - MS_CHECK_TRUE_MSG(!subgraph_inputs.empty(), RET_ERROR, - "get subgraph inputs failed. subgraph id is " << subgraph.graph_id); - (void)dump_kernels->insert(dump_kernels->end(), subgraph_inputs.begin(), subgraph_inputs.end()); - for (auto &input_node : subgraph_inputs) { - if (input_node == nullptr) { - continue; - } - auto input_cnode = input_node->cast(); - if (input_cnode == nullptr) { - continue; - } - (*input_fomat_infos)[input_node->fullname_with_scope()] = 0; - for (const auto &inner_cnode : subgraph.cnodes) { - if (inner_cnode == nullptr) { - MS_LOG(ERROR) << "inner is nullptr."; - return RET_ERROR; - } - auto cnode_inputs = inner_cnode->inputs(); - auto iter = std::find(cnode_inputs.begin(), cnode_inputs.end(), input_node); - if (iter == cnode_inputs.end()) { - continue; - } - - auto inner_prim = api::GetValueNode(inner_cnode->input(0)); - MS_CHECK_TRUE_MSG(inner_prim != nullptr, RET_ERROR, "inner_prim primitive is nullptr."); - auto value_ptr = inner_prim->GetAttr(ops::kFormat); - if (value_ptr == nullptr) { - MS_LOG(ERROR) << "value_ptr is nullptr."; - return RET_ERROR; - } - auto value = api::GetValue(value_ptr); - MS_CHECK_TRUE_MSG(value >= NCHW && value <= NCW, RET_ERROR, "format val is out of enum's range."); - auto input_format = static_cast(value); - MS_LOG(DEBUG) << "subgraph next node name " << inner_cnode->fullname_with_scope() - << " inputformat = " << input_format; - (*input_fomat_infos)[input_node->fullname_with_scope()] = input_format; - } - } - bool is_main_graph = - func_graph->get_attr(kIsMainGraph) != nullptr && api::GetValue(func_graph->get_attr(kIsMainGraph)); - if (is_main_graph) { - return RET_OK; - } - for (const auto &node : subgraph_inputs) { - if (!api::utils::isa(node)) { - continue; - } - if (param_to_cnode->find(node) != param_to_cnode->end()) { - continue; - } - for (const auto &inner_cnode : subgraph.cnodes) { - MS_CHECK_TRUE_MSG(api::utils::isa(inner_cnode), RET_ERROR, "inner cnode is nullptr."); - auto cnode_inputs = inner_cnode->inputs(); - auto iter = std::find(cnode_inputs.begin(), cnode_inputs.end(), node); - if (iter == cnode_inputs.end()) { - continue; - } - (void)param_to_cnode->emplace(node, std::make_pair(inner_cnode, iter - cnode_inputs.begin() - 1)); - } - } - return RET_OK; -} -STATUS ModifyGraphInputDataType(const Subgraph &subgraph, const api::FuncGraphPtr &func_graph, - const std::shared_ptr &om_model_info) { - auto subgraph_inputs = GetSubgraphInputs(subgraph, func_graph); - for (size_t i = 0; i < subgraph_inputs.size(); i++) { - auto input = subgraph_inputs.at(i); - auto input_node_name = input->fullname_with_scope(); - auto param = input->cast(); - if (param != nullptr && !param->has_default()) { // only for graph input parameter node - auto param_abstract = param->abstract(); - MS_CHECK_TRUE_MSG(param_abstract != nullptr, RET_ERROR, "param_abstract is nullptr"); - auto abstractScalar = param_abstract->cast(); - MS_CHECK_TRUE_MSG(abstractScalar != nullptr, RET_ERROR, "abstractScalar is nullptr"); - auto element = abstractScalar->element(); - MS_CHECK_TRUE_MSG(element != nullptr, RET_ERROR, "element is nullptr"); - auto correspond_info_iter = std::find_if(om_model_info->inputInfos.begin(), om_model_info->inputInfos.end(), - [input_node_name](const mapper::DataCoreInfo &data_core_info) { - auto om_input_name = RemoveSpecifiedChar(data_core_info.name, '\0'); - return om_input_name == input_node_name; - }); - MS_CHECK_TRUE_MSG(correspond_info_iter != om_model_info->inputInfos.end(), RET_ERROR, - "can't find \"" << input_node_name << "\" in om model input infos."); - switch (correspond_info_iter->type) { - case mapper::OpDataType::OP_DTYPE_S8: - element->set_type(api::Type::GetType(kNumberTypeInt8)); - break; - case mapper::OpDataType::OP_DTYPE_U8: - element->set_type(api::Type::GetType(kNumberTypeUInt8)); - break; - case mapper::OpDataType::OP_DTYPE_S16: - element->set_type(api::Type::GetType(kNumberTypeInt16)); - break; - case mapper::OpDataType::OP_DTYPE_U16: - element->set_type(api::Type::GetType(kNumberTypeUInt16)); - break; - case mapper::OpDataType::OP_DTYPE_F32: - element->set_type(api::Type::GetType(kNumberTypeFloat32)); - break; - default: - MS_LOG(ERROR) << "current op type is unsupported. " << om_model_info->inputInfos.at(i).type; - return RET_ERROR; - } - } - } - return RET_OK; -} -#ifdef Debug -void PrintUnsupportedOps(const std::map> &unsupported_ops, - size_t unsupported_ops_size, const api::FuncGraphPtr &func_graph) { - if (!unsupported_ops.empty()) { - if (func_graph->get_attr(kGraphName) != nullptr) { - auto func_graph_name = api::GetValue(func_graph->get_attr(kGraphName)); - MS_LOG(WARNING) << "func_graph: " << func_graph_name; - } - MS_LOG(WARNING) << "there are " << unsupported_ops_size << " unsupported ops in this net."; - for (auto &unsupported_op : unsupported_ops) { - MS_LOG(WARNING) << "type: " << unsupported_op.first - << " op_nums: " << std::to_string(unsupported_op.second.size()); - auto type_name_and_op_names = std::accumulate( - unsupported_op.second.begin(), unsupported_op.second.end(), std::string{}, - [](const std::string &cur_str, const std::string &op_name) { return cur_str + " |" + op_name; }); - MS_LOG(WARNING) << type_name_and_op_names; - } - } -} -#endif -} // namespace -STATUS DpicoPass::InitDpicoConfigInfo() { - dpico_config_path_ = "./dpico.cfg"; - bool use_default_config = true; - auto config_info = converter::ConverterContext::GetConfigInfo("dpico"); - if (!config_info.empty()) { - if (config_info.find("dpico_config_path") != config_info.end()) { - dpico_config_path_ = config_info.at("dpico_config_path"); - use_default_config = false; - } - if (config_info.find("save_temporary_files") != config_info.end()) { - auto save_temp_file_str = config_info.at("save_temporary_files"); - if (save_temp_file_str == "on") { - save_tmp_files_ = true; - } else if (save_temp_file_str == "off") { - save_tmp_files_ = false; - } else { - MS_LOG(WARNING) << "invalid [save_temporary_files] value, will consider it as off."; - save_tmp_files_ = false; - } - } - } - if (use_default_config) { - MS_LOG(WARNING) - << R"(there is no "dpico_config_path" in the converter config file, will use the default value: "./dpico.cfg")"; - } - dpico_config_path_ = RealPath(dpico_config_path_.c_str()); - if (dpico_config_path_.empty()) { - MS_LOG(ERROR) << "dpico_config_path: " << dpico_config_path_ << " is invalid"; - return RET_ERROR; - } - if (AccessFile(dpico_config_path_, F_OK) != 0) { - MS_LOG(ERROR) << "File not exist: " << dpico_config_path_; - return RET_ERROR; - } - return RET_OK; -} - -void DpicoPass::FetchFuncGraphs(const api::FuncGraphPtr &func_graph) { - if (std::find(func_graphs_.begin(), func_graphs_.end(), func_graph) == func_graphs_.end()) { - func_graphs_.push_back(func_graph); - } else { - return; - } - auto node_list = api::FuncGraph::TopoSort(func_graph->get_return()); - for (auto &node : node_list) { - auto fg = api::GetValueNode(node); - if (fg != nullptr) { - FetchFuncGraphs(fg); - } - } -} - -STATUS DpicoPass::CheckDynamicInputShape(const api::FuncGraphPtr &func_graph) { - MS_ASSERT(func_graph != nullptr); - auto graph_inputs = func_graph->get_inputs(); - for (const auto &node : graph_inputs) { - auto graph_input = node->cast(); - MS_CHECK_TRUE_MSG(graph_input != nullptr, RET_ERROR, "graph_input is nullptr."); - ShapeVector shape_vector; - if (GetShapeVectorFromParameter(graph_input, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "get shape vector failed. " << graph_input->fullname_with_scope(); - return RET_ERROR; - } - std::vector indexes; - for (size_t i = 0; i < shape_vector.size(); i++) { - if (shape_vector.at(i) < 0) { - indexes.push_back(i); - } - } - if (!indexes.empty()) { - MS_LOG(WARNING) << "dynamic graph input is unsupported by dpico."; - return RET_NO_CHANGE; - } - } - - return RET_OK; -} - -STATUS DpicoPass::MarkNodes(const api::FuncGraphPtr &func_graph) { - MS_CHECK_TRUE_MSG(func_graph != nullptr, RET_ERROR, "func_graph is nullptr."); - auto manager = api::FuncGraphManager::Manage(func_graph, true); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "manager is nullptr."); - auto node_list = api::FuncGraph::TopoSort(func_graph->get_return()); - std::map> unsupported_ops; - size_t unsupported_ops_size = 0; - for (auto &node : node_list) { - auto cnode = node->cast(); - if (cnode == nullptr) { - continue; - } - auto primitive = api::GetValueNode(cnode->input(0)); - MS_CHECK_TRUE_MSG(primitive != nullptr, RET_ERROR, "primitive is nullptr:" << cnode->fullname_with_scope()); - std::string op_type_name; - if (GetPrimitiveType(cnode, &op_type_name) != RET_OK) { - MS_LOG(ERROR) << "get cnode primitive type failed:" << cnode->fullname_with_scope(); - return RET_ERROR; - } - - // mark nodes - bool is_supported = false; - if (IsSpecialType(cnode)) { - auto cnode_inputs = cnode->inputs(); - is_supported = CheckPrimitiveType(cnode, api::MakeShared()) || - CheckPrimitiveType(cnode, api::MakeShared()) - ? false - : std::all_of(cnode_inputs.begin(), cnode_inputs.end(), [](const api::AnfNodePtr &node) { - return !api::utils::isa(node) || GetBoolAttr(node, kIsMapperSupported); - }); - } else { - auto op_checker = OpCheckerRegistry::GetInstance()->GetOpChecker(op_type_name); - if (op_checker != nullptr) { - auto node_users = manager->GetUsers(cnode); - is_supported = CheckInputDimSize(cnode) && - op_checker->Check(cnode, static_cast(node_users.size()), mindspore::Format::NCHW); - } - is_supported = is_supported && CheckOpHasInferred(cnode); - is_supported = is_supported && (CheckPrimitiveType(cnode, api::MakeShared()) - ? api::utils::isa(cnode->input(1)) && - GetBoolAttr(cnode->input(1), kIsMapperSupported) - : true); - } - if (!is_supported && !CheckPrimitiveType(cnode, api::MakeShared())) { - unsupported_ops[op_type_name].push_back(cnode->fullname_with_scope()); - unsupported_ops_size++; - } - (void)primitive->AddAttr(kIsMapperSupported, api::MakeValue(is_supported)); - } -#ifdef Debug - PrintUnsupportedOps(unsupported_ops, unsupported_ops_size, func_graph); -#endif - return RET_OK; -} - -STATUS DpicoPass::ParseMapperConfig(const api::FuncGraphPtr &func_graph) { - if (graph_split_info_.num_of_segments < kMinimumNumbOfSegments) { // no segment - MapperConfigParser::GetInstance()->SetOriginConfigFilePath(dpico_config_path_); - } - - std::vector graph_input_names; - auto inputs = func_graph->get_inputs(); - (void)std::transform(inputs.begin(), inputs.end(), std::back_inserter(graph_input_names), - [](const api::AnfNodePtr &anode) { return anode->fullname_with_scope(); }); - - if (MapperConfigParser::GetInstance()->Parse(dpico_config_path_, graph_input_names) != RET_OK) { - MS_LOG(ERROR) << "parse mapper config file failed."; - return RET_ERROR; - } - - return RET_OK; -} - -STATUS DpicoPass::DataPrepare(const api::FuncGraphPtr &func_graph, bool *use_origin_config) { - MS_CHECK_TRUE_MSG(func_graph != nullptr && use_origin_config != nullptr, RET_ERROR, - "obtain nullptr input parameter."); - auto graph_inputs = func_graph->get_inputs(); - auto mapper_config = MapperConfigParser::GetInstance()->GetCommonConfig(); - if (graph_split_info_.num_of_segments >= kMinimumNumbOfSegments && - mapper_config.find(kImageList) != mapper_config.end()) { - MS_LOG(WARNING) << "there are unsupported npu operators in this model, and it's going to generate calib set."; - if (DataPreprocessor::GetInstance()->Run(graph_inputs) != RET_OK) { - MS_LOG(ERROR) << "input data preprocess failed."; - return RET_ERROR; - } - - api::AnfNodePtrList dump_kernels; - std::map input_fomat_infos; - std::map> param_to_cnode; - for (auto &graph : func_graphs_) { - for (auto &subgraph : graph_split_info_.subgraphs_map[graph]) { - if (!subgraph.is_supported) { - continue; - } - // reset GraphOutputNameKeeper - GraphOutputNameKeeper::GetInstance()->ResetOutputNameMapper(); - if (AddDumpKernels(graph, subgraph, &dump_kernels, ¶m_to_cnode, &input_fomat_infos) != RET_OK) { - MS_LOG(ERROR) << "add dump kernels failed."; - return RET_ERROR; - } - } - } - if (param_to_cnode.empty() && - std::all_of(dump_kernels.begin(), dump_kernels.end(), - [](const api::AnfNodePtr &node) { return api::utils::isa(node); })) { - MS_LOG(DEBUG) << "required tensors are all graph inputs, which do not need to dump data."; - return RET_OK; - } - int dump_level = static_cast(param_to_cnode.empty() ? kDumpOutput : kDumpInputOutput); - auto calib_data_generator = std::make_shared(dump_level, param_to_cnode); - MS_CHECK_TRUE_MSG(calib_data_generator != nullptr, RET_ERROR, "new calib generator failed."); - if (calib_data_generator->Run(graph_inputs, dump_kernels, input_fomat_infos) != RET_OK && - mapper_config.find(kGfpqParamFile) == mapper_config.end()) { - MS_LOG(ERROR) << "generate calib data failed."; - return RET_ERROR; - } - *use_origin_config = false; - } - return RET_OK; -} - -STATUS DpicoPass::ReplaceSubgraphWithCustom(const api::FuncGraphPtr &func_graph, bool use_origin_config) { - MS_CHECK_TRUE_MSG(func_graph != nullptr, RET_ERROR, "func_graph is nullptr."); - auto manager = api::FuncGraphManager::Manage(func_graph, true); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "manager is nullptr."); - for (auto &subgraph : graph_split_info_.subgraphs_map[func_graph]) { - if (!subgraph.is_supported) { - continue; - } - // pre fill subgraph's outputs_format info, so that the replaced custom op do not need to consider. - if (FillSubgraphOutputsFormat(&subgraph, func_graph) != RET_OK) { - MS_LOG(ERROR) << "fill subgraph's outputs_format info failed."; - return RET_ERROR; - } - } - for (auto &subgraph : graph_split_info_.subgraphs_map[func_graph]) { - if (!subgraph.is_supported) { - continue; - } - // transform subgraph to om - auto om_generator = std::make_shared(); - MS_CHECK_TRUE_MSG(om_generator != nullptr, RET_ERROR, "OmGenerator is nullptr."); - auto om_model_info = std::make_shared(); - MS_CHECK_TRUE_MSG(om_model_info != nullptr, RET_ERROR, "ModelCoreInfo is nullptr."); - MS_CHECK_TRUE_MSG(custom_op_creator_ != nullptr, RET_ERROR, "custom_op_creator_ is nullptr."); - if (om_generator->Run(func_graph, subgraph, custom_op_creator_->GetCustomId(), om_model_info.get(), - use_origin_config) != RET_OK) { - MS_LOG(ERROR) << "current subgraph generate om failed."; - return RET_ERROR; - } - MS_CHECK_TRUE_MSG(WriteOmBufferToFile(om_model_info, custom_op_creator_->GetCustomId()) == RET_OK, RET_ERROR, - "save om file failed. custom id is " << custom_op_creator_->GetCustomId()); - auto custom_cnode = custom_op_creator_->CreateCustomOp(func_graph, &subgraph, om_model_info); - MS_CHECK_TRUE_MSG(custom_cnode != nullptr, RET_ERROR, "custom_cnode is nullptr."); - if (ModifyGraphInputDataType(subgraph, func_graph, om_model_info) != RET_OK) { - MS_LOG(ERROR) << "modify graph input data type failed"; - return RET_ERROR; - } - } - return RET_OK; -} -STATUS DpicoPass::WriteOmBufferToFile(const std::shared_ptr &om_model_info, size_t custom_id) { - if (!save_tmp_files_) { - MS_LOG(DEBUG) << "om file will not be generated."; - return RET_OK; - } - auto tmp_file_path = MapperConfigParser::GetInstance()->GetOutputPath(); - if (tmp_file_path.empty()) { - auto dir_pos = dpico_config_path_.find_last_of('/'); - tmp_file_path = dpico_config_path_.substr(0, dir_pos + 1) + "tmp/"; - if (AccessFile(tmp_file_path, F_OK) == 0) { - MS_CHECK_TRUE_MSG(RemoveDir(tmp_file_path) == RET_OK, RET_ERROR, "rm dir failed. " << tmp_file_path); - } - MS_CHECK_TRUE_MSG(CreateDir(&tmp_file_path) == RET_OK, RET_ERROR, "create dir failed. " << tmp_file_path); - } - std::string output_om_path = tmp_file_path + "custom_" + std::to_string(custom_id) + ".om"; - MS_CHECK_TRUE_MSG(WriteToBin(output_om_path, om_model_info->modelBuffer, om_model_info->modelSize) == RET_OK, - RET_ERROR, "write om to file failed."); - return RET_OK; -} - -STATUS DpicoPass::RemoveTemporaryFiles() { - if (save_tmp_files_) { - MS_LOG(DEBUG) << "temporary files will not be removed."; - return RET_OK; - } - auto tmp_file_path = MapperConfigParser::GetInstance()->GetOutputPath(); - if (tmp_file_path.empty()) { - MS_LOG(DEBUG) << "there is no temporary file, no need to remove."; - return RET_OK; - } - if (RemoveDir(tmp_file_path) != RET_OK) { - MS_LOG(ERROR) << "remove temp files failed."; - return RET_ERROR; - } - return RET_OK; -} - -bool DpicoPass::Execute(const api::FuncGraphPtr &func_graph) { - MS_CHECK_TRUE_MSG(func_graph != nullptr, false, "func_graph is nullptr."); - func_graph->set_attr(kIsMainGraph, api::MakeValue(true)); - FetchFuncGraphs(func_graph); - auto status = CheckDynamicInputShape(func_graph); - if (status == RET_NO_CHANGE) { - MS_LOG(WARNING) << "Dynamic input shape is unsupported by dpico. All nodes will be CPU operator. " - << "Or, you can set the \"inputShape\" when converting."; - return true; - } else if (status != RET_OK) { - MS_LOG(ERROR) << "check dynamic graph input failed."; - return false; - } - - if (InitDpicoConfigInfo() != RET_OK) { - MS_LOG(ERROR) << "get dpico config info from converter context failed."; - return false; - } - status = GraphOutputNameKeeper::GetInstance()->SaveOriginalOutputs(func_graph); - MS_CHECK_TRUE_MSG(status == RET_OK, false, "save outputs node failed."); - for (auto &graph : func_graphs_) { - if (MarkNodes(graph) != RET_OK) { - MS_LOG(ERROR) << "mark graph nodes failed."; - return false; - } - } - - if (GraphSplit(func_graphs_, &graph_split_info_) != RET_OK) { - MS_LOG(ERROR) << "split subgraphs failed."; - return false; - } - - if (ParseMapperConfig(func_graph) != RET_OK) { - MS_LOG(ERROR) << "parse mapper config failed."; - return false; - } - - bool use_origin_config = true; - if (DataPrepare(func_graph, &use_origin_config) != RET_OK) { - MS_LOG(ERROR) << "prepare data for mapper failed."; - return false; - } - - bool has_unsupported = graph_split_info_.num_of_segments >= kMinimumNumbOfSegments; - custom_op_creator_ = std::make_shared(0, graph_split_info_.num_of_custom_op, - graph_split_info_.head_tail_op_is_custom, has_unsupported); - MS_CHECK_TRUE_MSG(custom_op_creator_ != nullptr, false, "make a custom op creator failed."); - for (auto &graph : func_graphs_) { - if (ReplaceSubgraphWithCustom(graph, use_origin_config) != RET_OK) { - MS_LOG(ERROR) << "replace subgraph with custom node failed."; - return false; - } - } - if (RemoveTemporaryFiles() != RET_OK) { - MS_LOG(ERROR) << "remove temporarily generated files failed."; - return false; - } - GraphOutputNameKeeper::GetInstance()->RecycleResource(); - return true; -} -REG_PASS(DpicoPass, dpico::DpicoPass) -} // namespace dpico -} // namespace mindspore -namespace mindspore::registry { -const std::vector schedule_pipe = {"ConstFoldPass", "ToNCHWFormat", "DpicoPreprocessPass", - "DecreaseTransposeAlgo", "DumpGraph", "DpicoPass", - "ToNHWCFormat"}; -REG_SCHEDULED_PASS(POSITION_BEGIN, schedule_pipe) -} // namespace mindspore::registry diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.h b/mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.h deleted file mode 100644 index cb262e70..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_pass.h +++ /dev/null @@ -1,62 +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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DPICO_PASS_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DPICO_PASS_H_ - -#include -#include -#include -#include -#include -#include "src/custom_creator.h" -#include "./op_enum_public.h" -#include "include/registry/pass_base.h" -#include "include/errorcode.h" -#include "src/graph_split_info.h" -#include "src/graph_split_api.h" - -using mindspore::lite::STATUS; -namespace mindspore { -namespace dpico { -class DpicoPass : public registry::PassBase { - public: - DpicoPass() : PassBase("DpicoPass") {} - ~DpicoPass() override = default; - - bool Execute(const api::FuncGraphPtr &func_graph) override; - - private: - STATUS InitDpicoConfigInfo(); - void FetchFuncGraphs(const api::FuncGraphPtr &func_graph); - STATUS CheckDynamicInputShape(const api::FuncGraphPtr &func_graph); - STATUS MarkNodes(const api::FuncGraphPtr &func_graph); - STATUS ParseMapperConfig(const api::FuncGraphPtr &func_graph); - STATUS DataPrepare(const api::FuncGraphPtr &func_graph, bool *use_origin_config); - STATUS ReplaceSubgraphWithCustom(const api::FuncGraphPtr &func_graph, bool use_origin_config); - STATUS WriteOmBufferToFile(const std::shared_ptr &om_model_info, size_t custom_id); - STATUS RemoveTemporaryFiles(); - - std::vector func_graphs_; - std::shared_ptr custom_op_creator_{nullptr}; - struct GraphSplitInfo graph_split_info_; - bool save_tmp_files_{false}; - std::string dpico_config_path_{}; -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DPICO_PASS_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.cc b/mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.cc deleted file mode 100644 index 45537e58..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.cc +++ /dev/null @@ -1,222 +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 "src/dpico_preprocess_pass.h" -#include "include/registry/pass_registry.h" -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "common/data_transpose_utils.h" -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "infer/cxx_api/add_fusion.h" -#include "mindspore/ops/op_def/op_name.h" -#include "common/check_base.h" -#include "common/op_attr.h" -#include "mindspore/core/include/ir/graph_utils.h" - -namespace mindspore { -namespace dpico { -namespace { -STATUS InsertTransposeBeforeBiasAdd(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const ShapeVector &shape_vector, const api::AbstractBasePtr &abstract) { - auto manager = func_graph->manager(); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr. "; - return RET_ERROR; - } - auto pre_trans_cnode = - GenTransposeNode(func_graph, cnode->input(1), kNC2NH, cnode->fullname_with_scope() + "_converted_to_add_pre_0"); - if (pre_trans_cnode == nullptr) { - MS_LOG(ERROR) << "create pre transpose cnode failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto pre_trans_abstract = abstract->Clone(); - if (pre_trans_abstract == nullptr) { - MS_LOG(ERROR) << "create tensor abstract failed. "; - return RET_ERROR; - } - ShapeVector nc2nh_shape{shape_vector.at(0), shape_vector.at(kInputIndex2), shape_vector.at(kInputIndex3), - shape_vector.at(1)}; - auto nc2nh_shape_ptr = api::MakeShared(nc2nh_shape); - if (nc2nh_shape_ptr == nullptr) { - MS_LOG(ERROR) << "new abstract shape failed."; - return RET_ERROR; - } - pre_trans_abstract->set_shape(nc2nh_shape_ptr); - pre_trans_cnode->set_abstract(pre_trans_abstract); - auto pre_trans_prim = api::GetValueNode(pre_trans_cnode->input(0)); - MS_ASSERT(pre_trans_prim != nullptr); - (void)pre_trans_prim->AddAttr(ops::kFormat, api::MakeValue(NCHW)); - (void)pre_trans_prim->AddAttr(kInferDone, api::MakeValue(true)); - manager->SetEdge(cnode, kInputIndex1, pre_trans_cnode); - return RET_OK; -} -STATUS ReplaceBiasAddWithAdd(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const api::PrimitivePtr &primitive) { - auto manager = func_graph->manager(); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr. "; - return RET_ERROR; - } - auto prim = api::MakeShared(); - if (prim == nullptr) { - MS_LOG(ERROR) << "new AddFusion failed." << cnode->fullname_with_scope(); - return RET_ERROR; - } - (void)prim->SetAttrs(primitive->attrs()); - (void)prim->AddAttr(ops::kFormat, api::MakeValue(NHWC)); - auto add_value_node = api::NewValueNode(prim); - if (add_value_node == nullptr) { - MS_LOG(ERROR) << "new value node failed."; - return RET_ERROR; - } - if (!manager->Replace(cnode->input(0), add_value_node)) { - MS_LOG(ERROR) << "replace cnode failed."; - return RET_ERROR; - } - auto pre_trans_abstract = GetCNodeInputAbstract(cnode, kInputIndex1); - if (pre_trans_abstract == nullptr) { - MS_LOG(ERROR) << "cnode input_1 's abstract is nullptr. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - cnode->set_abstract(pre_trans_abstract->Clone()); - cnode->set_fullname_with_scope(cnode->fullname_with_scope() + "_converted_to_add"); - return RET_OK; -} -STATUS InsertTransposeAfterBiasAdd(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode, - const ShapeVector &shape_vector) { - auto manager = func_graph->manager(); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr. "; - return RET_ERROR; - } - auto post_trans_cnode = GenTransposeNode(func_graph, cnode, kNH2NC, cnode->fullname_with_scope() + "_post_0"); - if (post_trans_cnode == nullptr) { - MS_LOG(ERROR) << "create post transpose cnode failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto post_trans_abstract = CreateTensorAbstract(shape_vector, kNumberTypeFloat32); - if (post_trans_abstract == nullptr) { - MS_LOG(ERROR) << "create tensor abstract failed. "; - return RET_ERROR; - } - post_trans_cnode->set_abstract(post_trans_abstract->Clone()); - auto post_trans_prim = api::GetValueNode(post_trans_cnode->input(0)); - MS_ASSERT(post_trans_prim != nullptr); - (void)post_trans_prim->AddAttr(ops::kFormat, api::MakeValue(NHWC)); - (void)post_trans_prim->AddAttr(kInferDone, api::MakeValue(true)); - if (!manager->Replace(cnode, post_trans_cnode)) { - MS_LOG(ERROR) << "replace biasadd with add failed." << cnode->fullname_with_scope(); - return RET_ERROR; - } - return RET_OK; -} -} // namespace -STATUS DpicoPreprocessPass::PreProcessBiadAdd(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode) { - if (func_graph == nullptr) { - MS_LOG(ERROR) << "func_graph is nullptr."; - return RET_ERROR; - } - if (cnode == nullptr) { - MS_LOG(ERROR) << "cnode is nullptr."; - return RET_ERROR; - } - if (cnode->inputs().size() < kInputSize2) { - MS_LOG(ERROR) << "The size of cnode input cannot be less than 2."; - return RET_ERROR; - } - auto manager = func_graph->manager(); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr. "; - return RET_ERROR; - } - auto primitive = api::GetValueNode(cnode->input(0)); - if (primitive == nullptr) { - MS_LOG(ERROR) << "primitive is nullptr:" << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto abstract = GetCNodeInputAbstract(cnode, kInputIndex1); - if (abstract == nullptr) { - MS_LOG(ERROR) << "abstract is nullptr. "; - if (cnode->input(1) != nullptr) { - MS_LOG(ERROR) << "cnode name : " << cnode->input(1)->fullname_with_scope(); - } - return RET_ERROR; - } - ShapeVector shape_vector; - if (FetchShapeFromAbstract(abstract, &shape_vector) != RET_OK) { - MS_LOG(ERROR) << "fetch shape from abstract failed. "; - if (cnode->input(1) != nullptr) { - MS_LOG(ERROR) << "cnode name : " << cnode->input(1)->fullname_with_scope(); - } - return RET_ERROR; - } - if (shape_vector.empty() || shape_vector.size() != kDims4) { - MS_LOG(DEBUG) << "shape is empty or shape vector size is not equal to 4 dims, don't need to insert transpose op."; - return RET_NO_CHANGE; - } - - if (InsertTransposeBeforeBiasAdd(func_graph, cnode, shape_vector, abstract) != RET_OK) { - MS_LOG(ERROR) << "insert transpose before BiasAdd failed." << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (ReplaceBiasAddWithAdd(func_graph, cnode, primitive) != RET_OK) { - MS_LOG(ERROR) << "replace BiasAdd with Add failed. " << cnode->fullname_with_scope(); - return RET_ERROR; - } - - if (InsertTransposeAfterBiasAdd(func_graph, cnode, shape_vector) != RET_OK) { - MS_LOG(ERROR) << "insert transpose after BiasAdd failed." << cnode->fullname_with_scope(); - return RET_ERROR; - } - - return RET_OK; -} - -bool DpicoPreprocessPass::Execute(const api::FuncGraphPtr &func_graph) { - if (func_graph == nullptr) { - MS_LOG(ERROR) << "func_graph is nullptr."; - return false; - } - - auto manager = api::FuncGraphManager::Manage(func_graph, true); - if (manager == nullptr) { - MS_LOG(ERROR) << "manager is nullptr."; - return false; - } - - auto node_list = api::FuncGraph::TopoSort(func_graph->get_return()); - int status; - for (const auto &node : node_list) { - auto cnode = node->cast(); - if (cnode == nullptr) { - continue; - } - if (CheckPrimitiveType(cnode, api::MakeShared())) { - status = PreProcessBiadAdd(func_graph, cnode); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "preprocess biasadd for dpico failed."; - return false; - } - } - } - return true; -} -} // namespace dpico -} // namespace mindspore -namespace mindspore::registry { -REG_PASS(DpicoPreprocessPass, dpico::DpicoPreprocessPass) -} diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.h b/mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.h deleted file mode 100644 index 20751359..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/dpico_preprocess_pass.h +++ /dev/null @@ -1,46 +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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DPICO_PREPROCESS_PASS_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DPICO_PREPROCESS_PASS_H_ - -#include -#include -#include -#include -#include -#include "include/registry/pass_base.h" -#include "include/errorcode.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_OK; -using mindspore::lite::STATUS; -namespace mindspore { -namespace dpico { -class DpicoPreprocessPass : public registry::PassBase { - public: - DpicoPreprocessPass() : PassBase("DpicoPreprocessPass") {} - ~DpicoPreprocessPass() override = default; - - bool Execute(const api::FuncGraphPtr &func_graph) override; - - private: - STATUS PreProcessBiadAdd(const api::FuncGraphPtr &func_graph, const api::CNodePtr &cnode); -}; -} // namespace dpico -} // namespace mindspore - -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_DPICO_PREPROCESS_PASS_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.cc b/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.cc deleted file mode 100644 index ad99c5ea..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.cc +++ /dev/null @@ -1,395 +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 "src/graph_split_api.h" -#include -#include -#include -#include "mindspore/ops/op_def/auto_generate/gen_lite_ops.h" -#include "infer/return.h" -#include "infer/make_tuple.h" -#include "infer/tuple_get_item.h" -#include "common/op_attr.h" -#include "include/errorcode.h" -#include "include/api/format.h" -#include "src/graph_split_info.h" -#include "common/check_base.h" -#include "common/anf_util.h" -#include "common/op_enum.h" -#include "mindspore/core/include/ir/graph_utils.h" - -using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_NULL_PTR; -using mindspore::lite::RET_OK; -namespace mindspore { -namespace dpico { -namespace { -constexpr auto kFormat = "format"; -const std::unordered_set kRoiOpList = {"DetectionOutput", "DecBBox"}; -const std::unordered_set kRecurrentOpList = {"Lstm", "Rnn", "Gru", "BiLstm"}; -const size_t kMaximumNumbOfSegments = 64; -struct SegmentInfo { - size_t left_border; - size_t right_border; - bool is_supported; -}; -api::CNodePtrList GetFuncGraphTotalCNodes(const api::FuncGraphPtr &func_graph) { - api::CNodePtrList graph_total_cnodes; - auto node_list = api::FuncGraph::TopoSort(func_graph->get_return()); - for (auto &node : node_list) { - auto cnode = node->cast(); - if (cnode != nullptr && - !CheckPrimitiveType(cnode, api::MakeShared())) { // tuple_get_item may affect split graph - graph_total_cnodes.push_back(cnode); - } - } - return graph_total_cnodes; -} - -bool IsTupleGetItemNeeded(const api::CNodePtr &cnode, const api::CNodePtr &linked_cnode, - const api::CNodePtrList &total_cnodes) { - return CheckPrimitiveType(cnode, api::MakeShared()) && - GetBoolAttr(cnode, kIsMapperSupported) == GetBoolAttr(linked_cnode, kIsMapperSupported) && - std::find(total_cnodes.begin(), total_cnodes.end(), cnode) == total_cnodes.end(); -} - -api::CNodePtrList GetSubgraphTotalCNodes(const api::FuncGraphPtr &func_graph, const api::CNodePtrList &cnode_list, - const SegmentInfo &segment_info) { - api::CNodePtrList total_cnodes{}; - for (size_t i = segment_info.left_border; i <= segment_info.right_border; i++) { - auto &cur_cnode = cnode_list[i]; - total_cnodes.push_back(cur_cnode); - for (const auto &input_node : cur_cnode->inputs()) { - auto input_cnode = input_node->cast(); - if (input_cnode == nullptr) { - continue; - } - if (IsTupleGetItemNeeded(input_cnode, cur_cnode, total_cnodes)) { - total_cnodes.push_back(input_cnode); - } - } - - auto manager = api::FuncGraphManager::Manage(func_graph, true); - MS_CHECK_TRUE_MSG(manager != nullptr, {}, "manager is nullptr."); - auto node_users = manager->GetUsers(cur_cnode); - for (const auto &node_user : node_users) { - auto output_cnode = node_user.first->cast(); - if (IsTupleGetItemNeeded(output_cnode, cur_cnode, total_cnodes)) { - total_cnodes.push_back(output_cnode); - } - } - } - return total_cnodes; -} - -STATUS GetSubgraphNetType(const api::CNodePtrList &cnodes, OmNetType *om_net_type) { - for (const auto &cnode : cnodes) { - std::string op_type_name; - if (GetPrimitiveType(cnode, &op_type_name) != RET_OK) { - MS_LOG(ERROR) << "get cnode primitive type failed:" << cnode->fullname_with_scope(); - return RET_ERROR; - } - if (kRoiOpList.find(op_type_name) != kRoiOpList.end()) { - if (*om_net_type == OmNetType::kRecurrent) { - MS_LOG(ERROR) << "subgraph has been marked as Recurrent net type. " << op_type_name; - return RET_ERROR; - } - *om_net_type = OmNetType::kRoi; - } else if (kRecurrentOpList.find(op_type_name) != kRecurrentOpList.end()) { - if (*om_net_type == OmNetType::kRoi) { - MS_LOG(ERROR) << "subgraph has been marked as ROI net type. " << op_type_name; - return RET_ERROR; - } - *om_net_type = OmNetType::kRecurrent; - } - } - return RET_OK; -} - -STATUS GenerateSegmentInfos(const api::CNodePtrList &graph_total_cnodes, std::vector *segment_infos, - bool *last_op_is_custom) { - MS_CHECK_TRUE_MSG(segment_infos != nullptr, RET_ERROR, "segment_infos are nullptr"); - size_t start = 0; - for (size_t pos = 0; pos < graph_total_cnodes.size(); pos++) { - if (pos == graph_total_cnodes.size() - 1) { - if (!CheckPrimitiveType(graph_total_cnodes[pos], api::MakeShared())) { - MS_LOG(ERROR) << "last cnode should be return node."; - return RET_ERROR; - } - (void)segment_infos->emplace_back(SegmentInfo{start, pos, false}); - auto is_supported = GetBoolAttr(graph_total_cnodes[pos - 1], kIsMapperSupported); - if (is_supported) { - *last_op_is_custom = true; - } else { - *last_op_is_custom = false; - } - } else { - auto is_supported = GetBoolAttr(graph_total_cnodes[pos], kIsMapperSupported); - if (is_supported != GetBoolAttr(graph_total_cnodes[pos + 1], kIsMapperSupported)) { - (void)segment_infos->emplace_back(SegmentInfo{start, pos, is_supported}); - start = pos + 1; - } - } - } - return RET_OK; -} - -STATUS ComputeNetworkSegments(const std::vector &segment_infos, const bool &last_op_is_custom, - GraphSplitInfo *graph_split_info) { - MS_CHECK_TRUE_MSG(graph_split_info != nullptr, RET_ERROR, "graph split info is nullptr."); - MS_CHECK_TRUE_MSG(segment_infos.size() > 0, RET_ERROR, "segment_infos shouldn't be smaller than 1."); - for (auto segment_info : segment_infos) { - if (!segment_info.is_supported) { - graph_split_info->num_of_segments++; - } else { - graph_split_info->num_of_custom_op++; - } - } - if (!segment_infos.back().is_supported) { // remove last unsupported subgraph which contains Return cnode - graph_split_info->num_of_segments--; - } - if (segment_infos.front().is_supported && last_op_is_custom) { - graph_split_info->head_tail_op_is_custom = 1; - } - MS_LOG(DEBUG) << "graph_split_info->head_tail_op_is_custom = " << graph_split_info->head_tail_op_is_custom; - if (graph_split_info->num_of_segments > kMaximumNumbOfSegments) { - MS_LOG(ERROR) << "There are over " << kMaximumNumbOfSegments - << " segments in this network, so this process will stop. It's recommended that you don't set " - "\"configFile\" when converting, and all operators will be running on CPU."; - return RET_ERROR; - } - return RET_OK; -} - -std::vector GenerateSubgraphs(const api::FuncGraphPtr &func_graph, - const api::CNodePtrList &graph_total_cnodes, - const std::vector &segment_infos, size_t *subgraph_cnt) { - MS_CHECK_TRUE_MSG(subgraph_cnt != nullptr, {}, "subgraph_cnt is nullptr."); - std::vector subgraphs; - for (const auto &segment_info : segment_infos) { - auto subgraph_total_cnodes = GetSubgraphTotalCNodes(func_graph, graph_total_cnodes, segment_info); - MS_CHECK_TRUE_MSG(!subgraph_total_cnodes.empty(), {}, "get subgraph cnodes failed."); - OmNetType net_type = OmNetType::kCnn; - if (GetSubgraphNetType(subgraph_total_cnodes, &net_type) != RET_OK) { - MS_LOG(ERROR) << "get subgraph net type failed."; - return {}; - } - (void)subgraphs.emplace_back(*subgraph_cnt, segment_info.is_supported, net_type, subgraph_total_cnodes); - *subgraph_cnt += 1; - } - return subgraphs; -} - -bool FilterMakeTuple(const api::FuncGraphManagerPtr &manager, const Subgraph &subgraph, const api::CNodePtr &cnode) { - auto node_users = manager->GetUsers(cnode); - bool is_subgraph_output = true; - for (const auto &node_user : node_users) { - auto output_cnode = node_user.first->cast(); - if (output_cnode == nullptr) { - continue; - } - if (std::find(subgraph.cnodes.begin(), subgraph.cnodes.end(), output_cnode) != subgraph.cnodes.end()) { - is_subgraph_output = false; - } - } - return is_subgraph_output; -} - -bool IsSubgraphParamInput(const api::AnfNodePtr &front_node, const api::AnfNodePtrList &subgraph_param_inputs) { - auto param = front_node->cast(); - return !param->has_default() && - std::find(subgraph_param_inputs.begin(), subgraph_param_inputs.end(), param) == subgraph_param_inputs.end(); -} - -bool IsSubgraphCNodeInput(const api::AnfNodePtr &front_node, const Subgraph &subgraph, - const api::AnfNodePtrList &subgraph_cnode_inputs) { - return std::find(subgraph.cnodes.begin(), subgraph.cnodes.end(), front_node) == subgraph.cnodes.end() && - std::find(subgraph_cnode_inputs.begin(), subgraph_cnode_inputs.end(), front_node) == - subgraph_cnode_inputs.end(); -} - -int DetermineOutputFormat(const api::AnfNodePtr &output_node, Format *format) { - MS_CHECK_TRUE_MSG(output_node != nullptr && output_node->isa(), RET_ERROR, "output node is invalid."); - auto output_cnode = output_node->cast(); - int64_t local_format = static_cast(NCHW); - auto search_cnode = output_cnode; - const int max_search_depth = 10; - int loop = 0; - // current node may has no format, which can be obtain by transitivity of format. - while (loop < max_search_depth) { - auto primitive = api::GetValueNode(search_cnode->input(0)); - if (primitive == nullptr) { - break; - } - if (primitive->GetAttr(kFormat) != nullptr) { - local_format = api::GetValue(primitive->GetAttr(kFormat)); - break; - } - auto input_node = search_cnode->input(1); - if (!api::utils::isa(input_node)) { - break; - } - search_cnode = input_node->cast(); - loop++; - } - if (local_format < static_cast(NCHW) || local_format > static_cast(NCW)) { - MS_LOG(ERROR) << "obtained format is out of range, which is invalid."; - return RET_ERROR; - } - *format = static_cast(local_format); - if (CheckPrimitiveType(output_cnode, api::MakeShared())) { - auto abstract = GetCNodeInputAbstract(output_cnode, 1); - MS_CHECK_TRUE_MSG(abstract != nullptr, RET_ERROR, "input's abstract is nullptr."); - ShapeVector input_shape; - auto ret = FetchShapeFromAbstract(abstract, &input_shape); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "obtain input shape failed."); - abstract = output_cnode->abstract(); - MS_CHECK_TRUE_MSG(abstract != nullptr, RET_ERROR, "current cnode's abstract is nullptr."); - ShapeVector output_shape; - ret = FetchShapeFromAbstract(abstract, &output_shape); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "obtain output shape failed."); - if (input_shape.size() != kDims4) { - return RET_OK; - } - ShapeVector nc2nh = {input_shape[0], input_shape[kDims2], input_shape[kDims3], input_shape[kDims1]}; - if (nc2nh == output_shape && *format == NCHW) { - *format = NHWC; - } - ShapeVector nh2nc = {input_shape[0], input_shape[kDims3], input_shape[kDims1], input_shape[kDims2]}; - if (nh2nc == output_shape && *format == NHWC) { - *format = NCHW; - } - } - return RET_OK; -} -} // namespace - -int GraphSplit(const std::vector &func_graphs, GraphSplitInfo *graph_split_info) { - MS_CHECK_TRUE_MSG(graph_split_info != nullptr, RET_NULL_PTR, "graph_split_info is nullptr."); - size_t subgraph_cnt = 0; - for (const auto &func_graph : func_graphs) { - MS_CHECK_TRUE_MSG(func_graph != nullptr, RET_NULL_PTR, "func_graph is nullptr."); - auto graph_total_cnodes = GetFuncGraphTotalCNodes(func_graph); - MS_CHECK_TRUE_MSG(graph_total_cnodes.size() > 1, {}, "func graph should have 2 cnode at least."); - std::vector segment_infos; - bool last_op_is_custom = false; - if (GenerateSegmentInfos(graph_total_cnodes, &segment_infos, &last_op_is_custom) != RET_OK) { - MS_LOG(ERROR) << "generate segment infos failed."; - return RET_ERROR; - } - - if (ComputeNetworkSegments(segment_infos, last_op_is_custom, graph_split_info) != RET_OK) { - MS_LOG(ERROR) << "compute network segments failed."; - return RET_ERROR; - } - - auto subgraphs = GenerateSubgraphs(func_graph, graph_total_cnodes, segment_infos, &subgraph_cnt); - if (subgraphs.empty()) { - MS_LOG(ERROR) << "generate subgraphs failed."; - return RET_ERROR; - } - graph_split_info->subgraphs_map[func_graph] = subgraphs; - } - return RET_OK; -} - -api::AnfNodePtrList GetSubgraphInputs(const Subgraph &subgraph, const api::FuncGraphPtr &func_graph) { - MS_CHECK_TRUE_MSG(func_graph != nullptr, {}, "func_graph is nullptr."); - auto manager = func_graph->manager(); - MS_CHECK_TRUE_MSG(manager != nullptr, {}, "funcgraph manager is nullptr."); - api::AnfNodePtrList subgraph_param_inputs; - api::AnfNodePtrList subgraph_cnode_inputs; - for (const auto &cnode : subgraph.cnodes) { - if (CheckPrimitiveType(cnode, api::MakeShared())) { - if (FilterMakeTuple(manager, subgraph, cnode)) { - continue; - } - } - for (size_t i = 1; i < cnode->size(); i++) { - auto front_node = cnode->input(i); - MS_CHECK_TRUE_MSG(front_node != nullptr, {}, "input node is nullptr."); - if (api::utils::isa(front_node)) { - if (IsSubgraphParamInput(front_node, subgraph_param_inputs)) { - subgraph_param_inputs.push_back(front_node); - } - } else if (api::utils::isa(front_node)) { - if (IsSubgraphCNodeInput(front_node, subgraph, subgraph_cnode_inputs)) { - subgraph_cnode_inputs.push_back(front_node); - } - } - } - } - // keep subgraph input as origin graph input order - api::AnfNodePtrList subgraph_inputs; - auto graph_inputs = func_graph->get_inputs(); - for (auto &graph_input : graph_inputs) { - if (std::find(subgraph_param_inputs.begin(), subgraph_param_inputs.end(), graph_input) == - subgraph_param_inputs.end()) { - continue; - } - subgraph_inputs.push_back(graph_input); - } - (void)subgraph_inputs.insert(subgraph_inputs.end(), subgraph_cnode_inputs.begin(), subgraph_cnode_inputs.end()); - return subgraph_inputs; -} - -api::AnfNodePtrList GetSubgraphOutputs(const Subgraph &subgraph, const api::FuncGraphManagerPtr &manager) { - api::AnfNodePtrList subgraph_outputs; - for (const auto &cnode : subgraph.cnodes) { - auto node_users = manager->GetUsers(cnode); - for (const auto &node_user : node_users) { - auto output_cnode = node_user.first->cast(); - if (output_cnode == nullptr) { - continue; - } - if (std::find(subgraph.cnodes.begin(), subgraph.cnodes.end(), output_cnode) != subgraph.cnodes.end()) { - continue; - } - if (!CheckPrimitiveType(cnode, api::MakeShared())) { - subgraph_outputs.push_back(cnode); - break; - } - for (size_t i = 1; i < cnode->size(); i++) { - auto input_node = cnode->input(i); - if (api::utils::isa(input_node) && - std::find(subgraph.cnodes.begin(), subgraph.cnodes.end(), input_node) != subgraph.cnodes.end() && - std::find(subgraph_outputs.begin(), subgraph_outputs.end(), input_node) == subgraph_outputs.end()) { - subgraph_outputs.push_back(input_node); - } - } - break; - } - } - return subgraph_outputs; -} - -int FillSubgraphOutputsFormat(Subgraph *subgraph, const api::FuncGraphPtr &func_graph) { - MS_CHECK_TRUE_MSG(subgraph != nullptr && func_graph != nullptr, RET_ERROR, "output node is invalid."); - auto manager = func_graph->manager(); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "func_graph's manager is a nullptr."); - auto subgraph_outputs = GetSubgraphOutputs(*subgraph, manager); - for (auto &output_node : subgraph_outputs) { - Format output_format; - if (DetermineOutputFormat(output_node, &output_format) != RET_OK) { - MS_LOG(ERROR) << "obtain output format failed."; - return RET_ERROR; - } - subgraph->outputs_format.push_back(static_cast(output_format)); - } - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.h b/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.h deleted file mode 100644 index 3937aecf..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_api.h +++ /dev/null @@ -1,36 +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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_GRAPH_SPLITT_API_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_GRAPH_SPLITT_API_H_ - -#include -#include -#include -#include "mindapi/ir/common.h" - -namespace mindspore { -namespace dpico { -struct Subgraph; -struct GraphSplitInfo; - -int GraphSplit(const std::vector &func_graphs, GraphSplitInfo *graph_split_info); -api::AnfNodePtrList GetSubgraphInputs(const Subgraph &subgraph, const api::FuncGraphPtr &func_graph); -api::AnfNodePtrList GetSubgraphOutputs(const Subgraph &subgraph, const api::FuncGraphManagerPtr &manager); -int FillSubgraphOutputsFormat(Subgraph *subgraph, const api::FuncGraphPtr &func_graph); -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_GRAPH_SPLITT_API_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_info.h b/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_info.h deleted file mode 100644 index 0255a6a6..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/graph_split_info.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2021-2022 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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_GRAPH_SPLIT_INFO_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_GRAPH_SPLIT_INFO_H_ - -#include -#include -#include -#include "mindapi/ir/common.h" - -using ShapeVector = std::vector; -namespace mindspore { -namespace dpico { -enum OmNetType : int { kCnn = 0, kRoi = 1, kRecurrent = 2 }; - -struct Subgraph { - int32_t graph_id; - bool is_supported; - OmNetType om_net_type; - api::CNodePtrList cnodes; - std::vector inputs_dims; - std::vector outputs_dims; - std::vector outputs_format; - Subgraph(size_t input_id, bool input_flag, OmNetType input_type, api::CNodePtrList input_cnodes) - : graph_id(input_id), is_supported(input_flag), om_net_type(input_type), cnodes(std::move(input_cnodes)) {} -}; - -struct GraphSplitInfo { - size_t num_of_segments{0}; - size_t num_of_custom_op{0}; - int32_t head_tail_op_is_custom{0}; - std::map> subgraphs_map; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_GRAPH_SPLIT_INFO_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.cc b/mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.cc deleted file mode 100644 index 88032dea..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.cc +++ /dev/null @@ -1,377 +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 "src/mapper_config_parser.h" -#include -#include -#include -#include "common/op_enum.h" -#include "common/string_util.h" -#include "common/file_util.h" -#include "mindapi/base/logging.h" - -namespace mindspore { -namespace dpico { -namespace { -constexpr size_t kPairSize = 2; -constexpr size_t kMaxPixelVal = 255; -constexpr int kMaxVarReciChn = 65504; -const std::unordered_set kSupportedInputFormat = {"YUV400", "BGR_PLANAR", "RGB_PLANAR"}; -const std::unordered_set kSupportedModelFormat = {"RGB", "BGR"}; -const std::unordered_set kSupportedInterStride = {"16", "32", "64", "128", "256"}; -const std::unordered_map kDpicoDataTypeMap = { - {"FP16", kNumberTypeFloat16}, {"FP32", kNumberTypeFloat32}, {"INT16", kNumberTypeInt16}, {"INT8", kNumberTypeInt8}, - {"S16", kNumberTypeInt16}, {"S8", kNumberTypeInt8}, {"U16", kNumberTypeUInt16}, {"U8", kNumberTypeUInt8}, - {"UINT16", kNumberTypeUInt16}, {"UINT8", kNumberTypeUInt8}}; -int ParseInputFormat(AippModule *aipp_module, const std::string &content) { - if (aipp_module == nullptr) { - MS_LOG(ERROR) << "input aipp_module is nullptr."; - return RET_ERROR; - } - if (kSupportedInputFormat.find(content) == kSupportedInputFormat.end()) { - MS_LOG(ERROR) << "input_format is invalid. " << content; - return RET_ERROR; - } - if (!aipp_module->input_format.empty()) { - MS_LOG(ERROR) << "there is redundant \"input_format\" param in your config."; - return RET_ERROR; - } - aipp_module->input_format = content; - return RET_OK; -} -int ParseModelFormat(AippModule *aipp_module, const std::string &content) { - if (aipp_module == nullptr) { - MS_LOG(ERROR) << "input aipp_module is nullptr."; - return RET_ERROR; - } - if (kSupportedModelFormat.find(content) == kSupportedModelFormat.end()) { - MS_LOG(ERROR) << "model_format is invalid. " << content; - return RET_ERROR; - } - if (!aipp_module->model_format.empty()) { - MS_LOG(ERROR) << "there is redundant \"model_format\" param in your config."; - return RET_ERROR; - } - aipp_module->model_format = content; - return RET_OK; -} -template -int ParseMeanChn(AippModule *aipp_module, const std::string &content) { - if (aipp_module == nullptr) { - MS_LOG(ERROR) << "input aipp_module is nullptr."; - return RET_ERROR; - } - if (!IsValidDoubleNum(content)) { - MS_LOG(ERROR) << "input mecn_chn_" << n << " is invalid. " << content; - return RET_ERROR; - } - auto mean_val = std::stod(content); - if (mean_val < 0 || mean_val > kMaxPixelVal) { - MS_LOG(ERROR) << "input mecn_chn_" << n << "should be in range [0, 255]"; - return RET_ERROR; - } - if (aipp_module->mean_map.find(n) != aipp_module->mean_map.end()) { - MS_LOG(ERROR) << "there is redundant \"mecn_chn_" << n << "\" param in your config."; - return RET_ERROR; - } - aipp_module->mean_map[n] = mean_val; - return RET_OK; -} -template -int ParseVarReciChn(AippModule *aipp_module, const std::string &content) { - if (aipp_module == nullptr) { - MS_LOG(ERROR) << "input aipp_module is nullptr."; - return RET_ERROR; - } - if (!IsValidDoubleNum(content)) { - MS_LOG(ERROR) << "input var_reci_chn_" << n << " is invalid. " << content; - return RET_ERROR; - } - auto var_reci_val = std::stod(content); - if (var_reci_val < -kMaxVarReciChn || var_reci_val > kMaxVarReciChn) { - MS_LOG(ERROR) << "input var_reci_chn_" << n << "should be in range [-66504, 65504]"; - return RET_ERROR; - } - if (aipp_module->val_map.find(n) != aipp_module->val_map.end()) { - MS_LOG(ERROR) << "there is redundant \"var_reci_chn_" << n << "\" param in your config."; - return RET_ERROR; - } - aipp_module->val_map[n] = var_reci_val; - return RET_OK; -} -using AippCfgFunc = int (*)(AippModule *aipp_module, const std::string &content); -const std::unordered_map kParseAippFuncMap = { - {kInputFormat, &ParseInputFormat}, {kModelFormat, &ParseModelFormat}, {kMeanChn0, &ParseMeanChn<0>}, - {kMeanChn1, &ParseMeanChn<1>}, {kMeanChn2, &ParseMeanChn<2>}, {kMeanChn3, &ParseMeanChn<3>}, - {kVarReciChn0, &ParseVarReciChn<0>}, {kVarReciChn1, &ParseVarReciChn<1>}, {kVarReciChn2, &ParseVarReciChn<2>}, - {kVarReciChn3, &ParseVarReciChn<3>}}; -} // namespace - -MapperConfigParser *MapperConfigParser::GetInstance() { - static MapperConfigParser instance; - return &instance; -} - -int MapperConfigParser::ParseInputType(const std::string &input_type_str, - const std::vector &graph_input_names) { - auto input_types = SplitString(input_type_str, ';'); - for (const auto &input_type : input_types) { - auto pos = input_type.rfind(':'); - if (pos == std::string::npos) { - MS_LOG(ERROR) << "can't find \":\" in " << kInputType << ", please config it like: op_name:data_type"; - return RET_ERROR; - } - auto op_name = input_type.substr(0, pos); - if (std::find(graph_input_names.begin(), graph_input_names.end(), op_name) == graph_input_names.end()) { - MS_LOG(ERROR) << "can't find " << op_name << " of " << kInputType << " in origin graph inputs."; - return RET_ERROR; - } - auto data_type = input_type.substr(pos + 1); - if (kDpicoDataTypeMap.find(data_type) == kDpicoDataTypeMap.end()) { - MS_LOG(WARNING) << data_type << " is unsupported, will be set to FP32."; - } - } - return RET_OK; -} - -int MapperConfigParser::ParseImageList(const std::string &image_list_str, - const std::vector &graph_input_names) { - auto image_lists = SplitString(image_list_str, ';'); - if (image_lists.size() != graph_input_names.size()) { - MS_LOG(ERROR) << "image_list calib data path size " << image_lists.size() << " is not equal to graph input size " - << graph_input_names.size(); - return RET_ERROR; - } - if (image_lists.size() == 1) { - auto pos = image_lists.at(0).rfind(':'); - if (pos != std::string::npos) { - auto op_name = image_lists.at(0).substr(0, pos); - auto calib_data_path = image_lists.at(0).substr(pos + 1); - image_lists_[op_name] = calib_data_path; - } else { - image_lists_[graph_input_names.at(0)] = image_lists.at(0); - } - } else { - for (const auto &image_list : image_lists) { - auto pos = image_list.rfind(':'); - if (pos == std::string::npos) { - MS_LOG(ERROR) << "multi-input model should specify node name in [image_list] config."; - return RET_ERROR; - } - auto op_name = image_list.substr(0, pos); - auto calib_data_path = image_list.substr(pos + 1); - image_lists_[op_name] = calib_data_path; - } - } - return RET_OK; -} - -int MapperConfigParser::ParseRawLine(const std::string &raw_line, const std::vector &graph_input_names, - size_t *graph_input_idx) { - auto aipp_param = SplitString(raw_line, ':'); - if (aipp_param.size() != kPairSize) { - MS_LOG(ERROR) << "input pair is invalid. " << raw_line; - return RET_ERROR; - } - if (aipp_param.at(0) == kRelatedInputRank) { - if (IsValidUnsignedNum(aipp_param.at(1))) { - size_t idx = std::stoi(aipp_param.at(1)); - if (idx > graph_input_names.size() - 1) { - MS_LOG(ERROR) << kRelatedInputRank << " index " << idx << " is greater than graph input size " - << graph_input_names.size(); - return RET_ERROR; - } - *graph_input_idx = idx; - } else { - MS_LOG(ERROR) << kRelatedInputRank << " index is invalid."; - return RET_ERROR; - } - } else { - if (kParseAippFuncMap.find(aipp_param.at(0)) == kParseAippFuncMap.end()) { - MS_LOG(ERROR) << aipp_param.at(0) << " is unrecognized."; - return RET_ERROR; - } else { - auto parse_aipp_func = kParseAippFuncMap.at(aipp_param.at(0)); - if (parse_aipp_func == nullptr) { - MS_LOG(ERROR) << "parse aipp func is nullptr. " << aipp_param.at(0); - return RET_ERROR; - } - if (parse_aipp_func(&aipp_[graph_input_names.at(*graph_input_idx)], aipp_param.at(1)) != RET_OK) { - MS_LOG(ERROR) << "run " << aipp_param.at(1) << " parse func failed."; - return RET_ERROR; - } - } - } - return RET_OK; -} -int MapperConfigParser::ParseAippModule(const std::string &aipp_cfg, - const std::vector &graph_input_names) { - std::ifstream ifs; - if (ReadFileToIfstream(aipp_cfg, &ifs) != RET_OK) { - MS_LOG(ERROR) << "read file to ifstream failed."; - return RET_ERROR; - } - size_t graph_input_idx = 0; - size_t num_of_line = 0; - std::string raw_line; - int aipp_op_num = 0; - while (getline(ifs, raw_line)) { - if (num_of_line > kMaxLineCount) { - MS_LOG(ERROR) << "the line count is exceeds the maximum range 9999."; - return RET_ERROR; - } - num_of_line++; - if (EraseBlankSpace(&raw_line) != RET_OK) { - MS_LOG(ERROR) << "erase blank space failed. " << raw_line; - return RET_ERROR; - } - if (raw_line.empty() || raw_line.at(0) == '#') { - continue; - } - if (raw_line[raw_line.size() - 1] == '}') { - aipp_op_num--; - if (aipp_op_num != 0) { - MS_LOG(ERROR) << "brackets are not a pair! \"}\" is mismatched."; - return RET_ERROR; - } - continue; - } else if (raw_line[raw_line.size() - 1] == '{') { - aipp_op_num++; - if (aipp_op_num == 0) { - MS_LOG(ERROR) << "brackets are not a pair! \"{\" is mismatched."; - return RET_ERROR; - } - continue; - } else { - if (ParseRawLine(raw_line, graph_input_names, &graph_input_idx) != RET_OK) { - MS_LOG(ERROR) << "parse raw line failed. " << raw_line; - return RET_ERROR; - } - } - } - return RET_OK; -} - -int MapperConfigParser::AddImageList(const std::string &op_name, const std::string &calib_data_path) { - if (op_name.empty()) { - MS_LOG(ERROR) << "op_name is nullptr."; - return RET_ERROR; - } - if (calib_data_path.empty()) { - MS_LOG(ERROR) << "calib_data_path is nullptr."; - return RET_ERROR; - } - image_lists_[op_name] = calib_data_path; - return RET_OK; -} - -int MapperConfigParser::ParserFile(const std::string &cfg_file) { - std::ifstream ifs; - if (ReadFileToIfstream(cfg_file, &ifs) != RET_OK) { - MS_LOG(ERROR) << "read file to ifstream failed."; - return RET_ERROR; - } - origin_config_file_path_ = RealPath(cfg_file.c_str()); - if (origin_config_file_path_.empty()) { - MS_LOG(ERROR) << "cfg_file: " << file << " is invalid"; - return RET_ERROR; - } - auto dir_pos = origin_config_file_path_.find_last_of('/'); - tmp_generated_file_dir_ = origin_config_file_path_.substr(0, dir_pos + 1) + "tmp/"; - if (AccessFile(tmp_generated_file_dir_, F_OK) == 0 && RemoveDir(tmp_generated_file_dir_) != RET_OK) { - MS_LOG(ERROR) << "rm dir failed. " << tmp_generated_file_dir_; - return RET_ERROR; - } - if (CreateDir(&tmp_generated_file_dir_) != RET_OK) { - MS_LOG(ERROR) << "create dir failed. " << tmp_generated_file_dir_; - return RET_ERROR; - } - - size_t num_of_line = 0; - std::string raw_line; - while (getline(ifs, raw_line)) { - if (num_of_line > kMaxLineCount) { - MS_LOG(ERROR) << "the line count is exceeds the maximum range 9999."; - return RET_ERROR; - } - num_of_line++; - std::istringstream iss(raw_line); - if (iss.fail()) { - MS_LOG(ERROR) << "read input line to istringstream failed."; - return RET_ERROR; - } - std::string key; - std::string value; - if (iss >> key >> value) { - mapper_config_[key] = value; - } else { - if (key.empty() && value.empty()) { - MS_LOG(INFO) << "blank line is filtered out."; - continue; - } else { - MS_LOG(ERROR) << "invalid input line: " << raw_line; - return RET_ERROR; - } - } - } - return RET_OK; -} - -int MapperConfigParser::Parse(const std::string &cfg_file, const std::vector &graph_input_names) { - if (ParserFile(cfg_file) != RET_OK) { - MS_LOG(ERROR) << "parse file failed."; - return RET_ERROR; - } - if (mapper_config_.find(kInputType) != mapper_config_.end()) { - if (ParseInputType(mapper_config_.at(kInputType), graph_input_names) != RET_OK) { - MS_LOG(ERROR) << "parse input type failed."; - return RET_ERROR; - } - } - - if (mapper_config_.find(kInternalStride) != mapper_config_.end()) { - auto inter_stride_value = mapper_config_.at(kInternalStride); - if (kSupportedInterStride.count(inter_stride_value) == 0) { - MS_LOG(ERROR) << "The 'internal_stride' value " << inter_stride_value - << " is invalid, only support {16, 32, 64, 128, 256}."; - return RET_ERROR; - } - internal_stride_ = inter_stride_value; - MS_LOG(INFO) << "The 'internal_stride' is " << internal_stride_; - } else { - MS_LOG(INFO) << "Has not configure 'internal_stride', then will use default value " << internal_stride_; - } - if (mapper_config_.find(kImageList) != mapper_config_.end()) { - if (ParseImageList(mapper_config_.at(kImageList), graph_input_names) != RET_OK) { - MS_LOG(ERROR) << "parse image list failed."; - return RET_OK; - } - } - - if (mapper_config_.find(kInsertOpConf) != mapper_config_.end()) { - if (ParseAippModule(mapper_config_.at(kInsertOpConf), graph_input_names) != RET_OK) { - MS_LOG(ERROR) << "parse aipp config file failed."; - return RET_ERROR; - } - } - - return RET_OK; -} -void MapperConfigParser::SetOriginConfigFilePath(const std::string &origin_config_file_path) { - origin_config_file_path_ = origin_config_file_path; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.h b/mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.h deleted file mode 100644 index ca8f4f8a..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/mapper_config_parser.h +++ /dev/null @@ -1,92 +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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_MAPPER_CONFIG_PARSER_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_MAPPER_CONFIG_PARSER_H_ - -#include -#include -#include -#include -#include -#include "ir/dtype/type_id.h" - -namespace mindspore { -namespace dpico { -constexpr auto kInsertOpConf = "[insert_op_conf]"; -constexpr auto kInstructionName = "[instruction_name]"; -constexpr auto kImageList = "[image_list]"; -constexpr auto kInputType = "[input_type]"; -constexpr auto kInputShape = "[input_shape]"; -constexpr auto kGfpqParamFile = "[gfpq_param_file]"; -constexpr auto kOutNodes = "[out_nodes]"; -constexpr auto kOutputType = "[output_type]"; -constexpr auto kRelatedInputRank = "related_input_rank"; -constexpr auto kInputFormat = "input_format"; -constexpr auto kModelFormat = "model_format"; -constexpr auto kMeanChn = "mean_chn"; -constexpr auto kMeanChn0 = "mean_chn_0"; -constexpr auto kMeanChn1 = "mean_chn_1"; -constexpr auto kMeanChn2 = "mean_chn_2"; -constexpr auto kMeanChn3 = "mean_chn_3"; -constexpr auto kVarReciChn = "var_reci_chn"; -constexpr auto kVarReciChn0 = "var_reci_chn_0"; -constexpr auto kVarReciChn1 = "var_reci_chn_1"; -constexpr auto kVarReciChn2 = "var_reci_chn_2"; -constexpr auto kVarReciChn3 = "var_reci_chn_3"; -constexpr auto kInternalStride = "[internal_stride]"; -constexpr size_t kNumPrecision = 10; - -struct AippModule { - std::string input_format; - std::string model_format; - std::map mean_map; - std::map val_map; -}; - -class MapperConfigParser { - public: - static MapperConfigParser *GetInstance(); - int Parse(const std::string &cfg_file, const std::vector &graph_input_names); - int AddImageList(const std::string &op_name, const std::string &calib_data_path); - const std::unordered_map &GetCommonConfig() const { return mapper_config_; } - const std::unordered_map &GetImageLists() const { return image_lists_; } - const std::unordered_map &GetAippModules() const { return aipp_; } - const std::string &GetOriginConfigPath() const { return origin_config_file_path_; } - const std::string &GetOutputPath() const { return tmp_generated_file_dir_; } - const std::string &GetInternalStride() const { return internal_stride_; } - void SetOriginConfigFilePath(const std::string &origin_config_file_path); - - private: - MapperConfigParser() = default; - ~MapperConfigParser() = default; - int ParseInputType(const std::string &input_type_str, const std::vector &graph_input_names); - int ParseImageList(const std::string &image_list_str, const std::vector &graph_input_names); - int ParseRawLine(const std::string &raw_line, const std::vector &graph_input_names, - size_t *graph_input_idx); - int ParseAippModule(const std::string &aipp_cfg, const std::vector &graph_input_names); - int ParserFile(const std::string &cfg_file); - - std::unordered_map mapper_config_; - std::unordered_map image_lists_; - std::unordered_map aipp_; - std::string origin_config_file_path_; - std::string tmp_generated_file_dir_; - std::string internal_stride_ = "16"; -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_MAPPER_CONFIG_PARSER_H_ diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/om_generator.cc b/mindspore-lite/tools/converter/adapter/dpico/src/om_generator.cc deleted file mode 100644 index b2fee070..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/om_generator.cc +++ /dev/null @@ -1,391 +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 "src/om_generator.h" -#include -#include -#include -#include -#include -#include "infer/tuple_get_item.h" -#include "infer/custom.h" -#include "infer/make_tuple.h" -#include "common/anf_util.h" -#include "common/string_util.h" -#include "mapper/op_mapper_registry.h" -#include "common/op_attr.h" -#include "common/graph_output_name_keeper.h" -#include "./pico_mapper_api.h" -#include "op/preprocess_operator.h" -#include "src/mapper_config_parser.h" -#include "src/graph_split_api.h" - -namespace mindspore { -namespace dpico { -namespace { -const std::unordered_map kMapperSupportedTypes = { - {kNumberTypeUInt8, "U8"}, {kNumberTypeInt8, "S8"}, {kNumberTypeInt16, "S16"}, - {kNumberTypeUInt16, "U16"}, {kNumberTypeFloat16, "FP16"}, {kNumberTypeFloat32, "FP32"}}; -api::CNodePtrList GetOutputCNodes(const api::FuncGraphManagerPtr &manager, const api::AnfNodePtr &node) { - MS_CHECK_TRUE_MSG(manager != nullptr && node != nullptr, {}, "obtain nullptr input parameter."); - api::CNodePtrList output_cnodes; - auto node_users = manager->GetUsers(node); - if (node_users.size() == 1) { - auto output_cnode = node_users.begin()->first->cast(); - if (output_cnode != nullptr) { - (void)output_cnodes.emplace_back(output_cnode); - } - } else { - std::map output_cnode_ptr_map; - bool has_tuple_get_item = false; - for (const auto &node_user : node_users) { - auto output_cnode = node_user.first->cast(); - if (output_cnode != nullptr) { - if (CheckPrimitiveType(output_cnode, api::MakeShared())) { - has_tuple_get_item = true; - auto last_input_idx = output_cnode->size() - 1; - auto anode = output_cnode->input(last_input_idx); - MS_CHECK_TRUE_MSG(anode != nullptr, {}, - output_cnode->fullname_with_scope() << " input(" << last_input_idx << ") is nullptr."); - auto value_node = anode->cast(); - MS_CHECK_TRUE_MSG(value_node != nullptr, {}, "value node is nullptr. " << anode->fullname_with_scope()); - auto value_ptr = value_node->value(); - MS_CHECK_TRUE_MSG(value_ptr != nullptr, {}, "value ptr is nullptr. " << anode->fullname_with_scope()); - auto num_str = value_ptr->ToString(); - MS_CHECK_TRUE_MSG(IsValidUnsignedNum(num_str), {}, "num_str must an unsigned int, which is invalid"); - auto index = stoi(num_str); - MS_CHECK_TRUE_MSG(index >= 0, {}, "tuple_get_item index is invalid. " << index); - output_cnode_ptr_map[index] = output_cnode; - } else { - (void)output_cnodes.emplace_back(output_cnode); - } - } - } - if (has_tuple_get_item) { - (void)std::transform(output_cnode_ptr_map.begin(), output_cnode_ptr_map.end(), std::back_inserter(output_cnodes), - [](const std::pair &iter) { return iter.second; }); - } - } - return output_cnodes; -} - -std::string GetOutNodesStr(const api::FuncGraphManagerPtr &manager, const Subgraph &sub_graph, - const std::unordered_map &mapper_config) { - std::string out_nodes_str; - if (mapper_config.find(kOutNodes) != mapper_config.end()) { - out_nodes_str = mapper_config.at(kOutNodes); - } - if (!out_nodes_str.empty() && out_nodes_str.back() != ';') { - out_nodes_str.push_back(';'); - } - auto subgraph_outputs = GetSubgraphOutputs(sub_graph, manager); - api::AnfNodePtrList report_nodes; - for (const auto &output : subgraph_outputs) { - auto node_users = manager->GetUsers(output); - for (const auto &node_user : node_users) { - auto output_cnode = node_user.first->cast(); - if (output_cnode == nullptr) { - continue; - } - if (std::find(sub_graph.cnodes.begin(), sub_graph.cnodes.end(), output_cnode) != sub_graph.cnodes.end()) { - report_nodes.push_back(output); - } - } - } - out_nodes_str = std::accumulate(report_nodes.begin(), report_nodes.end(), out_nodes_str, - [](const std::string &res, const api::AnfNodePtr &anf_node_ptr) { - return res + anf_node_ptr->fullname_with_scope() + ":0;"; - }); - return out_nodes_str; -} -std::string GetInputTypeStr(const api::AnfNodePtrList &subgraph_inputs, - const std::unordered_map &) { - std::string input_type_str; - for (const auto &input : subgraph_inputs) { - auto node_name = input->fullname_with_scope(); - if (CheckPrimitiveType(input, api::MakeShared())) { - node_name = GetCustomOutputName(input); - MS_CHECK_TRUE_MSG(!node_name.empty(), {}, "get custom node origin name failed." << input->fullname_with_scope()); - } - auto ret = GraphOutputNameKeeper::GetInstance()->DetermineOmOpOutputName(input, &node_name, true); - MS_CHECK_TRUE_MSG(ret == RET_OK, "", "determine sub-graph's input name failed."); - auto abstract = GetAbstractFromAnfNode(input); - MS_CHECK_TRUE_MSG(abstract != nullptr, "", "get abstract failed. " << input->fullname_with_scope()); - TypeId type_id; - if (FetchTypeIdFromAbstract(abstract, &type_id) != RET_OK) { - MS_LOG(ERROR) << "get type_id failed." << input->fullname_with_scope(); - return ""; - } - std::string data_type; - if (kMapperSupportedTypes.find(type_id) == kMapperSupportedTypes.end()) { - MS_LOG(WARNING) << node_name << "'s data type " << dpico::TypeIdToString(type_id) - << " is unsupported by dpico, will set it to FP32"; - data_type = "FP32"; - } else { - data_type = kMapperSupportedTypes.at(type_id); - } - input_type_str = node_name + ':' + data_type + ';'; - } - if (!input_type_str.empty() && input_type_str.back() == ';') { - input_type_str.pop_back(); - } - return input_type_str; -} -STATUS ConfigImageList(const api::AnfNodePtrList &subgraph_inputs, std::ofstream *mapper_ofs) { - MS_CHECK_TRUE_MSG(mapper_ofs != nullptr, RET_ERROR, "mapper_ofs is nullptr."); - auto &image_lists = MapperConfigParser::GetInstance()->GetImageLists(); - if (image_lists.empty()) { - MS_LOG(ERROR) << "image_lists shouldn't be empty."; - mapper_ofs->close(); - return RET_ERROR; - } - *mapper_ofs << kImageList << " "; - - for (const auto &input : subgraph_inputs) { - auto in_name = input->fullname_with_scope(); - if (in_name.empty()) { - MS_LOG(ERROR) << "graph input node name is empty."; - mapper_ofs->close(); - return RET_ERROR; - } - if (CheckPrimitiveType(input, api::MakeShared())) { - in_name = GetCustomOutputName(input); - if (in_name.empty()) { - MS_LOG(ERROR) << "get custom node origin name failed." << input->fullname_with_scope(); - mapper_ofs->close(); - return RET_ERROR; - } - } - auto ret = GraphOutputNameKeeper::GetInstance()->DetermineOmOpOutputName(input, &in_name, true); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "determine sub-graph's input name failed."); - if (image_lists.find(in_name) == image_lists.end()) { - auto node_name = input->fullname_with_scope(); - auto iter = image_lists.find(node_name); - if (iter == image_lists.end()) { - MS_LOG(ERROR) << "can't find " << in_name << " in image_lists."; - mapper_ofs->close(); - return RET_ERROR; - } - MapperConfigParser::GetInstance()->AddImageList(in_name, iter->second); - } - *mapper_ofs << in_name << ":" << image_lists.at(in_name) << ";"; - } - *mapper_ofs << std::endl; - return RET_OK; -} -} // namespace - -int OmGenerator::GenerateAippConfig(const std::string &aipp_cfg_path, const api::AnfNodePtrList &subgraph_inputs) { - auto aipp_modules = MapperConfigParser::GetInstance()->GetAippModules(); - bool need_aipp_cfg = false; - std::ofstream aipp_ofs; - aipp_ofs.open(aipp_cfg_path, std::ios::out); - MS_CHECK_TRUE_MSG(aipp_ofs.is_open(), RET_ERROR, "open file failed."); - (void)aipp_ofs.precision(kNumPrecision); - aipp_ofs << "aipp_op {" << std::endl; - for (size_t i = 0; i < subgraph_inputs.size(); i++) { - auto input = subgraph_inputs.at(i); - auto node_name = input->fullname_with_scope(); - if (node_name.empty()) { - MS_LOG(ERROR) << "graph input node name is empty."; - aipp_ofs.close(); - return RET_ERROR; - } - if (aipp_modules.find(node_name) != aipp_modules.end()) { - need_aipp_cfg = true; - auto aipp_module = aipp_modules.at(node_name); - aipp_ofs << kRelatedInputRank << ":" << i << std::endl; - aipp_ofs << kInputFormat << ":" << aipp_module.input_format << std::endl; - aipp_ofs << kModelFormat << ":" << aipp_module.model_format << std::endl; - for (const auto &iter : aipp_module.mean_map) { - aipp_ofs << kMeanChn << "_" << iter.first << ":" << aipp_module.mean_map.at(iter.first) << std::endl; - } - for (const auto &iter : aipp_module.val_map) { - aipp_ofs << kVarReciChn << "_" << iter.first << ":" << aipp_module.val_map.at(iter.first) << std::endl; - } - } - } - aipp_ofs << "}" << std::endl; - aipp_ofs.close(); - if (!need_aipp_cfg) { - return RET_NO_CHANGE; - } - return RET_OK; -} - -int OmGenerator::GenerateMapperConfig(const api::FuncGraphPtr &func_graph, const Subgraph &sub_graph, int custom_id, - const std::string &mapper_cfg_path) { - MS_CHECK_TRUE_MSG(func_graph != nullptr, RET_ERROR, "func_graph is nullptr."); - auto manager = func_graph->manager(); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "funcgraph manager is nullptr."); - auto mapper_config = MapperConfigParser::GetInstance()->GetCommonConfig(); - MS_CHECK_TRUE_MSG(!mapper_config.empty(), RET_ERROR, "mapper config is empty."); - auto subgraph_inputs = GetSubgraphInputs(sub_graph, func_graph); - MS_CHECK_TRUE_MSG(!subgraph_inputs.empty(), RET_ERROR, "get subgraph inputs failed."); - // generate mapper config file - std::ofstream mapper_ofs; - mapper_ofs.open(mapper_cfg_path, std::ios::out); - MS_CHECK_TRUE_MSG(mapper_ofs.is_open(), RET_ERROR, "open file failed."); - for (const auto &iter : mapper_config) { - if (iter.first == kImageList || iter.first == kInsertOpConf || iter.first == kInstructionName || - iter.first == kOutNodes || iter.first == kInputType || iter.first == kInputShape || iter.first == kOutputType) { - continue; - } - mapper_ofs << iter.first << " " << iter.second << std::endl; - } - mapper_ofs << kInstructionName << " " << MapperConfigParser::GetInstance()->GetOutputPath() << kCustomName - << std::to_string(custom_id) << "/inst" << std::endl; - - // set subgraph inner cnode to report - auto out_nodes_str = GetOutNodesStr(manager, sub_graph, mapper_config); - if (!out_nodes_str.empty()) { - mapper_ofs << kOutNodes << " " + out_nodes_str << std::endl; - } - - // config [image_list] - if (ConfigImageList(subgraph_inputs, &mapper_ofs) != RET_OK) { - MS_LOG(ERROR) << "config [image_list] failed."; - return RET_ERROR; - } - - // config [input_type] - auto input_type_str = GetInputTypeStr(subgraph_inputs, mapper_config); - if (!input_type_str.empty()) { - mapper_ofs << kInputType << " " + input_type_str << std::endl; - } - - // generate aipp config file - auto aipp_cfg_path = - MapperConfigParser::GetInstance()->GetOutputPath() + kCustomName + std::to_string(custom_id) + "_aipp.cfg"; - auto status = GenerateAippConfig(aipp_cfg_path, subgraph_inputs); - if (status == RET_ERROR) { - MS_LOG(ERROR) << "generate aipp config file failed."; - return RET_ERROR; - } else if (status == RET_OK) { - mapper_ofs << kInsertOpConf << " " << aipp_cfg_path << std::endl; - } - mapper_ofs.close(); - - return RET_OK; -} - -int OmGenerator::TransformSubGraphInputs(const api::AnfNodePtrList &inputs, - std::vector *base_operators) { - MS_CHECK_TRUE_MSG(!inputs.empty(), RET_ERROR, "subgraph inputs shouldn't be empty."); - MS_CHECK_TRUE_MSG(base_operators != nullptr, RET_ERROR, "base_operators is nullptr."); - for (const auto &input : inputs) { - MS_CHECK_TRUE_MSG(input != nullptr, RET_ERROR, "input node is nullptr."); - auto preprocess_operator = std::make_unique(); - MS_CHECK_TRUE_MSG(preprocess_operator != nullptr, RET_ERROR, "preprocess_operator is nullptr."); - preprocess_operator->SetOpType(mapper::OpType::PREPROCESS); - - auto op_name = input->fullname_with_scope(); - if (CheckPrimitiveType(input, api::MakeShared())) { - op_name = GetCustomOutputName(input); - MS_CHECK_TRUE_MSG(!op_name.empty(), RET_ERROR, - "get custom node output name failed." << input->fullname_with_scope()); - } - auto ret = GraphOutputNameKeeper::GetInstance()->DetermineOmOpOutputName(input, &op_name, true); - MS_CHECK_TRUE_MSG(ret == RET_OK, RET_ERROR, "determine sub-graph's input name failed."); - preprocess_operator->SetOpName(op_name); - preprocess_operator->SetOutputNamesVec({op_name}); - - ShapeVector shape_vector; - MS_CHECK_TRUE_MSG(GetAnfNodeOutputShape(input, &shape_vector) == RET_OK, RET_ERROR, - "get " << input->fullname_with_scope() << " output shape failed."); - std::vector dims; - (void)std::transform(shape_vector.begin(), shape_vector.end(), std::back_inserter(dims), - [](const int64_t &value) { return static_cast(value); }); - preprocess_operator->SetShapeParamVec(dims); - base_operators->push_back(std::move(preprocess_operator)); - } - - return RET_OK; -} - -int OmGenerator::TransformSubGraphCNodes(const api::FuncGraphManagerPtr &manager, const api::CNodePtrList &cnodes, - std::vector *base_operators) { - MS_CHECK_TRUE_MSG(!cnodes.empty(), RET_ERROR, "subgraph inputs shouldn't be empty."); - MS_CHECK_TRUE_MSG(base_operators != nullptr, RET_ERROR, "base_operators is nullptr."); - for (const auto &cnode : cnodes) { - MS_CHECK_TRUE_MSG(api::utils::isa(cnode), RET_ERROR, "cur node should be a cnode"); - auto primitive = api::GetValueNode(cnode->input(0)); - MS_CHECK_TRUE_MSG(primitive != nullptr, RET_ERROR, - "invalid anf node, which don't have primitive. " << cnode->fullname_with_scope()); - if (CheckPrimitiveType(cnode, api::MakeShared()) || - CheckPrimitiveType(cnode, api::MakeShared())) { - MS_LOG(DEBUG) << "MakeTuple and TupleGetItem don't need to transform."; - continue; - } - - auto output_cnodes = GetOutputCNodes(manager, cnode); - MS_CHECK_TRUE_MSG(!output_cnodes.empty(), RET_ERROR, "output_cnodes is empty. " << cnode->fullname_with_scope()); - std::string op_type_name; - if (GetPrimitiveType(cnode, &op_type_name) != RET_OK) { - MS_LOG(ERROR) << "get cnode primitive type failed " << cnode->fullname_with_scope(); - return RET_ERROR; - } - auto op_mapper = OpMapperRegistry::GetInstance()->GetOpMapper(op_type_name); - MS_CHECK_TRUE_MSG(op_mapper != nullptr, RET_ERROR, "op mapper is unsupported: " << op_type_name); - if (op_mapper->Map(cnode, base_operators, primitive, output_cnodes) != RET_OK) { - MS_LOG(ERROR) << "op mapper Map failed: " << op_type_name; - return RET_ERROR; - } - } - - return RET_OK; -} - -int OmGenerator::Run(const api::FuncGraphPtr &func_graph, const Subgraph &sub_graph, int custom_id, - mapper::ModelCoreInfo *om_model_info, bool use_origin_config) { - MS_CHECK_TRUE_MSG(func_graph != nullptr && om_model_info != nullptr, RET_ERROR, "obtain nullptr input parameter."); - auto manager = func_graph->manager(); - MS_CHECK_TRUE_MSG(manager != nullptr, RET_ERROR, "funcgraph manager is nullptr."); - std::string mapper_cfg_path; - if (!use_origin_config) { - mapper_cfg_path = - MapperConfigParser::GetInstance()->GetOutputPath() + kCustomName + std::to_string(custom_id) + "_mapper.cfg"; - if (GenerateMapperConfig(func_graph, sub_graph, custom_id, mapper_cfg_path) != RET_OK) { - MS_LOG(ERROR) << "generate om config file failed."; - return RET_ERROR; - } - } else { - mapper_cfg_path = MapperConfigParser::GetInstance()->GetOriginConfigPath(); - } - - std::vector base_operators; - auto subgraph_inputs = GetSubgraphInputs(sub_graph, func_graph); - MS_CHECK_TRUE_MSG(!subgraph_inputs.empty(), RET_ERROR, - "get subgraph inputs failed. subgraph id is " << sub_graph.graph_id); - if (TransformSubGraphInputs(subgraph_inputs, &base_operators) != RET_OK) { - MS_LOG(ERROR) << "subgraph inputs transform failed."; - return RET_ERROR; - } - - if (TransformSubGraphCNodes(manager, sub_graph.cnodes, &base_operators) != RET_OK) { - MS_LOG(ERROR) << "subgraph cnodes transform failed."; - return RET_ERROR; - } - - if (!mapper::GenerateModelBinary(mapper_cfg_path.c_str(), base_operators, om_model_info)) { - MS_LOG(ERROR) << "Generate Model Binary failed."; - return RET_ERROR; - } - - return RET_OK; -} -} // namespace dpico -} // namespace mindspore diff --git a/mindspore-lite/tools/converter/adapter/dpico/src/om_generator.h b/mindspore-lite/tools/converter/adapter/dpico/src/om_generator.h deleted file mode 100644 index 50d089c5..00000000 --- a/mindspore-lite/tools/converter/adapter/dpico/src/om_generator.h +++ /dev/null @@ -1,49 +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_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_OM_GENERATOR_H_ -#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_OM_GENERATOR_H_ - -#include -#include -#include -#include -#include -#include "mindapi/ir/common.h" -#include "src/graph_split_info.h" -#include "mapper/op_mapper.h" -#include "op/base_operator.h" - -namespace mindspore { -namespace dpico { -class OmGenerator { - public: - OmGenerator() = default; - ~OmGenerator() = default; - int Run(const api::FuncGraphPtr &func_graph, const Subgraph &sub_graph, int custom_id, - mapper::ModelCoreInfo *om_model_info, bool use_origin_config); - - private: - int GenerateAippConfig(const std::string &aipp_cfg_path, const api::AnfNodePtrList &subgraph_inputs); - int GenerateMapperConfig(const api::FuncGraphPtr &func_graph, const Subgraph &sub_graph, int custom_id, - const std::string &cfg); - int TransformSubGraphInputs(const api::AnfNodePtrList &nodes, std::vector *base_operators); - int TransformSubGraphCNodes(const api::FuncGraphManagerPtr &manager, const api::CNodePtrList &Cnodes, - std::vector *base_operators); -}; -} // namespace dpico -} // namespace mindspore -#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_SRC_OM_GENERATOR_H_ diff --git a/mindspore-lite/tools/providers/NNIE/Hi3516D/compile_nnie.sh b/mindspore-lite/tools/providers/NNIE/Hi3516D/compile_nnie.sh deleted file mode 100644 index 5b05804b..00000000 --- a/mindspore-lite/tools/providers/NNIE/Hi3516D/compile_nnie.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/bash -# Copyright 2025 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. -# ============================================================================ - -# Build x86 for nnie -function Run_Build_x86() { - # decompress release_pkg - cd ${open_source_lite_path}/output/ || exit 1 - file_name=$(ls ./*linux-x64.tar.gz) - IFS="-" read -r -a file_name_array <<< "$file_name" - version=${file_name_array[2]} - tar -xf mindspore-lite-${version}-linux-x64.tar.gz - - # cp tools folder - cd ${open_source_lite_path}/output/mindspore-lite-${version}-linux-x64 || exit 1 - rm -rf ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/adapter/nnie/third_party/ms_lite/ - mkdir -p ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/adapter/nnie/third_party/ms_lite/ || exit 1 - cp -r ./tools/ ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/adapter/nnie/third_party/ms_lite/ || exit 1 - - # compile nnie converter so - export MSLITE_ENABLE_NNIE=on - export MSLITE_ENABLE_CONVERTER=off - export MSLITE_ENABLE_TRAIN=off - export MSLITE_ENABLE_TOOLS=off - export MSLITE_ENABLE_TESTCASES=off - bash ${nnie_code_path}/mindspore/build.sh -I x86_64 -j ${thread_num} - if [ $? = 0 ]; then - echo "build x86 for nnie success" - hi3516d_release_path=${open_source_lite_path}/output/mindspore-lite-${version}-linux-x64/tools/converter/providers/Hi3516D - rm -rf ${hi3516d_release_path} - mkdir -p ${hi3516d_release_path} - cp ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/adapter/nnie/providers/NNIE/Hi3516D/libnnie_mapper.so ${hi3516d_release_path}/ || exit 1 - cp ${nnie_code_path}/mindspore/mindspore/lite/build/tools/converter/adapter/nnie/libmslite_nnie_converter.so ${hi3516d_release_path}/ || exit 1 - cp ${nnie_code_path}/mindspore/mindspore/lite/build/tools/converter/adapter/nnie/data_process/libmslite_nnie_data_process.so ${hi3516d_release_path}/ || exit 1 - ms_config_file=${hi3516d_release_path}/../../converter/converter.cfg - echo "[registry]" > ${ms_config_file} - echo 'plugin_path=../providers/Hi3516D/libmslite_nnie_converter.so' >> ${ms_config_file} - - hi3559a_release_path=${open_source_lite_path}/output/mindspore-lite-${version}-linux-x64/tools/converter/providers/Hi3559A - rm -rf ${hi3559a_release_path} - mkdir -p ${hi3559a_release_path} - cp ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/adapter/nnie/providers/NNIE/Hi3559A/libnnie_mapper.so ${hi3559a_release_path}/ || exit 1 - - cd ${open_source_lite_path}/output/ || exit 1 - # remove unused static library - echo "cp new nnie so to release pkg success" - rm ${open_source_lite_path}/output/mindspore-lite-${version}-linux-x64.tar.gz - tar -zcf ./mindspore-lite-${version}-linux-x64.tar.gz ./mindspore-lite-${version}-linux-x64/ || exit 1 - sha256sum ./mindspore-lite-${version}-linux-x64.tar.gz > ./mindspore-lite-${version}-linux-x64.tar.gz.sha256 || exit 1 - else - echo "build x86 for nnie failed"; return 1 - fi -} - -# bashpath should be /home/jenkins/agent-working-dir/workspace/Compile_Lite_ARM32_3516D/ -basepath=$(pwd) -echo "basepath is ${basepath}" -#set -e -open_source_lite_path=${basepath}/mindspore-lite - -# Example:sh compile_nnie.sh -I arm32 -b nnie_master -while getopts "I:b:j:t:d:" opt; do - case ${opt} in - I) - task=${OPTARG} - echo "compile task is ${OPTARG}" - ;; - b) - branch_name=${OPTARG} - echo "branch name is ${OPTARG}" - ;; - t) - ;; - d) - ;; - j) - thread_num=${OPTARG} - echo "thread_num is ${OPTARG}" - ;; - ?) - echo "unknown para" - exit 1;; - esac -done - -# download nnie repository -nnie_code_path=${basepath}/nnie_code/ -rm -rf ${nnie_code_path} -mkdir -p ${nnie_code_path} -cd ${nnie_code_path} || exit 1 - -if [[ "${GITEE_CREDENTIAL_USR}" && "${GITEE_CREDENTIAL_PSW}" ]]; then - gitee_user_name=${GITEE_CREDENTIAL_USR} - gitee_user_pass=${GITEE_CREDENTIAL_PSW} -else - echo "ERROR: ENV GITEE_CREDENTIAL_USR or GITEE_CREDENTIAL_PSW not found." - exit 1 -fi - -git clone https://${gitee_user_name}:${gitee_user_pass}@gitee.com/ms-incubator/mindspore.git -b ${branch_name} --single-branch -if [[ $? -ne 0 ]]; then - echo "git clone https://gitee.com/ms-incubator/mindspore.git -b ${branch_name} failed." - exit 1 -fi - -if [ ${task} == "x86_64" ]; then - echo "start building x86 for nnie..." - Run_Build_x86 -fi - -Run_build_PID=$! -exit ${Run_build_PID} -- Gitee