forked from huawei/mindspore2022
dynamic shape CPU & GPU
This commit is contained in:
parent
3b24d825bf
commit
adb18b82ca
|
|
@ -34,6 +34,8 @@
|
|||
#include "backend/common/pass/add_akg_kernel_attrs.h"
|
||||
#include "backend/common/pass/sparse_process.h"
|
||||
#include "backend/common/pass/insert_assign_for_custom_op.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/convert_custom_op.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/link_custom_op.h"
|
||||
#include "utils/ms_context.h"
|
||||
#include "include/common/debug/anf_ir_dump.h"
|
||||
|
||||
|
|
@ -164,5 +166,33 @@ void EliminateIllegalDataTypePass(const std::shared_ptr<session::KernelGraph> &k
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DynamicShapeConvertPass(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
|
||||
MS_EXCEPTION_IF_NULL(kernel_graph);
|
||||
MS_LOG(INFO) << "Start dynamic shape convert for kernel graph id:" << kernel_graph->graph_id();
|
||||
#ifdef ENABLE_DUMP_IR
|
||||
auto context_ptr = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
bool save_graphs = context_ptr->get_param<bool>(MS_CTX_SAVE_GRAPHS_FLAG);
|
||||
if (save_graphs) {
|
||||
std::string file_name =
|
||||
"hwopt_d_before_dynamic_shape_convert_graph_" + std::to_string(kernel_graph->graph_id()) + ".ir";
|
||||
DumpIR(file_name, kernel_graph);
|
||||
}
|
||||
#endif
|
||||
auto optimizer = std::make_shared<opt::GraphOptimizer>();
|
||||
auto dynamic_shape_convert_pm = std::make_shared<opt::PassManager>("dynamic_shape_convert_pm");
|
||||
dynamic_shape_convert_pm->AddPass(std::make_shared<opt::dynamic_shape::ConvertCustomOp>());
|
||||
dynamic_shape_convert_pm->AddPass(std::make_shared<opt::dynamic_shape::LinkCustomOp>());
|
||||
optimizer->AddPassManager(dynamic_shape_convert_pm);
|
||||
(void)optimizer->Optimize(kernel_graph);
|
||||
#ifdef ENABLE_DUMP_IR
|
||||
if (save_graphs) {
|
||||
std::string file_name =
|
||||
"hwopt_d_after_dynamic_shape_convert_graph_" + std::to_string(kernel_graph->graph_id()) + ".ir";
|
||||
DumpIR(file_name, kernel_graph);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace opt
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ void CommonFinalOptimization(const std::shared_ptr<session::KernelGraph> &kernel
|
|||
void CommonUnifyMindIR(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
void AddDynamicShapeAttrPass(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
void EliminateIllegalDataTypePass(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
void DynamicShapeConvertPass(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
} // namespace opt
|
||||
} // namespace mindspore
|
||||
|
||||
|
|
|
|||
|
|
@ -14,30 +14,49 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/convert_dynamic_op.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/convert_custom_op.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "backend/common/session/anf_runtime_algorithm.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
#include "backend/common/optimizer/helper.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/ascend_dynamic_shape_helper.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/dynamic_shape_helper.h"
|
||||
#include "utils/ms_context.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt::dynamic_shape {
|
||||
const BaseRef ConvertDynamicOp::DefinePattern() const {
|
||||
VarPtr X = std::make_shared<CondVar>(IsDynamicOp);
|
||||
return BaseRef({X});
|
||||
bool ConvertCustomOp::Run(const FuncGraphPtr &func_graph) {
|
||||
MS_EXCEPTION_IF_NULL(func_graph);
|
||||
auto node_list = TopoSort(func_graph->get_return());
|
||||
for (const auto &node : node_list) {
|
||||
if (!IsRealCNode(node)) {
|
||||
continue;
|
||||
}
|
||||
ConvertCustomOpForNode(node);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const AnfNodePtr ConvertDynamicOp::Process(const FuncGraphPtr &graph, const AnfNodePtr &node, const EquivPtr &) const {
|
||||
MS_EXCEPTION_IF_NULL(graph);
|
||||
void ConvertCustomOp::ConvertCustomOpForNode(const AnfNodePtr &node) const {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto infer_node = GenInferNode(node);
|
||||
auto init_node = GenInitNode(node);
|
||||
auto update_node = GenUpdateNode(node);
|
||||
bool is_dynamic_node = common::AnfAlgo::IsDynamicShape(node);
|
||||
AnfNodePtr infer_node = nullptr;
|
||||
AnfNodePtr init_node = nullptr;
|
||||
AnfNodePtr update_node = nullptr;
|
||||
if (is_dynamic_node) {
|
||||
infer_node = GenInferNode(node);
|
||||
init_node = GenInitNode(node);
|
||||
}
|
||||
|
||||
auto ms_context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(ms_context);
|
||||
if (ms_context->get_param<std::string>(MS_CTX_DEVICE_TARGET) != kCPUDevice) {
|
||||
update_node = GenUpdateNode(node);
|
||||
}
|
||||
|
||||
RelatedCustomActorNode custom_nodes = {infer_node, init_node, update_node};
|
||||
CustomActorNodeManager::Instance().Register(node, custom_nodes);
|
||||
return node;
|
||||
}
|
||||
} // namespace opt::dynamic_shape
|
||||
} // namespace mindspore
|
||||
|
|
@ -14,19 +14,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_GENERAL_OP_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_GENERAL_OP_H
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_CONVERT_CUSTOM_OP_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_CONVERT_CUSTOM_OP_H
|
||||
|
||||
#include "ir/anf.h"
|
||||
#include "backend/common/optimizer/optimizer.h"
|
||||
|
||||
namespace mindspore::opt::dynamic_shape {
|
||||
class ConvertGeneralOp : public PatternProcessPass {
|
||||
class ConvertCustomOp : public Pass {
|
||||
public:
|
||||
explicit ConvertGeneralOp(bool multigraph = true) : PatternProcessPass("convert_general_op", multigraph) {}
|
||||
~ConvertGeneralOp() override = default;
|
||||
const BaseRef DefinePattern() const override;
|
||||
const AnfNodePtr Process(const FuncGraphPtr &graph, const AnfNodePtr &node, const EquivPtr &) const override;
|
||||
ConvertCustomOp() : Pass("convert_custom_op") {}
|
||||
~ConvertCustomOp() override = default;
|
||||
bool Run(const FuncGraphPtr &func_graph) override;
|
||||
|
||||
private:
|
||||
void ConvertCustomOpForNode(const AnfNodePtr &node) const;
|
||||
};
|
||||
} // namespace mindspore::opt::dynamic_shape
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_GENERAL_OP_H
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_CONVERT_CUSTOM_OP_H
|
||||
|
|
@ -14,16 +14,17 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/ascend_dynamic_shape_helper.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/dynamic_shape_helper.h"
|
||||
|
||||
#include <memory>
|
||||
#include "backend/common/session/anf_runtime_algorithm.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
#include "include/common/utils/utils.h"
|
||||
#include "utils/anf_utils.h"
|
||||
#include "kernel/kernel.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace {
|
||||
namespace opt::dynamic_shape {
|
||||
bool IsRealCNode(const BaseRef &n) {
|
||||
if (utils::isa<CNodePtr>(n)) {
|
||||
CNodePtr cnode = utils::cast<CNodePtr>(n);
|
||||
|
|
@ -31,45 +32,6 @@ bool IsRealCNode(const BaseRef &n) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace opt::dynamic_shape {
|
||||
bool IsGeneralOp(const BaseRef &n) {
|
||||
if (IsDynamicOp(n)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsInheritedDynamicOp(n)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsRealCNode(n);
|
||||
}
|
||||
|
||||
bool IsDynamicOp(const BaseRef &n) {
|
||||
if (!IsRealCNode(n)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CNodePtr cnode = utils::cast<CNodePtr>(n);
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
auto op_name = common::AnfAlgo::GetCNodeName(cnode);
|
||||
return kComputeDepend.find(op_name) != kComputeDepend.end();
|
||||
}
|
||||
|
||||
bool IsInheritedDynamicOp(const BaseRef &n) {
|
||||
if (IsDynamicOp(n)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsRealCNode(n)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CNodePtr cnode = utils::cast<CNodePtr>(n);
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
return common::AnfAlgo::IsNodeInputDynamicShape(cnode) || AnfUtils::IsNodeOutputDynamicShape(cnode);
|
||||
}
|
||||
|
||||
AnfNodePtr GenInferNode(const AnfNodePtr &node, bool fake_flag) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
|
|
@ -89,18 +51,25 @@ AnfNodePtr GenInferNode(const AnfNodePtr &node, bool fake_flag) {
|
|||
return infer_node;
|
||||
}
|
||||
|
||||
AnfNodePtr GenInitNode(const AnfNodePtr &node) {
|
||||
AnfNodePtr GenInitNode(const AnfNodePtr &node, bool fake_flag) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto cnode = node->cast<CNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
auto kernel_mod = AnfAlgo::GetKernelMod(cnode);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod);
|
||||
auto init_node = AnfUtils::NewInitActorNode([kernel_mod](void *) { kernel_mod->InitOp(); }, cnode);
|
||||
AnfUtils::CustomActorCallback actor_func;
|
||||
if (fake_flag) {
|
||||
actor_func = [](void *) -> void { return; };
|
||||
} else {
|
||||
auto kernel_mod = AnfAlgo::GetKernelMod(cnode);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod);
|
||||
actor_func = [kernel_mod](void *) { kernel_mod->InitOp(); };
|
||||
}
|
||||
|
||||
auto init_node = AnfUtils::NewInitActorNode(actor_func, cnode, fake_flag);
|
||||
init_node->set_kernel_info(std::make_shared<device::KernelInfo>());
|
||||
return init_node;
|
||||
}
|
||||
|
||||
AnfNodePtr GenUpdateNode(const AnfNodePtr &node, bool just_sync_flag) {
|
||||
AnfNodePtr GenUpdateNode(const AnfNodePtr &node) {
|
||||
// Some not dynamic shape node should sync after launch for latter node.
|
||||
// Use a flag `just_sync_flag` to distinguish them with dynamic ones.
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
|
|
@ -108,19 +77,18 @@ AnfNodePtr GenUpdateNode(const AnfNodePtr &node, bool just_sync_flag) {
|
|||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
auto kernel_mod = AnfAlgo::GetKernelMod(cnode);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod);
|
||||
auto update_node =
|
||||
AnfUtils::NewUpdateActorNode([kernel_mod](void *) { kernel_mod->UpdateOp(); }, cnode, just_sync_flag);
|
||||
auto update_node = AnfUtils::NewUpdateActorNode([kernel_mod](void *) { kernel_mod->UpdateOp(); }, cnode);
|
||||
update_node->set_kernel_info(std::make_shared<device::KernelInfo>());
|
||||
return update_node;
|
||||
}
|
||||
|
||||
bool IsDynUpdate(const AnfNodePtr &node) {
|
||||
bool IsNeedUpdateOp(const AnfNodePtr &node) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto custom_actor_type = AnfUtils::GetCustomActorType(node);
|
||||
if (custom_actor_type != kUpdate) {
|
||||
MS_LOG(EXCEPTION) << node->fullname_with_scope() << " is not a custom update node!";
|
||||
}
|
||||
return !AnfUtils::GetCustomActorJustSyncFlag(node);
|
||||
auto cnode = node->cast<CNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
auto kernel_mod = AnfAlgo::GetKernelMod(cnode);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod);
|
||||
return kernel_mod->IsNeedUpdateOp();
|
||||
}
|
||||
|
||||
CustomActorNodeManager &CustomActorNodeManager::Instance() {
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_ASCEND_DYNAMIC_SHAPE_HELPER_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_ASCEND_DYNAMIC_SHAPE_HELPER_H
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_DYNAMIC_SHAPE_HELPER_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_DYNAMIC_SHAPE_HELPER_H
|
||||
|
||||
#include <string>
|
||||
#include "ir/anf.h"
|
||||
|
|
@ -23,13 +23,11 @@
|
|||
#include "backend/common/optimizer/optimizer.h"
|
||||
|
||||
namespace mindspore::opt::dynamic_shape {
|
||||
bool IsGeneralOp(const BaseRef &n);
|
||||
bool IsDynamicOp(const BaseRef &n);
|
||||
bool IsInheritedDynamicOp(const BaseRef &n);
|
||||
bool IsRealCNode(const BaseRef &n);
|
||||
bool IsNeedUpdateOp(const AnfNodePtr &node);
|
||||
AnfNodePtr GenInferNode(const AnfNodePtr &node, bool fake_flag = false);
|
||||
AnfNodePtr GenInitNode(const AnfNodePtr &node);
|
||||
AnfNodePtr GenUpdateNode(const AnfNodePtr &node, bool just_sync_flag = false);
|
||||
bool IsDynUpdate(const AnfNodePtr &node);
|
||||
AnfNodePtr GenInitNode(const AnfNodePtr &node, bool fake_flag = false);
|
||||
AnfNodePtr GenUpdateNode(const AnfNodePtr &node);
|
||||
|
||||
struct RelatedCustomActorNode {
|
||||
AnfNodePtr infer_node;
|
||||
|
|
@ -60,4 +58,4 @@ class CustomActorNodeManager {
|
|||
OrderedMap<AnfNodePtr, RelatedCustomActorNode> custom_nodes_map_;
|
||||
};
|
||||
} // namespace mindspore::opt::dynamic_shape
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_ASCEND_DYNAMIC_SHAPE_HELPER_H
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_DYNAMIC_SHAPE_HELPER_H
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/link_custom_op.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/link_custom_op.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
#include "backend/common/session/anf_runtime_algorithm.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
#include "backend/common/optimizer/helper.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/ascend_dynamic_shape_helper.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/dynamic_shape_helper.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt::dynamic_shape {
|
||||
|
|
@ -72,7 +72,7 @@ bool LinkInternalOp(const FuncGraphPtr &g, const AnfNodePtr &node, AnfNodePtrLis
|
|||
changed = true;
|
||||
}
|
||||
|
||||
if (IsDynUpdate(custom_nodes.update_node)) {
|
||||
if (IsNeedUpdateOp(node) && custom_nodes.update_node != nullptr) {
|
||||
InsertDepend(g, node, custom_nodes.update_node, depend_nodes); // link launch => update
|
||||
changed = true;
|
||||
}
|
||||
|
|
@ -93,19 +93,31 @@ bool LinkInputOp(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList *d
|
|||
for (size_t i = 0; i < input_num; ++i) {
|
||||
auto prev = common::AnfAlgo::GetPrevNodeOutput(cnode, i);
|
||||
const auto &prev_node = prev.first;
|
||||
if (prev_node == nullptr || !CustomActorNodeManager::Instance().IsRegistered(prev_node)) {
|
||||
if (prev_node == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (!CustomActorNodeManager::Instance().IsRegistered(prev_node)) {
|
||||
continue;
|
||||
}
|
||||
auto prev_custom_nodes = CustomActorNodeManager::Instance().GetCustomActorNodes(prev_node);
|
||||
if (prev_custom_nodes.infer_node != nullptr) {
|
||||
InsertDepend(g, prev_custom_nodes.infer_node, custom_nodes.infer_node,
|
||||
depend_nodes); // link prev.infer => curr.infer
|
||||
// link prev.infer => curr.infer
|
||||
InsertDepend(g, prev_custom_nodes.infer_node, custom_nodes.infer_node, depend_nodes);
|
||||
changed = true;
|
||||
}
|
||||
if (IsDynUpdate(prev_custom_nodes.update_node)) {
|
||||
InsertDepend(g, prev_custom_nodes.update_node, custom_nodes.infer_node,
|
||||
depend_nodes); // link prev.update => curr.infer
|
||||
changed = true;
|
||||
|
||||
if (IsNeedUpdateOp(prev_node)) {
|
||||
if (prev_custom_nodes.update_node != nullptr) {
|
||||
// link prev.update => curr.infer
|
||||
InsertDepend(g, prev_custom_nodes.update_node, custom_nodes.infer_node, depend_nodes);
|
||||
changed = true;
|
||||
} else {
|
||||
// for CPU, its Updateop is in Launch function, so its update_node is set to nullptr, for reduce the time cast
|
||||
// of send messages between actors
|
||||
// link prev.launch => curr.infer
|
||||
InsertDepend(g, prev_node, custom_nodes.infer_node, depend_nodes);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
|
|
@ -135,14 +147,21 @@ bool LinkDependSync(const FuncGraphPtr &g, const CNodePtr &cnode, AnfNodePtrList
|
|||
|
||||
// If previous node is dynamic, so it was already link.
|
||||
auto prev_custom_nodes = CustomActorNodeManager::Instance().GetCustomActorNodes(prev_node);
|
||||
if (IsDynUpdate(prev_custom_nodes.update_node)) {
|
||||
if (IsNeedUpdateOp(prev_node)) {
|
||||
continue;
|
||||
}
|
||||
// 1. Link prev_node => prev_node.update if its update is just sync.
|
||||
InsertDepend(g, prev_node, prev_custom_nodes.update_node, depend_nodes);
|
||||
// 1. Link prev_node => prev_node.update if its update is just sync.
|
||||
// 2. Link prev_node.update => cur_node.infer.
|
||||
InsertDepend(g, prev_custom_nodes.update_node, custom_nodes.infer_node, depend_nodes);
|
||||
if (prev_custom_nodes.update_node != nullptr) {
|
||||
// 1. Link prev_node => prev_node.update if its update is just sync.
|
||||
InsertDepend(g, prev_node, prev_custom_nodes.update_node, depend_nodes);
|
||||
// 2. Link prev_node.update => cur_node.infer.
|
||||
InsertDepend(g, prev_custom_nodes.update_node, custom_nodes.infer_node, depend_nodes);
|
||||
} else {
|
||||
// for CPU, its Updateop is in Launch function, so its update_node is set to nullptr, for reduce the time cast of
|
||||
// send messages between actors
|
||||
// Link prev_node.launch => cur_node.infer.
|
||||
InsertDepend(g, prev_node, custom_nodes.infer_node, depend_nodes);
|
||||
}
|
||||
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
#ifndef MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
|
||||
#include "ir/anf.h"
|
||||
#include "backend/common/optimizer/optimizer.h"
|
||||
|
|
@ -28,4 +28,4 @@ class LinkCustomOp : public Pass {
|
|||
bool Run(const FuncGraphPtr &func_graph) override;
|
||||
};
|
||||
} // namespace mindspore::opt::dynamic_shape
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_GENERAL_OP_H
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_COMMON_OPTIMIZER_DYNAMIC_SHAPE_LINK_CUSTOM_OP_H
|
||||
|
|
@ -554,6 +554,8 @@ constexpr auto kAttrGroupRankIds = "group_rank_ids";
|
|||
|
||||
// TODO(dsj): for ms_function running in graph_mode. should be delete later
|
||||
constexpr auto kAttrMSFunction = "ms_function_graph";
|
||||
// for single_op_compile_and_run condition and set_context GraphMode. should be delete later
|
||||
constexpr auto kAttrSingleOpCompile = "compile_and_run_in_single_op";
|
||||
|
||||
// custom operator func type
|
||||
constexpr auto kCustomTypeAOT = "aot";
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include "kernel/ascend_kernel_mod.h"
|
||||
#include "runtime/device/kernel_runtime.h"
|
||||
#include "runtime/rt.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
namespace mindspore {
|
||||
namespace kernel {
|
||||
void AscendKernelMod::UpdateOp() {
|
||||
|
|
@ -27,5 +28,18 @@ void AscendKernelMod::UpdateOp() {
|
|||
MS_LOG(EXCEPTION) << "Call runtime rtStreamSynchronize failed.";
|
||||
}
|
||||
}
|
||||
|
||||
bool AscendKernelMod::IsNeedUpdateOp() {
|
||||
auto node = anf_node_.lock();
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto cnode = node->cast<CNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
|
||||
auto op_name = common::AnfAlgo::GetCNodeName(cnode);
|
||||
if (kComputeDepend.find(op_name) != kComputeDepend.end()) {
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
return is_need_updateop_;
|
||||
}
|
||||
} // namespace kernel
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class AscendKernelMod : public KernelMod {
|
|||
#endif
|
||||
}
|
||||
void UpdateOp() override;
|
||||
bool IsNeedUpdateOp() override;
|
||||
|
||||
void InitDynamicKernel(const CNodePtr &cnode_ptr, void *stream) {
|
||||
if (dynamic_kernel_ == nullptr) {
|
||||
|
|
|
|||
|
|
@ -219,6 +219,8 @@ class KernelMod {
|
|||
void set_stream(StreamType stream) { stream_ = stream; }
|
||||
StreamType stream() const { return stream_; }
|
||||
void SetAtomicCleanNodes(const std::vector<CNodePtr> &atomic_clean_node);
|
||||
// set true if need to update output's shape after launch in dynamic_shape, like Unique
|
||||
virtual bool IsNeedUpdateOp() { return is_need_updateop_; }
|
||||
|
||||
protected:
|
||||
void InferShape();
|
||||
|
|
@ -238,6 +240,7 @@ class KernelMod {
|
|||
std::vector<size_t> output_size_list_;
|
||||
std::vector<size_t> workspace_size_list_;
|
||||
std::set<uint32_t> depend_list_;
|
||||
bool is_need_updateop_ = false;
|
||||
|
||||
private:
|
||||
void InferShapeForNopNode(const AnfNodePtr &input_node);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "plugin/device/ascend/hal/device/ascend_bucket.h"
|
||||
#include "common/util/error_manager/error_manager.h"
|
||||
#include "plugin/device/ascend/hal/device/ascend_memory_adapter.h"
|
||||
#include "backend/common/optimizer/common_backend_optimization.h"
|
||||
|
||||
#ifndef ENABLE_SECURITY
|
||||
#include "debug/data_dump/dump_json_parser.h"
|
||||
|
|
@ -407,7 +408,7 @@ void AscendDeviceContext::PreprocessBeforeRunGraph(const KernelGraphPtr &graph)
|
|||
} else if (graph->is_dynamic_shape() && IsGraphMode()) {
|
||||
device::ascend::InsertAtomicCleanOps(graph->execution_order(), &node_atomics_);
|
||||
SetAtomicCleanToNodes(graph); // graph mode may can do it too, instead of update execorder
|
||||
opt::AscendDynamicShapeConvert(graph);
|
||||
opt::DynamicShapeConvertPass(graph);
|
||||
AscendStreamAssign::GetInstance().AssignStream(NOT_NULL(graph));
|
||||
AssignOutputNopNodeDeviceAddress(graph);
|
||||
LaunchDeviceLibrary();
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ void DynamicTbeKernelMod::InitOp() {
|
|||
}
|
||||
|
||||
// gen FuncStub
|
||||
if (func_stub_ == nullptr || handle_ == nullptr) {
|
||||
if (func_stub_ == nullptr && handle_ == nullptr) {
|
||||
auto func_stub = KernelManager::GenFuncStub(*kernel_pack_, false, &block_dim_, &handle_, &origin_key_);
|
||||
if (kernel_pack_->kernel_json_info().has_kernel_list) {
|
||||
if (func_stub != 1) {
|
||||
|
|
|
|||
|
|
@ -153,10 +153,6 @@
|
|||
#include "plugin/device/ascend/optimizer/mindir/bn_grad_unify_mindir.h"
|
||||
#include "plugin/device/ascend/optimizer/mindir/all_to_all_unify_mindir.h"
|
||||
#include "plugin/device/ascend/optimizer/mindir/neighbor_exchange_v2_unify_mindir.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/convert_dynamic_op.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/convert_general_op.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/convert_inherited_dynamic_op.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/link_custom_op.h"
|
||||
#include "backend/common/pass/adjust_depend_for_parallel_optimizer_recompute_all_gather.h"
|
||||
#include "plugin/device/ascend/kernel/tbe/tbe_kernel_compile.h"
|
||||
#include "utils/ms_context.h"
|
||||
|
|
@ -621,34 +617,5 @@ void AscendUnifyMindIR(const std::shared_ptr<session::KernelGraph> &graph) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
void AscendDynamicShapeConvert(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
|
||||
auto context_ptr = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context_ptr);
|
||||
#ifdef ENABLE_DUMP_IR
|
||||
bool save_graphs = context_ptr->get_param<bool>(MS_CTX_SAVE_GRAPHS_FLAG);
|
||||
if (save_graphs) {
|
||||
std::string file_name =
|
||||
"hwopt_d_before_dynamic_shape_convert_graph_" + std::to_string(kernel_graph->graph_id()) + ".ir";
|
||||
DumpIR(file_name, kernel_graph);
|
||||
DumpIRProto(kernel_graph, "before_dynamic_shape_convert_hwopt_" + std::to_string(kernel_graph->graph_id()));
|
||||
}
|
||||
#endif
|
||||
auto optimizer = std::make_shared<opt::GraphOptimizer>();
|
||||
auto dynamic_shape_convert_pm = std::make_shared<opt::PassManager>("dynamic_shape_convert_pm");
|
||||
dynamic_shape_convert_pm->AddPass(std::make_shared<opt::dynamic_shape::ConvertDynamicOp>());
|
||||
dynamic_shape_convert_pm->AddPass(std::make_shared<opt::dynamic_shape::ConvertGeneralOp>());
|
||||
dynamic_shape_convert_pm->AddPass(std::make_shared<opt::dynamic_shape::ConvertInheritedDynamicOp>());
|
||||
dynamic_shape_convert_pm->AddPass(std::make_shared<opt::dynamic_shape::LinkCustomOp>());
|
||||
optimizer->AddPassManager(dynamic_shape_convert_pm);
|
||||
(void)optimizer->Optimize(kernel_graph);
|
||||
kernel_graph->SetExecOrderByDefault();
|
||||
#ifdef ENABLE_DUMP_IR
|
||||
if (save_graphs) {
|
||||
std::string file_name =
|
||||
"hwopt_d_after_dynamic_shape_convert_graph_" + std::to_string(kernel_graph->graph_id()) + ".ir";
|
||||
DumpIR(file_name, kernel_graph);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace opt
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ void AscendBackendOptimization(const std::shared_ptr<session::KernelGraph> &kern
|
|||
void AscendBackendIRFusionOptimization(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
void AscendBackendUBFusionOptimization(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
void AscendUnifyMindIR(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
void AscendDynamicShapeConvert(const std::shared_ptr<session::KernelGraph> &kernel_graph);
|
||||
} // namespace opt
|
||||
} // namespace mindspore
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Copyright 2022 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_ASCEND_DYNAMIC_SHAPE_CONVERT_DYNAMIC_OP_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_DYNAMIC_OP_H
|
||||
|
||||
#include "ir/anf.h"
|
||||
#include "backend/common/optimizer/optimizer.h"
|
||||
|
||||
namespace mindspore::opt::dynamic_shape {
|
||||
class ConvertDynamicOp : public PatternProcessPass {
|
||||
public:
|
||||
explicit ConvertDynamicOp(bool multigraph = true) : PatternProcessPass("convert_dynamic_op", multigraph) {}
|
||||
~ConvertDynamicOp() override = default;
|
||||
const BaseRef DefinePattern() const override;
|
||||
const AnfNodePtr Process(const FuncGraphPtr &graph, const AnfNodePtr &node, const EquivPtr &) const override;
|
||||
};
|
||||
} // namespace mindspore::opt::dynamic_shape
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_DYNAMIC_OP_H
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
* Copyright 2022 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 "plugin/device/ascend/optimizer/dynamic_shape/convert_general_op.h"
|
||||
|
||||
#include <memory>
|
||||
#include "backend/common/session/anf_runtime_algorithm.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
#include "backend/common/optimizer/helper.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/ascend_dynamic_shape_helper.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt::dynamic_shape {
|
||||
const BaseRef ConvertGeneralOp::DefinePattern() const {
|
||||
VarPtr X = std::make_shared<CondVar>(IsGeneralOp);
|
||||
return BaseRef({X});
|
||||
}
|
||||
|
||||
const AnfNodePtr ConvertGeneralOp::Process(const FuncGraphPtr &graph, const AnfNodePtr &node, const EquivPtr &) const {
|
||||
MS_EXCEPTION_IF_NULL(graph);
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto stub_infer_node = GenInferNode(node, true);
|
||||
auto init_node = GenInitNode(node);
|
||||
auto sync_node = GenUpdateNode(node, true); // Use to call sync if needed.
|
||||
RelatedCustomActorNode custom_nodes = {stub_infer_node, init_node, sync_node};
|
||||
CustomActorNodeManager::Instance().Register(node, custom_nodes);
|
||||
return node;
|
||||
}
|
||||
} // namespace opt::dynamic_shape
|
||||
} // namespace mindspore
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* Copyright 2022 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 "plugin/device/ascend/optimizer/dynamic_shape/convert_inherited_dynamic_op.h"
|
||||
|
||||
#include <memory>
|
||||
#include "backend/common/session/anf_runtime_algorithm.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
#include "backend/common/optimizer/helper.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/ascend_dynamic_shape_helper.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt::dynamic_shape {
|
||||
const BaseRef ConvertInheritedDynamicOp::DefinePattern() const {
|
||||
VarPtr X = std::make_shared<CondVar>(IsInheritedDynamicOp);
|
||||
return BaseRef({X});
|
||||
}
|
||||
|
||||
const AnfNodePtr ConvertInheritedDynamicOp::Process(const FuncGraphPtr &graph, const AnfNodePtr &node,
|
||||
const EquivPtr &) const {
|
||||
MS_EXCEPTION_IF_NULL(graph);
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
auto infer_node = GenInferNode(node);
|
||||
auto init_node = GenInitNode(node);
|
||||
auto sync_node = GenUpdateNode(node, true); // Use to call sync if needed.
|
||||
RelatedCustomActorNode custom_nodes = {infer_node, init_node, sync_node};
|
||||
CustomActorNodeManager::Instance().Register(node, custom_nodes);
|
||||
return node;
|
||||
}
|
||||
} // namespace opt::dynamic_shape
|
||||
} // namespace mindspore
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Copyright 2022 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_ASCEND_DYNAMIC_SHAPE_CONVERT_INHERITED_DYNAMIC_OP_H
|
||||
#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_INHERITED_DYNAMIC_OP_H
|
||||
|
||||
#include "ir/anf.h"
|
||||
#include "backend/common/optimizer/optimizer.h"
|
||||
|
||||
namespace mindspore::opt::dynamic_shape {
|
||||
class ConvertInheritedDynamicOp : public PatternProcessPass {
|
||||
public:
|
||||
explicit ConvertInheritedDynamicOp(bool multigraph = true)
|
||||
: PatternProcessPass("convert_inherited_dynamic_op", multigraph) {}
|
||||
~ConvertInheritedDynamicOp() override = default;
|
||||
const BaseRef DefinePattern() const override;
|
||||
const AnfNodePtr Process(const FuncGraphPtr &graph, const AnfNodePtr &node, const EquivPtr &) const override;
|
||||
};
|
||||
} // namespace mindspore::opt::dynamic_shape
|
||||
#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_DYNAMIC_SHAPE_CONVERT_GENERAL_OP_H
|
||||
|
|
@ -261,6 +261,13 @@ void CPUDeviceContext::PreprocessBeforeRunGraph(const KernelGraphPtr &graph) con
|
|||
graph->set_execution_order(execution_order);
|
||||
}
|
||||
|
||||
bool CPUDeviceContext::LaunchCustomFunc(const AnfNodePtr &kernel) const {
|
||||
MS_EXCEPTION_IF_NULL(kernel);
|
||||
auto custom_func = AnfUtils::GetCustomFunc(kernel);
|
||||
custom_func(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPUDeviceContext::LaunchKernel(const CNodePtr &kernel, const std::vector<AddressPtr> &inputs,
|
||||
const std::vector<AddressPtr> &workspace, const std::vector<AddressPtr> &outputs,
|
||||
bool) const {
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ class CPUDeviceContext : public DeviceContext {
|
|||
|
||||
bool LoadCollectiveCommLib() override;
|
||||
|
||||
bool LaunchCustomFunc(const AnfNodePtr &kernel) const override;
|
||||
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(CPUDeviceContext);
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ void CoalesceCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
auto indices_shape = common::AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
|
||||
values_size_ = indices_shape[1];
|
||||
shape_size_ = indices_shape[0];
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
void CoalesceCpuKernelMod::Check(const std::vector<kernel::AddressPtr> &inputs) {
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ void NativeCpuKernelMod::Init(const CNodePtr &kernel_node) {
|
|||
cnode_ptr_ = kernel_node;
|
||||
}
|
||||
|
||||
workspace_size_list_.clear();
|
||||
InitKernel(kernel_node);
|
||||
InitInputOutputSize(kernel_node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ void DynamicStitchCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
}
|
||||
|
||||
kernel_func_ = func_list_[index].second;
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
MS_KERNEL_FACTORY_REG(NativeCpuKernelMod, DynamicStitch, DynamicStitchCpuKernelMod);
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ void MapCacheIdxCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
<< "', the first dimension of 'HashMap' should be greater than 0, but got " << hashmap_length_;
|
||||
}
|
||||
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
bool MapCacheIdxCpuKernelMod::Launch(const std::vector<kernel::AddressPtr> &inputs,
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ void MaskedSelectCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
MS_LOG(EXCEPTION) << "MaskedSelect does not support this kernel data type: " << kernel_attr;
|
||||
}
|
||||
kernel_func_ = func_list_[index].second;
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ void MatrixDiagPartCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
MS_LOG(EXCEPTION) << "MatrixDiagPart does not support this kernel data type: " << kernel_attr;
|
||||
}
|
||||
kernel_func_ = func_list_[index].second;
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ void PadAndShiftCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
<< cum_sum_arr_shape.size() << ".";
|
||||
}
|
||||
cum_sum_size_ = cum_sum_arr_shape[0];
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
bool PadAndShiftCpuKernelMod::Launch(const std::vector<kernel::AddressPtr> &inputs,
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ void TensorArrayStackCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
}
|
||||
output_size_list_.push_back(value_size_);
|
||||
input_size_list_.push_back(sizeof(int64_t));
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
void TensorArrayStackCpuKernelMod::PostExecute() {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ void SubAndFilterCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
kernel_name_ = common::AnfAlgo::GetCNodeName(kernel_node);
|
||||
node_wpt_ = kernel_node;
|
||||
input_x_dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
bool SubAndFilterCpuKernelMod::Launch(const std::vector<kernel::AddressPtr> &inputs,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ void UniqueCpuKernelMod::InitKernel(const CNodePtr &kernel_node) {
|
|||
if (common::AnfAlgo::HasNodeAttr(SORTED, kernel_node)) {
|
||||
sorted_ = common::AnfAlgo::GetNodeAttr<bool>(kernel_node, SORTED);
|
||||
}
|
||||
is_need_updateop_ = true;
|
||||
}
|
||||
|
||||
void UniqueCpuKernelMod::InitInputOutputSize(const CNodePtr &kernel_node) {
|
||||
|
|
@ -63,6 +64,7 @@ bool UniqueCpuKernelMod::Launch(const std::vector<kernel::AddressPtr> &inputs,
|
|||
<< "', the dtype of input should be float16, float32, int32, or int64, but got "
|
||||
<< TypeIdToType(dtype_)->ToString();
|
||||
}
|
||||
|
||||
if (!node_wpt_.expired()) {
|
||||
auto node_ = node_wpt_.lock();
|
||||
if (!node_) {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
#include "profiler/device/gpu/gpu_profiling_utils.h"
|
||||
#include "backend/common/session/kernel_graph.h"
|
||||
#include "plugin/device/gpu/kernel/gpu_kernel.h"
|
||||
#include "backend/common/optimizer/common_backend_optimization.h"
|
||||
#ifdef ENABLE_DUMP_IR
|
||||
#include "include/common/debug/rdr/recorder_manager.h"
|
||||
#include "debug/rdr/mem_address_recorder.h"
|
||||
|
|
@ -265,6 +266,14 @@ void GPUDeviceContext::OptimizeGraph(const KernelGraphPtr &graph) const {
|
|||
device::gpu::AssignGpuStream(graph);
|
||||
}
|
||||
|
||||
void GPUDeviceContext::PreprocessBeforeRunGraph(const KernelGraphPtr &graph) const {
|
||||
auto ms_context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(ms_context);
|
||||
if (graph->is_dynamic_shape() && ms_context->get_param<int>(MS_CTX_EXECUTION_MODE) == kGraphMode) {
|
||||
opt::DynamicShapeConvertPass(graph);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUDeviceContext::OptimizeGraphWithoutDeviceInfo(const KernelGraphPtr &graph) const {
|
||||
MS_EXCEPTION_IF_NULL(graph);
|
||||
// Operator fusion optimization.
|
||||
|
|
@ -421,8 +430,21 @@ void GPUDeviceContext::UpdateDynamicShape(const CNodePtr &kernel) const {
|
|||
kernel::NativeGpuKernelMod *gpu_kernel = dynamic_cast<kernel::NativeGpuKernelMod *>(kernel_mod);
|
||||
MS_EXCEPTION_IF_NULL(gpu_kernel);
|
||||
|
||||
gpu_kernel->InferOp();
|
||||
gpu_kernel->InitOp();
|
||||
if (ms_context->get_param<int>(MS_CTX_EXECUTION_MODE) == kPynativeMode ||
|
||||
common::AnfAlgo::GetBooleanAttr(kernel, kAttrSingleOpCompile)) {
|
||||
gpu_kernel->InferOp();
|
||||
gpu_kernel->InitOp();
|
||||
}
|
||||
}
|
||||
|
||||
bool GPUDeviceContext::LaunchCustomFunc(const AnfNodePtr &kernel) const {
|
||||
MS_EXCEPTION_IF_NULL(kernel);
|
||||
auto custom_func = AnfUtils::GetCustomFunc(kernel);
|
||||
if (!BindDeviceToCurrentThread()) {
|
||||
return false;
|
||||
}
|
||||
custom_func(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GPUDeviceContext::LaunchKernel(const CNodePtr &kernel, const std::vector<AddressPtr> &inputs,
|
||||
|
|
@ -436,6 +458,7 @@ bool GPUDeviceContext::LaunchKernel(const CNodePtr &kernel, const std::vector<Ad
|
|||
auto kernel_mod = AnfAlgo::GetKernelMod(kernel);
|
||||
MS_EXCEPTION_IF_NULL(kernel_mod);
|
||||
bool ret = true;
|
||||
|
||||
#ifndef ENABLE_SECURITY
|
||||
const auto &profiler_inst = profiler::gpu::GPUProfiler::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(profiler_inst);
|
||||
|
|
@ -466,7 +489,8 @@ bool GPUDeviceContext::LaunchKernel(const CNodePtr &kernel, const std::vector<Ad
|
|||
}
|
||||
|
||||
// Processing after execution of dynamic kernel to update output shape.
|
||||
if (is_dynamic_shape) {
|
||||
if (is_dynamic_shape && (ms_context->get_param<int>(MS_CTX_EXECUTION_MODE) == kPynativeMode ||
|
||||
common::AnfAlgo::GetBooleanAttr(kernel, kAttrSingleOpCompile))) {
|
||||
kernel::NativeGpuKernelMod *gpu_kernel = dynamic_cast<kernel::NativeGpuKernelMod *>(kernel_mod);
|
||||
MS_EXCEPTION_IF_NULL(gpu_kernel);
|
||||
gpu_kernel->UpdateOp();
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ class GPUDeviceContext : public DeviceContext {
|
|||
|
||||
bool LoadCollectiveCommLib() override;
|
||||
|
||||
void PreprocessBeforeRunGraph(const KernelGraphPtr &graph) const override;
|
||||
|
||||
bool LaunchCustomFunc(const AnfNodePtr &kernel) const override;
|
||||
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(GPUDeviceContext);
|
||||
bool InitDevice();
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class DynamicRangeGpuKernelMod : public NativeGpuKernelMod {
|
|||
max_output_length_ = GetAttr<int64_t>(kernel_node, "maxlen");
|
||||
kernel_node_ = kernel_node;
|
||||
InitSizeLists();
|
||||
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class MatrixDiagPartGpuKernelMod : public NativeGpuKernelMod {
|
|||
InitSizeLists();
|
||||
alignment_ = GetAlignments(common::AnfAlgo::GetNodeAttr<std::string>(kernel_node, kAlignment));
|
||||
kernel_node_ = kernel_node;
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class UniqueGpuKernelMod : public NativeGpuKernelMod {
|
|||
input_shapes.emplace_back(shape);
|
||||
helper_ptr_->CalMemSize(input_shapes, output_shapes);
|
||||
InitSizeLists();
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ bool DatasetIteratorKernelMod::Init(const CNodePtr &kernel_node) {
|
|||
output_size_list_.push_back(bytes);
|
||||
}
|
||||
|
||||
is_need_updateop_ = true;
|
||||
|
||||
#ifndef ENABLE_SECURITY
|
||||
auto profiler_inst = profiler::gpu::GPUProfiler::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(profiler_inst);
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ class DynamicBroadcastGradientArgsGpuKernelMod : public NativeGpuKernelMod {
|
|||
input_size_list_.push_back(s1_size);
|
||||
output_size_list_.push_back(r0_shape[0] * sizeof(S));
|
||||
output_size_list_.push_back(r1_shape[0] * sizeof(S));
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
void ResetResource() noexcept override {
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ class DynamicBroadcastToGpuKernelMod : public NativeGpuKernelMod {
|
|||
}
|
||||
|
||||
InitSizeLists();
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
void ResetResource() noexcept override {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class DynamicReshapeKernelMod : public NativeGpuKernelMod {
|
|||
size_t output_size =
|
||||
std::accumulate(output_shape.begin(), output_shape.end(), data_type_size_, std::multiplies<size_t>());
|
||||
output_size_list_.push_back(output_size);
|
||||
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
void ResetResource() noexcept override {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ bool DynamicStitchKernelMod::Init(const CNodePtr &kernel_node) {
|
|||
workspace_size_list_.push_back(index_type_size);
|
||||
// One output
|
||||
output_size_list_.push_back(output_size);
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class GpuConvertToDynamicShapeGpuKernelMod : public NativeGpuKernelMod {
|
|||
}
|
||||
|
||||
InitSizeLists();
|
||||
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ bool TensorArrayStackKernelMod::Init(const CNodePtr &kernel_node) {
|
|||
value_size_ = ele_size_ * LongToSize(size);
|
||||
}
|
||||
InitSizeLists();
|
||||
is_need_updateop_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -556,6 +556,11 @@ GraphId GraphCompiler::CompileGraph(const session::OpRunInfo &op_run_info, bool
|
|||
|
||||
UpdateRefCountForGraphOutput(outputs_with_index);
|
||||
AnfAlgo::UpdateGraphValidRefPair(graph);
|
||||
|
||||
const std::vector<CNodePtr> &kernels = graph->execution_order();
|
||||
for (const auto &kernel : kernels) {
|
||||
common::AnfAlgo::SetNodeAttr(kAttrSingleOpCompile, MakeValue(true), kernel);
|
||||
}
|
||||
return graph->graph_id();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ class AbstractMutexManager {
|
|||
|
||||
struct CustomActorInfo {
|
||||
CustomActorInfo(const AnfUtils::CustomActorCallback &func, const std::string &type_name, const CNodePtr &cnode,
|
||||
bool is_fake = false, bool is_just_sync = false)
|
||||
: actor_func(func), type_name(type_name), base_cnode_ptr_(cnode), is_fake(is_fake), is_just_sync(is_just_sync) {}
|
||||
bool is_fake = false)
|
||||
: actor_func(func), type_name(type_name), base_cnode_ptr_(cnode), is_fake(is_fake) {}
|
||||
~CustomActorInfo() = default;
|
||||
|
||||
// Key for user data.
|
||||
|
|
@ -65,8 +65,7 @@ struct CustomActorInfo {
|
|||
AnfUtils::CustomActorCallback actor_func = {};
|
||||
std::string type_name;
|
||||
CNodeWeakPtr base_cnode_ptr_;
|
||||
bool is_fake{false}; // For infer
|
||||
bool is_just_sync{false}; // For update
|
||||
bool is_fake{false}; // For infer
|
||||
};
|
||||
using CustomActorInfoPtr = std::shared_ptr<CustomActorInfo>;
|
||||
|
||||
|
|
@ -451,15 +450,13 @@ bool AnfUtils::IsCutomActorNodeSame(const AnfNodePtr &node1, const AnfNodePtr &n
|
|||
MS_EXCEPTION_IF_NULL(actor_info1);
|
||||
std::string actor_type1 = actor_info1->type_name;
|
||||
bool is_fake1 = actor_info1->is_fake;
|
||||
bool is_just_sync1 = actor_info1->is_just_sync;
|
||||
|
||||
auto actor_info2 = node2->user_data<CustomActorInfo>();
|
||||
MS_EXCEPTION_IF_NULL(actor_info2);
|
||||
std::string actor_type2 = actor_info2->type_name;
|
||||
bool is_fake2 = actor_info2->is_fake;
|
||||
bool is_just_sync2 = actor_info2->is_just_sync;
|
||||
|
||||
return (actor_type1 == actor_type2) && (is_fake1 == is_fake2) && (is_just_sync1 == is_just_sync2);
|
||||
return (actor_type1 == actor_type2) && (is_fake1 == is_fake2);
|
||||
}
|
||||
|
||||
std::string AnfUtils::GetCustomActorType(const AnfNodePtr &node) {
|
||||
|
|
@ -498,16 +495,6 @@ CNodePtr AnfUtils::GetCustomActorBaseNode(const AnfNodePtr &node) {
|
|||
return actor_info->base_cnode_ptr_.lock();
|
||||
}
|
||||
|
||||
bool AnfUtils::GetCustomActorJustSyncFlag(const AnfNodePtr &node) {
|
||||
if (!IsCustomActorNode(node)) {
|
||||
MS_LOG(EXCEPTION) << node->fullname_with_scope() << " is not a custom actor node!";
|
||||
}
|
||||
|
||||
auto update_info = node->user_data<CustomActorInfo>();
|
||||
MS_EXCEPTION_IF_NULL(update_info);
|
||||
return update_info->is_just_sync;
|
||||
}
|
||||
|
||||
AnfUtils::CustomActorCallback AnfUtils::GetCustomFunc(const AnfNodePtr &node) {
|
||||
MS_EXCEPTION_IF_NULL(node);
|
||||
if (!IsCustomActorNode(node)) {
|
||||
|
|
@ -519,9 +506,9 @@ AnfUtils::CustomActorCallback AnfUtils::GetCustomFunc(const AnfNodePtr &node) {
|
|||
return actor_info->actor_func;
|
||||
}
|
||||
|
||||
AnfNodePtr AnfUtils::NewInitActorNode(AnfUtils::CustomActorCallback f, const CNodePtr &base_cnode) {
|
||||
AnfNodePtr AnfUtils::NewInitActorNode(AnfUtils::CustomActorCallback f, const CNodePtr &base_cnode, bool is_fake) {
|
||||
MS_EXCEPTION_IF_NULL(base_cnode);
|
||||
auto actor_info = std::make_shared<CustomActorInfo>(f, kInit, base_cnode);
|
||||
auto actor_info = std::make_shared<CustomActorInfo>(f, kInit, base_cnode, is_fake);
|
||||
return NewCustomActorNode(actor_info, base_cnode->func_graph());
|
||||
}
|
||||
|
||||
|
|
@ -531,10 +518,9 @@ AnfNodePtr AnfUtils::NewInferActorNode(AnfUtils::CustomActorCallback f, const CN
|
|||
return NewCustomActorNode(actor_info, base_cnode->func_graph());
|
||||
}
|
||||
|
||||
AnfNodePtr AnfUtils::NewUpdateActorNode(AnfUtils::CustomActorCallback f, const CNodePtr &base_cnode,
|
||||
bool is_just_sync) {
|
||||
AnfNodePtr AnfUtils::NewUpdateActorNode(AnfUtils::CustomActorCallback f, const CNodePtr &base_cnode) {
|
||||
MS_EXCEPTION_IF_NULL(base_cnode);
|
||||
auto actor_info = std::make_shared<CustomActorInfo>(f, kUpdate, base_cnode, false, is_just_sync);
|
||||
auto actor_info = std::make_shared<CustomActorInfo>(f, kUpdate, base_cnode, false);
|
||||
return NewCustomActorNode(actor_info, base_cnode->func_graph());
|
||||
}
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -97,16 +97,15 @@ class MS_CORE_API AnfUtils {
|
|||
|
||||
// Custom actor node is for dynamic shape.
|
||||
// Generate a Init custom actor node.
|
||||
static AnfNodePtr NewInitActorNode(CustomActorCallback f, const CNodePtr &base_cnode);
|
||||
static AnfNodePtr NewInitActorNode(CustomActorCallback f, const CNodePtr &base_cnode, bool is_fake);
|
||||
// Generate a Infer custom actor node. If `is_fake` is set to true, this node is a fake node without any infer action.
|
||||
static AnfNodePtr NewInferActorNode(CustomActorCallback f, const CNodePtr &base_cnode, bool is_fake);
|
||||
// Generate a Update custom actor node. If `is_just_sync` is set to true, this node is just for a stream-sync call.
|
||||
static AnfNodePtr NewUpdateActorNode(CustomActorCallback f, const CNodePtr &base_cnode, bool is_just_sync);
|
||||
static AnfNodePtr NewUpdateActorNode(CustomActorCallback f, const CNodePtr &base_cnode);
|
||||
static bool IsCustomActorNode(const AnfNodePtr &node);
|
||||
static std::string GetCustomActorType(const AnfNodePtr &node);
|
||||
static std::string GetCustomActorName(const AnfNodePtr &node);
|
||||
static CNodePtr GetCustomActorBaseNode(const AnfNodePtr &node);
|
||||
static bool GetCustomActorJustSyncFlag(const AnfNodePtr &node);
|
||||
static CustomActorCallback GetCustomFunc(const AnfNodePtr &node);
|
||||
static bool IsCutomActorNodeSame(const AnfNodePtr &node1, const AnfNodePtr &node2);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -333,7 +333,6 @@ def irbuilder_case():
|
|||
raise ValueError("Precision error, compare result: {}".format(compare_res))
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
|
|
@ -347,7 +346,6 @@ def test_irbuilder_ascend_graph_mode():
|
|||
irbuilder_case()
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_arm_ascend_training
|
||||
@pytest.mark.platform_x86_ascend_training
|
||||
@pytest.mark.env_onecard
|
||||
|
|
|
|||
|
|
@ -14,10 +14,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include <string>
|
||||
#include "utils/ms_context.h"
|
||||
#include "backend/common/session/anf_runtime_algorithm.h"
|
||||
#include "plugin/device/ascend/optimizer/dynamic_shape/ascend_dynamic_shape_helper.h"
|
||||
#include "plugin/device/ascend/optimizer/ascend_backend_optimization.h"
|
||||
#include "backend/common/optimizer/common_backend_optimization.h"
|
||||
#include "backend/common/optimizer/dynamic_shape/dynamic_shape_helper.h"
|
||||
#include "plugin/device/ascend/kernel/tbe/tbe_kernel_mod.h"
|
||||
#include "include/common/utils/anfalgo.h"
|
||||
#include "common/backend_common_test.h"
|
||||
#include "include/common/debug/anf_ir_dump.h"
|
||||
#include "include/common/debug/dump_proto.h"
|
||||
|
|
@ -52,9 +54,16 @@ CNodePtr TestCreateCNode(const KernelGraphPtr &g, const std::string &prim_name,
|
|||
if (cnode == nullptr) {
|
||||
MS_LOG(ERROR) << "Cannot create cnode!";
|
||||
}
|
||||
if (prim_name != "TupleGetItem" && prim_name != "MakeTuple") {
|
||||
common::AnfAlgo::SetNodeAttr(kAttrInputIsDynamicShape, MakeValue(true), cnode);
|
||||
}
|
||||
|
||||
cnode->set_abstract(abstract);
|
||||
auto cnode_kernel_info = std::make_shared<device::KernelInfo>();
|
||||
cnode_kernel_info->set_kernel_mod(std::make_shared<kernel::TbeKernelMod>(std::make_shared<kernel::KernelPack>()));
|
||||
auto anf_node = cnode->cast<AnfNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(anf_node);
|
||||
cnode_kernel_info->set_kernel_mod(
|
||||
std::make_shared<kernel::TbeKernelMod>(std::make_shared<kernel::KernelPack>(), anf_node));
|
||||
cnode->set_kernel_info(cnode_kernel_info);
|
||||
return cnode;
|
||||
}
|
||||
|
|
@ -128,6 +137,9 @@ class TestDynamicShapePass : public BackendCommon {
|
|||
/// \ / \ / \ |
|
||||
/// depend depend depend
|
||||
TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_0) {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kAscendDevice);
|
||||
// construct before graph
|
||||
auto before_fg = std::make_shared<session::KernelGraph>();
|
||||
ASSERT_TRUE(before_fg != nullptr);
|
||||
|
|
@ -140,7 +152,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_0) {
|
|||
before_fg->set_output(before_a_node);
|
||||
|
||||
// run pass
|
||||
AscendDynamicShapeConvert(before_fg);
|
||||
DynamicShapeConvertPass(before_fg);
|
||||
|
||||
// construct after graph
|
||||
auto after_fg = std::make_shared<session::KernelGraph>();
|
||||
|
|
@ -174,6 +186,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_0) {
|
|||
|
||||
// assert
|
||||
EXPECT_TRUE(CheckEqualGraph(after_fg, before_fg));
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kCPUDevice);
|
||||
}
|
||||
|
||||
/// Feature: Dynamic shape
|
||||
|
|
@ -186,6 +199,9 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_0) {
|
|||
/// \ / \ /
|
||||
/// depend depend
|
||||
TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_1) {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kAscendDevice);
|
||||
// construct before graph
|
||||
auto before_fg = std::make_shared<session::KernelGraph>();
|
||||
ASSERT_TRUE(before_fg != nullptr);
|
||||
|
|
@ -196,7 +212,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_1) {
|
|||
before_fg->set_output(before_a_node);
|
||||
|
||||
// run pass
|
||||
AscendDynamicShapeConvert(before_fg);
|
||||
DynamicShapeConvertPass(before_fg);
|
||||
|
||||
// construct after graph
|
||||
auto after_fg = std::make_shared<session::KernelGraph>();
|
||||
|
|
@ -205,7 +221,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_1) {
|
|||
auto after_a_node =
|
||||
TestCreateCNode(after_fg, "A", AnfNodePtrList{after_p}, TestCreateTensor(kFloat32, std::vector<int64_t>{1, 10}));
|
||||
|
||||
auto infer_a = dynamic_shape::GenInferNode(after_a_node, true);
|
||||
auto infer_a = dynamic_shape::GenInferNode(after_a_node);
|
||||
auto init_a = dynamic_shape::GenInitNode(after_a_node);
|
||||
|
||||
auto depend0 = TestCreateDepend(after_fg, AnfNodePtrList{init_a, infer_a});
|
||||
|
|
@ -219,6 +235,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_1) {
|
|||
|
||||
// assert
|
||||
EXPECT_TRUE(CheckEqualGraph(after_fg, before_fg));
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kCPUDevice);
|
||||
}
|
||||
|
||||
/// Feature: Dynamic shape
|
||||
|
|
@ -245,6 +262,9 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_1) {
|
|||
/// \ / Depend
|
||||
/// MakeTuple
|
||||
TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_2) {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kAscendDevice);
|
||||
// construct before graph
|
||||
auto before_fg = std::make_shared<session::KernelGraph>();
|
||||
ASSERT_TRUE(before_fg != nullptr);
|
||||
|
|
@ -265,7 +285,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_2) {
|
|||
before_fg->set_output(before_make_tuple);
|
||||
|
||||
// run pass
|
||||
AscendDynamicShapeConvert(before_fg);
|
||||
DynamicShapeConvertPass(before_fg);
|
||||
|
||||
// construct after graph
|
||||
auto after_fg = std::make_shared<session::KernelGraph>();
|
||||
|
|
@ -307,12 +327,16 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_2) {
|
|||
|
||||
// assert
|
||||
EXPECT_TRUE(CheckEqualGraph(after_fg, before_fg));
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kCPUDevice);
|
||||
}
|
||||
|
||||
/// Feature: Dynamic shape
|
||||
/// Description: Complecate case case.
|
||||
/// Expectation: Graph as expected.
|
||||
TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_3) {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kAscendDevice);
|
||||
// construct before graph
|
||||
auto before_fg = std::make_shared<session::KernelGraph>();
|
||||
ASSERT_TRUE(before_fg != nullptr);
|
||||
|
|
@ -345,7 +369,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_3) {
|
|||
before_fg->set_output(before_make_tuple);
|
||||
|
||||
// run pass
|
||||
AscendDynamicShapeConvert(before_fg);
|
||||
DynamicShapeConvertPass(before_fg);
|
||||
|
||||
// construct after graph
|
||||
auto after_fg = std::make_shared<session::KernelGraph>();
|
||||
|
|
@ -377,7 +401,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_3) {
|
|||
|
||||
auto after_make_tuple = TestCreateMakeTuple(after_fg, AnfNodePtrList{after_c, after_e});
|
||||
|
||||
auto infer_a = dynamic_shape::GenInferNode(after_a, true);
|
||||
auto infer_a = dynamic_shape::GenInferNode(after_a);
|
||||
auto init_a = dynamic_shape::GenInitNode(after_a);
|
||||
|
||||
auto infer_tuple = dynamic_shape::GenInferNode(after_tuple);
|
||||
|
|
@ -397,7 +421,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_3) {
|
|||
auto init_de = dynamic_shape::GenInitNode(after_dync_end);
|
||||
auto update_de = dynamic_shape::GenUpdateNode(after_dync_end);
|
||||
|
||||
auto infer_e = dynamic_shape::GenInferNode(after_e, true);
|
||||
auto infer_e = dynamic_shape::GenInferNode(after_e);
|
||||
auto init_e = dynamic_shape::GenInitNode(after_e);
|
||||
|
||||
auto depend0 = TestCreateDepend(after_fg, AnfNodePtrList{init_a, infer_a});
|
||||
|
|
@ -444,6 +468,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_3) {
|
|||
|
||||
// assert
|
||||
EXPECT_TRUE(CheckEqualGraph(after_fg, before_fg));
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kCPUDevice);
|
||||
}
|
||||
|
||||
/// Feature: Dynamic shape
|
||||
|
|
@ -464,6 +489,9 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_3) {
|
|||
/// \ / \ / \ / \ |
|
||||
/// depend depend depend depend
|
||||
TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_with_depend) {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kAscendDevice);
|
||||
// construct before graph
|
||||
auto before_fg = std::make_shared<session::KernelGraph>();
|
||||
ASSERT_TRUE(before_fg != nullptr);
|
||||
|
|
@ -479,7 +507,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_with_depend) {
|
|||
before_fg->set_output(before_depend_node);
|
||||
|
||||
// run pass
|
||||
AscendDynamicShapeConvert(before_fg);
|
||||
DynamicShapeConvertPass(before_fg);
|
||||
|
||||
// construct after graph
|
||||
auto after_fg = std::make_shared<session::KernelGraph>();
|
||||
|
|
@ -522,6 +550,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_with_depend) {
|
|||
|
||||
// assert
|
||||
EXPECT_TRUE(CheckEqualGraph(after_fg, before_fg));
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kCPUDevice);
|
||||
}
|
||||
|
||||
/// Feature: Dynamic shape
|
||||
|
|
@ -547,6 +576,9 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_with_depend) {
|
|||
/// | /
|
||||
/// depend
|
||||
TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_with_monad) {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kAscendDevice);
|
||||
// construct before graph
|
||||
auto before_fg = std::make_shared<session::KernelGraph>();
|
||||
ASSERT_TRUE(before_fg != nullptr);
|
||||
|
|
@ -569,7 +601,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_with_monad) {
|
|||
before_fg->set_output(before_depend_node);
|
||||
|
||||
// run pass
|
||||
AscendDynamicShapeConvert(before_fg);
|
||||
DynamicShapeConvertPass(before_fg);
|
||||
|
||||
// construct after graph
|
||||
auto after_fg = std::make_shared<session::KernelGraph>();
|
||||
|
|
@ -612,12 +644,16 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_with_monad) {
|
|||
|
||||
// assert
|
||||
EXPECT_TRUE(CheckEqualGraph(after_fg, before_fg));
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kCPUDevice);
|
||||
}
|
||||
|
||||
/// Feature: Dynamic shape
|
||||
/// Description: Need sync case(contain op such as Tile...).
|
||||
/// Expectation: Graph as expected.
|
||||
TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_sync) {
|
||||
auto context = MsContext::GetInstance();
|
||||
MS_EXCEPTION_IF_NULL(context);
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kAscendDevice);
|
||||
// construct before graph
|
||||
auto before_fg = std::make_shared<session::KernelGraph>();
|
||||
ASSERT_TRUE(before_fg != nullptr);
|
||||
|
|
@ -641,7 +677,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_sync) {
|
|||
before_fg->set_output(before_add_node);
|
||||
|
||||
// run pass
|
||||
AscendDynamicShapeConvert(before_fg);
|
||||
DynamicShapeConvertPass(before_fg);
|
||||
|
||||
// construct after graph
|
||||
auto after_fg = std::make_shared<session::KernelGraph>();
|
||||
|
|
@ -669,17 +705,17 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_sync) {
|
|||
auto infer_tile1 = dynamic_shape::GenInferNode(after_tile1_node);
|
||||
auto init_tile1 = dynamic_shape::GenInitNode(after_tile1_node);
|
||||
|
||||
auto infer_a = dynamic_shape::GenInferNode(after_a_node, true);
|
||||
auto infer_a = dynamic_shape::GenInferNode(after_a_node);
|
||||
auto init_a = dynamic_shape::GenInitNode(after_a_node);
|
||||
|
||||
auto infer_b = dynamic_shape::GenInferNode(after_b_node, true);
|
||||
auto infer_b = dynamic_shape::GenInferNode(after_b_node);
|
||||
auto init_b = dynamic_shape::GenInitNode(after_b_node);
|
||||
auto update_b = dynamic_shape::GenUpdateNode(after_b_node, true);
|
||||
auto update_b = dynamic_shape::GenUpdateNode(after_b_node);
|
||||
|
||||
auto infer_tile2 = dynamic_shape::GenInferNode(after_tile2_node, true);
|
||||
auto infer_tile2 = dynamic_shape::GenInferNode(after_tile2_node);
|
||||
auto init_tile2 = dynamic_shape::GenInitNode(after_tile2_node);
|
||||
|
||||
auto infer_add = dynamic_shape::GenInferNode(after_add_node, true);
|
||||
auto infer_add = dynamic_shape::GenInferNode(after_add_node);
|
||||
auto init_add = dynamic_shape::GenInitNode(after_add_node);
|
||||
|
||||
auto depend0 = TestCreateDepend(after_fg, AnfNodePtrList{init_uniq, infer_uniq});
|
||||
|
|
@ -721,6 +757,7 @@ TEST_F(TestDynamicShapePass, test_dynamic_shape_pass_sync) {
|
|||
|
||||
// assert
|
||||
EXPECT_TRUE(CheckEqualGraph(after_fg, before_fg));
|
||||
context->set_param<std::string>(MS_CTX_DEVICE_TARGET, kCPUDevice);
|
||||
}
|
||||
} // namespace opt
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
Loading…
Reference in New Issue