[IE][VPU]: Some KW fixes (#2142)

* Some KW fixes
* Fix printTo in vpu ngraph transformations
This commit is contained in:
Maksim Doronin 2020-09-15 12:42:16 +03:00 committed by GitHub
parent eea5acaacc
commit 27c03b35be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 63 additions and 22 deletions

View File

@ -24,6 +24,4 @@ private:
Transformations transformations;
};
void printTo(std::ostream& stream, const ngraph::NodeTypeInfo& object);
} // namespace vpu

View File

@ -7,3 +7,9 @@
#include "ngraph/node.hpp"
std::vector<std::int64_t> evaluateTargetShape(const ngraph::Output<ngraph::Node>& value);
namespace vpu {
void printTo(std::ostream& stream, const ngraph::NodeTypeInfo& object);
} // namespace vpu

View File

@ -26,7 +26,7 @@ namespace vpu {
template <typename T>
Optional<int> parseNumber(const std::string& s) {
T value;
T value{};
if ((std::istringstream(s) >> value >> std::ws).eof()) {
return {value};
}

View File

@ -21,6 +21,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_unsqueeze.hpp"
#include "vpu/ngraph/transformations/dynamic_to_static_shape_variadic_split.hpp"
#include "vpu/ngraph/utilities.hpp"
#include "vpu/utils/error.hpp"
#include "ngraph/opsets/opset3.hpp"
@ -28,10 +29,6 @@
namespace vpu {
void printTo(std::ostream& stream, const ngraph::NodeTypeInfo& object) {
stream << object.name << " ver. " << object.version;
}
namespace {
using namespace ngraph;
@ -41,7 +38,7 @@ bool isDynamic(const Node& node) {
return std::any_of(outputs.cbegin(), outputs.cend(), [](const Output<const Node>& output) {
VPU_THROW_UNLESS(output.get_partial_shape().rank() != ngraph::Rank::dynamic(),
"DynamicToStaticShape transformation: got dynamic rank for {} with type {} while only static is supported",
output.get_node_shared_ptr()->get_friendly_name(), output.get_node_shared_ptr()->get_type_name());
output.get_node_shared_ptr()->get_friendly_name(), output.get_node_shared_ptr()->get_type_info());
return output.get_partial_shape().is_dynamic();
});
@ -51,7 +48,7 @@ bool validateStaticShapes(const ngraph::Function& function) {
for (const auto& node : function.get_ordered_ops()) {
VPU_THROW_UNLESS(!isDynamic(*node),
"DynamicToStaticShape transformation: after all the transformations there is still dynamism in the network."
" First met node with dynamic output: {} (type: {})", node->get_friendly_name(), node->get_type_name());
" First met node with dynamic output: {} (type: {})", node->get_friendly_name(), node->get_type_info());
}
return true;
}

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_binary_elementwise.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -6,6 +6,7 @@
#include "vpu/ngraph/operations/static_shape_broadcast.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include "vpu/utils/error.hpp"
#include "ngraph/graph_util.hpp"
@ -20,7 +21,7 @@ void dynamicToStaticShapeBroadcast(std::shared_ptr<ngraph::Node> target) {
VPU_THROW_UNLESS(broadcast,
"dynamicToStaticShapeBroadcast transformation is not applicable for {}, "
"it should be {} instead",
target, ngraph::opset3::Broadcast::type_info.name);
target, ngraph::opset3::Broadcast::type_info);
std::shared_ptr<ngraph::vpu::op::StaticShapeBroadcast> staticShapeBroadcast;
if (broadcast->get_broadcast_spec() == ngraph::op::BroadcastType::EXPLICIT) {

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_concat.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"
@ -33,7 +34,7 @@ void dynamicToStaticShapeConcat(std::shared_ptr<ngraph::Node> target) {
VPU_THROW_UNLESS(!dsrInputs.empty(),
"DynamicToStaticShape transformation for {} of type {} expects at least "
"one {} as input, actual types: {}", target->get_friendly_name(),
target->get_type_info().name, ngraph::vpu::op::DynamicShapeResolver::type_info.name,
target->get_type_info(), ngraph::vpu::op::DynamicShapeResolver::type_info,
std::accumulate(inputs.begin(), inputs.end(), std::string(), [](
const std::string& typesStr, const ngraph::Output<ngraph::Node>& input) {
return typesStr + input.get_node_shared_ptr()->get_type_info().name + ", ";
@ -55,8 +56,8 @@ void dynamicToStaticShapeConcat(std::shared_ptr<ngraph::Node> target) {
VPU_THROW_UNLESS(dsrShapeInputValue.get_element_type() == shapeDataType,
"DynamicToStaticShape transformation for {} of type {} expects input "
"shape with {} type from {} argument of type {}, provided {}",
target->get_friendly_name(), target->get_type_info().name,
shapeDataType, dsrNode->get_friendly_name(), dsrNode->get_type_info().name,
target->get_friendly_name(), target->get_type_info(),
shapeDataType, dsrNode->get_friendly_name(), dsrNode->get_type_info(),
dsrShapeInputValue.get_element_type());
return dsrShapeInputValue;
};
@ -85,7 +86,7 @@ void dynamicToStaticShapeConcat(std::shared_ptr<ngraph::Node> target) {
VPU_THROW_UNLESS(staticInputPartialShape.is_static(),
"DynamicToStaticShape transformation for {} of type {} expects static "
"shape on inputs without DSR", target->get_friendly_name(),
target->get_type_info().name);
target->get_type_info());
accumulatedStaticShapeValue[axis] += staticInputPartialShape[axis].get_length();
}
return accumulatedStaticShapeValue;

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_gather.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_matmul.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -6,6 +6,7 @@
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/operations/dynamic_non_max_suppression.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -6,6 +6,7 @@
#include "vpu/ngraph/operations/static_shape_nonzero.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include "vpu/utils/error.hpp"
#include "ngraph/graph_util.hpp"

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_reduce.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -6,6 +6,7 @@
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/operations/out_shape_of_reshape.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"
@ -17,15 +18,18 @@
namespace vpu {
void dynamicToStaticShapeReshape(std::shared_ptr<ngraph::Node> target) {
const auto reshape = ngraph::as_type_ptr<ngraph::opset3::Reshape>(target);
VPU_THROW_UNLESS(reshape, "dynamicToStaticShapeReshape transformation is not applicable for {}, it should be {} instead",
target, ngraph::opset3::Reshape::type_info);
const auto dsr = target->input_value(0).get_node_shared_ptr();
VPU_THROW_UNLESS(ngraph::as_type_ptr<ngraph::vpu::op::DynamicShapeResolver>(dsr),
"DynamicToStaticShape transformation for {} of type {} expects {} as input with index {}",
target->get_friendly_name(), target->get_type_info(), ngraph::vpu::op::DynamicShapeResolver::type_info, 0);
const auto reshape = std::dynamic_pointer_cast<ngraph::opset3::Reshape>(target);
const auto outShapeDescriptor = reshape->input_value(1).get_node_shared_ptr();
const auto replacement = ngraph::as_type_ptr<ngraph::opset3::Constant>(outShapeDescriptor)
const auto replacement = ngraph::is_type<ngraph::opset3::Constant>(outShapeDescriptor)
? reshape->clone_with_new_inputs(reshape->input_values())
: std::make_shared<ngraph::vpu::op::StaticShapeReshape>(reshape);

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_roialign.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_squeeze.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"
@ -18,6 +19,10 @@
namespace vpu {
void dynamicToStaticShapeSqueeze(std::shared_ptr<ngraph::Node> target) {
const auto squeeze = ngraph::as_type_ptr<ngraph::opset3::Squeeze>(target);
VPU_THROW_UNLESS(squeeze, "dynamicToStaticShapeSqueeze transformation is not applicable for {}, it should be {} instead",
target, ngraph::opset3::Squeeze::type_info);
const auto dsr = target->input_value(0).get_node_shared_ptr();
VPU_THROW_UNLESS(std::dynamic_pointer_cast<ngraph::vpu::op::DynamicShapeResolver>(dsr),
"DynamicToStaticShape transformation for {} of type {} expects {} as input with index {}",
@ -27,7 +32,6 @@ void dynamicToStaticShapeSqueeze(std::shared_ptr<ngraph::Node> target) {
VPU_THROW_UNLESS(axes, "DynamicToStaticShape transformation for {} of type {} expects {} as input with index {}",
target->get_friendly_name(), target->get_type_info(), ngraph::op::Constant::type_info, 1);
const auto squeeze = std::dynamic_pointer_cast<ngraph::opset3::Squeeze>(target);
const auto copied = squeeze->clone_with_new_inputs(target->input_values());
const auto shape = dsr->input(1).get_source_output();

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_strided_slice.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -6,6 +6,7 @@
#include "vpu/ngraph/operations/static_shape_topk.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_transpose.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"
@ -15,6 +16,10 @@
namespace vpu {
void dynamicToStaticShapeTranspose(std::shared_ptr<ngraph::Node> target) {
const auto transpose = ngraph::as_type_ptr<ngraph::opset3::Transpose>(target);
VPU_THROW_UNLESS(transpose, "dynamicToStaticShapeTranspose transformation is not applicable for {}, it should be {} instead",
target, ngraph::opset3::Transpose::type_info);
const auto dsr = target->input_value(0).get_node_shared_ptr();
VPU_THROW_UNLESS(ngraph::as_type_ptr<ngraph::vpu::op::DynamicShapeResolver>(dsr),
"DynamicToStaticShape transformation for {} of type {} expects {} as input with index {}",
@ -22,10 +27,9 @@ void dynamicToStaticShapeTranspose(std::shared_ptr<ngraph::Node> target) {
const auto transposition = target->input_value(1).get_node_shared_ptr();
VPU_THROW_UNLESS(ngraph::as_type_ptr<ngraph::opset3::Constant>(transposition),
"DynamicToStaticShape transformation for {] of type {} expects {} as input with index {}",
"DynamicToStaticShape transformation for {} of type {} expects {} as input with index {}",
target->get_friendly_name(), target->get_type_info(), ngraph::opset3::Constant::type_info, 1);
const auto transpose = std::dynamic_pointer_cast<ngraph::opset3::Transpose>(target);
const auto copied = transpose->clone_with_new_inputs(target->input_values());
const auto shape = dsr->input(1).get_source_output();

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_unary_elementwise.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_unsqueeze.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"
@ -19,6 +20,10 @@
namespace vpu {
void dynamicToStaticShapeUnsqueeze(std::shared_ptr<ngraph::Node> target) {
const auto unsqueeze = ngraph::as_type_ptr<ngraph::opset3::Unsqueeze>(target);
VPU_THROW_UNLESS(unsqueeze, "dynamicToStaticShapeUnsqueeze transformation is not applicable for {}, it should be {} instead",
target, ngraph::opset3::Unsqueeze::type_info);
const auto dsr = target->input_value(0).get_node_shared_ptr();
VPU_THROW_UNLESS(std::dynamic_pointer_cast<ngraph::vpu::op::DynamicShapeResolver>(dsr),
"DynamicToStaticShape transformation for {} of type {} expects {} as input with index {}",
@ -28,7 +33,6 @@ void dynamicToStaticShapeUnsqueeze(std::shared_ptr<ngraph::Node> target) {
VPU_THROW_UNLESS(axes, "DynamicToStaticShape transformation for {} of type {} expects {} as input with index {}",
target->get_friendly_name(), target->get_type_info(), ngraph::op::Constant::type_info, 1);
const auto unsqueeze = std::dynamic_pointer_cast<ngraph::opset3::Unsqueeze>(target);
const auto copied = unsqueeze->clone_with_new_inputs(target->input_values());
const auto shape = dsr->input(1).get_source_output();

View File

@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_variadic_split.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/utilities.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"

View File

@ -60,3 +60,11 @@ std::vector<std::int64_t> evaluateTargetShape(const ngraph::Output<ngraph::Node>
const auto shapeConstNode = std::make_shared<ngraph::opset3::Constant>(shapeTensor);
return {shapeConstNode->cast_vector<std::int64_t>()};
}
namespace vpu {
void printTo(std::ostream& stream, const ngraph::NodeTypeInfo& object) {
stream << object.name << " ver. " << object.version;
}
} // namespace vpu

View File

@ -184,6 +184,8 @@ CustomLayer::CustomLayer(std::string configDir, const pugi::xml_node& customLaye
stageOrder.emplace(stageNum, CustomKernel{kernel, _configDir});
}
VPU_THROW_UNLESS(!stageOrder.empty(),
"Error while binding %s custom layer: No kernels are found.", _layerName);
VPU_THROW_UNLESS(stageOrder.begin()->first == 0,
"Error while binding %s custom layer: Stage 0 is not found.", _layerName);
VPU_THROW_UNLESS(stageOrder.rbegin()->first == stageOrder.size() - 1,

View File

@ -135,11 +135,12 @@ private:
case CustomParamType::InputBuffer:
case CustomParamType::OutputBuffer:
case CustomParamType::Data: {
VPU_THROW_UNLESS(ports.find(kp) != ports.end(),
const auto& kpIt = ports.find(kp);
VPU_THROW_UNLESS(kpIt != ports.end(),
"XML specification for %s layer has no definition for '%s' parameter. Layer name: %s",
origLayer()->type, kp, origLayer()->name);
int id = ports.find(kp)->second;
int id = kpIt->second;
serializer.append(static_cast<uint32_t>(0));
serializer.append(static_cast<uint32_t>(id));
break;