Files
kernbench2/benches/loader.py
T
ywkang 08812eda58 Add virtual memory support: PE_MMU, VA allocator, fabric MmuMapMsg
Implement VA/MMU layer (ADR-0011 Phase 1) enabling Triton kernels to use
contiguous virtual addresses on sharded tensors.

Key changes:
- PE_MMU component: hybrid inbox (MmuMapMsg) + sync translate() for PE_DMA
- VirtualAllocator + PEMemAllocator: free-list with coalescing
- MmuMapMsg/MmuUnmapMsg fabric path with SIP-level routing
- DPPolicy-based mapping: replicate=local, sharded=broadcast
- Tensor lifecycle: del + weakref cleanup, context manager
- Rename: TensorHandle.pa→addr, DmaReadCmd.src_pa→src_addr, ctx→torch

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 00:01:47 -07:00

38 lines
1.0 KiB
Python

from __future__ import annotations
import importlib
from collections.abc import Callable
from typing import Any
from kernbench.runtime_api.context import RuntimeContext
BenchFn = Callable[[RuntimeContext], Any]
def resolve_bench(bench_id: str) -> BenchFn:
"""
Resolve a bench id into a callable bench function.
Expected layout (repo root):
benches/<bench_id>.py
def run(torch: RuntimeContext) -> Any
"""
bench_id = bench_id.strip()
if not bench_id:
raise ValueError("Bench id is empty.")
module_path = f"benches.{bench_id}"
try:
mod = importlib.import_module(module_path)
except ModuleNotFoundError as e:
raise ValueError(f"Unknown bench '{bench_id}'. Expected module {module_path}.py") from e
run_fn = getattr(mod, "run", None)
if run_fn is None:
raise ValueError(f"Bench module {module_path} must define a 'run(torch)' function.")
if not callable(run_fn):
raise ValueError(f"'run' in {module_path} is not callable.")
return run_fn