Skip to content

Commit 06c3f20

Browse files
authored
NPUW: Fix SPATIAL execution mode (#28862)
### Details: - This is mainly a workaround, but it allows to keep using strided tensors without a copy. ### Tickets: - *E-156237*, *E-156237*
1 parent a0022e7 commit 06c3f20

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/plugins/intel_npu/src/plugin/npuw/just_sync_infer_request.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,10 @@ void ov::npuw::JustInferRequest::unsafe_infer(std::size_t real_idx) {
733733
// Collect spatial inputs for this offset
734734
for (auto&& param : spatial.params) {
735735
const auto& iport = comp_model_desc.compiled_model->inputs()[param.idx];
736-
r->set_tensor(
737-
iport,
738-
ov::npuw::util::view(m_spatial_io[real_idx].inputs.at(param.idx), param.dim, offset, spatial.nway));
736+
const auto& iview = ov::npuw::util::view(m_spatial_io[real_idx].inputs.at(param.idx),
737+
param.dim, offset,
738+
spatial.nway);
739+
r->set_tensor(iport, iview);
739740
} // for(params)
740741

741742
// Now set the spatial outputs

src/plugins/intel_npu/src/plugin/npuw/util.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,32 @@ ov::SoPtr<ov::ITensor> ov::npuw::util::view(const ov::SoPtr<ov::ITensor>& src,
360360
std::size_t offset,
361361
std::size_t len) {
362362
const auto& shape = src->get_shape();
363+
NPUW_ASSERT(dim < shape.size());
363364
View view_start = View(shape.size(), 0u);
364365
View view_end = shape;
365366
view_start[dim] = offset;
366367
view_end[dim] = offset + len;
367-
return ov::npuw::util::view(src, view_start, view_end);
368+
369+
auto ret_view = ov::npuw::util::view(src, view_start, view_end);
370+
371+
// Check if a tensor view can be faked as "continuous"
372+
// FIXME: This trick should be removed after strided tensor
373+
// checks are relaxed
374+
if (std::all_of(shape.begin(), shape.begin() + dim, [](std::size_t d) { return d == 1u; })) {
375+
// If all dimensions up to the sub-ranged dimension are 1s,
376+
// This tensor can be faked as continuous
377+
const auto type = src->get_element_type();
378+
const auto view_shape = ret_view->get_shape();
379+
ov::Strides fake_strides(shape.size());
380+
fake_strides.back() = type.size();
381+
std::transform(view_shape.crbegin(),
382+
view_shape.crend() - 1,
383+
fake_strides.rbegin(),
384+
fake_strides.rbegin() + 1,
385+
std::multiplies<size_t>());
386+
return ov::get_tensor_impl(ov::Tensor(type, view_shape, ret_view->data(), fake_strides));
387+
}
388+
return ret_view;
368389
}
369390

370391
template <typename InT>

0 commit comments

Comments
 (0)