-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[WIP][NPUW] Add tests on set_tensor() #32097
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
Open
smirnov-alexey
wants to merge
5
commits into
openvinotoolkit:master
Choose a base branch
from
smirnov-alexey:as/npuw_set_tensor_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
624f2dd
WIP
smirnov-alexey 4a44063
Merge branch 'master' of https://github.com/openvinotoolkit/openvino …
smirnov-alexey 485e200
Use mock plugin to create npuw infer request class
smirnov-alexey cb4ae04
WIP
smirnov-alexey 61d40cc
Make unit tests buildable
smirnov-alexey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (C) 2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <iostream> | ||
|
||
#include "openvino/openvino.hpp" | ||
#include "npuw/compiled_model.hpp" | ||
#include "npuw/just_sync_infer_request.hpp" | ||
#include "model_generator/model_generator.hpp" | ||
#include "plugin.hpp" | ||
|
||
// FIXME: parametrize all the tests below | ||
|
||
// TODO: add tests on Unfold, Base and Just for inputs and outputs (where applicable) | ||
TEST(SetTensor, RemoteTensorOutputJust) { | ||
// Only run this test on NPU device | ||
ov::Core ov_core; | ||
auto core_devices = ov_core.get_available_devices(); | ||
if (std::find(core_devices.begin(), core_devices.end(), "NPU") == core_devices.end()) { | ||
GTEST_SKIP() << "No available devices."; | ||
} | ||
|
||
// Create model | ||
ModelGenerator mg; | ||
auto model = mg.get_model_with_repeated_blocks(); | ||
|
||
ov::element::Type element_type = ov::element::i32; | ||
auto output_tensor_shape = model->outputs()[0].get_shape(); | ||
// Calculate total number of elements | ||
size_t total_elements = ov::shape_size(output_tensor_shape); | ||
|
||
// Create output data | ||
std::vector<int> data = std::vector<int>(total_elements, 0); | ||
std::iota(data.begin(), data.end(), 1); | ||
|
||
// Create the remote tensor output | ||
auto npu_context = ov_core.get_default_context("NPU"); | ||
auto output = npu_context.create_host_tensor(element_type, output_tensor_shape); | ||
|
||
// Initialize remote input with non-zero data | ||
ov::Tensor values(element_type, output_tensor_shape, data.data()); | ||
values.copy_to(output); | ||
|
||
// Create plugin object | ||
auto plugin = std::make_shared<intel_npu::Plugin>(); | ||
|
||
// Compile NPUW | ||
auto compiled = std::make_shared<ov::npuw::CompiledModel>(model, plugin, ov::AnyMap{}); | ||
|
||
// Create infer request | ||
std::shared_ptr<ov::ISyncInferRequest> request; | ||
request = std::make_shared<ov::npuw::JustInferRequest>(compiled); | ||
|
||
// Set remote io | ||
request->set_tensor(compiled->outputs()[0], ov::get_tensor_impl(output)); | ||
|
||
// Check output tensor is not zero | ||
auto output_tensor = request->get_tensor(compiled->outputs()[0]); | ||
|
||
auto check_non_zero = [](const ov::npuw::util::TensorPtr& t, size_t size) { | ||
int32_t* tdata = t->data<int32_t>(); | ||
for (size_t i = 0; i < size; ++i) { | ||
if (tdata[i] == 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
EXPECT_TRUE(check_non_zero(output_tensor, total_elements)); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative idea how to test
set_tensor
: