Skip to content

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

[Protopipe] Workaround for INT64 input type (#31972)

fcmiron8625f318b072
diff --git a/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp b/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp
index cf17e9f4832..f7e3955a0e4 100644
--- a/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp
+++ b/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp
@@ -95,7 +95,7 @@ static int toDepth(const std::string& prec) {
return CV_16F;
if (prec == "U8")
return CV_8U;
- if (prec == "I32")
+ if (prec == "I32" || prec == "I64")
return CV_32S;
throw std::logic_error("Unsupported precision type: " + prec);
}
diff --git a/src/plugins/intel_npu/tools/protopipe/src/utils/utils.cpp b/src/plugins/intel_npu/tools/protopipe/src/utils/utils.cpp
index 94081dd2952..b9f8bd16518 100644
--- a/src/plugins/intel_npu/tools/protopipe/src/utils/utils.cpp
+++ b/src/plugins/intel_npu/tools/protopipe/src/utils/utils.cpp
@@ -5,8 +5,9 @@
#include "utils.hpp"
+#include <algorithm>
+#include <cstdint>
#include <opencv2/gapi/own/assert.hpp>
-
#include <fstream>
namespace utils {
@@ -65,12 +66,23 @@ void readFromBinFile(const std::string& filepath, cv::Mat& mat) {
ifs.seekg(0, std::ios::beg);
const auto mat_byte_size = mat.total() * mat.elemSize();
- if (file_byte_size != mat_byte_size) {
- throw std::logic_error("Failed to read cv::Mat from binary file: " + filepath + ". Mat size: " +
- std::to_string(mat_byte_size) + ", File size: " + std::to_string(file_byte_size));
- }
+ // workaround for I64 input type precision
+ if (mat.type() == CV_32S && file_byte_size == mat_byte_size * 2) {
- ifs.read(mat.ptr<char>(), mat_byte_size);
+ std::vector<int64_t> buffer64;
+ buffer64.resize(file_byte_size / 8);
+ ifs.read(reinterpret_cast<char*>(buffer64.data()), file_byte_size);
+ std::transform(buffer64.begin(), buffer64.end(), mat.ptr<int32_t>(),
+ [](int64_t val) {return static_cast<int32_t>(val); });
+ }
+ else {
+ if (file_byte_size != mat_byte_size) {
+ throw std::logic_error("Failed to read cv::Mat from binary file: " + filepath + ". Mat size: " +
+ std::to_string(mat_byte_size) + ", File size: " + std::to_string(file_byte_size));
+ }
+ ifs.read(mat.ptr<char>(), mat_byte_size);
+ }
+ ifs.close();
}
void writeToBinFile(const std::string& filepath, const cv::Mat& mat) {