hip-tests: new package (#47273)

* hip-tests: add new package
* remove hip-tests from hip recipe
* remove old versions
* fix style
* add missing import
* bump hip-tests to 6.3.1
* fix style
This commit is contained in:
afzpatel 2025-02-05 18:35:04 -05:00 committed by GitHub
parent e0e6f29584
commit c943c8c1d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 177 additions and 94 deletions

View File

@ -0,0 +1,177 @@
# Copyright Spack Project Developers. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import spack.build_systems.cmake
from spack.package import *
class HipTests(CMakePackage):
"""This repository provides unit tests for HIP implementation."""
homepage = "https://github.com/ROCm/hip-tests"
url = "https://github.com/ROCm/hip-tests/archive/refs/tags/rocm-6.1.2.tar.gz"
git = "https://github.com/ROCm/hip-tests.git"
tags = ["rocm"]
maintainers("srekolam", "renjithravindrankannath", "afzpatel")
version("6.3.1", sha256="0fc1cf4f46f2bbef377d65803d86c2489b01b598c468070c79c5114a661f07c6")
version("6.3.0", sha256="8081d4ab1a43ffa1cebd646668d83008b799ab98c14daf7b455922355a439c8a")
version("6.2.4", sha256="1478b49583d09cb3a96e26ec3bf8dc5ff3e3ec72fa133bb6d7768595d825051e")
version("6.2.1", sha256="90fcf0169889533b882d289f9cb8a7baf9bd46a3ce36752b915083931dc839f1")
version("6.2.0", sha256="314837dbac78be71844ceb959476470c484fdcd4fb622ff8de9277783e0fcf1c")
version("6.1.2", sha256="5b14e4a30d8d8fb56c43e262009646ba9188eac1c8ff882d9a606a4bec69b56b")
version("6.1.1", sha256="10c96ee72adf4580056292ab17cfd858a2fd7bc07abeb41c6780bd147b47f7af")
version("6.1.0", sha256="cf3a6a7c43116032d933cc3bc88bfc4b17a4ee1513c978e751755ca11a5ed381")
depends_on("c", type="build") # generated
depends_on("cxx", type="build") # generated
depends_on("cmake", type="run")
for ver in ["6.1.0", "6.1.1", "6.1.2", "6.2.0", "6.2.1", "6.2.4", "6.3.0", "6.3.1"]:
depends_on(f"rocm-cmake@{ver}:", type="build", when=f"@{ver}")
depends_on(f"hip@{ver}", when=f"@{ver}")
depends_on(f"rocm-core@{ver}", when=f"@{ver}")
depends_on(f"rocminfo@{ver}", when=f"@{ver}")
depends_on(f"hipify-clang@{ver}", when=f"@{ver}")
depends_on(f"llvm-amdgpu@{ver}", when=f"@{ver}")
root_cmakelists_dir = "catch"
def patch(self):
filter_file(
"${ROCM_PATH}/bin/rocm_agent_enumerator",
f"{self.spec['rocminfo'].prefix}/bin/rocm_agent_enumerator",
"catch/CMakeLists.txt",
string=True,
)
filter_file(
"/opt/rocm/bin/rocm_agent_enumerator",
f"{self.spec['rocminfo'].prefix}/bin/rocm_agent_enumerator",
"catch/hipTestMain/hip_test_context.cc",
string=True,
)
filter_file(
"${HIP_PATH}/llvm",
self.spec["llvm-amdgpu"].prefix,
"samples/2_Cookbook/17_llvm_ir_to_executable/CMakeLists.txt",
"samples/2_Cookbook/16_assembly_to_executable/CMakeLists.txt",
string=True,
)
filter_file(
"${ROCM_PATH}/llvm",
self.spec["llvm-amdgpu"].prefix,
"catch/CMakeLists.txt",
"samples/2_Cookbook/16_assembly_to_executable/CMakeLists.txt",
"samples/2_Cookbook/21_cmake_hip_cxx_clang/CMakeLists.txt",
"samples/2_Cookbook/18_cmake_hip_device/CMakeLists.txt",
"samples/2_Cookbook/17_llvm_ir_to_executable/CMakeLists.txt",
"samples/2_Cookbook/23_cmake_hiprtc/CMakeLists.txt",
"samples/2_Cookbook/22_cmake_hip_lang/CMakeLists.txt",
"samples/2_Cookbook/19_cmake_lang/CMakeLists.txt",
string=True,
)
filter_file(
"${CMAKE_PREFIX_PATH}/bin/hipify-perl",
f"{self.spec['hipify-clang'].prefix.bin}/hipify-perl",
"samples/0_Intro/square/CMakeLists.txt",
string=True,
)
def setup_build_environment(self, env):
env.set("CXX", self.spec["hip"].hipcc)
def cmake_args(self):
args = [
self.define("HIP_PLATFORM", "amd"),
self.define("HIP_PATH", self.spec["hip"].prefix),
self.define("ROCM_PATH", self.spec["hip"].prefix),
]
if self.spec.satisfies("^cmake@3.21.0:3.21.2"):
args.append(self.define("__skip_rocmclang", "ON"))
return args
def build(self, spec, prefix):
with working_dir(self.build_directory):
make("build_tests")
@run_after("install")
def cache_test_sources(self):
"""Copy the tests source files after the package is installed to an
install test subdirectory for use during `spack test run`."""
cache_extra_test_sources(self, "samples")
def test_samples(self):
"""build and run all hip samples"""
sample_test_binaries = [
"0_Intro/bit_extract/bit_extract",
"0_Intro/module_api/launchKernelHcc.hip.out",
"0_Intro/module_api/runKernel.hip.out",
"0_Intro/module_api/defaultDriver.hip.out",
"0_Intro/module_api_global/runKernel1.hip.out",
"0_Intro/square/square",
"1_Utils/hipDispatchLatency/hipDispatchEnqueueRateMT",
"1_Utils/hipDispatchLatency/hipDispatchLatency",
"1_Utils/hipInfo/hipInfo",
"2_Cookbook/0_MatrixTranspose/MatrixTranspose",
"2_Cookbook/1_hipEvent/hipEvent",
"2_Cookbook/3_shared_memory/sharedMemory",
"2_Cookbook/4_shfl/shfl",
"2_Cookbook/5_2dshfl/2dshfl",
"2_Cookbook/6_dynamic_shared/dynamic_shared",
"2_Cookbook/8_peer2peer/peer2peer",
"2_Cookbook/9_unroll/unroll",
"2_Cookbook/10_inline_asm/inline_asm",
"2_Cookbook/11_texture_driver/texture2dDrv",
"2_Cookbook/12_cmake_hip_add_executable/MatrixTranspose1",
"2_Cookbook/13_occupancy/occupancy",
"2_Cookbook/14_gpu_arch/gpuarch",
"2_Cookbook/15_static_library/device_functions/test_device_static",
"2_Cookbook/15_static_library/host_functions/test_opt_static",
"2_Cookbook/16_assembly_to_executable/square_asm.out",
"2_Cookbook/17_llvm_ir_to_executable/square_ir.out",
"2_Cookbook/18_cmake_hip_device/test_cpp",
"2_Cookbook/19_cmake_lang/test_cpp1",
"2_Cookbook/19_cmake_lang/test_fortran",
"2_Cookbook/21_cmake_hip_cxx_clang/square1",
"2_Cookbook/22_cmake_hip_lang/square2",
"2_Cookbook/23_cmake_hiprtc/test",
]
test_dir = join_path(self.test_suite.current_test_cache_dir, "samples")
prefix_paths = ";".join(spack.build_systems.cmake.get_cmake_prefix_path(self))
clang_cpp_path = join_path(self.spec["llvm-amdgpu"].prefix, "bin", "clang++")
clang_path = join_path(self.spec["llvm-amdgpu"].prefix, "bin", "clang")
cc_options = [
f"-DCMAKE_MODULE_PATH={self.spec['hip'].prefix.lib.cmake.hip}",
f"-DCMAKE_PREFIX_PATH={prefix_paths}",
f"-DCMAKE_CXX_COMPILER={clang_cpp_path}",
f"-DCMAKE_C_COMPILER={clang_path}",
f"-DHIP_HIPCC_EXECUTABLE={self.spec['hip'].prefix.bin}/hipcc",
f"-DCMAKE_HIP_COMPILER_ROCM={clang_cpp_path}",
".",
]
cmake = which(self.spec["cmake"].prefix.bin.cmake)
with working_dir(test_dir, create=True):
cmake(*cc_options)
make("build_samples")
for binary_path in sample_test_binaries:
# binaries need to run in their directories
bin_dir, binary = os.path.split(binary_path)
with working_dir(bin_dir, create=True):
with test_part(
self,
"test_sample_{0}".format(binary),
purpose="configure, build and run test: {0}".format(binary),
):
exe = Executable(binary)
if binary == "hipDispatchEnqueueRateMT":
options = ["16", "0"]
else:
options = []
exe(*options)

View File

@ -5,7 +5,6 @@
import os
import re
import spack.build_environment
from spack.hooks.sbang import filter_shebang
from spack.package import *
@ -325,33 +324,6 @@ class Hip(CMakePackage):
when=f"@{d_version} +cuda",
)
# Add hiptests sources thru the below
for d_version, d_shasum in [
("6.3.1", "0fc1cf4f46f2bbef377d65803d86c2489b01b598c468070c79c5114a661f07c6"),
("6.3.0", "8081d4ab1a43ffa1cebd646668d83008b799ab98c14daf7b455922355a439c8a"),
("6.2.4", "1478b49583d09cb3a96e26ec3bf8dc5ff3e3ec72fa133bb6d7768595d825051e"),
("6.2.1", "90fcf0169889533b882d289f9cb8a7baf9bd46a3ce36752b915083931dc839f1"),
("6.2.0", "314837dbac78be71844ceb959476470c484fdcd4fb622ff8de9277783e0fcf1c"),
("6.1.2", "5b14e4a30d8d8fb56c43e262009646ba9188eac1c8ff882d9a606a4bec69b56b"),
("6.1.1", "10c96ee72adf4580056292ab17cfd858a2fd7bc07abeb41c6780bd147b47f7af"),
("6.1.0", "cf3a6a7c43116032d933cc3bc88bfc4b17a4ee1513c978e751755ca11a5ed381"),
("6.0.2", "740ca064f4909c20d83226a63c2f164f7555783ec5f5f70be5bc23d3587ad829"),
("6.0.0", "e8f92a0f5d1f6093ca1fb24ff1b7140128900fcdc6e9f01f153d6907e5c2d807"),
("5.7.1", "28fbdf49f405adfee903bc0f05a43ac392c55b34c514c3582dfb7d6d67e79985"),
("5.7.0", "b1dae3cfc715e71dce92ac1da94265a9398944c76cee85ffab8f0c93665a48d6"),
("5.6.1", "5b3002ddfafda162329e4d9e6ac1200eeb48ff08e666b342aa8aeca30750f48b"),
("5.6.0", "8cf4509bf9c0747dab8ed8fec1365a9156792034b517207a0b2d63270429fd2e"),
]:
resource(
name="hip-tests",
url=f"https://github.com/ROCm/hip-tests/archive/refs/tags/rocm-{d_version}.tar.gz",
sha256=d_shasum,
expand=True,
destination="",
placement="hip-tests",
when=f"@{d_version}",
)
# Improve compilation without git repo and remove compiler rt linkage
# for host and correction in CMake target path variable and
# correcting the CMake path variable.
@ -673,69 +645,3 @@ def cmake_args(self):
if self.spec.satisfies("@6.0:"):
args.append(self.define("HIPCC_BIN_DIR", self.spec["hipcc"].prefix.bin))
return args
test_src_dir_old = "samples"
test_src_dir = "hip-tests/samples"
@run_after("install")
def install_samples(self):
if self.spec.satisfies("@5.6.0:"):
install_tree(self.test_src_dir, self.spec.prefix.share.samples)
@run_after("install")
def cache_test_sources(self):
"""Copy the tests source files after the package is installed to an
install test subdirectory for use during `spack test run`."""
if self.spec.satisfies("@5.1:5.5"):
cache_extra_test_sources(self, [self.test_src_dir_old])
elif self.spec.satisfies("@5.6:"):
cache_extra_test_sources(self, [self.test_src_dir])
def test_samples(self):
"""build and run all hip samples"""
if self.spec.satisfies("@5.1:5.5"):
test_dir = join_path(self.test_suite.current_test_cache_dir, self.test_src_dir_old)
elif self.spec.satisfies("@5.6:"):
test_dir = join_path(self.test_suite.current_test_cache_dir, self.test_src_dir)
prefixes = ";".join(spack.build_environment.get_cmake_prefix_path(self))
cc_options = ["-DCMAKE_PREFIX_PATH=" + prefixes, ".."]
amdclang_path = join_path(self.spec["llvm-amdgpu"].prefix, "bin", "amdclang++")
os.environ["CXX"] = amdclang_path
os.environ["FC"] = "/usr/bin/gfortran"
cmake = which(self.spec["cmake"].prefix.bin.cmake)
for root, dirs, files in os.walk(test_dir):
dirs.sort()
if "CMakeLists.txt" in files or "Makefile" in files:
with working_dir(root, create=True):
head, test_name = os.path.split(root)
with test_part(
self,
"test_sample_{0}".format(test_name),
purpose="configure, build and run test: {0}".format(test_name),
):
if "CMakeLists.txt" in files:
print("Configuring test " + test_name)
os.mkdir("build")
os.chdir("build")
cmake(*cc_options)
print("Building test " + test_name)
make(parallel=False)
# iterate through the files in dir to find the newly built binary
for file in os.listdir("."):
if (
file not in files
and os.path.isfile(file)
and os.access(file, os.X_OK)
and not file.endswith(".o")
):
print("Executing test binary: " + file)
exe = which(file)
if file == "hipDispatchEnqueueRateMT":
options = ["16", "0"]
else:
options = []
exe(*options)