mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-06-22 07:11:12 +00:00
[AZ-321] C10 EngineCompiler: hardware-tied TRT compile + cache reuse
Land the C10 per-model engine compile + cache-reuse orchestrator. `EngineCompiler.compile_engines_for_corpus(request)` walks the corpus, computes the canonical engine filename via AZ-281 `EngineFilenameSchema.build`, and either reuses the cached binary (cache hit, AZ-280 `Sha256Sidecar.verify` returns True) or delegates to the AZ-297 `compile_engine` on the injected runtime (cache miss; the runtime owns the write path). Returns one `EngineCompileResult` per backbone carrying the canonical `EngineCacheEntry`, outcome (BUILT / REUSED), and `compile_duration_s` (None on reuse). Hardware-tied reuse (D-C10-6 / D-C10-7) falls out of the filename schema — a host change rebuilds at the new path and leaves the old files untouched (AC-4). Design corrections vs. the task spec body: - The spec proposed a c10-local `EngineCacheEntry` carrying outcome and duration; that name is already taken by the AZ-297 canonical DTO. The wrapper is renamed `EngineCompileResult`; the canonical shape wins. - The spec called `InferenceRuntime.host_info()`, which is not in the AZ-297 Protocol. `HostCapabilities` is threaded through `EngineCompileRequest` instead so the composition root owns host probing and the compiler stays decoupled. - The c10 layer cannot import `components.c7_inference` (arch rule `test_az270_compose_root.test_ac6`). `engine_compiler.py` defines `CompileEngineCallable` — a structural Protocol cut of `InferenceRuntime` exposing only `compile_engine` — and catches broad `Exception` (re-raising preserves the original type; `error_class` is recorded in the ERROR log payload). Production - engine_compiler.py: `CompileOutcome` enum, `BackboneSpec`, `EngineCompileRequest`, `EngineCompileResult`, `EngineCompileSummary` DTOs; `CompileEngineCallable` Protocol; `EngineCompiler` with the single public method. - config.py: `BackboneConfig` + `C10ProvisioningConfig` (`workspace_mb` default 4 GiB to match C7 NFT-LIM-01); validate positive shape dims and duplicate model_name detection in `__post_init__`. - runtime_root/c10_factory.py: `build_engine_compiler(config)` wires the existing `build_inference_runtime` factory through; `build_backbone_specs(config)` materialises the `BackboneSpec` tuple from the config block. - components/c10_provisioning/__init__.py: re-exports the AZ-321 surface and registers the new config block. Tests - test_engine_compiler.py: covers AC-1..AC-10 + missing-sidecar sibling case for AC-5. Tier-1 via fake runtime that writes through the REAL `Sha256Sidecar.write_atomic_and_sidecar`. Tier-2 placeholders for the cache-hit p99 NFR (200 MB engine sweep) and kill-during-compile atomic-write NFR. Docs - module-layout.md: c10_provisioning Per-Component Mapping lists the new internal modules (engine_compiler.py, config.py), the composition-root c10_factory.py, the AZ-321 public re-export surface, and the registered config block. - batch_33_cycle1_report.md + reviews/batch_33_review.md: PASS_WITH_WARNINGS (4 Low findings accepted). Tests run: c10_provisioning 13 passing + 2 Tier-2 skips; combined unit suite (excluding pending components) 543 passing, 21 env-skipped. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
"""C10 cache-provisioning factory (AZ-321).
|
||||
|
||||
Composition-root wiring for the AZ-321 :class:`EngineCompiler`. Reads
|
||||
``config.components['c10_provisioning']`` for the backbone corpus,
|
||||
resolves the :class:`InferenceRuntime` strategy via
|
||||
:func:`gps_denied_onboard.runtime_root.inference_factory.build_inference_runtime`,
|
||||
and returns a ready-to-call :class:`EngineCompiler`.
|
||||
|
||||
Backbone resolution is config-driven: the YAML enumerates the
|
||||
project's engine corpus (initially DINOv2-VPR + LightGlue + ALIKED
|
||||
per the AZ-321 task spec); adding a model is a config change rather
|
||||
than a code change.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from gps_denied_onboard.components.c10_provisioning import (
|
||||
BackboneSpec,
|
||||
EngineCompiler,
|
||||
)
|
||||
from gps_denied_onboard.components.c10_provisioning.config import (
|
||||
BackboneConfig,
|
||||
C10ProvisioningConfig,
|
||||
)
|
||||
from gps_denied_onboard.logging import get_logger
|
||||
from gps_denied_onboard.runtime_root.inference_factory import (
|
||||
build_inference_runtime,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from gps_denied_onboard.config.schema import Config
|
||||
|
||||
__all__ = [
|
||||
"build_backbone_specs",
|
||||
"build_engine_compiler",
|
||||
]
|
||||
|
||||
|
||||
def build_engine_compiler(config: "Config") -> EngineCompiler:
|
||||
"""Construct a wired :class:`EngineCompiler` from ``config``.
|
||||
|
||||
The factory:
|
||||
|
||||
1. Resolves the :class:`InferenceRuntime` via the existing
|
||||
C7 factory (honouring the ``BUILD_*`` gating and the runtime
|
||||
selection in ``config.components['c7_inference']``).
|
||||
2. Names a c10-scoped structured logger.
|
||||
3. Hands both to :class:`EngineCompiler`.
|
||||
|
||||
The :class:`BackboneSpec` corpus is NOT materialised by this
|
||||
factory — call :func:`build_backbone_specs` separately so the
|
||||
operator binary can pick up the spec list after Step 7 of the
|
||||
autodev flow without dragging an :class:`InferenceRuntime` along.
|
||||
"""
|
||||
|
||||
runtime = build_inference_runtime(config)
|
||||
logger = get_logger("c10_provisioning")
|
||||
return EngineCompiler(inference_runtime=runtime, logger=logger)
|
||||
|
||||
|
||||
def build_backbone_specs(config: "Config") -> tuple[BackboneSpec, ...]:
|
||||
"""Materialise :class:`BackboneSpec` tuple from
|
||||
``config.components['c10_provisioning'].backbones``.
|
||||
|
||||
Resolves each :class:`BackboneConfig` ``onnx_path`` string into
|
||||
an absolute :class:`Path` (validation happened at load time via
|
||||
:meth:`BackboneConfig.__post_init__`).
|
||||
"""
|
||||
|
||||
block: C10ProvisioningConfig = config.components["c10_provisioning"]
|
||||
return tuple(_backbone_spec_from_config(bb) for bb in block.backbones)
|
||||
|
||||
|
||||
def _backbone_spec_from_config(
|
||||
backbone: BackboneConfig,
|
||||
) -> BackboneSpec:
|
||||
return BackboneSpec(
|
||||
model_name=backbone.model_name,
|
||||
onnx_path=Path(backbone.onnx_path),
|
||||
expected_input_shape=tuple(backbone.expected_input_shape),
|
||||
input_name=backbone.input_name,
|
||||
)
|
||||
Reference in New Issue
Block a user