Skip to content

Commit

Permalink
[CPU] Remove errorPrefix usage for error reporting (openvinotoolkit#2…
Browse files Browse the repository at this point in the history
…8386)

### Details:
Take a first step of unifying error handling infrastructure in CPU
plugin: get rid of `OPENVINO_THROW` and `errorPrefix` class field usage
in favor of `THROW_CPU_NODE_ERR` approach

### Tickets:
 - 160275
  • Loading branch information
aobolensk authored Jan 16, 2025
1 parent 0a20c6f commit 9777fb8
Show file tree
Hide file tree
Showing 101 changed files with 426 additions and 636 deletions.
31 changes: 14 additions & 17 deletions src/plugins/intel_cpu/src/nodes/adaptive_pooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ bool AdaptivePooling::isSupportedOperation(const std::shared_ptr<const ov::Node>
AdaptivePooling::AdaptivePooling(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr context)
: Node(op, context, AdaptivePoolingShapeInferFactory(op)) {
std::string errorMessage;
if (isSupportedOperation(op, errorMessage)) {
errorPrefix = "Adaptive Pooling layer with name '" + getName() + "' ";
} else {
if (!isSupportedOperation(op, errorMessage)) {
OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
}
if (one_of(op->get_type_info(), ov::op::v8::AdaptiveAvgPool::get_type_info_static())) {
Expand All @@ -70,21 +68,21 @@ AdaptivePooling::AdaptivePooling(const std::shared_ptr<ov::Node>& op, const Grap

void AdaptivePooling::getSupportedDescriptors() {
if (getParentEdges().size() != 2)
OPENVINO_THROW(errorPrefix, "has incorrect number of input edges: ", getParentEdges().size());
THROW_CPU_NODE_ERR("has incorrect number of input edges: ", getParentEdges().size());
if (getChildEdges().size() < (algorithm == Algorithm::AdaptivePoolingMax ? 2 : 1))
OPENVINO_THROW(errorPrefix, "has incorrect number of output edges: ", getChildEdges().size());
THROW_CPU_NODE_ERR("has incorrect number of output edges: ", getChildEdges().size());

auto srcRank = getInputShapeAtPort(0).getRank();
if (!one_of(spatialDimsCount, 1, 2, 3)) {
OPENVINO_THROW(errorPrefix, "doesn't support 0th input with rank: ", srcRank);
THROW_CPU_NODE_ERR("doesn't support 0th input with rank: ", srcRank);
}

if (getInputShapeAtPort(1).getRank() != 1) {
OPENVINO_THROW(errorPrefix, "doesn't support 1st input with rank: ", getInputShapeAtPort(1).getRank());
THROW_CPU_NODE_ERR("doesn't support 1st input with rank: ", getInputShapeAtPort(1).getRank());
}

if (getOutputShapeAtPort(0).getRank() != getInputShapeAtPort(0).getRank()) {
OPENVINO_THROW(errorPrefix, "must keep data rank");
THROW_CPU_NODE_ERR("must keep data rank");
}
}

Expand Down Expand Up @@ -136,7 +134,7 @@ void AdaptivePooling::execute(dnnl::stream strm) {
auto inputPrec = getParentEdgeAt(0)->getMemory().getDataType();
auto outputPrec = getChildEdgeAt(0)->getMemory().getDataType();
if (!(inputPrec == dnnl_f32 && outputPrec == dnnl_f32))
OPENVINO_THROW(errorPrefix, "doesn't support demanded precisions");
THROW_CPU_NODE_ERR("doesn't support demanded precisions");

auto& srcMemory0 = getParentEdgeAt(0)->getMemory();
auto& srcMemory1 = getParentEdgeAt(1)->getMemory();
Expand All @@ -159,12 +157,11 @@ void AdaptivePooling::execute(dnnl::stream strm) {
auto* dst = getDstDataAtPortAs<float>(0);

if (static_cast<int>(srcMemory1.getShape().getElementsCount()) != spatialDimsCount)
OPENVINO_THROW(errorPrefix,
"has input spatial dimension (",
srcMemory1.getShape().getElementsCount(),
") inconsistent with pooling vector size (",
spatialDimsCount,
")");
THROW_CPU_NODE_ERR("has input spatial dimension (",
srcMemory1.getShape().getElementsCount(),
") inconsistent with pooling vector size (",
spatialDimsCount,
")");

auto inputDimVector = srcMemory0.getStaticDims();
const int N = static_cast<int>(inputDimVector[0]);
Expand All @@ -185,7 +182,7 @@ void AdaptivePooling::execute(dnnl::stream strm) {
const int blockCount = (isTailCFmt ? 1 : chPadding / blockSize);
auto selectedPrimitiveDescriptor = getSelectedPrimitiveDescriptor();
if (!selectedPrimitiveDescriptor)
OPENVINO_THROW(errorPrefix, "doesn't have primitive descriptors.");
THROW_CPU_NODE_ERR("doesn't have primitive descriptors.");
auto config = selectedPrimitiveDescriptor->getConfig();
auto srcStrides = srcBlockDesc->getStrides();
auto dstStrides = getChildEdgeAt(0)->getMemory().getDescWithType<BlockedMemoryDesc>()->getStrides();
Expand Down Expand Up @@ -231,7 +228,7 @@ void AdaptivePooling::execute(dnnl::stream strm) {
setBinBorders(&wStart, &wEnd, ow, IW, OW);
auto binSize = (dEnd - dStart) * (hEnd - hStart) * (wEnd - wStart);
if (binSize == 0)
OPENVINO_THROW(errorPrefix, "has empty bin");
THROW_CPU_NODE_ERR("has empty bin");
float sum = 0;
for (size_t pixD = dStart; pixD < dEnd; pixD++) {
for (size_t pixH = hStart; pixH < hEnd; pixH++) {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes/adaptive_pooling.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class AdaptivePooling : public Node {
ov::element::Type precision = ov::element::f32;
inline void setBinBorders(size_t* startPtr, size_t* endPtr, size_t idx, size_t inputLength, size_t outputLength);

std::string errorPrefix;

protected:
bool needShapeInfer() const override;
bool needPrepareParams() const override {
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/intel_cpu/src/nodes/batch_to_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ BatchToSpace::BatchToSpace(const std::shared_ptr<ov::Node>& op, const GraphConte
OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
}

errorPrefix = "BatchToSpace layer with name '" + op->get_friendly_name() + "'";

if (inputShapes.size() != 4 || outputShapes.size() != 1)
OPENVINO_THROW(errorPrefix, " has incorrect number of input or output edges!");
THROW_CPU_NODE_ERR("has incorrect number of input or output edges!");

const auto& inDims = getInputShapeAtPort(0).getDims();
const auto& outDims = getOutputShapeAtPort(0).getDims();
if (inDims.size() < 4 || inDims.size() > 5)
OPENVINO_THROW(errorPrefix, " has unsupported 'data' input rank: ", inDims.size());
THROW_CPU_NODE_ERR("has unsupported 'data' input rank: ", inDims.size());
if (inDims.size() != outDims.size())
OPENVINO_THROW(errorPrefix, " has incorrect number of input/output dimensions");
THROW_CPU_NODE_ERR("has incorrect number of input/output dimensions");
}

void BatchToSpace::initSupportedPrimitiveDescriptors() {
Expand All @@ -58,7 +56,7 @@ void BatchToSpace::initSupportedPrimitiveDescriptors() {
const auto precision = getOriginalInputPrecisionAtPort(0);
const std::set<size_t> supported_precision_sizes = {1, 2, 4, 8};
if (supported_precision_sizes.find(precision.size()) == supported_precision_sizes.end())
OPENVINO_THROW(errorPrefix, " has unsupported precision: ", precision.get_type_name());
THROW_CPU_NODE_ERR("has unsupported precision: ", precision.get_type_name());

addSupportedPrimDesc({{LayoutType::nspc, precision},
{LayoutType::ncsp, ov::element::i32},
Expand Down Expand Up @@ -156,7 +154,9 @@ void BatchToSpace::batchToSpaceKernel() {
size_t channels = (inShape5D[1] / blockSize);
channels = channels == 0 ? 1 : channels;
const size_t workAmount = inShape5D[0] * channels;
OPENVINO_ASSERT(workAmount > 0, errorPrefix, " has unsupported work amount == 0");
if (workAmount == 0) {
THROW_CPU_NODE_ERR("has unsupported work amount == 0");
}

parallel_nt(0, [&](const int ithr, const int nthr) {
size_t start(0lu), end(0lu);
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes/batch_to_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class BatchToSpace : public Node {
private:
std::vector<size_t> blockShapeIn;
std::vector<size_t> cropsBeginIn;

std::string errorPrefix;
};

} // namespace node
Expand Down
11 changes: 5 additions & 6 deletions src/plugins/intel_cpu/src/nodes/bin_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,6 @@ BinaryConvolution::BinaryConvolution(const std::shared_ptr<ov::Node>& op, const
: Node(op, context, NgraphShapeInferFactory(op)) {
std::string errorMessage;
if (isSupportedOperation(op, errorMessage)) {
errorPrefix = "BinaryConvolution node with name '" + getName() + "' ";
const auto binConv = ov::as_type_ptr<const ov::opset1::BinaryConvolution>(op);

pad_value = binConv->get_pad_value();
Expand Down Expand Up @@ -980,21 +979,21 @@ void BinaryConvolution::getSupportedDescriptors() {
}

if (getParentEdges().size() != expectedInputEdgesNum)
OPENVINO_THROW(errorPrefix, "has incorrect number of input edges");
THROW_CPU_NODE_ERR("has incorrect number of input edges");

if (getChildEdges().empty())
OPENVINO_THROW(errorPrefix, "has incorrect number of output edges");
THROW_CPU_NODE_ERR("has incorrect number of output edges");

if (getInputShapeAtPort(0).getRank() != 4) {
OPENVINO_THROW(errorPrefix, "doesn't support 0th input with rank: ", getInputShapeAtPort(0).getRank());
THROW_CPU_NODE_ERR("doesn't support 0th input with rank: ", getInputShapeAtPort(0).getRank());
}

if (getInputShapeAtPort(1).getRank() != 4) {
OPENVINO_THROW(errorPrefix, "doesn't support 1st input with rank: ", getInputShapeAtPort(1).getRank());
THROW_CPU_NODE_ERR("doesn't support 1st input with rank: ", getInputShapeAtPort(1).getRank());
}

if (getOutputShapeAtPort(0).getRank() != 4) {
OPENVINO_THROW(errorPrefix, "doesn't support output with rank: ", getOutputShapeAtPort(0).getRank());
THROW_CPU_NODE_ERR("doesn't support output with rank: ", getOutputShapeAtPort(0).getRank());
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes/bin_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ class BinaryConvolution : public Node {
const std::vector<size_t>& s_str,
const std::vector<size_t>& w_str,
const std::vector<size_t>& d_str);

std::string errorPrefix;
};

} // namespace node
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/intel_cpu/src/nodes/broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,20 @@ Broadcast::Broadcast(const std::shared_ptr<ov::Node>& op, const GraphContext::CP
OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
}

errorPrefix = "Broadcast node with name '" + op->get_friendly_name() + "' ";
if (op->get_input_size() != 2 && op->get_input_size() != 3)
OPENVINO_THROW(errorPrefix, "has incorrect number of input edges: ", getParentEdges().size());
THROW_CPU_NODE_ERR("has incorrect number of input edges: ", getParentEdges().size());
if (op->get_output_size() == 0)
OPENVINO_THROW(errorPrefix, "has no output edges.");
THROW_CPU_NODE_ERR("has no output edges.");

auto broadcastOp = ov::as_type_ptr<const ov::op::v1::Broadcast>(op);
if (broadcastOp->get_broadcast_spec().m_type == ov::op::AutoBroadcastType::NUMPY) {
broadcastType = NUMPY;
} else if (broadcastOp->get_broadcast_spec().m_type == ov::op::AutoBroadcastType::EXPLICIT) {
if (op->get_input_size() <= AXES_MAPPING_IDX)
OPENVINO_THROW(errorPrefix, " and EXPLICIT mode must have tree input edges: ", getParentEdges().size());
THROW_CPU_NODE_ERR("and EXPLICIT mode must have tree input edges: ", getParentEdges().size());
broadcastType = EXPLICIT;
} else {
OPENVINO_THROW(errorPrefix, "has unexpected broadcast type: ", broadcastOp->get_broadcast_spec().m_type);
THROW_CPU_NODE_ERR("has unexpected broadcast type: ", broadcastOp->get_broadcast_spec().m_type);
}

if (ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(TARGET_SHAPE_IDX))) {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes/broadcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class Broadcast : public Node, public TileBroadcastCommon {

std::vector<int32_t> targetShape;
std::vector<int32_t> axesMapping;

std::string errorPrefix;
};

} // namespace node
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/intel_cpu/src/nodes/bucketize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ Bucketize::Bucketize(const std::shared_ptr<ov::Node>& op, const GraphContext::CP
OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
}

errorPrefix = "Bucketize layer with name '" + op->get_friendly_name() + "' ";
const auto bucketsize = ov::as_type_ptr<const ov::opset3::Bucketize>(op);
if (bucketsize == nullptr)
OPENVINO_THROW("Operation with name '",
op->get_friendly_name(),
"' is not an instance of Bucketize from opset3.");

if (getOriginalInputsNumber() != 2 || getOriginalOutputsNumber() != 1) {
OPENVINO_THROW(errorPrefix, " has incorrect number of input/output edges!");
THROW_CPU_NODE_ERR("has incorrect number of input/output edges!");
}

// check one attribute
Expand Down Expand Up @@ -181,7 +180,7 @@ void Bucketize::execute(dnnl::stream strm) {
element_type_traits<ov::element::i64>::value_type>();
break;
default:
OPENVINO_THROW(errorPrefix, " has unsupported precision: ", precision_mask);
THROW_CPU_NODE_ERR("has unsupported precision: ", precision_mask);
}
}

Expand All @@ -201,11 +200,11 @@ void Bucketize::prepareParams() {
// update with_bins/num_values/num_bin_values
auto input_tensor_dims = inputTensorMemPtr->getStaticDims();
if (input_tensor_dims.size() < 1) {
OPENVINO_THROW(errorPrefix, " has incorrect dimensions of the input.");
THROW_CPU_NODE_ERR("has incorrect dimensions of the input.");
}
auto input_bin_dims = inputBinsMemPtr->getStaticDims();
if (input_bin_dims.size() != 1) {
OPENVINO_THROW(errorPrefix, " has incorrect dimensions of the boundaries tensor.");
THROW_CPU_NODE_ERR("has incorrect dimensions of the boundaries tensor.");
}
if (input_bin_dims[0] != 0) {
with_bins = true;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_cpu/src/nodes/bucketize.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Bucketize : public Node {
ov::element::Type input_precision;
ov::element::Type boundaries_precision;
ov::element::Type output_precision;
std::string errorPrefix;
};

} // namespace node
Expand Down
14 changes: 5 additions & 9 deletions src/plugins/intel_cpu/src/nodes/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ bool Convert::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, st
Convert::Convert(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr context)
: Node(op, context, PassThroughShapeInferFactory()) {
std::string errorMessage;
if (isSupportedOperation(op, errorMessage)) {
errorPrefix = "Convert node with name '" + getName() + "'";
} else {
if (!isSupportedOperation(op, errorMessage)) {
OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
}

Expand All @@ -61,8 +59,6 @@ Convert::Convert(const Shape& shape,
if (isDynamicNode()) {
shapeInference = std::make_shared<ShapeInferPassThrough>();
}

errorPrefix = "Convert node with name '" + getName() + "'";
}

void Convert::getSupportedDescriptors() {
Expand All @@ -73,9 +69,9 @@ void Convert::getSupportedDescriptors() {
if (inputShapes.empty())
inputShapes.push_back(input->getShape());
if (getParentEdges().size() != 1)
OPENVINO_THROW(errorPrefix, " has incorrect number of input edges");
THROW_CPU_NODE_ERR("has incorrect number of input edges");
if (getChildEdges().empty())
OPENVINO_THROW(errorPrefix, " has incorrect number of output edges");
THROW_CPU_NODE_ERR("has incorrect number of output edges");
}

bool Convert::isSupportedDesc(const MemoryDesc& desc) {
Expand Down Expand Up @@ -157,7 +153,7 @@ void Convert::initSupportedPrimitiveDescriptors() {
supportedPrimitiveDescriptorsBuilder(config);
}
} else {
OPENVINO_THROW(errorPrefix, " has incorrect number of input/output edges");
THROW_CPU_NODE_ERR("has incorrect number of input/output edges");
}
}

Expand Down Expand Up @@ -185,7 +181,7 @@ void Convert::execute(dnnl::stream strm) {
const auto childPaddElemCount = childMem.getDescWithType<BlockedMemoryDesc>()->getPaddedElementsCount();

if (parentPaddElemCount != childPaddElemCount)
OPENVINO_THROW(errorPrefix, " has different elements number in input and output buffers");
THROW_CPU_NODE_ERR("has different elements number in input and output buffers");

MemoryCPtr srcMemory = getSrcMemoryAtPort(0);
MemoryPtr dstMemory = getDstMemoryAtPort(0);
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class Convert : public Node {
ConvertParams convertParams;
std::shared_ptr<ConvertExecutor> execPtr = nullptr;
NodeConfig config;

std::string errorPrefix;
};

} // namespace node
Expand Down
11 changes: 5 additions & 6 deletions src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ CTCGreedyDecoder::CTCGreedyDecoder(const std::shared_ptr<ov::Node>& op, const Gr
OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
}

errorPrefix = "CTCGreedyDecoder layer with name '" + op->get_friendly_name() + "' ";
if (getOriginalInputsNumber() != 2)
OPENVINO_THROW(errorPrefix, "has invalid number of input edges: ", getOriginalInputsNumber());
THROW_CPU_NODE_ERR("has invalid number of input edges: ", getOriginalInputsNumber());
if (getOriginalOutputsNumber() != 1)
OPENVINO_THROW(errorPrefix, "has invalid number of outputs edges: ", getOriginalOutputsNumber());
THROW_CPU_NODE_ERR("has invalid number of outputs edges: ", getOriginalOutputsNumber());

const auto& dataDims = getInputShapeAtPort(DATA_INDEX).getDims();
const auto& seqDims = getInputShapeAtPort(SEQUENCE_LENGTH_INDEX).getDims();

if (!dimsEqualWeak(dataDims[0], seqDims[0]) || !dimsEqualWeak(dataDims[1], seqDims[1]))
OPENVINO_THROW(errorPrefix, "has invalid input shapes.");
THROW_CPU_NODE_ERR("has invalid input shapes.");

auto greedyDecOp = ov::as_type_ptr<const ov::op::v0::CTCGreedyDecoder>(op);
mergeRepeated = greedyDecOp->get_ctc_merge_repeated();
Expand All @@ -57,11 +56,11 @@ void CTCGreedyDecoder::initSupportedPrimitiveDescriptors() {

ov::element::Type inDataPrecision = getOriginalInputPrecisionAtPort(DATA_INDEX);
if (!one_of(inDataPrecision, ov::element::f32, ov::element::bf16, ov::element::f16))
OPENVINO_THROW(errorPrefix, "has unsupported 'data' input precision: ", inDataPrecision);
THROW_CPU_NODE_ERR("has unsupported 'data' input precision: ", inDataPrecision);

ov::element::Type seqLenPrecision = getOriginalInputPrecisionAtPort(SEQUENCE_LENGTH_INDEX);
if (!one_of(seqLenPrecision, ov::element::f32, ov::element::bf16, ov::element::f16))
OPENVINO_THROW(errorPrefix, "has unsupported 'sequence_length' input precision: ", seqLenPrecision);
THROW_CPU_NODE_ERR("has unsupported 'sequence_length' input precision: ", seqLenPrecision);

addSupportedPrimDesc({{LayoutType::ncsp, ov::element::f32}, {LayoutType::ncsp, ov::element::f32}},
{{LayoutType::ncsp, ov::element::f32}},
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes/ctc_greedy_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class CTCGreedyDecoder : public Node {
const size_t DATA_INDEX = 0lu;
const size_t SEQUENCE_LENGTH_INDEX = 1lu;
bool mergeRepeated;

std::string errorPrefix;
};

} // namespace node
Expand Down
Loading

0 comments on commit 9777fb8

Please sign in to comment.