Skip to content

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

Memcheck update runner and test (#38664)

Egor Tyuvaevd3f0de8a9476
diff --git a/tests/memory_tests/CMakeLists.txt b/tests/memory_tests/CMakeLists.txt
index 4826b807248..0196eba3d68 100644
--- a/tests/memory_tests/CMakeLists.txt
+++ b/tests/memory_tests/CMakeLists.txt
@@ -8,11 +8,16 @@ set (CMAKE_CXX_STANDARD 17)
if(NOT TARGET openvino::runtime)
find_package(OpenVINO REQUIRED)
+ if(MSVC)
+ add_compile_options(/W4 /WX)
+ else()
+ add_compile_options(-Wall -Wextra -Wpedantic -Werror)
+ endif()
endif()
function(add_test)
set(target "test_${ARGV0}")
- add_executable(${target} "src/${target}.cpp" "src/system_memory_sampling.cpp" "src/gpu_memory_sampling.cpp")
+ add_executable(${target} "src/${target}.cpp" "src/common.cpp" "src/system_memory_sampling.cpp" "src/gpu_memory_sampling.cpp")
target_link_libraries(${target} openvino::runtime)
target_compile_definitions(${target} PUBLIC TEST_NAME=${ARGV0})
install(TARGETS ${target} DESTINATION tests/memory_tests COMPONENT tests EXCLUDE_FROM_ALL)
diff --git a/tests/memory_tests/src/common.cpp b/tests/memory_tests/src/common.cpp
new file mode 100644
index 00000000000..4ba19de7929
--- /dev/null
+++ b/tests/memory_tests/src/common.cpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "common.hpp"
+
+
+ov::PartialShape get_default_image_shape(ov::PartialShape given_shape) {
+ if (given_shape.is_static()) {
+ return given_shape.get_shape();
+ }
+ if (given_shape.size() != 4) {
+ // unlikely an image
+ throw std::runtime_error("For dynamic shapes, only inputs with four dimensions are supported.");
+ }
+ const ov::Shape default_shape = {1, 3, 480, 480};
+ ov::Shape new_shape;
+ for (size_t index = 0; index < given_shape.size(); index++) {
+ auto dimention = given_shape[index];
+ auto default_value = default_shape[index];
+ if (dimention.is_static()) {
+ new_shape.push_back(dimention.get_length());
+ } else {
+ auto interval = dimention.get_interval();
+ if (interval.contains(default_value)) {
+ new_shape.push_back(default_value);
+ } else if (static_cast<int64_t>(default_value) > interval.get_max_val()) {
+ new_shape.push_back(interval.get_max_val());
+ } else {
+ new_shape.push_back(interval.get_min_val());
+ }
+ }
+ }
+ return new_shape;
+}
diff --git a/tests/memory_tests/src/common.hpp b/tests/memory_tests/src/common.hpp
new file mode 100644
index 00000000000..df5b73876c2
--- /dev/null
+++ b/tests/memory_tests/src/common.hpp
@@ -0,0 +1,8 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <openvino/openvino.hpp>
+
+
+ov::PartialShape get_default_image_shape(ov::PartialShape given_shape);
diff --git a/tests/memory_tests/src/memory_test.hpp b/tests/memory_tests/src/memory_test.hpp
index 810a3363e38..d1c50af5a0e 100644
--- a/tests/memory_tests/src/memory_test.hpp
+++ b/tests/memory_tests/src/memory_test.hpp
@@ -109,7 +109,7 @@ struct Context {
}
}
- return {model_path, device, gpu_ready};
+ return {model_path, device, gpu_ready, {}};
}
bool is_sample_registered(std::string &sample_name) {
diff --git a/tests/memory_tests/src/test_inference_async.cpp b/tests/memory_tests/src/test_inference_async.cpp
index 3934c38c907..321e3f1b8c2 100644
--- a/tests/memory_tests/src/test_inference_async.cpp
+++ b/tests/memory_tests/src/test_inference_async.cpp
@@ -5,6 +5,7 @@
#include <openvino/openvino.hpp>
#include "memory_test.hpp"
+#include "common.hpp"
std::vector<std::string> test_samples() {
@@ -21,11 +22,19 @@ void do_test(memory_tests::Context &test) {
test.sample("start");
ov::Core core;
- ov::CompiledModel model = core.compile_model(test.model_path, test.device);
+ auto model = core.read_model(test.model_path);
+ std::map<ov::Output<ov::Node>, ov::PartialShape> input_shapes;
+ for (const auto& input : model->inputs()) {
+ if (!input.get_partial_shape().is_static()) {
+ input_shapes.emplace(input, get_default_image_shape(input.get_partial_shape()));
+ }
+ }
+ model->reshape(input_shapes);
+ ov::CompiledModel compiled_model = core.compile_model(model, test.device);
test.sample("compile_model");
- auto ireq = model.create_infer_request();
- for (auto input: model.inputs()) {
+ auto ireq = compiled_model.create_infer_request();
+ for (auto input: compiled_model.inputs()) {
ireq.set_tensor(input, {input});
}
test.sample("fill_inputs");
diff --git a/tests/memory_tests/src/test_inference_sync.cpp b/tests/memory_tests/src/test_inference_sync.cpp
index fa82f48e098..0c8a04e9629 100644
--- a/tests/memory_tests/src/test_inference_sync.cpp
+++ b/tests/memory_tests/src/test_inference_sync.cpp
@@ -5,6 +5,7 @@
#include <openvino/openvino.hpp>
#include "memory_test.hpp"
+#include "common.hpp"
std::vector<std::string> test_samples() {
@@ -21,11 +22,19 @@ void do_test(memory_tests::Context &test) {
test.sample("start");
ov::Core core;
- ov::CompiledModel model = core.compile_model(test.model_path, test.device);
+ auto model = core.read_model(test.model_path);
+ std::map<ov::Output<ov::Node>, ov::PartialShape> input_shapes;
+ for (const auto& input : model->inputs()) {
+ if (!input.get_partial_shape().is_static()) {
+ input_shapes.emplace(input, get_default_image_shape(input.get_partial_shape()));
+ }
+ }
+ model->reshape(input_shapes);
+ ov::CompiledModel compiled_model = core.compile_model(model, test.device);
test.sample("compile_model");
- auto ireq = model.create_infer_request();
- for (auto input: model.inputs()) {
+ auto ireq = compiled_model.create_infer_request();
+ for (auto input: compiled_model.inputs()) {
ireq.set_tensor(input, {input});
}
test.sample("fill_inputs");
diff --git a/tests/memory_tests/tools/run_tests.py b/tests/memory_tests/tools/run_tests.py
index 4fdd1340f40..0b5022c8f47 100644
--- a/tests/memory_tests/tools/run_tests.py
+++ b/tests/memory_tests/tools/run_tests.py
@@ -11,6 +11,7 @@ import subprocess
import json
import time
import sys
+import csv
from typing import Any
from pathlib import Path
@@ -235,22 +236,10 @@ def run_test_executable_extract_result(command):
MODELID_RE = re.compile(r"\/?([^\/]+)\/(\w+)\/?[^\/]*\/((OV_)?(FP|INT)\d+(\/INT\d+)?[^\/]*)(\/\d+\/ov)?\/(.+).xml")
-def modelid_assume_info(modelid):
- match = MODELID_RE.match(modelid.replace("\\", "/"))
- if not match:
- return None
- model, fw, prec, _n1, _n2, _n3, _n4, model2 = match.groups()
- if model == model2:
- modelname = model
- else:
- modelname = f"{model}/{model2}"
- framework = fw
- precision = prec.replace("/", "-")
- return modelname, framework, precision
-
-
@dataclass
class TestCase:
+ _main_fields = ["model_id", "model_path", "device"]
+
model_id: str
model_path: Path
device: str
@@ -263,9 +252,63 @@ class TestCase:
def original_model(self) -> str | None:
return self.description.get("src_model_path")
+ @property
+ def model_name(self) -> str | None:
+ return self.description.get("topology_name")
+
+ @property
+ def framework(self) -> str | None:
+ return self.description.get("base_framework")
+
+ @property
+ def precision(self) -> str | None:
+ return self.description.get("weight_precision")
+
+ @staticmethod
+ def _read_description(model_path: Path) -> dict[str, str] | None:
+ description_path = model_path.parent / "description.txt"
+ description_text = None
+ try:
+ description_text = description_path.read_text()
+ except OSError:
+ pass
+ if not description_text:
+ description_path = model_path.parent.parent / "description.txt"
+ try:
+ description_text = description_path.read_text()
+ except OSError:
+ return None
+ return dict([
+ line.split(":", 1)
+ for line in description_text.splitlines()
+ if ":" in line
+ ])
+
+ @classmethod
+ def from_model_path(cls, model_id: str, model_path: Path, device: str) -> "TestCase":
+ model_descr = cls._read_description(model_path) or {}
+ weights_path = model_path.with_suffix(".bin")
+ if not weights_path.is_file():
+ print(f"Warning: Test case {model_id} invalid: can't find weights file at {str(weights_path)}")
+ raise Exception(f"No weights file was found")
+ weights_size = weights_path.stat().st_size
+ return cls(
+ model_id=model_id,
+ model_path=model_path,
+ device=device,
+ description=model_descr,
+ weights_size=weights_size
+ )
+
+ def to_main_json(self):
+ return {
+ key: getattr(self, key)
+ for key in self._main_fields
+ }
+
class TestSession:
- def __init__(self, executable: Path, ir_cache_dirs: list[Path], devices: list[str], api=None, report_reference=False):
+ def __init__(self, executable: Path, ir_cache_dirs: list[Path], devices: list[str], api=None, report_reference=False, log_dir=None):
self.executable = executable
self.test_name = executable.stem.removeprefix("test_")
self.ir_cache_dirs = ir_cache_dirs
@@ -278,6 +321,16 @@ class TestSession:
if self.report_api:
self.detect_report_metadata()
+ # logging setup
+ self.log_dir: Path | None = log_dir
+ self.test_case_log = None
+ if self.log_dir:
+ self.log_dir.mkdir(parents=True, exist_ok=True)
+ self.test_case_log_file = (self.log_dir / "test_cases.csv").open("w", newline="")
+ self.test_case_log = csv.DictWriter(
+ self.test_case_log_file, TestCase._main_fields)
+ self.test_case_log.writeheader()
+
def get_test_info(self):
result = run_test_executable_extract_result([str(self.executable), "--info"])
if "error" in result:
@@ -303,8 +356,6 @@ class TestSession:
if not self.report_metadata:
print("No job metadata found, no report will be made.")
return
- model_assumptions = modelid_assume_info(test.model_id)
- modelname, framework, precision = model_assumptions or (test.model_id, "unknown", "unknown")
test_report = []
sample_names = result.get("samples", {}).keys() or self.test_info["samples"]
for sname in sample_names:
@@ -315,11 +366,11 @@ class TestSession:
"status": "failed" if "error" in result else "passed",
"source": str(test.model_path),
"log": result.get("stderr", ""),
- "model_name": modelname,
+ "model_name": test.model_name,
"model": test.model_id,
"device": result.get("device") or test.device,
- "framework": framework,
- "precision": precision,
+ "framework": test.framework,
+ "precision": test.precision,
"metrics": sample.as_dict(),
"cpu_family": CPU_FAMILY,
"model_size": test.weights_size,
@@ -336,7 +387,7 @@ class TestSession:
self.report_metadata = {
"build_url": os.environ["BUILD_URL"],
"os": os.environ.get("os", "unknown"),
- "commit_date": os.environ.get("commitDate", "2030-12-22T22:22:22.000Z"),
+ "commit_date": os.environ["commitDate"],
"branch": os.environ.get("sourceBranch", "unknown"),
"target_branch": os.environ.get("targetBranch", "unknown"),
"log_path": os.environ.get("SHARED_LOG_PATH", ""),
@@ -372,41 +423,14 @@ class TestSession:
for path in new_files
)
- def get_description(self, model_path: Path) -> dict[str, str] | None:
- description_path = model_path.parent / "description.txt"
- description_text = None
- try:
- description_text = description_path.read_text()
- except OSError:
- pass
- if not description_text:
- description_path = model_path.parent.parent / "description.txt"
- try:
- description_text = description_path.read_text()
- except OSError:
- return None
- return dict([
- line.split(":", 1)
- for line in description_text.splitlines()
- if ":" in line
- ])
-
def generate_test_cases(self):
for ir_cache_dir in self.ir_cache_dirs:
for (model_id, model_path) in self.scan_directory(ir_cache_dir):
- weights_path = model_path.with_suffix(".bin")
- if not weights_path.is_file():
- print(f"Warning: Test case {model_id} invalid: can't find weights file at {weights_path}")
- continue
- weights_size = weights_path.stat().st_size
for device in self.devices:
- yield TestCase(
- model_id=model_id,
- model_path=model_path,
- device=device,
- description=self.get_description(model_path) or {},
- weights_size=weights_size,
- )
+ try:
+ yield TestCase.from_model_path(model_id, model_path, device)
+ except Exception as ex:
+ print(f"Warning: TestCase is not correct: {repr(ex)}")
def run_test_case(self, test_case: TestCase):
try:
@@ -417,8 +441,7 @@ class TestSession:
for _ in range(run_num)
]
errors = ["error" in r for r in results]
- if run_num > 1 and all(errors):
- print("All attempts failed")
+ if all(errors):
return results[0]
if run_num > 1 and any(errors):
print("Some attempts failed:", repr([r for r in results if "error" in r]))
@@ -427,7 +450,7 @@ class TestSession:
print(f" When running test an unexpected error happened: {ex}")
return {"error": "unexpected error", "exception": ex}
- def handle_test_result(self, test: TestCase, result):
+ def log_test_result(self, test: TestCase, result):
base2_suffixes = ["bytes", "KiB", "MiB", "GiB", "TiB", "PiB"]
def _base2_human_readable(number):
@@ -460,11 +483,19 @@ class TestSession:
sys.stdout.flush()
sys.stderr.flush()
+ def log_test_case(self, test: TestCase):
+ if self.test_case_log is None:
+ return
+ self.test_case_log.writerow(test.to_main_json())
+ self.test_case_log_file.flush()
+
def run(self):
for test in self.generate_test_cases():
+ self.log_test_case(test)
result = self.run_test_case(test)
- self.api_push_test_result(test, result)
- self.handle_test_result(test, result)
+ if self.report_api:
+ self.api_push_test_result(test, result)
+ self.log_test_result(test, result)
if __name__ == "__main__":
@@ -482,6 +513,8 @@ if __name__ == "__main__":
parser.add_argument("--api", help="API endpoint for results to upload")
parser.add_argument("--upload-reference", "--reference", action="store_true",
help="This run will make new reference values")
+ parser.add_argument("--log-dir", type=Path, default=None,
+ help="Path to directory to write logs to")
args = parser.parse_args()
@@ -490,5 +523,6 @@ if __name__ == "__main__":
args.ir_cache,
[device.upper() for device in args.devices.split(",")],
args.api,
- args.upload_reference
+ args.upload_reference,
+ args.log_dir
).run()