You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

option_utils.h 5.2 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FRAMEWORK_DOMI_ATC_IR_COMMON_H_
  17. #define FRAMEWORK_DOMI_ATC_IR_COMMON_H_
  18. #include <unistd.h>
  19. #include <string>
  20. #include <unordered_map>
  21. #include <utility>
  22. #include <vector>
  23. #include <set>
  24. #include "framework/common/debug/ge_log.h"
  25. #include "framework/common/ge_inner_error_codes.h"
  26. #include "framework/omg/omg_inner_types.h"
  27. #include "graph/preprocess/multi_batch_options.h"
  28. namespace ge {
  29. const char *const kModifyMixlistError = "modify_mixlist is assigned, please ensure that "
  30. "precision_mode is assigned to 'allow_mix_precision'";
  31. static std::set<std::string> caffe_support_input_format = {"NCHW", "ND"};
  32. static std::set<std::string> tf_support_input_format = {"NCHW", "NHWC", "ND", "NCDHW", "NDHWC"};
  33. static std::set<std::string> onnx_support_input_format = {"NCHW", "ND", "NCDHW"};
  34. static std::map<std::string, domiTensorFormat_t> input_format_str_to_geformat = {
  35. {"ND", domi::DOMI_TENSOR_ND},
  36. {"NCHW", domi::DOMI_TENSOR_NCHW},
  37. {"NHWC", domi::DOMI_TENSOR_NHWC},
  38. {"CHWN", domi::DOMI_TENSOR_CHWN},
  39. {"NC1HWC0", domi::DOMI_TENSOR_NC1HWC0},
  40. {"NHWC1C0", domi::DOMI_TENSOR_NHWC1C0},
  41. {"NCDHW", domi::DOMI_TENSOR_NCDHW},
  42. {"NDHWC", domi::DOMI_TENSOR_NDHWC}
  43. };
  44. static const std::string kEnableCompressWeightTrue = "1";
  45. static const std::string kEnableCompressWeightFalse = "0";
  46. bool CheckDynamicBatchSizeInputShapeValid(map<string, vector<int64_t>> shape_map,
  47. std::string &dynamic_batch_size);
  48. bool CheckDynamicImagesizeInputShapeValid(map<string, vector<int64_t>> shape_map,
  49. const std::string input_format, std::string &dynamic_image_size);
  50. bool CheckDynamicDimsInputShapeValid(const std::map<std::string, std::vector<int64_t>> &shape_map,
  51. std::string input_format, std::string &dynamic_dims);
  52. bool CheckAndParseDynamicDims(int32_t dynamic_dim_num, std::string &dynamic_dims);
  53. Status CheckDynamicInputParamValid(std::string &dynamic_batch_size, std::string &dynamic_image_size,
  54. std::string &dynamic_dims, const std::string input_shape,
  55. const std::string input_shape_range, const std::string input_format,
  56. bool &is_dynamic_input);
  57. bool ParseInputShape(const std::string &input_shape, std::map<string, std::vector<int64_t>> &shape_map,
  58. std::vector<std::pair<string, vector<int64_t>>> &user_shape_map, bool is_dynamic_input = false);
  59. Status ParseInputShapeRange(const std::string &shape_range,
  60. std::map<string, std::vector<std::pair<int64_t, int64_t>>> &shape_range_map);
  61. Status ParseInputShapeRange(const std::string &shape_range,
  62. std::vector<std::vector<std::pair<int64_t, int64_t>>> &range);
  63. Status CheckOutputTypeParamValid(const std::string output_type);
  64. Status CheckBufferOptimizeParamValid(const std::string buffer_optimize);
  65. Status CheckCompressWeightParamValid(const std::string enable_compress_weight, const std::string compress_weight_conf);
  66. int CheckLogParamValidAndSetLogLevel(const std::string log);
  67. Status CheckInsertOpConfParamValid(const std::string insert_op_conf);
  68. Status CheckDisableReuseMemoryParamValid(const std::string disable_reuse_memory);
  69. Status CheckEnableSingleStreamParamValid(const std::string enable_single_stream);
  70. Status CheckImplmodeParamValid(const std::string &optypelist_for_implmode, std::string &op_select_implmode);
  71. Status CheckModifyMixlistParamValid(const std::map<std::string, std::string> &options);
  72. Status CheckModifyMixlistParamValid(const std::string &precision_mode, const std::string &modify_mixlist);
  73. Status CheckInputFormat(const string &input_format);
  74. Status CheckKeepTypeParamValid(const std::string &keep_dtype);
  75. void PrintOptionMap(std::map<std::string, std::string> &options, std::string tips);
  76. void EraseEndSemicolon(std::string &param);
  77. Status UpdateDataOpShape(const OpDescPtr &op, std::map<std::string, std::vector<int64_t>> &shape_map);
  78. Status UpdateDataOpShapeRange(
  79. const OpDescPtr &op, const std::map<std::string, std::vector<std::pair<int64_t, int64_t>>> &name_shape_range_map);
  80. Status UpdateDataOpShapeRange(const OpDescPtr &op,
  81. const std::vector<std::vector<std::pair<int64_t, int64_t>>> &index_shape_range_map);
  82. Status UpdateDynamicInputShapeRange(const ge::ComputeGraphPtr &compute_graph, const string &input_shape_range);
  83. }
  84. #endif // FRAMEWORK_DOMI_ATC_IR_COMMON_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示