Files
TheRock/rocm-libraries/projects/hipblaslt/tensilelite/Tensile/backends/base.py
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

118 lines
4.5 KiB
Python

# Copyright Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT
"""
Backend abstraction for benchmark solution selection and optimization strategies.
Provides a pluggable interface for different solution enumeration and optimization backends:
- TensileBackend: Exhaustive fork parameter enumeration
- DuctileBackend: Genetic algorithm-based parameter optimization
Each backend implements its own candidate generation and evaluation loop,
calling out to shared helpers provided by BenchmarkProblems.
"""
from abc import ABC, abstractmethod
from typing import Dict, Any, List, Callable, Tuple
class OptimizationBackend(ABC):
"""Abstract base class for optimization backends.
A backend orchestrates the solution optimization strategy (exhaustive, GA, etc.)
by implementing run(). The run() method handles its own
candidate generation and evaluation loop, calling shared helper functions
provided by the caller.
"""
@abstractmethod
def run(self,
backend_config: Dict[str, Any],
benchmark_config: Dict[str, Any],
benchmark_runner: Callable[..., Tuple[str, int]],
cacheValid: bool = False,
buildOnly: bool = False) -> None:
"""Execute the backend's optimization strategy.
The backend orchestrates its own candidate generation loop, converts candidates
to solutions, and benchmarks them. Each backend handles solution generation
using helper functions from BenchmarkProblems.
Args:
backend_config: Configuration dict containing backend-specific settings.
benchmark_config: Configuration dict containing backend-specific step settings.
Required keys: forkParams, constantParams, paramGroups,
customKernels, internalSupportParams, customKernelWildcard,
ForkParameters, problemType, assembler, debugConfig, isaInfoMap,
sourcePath
benchmark_runner: Callable that benchmarks a list of solutions and returns results.
Signature: (solutions, isCached=False, buildOnly=False)
-> (resultsFileName, returncode)
cacheValid: If True, matching cache data is available for this step
buildOnly: If True, skip benchmarking (only build/compile kernels)
Returns:
None
"""
pass
@abstractmethod
def supports_solution_pool(self) -> bool:
"""Check if this backend supports loading solutions from a solution pool.
Returns:
True if the backend can load solutions from pool files, False otherwise.
"""
pass
class BackendFactory:
"""Factory for registering and instantiating benchmark backends."""
_backends: Dict[str, type] = {}
@classmethod
def register(cls, name: str, backend_class: type) -> None:
"""Register a backend class.
Args:
name: String identifier for the backend (e.g., 'tensile', 'ductile')
backend_class: Class that inherits from OptimizationBackend
"""
if not issubclass(backend_class, OptimizationBackend):
raise TypeError(f"{backend_class} must inherit from OptimizationBackend")
cls._backends[name] = backend_class
@classmethod
def create(cls, name: str) -> OptimizationBackend:
"""Create an instance of a registered backend.
Args:
name: String identifier of the backend to create
Returns:
New instance of the backend class
Raises:
ValueError: If backend name is not registered
"""
if name == "ductile" and name not in cls._backends:
from .ductile_backend import DuctileBackend
cls.register("ductile", DuctileBackend)
if name not in cls._backends:
raise ValueError(f"Unknown backend: {name}. Registered backends: {list(cls._backends.keys())}")
return cls._backends[name]()
@classmethod
def get_available_backends(cls) -> List[str]:
"""Get list of registered backend names.
Returns:
List of available backend identifiers
"""
return list(cls._backends.keys())