"""Kernel registry: maps kernel names to Python callable generators.

Benchmarks register kernel functions here; PE_CPU looks them up by
KernelRef.name at execution time.
"""
from __future__ import annotations

from collections.abc import Callable
from typing import Any

_kernels: dict[str, Callable[..., None]] = {}


def register_kernel(name: str, fn: Callable[..., None]) -> None:
    """Register a kernel function by name."""
    if name in _kernels:
        raise ValueError(f"kernel '{name}' already registered")
    _kernels[name] = fn


def get_kernel(name: str) -> Callable[..., None]:
    """Look up a registered kernel function by name."""
    if name not in _kernels:
        raise KeyError(f"kernel '{name}' not registered")
    return _kernels[name]


def clear_registry() -> None:
    """Clear all registered kernels (for testing)."""
    _kernels.clear()
