Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion shared/kpack/python/rocm_kpack/database_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ def should_move(self, path: Path) -> bool:


# Regex matching a library/<arch>/ path component (for per-arch subdirectory layout).
# A stepping suffix (library/gfx1250v0/ holds gfx1250 A0 kernels) is not a separate
# target: the directory belongs to its base arch, matching the arch in the filenames.
_LIBRARY_ARCH_DIR_PATTERN = re.compile(
r"/library/(" + _GFX_ARCH_PATTERN.pattern + r")/"
r"/library/(" + _GFX_ARCH_PATTERN.pattern + r")(?:v\d+)?/"
)


Expand Down
4 changes: 4 additions & 0 deletions shared/kpack/python/rocm_kpack/tools/verify_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def _check_architecture_separation(self, artifacts: list[Path]) -> None:

# Find arch-specific artifacts (not generic, not gfx906 which is minimal)
arch_pattern = re.compile(r"gfx\d+[a-z]*(?:-strict)?")
# Stepping directories (gfx1250v0) hold kernels for their base arch.
stepping_dir_pattern = re.compile(r"(gfx\d+[a-z]*?)v\d+")
# Bundle keys may include a sub-family suffix, such as gfx12_0.
bundle_pattern = re.compile(r"gfx\d+[a-z]*(?:_\d+)?(?:-strict)?")
arch_artifacts = []
Expand Down Expand Up @@ -335,6 +337,8 @@ def _check_architecture_separation(self, artifacts: list[Path]) -> None:
directory_arch = aotriton.detect(file, artifact)
if directory_arch is not None:
directory_arches.append(directory_arch)
elif stepping := stepping_dir_pattern.fullmatch(part):
directory_arches.append(stepping.group(1))
else:
directory_arches.extend(arch_pattern.findall(part))
# Handlers may preserve xnack features while filename/directory
Expand Down
30 changes: 30 additions & 0 deletions shared/kpack/tests/test_database_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,24 @@ def test_detect_arch_subdir_manifest(self, handler, prefix_root):
result = handler.detect(file_path, prefix_root)
assert result == "gfx1100"

@pytest.mark.parametrize(
"filename",
[
"TensileLibrary_lazy_gfx1250.dat.zlib",
"TensileLibrary_Type_HH_gfx1250.dat.zlib",
"TensileLibrary_Type_HH_gfx1250.co",
"Kernels.so-000-gfx1250.hsaco",
],
)
def test_detect_arch_subdir_stepping(self, handler, prefix_root, filename):
"""Stepping subdirectory library/gfx1250v0/ belongs to the gfx1250 bundle."""
file_path = prefix_root / "lib/hipblaslt/library/gfx1250v0" / filename
file_path.parent.mkdir(parents=True)
file_path.touch()

result = handler.detect(file_path, prefix_root)
assert result == "gfx1250"

def test_reject_wrong_directory(self, handler, prefix_root):
"""Test that files not in hipblaslt/library are rejected."""
file_path = prefix_root / "lib/rocblas/library/TensileLibrary_gfx1100.dat"
Expand Down Expand Up @@ -424,6 +442,18 @@ def test_detect_arch_subdir_dat(self, handler, prefix_root):
result = handler.detect(file_path, prefix_root)
assert result == "gfx950"

def test_detect_arch_subdir_stepping(self, handler, prefix_root):
"""Stepping subdirectory library/gfx1250v0/ belongs to the gfx1250 bundle."""
file_path = (
prefix_root
/ "lib/hipsparselt/library/gfx1250v0/TensileLibrary_lazy_gfx1250.dat.zlib"
)
file_path.parent.mkdir(parents=True)
file_path.touch()

result = handler.detect(file_path, prefix_root)
assert result == "gfx1250"

def test_reject_wrong_directory(self, handler, prefix_root):
file_path = prefix_root / "lib/rocblas/library/something_gfx942.co"
file_path.parent.mkdir(parents=True)
Expand Down
63 changes: 63 additions & 0 deletions shared/kpack/tests/test_strict_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,54 @@ def test_split_preserves_only_selected_database_payloads(tmp_path, selected):
assert not list((dest / "miopen_lib_generic").rglob("*.db.txt"))


def test_split_routes_stepping_directory_to_base_arch(tmp_path):
# hipBLASLt installs gfx1250 A0 kernels under library/gfx1250v0/ with
# gfx1250 filenames; every file there must ship with the gfx1250 bundle.
source = tmp_path / "blas_lib_gfx125X-all"
prefix = "math-libs/BLAS/hipBLASLt/stage"
library = source / prefix / "lib/hipblaslt/library"
layout = {
"gfx1250": "gfx1250",
"gfx1250v0": "gfx1250",
"gfx1250-strict": "gfx1250-strict",
}
for directory, target in layout.items():
(library / directory).mkdir(parents=True)
for name in [
f"TensileLibrary_lazy_{target}.dat.zlib",
f"TensileLibrary_Type_HH_{target}.dat.zlib",
f"TensileLibrary_Type_HH_{target}.co",
]:
(library / directory / name).write_text(directory)
write_artifact_manifest(source, [prefix])
dest = tmp_path / "split"
splitter = ArtifactSplitter(
artifact_prefix="blas_lib",
toolchain=Toolchain(),
database_handlers=[HipBLASLtHandler()],
gpu_targets=["gfx1250", "gfx1250-strict"],
)
splitter.split(source, dest)

def library_dirs(artifact):
output = dest / artifact / prefix / "lib/hipblaslt/library"
return {d.name: sorted(p.name for p in d.iterdir()) for d in output.iterdir()}

assert set(library_dirs("blas_lib_gfx1250")) == {"gfx1250", "gfx1250v0"}
assert len(library_dirs("blas_lib_gfx1250")["gfx1250v0"]) == 3
assert set(library_dirs("blas_lib_gfx1250-strict")) == {"gfx1250-strict"}
assert not [
p
for p in (dest / "blas_lib_generic").rglob("*")
if p.is_file() and "hipblaslt/library" in p.as_posix()
]
verifier = ArtifactVerifier(dest, Toolchain())
verifier._check_architecture_separation(
[dest / "blas_lib_gfx1250", dest / "blas_lib_gfx1250-strict"]
)
assert verifier.results[-1].passed


def test_archive_and_bundler_identity(tmp_path):
target = "gfx1250-strict"
assert (
Expand Down Expand Up @@ -134,6 +182,21 @@ def test_verifier_detects_target_directory_contamination(tmp_path):
assert not verifier.results[-1].passed


@pytest.mark.parametrize(
"artifact_target,passed", [("gfx1250", True), ("gfx1250-strict", False)]
)
def test_verifier_maps_stepping_directory_to_base_arch(
tmp_path, artifact_target, passed
):
artifact = tmp_path / f"blas_lib_{artifact_target}"
directory = artifact / "stage/lib/hipblaslt/library/gfx1250v0"
directory.mkdir(parents=True)
(directory / "TensileLibrary_lazy_gfx1250.dat.zlib").write_text("data")
verifier = ArtifactVerifier(tmp_path, Toolchain())
verifier._check_architecture_separation([artifact])
assert verifier.results[-1].passed == passed


@pytest.mark.parametrize("valid", [True, False])
def test_verifier_checks_archives_under_component_stage(tmp_path, valid):
target = "gfx1250-strict"
Expand Down
Loading