Browse Source

!31822 clean code

Merge pull request !31822 from zhupuxu/clean_code_master
r1.7
i-robot Gitee 4 years ago
parent
commit
4981c879ec
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 41 additions and 31 deletions
  1. +6
    -7
      mindspore/ccsrc/plugin/device/ascend/hal/device/executor/aicpu_ext_info_handle.cc
  2. +1
    -1
      mindspore/ccsrc/plugin/device/ascend/hal/device/executor/aicpu_ext_info_handle.h
  3. +1
    -1
      mindspore/ccsrc/plugin/device/ascend/hal/hccl_adapter/all_to_all_v_calc_param.cc
  4. +1
    -1
      mindspore/ccsrc/plugin/device/ascend/kernel/tbe/tbe_json/tbe_json_creator.h
  5. +28
    -20
      mindspore/ccsrc/plugin/device/ascend/optimizer/format_type/insert_transdata_for_runop.cc
  6. +3
    -0
      mindspore/ccsrc/plugin/device/ascend/optimizer/format_type/insert_transdata_for_runop.h
  7. +0
    -1
      mindspore/ccsrc/plugin/device/ascend/optimizer/ir_fusion/transposed_update_fusion.h
  8. +1
    -0
      mindspore/ccsrc/plugin/device/gpu/optimizer/concat_outputs_for_all_gather.cc

+ 6
- 7
mindspore/ccsrc/plugin/device/ascend/hal/device/executor/aicpu_ext_info_handle.cc View File

@@ -54,7 +54,7 @@ bool AicpuExtInfoHandler::Parse(const std::string &ext_info) {
MS_EXCEPTION_IF_NULL(aicpu_ext_info);
switch (aicpu_ext_info->infoType) {
case kernel::FWK_ADPT_EXT_SHAPE_TYPE:
if (!ParseExtShapeType(aicpu_ext_info)) {
if (!ParseExtShapeType(*aicpu_ext_info)) {
MS_LOG(ERROR) << "Parse aicpu_ext_info shape type failed, node: " << node_name_;
return false;
}
@@ -89,22 +89,21 @@ bool AicpuExtInfoHandler::Parse(const std::string &ext_info) {
return true;
}

bool AicpuExtInfoHandler::ParseExtShapeType(AicpuExtInfo *aicpu_ext_info) {
MS_EXCEPTION_IF_NULL(aicpu_ext_info);
if (aicpu_ext_info->infoLen != sizeof(int32_t)) {
bool AicpuExtInfoHandler::ParseExtShapeType(const AicpuExtInfo &aicpu_ext_info) const {
if (aicpu_ext_info.infoLen != sizeof(int32_t)) {
MS_LOG(ERROR) << "Node:" << node_name_ << " parse ext shape type failed as infoLen must be " << sizeof(int32_t)
<< " but got:" << aicpu_ext_info->infoLen;
<< " but got:" << aicpu_ext_info.infoLen;
return false;
}

auto type = reinterpret_cast<const int32_t *>(aicpu_ext_info->infoMsg);
auto type = reinterpret_cast<const int32_t *>(aicpu_ext_info.infoMsg);

if (*type != unknown_type_) {
MS_LOG(ERROR) << "Node:" << node_name_ << " parse ext shape type failed as need:" << unknown_type_
<< " but got:" << *type;
return false;
}
MS_LOG(INFO) << "Node:" << node_name_ << "parse ext shape type success infoLen=" << aicpu_ext_info->infoLen;
MS_LOG(INFO) << "Node:" << node_name_ << "parse ext shape type success infoLen=" << aicpu_ext_info.infoLen;
return true;
}



+ 1
- 1
mindspore/ccsrc/plugin/device/ascend/hal/device/executor/aicpu_ext_info_handle.h View File

@@ -62,7 +62,7 @@ class AicpuExtInfoHandler {
NotNull<TypeId *> data_type);

private:
[[nodiscard]] bool ParseExtShapeType(AicpuExtInfo *aicpu_ext_info);
[[nodiscard]] bool ParseExtShapeType(const AicpuExtInfo &aicpu_ext_info) const;
[[nodiscard]] bool ParseExtInputShape(AicpuExtInfo *aicpu_ext_info);
[[nodiscard]] bool ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info);



+ 1
- 1
mindspore/ccsrc/plugin/device/ascend/hal/hccl_adapter/all_to_all_v_calc_param.cc View File

@@ -123,7 +123,7 @@ void AllToAllvCalcParam::CalcMemOffset(const std::vector<size_t> &mem_sizes, con
(*displs)[i] = SizeToLong(offset);
auto iter = rank_id_map.find(i);
if (iter != rank_id_map.end()) {
(*counts)[i] = real_sizes[iter->second];
(*counts)[i] = static_cast<int64_t>(real_sizes[iter->second]);
offset += mem_sizes[iter->second];
} else {
(*counts)[i] = 0;


+ 1
- 1
mindspore/ccsrc/plugin/device/ascend/kernel/tbe/tbe_json/tbe_json_creator.h View File

@@ -69,7 +69,7 @@ class TbeJsonCreator {
virtual bool GenJson(const AnfNodePtr &anf_node, nlohmann::json *kernel_json) { return false; }
virtual bool GenJson(const FusionScopeInfo &fusion_scope_info, nlohmann::json *fusion_json) { return false; }
std::string GetJsonName() { return json_name_; }
size_t GetJsonHash() { return json_hash_; }
size_t GetJsonHash() const { return json_hash_; }

protected:
bool GenComputeJson(const AnfNodePtr &anf_node, nlohmann::json *compute_json);


+ 28
- 20
mindspore/ccsrc/plugin/device/ascend/optimizer/format_type/insert_transdata_for_runop.cc View File

@@ -55,6 +55,24 @@ bool RunOpInsertTransData::InsertTransdataForOutput(const FuncGraphPtr &graph) {
return changed;
}

bool RunOpInsertTransData::ConvertNodeFormat(const FuncGraphPtr &graph, const AnfNodePtr &node,
const std::string &format, size_t insert_index, size_t input_index,
bool is_insert) const {
MS_EXCEPTION_IF_NULL(graph);
MS_EXCEPTION_IF_NULL(node);
auto cnode = node->cast<CNodePtr>();
MS_EXCEPTION_IF_NULL(cnode);
bool changed = false;
// convert the format of node to default
if (kCommonFormatSet.find(format) == kCommonFormatSet.end() && (input_size_ > 1 || format == kOpFormat_ND_RNN_BIAS)) {
auto input_node = (!is_insert) ? common::AnfAlgo::GetInputNode(cnode, input_index) : node;
auto trans_node = AddTransOpNodeToGraph(graph, input_node, kernel_select_, insert_index, is_insert);
common::AnfAlgo::SetNodeInput(cnode, trans_node, input_index);
changed = true;
}
return changed;
}

bool RunOpInsertTransData::Run(const FuncGraphPtr &graph) {
MS_EXCEPTION_IF_NULL(graph);
bool changed = false;
@@ -65,29 +83,19 @@ bool RunOpInsertTransData::Run(const FuncGraphPtr &graph) {
if (!node->cast<CNodePtr>() || !AnfUtils::IsRealKernel(node)) {
continue;
}
auto cnode = node->cast<CNodePtr>();
size_t input_num = common::AnfAlgo::GetInputTensorNum(cnode);
size_t input_num = common::AnfAlgo::GetInputTensorNum(node);
for (size_t index = 0; index < input_num; ++index) {
auto prev_input_format = AnfAlgo::GetPrevNodeOutputFormat(cnode, index);
auto prev_node_out_infer_shape = common::AnfAlgo::GetPrevNodeOutputInferShape(cnode, index);
auto input_format = AnfAlgo::GetInputFormat(cnode, index);
auto input_node = common::AnfAlgo::GetInputNode(cnode, index);
// convert the format of node's input node to default
if (kCommonFormatSet.find(prev_input_format) == kCommonFormatSet.end() &&
(prev_node_out_infer_shape.size() > 1 || prev_input_format == kOpFormat_ND_RNN_BIAS)) {
auto trans_node = AddTransOpNodeToGraph(graph, input_node, kernel_select_, 0, false);
common::AnfAlgo::SetNodeInput(cnode, trans_node, index);
has_changed = true;
}
// convert node's output format
if (kCommonFormatSet.find(input_format) == kCommonFormatSet.end() &&
(prev_node_out_infer_shape.size() > 1 || input_format == kOpFormat_ND_RNN_BIAS)) {
auto trans_node = AddTransOpNodeToGraph(graph, cnode, kernel_select_, index, true);
common::AnfAlgo::SetNodeInput(cnode, trans_node, index);
has_changed = true;
}
auto prev_input_format = AnfAlgo::GetPrevNodeOutputFormat(node, index);
auto prev_node_out_infer_shape = common::AnfAlgo::GetPrevNodeOutputInferShape(node, index);
input_size_ = prev_node_out_infer_shape.size();
auto input_format = AnfAlgo::GetInputFormat(node, index);
// convert the format of node's input or output
auto input_changed = ConvertNodeFormat(graph, node, prev_input_format, 0, index, false);
auto output_changed = ConvertNodeFormat(graph, node, input_format, index, index, true);
has_changed = input_changed || output_changed;
}
if (has_changed) {
auto cnode = node->cast<CNodePtr>();
auto kernel_graph = graph->cast<KernelGraphPtr>();
MS_EXCEPTION_IF_NULL(kernel_graph);
auto new_node = kernel_graph->NewCNode(cnode);


+ 3
- 0
mindspore/ccsrc/plugin/device/ascend/optimizer/format_type/insert_transdata_for_runop.h View File

@@ -38,7 +38,10 @@ class RunOpInsertTransData : public Pass {

private:
bool InsertTransdataForOutput(const FuncGraphPtr &graph);
bool ConvertNodeFormat(const FuncGraphPtr &graph, const AnfNodePtr &node, const std::string &format,
size_t insert_index, size_t index, bool is_insert) const;
KernelSelectPtr kernel_select_;
size_t input_size_;
};
} // namespace opt
} // namespace mindspore


+ 0
- 1
mindspore/ccsrc/plugin/device/ascend/optimizer/ir_fusion/transposed_update_fusion.h View File

@@ -15,7 +15,6 @@
*/
#ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_IR_FUSION_TRANSPOSED_UPDATE_FUSION_H_
#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_IR_FUSION_TRANSPOSED_UPDATE_FUSION_H_
#include <vector>
#include <string>
#include <utility>
#include <memory>


+ 1
- 0
mindspore/ccsrc/plugin/device/gpu/optimizer/concat_outputs_for_all_gather.cc View File

@@ -18,6 +18,7 @@
#include <string>
#include <tuple>
#include <utility>
#include <algorithm>
#include "backend/common/session/anf_runtime_algorithm.h"
#include "include/common/utils/anfalgo.h"



Loading…
Cancel
Save