forked from mindspore-Ecosystem/mindspore
code check clean
This commit is contained in:
parent
273330f59d
commit
19fb9e645d
|
@ -17,6 +17,7 @@
|
|||
#include "backend/optimizer/mem_reuse/mem_reuse.h"
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include "utils/context/graph_kernel_flags.h"
|
||||
#include "backend/optimizer/mem_reuse/mem_reuse_checker.h"
|
||||
#include "backend/optimizer/common/helper.h"
|
||||
|
@ -246,7 +247,7 @@ void MemReuseUtil::SetWkMap(const CNodePtr &kernel, KernelDef *kernel_def_ptr) {
|
|||
}
|
||||
}
|
||||
|
||||
KernelRefCountPtr MemReuseUtil::GetRef(const AnfNodePtr &node, int output_idx) {
|
||||
KernelRefCountPtr MemReuseUtil::GetRef(const AnfNodePtr &node, size_t output_idx) {
|
||||
if (node == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "The node pointer is a nullptr.";
|
||||
}
|
||||
|
@ -254,8 +255,8 @@ KernelRefCountPtr MemReuseUtil::GetRef(const AnfNodePtr &node, int output_idx) {
|
|||
if (node->isa<CNode>() && !HasAbstractMonad(node)) {
|
||||
auto ak_node = node->cast<CNodePtr>();
|
||||
auto key = ak_node.get();
|
||||
MemReuseChecker::GetInstance().CheckOutRef(kernel_output_refs_, ak_node, IntToSize(output_idx));
|
||||
return kernel_output_refs_[key][IntToSize(output_idx)];
|
||||
MemReuseChecker::GetInstance().CheckOutRef(kernel_output_refs_, ak_node, output_idx);
|
||||
return kernel_output_refs_[key][output_idx];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -278,7 +279,7 @@ KernelRefCountPtr MemReuseUtil::GetKernelInputRef(const CNodePtr &kernel, size_t
|
|||
if (IsPrimitive(kernel_input.first, prim::kPrimMakeTuple)) {
|
||||
MS_LOG(EXCEPTION) << "Input node [" << input_node->DebugString() << "]'s input " << input_idx << " is MakeTuple";
|
||||
}
|
||||
auto result = GetRef(kernel_input.first, SizeToInt(kernel_input.second));
|
||||
auto result = GetRef(kernel_input.first, kernel_input.second);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -506,7 +507,9 @@ session::KernelWithIndex MemReuseUtil::VisitKernelWithReturnType(const AnfNodePt
|
|||
visit_nop_node ? visit_kernel_with_return_type_in0pos_cache_ : visit_kernel_with_return_type_in0pos_skip_nop_cache_;
|
||||
std::unordered_map<AnfNodePtr, session::KernelWithIndex>::iterator tag_iter;
|
||||
if (auto iter = cache.find(node); iter == cache.end()) {
|
||||
tag_iter = cache.insert({node, AnfAlgo::VisitKernelWithReturnType(node, i, visit_nop_node)}).first;
|
||||
auto tmp_item = std::pair<AnfNodePtr, session::KernelWithIndex>{
|
||||
node, AnfAlgo::VisitKernelWithReturnType(node, i, visit_nop_node)};
|
||||
tag_iter = cache.emplace(tmp_item).first;
|
||||
} else {
|
||||
tag_iter = iter;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ class MemReuseUtil {
|
|||
// Reset the dynamic used reference count by ref_count_.
|
||||
void ResetDynamicUsedRefCount();
|
||||
|
||||
KernelRefCountPtr GetRef(const AnfNodePtr &node, int output_idx);
|
||||
KernelRefCountPtr GetRef(const AnfNodePtr &node, size_t output_idx);
|
||||
KernelRefCountPtr GetKernelInputRef(const CNodePtr &kernel, size_t input_idx);
|
||||
KernelRefCountPtrList total_refs_list() const { return total_refs_list_; }
|
||||
KernelRefCountPtrList total_wk_ref_list() const { return total_wk_ref_list_; }
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
namespace mindspore {
|
||||
namespace memreuse {
|
||||
MemReuseChecker &MemReuseChecker::GetInstance() {
|
||||
static MemReuseChecker instance;
|
||||
static MemReuseChecker instance{};
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -94,8 +94,7 @@ int64_t MemReuseChecker::CalculOriValue(const KernelGraph *graph) const {
|
|||
if (tensor == nullptr) {
|
||||
continue;
|
||||
}
|
||||
size_t tensor_size = tensor->data().nbytes();
|
||||
auto checker_size = SizeToLong(tensor_size);
|
||||
int64_t checker_size = tensor->data().nbytes();
|
||||
static_value_size += checker_size;
|
||||
}
|
||||
return static_value_size;
|
||||
|
|
|
@ -39,7 +39,7 @@ const AnfNodePtr ConvTransposeToConvBackpropInputPass::Process(const FuncGraphPt
|
|||
auto conv_transpose = node->cast<CNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(conv_transpose);
|
||||
|
||||
if (conv_transpose->size() <= kCNodePrimitiveIdx) {
|
||||
if (conv_transpose->size() == kCNodePrimitiveIdx) {
|
||||
MS_LOG(EXCEPTION) << "Invalid cnode " << node->DebugString() << " input size " << conv_transpose->size();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
namespace mindspore {
|
||||
namespace opt {
|
||||
namespace {
|
||||
AnfNodePtr CreateTensorInput(const AnfNodePtr &node, const KernelGraphPtr &kernel_graph, const AnfNodePtr &input_node) {
|
||||
AnfNodePtr CreateTensorInput(const KernelGraphPtr &kernel_graph, const AnfNodePtr &input_node) {
|
||||
MS_EXCEPTION_IF_NULL(input_node);
|
||||
auto value_node = input_node->cast<ValueNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(value_node);
|
||||
|
@ -76,7 +76,7 @@ AnfNodePtr ConstInputToTensorInput(const FuncGraphPtr &func_graph, const CNodePt
|
|||
for (size_t i = 0; i < inputs.size() - 1; ++i) {
|
||||
auto input_node = inputs[i + 1];
|
||||
if (IsValueNode<Scalar>(input_node) || IsValueNode<ValueTuple>(input_node)) {
|
||||
auto tensor_input = CreateTensorInput(cnode, kernel_graph, input_node);
|
||||
auto tensor_input = CreateTensorInput(kernel_graph, input_node);
|
||||
if (tensor_input == nullptr) {
|
||||
new_inputs.push_back(input_node);
|
||||
continue;
|
||||
|
|
|
@ -77,7 +77,7 @@ AnfNodePtr EliminateIsolatedVirtualNodeInput(const FuncGraphPtr &func_graph, con
|
|||
std::vector<AnfNodePtr> new_depend_inputs = cnode->inputs();
|
||||
new_depend_inputs[kIsolatedDependRealInputIndex + 1] = replace_node;
|
||||
auto new_depend = CreateNewDependNode(func_graph, cnode, new_depend_inputs);
|
||||
func_graph->manager()->Replace(cnode, new_depend);
|
||||
(void)func_graph->manager()->Replace(cnode, new_depend);
|
||||
return new_depend;
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ std::vector<size_t> SearchTransDataAndCast(const CNodePtr &cnode) {
|
|||
if (AnfAlgo::CheckPrimitiveType(input, prim::kPrimCast) ||
|
||||
AnfAlgo::CheckPrimitiveType(input, prim::KPrimTransData) ||
|
||||
AnfAlgo::CheckPrimitiveType(input, prim::kPrimMakeTuple)) {
|
||||
result.emplace_back(i);
|
||||
(void)result.emplace_back(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -205,7 +205,7 @@ const AnfNodePtr OptimizeDependence::Process(const FuncGraphPtr &func_graph, con
|
|||
}
|
||||
// Create a new Depend node to replace the old one if inputs changed.
|
||||
auto new_depend = CreateNewDependNode(func_graph, cnode, new_inputs);
|
||||
func_graph->manager()->Replace(cnode, new_depend);
|
||||
(void)func_graph->manager()->Replace(cnode, new_depend);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@ const AnfNodePtr OptimizeUpdateState::Process(const FuncGraphPtr &func_graph, co
|
|||
MS_EXCEPTION_IF_NULL(manager);
|
||||
auto &node_users = manager->node_users();
|
||||
std::vector<AnfNodePtr> new_inputs;
|
||||
new_inputs.emplace_back(update_state->input(0));
|
||||
new_inputs.emplace_back(update_state->input(kInputIndex));
|
||||
new_inputs.emplace_back(update_state->input(kAttachIndex));
|
||||
(void)new_inputs.emplace_back(update_state->input(0));
|
||||
(void)new_inputs.emplace_back(update_state->input(kInputIndex));
|
||||
(void)new_inputs.emplace_back(update_state->input(kAttachIndex));
|
||||
for (size_t i = kAdditionalAttachIndex; i < update_state->size(); ++i) {
|
||||
auto &attach = update_state->input(i);
|
||||
auto &users = node_users[attach];
|
||||
|
@ -57,7 +57,7 @@ const AnfNodePtr OptimizeUpdateState::Process(const FuncGraphPtr &func_graph, co
|
|||
// If the only user of attach is the UpdateState node, drop the attach node.
|
||||
continue;
|
||||
}
|
||||
new_inputs.emplace_back(attach);
|
||||
(void)new_inputs.emplace_back(attach);
|
||||
}
|
||||
if (new_inputs.size() == update_state->size()) {
|
||||
// Attaches not changed.
|
||||
|
|
|
@ -228,7 +228,7 @@ KernelWithIndex AnfRuntimeAlgorithm::VisitKernel(const AnfNodePtr &anf_node, siz
|
|||
}
|
||||
}
|
||||
|
||||
KernelWithIndex AnfRuntimeAlgorithm::VisitKernelWithReturnType(const AnfNodePtr &anf_node, int index,
|
||||
KernelWithIndex AnfRuntimeAlgorithm::VisitKernelWithReturnType(const AnfNodePtr &anf_node, size_t index,
|
||||
bool visit_nop_node,
|
||||
const std::vector<PrimitivePtr> &return_types) {
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
|
@ -344,7 +344,7 @@ std::vector<KernelWithIndex> AnfRuntimeAlgorithm::GetAllOutputWithIndex(const An
|
|||
}
|
||||
// The output may be the tuple of node, so need visit all the outputs of node.
|
||||
for (size_t i = 0; i < outputs_num; ++i) {
|
||||
auto output_with_index = AnfAlgo::VisitKernelWithReturnType(node, SizeToInt(i), false, return_types);
|
||||
auto output_with_index = AnfAlgo::VisitKernelWithReturnType(node, i, false, return_types);
|
||||
MS_EXCEPTION_IF_NULL(output_with_index.first);
|
||||
|
||||
// The depend and makeTuple node need recurse.
|
||||
|
|
|
@ -66,7 +66,7 @@ class AnfRuntimeAlgorithm {
|
|||
static size_t GetTupleGetItemOutIndex(const CNodePtr &tuple_get_item);
|
||||
// get input_anf_node's real kernel by recurse
|
||||
static KernelWithIndex VisitKernel(const AnfNodePtr &input_anf_node, size_t output_index);
|
||||
static KernelWithIndex VisitKernelWithReturnType(const AnfNodePtr &input_anf_node, int output_index,
|
||||
static KernelWithIndex VisitKernelWithReturnType(const AnfNodePtr &input_anf_node, size_t output_index,
|
||||
bool visit_nop_node = false,
|
||||
const std::vector<PrimitivePtr> &return_types = {
|
||||
prim::kPrimMakeTuple});
|
||||
|
|
|
@ -389,6 +389,9 @@ std::vector<size_t> FracZDeviceShapeWithGroups(const std::vector<size_t> &shape,
|
|||
if (!CheckDims(shape)) {
|
||||
MS_LOG(EXCEPTION) << "Check dims failed.";
|
||||
}
|
||||
if (groups <= 0) {
|
||||
MS_LOG(EXCEPTION) << "The value of groups should be greater than 0, but got " << groups;
|
||||
}
|
||||
size_t group_size = LongToSize(groups);
|
||||
size_t cin_ori = shape[kC];
|
||||
size_t cout_ori = shape[kN] / group_size;
|
||||
|
@ -1607,6 +1610,9 @@ bool NchwFracZTransWithGroups(const FormatArgs &args, void *result, bool to_devi
|
|||
MS_LOG(ERROR) << "Illegal dtype";
|
||||
return false;
|
||||
}
|
||||
if (groups <= 0) {
|
||||
MS_LOG(EXCEPTION) << "The value of groups should be greater than 0, but got " << groups;
|
||||
}
|
||||
auto n_dim = args.host_shape[kN];
|
||||
auto c_dim = args.host_shape[kC];
|
||||
auto h_dim = args.host_shape[kH];
|
||||
|
|
|
@ -555,7 +555,7 @@ bool IsSubCallNode(const AnfNodePtr &node) {
|
|||
|
||||
std::vector<KernelWithIndex> FetchAllRealInputNodeByParameter(const KernelWithIndex &node) {
|
||||
std::vector<KernelWithIndex> parameters;
|
||||
const auto &real_node_with_index = AnfAlgo::VisitKernelWithReturnType(node.first, SizeToInt(node.second));
|
||||
const auto &real_node_with_index = AnfAlgo::VisitKernelWithReturnType(node.first, node.second);
|
||||
const auto &real_node = real_node_with_index.first;
|
||||
if (real_node->isa<Parameter>()) {
|
||||
if (!HasAbstractRef(real_node) && !HasAbstractMonad(real_node)) {
|
||||
|
@ -944,8 +944,8 @@ void ControlNodeParser::FetchFrontValueNode(const std::vector<AnfNodePtr> &contr
|
|||
if (IsInternalParameter(parameter, graph)) {
|
||||
auto front_node_with_index = graph->GetFrontNodeByInternalParameter(parameter);
|
||||
MS_EXCEPTION_IF_NULL(front_node_with_index.first);
|
||||
const auto &front_output_with_index = AnfAlgo::VisitKernelWithReturnType(
|
||||
front_node_with_index.first, SizeToInt(front_node_with_index.second), false);
|
||||
const auto &front_output_with_index =
|
||||
AnfAlgo::VisitKernelWithReturnType(front_node_with_index.first, front_node_with_index.second, false);
|
||||
auto front_output_node = front_output_with_index.first;
|
||||
MS_EXCEPTION_IF_NULL(front_output_node);
|
||||
if (AnfAlgo::CheckPrimitiveType(front_output_node, prim::kPrimSwitch)) {
|
||||
|
|
|
@ -1374,7 +1374,7 @@ void GraphScheduler::LinkDataArrow(KernelActor *const to_actor, const GraphCompi
|
|||
if (from_kernel->isa<Parameter>() && graph_compiler_info.control_node_parser_->IsCallInputKernelGraph(graph)) {
|
||||
const auto &kernel_with_index = GetFrontNodeByKernelGraph(from_kernel, graph);
|
||||
const auto &real_front_node_with_index =
|
||||
AnfAlgo::VisitKernelWithReturnType(kernel_with_index.first, SizeToInt(kernel_with_index.second));
|
||||
AnfAlgo::VisitKernelWithReturnType(kernel_with_index.first, kernel_with_index.second);
|
||||
if (HasAbstractRef(real_front_node_with_index.first)) {
|
||||
(void)to_actor->device_tensor_store_keys_.emplace_back(to_kernel_with_input_idx.second,
|
||||
real_front_node_with_index.first);
|
||||
|
|
Loading…
Reference in New Issue