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
100 lines
2.9 KiB
Python
100 lines
2.9 KiB
Python
"""Parallel processing utilities for kernel preparation.
|
|
|
|
This module provides utilities for parallelizing CPU-intensive kernel preparation
|
|
(compression, preprocessing) while keeping metadata manipulation (TOC updates) sequential.
|
|
"""
|
|
|
|
import os
|
|
from concurrent.futures import Executor, ThreadPoolExecutor, as_completed
|
|
from typing import NamedTuple
|
|
|
|
from rocm_kpack.kpack import PackedKernelArchive, PreparedKernel
|
|
|
|
|
|
class KernelInput(NamedTuple):
|
|
"""Input data for preparing a kernel for packing.
|
|
|
|
Attributes:
|
|
relative_path: Path relative to archive root (e.g., "kernels/my_kernel")
|
|
gfx_arch: GPU architecture (e.g., "gfx1100")
|
|
hsaco_data: Raw HSACO binary data
|
|
metadata: Optional metadata dict to store in TOC
|
|
"""
|
|
|
|
relative_path: str
|
|
gfx_arch: str
|
|
hsaco_data: bytes
|
|
metadata: dict[str, object] | None
|
|
|
|
|
|
def get_worker_count(max_workers: int | None = None) -> int:
|
|
"""Determine the number of worker threads to use.
|
|
|
|
Args:
|
|
max_workers: Explicit worker count, or None for auto-detection
|
|
|
|
Returns:
|
|
Number of worker threads (minimum 1)
|
|
"""
|
|
if max_workers is not None:
|
|
return max(1, max_workers)
|
|
|
|
# Auto-detect: use all available cores
|
|
cpu_count = os.cpu_count()
|
|
if cpu_count is None:
|
|
return 1
|
|
return max(1, cpu_count)
|
|
|
|
|
|
def parallel_prepare_kernels(
|
|
archive: PackedKernelArchive,
|
|
kernels: list[KernelInput],
|
|
executor: Executor | None = None,
|
|
) -> list[PreparedKernel]:
|
|
"""Prepare multiple kernels in parallel using provided executor.
|
|
|
|
This is the map phase of map/reduce compression. Each kernel is prepared
|
|
(compressed/preprocessed) independently in parallel, then the results can
|
|
be added to the archive sequentially.
|
|
|
|
Args:
|
|
archive: PackedKernelArchive instance
|
|
kernels: List of KernelInput objects containing kernel data and metadata
|
|
executor: Executor for parallel execution. If None, runs sequentially.
|
|
|
|
Returns:
|
|
List of PreparedKernel objects in the same order as input
|
|
"""
|
|
if not kernels:
|
|
return []
|
|
|
|
# Sequential path when no executor provided
|
|
if executor is None:
|
|
return [
|
|
archive.prepare_kernel(
|
|
k.relative_path, k.gfx_arch, k.hsaco_data, k.metadata
|
|
)
|
|
for k in kernels
|
|
]
|
|
|
|
# Parallel preparation using provided executor
|
|
# Submit all tasks
|
|
future_to_index = {}
|
|
for i, k in enumerate(kernels):
|
|
future = executor.submit(
|
|
archive.prepare_kernel,
|
|
k.relative_path,
|
|
k.gfx_arch,
|
|
k.hsaco_data,
|
|
k.metadata,
|
|
)
|
|
future_to_index[future] = i
|
|
|
|
# Collect results in original order
|
|
results = [None] * len(kernels)
|
|
for future in as_completed(future_to_index):
|
|
index = future_to_index[future]
|
|
results[index] = future.result()
|
|
|
|
return results
|