Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPUW: Fix SPATIAL execution mode #28862

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,10 @@ void ov::npuw::JustInferRequest::unsafe_infer(std::size_t real_idx) {
// Collect spatial inputs for this offset
for (auto&& param : spatial.params) {
const auto& iport = comp_model_desc.compiled_model->inputs()[param.idx];
r->set_tensor(
iport,
ov::npuw::util::view(m_spatial_io[real_idx].inputs.at(param.idx), param.dim, offset, spatial.nway));
const auto& iview = ov::npuw::util::view(m_spatial_io[real_idx].inputs.at(param.idx),
param.dim, offset,
spatial.nway);
r->set_tensor(iport, iview);
} // for(params)

// Now set the spatial outputs
Expand Down
23 changes: 22 additions & 1 deletion src/plugins/intel_npu/src/plugin/npuw/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,32 @@ ov::SoPtr<ov::ITensor> ov::npuw::util::view(const ov::SoPtr<ov::ITensor>& src,
std::size_t offset,
std::size_t len) {
const auto& shape = src->get_shape();
NPUW_ASSERT(dim < shape.size());
View view_start = View(shape.size(), 0u);
View view_end = shape;
view_start[dim] = offset;
view_end[dim] = offset + len;
return ov::npuw::util::view(src, view_start, view_end);

auto ret_view = ov::npuw::util::view(src, view_start, view_end);

// Check if a tensor view can be faked as "continuous"
// FIXME: This trick should be removed after strided tensor
// checks are relaxed
if (std::all_of(shape.begin(), shape.begin() + dim, [](std::size_t d) { return d == 1u; })) {
// If all dimensions up to the sub-ranged dimension are 1s,
// This tensor can be faked as continuous
const auto type = src->get_element_type();
const auto view_shape = ret_view->get_shape();
ov::Strides fake_strides(shape.size());
fake_strides.back() = type.size();
std::transform(view_shape.crbegin(),
view_shape.crend() - 1,
fake_strides.rbegin(),
fake_strides.rbegin() + 1,
std::multiplies<size_t>());
return ov::get_tensor_impl(ov::Tensor(type, view_shape, ret_view->data(), fake_strides));
}
return ret_view;
}

template <typename InT>
Expand Down
Loading