From 457daf4be65478a592102177662eb9dad52b8767 Mon Sep 17 00:00:00 2001 From: Sreenivasa Murthy Kolam <67086238+srekolam@users.noreply.github.com> Date: Wed, 21 Sep 2022 16:54:40 -0700 Subject: Add new variants (OPENCL and HIP) for MIVisionX recipe and their dependencies correctly. (#32486) * add the 2 variants OPENCL and HIP and their dependencies correctly for OPENCL - rocm-opencl, miopengemm and miopen-opencl for HIP - miopen-hip Earlier this was adding both the dependencies -miopen-hip and miopen-opencl for both the backends which did not seem correct. Also corrected the miopen-hip or miopen-opencl config.h in patch() depending on the backend Also added libjpeg-turbo as it is required for building ROCAl . the AMDRpp is still required for ROCAL inclusion but it currently does not build AMDRpp will be added as a new spack recipe and the mivisionx will refer to that as a dependency in future. * fix style errors * bump up the version for 5.2.3 release. tested +opencl, +hip and ~hip~opencl(cpu backend) Co-authored-by: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> --- .../repos/builtin/packages/mivisionx/package.py | 124 ++++++++++++++------- 1 file changed, 84 insertions(+), 40 deletions(-) diff --git a/var/spack/repos/builtin/packages/mivisionx/package.py b/var/spack/repos/builtin/packages/mivisionx/package.py index 625e4914fc..4bec317816 100644 --- a/var/spack/repos/builtin/packages/mivisionx/package.py +++ b/var/spack/repos/builtin/packages/mivisionx/package.py @@ -25,6 +25,7 @@ class Mivisionx(CMakePackage): url = "https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX/archive/rocm-{0}.tar.gz" return url.format(version) + version("5.2.3", sha256="bbcdb5808d2bc880486dffa89f4111fb4b1d6dfe9b11fcd46fbd17939d057cf0") version("5.2.1", sha256="201996b31f59a8d5e4cc3f17d17a5b81158a34d2a1c833b65ccc3dceb21d176f") version("5.2.0", sha256="fee620a1edd3bce18b2cec9ef26ec2afe0a85d6da8a37ed713ab0d1342382503") version("5.1.3", sha256="62591d5caedc13832c3ccef629a88d9c2a43c884daad1124ddcb9c5f7d5470e9") @@ -90,10 +91,16 @@ class Mivisionx(CMakePackage): values=("Release", "Debug", "RelWithDebInfo"), description="CMake build type", ) - variant("backend", default="OPENCL", values=("HIP", "OPENCL"), description="backend type") + # Adding 2 variants OPENCL ,HIP which HIP as default. earlier to 5.0.0,OPENCL + # was the default but has change dto HIP from 5.0.0 onwards. + # when tested with HIP as true for versions before 5.1.0, build errors were encountered + # this was corrected with 5.2.0. Hence it was made as default starting with 5.2.0 onwards + + variant("opencl", default=False, description="Use OPENCL as the backend") + variant("hip", default=True, description="Use HIP as backend") def patch(self): - if "@4.2.0" in self.spec: + if self.spec.satisfies("@4.2.0"): filter_file( "${ROCM_PATH}/opencl", self.spec["rocm-opencl"].prefix, @@ -106,7 +113,7 @@ class Mivisionx(CMakePackage): "utilities/mv_deploy/CMakeLists.txt", string=True, ) - if "@4.5.0:5.1" in self.spec: + if self.spec.satisfies("@4.5.0:5.1 + hip"): filter_file( "${ROCM_PATH}/miopen", self.spec["miopen-hip"].prefix.miopen, @@ -125,13 +132,20 @@ class Mivisionx(CMakePackage): "amd_openvx_extensions/amd_nn/nn_hip/CMakeLists.txt", string=True, ) - - def flag_handler(self, name, flags): - spec = self.spec - protobuf = spec["protobuf"].prefix.include - if name == "cxxflags": - flags.append("-I{0}".format(protobuf)) - return (flags, None, None) + if self.spec.satisfies("@5.1.3: + hip"): + filter_file( + "${ROCM_PATH}/include/miopen/config.h", + "{0}/include/miopen/config.h".format(self.spec["miopen-hip"].prefix), + "amd_openvx_extensions/CMakeLists.txt", + string=True, + ) + if self.spec.satisfies("@5.1.3: + opencl"): + filter_file( + "${ROCM_PATH}/include/miopen/config.h", + "{0}/include/miopen/config.h".format(self.spec["miopen-opencl"].prefix), + "amd_openvx_extensions/CMakeLists.txt", + string=True, + ) depends_on("cmake@3.5:", type="build") depends_on("ffmpeg@:4", type="build") @@ -142,46 +156,76 @@ class Mivisionx(CMakePackage): "+video+videoio+flann+photo+objdetect", type="build", ) - depends_on("rocm-opencl@3.5.0", when="@1.7") + depends_on("rocm-opencl@3.5.0", when="@1.7+opencl") depends_on("rocm-cmake@3.5.0", type="build", when="@1.7") - depends_on("miopen-opencl@3.5.0", when="@1.7") - depends_on("miopengemm@1.1.6", when="@1.7") + depends_on("miopen-opencl@3.5.0", when="@1.7+opencl") + depends_on("miopengemm@1.1.6", when="@1.7+opencl") depends_on("openssl", when="@4.0.0:") + depends_on("libjpeg-turbo", type="build") conflicts("^cmake@3.22:", when="@:5.0.0") + # need to choose atleast one backend and both cannot be set + # HIP as backend did not build for older releases 5.1.0 where + # OPENCL was default backend. + conflicts("+opencl+hip") + conflicts("+hip", when="@:5.1.0") - for ver in [ - "3.7.0", - "3.8.0", - "3.9.0", - "3.10.0", - "4.0.0", - "4.1.0", - "4.2.0", - "4.3.0", - "4.3.1", - "4.5.0", - "4.5.2", - "5.0.0", - "5.0.2", - "5.1.0", - "5.1.3", - "5.2.0", - "5.2.1", - ]: - depends_on("rocm-opencl@" + ver, when="@" + ver) - depends_on("miopengemm@" + ver, when="@" + ver) - depends_on("miopen-opencl@" + ver, when="@" + ver) - for ver in ["4.5.0", "4.5.2", "5.0.0", "5.0.2", "5.1.0", "5.1.3", "5.2.0", "5.2.1"]: - depends_on("miopen-hip@" + ver, when="@" + ver) + with when("+opencl"): + for ver in [ + "3.7.0", + "3.8.0", + "3.9.0", + "3.10.0", + "4.0.0", + "4.1.0", + "4.2.0", + "4.3.0", + "4.3.1", + "4.5.0", + "4.5.2", + "5.0.0", + "5.0.2", + "5.1.0", + "5.1.3", + "5.2.0", + "5.2.1", + "5.2.3", + ]: + depends_on("rocm-opencl@" + ver, when="@" + ver) + depends_on("miopengemm@" + ver, when="@" + ver) + depends_on("miopen-opencl@" + ver, when="@" + ver) + with when("+hip"): + for ver in [ + "4.5.0", + "4.5.2", + "5.0.0", + "5.0.2", + "5.1.0", + "5.1.3", + "5.2.0", + "5.2.1", + "5.2.3", + ]: + depends_on("miopen-hip@" + ver, when="@" + ver) + + def flag_handler(self, name, flags): + spec = self.spec + protobuf = spec["protobuf"].prefix.include + if name == "cxxflags": + flags.append("-I{0}".format(protobuf)) + return (flags, None, None) def cmake_args(self): spec = self.spec protobuf = spec["protobuf"].prefix.include args = [ self.define("CMAKE_CXX_FLAGS", "-I{0}".format(protobuf)), - self.define_from_variant("BACKEND", "backend"), - self.define("HIP_PATH", spec["hip"].prefix), - self.define("HSA_PATH", spec["hsa-rocr-dev"].prefix), ] + if self.spec.satisfies("+opencl"): + args.append(self.define("BACKEND", "OPENCL")) + args.append(self.define("HSA_PATH", spec["hsa-rocr-dev"].prefix)) + if self.spec.satisfies("+hip"): + args.append(self.define("BACKEND", "HIP")) + args.append(self.define("HSA_PATH", spec["hsa-rocr-dev"].prefix)) + args.append(self.define("HIP_PATH", spec["hip"].prefix)) return args -- cgit v1.2.3-70-g09d2