hip: mathlibs inherit CudaPackage and ROCmPackage (#34586)

Unless the amdgpu_target is overriden, the libraries will default to
being built for cuda, since amdgpu_target=none is both default and in
conflict with +rocm. This requires a custom Disjoint set to include
both the 'auto' variant used by the rocm mathlibs and the 'none'
variant used by ROCmPackage.

* Fix search for hip+cuda in hipcub@5.1 and later

This patch is not strictly necessary, but it may fix the search for HIP
in certain environments.

* Backport fix for CUDA 11.5 to hipsparse
This commit is contained in:
Cory Bloor 2023-04-03 12:28:24 -06:00 committed by GitHub
parent 0860139c83
commit cfea2d1010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 252 additions and 67 deletions

View File

@ -8,7 +8,7 @@
from spack.package import *
class Hipblas(CMakePackage):
class Hipblas(CMakePackage, CudaPackage, ROCmPackage):
"""hipBLAS is a BLAS marshalling library, with multiple
supported backends"""
@ -103,6 +103,22 @@ class Hipblas(CMakePackage):
deprecated=True,
)
# default to an 'auto' variant until amdgpu_targets can be given a better default than 'none'
amdgpu_targets = ROCmPackage.amdgpu_targets
variant(
"amdgpu_target",
values=spack.variant.DisjointSetsOfValues(("auto",), ("none",), amdgpu_targets)
.with_default("auto")
.with_error(
"the values 'auto' and 'none' are mutually exclusive with any of the other values"
)
.with_non_feature_values("auto", "none"),
sticky=True,
)
variant("rocm", default=True, description="Enable ROCm support")
conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive")
conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required")
variant(
"build_type",
default="Release",
@ -124,14 +140,11 @@ def check(self):
exe = join_path(self.build_directory, "clients", "staging", "hipblas-test")
self.run_test(exe, options=["--gtest_filter=-*known_bug*"])
depends_on("hip@4.1.0:", when="@4.1.0:")
depends_on("rocm-cmake@master", type="build", when="@master:")
depends_on("rocm-cmake@5.2.0:", type="build", when="@5.2.0:")
depends_on("rocm-cmake@4.5.0:", type="build", when="@4.5.0:")
depends_on("rocm-cmake@3.5.0:", type="build")
for ver in ["master", "develop"]:
depends_on("rocblas@" + ver, when="@" + ver)
depends_on("rocsolver@" + ver, when="@" + ver)
depends_on("hip +cuda", when="+cuda")
for ver in [
"3.5.0",
@ -157,10 +170,19 @@ def check(self):
"5.3.3",
"5.4.0",
"5.4.3",
"master",
"develop",
]:
depends_on("hip@" + ver, when="@" + ver)
depends_on("rocsolver@" + ver, when="@" + ver)
depends_on("rocblas@" + ver, when="@" + ver)
depends_on("rocsolver@" + ver, when="+rocm @" + ver)
depends_on("rocblas@" + ver, when="+rocm @" + ver)
for tgt in ROCmPackage.amdgpu_targets:
depends_on(
"rocblas amdgpu_target={0}".format(tgt), when="+rocm amdgpu_target={0}".format(tgt)
)
depends_on(
"rocsolver amdgpu_target={0}".format(tgt), when="+rocm amdgpu_target={0}".format(tgt)
)
@classmethod
def determine_version(cls, lib):
@ -175,28 +197,27 @@ def determine_version(cls, lib):
def cmake_args(self):
args = [
# Make sure find_package(HIP) finds the module.
self.define("BUILD_CLIENTS_SAMPLES", "OFF"),
self.define("BUILD_CLIENTS_TESTS", self.run_tests),
]
# hipblas actually prefers CUDA over AMD GPUs when you have it
# installed...
if self.spec.satisfies("@:3.9.0"):
args.append(self.define("TRY_CUDA", "OFF"))
args.append(self.define_from_variant("TRY_CUDA", "cuda"))
else:
args.append(self.define("USE_CUDA", "OFF"))
args.append(self.define_from_variant("USE_CUDA", "cuda"))
if self.spec.satisfies("^cmake@3.21.0:3.21.2"):
args.append(self.define("__skip_rocmclang", "ON"))
if self.spec.satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
elif self.spec.satisfies("@5.2.0:"):
# FindHIP.cmake was used for +rocm until 4.1.0 and is still used for +cuda
if self.spec.satisfies("@:4.0") or self.spec.satisfies("+cuda"):
if self.spec["hip"].satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
else:
args.append(
self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.lib.cmake.hip)
)
if self.spec.satisfies("@5.2.0:"):
args.append(self.define("BUILD_FILE_REORG_BACKWARD_COMPATIBILITY", True))
if self.spec.satisfies("@5.3.0:"):
args.append("-DCMAKE_INSTALL_LIBDIR=lib")
return args
def setup_build_environment(self, env):
env.set("CXX", self.spec["hip"].hipcc)

View File

@ -0,0 +1,13 @@
diff --git a/cmake/VerifyCompiler.cmake b/cmake/VerifyCompiler.cmake
index ca4d646..0256683 100644
--- a/cmake/VerifyCompiler.cmake
+++ b/cmake/VerifyCompiler.cmake
@@ -22,8 +22,6 @@
list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/hip)
if(CMAKE_CXX_COMPILER MATCHES ".*/nvcc$" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- list(APPEND CMAKE_MODULE_PATH /opt/rocm/hip/cmake)
- find_package(hip QUIET CONFIG PATHS /opt/rocm)
if(NOT hip_FOUND)
find_package(HIP REQUIRED)
endif()

View File

@ -0,0 +1,13 @@
diff --git a/cmake/VerifyCompiler.cmake b/cmake/VerifyCompiler.cmake
index 846072f..281ccdc 100644
--- a/cmake/VerifyCompiler.cmake
+++ b/cmake/VerifyCompiler.cmake
@@ -22,8 +22,6 @@
list(APPEND CMAKE_PREFIX_PATH /opt/rocm /opt/rocm/hip)
if(CMAKE_CXX_COMPILER MATCHES ".*nvcc$" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- list(APPEND CMAKE_MODULE_PATH /opt/rocm/hip/cmake)
- find_package(hip QUIET CONFIG PATHS /opt/rocm)
if(NOT hip_FOUND)
find_package(HIP REQUIRED)
endif()

View File

@ -6,7 +6,7 @@
from spack.package import *
class Hipcub(CMakePackage):
class Hipcub(CMakePackage, CudaPackage, ROCmPackage):
"""Radeon Open Compute Parallel Primitives Library"""
homepage = "https://github.com/ROCmSoftwarePlatform/hipCUB"
@ -96,6 +96,22 @@ class Hipcub(CMakePackage):
deprecated=True,
)
# default to an 'auto' variant until amdgpu_targets can be given a better default than 'none'
amdgpu_targets = ROCmPackage.amdgpu_targets
variant(
"amdgpu_target",
values=spack.variant.DisjointSetsOfValues(("auto",), ("none",), amdgpu_targets)
.with_default("auto")
.with_error(
"the values 'auto' and 'none' are mutually exclusive with any of the other values"
)
.with_non_feature_values("auto", "none"),
sticky=True,
)
variant("rocm", default=True, description="Enable ROCm support")
conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive")
conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required")
variant(
"build_type",
default="Release",
@ -105,7 +121,9 @@ class Hipcub(CMakePackage):
depends_on("cmake@3.10.2:", type="build", when="@4.2.0:")
depends_on("cmake@3.5.1:", type="build")
depends_on("numactl", type="link", when="@3.7.0:")
depends_on("hip +cuda", when="+cuda")
depends_on("googletest@1.10.0:", type="test")
for ver in [
@ -133,20 +151,32 @@ class Hipcub(CMakePackage):
"5.4.0",
"5.4.3",
]:
depends_on("hip@" + ver, when="@" + ver)
depends_on("rocprim@" + ver, when="@" + ver)
depends_on("rocprim@" + ver, when="+rocm @" + ver)
depends_on("rocm-cmake@%s:" % ver, type="build", when="@" + ver)
# fix hardcoded search in /opt/rocm and broken config mode search
patch("find-hip-cuda-rocm-5.1.patch", when="@5.1:5.2 +cuda")
patch("find-hip-cuda-rocm-5.3.patch", when="@5.3: +cuda")
def setup_build_environment(self, env):
env.set("CXX", self.spec["hip"].hipcc)
if self.spec.satisfies("+rocm"):
env.set("CXX", self.spec["hip"].hipcc)
def cmake_args(self):
args = [self.define("BUILD_TEST", self.run_tests)]
if self.spec.satisfies("^cmake@3.21.0:3.21.2"):
if self.spec.satisfies("+rocm ^cmake@3.21.0:3.21.2"):
args.append(self.define("__skip_rocmclang", "ON"))
if self.spec.satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
# FindHIP.cmake was used for +rocm until 3.7.0 and is still used for +cuda
if self.spec.satisfies("@:3.7.0") or self.spec.satisfies("+cuda"):
if self.spec["hip"].satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
else:
args.append(
self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.lib.cmake.hip)
)
if self.spec.satisfies("@5.2.0:"):
args.append(self.define("BUILD_FILE_REORG_BACKWARD_COMPATIBILITY", True))

View File

@ -7,7 +7,7 @@
from spack.package import *
class Hipfft(CMakePackage):
class Hipfft(CMakePackage, CudaPackage, ROCmPackage):
"""hipFFT is an FFT marshalling library. Currently, hipFFT supports
either rocFFT or cuFFT as backends.hipFFT exports an interface that
does not require the client to change, regardless of the chosen backend.
@ -73,6 +73,22 @@ class Hipfft(CMakePackage):
deprecated=True,
)
# default to an 'auto' variant until amdgpu_targets can be given a better default than 'none'
amdgpu_targets = ROCmPackage.amdgpu_targets
variant(
"amdgpu_target",
values=spack.variant.DisjointSetsOfValues(("auto",), ("none",), amdgpu_targets)
.with_default("auto")
.with_error(
"the values 'auto' and 'none' are mutually exclusive with any of the other values"
)
.with_non_feature_values("auto", "none"),
sticky=True,
)
variant("rocm", default=True, description="Enable ROCm support")
conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive")
conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required")
variant(
"build_type",
default="Release",
@ -82,6 +98,8 @@ class Hipfft(CMakePackage):
depends_on("cmake@3.5:", type="build")
depends_on("hip +cuda", when="+cuda")
for ver in [
"4.1.0",
"4.2.0",
@ -102,25 +120,28 @@ class Hipfft(CMakePackage):
"5.4.3",
]:
depends_on("rocm-cmake@%s:" % ver, type="build", when="@" + ver)
depends_on("hip@" + ver, when="@" + ver)
depends_on("rocfft@" + ver, when="@" + ver)
depends_on("rocfft@" + ver, when="+rocm @" + ver)
def setup_build_environment(self, env):
env.set("CXX", self.spec["hip"].hipcc)
for tgt in ROCmPackage.amdgpu_targets:
depends_on(
"rocfft amdgpu_target={0}".format(tgt), when="+rocm amdgpu_target={0}".format(tgt)
)
def cmake_args(self):
args = [
# Make sure find_package(HIP) finds the module.
self.define("BUILD_CLIENTS_SAMPLES", "OFF")
]
args = [self.define("BUILD_CLIENTS_SAMPLES", "OFF")]
if self.spec.satisfies("^cmake@3.21.0:3.21.2"):
args.append(self.define("__skip_rocmclang", "ON"))
if self.spec.satisfies("+rocm"):
args.append(self.define("BUILD_WITH_LIB", "ROCM"))
elif self.spec.satisfies("+cuda"):
args.append(self.define("BUILD_WITH_LIB", "CUDA"))
if self.spec.satisfies("@3.7.0:5.1"):
# FindHIP.cmake is still used for both +rocm and +cuda
if self.spec["hip"].satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
elif self.spec.satisfies("@5.2.0:"):
else:
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.lib.cmake.hip))
if self.spec.satisfies("@5.2.0:"):
args.append(self.define("BUILD_FILE_REORG_BACKWARD_COMPATIBILITY", True))
if self.spec.satisfies("@5.3.0:"):

View File

@ -8,7 +8,7 @@
from spack.package import *
class Hipsolver(CMakePackage):
class Hipsolver(CMakePackage, CudaPackage, ROCmPackage):
"""hipSOLVER is a LAPACK marshalling library, with multiple supported backends.
It sits between the application and a 'worker' LAPACK library, marshalling
inputs into the backend library and marshalling results back to the application.
@ -57,6 +57,22 @@ class Hipsolver(CMakePackage):
deprecated=True,
)
# default to an 'auto' variant until amdgpu_targets can be given a better default than 'none'
amdgpu_targets = ROCmPackage.amdgpu_targets
variant(
"amdgpu_target",
values=spack.variant.DisjointSetsOfValues(("auto",), ("none",), amdgpu_targets)
.with_default("auto")
.with_error(
"the values 'auto' and 'none' are mutually exclusive with any of the other values"
)
.with_non_feature_values("auto", "none"),
sticky=True,
)
variant("rocm", default=True, description="Enable ROCm support")
conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive")
conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required")
variant(
"build_type",
default="Release",
@ -66,13 +82,10 @@ class Hipsolver(CMakePackage):
depends_on("cmake@3.5:", type="build")
depends_on("hip@4.1.0:", when="@4.1.0:")
depends_on("rocm-cmake@master", type="build", when="@master:")
depends_on("rocm-cmake@5.2.0:", type="build", when="@5.2.0:")
depends_on("rocm-cmake@4.5.0:", type="build")
for ver in ["master", "develop"]:
depends_on("rocblas@" + ver, when="@" + ver)
depends_on("rocsolver@" + ver, when="@" + ver)
depends_on("hip +cuda", when="+cuda")
for ver in [
"4.5.0",
@ -88,10 +101,19 @@ class Hipsolver(CMakePackage):
"5.3.3",
"5.4.0",
"5.4.3",
"master",
"develop",
]:
depends_on("hip@" + ver, when="@" + ver)
depends_on("rocblas@" + ver, when="@" + ver)
depends_on("rocsolver@" + ver, when="@" + ver)
depends_on("rocblas@" + ver, when="+rocm @" + ver)
depends_on("rocsolver@" + ver, when="+rocm @" + ver)
for tgt in ROCmPackage.amdgpu_targets:
depends_on(
"rocblas amdgpu_target={0}".format(tgt), when="+rocm amdgpu_target={0}".format(tgt)
)
depends_on(
"rocsolver amdgpu_target={0}".format(tgt), when="+rocm amdgpu_target={0}".format(tgt)
)
depends_on("googletest@1.10.0:", type="test")
depends_on("netlib-lapack@3.7.1:", type="test")
@ -100,9 +122,6 @@ def check(self):
exe = join_path(self.build_directory, "clients", "staging", "hipsolver-test")
self.run_test(exe, options=["--gtest_filter=-*known_bug*"])
def setup_build_environment(self, env):
env.set("CXX", self.spec["hip"].hipcc)
@classmethod
def determine_version(cls, lib):
match = re.search(r"lib\S*\.so\.\d+\.\d+\.(\d)(\d\d)(\d\d)", lib)
@ -120,6 +139,17 @@ def cmake_args(self):
self.define("BUILD_CLIENTS_TESTS", self.run_tests),
]
args.append(self.define_from_variant("USE_CUDA", "cuda"))
# FindHIP.cmake is still used for +cuda
if self.spec.satisfies("+cuda"):
if self.spec["hip"].satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
else:
args.append(
self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.lib.cmake.hip)
)
if self.spec.satisfies("@5.2.0:"):
args.append(self.define("BUILD_FILE_REORG_BACKWARD_COMPATIBILITY", True))
if self.spec.satisfies("@5.3.0:"):

View File

@ -0,0 +1,30 @@
From 0a90ddc4c33ed409a938513b9dbdca8bfad65e06 Mon Sep 17 00:00:00 2001
From: James Sandham <33790278+jsandham@users.noreply.github.com>
Date: Tue, 29 Nov 2022 12:19:06 -0700
Subject: [PATCH] Fix cuda compilation (#287)
Co-authored-by: jsandham <james.sandham@amd.com>
---
library/src/nvcc_detail/hipsparse.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/library/src/nvcc_detail/hipsparse.cpp b/library/src/nvcc_detail/hipsparse.cpp
index 4d692855..25d257a8 100644
--- a/library/src/nvcc_detail/hipsparse.cpp
+++ b/library/src/nvcc_detail/hipsparse.cpp
@@ -360,6 +360,7 @@ cusparseSolvePolicy_t hipPolicyToCudaPolicy(hipsparseSolvePolicy_t policy)
}
}
+#if CUDART_VERSION < 11050
cusparseSideMode_t hipSideToCudaSide(hipsparseSideMode_t side)
{
switch(side)
@@ -385,6 +386,7 @@ hipsparseSideMode_t CudaSideToHIPSide(cusparseSideMode_t side)
throw "Non existent cusparseSideMode_t";
}
}
+#endif
#if CUDART_VERSION > 10000
cudaDataType hipDataTypeToCudaDataType(hipDataType datatype)

View File

@ -8,7 +8,7 @@
from spack.package import *
class Hipsparse(CMakePackage):
class Hipsparse(CMakePackage, CudaPackage, ROCmPackage):
"""hipSPARSE is a SPARSE marshalling library, with
multiple supported backends"""
@ -100,6 +100,22 @@ class Hipsparse(CMakePackage):
deprecated=True,
)
# default to an 'auto' variant until amdgpu_targets can be given a better default than 'none'
amdgpu_targets = ROCmPackage.amdgpu_targets
variant(
"amdgpu_target",
values=spack.variant.DisjointSetsOfValues(("auto",), ("none",), amdgpu_targets)
.with_default("auto")
.with_error(
"the values 'auto' and 'none' are mutually exclusive with any of the other values"
)
.with_non_feature_values("auto", "none"),
sticky=True,
)
variant("rocm", default=True, description="Enable ROCm support")
conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive")
conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required")
variant(
"build_type",
default="Release",
@ -107,6 +123,8 @@ class Hipsparse(CMakePackage):
description="CMake build type",
)
depends_on("hip +cuda", when="+cuda")
depends_on("cmake@3.5:", type="build")
depends_on("git", type="build")
@ -136,11 +154,16 @@ class Hipsparse(CMakePackage):
"5.4.3",
]:
depends_on("rocm-cmake@%s:" % ver, type="build", when="@" + ver)
depends_on("hip@" + ver, when="@" + ver)
depends_on("rocsparse@" + ver, when="@" + ver)
depends_on("rocsparse@" + ver, when="+rocm @" + ver)
for tgt in ROCmPackage.amdgpu_targets:
depends_on(
"rocsparse amdgpu_target={0}".format(tgt), when="+rocm amdgpu_target={0}".format(tgt)
)
patch("e79985dccde22d826aceb3badfc643a3227979d2.patch", when="@3.5.0")
patch("530047af4a0f437dafc02f76b3a17e3b1536c7ec.patch", when="@3.5.0")
patch("0a90ddc4c33ed409a938513b9dbdca8bfad65e06.patch")
@classmethod
def determine_version(cls, lib):
@ -155,22 +178,26 @@ def determine_version(cls, lib):
def cmake_args(self):
args = [
# Make sure find_package(HIP) finds the module.
self.define("CMAKE_CXX_STANDARD", "14"),
self.define("BUILD_CLIENTS_SAMPLES", "OFF"),
self.define("BUILD_CLIENTS_TESTS", "OFF"),
]
if self.spec.satisfies("^cmake@3.21.0:3.21.2"):
args.append(self.define("__skip_rocmclang", "ON"))
args.append(self.define_from_variant("BUILD_CUDA", "cuda"))
if self.spec.satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
elif self.spec.satisfies("@5.2.0:"):
# FindHIP.cmake was used for +rocm until 5.0.0 and is still used for +cuda
if self.spec.satisfies("@:4") or self.spec.satisfies("+cuda"):
if self.spec["hip"].satisfies("@:5.1"):
args.append(self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.cmake))
else:
args.append(
self.define("CMAKE_MODULE_PATH", self.spec["hip"].prefix.lib.cmake.hip)
)
if self.spec.satisfies("@5.2.0:"):
args.append(self.define("BUILD_FILE_REORG_BACKWARD_COMPATIBILITY", True))
if self.spec.satisfies("@5.3.0:"):
args.append("-DCMAKE_INSTALL_LIBDIR=lib")
return args
def setup_build_environment(self, env):
env.set("CXX", self.spec["hip"].hipcc)
return args