Browse Source

!9848 fix nullptr error when set out shape and type

From: @liubuyu
Reviewed-by: @kisnwang
Signed-off-by:
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
8c98fd301c
1 changed files with 23 additions and 10 deletions
  1. +23
    -10
      mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc

+ 23
- 10
mindspore/ccsrc/backend/session/anf_runtime_algorithm.cc View File

@@ -833,22 +833,35 @@ void AnfRuntimeAlgorithm::SetOutputInferTypeAndShape(const std::vector<TypeId> &
} else if (shapes.size() == 1) { } else if (shapes.size() == 1) {
// single output handle // single output handle
ShapeVector shape_int; ShapeVector shape_int;
auto max_shape = GetOutputMaxShape(node_ptr, 0);
auto min_shape = GetOutputMinShape(node_ptr, 0);
std::transform(shapes[0].begin(), shapes[0].end(), std::back_inserter(shape_int), SizeToLong);
auto abstract = std::make_shared<AbstractTensor>(
TypeIdToType(types[0]), std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape));
auto abstract_ptr = node_ptr->abstract();
abstract::AbstractTensorPtr abstract = nullptr;
if (abstract_ptr != nullptr) {
auto max_shape = GetOutputMaxShape(node_ptr, 0);
auto min_shape = GetOutputMinShape(node_ptr, 0);
std::transform(shapes[0].begin(), shapes[0].end(), std::back_inserter(shape_int), SizeToLong);
abstract = std::make_shared<AbstractTensor>(TypeIdToType(types[0]),
std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape));
} else {
abstract = std::make_shared<AbstractTensor>(TypeIdToType(types[0]), shape_int);
}
node->set_abstract(abstract); node->set_abstract(abstract);
} else { } else {
// multiple output handle // multiple output handle
std::vector<AbstractBasePtr> abstract_list; std::vector<AbstractBasePtr> abstract_list;
for (size_t i = 0; i < types.size(); ++i) { for (size_t i = 0; i < types.size(); ++i) {
ShapeVector shape_int; ShapeVector shape_int;
auto max_shape = GetOutputMaxShape(node_ptr, i);
auto min_shape = GetOutputMinShape(node_ptr, i);
std::transform(shapes[i].begin(), shapes[i].end(), std::back_inserter(shape_int), SizeToLong);
auto abstract = std::make_shared<AbstractTensor>(
TypeIdToType(types[i]), std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape));
auto abstract_ptr = node_ptr->abstract();
abstract::AbstractTensorPtr abstract = nullptr;
if (abstract_ptr != nullptr) {
auto max_shape = GetOutputMaxShape(node_ptr, i);
auto min_shape = GetOutputMinShape(node_ptr, i);
std::transform(shapes[i].begin(), shapes[i].end(), std::back_inserter(shape_int), SizeToLong);
abstract = std::make_shared<AbstractTensor>(TypeIdToType(types[i]),
std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape));
} else {
abstract =
std::make_shared<AbstractTensor>(TypeIdToType(types[i]), std::make_shared<abstract::Shape>(shape_int));
}
abstract_list.emplace_back(abstract); abstract_list.emplace_back(abstract);
} }
auto abstract_tuple = std::make_shared<AbstractTuple>(abstract_list); auto abstract_tuple = std::make_shared<AbstractTuple>(abstract_list);


Loading…
Cancel
Save