Browse Source

!16068 [GraphKernel] clean code for graph kernel on branch r1.2.

From: @chenlei_autodiff
Reviewed-by: @gaoxiong1,@ckey_dou,@gaoxiong1
Signed-off-by: @gaoxiong1
pull/16068/MERGE
mindspore-ci-bot Gitee 5 years ago
parent
commit
f91404ba2c
7 changed files with 20 additions and 16 deletions
  1. +9
    -7
      mindspore/ccsrc/backend/optimizer/graph_kernel/arithmetic_simplify.cc
  2. +1
    -1
      mindspore/ccsrc/backend/optimizer/graph_kernel/shape_ops_splitter.cc
  3. +1
    -1
      mindspore/ccsrc/backend/optimizer/graph_kernel/shape_ops_splitter.h
  4. +4
    -4
      mindspore/ccsrc/backend/optimizer/graph_kernel/substitute_dropout.cc
  5. +1
    -1
      mindspore/ccsrc/backend/optimizer/graph_kernel/substitute_dropout.h
  6. +3
    -1
      mindspore/ccsrc/backend/optimizer/graph_kernel/tensor_promotion.cc
  7. +1
    -1
      mindspore/ccsrc/backend/optimizer/graph_kernel/tensor_promotion.h

+ 9
- 7
mindspore/ccsrc/backend/optimizer/graph_kernel/arithmetic_simplify.cc View File

@@ -250,10 +250,10 @@ AnfNodePtr SimplifySelect(const AnfNodePtr &node) {
return nullptr;
}

#define PERFORM_REPLACE(OldNode, NewNode, Graph, FLAG) \
if ((NewNode) != nullptr) { \
(Graph)->manager()->Replace((OldNode), (NewNode)); \
(FLAG) = true; \
#define PERFORM_REPLACE(OldNode, NewNode, Graph, FLAG) \
if ((NewNode) != nullptr) { \
static_cast<void>((Graph)->manager()->Replace((OldNode), (NewNode))); \
(FLAG) = true; \
}

bool TryTransposeToReshape(const AnfNodePtr &node) {
@@ -261,11 +261,11 @@ bool TryTransposeToReshape(const AnfNodePtr &node) {
auto ori_shape = AnfAlgo::GetPrevNodeOutputInferShape(node, 0);
std::vector<int64_t> remove_one_perm;
for (auto idx : perm) {
if (idx < 0 || IntToSize(idx) >= ori_shape.size()) {
if (idx < 0 || LongToSize(idx) >= ori_shape.size()) {
MS_EXCEPTION(ValueError);
return false;
}
if (ori_shape[idx] != 1) {
if (ori_shape[LongToSize(idx)] != 1) {
remove_one_perm.emplace_back(idx);
}
}
@@ -540,7 +540,9 @@ void EliminateEmptyGraph(const FuncGraphPtr &func_graph) {
auto node = cnode->cast<AnfNodePtr>();
auto new_node = MatchIdentity(node);
if (new_node != nullptr) {
mng->Replace(node, new_node);
if (!mng->Replace(node, new_node)) {
MS_LOG(EXCEPTION) << "Manager replace node failed in arithmetic simplify";
}
}
}
}


+ 1
- 1
mindspore/ccsrc/backend/optimizer/graph_kernel/shape_ops_splitter.cc View File

@@ -67,7 +67,7 @@ void SplitNode(const AnfNodePtr &node, const FuncGraphManagerPtr &mng) {
auto user_node = user->cast<CNodePtr>();
MS_EXCEPTION_IF_NULL(user_node);
for (auto index : indices) {
user_node->set_input(index, split_nodes[i]);
user_node->set_input(IntToSize(index), split_nodes[i]);
}
i++;
}


+ 1
- 1
mindspore/ccsrc/backend/optimizer/graph_kernel/shape_ops_splitter.h View File

@@ -28,7 +28,7 @@ class ShapeOpsSplitter : public Pass {
explicit ShapeOpsSplitter(std::vector<PrimitivePtr> shape_ops)
: Pass("shape_ops_splitter"), shape_ops_(std::move(shape_ops)) {}
~ShapeOpsSplitter() override = default;
bool Run(const FuncGraphPtr &func_graph);
bool Run(const FuncGraphPtr &func_graph) override;

private:
bool Process(const FuncGraphPtr &func_graph);


+ 4
- 4
mindspore/ccsrc/backend/optimizer/graph_kernel/substitute_dropout.cc View File

@@ -31,7 +31,7 @@

namespace mindspore {
namespace opt {
unsigned int SubstituteDropout::seed_ = time(NULL);
int64_t SubstituteDropout::seed_ = time(nullptr);

const BaseRef SubstituteDropout::DefinePattern() const {
VarPtr Xs = std::make_shared<Var>();
@@ -72,7 +72,7 @@ const AnfNodePtr SubstituteDropout::Process(const FuncGraphPtr &func_graph, cons
CNodePtr cnode = node->cast<CNodePtr>();
MS_EXCEPTION_IF_NULL(cnode);
CheckCNodeInputSize(cnode, kDropoutInputTensorNum);
AbstractBasePtr old_abstract = cnode->abstract()->Clone();
auto old_abstract = cnode->abstract()->Clone();
auto shape = AnfAlgo::GetInputDeviceShape(cnode, 0);
ShapeVector shape_i64;
std::transform(shape.begin(), shape.end(), std::back_inserter(shape_i64), [](size_t x) { return SizeToLong(x); });
@@ -98,8 +98,8 @@ const AnfNodePtr SubstituteDropout::Process(const FuncGraphPtr &func_graph, cons

// create new uniform_real_node
auto uniform_real_node = func_graph->NewCNode(uniform_input);
SetNodeAttrSafely("seed", MakeValue(SizeToLong(seed_++)), uniform_real_node);
SetNodeAttrSafely("seed2", MakeValue(SizeToLong(seed_++)), uniform_real_node);
SetNodeAttrSafely("seed", MakeValue(seed_++), uniform_real_node);
SetNodeAttrSafely("seed2", MakeValue(seed_++), uniform_real_node);
auto uniform_abstract = std::make_shared<abstract::AbstractTensor>(std::make_shared<Float>(32), shape_i64);
uniform_real_node->set_abstract(uniform_abstract);
uniform_real_node->set_kernel_info(std::make_shared<device::KernelInfo>());


+ 1
- 1
mindspore/ccsrc/backend/optimizer/graph_kernel/substitute_dropout.h View File

@@ -28,7 +28,7 @@ class SubstituteDropout : public PatternProcessPass {
const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override;

private:
static unsigned int seed_;
static int64_t seed_;
};
} // namespace opt
} // namespace mindspore


+ 3
- 1
mindspore/ccsrc/backend/optimizer/graph_kernel/tensor_promotion.cc View File

@@ -47,7 +47,9 @@ bool TensorPromotion::Run(const FuncGraphPtr &func_graph) {
kernel::GetFuncGraphOutputNodes(fg, &outputs);
auto new_cnode = CreateNewFuseCNode(func_graph, fg, inputs, outputs);
SetNewKernelInfo(new_cnode, fg, inputs, outputs, AnfAlgo::GetProcessor(node));
mng->Replace(node, new_cnode);
if (!mng->Replace(node, new_cnode)) {
MS_LOG(EXCEPTION) << "Manager replace node failed in tensor promotion";
}
changed = true;
}



+ 1
- 1
mindspore/ccsrc/backend/optimizer/graph_kernel/tensor_promotion.h View File

@@ -25,7 +25,7 @@ class TensorPromotion : public Pass {
public:
TensorPromotion() : Pass("tensor_promotion") {}
~TensorPromotion() override = default;
bool Run(const FuncGraphPtr &func_graph);
bool Run(const FuncGraphPtr &func_graph) override;
};
using TensorPromotionPtr = std::shared_ptr<TensorPromotion>;
} // namespace opt


Loading…
Cancel
Save