Skip to content

Commit 1b69082

Browse files
committed
Merge remote-tracking branch 'upstream/master' into gpu_l0_enable_onednn
2 parents cfb7f82 + e3f6861 commit 1b69082

File tree

35 files changed

+510
-62
lines changed

35 files changed

+510
-62
lines changed

src/core/shape_inference/include/space_to_batch_shape_inference.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ std::vector<TRShape> shape_infer(const SpaceToBatch* op,
7070
for (auto idx = spatial_dim_offset; idx < data_rank_size; ++idx) {
7171
NODE_VALIDATION_CHECK(op, (*blocks)[idx] > 0, "block_shape values must be greater than 0");
7272

73-
const auto padded_dim = data_shape[idx] + static_cast<TVal>((*pads_begin)[idx] + (*pads_end)[idx]);
73+
const auto padded_dim =
74+
data_shape[idx] + static_cast<TVal>((*pads_begin)[idx]) + static_cast<TVal>((*pads_end)[idx]);
7475
const auto divisor = static_cast<TVal>((*blocks)[idx]);
7576

7677
if (static_cast<int64_t>(padded_dim.get_max_length()) == dim::inf_bound) {

src/core/src/op/space_to_batch.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
#include <cmath>
88
#include <cstddef>
9+
#include <limits>
910
#include <memory>
1011
#include <numeric>
1112

1213
#include "itt.hpp"
14+
#include "openvino/core/memory_util.hpp"
1315
#include "openvino/core/shape.hpp"
1416
#include "openvino/op/util/attr_types.hpp"
1517
#include "openvino/op/util/precision_sensitive_attribute.hpp"
@@ -100,10 +102,29 @@ bool evaluate(TensorVector& outputs, const TensorVector& inputs) {
100102

101103
Shape padded_shape(data_shape.size());
102104
for (size_t i = 0; i < data_shape.size(); ++i) {
103-
padded_shape[i] = data_shape[i] + pads_begin_vec[i] + pads_end_vec[i];
105+
OPENVINO_ASSERT(pads_begin_vec[i] >= 0,
106+
"SpaceToBatch: pads_begin[",
107+
i,
108+
"] must be non-negative, got ",
109+
pads_begin_vec[i]);
110+
OPENVINO_ASSERT(pads_end_vec[i] >= 0,
111+
"SpaceToBatch: pads_end[",
112+
i,
113+
"] must be non-negative, got ",
114+
pads_end_vec[i]);
115+
const auto pb = static_cast<size_t>(pads_begin_vec[i]);
116+
const auto pe = static_cast<size_t>(pads_end_vec[i]);
117+
OPENVINO_ASSERT(data_shape[i] <= std::numeric_limits<size_t>::max() - pb &&
118+
data_shape[i] + pb <= std::numeric_limits<size_t>::max() - pe,
119+
"SpaceToBatch: padded dimension ",
120+
i,
121+
" overflows");
122+
padded_shape[i] = data_shape[i] + pb + pe;
104123
}
105124

106-
std::vector<char> padded_data(shape_size(padded_shape) * elem_size);
125+
const auto padded_byte_size = ov::util::get_memory_size_safe(data.get_element_type(), padded_shape);
126+
OPENVINO_ASSERT(padded_byte_size.has_value(), "SpaceToBatch: padded shape size overflows");
127+
std::vector<char> padded_data(*padded_byte_size);
107128
reference::pad(static_cast<const char*>(data.data()),
108129
pad_value,
109130
padded_data.data(),
@@ -122,8 +143,8 @@ bool evaluate(TensorVector& outputs, const TensorVector& inputs) {
122143
std::iota(plain_axes_order.begin(), plain_axes_order.end(), 0);
123144

124145
std::vector<char> flat_data(padded_data.begin(), padded_data.end());
125-
std::vector<char> dispersed_data(shape_size(data_shape) * elem_size);
126-
std::vector<char> post_transpose_data(shape_size(data_shape) * elem_size);
146+
std::vector<char> dispersed_data(*padded_byte_size);
147+
std::vector<char> post_transpose_data(*padded_byte_size);
127148

128149
for (int64_t block_idx = block_values_size - 1; block_idx >= 0; --block_idx) {
129150
int64_t sq_shape_idx = block_values_size - 1;

src/frontends/paddle/src/op/partial_ops.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace op {
1212

1313
NamedOutputs partial_ops(const NodeContext& node, const std::string type) {
1414
auto x = node.get_ng_inputs("X");
15+
PADDLE_OP_CHECK(node, x.size() == 2, "partial_ops requires exactly 2 inputs in X.");
1516
const auto start_index = node.get_attribute<int>("start_index");
1617
const auto length = node.get_attribute<int>("length");
1718
PADDLE_OP_CHECK(node, x[0].get_partial_shape().rank().get_length() == 2, "partial ops only support 2-D Tensor");

src/frontends/paddle/tests/read_paddle_model_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,18 @@ TEST(Paddle_Reader_Tests, ImportBasicModelToCoreWstring) {
307307
ASSERT_TRUE(res.valid) << res.message;
308308
}
309309
#endif
310+
311+
TEST(Paddle_Reader_Tests, LoadModelWithPartialOpsInsufficientInputs) {
312+
auto model =
313+
FrontEndTestUtils::make_model_path(std::string(TEST_PADDLE_MODELS_DIRNAME) + "partial_sum_oob/partial_sum_oob" +
314+
std::string(TEST_PADDLE_MODEL_EXT));
315+
316+
ov::Core core;
317+
try {
318+
core.read_model(model);
319+
FAIL() << "Expected load to fail due to insufficient X inputs for partial_sum";
320+
} catch (const std::exception& ex) {
321+
const std::string msg = ex.what();
322+
ASSERT_NE(msg.find("partial_ops requires exactly 2 inputs in X."), std::string::npos) << msg;
323+
}
324+
}

src/frontends/paddle/tests/test_models/gen_scripts/generate_partial_sum.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,48 @@
55
# partial_sum paddle model generator
66
#
77
import numpy as np
8+
import os
89
from save_model import saveModel
910
import paddle
1011
import sys
1112

1213

14+
def _get_framework_pb2():
15+
try:
16+
from paddle.fluid.proto import framework_pb2
17+
return framework_pb2
18+
except Exception:
19+
pass
20+
try:
21+
from paddle.base.proto import framework_pb2
22+
return framework_pb2
23+
except Exception:
24+
from paddle.framework.proto import framework_pb2
25+
return framework_pb2
26+
27+
28+
def _corrupt_partial_sum_inputs(model_path: str):
29+
framework_pb2 = _get_framework_pb2()
30+
prog = framework_pb2.ProgramDesc()
31+
with open(model_path, "rb") as f:
32+
prog.ParseFromString(f.read())
33+
34+
modified = False
35+
for block in prog.blocks:
36+
for op in block.ops:
37+
if op.type == "partial_sum":
38+
for inp in op.inputs:
39+
if inp.parameter == "X" and len(inp.arguments) > 1:
40+
del inp.arguments[1:]
41+
modified = True
42+
43+
if not modified:
44+
raise RuntimeError("Failed to modify partial_sum X inputs in model")
45+
46+
with open(model_path, "wb") as f:
47+
f.write(prog.SerializeToString())
48+
49+
1350
def partial_sum(name: str, x, y, start_index=0, length=-1):
1451
paddle.enable_static()
1552

@@ -64,5 +101,12 @@ def main():
64101
y = np.random.randint(-10, 10, [8, 10]).astype(dtype)
65102
partial_sum("partial_sum_3", x, y, start_index=1, length=5)
66103

104+
dtype = 'float32'
105+
x = np.random.randn(4, 8).astype(dtype)
106+
y = np.random.randn(4, 8).astype(dtype)
107+
partial_sum("partial_sum_oob", x, y, start_index=0, length=4)
108+
model_path = os.path.join(sys.argv[1], "partial_sum_oob", "partial_sum_oob.pdmodel")
109+
_corrupt_partial_sum_inputs(model_path)
110+
67111
if __name__ == "__main__":
68112
main()

src/frontends/pytorch/src/utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ std::deque<Output<Node>> get_list_as_outputs(const Output<Node>& start, bool uns
680680
} else if (op_type == "aten::add") {
681681
// Insert at beginning because we're walking backward through the chain.
682682
// Elements from RHS list come before any elements appended after this add operation.
683-
auto&& rhs_list = get_list_as_outputs(fw_node->get_input_source_output(1));
683+
auto&& rhs_list = get_list_as_outputs(fw_node->get_input_source_output(1), unsqueeze_for_concat);
684684
res.insert(res.begin(), rhs_list.begin(), rhs_list.end());
685685
} else {
686686
break;

src/plugins/intel_cpu/src/nodes/psroi_pooling.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ PSROIPooling::PSROIPooling(const std::shared_ptr<ov::Node>& op, const GraphConte
8585
const auto defPsroi = ov::as_type_ptr<const ov::op::v1::DeformablePSROIPooling>(op);
8686

8787
noTrans = op->get_input_size() == 2;
88+
inBatchNum = op->get_input_shape(0)[0];
8889
CPU_NODE_ASSERT(op->get_input_shape(0).size() == 4,
8990
"has first input with incorrect rank: " + std::to_string(op->get_input_shape(0).size()));
9091
CPU_NODE_ASSERT(op->get_input_shape(1).size() == 2,
@@ -619,6 +620,7 @@ void PSROIPooling::executeSpecified() {
619620
cpu_parallel->parallel_for(realRois, [&](int currentRoi) {
620621
const float* bottomRois = bottomRoisBeginning + currentRoi * 5;
621622
auto roiBatchInd = static_cast<int>(bottomRois[0]);
623+
OPENVINO_ASSERT(roiBatchInd <= inBatchNum, "required batch index > batch amount");
622624
if (getAlgorithm() == Algorithm::PSROIPoolingAverage) {
623625
executeAverage(srcData, dstData, bottomRois, currentRoi, roiBatchInd, *srcDesc, *dstDesc);
624626
} else if (getAlgorithm() == Algorithm::PSROIPoolingBilinear) {

src/plugins/intel_cpu/src/nodes/psroi_pooling.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class PSROIPooling : public Node {
4848
int nh = 0;
4949
int nw = 0;
5050

51+
int inBatchNum = 0;
52+
5153
// for Deformable PSROIPolling
5254
bool noTrans;
5355
int partSize = 1;

src/plugins/intel_cpu/src/nodes/roi_pooling.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ size_t RoiPoolingKey::hash() const {
377377
seed = hash_combine(seed, refParams.mb);
378378
seed = hash_combine(seed, refParams.c);
379379
seed = hash_combine(seed, refParams.nb_c);
380+
seed = hash_combine(seed, refParams.b_num);
380381
seed = hash_combine(seed, refParams.c_block);
381382
seed = hash_combine(seed, refParams.nb_c_blocking);
382383
seed = hash_combine(seed, refParams.ih);
@@ -546,9 +547,12 @@ void ROIPooling::prepareParams() {
546547
const auto& inDims = getParentEdgeAt(0)->getMemory().getStaticDims();
547548
const auto& outDims = getChildEdgeAt(0)->getMemory().getStaticDims();
548549

550+
const auto& featureShape = getParentEdgeAt(0)->getMemory().getStaticDims();
551+
549552
refParams.mb = outDims[0];
550553
refParams.c = rnd_up(inDims[1], refParams.c_block);
551554
refParams.nb_c = refParams.c / refParams.c_block;
555+
refParams.b_num = featureShape[0];
552556
refParams.ih = inDims[2];
553557
refParams.iw = inDims[3];
554558
refParams.oh = outDims[2];
@@ -619,6 +623,9 @@ class ROIPooling::ROIPoolingJitExecutor : public ROIPooling::ROIPoolingExecutor
619623
if (roi_batch_ind == -1) {
620624
break;
621625
}
626+
OPENVINO_ASSERT(0 <= roi_batch_ind && roi_batch_ind <= jpp.b_num,
627+
"takes incorrect roi_ind, max roi_ind = ",
628+
jpp.b_num);
622629
}
623630

624631
cpuParallel->parallel_for4d(MB, cb_work, jpp.oh, jpp.ow, [&](int n, int cbb, int oh, int ow) {
@@ -636,6 +643,9 @@ class ROIPooling::ROIPoolingJitExecutor : public ROIPooling::ROIPoolingExecutor
636643
const auto* src_roi_ptr = &src_roi[roi_off];
637644

638645
auto roi_batch_ind = static_cast<int>(src_roi_ptr[0]);
646+
OPENVINO_ASSERT(0 <= roi_batch_ind && roi_batch_ind <= jpp.b_num,
647+
"takes incorrect roi_ind, max roi_ind = ",
648+
jpp.b_num);
639649

640650
if (jpp.alg == Algorithm::ROIPoolingMax) {
641651
auto roi_start_w = static_cast<int>(round(src_roi_ptr[1] * jpp.spatial_scale));
@@ -758,6 +768,9 @@ class ROIPooling::ROIPoolingRefExecutor : public ROIPooling::ROIPoolingExecutor
758768
if (roi_batch_ind == -1) {
759769
break;
760770
}
771+
OPENVINO_ASSERT(0 <= roi_batch_ind && roi_batch_ind <= jpp.b_num,
772+
"takes incorrect roi_ind, max roi_ind = ",
773+
jpp.b_num);
761774
}
762775

763776
cpuParallel->parallel_for4d(MB, cb_work, jpp.oh, jpp.ow, [&](int n, int cbb, int oh, int ow) {
@@ -780,6 +793,9 @@ class ROIPooling::ROIPoolingRefExecutor : public ROIPooling::ROIPoolingExecutor
780793
const auto* src_roi_ptr = &src_roi[roi_off];
781794

782795
auto roi_batch_ind = static_cast<int>(src_roi_ptr[0]);
796+
OPENVINO_ASSERT(0 <= roi_batch_ind && roi_batch_ind <= jpp.b_num,
797+
"takes incorrect roi_ind, max roi_ind = ",
798+
jpp.b_num);
783799

784800
if (jpp.alg == Algorithm::ROIPoolingMax) {
785801
auto roi_start_w = static_cast<int>(round(src_roi_ptr[1] * jpp.spatial_scale));

src/plugins/intel_cpu/src/nodes/roi_pooling.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct jit_roi_pooling_params {
2727

2828
int c_block, nb_c, nb_c_blocking;
2929

30+
int b_num;
31+
3032
double spatial_scale;
3133
int pooled_h;
3234
int pooled_w;

0 commit comments

Comments
 (0)