|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright Advanced Micro Devices, Inc. |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +Test runner for TensileLite and rocisa Python tests using pre-built artifacts. |
| 7 | +
|
| 8 | +Runs against installed artifacts from the hipBLASLt test component: |
| 9 | + share/hipblaslt/tensilelite/Tensile/ — Tensile Python package |
| 10 | + share/hipblaslt/tensilelite/rocisa/ — rocisa Python package + _rocisa.abi3.so |
| 11 | + share/hipblaslt/tensilelite/rocisa_tests/ — rocisa pytest modules |
| 12 | +
|
| 13 | +Test order: rocisa first (build dependency of TensileLite), then TensileLite |
| 14 | +unit tests. A rocisa failure means TensileLite tests will also fail. |
| 15 | +
|
| 16 | +Usage (TheRock CI): |
| 17 | + python test_tensilelite.py |
| 18 | +
|
| 19 | +Usage (local, after install): |
| 20 | + THEROCK_BIN_DIR=./build/bin python test_tensilelite.py |
| 21 | +""" |
| 22 | + |
| 23 | +import logging |
| 24 | +import os |
| 25 | +import subprocess |
| 26 | +import sys |
| 27 | +from pathlib import Path |
| 28 | + |
| 29 | +logging.basicConfig(level=logging.INFO, format="%(message)s") |
| 30 | + |
| 31 | +SCRIPT_DIR = Path(__file__).resolve().parent |
| 32 | +THEROCK_DIR = SCRIPT_DIR.parent.parent.parent |
| 33 | +THEROCK_BIN_DIR = os.getenv("THEROCK_BIN_DIR", "") |
| 34 | + |
| 35 | +rocm_path = Path(THEROCK_BIN_DIR).resolve().parent |
| 36 | +tensilelite_root = rocm_path / "share" / "hipblaslt" / "tensilelite" |
| 37 | + |
| 38 | +if not tensilelite_root.is_dir(): |
| 39 | + raise FileNotFoundError( |
| 40 | + f"TensileLite test artifacts not found at {tensilelite_root}. " |
| 41 | + "Ensure the build used -DHIPBLASLT_INSTALL_TENSILELITE_TEST_ARTIFACTS=ON." |
| 42 | + ) |
| 43 | + |
| 44 | +env = os.environ.copy() |
| 45 | +existing_pythonpath = env.get("PYTHONPATH") |
| 46 | +env["PYTHONPATH"] = ( |
| 47 | + f"{tensilelite_root}{os.pathsep}{existing_pythonpath}" |
| 48 | + if existing_pythonpath |
| 49 | + else str(tensilelite_root) |
| 50 | +) |
| 51 | +env["ROCM_PATH"] = str(rocm_path) |
| 52 | + |
| 53 | +# _rocisa links libamdhip64.so — ensure HIP libraries are findable. |
| 54 | +lib_path = rocm_path / "lib" |
| 55 | +existing_ld_path = env.get("LD_LIBRARY_PATH", "") |
| 56 | +env["LD_LIBRARY_PATH"] = ( |
| 57 | + f"{lib_path}{os.pathsep}{existing_ld_path}" if existing_ld_path else str(lib_path) |
| 58 | +) |
| 59 | + |
| 60 | +# GPU unit tests use amdclang++ to assemble kernels. |
| 61 | +existing_path = env.get("PATH", "") |
| 62 | +env["PATH"] = os.pathsep.join( |
| 63 | + filter( |
| 64 | + None, |
| 65 | + [ |
| 66 | + str(rocm_path / "bin"), |
| 67 | + str(rocm_path / "lib" / "llvm" / "bin"), |
| 68 | + existing_path, |
| 69 | + ], |
| 70 | + ) |
| 71 | +) |
| 72 | + |
| 73 | +# Smoke test: verify install layout and stable ABI. |
| 74 | +logging.info("=== Verifying artifact install layout ===") |
| 75 | +rocisa_dir = tensilelite_root / "rocisa" |
| 76 | +logging.info( |
| 77 | + f"rocisa directory contents: {[f.name for f in rocisa_dir.iterdir() if not f.name.startswith('__')]}" |
| 78 | +) |
| 79 | +abi3_files = list(rocisa_dir.glob("*.abi3.*")) |
| 80 | +if abi3_files: |
| 81 | + logging.info(f"Stable ABI confirmed: {[f.name for f in abi3_files]}") |
| 82 | +else: |
| 83 | + logging.warning("No .abi3 extension found — stable ABI may not be enabled") |
| 84 | +subprocess.check_call( |
| 85 | + [ |
| 86 | + sys.executable, |
| 87 | + "-c", |
| 88 | + "import Tensile, rocisa, rocisa.instruction; " |
| 89 | + "print('Tensile:', Tensile.ROOT_PATH); print('rocisa:', rocisa.__file__)", |
| 90 | + ], |
| 91 | + cwd=str(THEROCK_DIR), |
| 92 | + env=env, |
| 93 | +) |
| 94 | + |
| 95 | +# rocisa tests (includes GPU tests — runner has GPU access). |
| 96 | +logging.info("=== Running rocisa tests ===") |
| 97 | +subprocess.check_call( |
| 98 | + [ |
| 99 | + sys.executable, |
| 100 | + "-m", |
| 101 | + "pytest", |
| 102 | + "-v", |
| 103 | + str(tensilelite_root / "rocisa_tests"), |
| 104 | + ], |
| 105 | + cwd=str(THEROCK_DIR), |
| 106 | + env=env, |
| 107 | +) |
| 108 | + |
| 109 | +# TensileLite Python unit tests (includes GPU subtile tests). |
| 110 | +logging.info("=== Running TensileLite unit tests ===") |
| 111 | +subprocess.check_call( |
| 112 | + [ |
| 113 | + sys.executable, |
| 114 | + "-m", |
| 115 | + "pytest", |
| 116 | + "-v", |
| 117 | + str(tensilelite_root / "Tensile" / "Tests" / "unit"), |
| 118 | + ], |
| 119 | + cwd=str(THEROCK_DIR), |
| 120 | + env=env, |
| 121 | +) |
0 commit comments