hip: add cuda variant (#33872)
This commit is contained in:
		| @@ -138,7 +138,7 @@ class ROCmPackage(PackageBase): | |||||||
| 
 | 
 | ||||||
|     depends_on("llvm-amdgpu", when="+rocm") |     depends_on("llvm-amdgpu", when="+rocm") | ||||||
|     depends_on("hsa-rocr-dev", when="+rocm") |     depends_on("hsa-rocr-dev", when="+rocm") | ||||||
|     depends_on("hip", when="+rocm") |     depends_on("hip +rocm", when="+rocm") | ||||||
| 
 | 
 | ||||||
|     conflicts("^blt@:0.3.6", when="+rocm") |     conflicts("^blt@:0.3.6", when="+rocm") | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -111,58 +111,66 @@ class Hip(CMakePackage): | |||||||
|         description="CMake build type", |         description="CMake build type", | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|  |     variant("rocm", default=True, description="Enable ROCm support") | ||||||
|  |     variant("cuda", default=False, description="Build with CUDA") | ||||||
|  |     conflicts("+cuda +rocm", msg="CUDA and ROCm support are mutually exclusive") | ||||||
|  |     conflicts("~cuda ~rocm", msg="CUDA or ROCm support is required") | ||||||
|  | 
 | ||||||
|  |     depends_on("cuda", when="+cuda") | ||||||
|  | 
 | ||||||
|     depends_on("cmake@3.16.8:", type="build", when="@4.5.0:") |     depends_on("cmake@3.16.8:", type="build", when="@4.5.0:") | ||||||
|     depends_on("cmake@3.4.3:", type="build") |     depends_on("cmake@3.4.3:", type="build") | ||||||
|     depends_on("perl@5.10:", type=("build", "run")) |     depends_on("perl@5.10:", type=("build", "run")) | ||||||
|     depends_on("gl@4.5:") |  | ||||||
|     depends_on("py-cppheaderparser", type="build", when="@5.3.3:") |  | ||||||
| 
 | 
 | ||||||
|     for ver in [ |     with when("+rocm"): | ||||||
|         "3.5.0", |         depends_on("gl@4.5:") | ||||||
|         "3.7.0", |         depends_on("py-cppheaderparser", type="build", when="@5.3.3:") | ||||||
|         "3.8.0", |         for ver in [ | ||||||
|         "3.9.0", |             "3.5.0", | ||||||
|         "3.10.0", |             "3.7.0", | ||||||
|         "4.0.0", |             "3.8.0", | ||||||
|         "4.1.0", |             "3.9.0", | ||||||
|         "4.2.0", |             "3.10.0", | ||||||
|         "4.3.0", |             "4.0.0", | ||||||
|         "4.3.1", |             "4.1.0", | ||||||
|     ]: |             "4.2.0", | ||||||
|         depends_on("hip-rocclr@" + ver, when="@" + ver) |             "4.3.0", | ||||||
|     for ver in [ |             "4.3.1", | ||||||
|         "3.5.0", |         ]: | ||||||
|         "3.7.0", |             depends_on("hip-rocclr@" + ver, when="@" + ver) | ||||||
|         "3.8.0", |         for ver in [ | ||||||
|         "3.9.0", |             "3.5.0", | ||||||
|         "3.10.0", |             "3.7.0", | ||||||
|         "4.0.0", |             "3.8.0", | ||||||
|         "4.1.0", |             "3.9.0", | ||||||
|         "4.2.0", |             "3.10.0", | ||||||
|         "4.3.0", |             "4.0.0", | ||||||
|         "4.3.1", |             "4.1.0", | ||||||
|         "4.5.0", |             "4.2.0", | ||||||
|         "4.5.2", |             "4.3.0", | ||||||
|         "5.0.0", |             "4.3.1", | ||||||
|         "5.0.2", |             "4.5.0", | ||||||
|         "5.1.0", |             "4.5.2", | ||||||
|         "5.1.3", |             "5.0.0", | ||||||
|         "5.2.0", |             "5.0.2", | ||||||
|         "5.2.1", |             "5.1.0", | ||||||
|         "5.2.3", |             "5.1.3", | ||||||
|         "5.3.0", |             "5.2.0", | ||||||
|         "5.3.3", |             "5.2.1", | ||||||
|     ]: |             "5.2.3", | ||||||
|         depends_on("hsakmt-roct@" + ver, when="@" + ver) |             "5.3.0", | ||||||
|         depends_on("hsa-rocr-dev@" + ver, when="@" + ver) |             "5.3.3", | ||||||
|         depends_on("comgr@" + ver, when="@" + ver) |         ]: | ||||||
|         depends_on("llvm-amdgpu@{0} +rocm-device-libs".format(ver), when="@" + ver) |             depends_on("hsakmt-roct@" + ver, when="@" + ver) | ||||||
|         depends_on("rocminfo@" + ver, when="@" + ver) |             depends_on("hsa-rocr-dev@" + ver, when="@" + ver) | ||||||
|         depends_on("roctracer-dev-api@" + ver, when="@" + ver) |             depends_on("comgr@" + ver, when="@" + ver) | ||||||
|  |             depends_on("llvm-amdgpu@{0} +rocm-device-libs".format(ver), when="@" + ver) | ||||||
|  |             depends_on("rocminfo@" + ver, when="@" + ver) | ||||||
|  |             depends_on("roctracer-dev-api@" + ver, when="@" + ver) | ||||||
| 
 | 
 | ||||||
|     # hipcc likes to add `-lnuma` by default :( |         # hipcc likes to add `-lnuma` by default :( | ||||||
|     # ref https://github.com/ROCm-Developer-Tools/HIP/pull/2202 |         # ref https://github.com/ROCm-Developer-Tools/HIP/pull/2202 | ||||||
|     depends_on("numactl", when="@3.7.0:") |         depends_on("numactl", when="@3.7.0:") | ||||||
| 
 | 
 | ||||||
|     # roc-obj-ls requirements |     # roc-obj-ls requirements | ||||||
|     depends_on("perl-file-which") |     depends_on("perl-file-which") | ||||||
| @@ -390,65 +398,70 @@ def determine_version(cls, lib): | |||||||
|         return ver |         return ver | ||||||
| 
 | 
 | ||||||
|     def set_variables(self, env): |     def set_variables(self, env): | ||||||
|         # Note: do not use self.spec[name] here, since not all dependencies |         if self.spec.satisfies("+rocm"): | ||||||
|         # have defined prefixes when hip is marked as external. |             # Note: do not use self.spec[name] here, since not all dependencies | ||||||
|         paths = self.get_paths() |             # have defined prefixes when hip is marked as external. | ||||||
|  |             paths = self.get_paths() | ||||||
| 
 | 
 | ||||||
|         # Used in hipcc, but only useful when hip is external, since only then |             # Used in hipcc, but only useful when hip is external, since only then | ||||||
|         # there is a common prefix /opt/rocm-x.y.z. |             # there is a common prefix /opt/rocm-x.y.z. | ||||||
|         env.set("ROCM_PATH", paths["rocm-path"]) |             env.set("ROCM_PATH", paths["rocm-path"]) | ||||||
| 
 | 
 | ||||||
|         # hipcc recognizes HIP_PLATFORM == hcc and HIP_COMPILER == clang, even |             # hipcc recognizes HIP_PLATFORM == hcc and HIP_COMPILER == clang, even | ||||||
|         # though below we specified HIP_PLATFORM=rocclr and HIP_COMPILER=clang |             # though below we specified HIP_PLATFORM=rocclr and HIP_COMPILER=clang | ||||||
|         # in the CMake args. |             # in the CMake args. | ||||||
|         if self.spec.satisfies("@:4.0.0"): |             if self.spec.satisfies("@:4.0.0"): | ||||||
|             env.set("HIP_PLATFORM", "hcc") |                 env.set("HIP_PLATFORM", "hcc") | ||||||
|         else: |             else: | ||||||
|             env.set("HIP_PLATFORM", "amd") |                 env.set("HIP_PLATFORM", "amd") | ||||||
| 
 | 
 | ||||||
|         env.set("HIP_COMPILER", "clang") |             env.set("HIP_COMPILER", "clang") | ||||||
| 
 | 
 | ||||||
|         # bin directory where clang++ resides |             # bin directory where clang++ resides | ||||||
|         env.set("HIP_CLANG_PATH", paths["llvm-amdgpu"].bin) |             env.set("HIP_CLANG_PATH", paths["llvm-amdgpu"].bin) | ||||||
| 
 | 
 | ||||||
|         # Path to hsa-rocr-dev prefix used by hipcc. |             # Path to hsa-rocr-dev prefix used by hipcc. | ||||||
|         env.set("HSA_PATH", paths["hsa-rocr-dev"]) |             env.set("HSA_PATH", paths["hsa-rocr-dev"]) | ||||||
| 
 | 
 | ||||||
|         # This is a variable that does not exist in hipcc but was introduced |             # This is a variable that does not exist in hipcc but was introduced | ||||||
|         # in a patch of ours since 3.5.0 to locate rocm_agent_enumerator: |             # in a patch of ours since 3.5.0 to locate rocm_agent_enumerator: | ||||||
|         # https://github.com/ROCm-Developer-Tools/HIP/pull/2138 |             # https://github.com/ROCm-Developer-Tools/HIP/pull/2138 | ||||||
|         env.set("ROCMINFO_PATH", paths["rocminfo"]) |             env.set("ROCMINFO_PATH", paths["rocminfo"]) | ||||||
| 
 | 
 | ||||||
|         # This one is used in hipcc to run `clang --hip-device-lib-path=...` |             # This one is used in hipcc to run `clang --hip-device-lib-path=...` | ||||||
|         env.set("DEVICE_LIB_PATH", paths["bitcode"]) |             env.set("DEVICE_LIB_PATH", paths["bitcode"]) | ||||||
| 
 | 
 | ||||||
|         # And this is used in clang whenever the --hip-device-lib-path is not |             # And this is used in clang whenever the --hip-device-lib-path is not | ||||||
|         # used (e.g. when clang is invoked directly) |             # used (e.g. when clang is invoked directly) | ||||||
|         env.set("HIP_DEVICE_LIB_PATH", paths["bitcode"]) |             env.set("HIP_DEVICE_LIB_PATH", paths["bitcode"]) | ||||||
| 
 | 
 | ||||||
|         # Just the prefix of hip (used in hipcc) |             # Just the prefix of hip (used in hipcc) | ||||||
|         env.set("HIP_PATH", paths["hip-path"]) |             env.set("HIP_PATH", paths["hip-path"]) | ||||||
| 
 | 
 | ||||||
|         # Used in comgr and seems necessary when using the JIT compiler, e.g. |             # Used in comgr and seems necessary when using the JIT compiler, e.g. | ||||||
|         # hiprtcCreateProgram: |             # hiprtcCreateProgram: | ||||||
|         # https://github.com/RadeonOpenCompute/ROCm-CompilerSupport/blob/rocm-4.0.0/lib/comgr/src/comgr-env.cpp |             # https://github.com/RadeonOpenCompute/ROCm-CompilerSupport/blob/rocm-4.0.0/lib/comgr/src/comgr-env.cpp | ||||||
|         env.set("LLVM_PATH", paths["llvm-amdgpu"]) |             env.set("LLVM_PATH", paths["llvm-amdgpu"]) | ||||||
| 
 | 
 | ||||||
|         # Finally we have to set --rocm-path=<prefix> ourselves, which is not |             # Finally we have to set --rocm-path=<prefix> ourselves, which is not | ||||||
|         # the same as --hip-device-lib-path (set by hipcc). It's used to set |             # the same as --hip-device-lib-path (set by hipcc). It's used to set | ||||||
|         # default bin, include and lib folders in clang. If it's not set it is |             # default bin, include and lib folders in clang. If it's not set it is | ||||||
|         # infered from the clang install dir (and they try to find |             # infered from the clang install dir (and they try to find | ||||||
|         # /opt/rocm again...). If this path is set, there is no strict checking |             # /opt/rocm again...). If this path is set, there is no strict checking | ||||||
|         # and parsing of the <prefix>/bin/.hipVersion file. Let's just set this |             # and parsing of the <prefix>/bin/.hipVersion file. Let's just set this | ||||||
|         # to the hip prefix directory for non-external builds so that the |             # to the hip prefix directory for non-external builds so that the | ||||||
|         # bin/.hipVersion file can still be parsed. |             # bin/.hipVersion file can still be parsed. | ||||||
|         # See also https://github.com/ROCm-Developer-Tools/HIP/issues/2223 |             # See also https://github.com/ROCm-Developer-Tools/HIP/issues/2223 | ||||||
|         if "@3.8.0:" in self.spec: |             if "@3.8.0:" in self.spec: | ||||||
|             env.append_path( |                 env.append_path( | ||||||
|                 "HIPCC_COMPILE_FLAGS_APPEND", |                     "HIPCC_COMPILE_FLAGS_APPEND", | ||||||
|                 "--rocm-path={0}".format(paths["rocm-path"]), |                     "--rocm-path={0}".format(paths["rocm-path"]), | ||||||
|                 separator=" ", |                     separator=" ", | ||||||
|             ) |                 ) | ||||||
|  |         elif self.spec.satisfies("+cuda"): | ||||||
|  |             env.set("CUDA_PATH", self.spec["cuda"].prefix) | ||||||
|  |             env.set("HIP_PATH", self.spec.prefix) | ||||||
|  |             env.set("HIP_PLATFORM", "nvidia") | ||||||
| 
 | 
 | ||||||
|     def setup_build_environment(self, env): |     def setup_build_environment(self, env): | ||||||
|         self.set_variables(env) |         self.set_variables(env) | ||||||
| @@ -478,7 +491,7 @@ def patch(self): | |||||||
|                 "hip-config.cmake.in", |                 "hip-config.cmake.in", | ||||||
|                 string=True, |                 string=True, | ||||||
|             ) |             ) | ||||||
|         if self.spec.satisfies("@5.2:"): |         if self.spec.satisfies("@5.2: +rocm"): | ||||||
|             filter_file( |             filter_file( | ||||||
|                 '"${ROCM_PATH}/llvm"', |                 '"${ROCM_PATH}/llvm"', | ||||||
|                 self.spec["llvm-amdgpu"].prefix, |                 self.spec["llvm-amdgpu"].prefix, | ||||||
| @@ -519,7 +532,7 @@ def patch(self): | |||||||
|                 substitute = "#!{perl}".format(perl=perl) |                 substitute = "#!{perl}".format(perl=perl) | ||||||
|                 files = ["roc-obj-extract", "roc-obj-ls"] |                 files = ["roc-obj-extract", "roc-obj-ls"] | ||||||
|                 filter_file(match, substitute, *files, **kwargs) |                 filter_file(match, substitute, *files, **kwargs) | ||||||
|         if "@3.7.0:" in self.spec: |         if "@3.7.0: +rocm" in self.spec: | ||||||
|             numactl = self.spec["numactl"].prefix.lib |             numactl = self.spec["numactl"].prefix.lib | ||||||
|             kwargs = {"ignore_absent": False, "backup": False, "string": False} |             kwargs = {"ignore_absent": False, "backup": False, "string": False} | ||||||
| 
 | 
 | ||||||
| @@ -537,20 +550,24 @@ def flag_handler(self, name, flags): | |||||||
|         return (flags, None, None) |         return (flags, None, None) | ||||||
| 
 | 
 | ||||||
|     def cmake_args(self): |     def cmake_args(self): | ||||||
|         args = [ |         args = [] | ||||||
|             self.define( |         if self.spec.satisfies("+rocm"): | ||||||
|                 "PROF_API_HEADER_PATH", |             args.append(self.define("HSA_PATH", self.spec["hsa-rocr-dev"].prefix)) | ||||||
|                 join_path(self.spec["roctracer-dev-api"].prefix, "roctracer", "include", "ext"), |             args.append(self.define("HIP_COMPILER", "clang")) | ||||||
|             ), |             args.append( | ||||||
|             self.define("HIP_COMPILER", "clang"), |                 self.define( | ||||||
|             self.define("HSA_PATH", self.spec["hsa-rocr-dev"].prefix), |                     "PROF_API_HEADER_PATH", | ||||||
|         ] |                     self.spec["roctracer-dev-api"].prefix.roctracer.include.ext, | ||||||
|         if self.spec.satisfies("@:4.0.0"): |                 ) | ||||||
|             args.append(self.define("HIP_RUNTIME", "ROCclr")) |             ) | ||||||
|             args.append(self.define("HIP_PLATFORM", "rocclr")) |             if self.spec.satisfies("@:4.0.0"): | ||||||
|         else: |                 args.append(self.define("HIP_RUNTIME", "ROCclr")) | ||||||
|             args.append(self.define("HIP_RUNTIME", "rocclr")) |                 args.append(self.define("HIP_PLATFORM", "rocclr")) | ||||||
|             args.append(self.define("HIP_PLATFORM", "amd")) |             else: | ||||||
|  |                 args.append(self.define("HIP_RUNTIME", "rocclr")) | ||||||
|  |                 args.append(self.define("HIP_PLATFORM", "amd")) | ||||||
|  |         if self.spec.satisfies("+cuda"): | ||||||
|  |             args.append(self.define("HIP_PLATFORM", "nvidia")) | ||||||
| 
 | 
 | ||||||
|         # LIBROCclr_STATIC_DIR is unused from 3.6.0 and above |         # LIBROCclr_STATIC_DIR is unused from 3.6.0 and above | ||||||
|         if "@3.5.0:4.3.2" in self.spec: |         if "@3.5.0:4.3.2" in self.spec: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Cory Bloor
					Cory Bloor