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
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Utility for kpacking fat binaries by removing .hip_fatbin sections.
|
|
|
|
This tool removes .hip_fatbin sections from ELF binaries and reclaims disk space
|
|
by shifting subsequent sections to fill the gap. Unlike objcopy --remove-section,
|
|
this tool actually modifies PT_LOAD segments to eliminate device code content.
|
|
|
|
Usage:
|
|
python -m rocm_kpack.tools.kpack_binary <input_binary> <output_binary>
|
|
|
|
Example:
|
|
python -m rocm_kpack.tools.kpack_binary librocblas.so.5.1 librocblas_host_only.so
|
|
"""
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
from rocm_kpack.elf import kpack_offload_binary
|
|
|
|
|
|
def run(args: argparse.Namespace):
|
|
input_path = args.input
|
|
output_path = args.output
|
|
|
|
print(f"Kpacking: {input_path}")
|
|
print(f"Output: {output_path}")
|
|
print()
|
|
|
|
result = kpack_offload_binary(input_path, output_path, verbose=True)
|
|
|
|
print()
|
|
print(f"Results:")
|
|
print(
|
|
f" Original size: {result['original_size']:,} bytes ({result['original_size'] / (1024**2):.2f} MB)"
|
|
)
|
|
print(
|
|
f" New size: {result['new_size']:,} bytes ({result['new_size'] / (1024**2):.2f} MB)"
|
|
)
|
|
print(
|
|
f" Removed: {result['removed']:,} bytes ({result['removed'] / (1024**2):.2f} MB)"
|
|
)
|
|
if result["original_size"] > 0:
|
|
reduction_pct = (result["removed"] / result["original_size"]) * 100
|
|
print(f" Reduction: {reduction_pct:.2f}%")
|
|
|
|
|
|
def main(argv: list[str]):
|
|
p = argparse.ArgumentParser(
|
|
description="Kpack fat binaries by removing .hip_fatbin sections and reclaiming disk space"
|
|
)
|
|
p.add_argument(
|
|
"input", type=Path, help="Input fat binary (ELF executable or shared library)"
|
|
)
|
|
p.add_argument("output", type=Path, help="Output host-only binary")
|
|
args = p.parse_args(argv)
|
|
run(args)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv[1:])
|