Skip to content

Commit 8d1f543

Browse files
committed
refactor configuration and tests: replace BuildConfig with OpenVINOConfig for enhanced flexibility and support of multiple OpenVINO distribution modes (build, install, link); update schema validations, experiment YAML, and add dedicated tests
1 parent e5532fa commit 8d1f543

14 files changed

Lines changed: 1007 additions & 103 deletions

experiments/android_example.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@ project:
33
run_id: "android_benchmark_001"
44
description: "OpenVINO benchmark on Android device"
55

6-
build:
7-
enabled: true
8-
openvino_repo: "/path/to/openvino" # UPDATE THIS PATH
9-
openvino_commit: "HEAD"
6+
# OpenVINO distribution configuration
7+
# Chooses one of three modes: build, install, or link
8+
openvino:
9+
# Mode 1: Build from source
10+
mode: "build"
11+
source_dir: "/path/to/openvino" # UPDATE THIS PATH
12+
commit: "HEAD"
1013
build_type: "Release"
14+
15+
# Mode 2: Use existing install (uncomment to use)
16+
# mode: "install"
17+
# install_dir: "/path/to/openvino/install" # UPDATE THIS PATH
18+
19+
# Mode 3: Download from URL (uncomment to use)
20+
# mode: "link"
21+
# archive_url: "https://storage.openvinotoolkit.org/repositories/openvino/packages/nightly/\
22+
# 2025.4.0-19820-4671c012da0/openvino_toolkit_ubuntu22_2025.4.0.dev20250820_arm64.tgz"
23+
# Or use 'latest' for auto-detection:
24+
# archive_url: "latest"
25+
26+
# Build configuration (for build mode)
1127
toolchain:
1228
android_ndk: "/path/to/android-ndk-r26d" # UPDATE THIS PATH
1329
abi: "arm64-v8a"

experiments/raspberry_pi_example.yaml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,34 @@ device:
3434
# port: 22
3535
push_dir: /home/pi/ovmobilebench # Remote directory for benchmark files
3636

37-
# Build configuration for ARM cross-compilation
38-
build:
39-
enabled: true
40-
openvino_repo: /path/to/openvino # UPDATE THIS PATH
41-
# ARM-specific build settings
42-
cmake_args:
43-
- -DCMAKE_BUILD_TYPE=Release
44-
- -DENABLE_SAMPLES=ON
45-
- -DENABLE_TESTS=OFF
46-
- -DTARGET_ARM=ON
37+
# OpenVINO distribution configuration for ARM
38+
openvino:
39+
# Mode 1: Build from source for ARM
40+
mode: "build"
41+
source_dir: "/path/to/openvino" # UPDATE THIS PATH
42+
commit: "HEAD"
43+
build_type: "Release"
44+
45+
# Mode 2: Use pre-built ARM install (uncomment to use)
46+
# mode: "install"
47+
# install_dir: "/path/to/openvino/arm64/install" # UPDATE THIS PATH
48+
49+
# Mode 3: Download from URL (uncomment to use)
50+
# mode: "link"
51+
# archive_url: "https://storage.openvinotoolkit.org/repositories/openvino/packages/nightly/\
52+
# 2025.4.0-19820-4671c012da0/openvino_toolkit_rhel8_2025.4.0.dev20250820_aarch64.tgz"
53+
# Or use 'latest' for auto-detection:
54+
# archive_url: "latest"
55+
56+
# ARM build options (for build mode)
57+
toolchain:
58+
cmake: "cmake"
59+
ninja: "ninja"
60+
options:
61+
ENABLE_INTEL_GPU: "OFF"
62+
ENABLE_ONEDNN_FOR_ARM: "ON"
63+
ENABLE_PYTHON: "OFF"
64+
BUILD_SHARED_LIBS: "ON"
4765

4866
# Model configuration with directory scanning
4967
models:

experiments/ssh_test_ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ device:
1010
username: testuser
1111
push_dir: /tmp/ovmobilebench
1212

13-
# Build configuration (disabled for CI)
14-
build:
15-
enabled: false
16-
openvino_repo: /tmp/openvino
13+
# OpenVINO configuration (using pre-installed for CI)
14+
openvino:
15+
mode: "install"
16+
install_dir: "/opt/openvino/install" # Pre-installed OpenVINO in CI
1717

1818
# Dummy models for testing
1919
models:

ovmobilebench/builders/openvino.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from pathlib import Path
55

6-
from ovmobilebench.config.schema import BuildConfig
6+
from ovmobilebench.config.schema import OpenVINOConfig
77
from ovmobilebench.core.errors import BuildError
88
from ovmobilebench.core.fs import ensure_dir
99
from ovmobilebench.core.shell import run
@@ -14,18 +14,22 @@
1414
class OpenVINOBuilder:
1515
"""Build OpenVINO runtime and benchmark_app for target platform."""
1616

17-
def __init__(self, config: BuildConfig, build_dir: Path, verbose: bool = False):
17+
def __init__(self, config: OpenVINOConfig, build_dir: Path, verbose: bool = False):
1818
self.config = config
1919
self.build_dir = ensure_dir(build_dir)
2020
self.verbose = verbose
2121

2222
def build(self) -> Path:
2323
"""Build OpenVINO and return path to build artifacts."""
24-
if not self.config.enabled:
25-
logger.info("Build disabled, using prebuilt binaries")
26-
return Path(self.config.openvino_repo) / "bin"
24+
if self.config.mode != "build":
25+
raise ValueError(
26+
f"OpenVINOBuilder can only be used with mode='build', got '{self.config.mode}'"
27+
)
28+
29+
if not self.config.source_dir:
30+
raise ValueError("source_dir must be specified for build mode")
2731

28-
logger.info(f"Building OpenVINO from {self.config.openvino_repo}")
32+
logger.info(f"Building OpenVINO from {self.config.source_dir}")
2933

3034
# Checkout specific commit
3135
self._checkout_commit()
@@ -40,21 +44,21 @@ def build(self) -> Path:
4044

4145
def _checkout_commit(self):
4246
"""Checkout specific commit if needed."""
43-
if self.config.openvino_commit != "HEAD":
47+
if self.config.commit != "HEAD":
4448
run(
45-
f"git checkout {self.config.openvino_commit}",
46-
cwd=Path(self.config.openvino_repo),
49+
f"git checkout {self.config.commit}",
50+
cwd=Path(self.config.source_dir),
4751
check=True,
4852
verbose=self.verbose,
4953
)
50-
logger.info(f"Checked out commit: {self.config.openvino_commit}")
54+
logger.info(f"Checked out commit: {self.config.commit}")
5155

5256
def _configure_cmake(self):
5357
"""Configure CMake for Android build."""
5458
cmake_args = [
5559
"cmake",
5660
"-S",
57-
self.config.openvino_repo,
61+
self.config.source_dir,
5862
"-B",
5963
str(self.build_dir),
6064
"-GNinja",

ovmobilebench/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Configuration module for OVMobileBench."""
22

33
from .loader import load_experiment
4-
from .schema import BuildConfig, DeviceConfig, Experiment, ReportConfig, RunConfig
4+
from .schema import DeviceConfig, Experiment, OpenVINOConfig, ReportConfig, RunConfig
55

66
__all__ = [
77
"Experiment",
8-
"BuildConfig",
8+
"OpenVINOConfig",
99
"DeviceConfig",
1010
"RunConfig",
1111
"ReportConfig",

ovmobilebench/config/schema.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,50 @@ class BuildOptions(BaseModel):
2424
BUILD_SHARED_LIBS: Literal["ON", "OFF"] = "ON"
2525

2626

27-
class BuildConfig(BaseModel):
28-
"""Build configuration."""
27+
class OpenVINOConfig(BaseModel):
28+
"""OpenVINO distribution configuration."""
2929

30-
enabled: bool = Field(True, description="Whether to build from source")
31-
openvino_repo: str = Field(..., description="Path to OpenVINO repository")
32-
openvino_commit: str = Field("HEAD", description="Git commit/tag to build")
30+
mode: Literal["build", "install", "link"] = Field(
31+
"build",
32+
description="How to obtain OpenVINO: build from source, use install dir, or download archive",
33+
)
34+
35+
# For 'build' mode
36+
source_dir: str | None = Field(
37+
None, description="Path to OpenVINO source code (for build mode)"
38+
)
39+
commit: str = Field("HEAD", description="Git commit/tag to build (for build mode)")
3340
build_type: Literal["Release", "RelWithDebInfo", "Debug"] = "RelWithDebInfo"
41+
42+
# For 'install' mode
43+
install_dir: str | None = Field(
44+
None, description="Path to OpenVINO install directory (for install mode)"
45+
)
46+
47+
# For 'link' mode
48+
archive_url: str | None = Field(
49+
None, description="URL to OpenVINO archive (for link mode). Use 'latest' for auto-detection"
50+
)
51+
52+
# Common build options (for build mode)
3453
toolchain: Toolchain = Field(
3554
default_factory=lambda: Toolchain(
3655
android_ndk=None, abi="arm64-v8a", api_level=24, cmake="cmake", ninja="ninja"
3756
)
3857
)
3958
options: BuildOptions = Field(default_factory=lambda: BuildOptions())
4059

60+
@model_validator(mode="after")
61+
def validate_mode_config(self):
62+
"""Validate that required fields are set based on mode."""
63+
if self.mode == "build" and not self.source_dir:
64+
raise ValueError("source_dir is required when mode is 'build'")
65+
elif self.mode == "install" and not self.install_dir:
66+
raise ValueError("install_dir is required when mode is 'install'")
67+
elif self.mode == "link" and not self.archive_url:
68+
raise ValueError("archive_url is required when mode is 'link'")
69+
return self
70+
4171

4272
class PackageConfig(BaseModel):
4373
"""Package configuration."""
@@ -187,7 +217,7 @@ class Experiment(BaseModel):
187217
"""Complete experiment configuration."""
188218

189219
project: ProjectConfig
190-
build: BuildConfig
220+
openvino: OpenVINOConfig
191221
package: PackageConfig = Field(default_factory=lambda: PackageConfig())
192222
device: DeviceConfig
193223
models: ModelsConfig | list[ModelItem]

0 commit comments

Comments
 (0)