Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU]fix: memory access error (#36440)

Xiuchuan Zhai65450f1d326d
diff --git a/src/plugins/intel_cpu/src/memory_control.cpp b/src/plugins/intel_cpu/src/memory_control.cpp
index 59c4bcfdebb..fa92b4a1181 100644
--- a/src/plugins/intel_cpu/src/memory_control.cpp
+++ b/src/plugins/intel_cpu/src/memory_control.cpp
@@ -272,16 +272,16 @@ public:
// We have to extend the lifespan of tensors that are crossing a sync point border in order to save
// the intermediate computation results from possible loss due to the tensor resize
OPENVINO_ASSERT(box.finish >= 0, "box.finish must be non-negative");
- const auto finish = static_cast<size_t>(box.finish);
- auto itr_upper = std::upper_bound(syncInds.begin(), syncInds.end(), finish, [](size_t y, size_t x) {
- return y < x;
- });
- auto itr_lower = std::lower_bound(syncInds.begin(), syncInds.end(), box.start);
- if (itr_lower != itr_upper) { // across sections
- if (itr_upper == syncInds.end()) {
+ // [start, finish) is the lifespan of the box. Extend it only if that interval contains a sync point,
+ // which means the tensor spans more than one sync section.
+ const auto first_sync_at_or_after_start = std::lower_bound(syncInds.begin(), syncInds.end(), box.start);
+ const auto first_sync_at_or_after_finish = std::lower_bound(syncInds.begin(), syncInds.end(), box.finish);
+ const bool crosses_sync_section = first_sync_at_or_after_start != first_sync_at_or_after_finish;
+ if (crosses_sync_section) {
+ if (first_sync_at_or_after_finish == syncInds.end()) {
box.finish = -1;
} else {
- box.finish = static_cast<int>(*itr_upper);
+ box.finish = static_cast<int>(*first_sync_at_or_after_finish);
}
}
}