OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Add support for the NPU remote tensor feature in the benchmark app (#25725)
Bogdan Pereanudd4bd86be9a2
diff --git a/samples/cpp/benchmark_app/benchmark_app.hpp b/samples/cpp/benchmark_app/benchmark_app.hppindex 5bbc2a1e15f..99cbd7edff8 100644--- a/samples/cpp/benchmark_app/benchmark_app.hpp+++ b/samples/cpp/benchmark_app/benchmark_app.hpp@@ -4,10 +4,6 @@#pragma once-#if defined(HAVE_GPU_DEVICE_MEM_SUPPORT)-# define HAVE_DEVICE_MEM_SUPPORT-#endif-#include <iostream>#include <string>#include <vector>@@ -185,11 +181,9 @@ static const char infer_threads_pinning_message[] ="\t\t\t\tthreads->(NUMA)nodes(\"NUMA\") or \n""\t\t\t\tcompletely disable(\"NO\") CPU inference threads pinning";-#ifdef HAVE_DEVICE_MEM_SUPPORT// @brief message for switching memory allocation type optionstatic const char use_device_mem_message[] ="Optional. Switch between host and device memory allocation for input and output buffers.";-#endif/// @brief message for latency percentile settingsstatic const char infer_latency_percentile_message[] =@@ -347,10 +341,8 @@ DEFINE_uint64(nthreads, 0, infer_num_threads_message);// @brief Enable plugin messagesDEFINE_string(pin, "", infer_threads_pinning_message);-#ifdef HAVE_DEVICE_MEM_SUPPORT/// @brief Define flag for switching beetwen host and device memory allocation for input and output buffersDEFINE_bool(use_device_mem, false, use_device_mem_message);-#endif/// @brief The percentile which will be reported in latency metricDEFINE_uint64(latency_percentile, 50, infer_latency_percentile_message);@@ -426,9 +418,7 @@ static void show_usage() {std::cout << " -nthreads <integer> " << infer_num_threads_message << std::endl;std::cout << " -pin <string> (\"YES\"|\"CORE\") / \"HYBRID_AWARE\" / (\"NO\"|\"NONE\") / \"NUMA\" "<< infer_threads_pinning_message << std::endl;-#ifdef HAVE_DEVICE_MEM_SUPPORTstd::cout << " -use_device_mem " << use_device_mem_message << std::endl;-#endifstd::cout << std::endl;std::cout << "Statistics dumping options:" << std::endl;std::cout << " -latency_percentile " << infer_latency_percentile_message << std::endl;diff --git a/samples/cpp/benchmark_app/main.cpp b/samples/cpp/benchmark_app/main.cppindex 41b72211f28..2cfd15b77af 100644--- a/samples/cpp/benchmark_app/main.cpp+++ b/samples/cpp/benchmark_app/main.cpp@@ -942,6 +942,7 @@ int main(int argc, char* argv[]) {// create vector to store remote input blobs bufferstd::vector<::gpu::BufferType> clInputsBuffer;bool useGpuMem = false;+ bool useNpuMem = false;std::map<std::string, ov::TensorVector> inputsData;if (isFlagSetInCommandLine("use_device_mem")) {@@ -962,6 +963,12 @@ int main(int argc, char* argv[]) {app_inputs_info[0],nireq);}+ } else if (device_name.find("NPU") == 0) {+ inputsData = ::npu::get_remote_input_tensors(inputFiles,+ app_inputs_info,+ compiledModel,+ inferRequestsQueue.requests.size());+ useNpuMem = true;} else {OPENVINO_THROW("Requested device doesn't support `use_device_mem` option.");}@@ -1032,6 +1039,8 @@ int main(int argc, char* argv[]) {// for remote blobs setTensor is used, they are already allocated on the deviceif (useGpuMem) {inferRequest->set_tensor(inputName, inputTensor);+ } else if (useNpuMem) {+ inferRequest->set_tensor(inputName, inputTensor);} else {auto requestTensor = inferRequest->get_tensor(inputName);if (isDynamicNetwork) {diff --git a/samples/cpp/benchmark_app/remote_tensors_filling.cpp b/samples/cpp/benchmark_app/remote_tensors_filling.cppindex a0d9bdc2fd5..a1c36a72f17 100644--- a/samples/cpp/benchmark_app/remote_tensors_filling.cpp+++ b/samples/cpp/benchmark_app/remote_tensors_filling.cpp@@ -11,12 +11,15 @@#include <utility>#include <vector>-#ifdef HAVE_DEVICE_MEM_SUPPORT+#ifdef HAVE_GPU_DEVICE_MEM_SUPPORT# include <openvino/runtime/intel_gpu/ocl/ocl.hpp># include <openvino/runtime/intel_gpu/ocl/ocl_wrapper.hpp>#endif-namespace gpu {+#include <openvino/runtime/intel_npu/level_zero/level_zero.hpp>+#include <openvino/runtime/intel_npu/remote_properties.hpp>++namespace {template <typename T>using uniformDistribution = typename std::conditional<@@ -66,6 +69,9 @@ void fill_buffer(void* inputBuffer, size_t elementsNum, const ov::element::Type&OPENVINO_THROW("Requested type is not supported");}}+} // namespace++namespace gpu {std::map<std::string, ov::TensorVector> get_remote_input_tensors(const std::map<std::string, std::vector<std::string>>& inputFiles,@@ -73,7 +79,7 @@ std::map<std::string, ov::TensorVector> get_remote_input_tensors(const ov::CompiledModel& compiledModel,std::vector<BufferType>& clBuffer,size_t num_requests) {-#ifdef HAVE_DEVICE_MEM_SUPPORT+#ifdef HAVE_GPU_DEVICE_MEM_SUPPORTslog::info << "Device memory will be used for input and output blobs" << slog::endl;if (inputFiles.size()) {slog::warn << "Device memory supports only random data at this moment, input images will be ignored"@@ -156,7 +162,7 @@ ov::Shape get_static_shape(const ov::Output<const ov::Node>& compiled_output) {std::map<std::string, ov::Tensor> get_remote_output_tensors(const ov::CompiledModel& compiledModel,std::map<std::string, ::gpu::BufferType>& clBuffer) {-#ifdef HAVE_DEVICE_MEM_SUPPORT+#ifdef HAVE_GPU_DEVICE_MEM_SUPPORTstd::map<std::string, ov::Tensor> outputTensors;std::shared_ptr<const ov::Model> runtime_model = nullptr;for (auto& output : compiledModel.outputs()) {@@ -189,3 +195,47 @@ std::map<std::string, ov::Tensor> get_remote_output_tensors(const ov::CompiledMo#endif}} // namespace gpu++namespace npu {++std::map<std::string, ov::TensorVector> get_remote_input_tensors(+ const std::map<std::string, std::vector<std::string>>& inputFiles,+ const std::vector<benchmark_app::InputsInfo>& app_inputs_info,+ const ov::CompiledModel& compiledModel,+ size_t num_requests) {+ slog::info << "Device memory will be used for input blobs" << slog::endl;++ std::map<std::string, ov::TensorVector> remoteTensors;+ auto context = compiledModel.get_context();+ auto& zeroContext = static_cast<ov::intel_npu::level_zero::ZeroContext&>(context);++ for (size_t i = 0; i < num_requests; i++) {+ for (auto& inputs_info : app_inputs_info) {+ for (auto& input : inputs_info) {+ auto tensor = zeroContext.create_l0_host_tensor(input.second.type,+ input.second.dataShape,+ ov::intel_npu::TensorType::INPUT);+ remoteTensors[input.first].push_back(tensor);++ if (inputFiles.empty()) {+ // Filling in random data+ slog::info << "Prepare remote blob for input '" << input.first << "' with random values ("+ << std::string((input.second.is_image() ? "image" : "some binary data"))+ << " is expected)" << slog::endl;++ auto elementsNum = std::accumulate(begin(input.second.dataShape),+ end(input.second.dataShape),+ 1,+ std::multiplies<size_t>());++ fill_buffer(tensor.get(), elementsNum, input.second.type);+ } else {+ OPENVINO_THROW(+ "[NPU] Device memory supports only random data at this moment, input images will be ignored");+ }+ }+ }+ }+ return remoteTensors;+}+} // namespace npudiff --git a/samples/cpp/benchmark_app/remote_tensors_filling.hpp b/samples/cpp/benchmark_app/remote_tensors_filling.hppindex dec6a23ecb4..abfa39d504a 100644--- a/samples/cpp/benchmark_app/remote_tensors_filling.hpp+++ b/samples/cpp/benchmark_app/remote_tensors_filling.hpp@@ -5,14 +5,13 @@#pragma once#if defined(HAVE_GPU_DEVICE_MEM_SUPPORT)-# define HAVE_DEVICE_MEM_SUPPORT# include "openvino/runtime/intel_gpu/ocl/ocl_wrapper.hpp"#endif#include "utils.hpp"namespace gpu {-#ifdef HAVE_DEVICE_MEM_SUPPORT+#ifdef HAVE_GPU_DEVICE_MEM_SUPPORTusing BufferType = cl::Buffer;struct OpenCL {@@ -67,3 +66,12 @@ std::map<std::string, ov::TensorVector> get_remote_input_tensors(std::map<std::string, ov::Tensor> get_remote_output_tensors(const ov::CompiledModel& compiledModel,std::map<std::string, ::gpu::BufferType>& clBuffer);} // namespace gpu++namespace npu {++std::map<std::string, ov::TensorVector> get_remote_input_tensors(+ const std::map<std::string, std::vector<std::string>>& inputFiles,+ const std::vector<benchmark_app::InputsInfo>& app_inputs_info,+ const ov::CompiledModel& compiledModel,+ size_t num_requests);+} // namespace npu