From 134b954c7f7863b33cd76a14e1dbd5976f24da3c Mon Sep 17 00:00:00 2001 From: afzpatel <122491982+afzpatel@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:39:49 -0400 Subject: [PATCH] enabling test for rccl hsakmt-roct and rocm-opencl (#35465) * initial commit for enabling test for rccl hsakmt-roct and rocm-opencl * fix styling and cleaning code * adding missing imports and minor fixes * minor style fix * moidfying hsakmt-roct test to run right after installation --- .../builtin/packages/hsakmt-roct/package.py | 36 +++++++++++++++++++ .../repos/builtin/packages/rccl/package.py | 11 ++++++ .../builtin/packages/rocm-opencl/package.py | 14 +++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/var/spack/repos/builtin/packages/hsakmt-roct/package.py b/var/spack/repos/builtin/packages/hsakmt-roct/package.py index a8d979698526e9..4d594406c7d7b0 100644 --- a/var/spack/repos/builtin/packages/hsakmt-roct/package.py +++ b/var/spack/repos/builtin/packages/hsakmt-roct/package.py @@ -4,6 +4,8 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) +import os + from spack.package import * @@ -113,6 +115,7 @@ class HsakmtRoct(CMakePackage): depends_on("cmake@3:", type="build") depends_on("numactl") depends_on("libdrm", when="@4.5.0:") + depends_on("llvm-amdgpu", type="test", when="@5.3.0:") # See https://github.com/RadeonOpenCompute/ROCT-Thunk-Interface/issues/72 # and https://github.com/spack/spack/issues/28398 @@ -128,3 +131,36 @@ def install_targets(self): def cmake_args(self): return [self.define_from_variant("BUILD_SHARED_LIBS", "shared")] + + @run_after("install") + @on_package_attributes(run_tests=True) + def check_install(self): + if self.spec.satisfies("@:5.3.0"): + print("Skipping: stand-alone tests") + return + test_dir = "tests/kfdtest" + with working_dir(test_dir, create=True): + cmake_bin = join_path(self.spec["cmake"].prefix.bin, "cmake") + prefixes = ";".join( + [ + self.spec["libdrm"].prefix, + self.spec["hsakmt-roct"].prefix, + self.spec["numactl"].prefix, + self.spec["pkgconfig"].prefix, + self.spec["llvm-amdgpu"].prefix, + self.spec["zlib"].prefix, + self.spec["ncurses"].prefix, + ] + ) + hsakmt_path = ";".join([self.spec["hsakmt-roct"].prefix]) + cc_options = [ + "-DCMAKE_PREFIX_PATH=" + prefixes, + "-DLIBHSAKMT_PATH=" + hsakmt_path, + ".", + ] + self.run_test(cmake_bin, cc_options) + make() + os.environ["LD_LIBRARY_PATH"] = hsakmt_path + os.environ["BIN_DIR"] = os.getcwd() + self.run_test("scripts/run_kfdtest.sh") + make("clean") diff --git a/var/spack/repos/builtin/packages/rccl/package.py b/var/spack/repos/builtin/packages/rccl/package.py index 91e3b3fbc544ad..bdae9578de75fa 100644 --- a/var/spack/repos/builtin/packages/rccl/package.py +++ b/var/spack/repos/builtin/packages/rccl/package.py @@ -188,6 +188,7 @@ class Rccl(CMakePackage): "5.4.3", ]: depends_on("rocm-smi-lib@" + ver, when="@" + ver) + depends_on("chrpath", when="@5.3.0:") @classmethod def determine_version(cls, lib): @@ -216,4 +217,14 @@ def cmake_args(self): if self.spec.satisfies("@4.5.0:"): args.append(self.define("ROCM_SMI_DIR", self.spec["rocm-smi-lib"].prefix)) + if self.spec.satisfies("@5.3.0:"): + args.append(self.define("BUILD_TESTS", "ON")) return args + + def test(self): + if self.spec.satisfies("@:5.3.0"): + print("Skipping: stand-alone tests") + return + test_dir = join_path(self.spec["rccl"].prefix, "bin") + with working_dir(test_dir, create=True): + self.run_test("UnitTests") diff --git a/var/spack/repos/builtin/packages/rocm-opencl/package.py b/var/spack/repos/builtin/packages/rocm-opencl/package.py index 45c9122bf70fb0..38c8aa9df8589c 100644 --- a/var/spack/repos/builtin/packages/rocm-opencl/package.py +++ b/var/spack/repos/builtin/packages/rocm-opencl/package.py @@ -3,6 +3,7 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) +import os import re from spack.package import * @@ -229,7 +230,7 @@ def flag_handler(self, name, flags): return (flags, None, None) def cmake_args(self): - args = ["-DUSE_COMGR_LIBRARY=yes"] + args = ["-DUSE_COMGR_LIBRARY=yes", "-DBUILD_TESTS=ON"] if self.spec.satisfies("@:4.3.0"): "-DROCclr_DIR={0}".format(self.spec["hip-rocclr"].prefix), "-DLIBROCclr_STATIC_DIR={0}/lib".format @@ -251,3 +252,14 @@ def post_install(self): config_file_name = "amdocl64_30800.icd" with open(join_path(vendor_config_path, config_file_name), "w") as f: f.write("libamdocl64.so") + + test_src_dir = "tests/ocltst" + + def test(self): + test_dir = join_path(self.spec["rocm-opencl"].prefix, self.test_src_dir) + with working_dir(test_dir, create=True): + os.environ["LD_LIBRARY_PATH"] += os.pathsep + test_dir + args = ["-m", "liboclruntime.so", "-A", "oclruntime.exclude"] + self.run_test("ocltst", args) + args = ["-m", "liboclperf.so", "-A", "oclperf.exclude"] + self.run_test("ocltst", args)