!12092 Change L2Norm, merge from r1.1 to master
From: @liangzhibo Reviewed-by: @ginfung Signed-off-by:pull/12092/MERGE
commit
c9aaa70b39
@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT 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 "backend/optimizer/pass/convert_attr_to_unify_mindir.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "utils/check_convert_utils.h"
|
||||||
|
#include "backend/session/anf_runtime_algorithm.h"
|
||||||
|
#include "backend/kernel_compiler/common_utils.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace opt {
|
||||||
|
const AnfNodePtr ConvertAttrToUnifyMindIR::Process(const FuncGraphPtr &, const AnfNodePtr &node,
|
||||||
|
const EquivPtr &) const {
|
||||||
|
if (node == nullptr || !AnfAlgo::IsRealCNodeKernel(node)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
std::vector<AnfNodePtr> todos;
|
||||||
|
if (AnfAlgo::IsGraphKernel(node)) {
|
||||||
|
auto sub_graph = AnfAlgo::GetCNodeFuncGraphPtr(node);
|
||||||
|
MS_EXCEPTION_IF_NULL(sub_graph);
|
||||||
|
kernel::GetValidKernelNodes(sub_graph, &todos);
|
||||||
|
} else {
|
||||||
|
todos.push_back(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &t : todos) {
|
||||||
|
CNodePtr cnode = t->cast<CNodePtr>();
|
||||||
|
auto inputs = cnode->inputs();
|
||||||
|
AnfNodePtr op = inputs[0];
|
||||||
|
if (IsValueNode<Primitive>(op)) {
|
||||||
|
auto prim = GetValueNode<PrimitivePtr>(op);
|
||||||
|
auto attrs = prim->attrs();
|
||||||
|
std::string type_name = prim->name();
|
||||||
|
for (auto attr : attrs) {
|
||||||
|
bool converted = CheckAndConvertUtils::ConvertAttrValueToString(type_name, attr.first, &attr.second);
|
||||||
|
if (converted) {
|
||||||
|
prim->set_attr(attr.first, attr.second);
|
||||||
|
}
|
||||||
|
bool converted_ir_attr = CheckAndConvertUtils::CheckIrAttrtoOpAttr(type_name, attr.first, &attr.second);
|
||||||
|
if (converted_ir_attr) {
|
||||||
|
prim->set_attr(attr.first, attr.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
} // namespace opt
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2021 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT 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_CCSRC_BACKEND_OPTIMIZER_PASS_CONVERT_ATTR_TO_UNIFY_MINDIR_H_
|
||||||
|
#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_PASS_CONVERT_ATTR_TO_UNIFY_MINDIR_H_
|
||||||
|
|
||||||
|
#include "ir/anf.h"
|
||||||
|
#include "backend/optimizer/common/optimizer.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace opt {
|
||||||
|
class ConvertAttrToUnifyMindIR : public PatternProcessPass {
|
||||||
|
public:
|
||||||
|
explicit ConvertAttrToUnifyMindIR(bool multigraph = true)
|
||||||
|
: PatternProcessPass("convert_attr_to_unify_mindir", multigraph) {}
|
||||||
|
~ConvertAttrToUnifyMindIR() override = default;
|
||||||
|
const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override;
|
||||||
|
};
|
||||||
|
} // namespace opt
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_PASS_CONVERT_ATTR_TO_UNIFY_MINDIR_H_
|
Loading…
Reference in new issue