From db23fd055ce17b48a21d307140ff4136acd64299 Mon Sep 17 00:00:00 2001 From: afzpatel <122491982+afzpatel@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:05:46 -0400 Subject: new hip-examples package (#35891) * initial commit for adding hip-examples package * adding test to hip-examples * fixed compile error on add4 * change standalone test to use new syntax --- ...dd-inc-and-lib-paths-to-openmp-helloworld.patch | 12 ++++ .../0002-add-fpic-compile-to-add4.patch | 9 +++ .../repos/builtin/packages/hip-examples/package.py | 64 ++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 var/spack/repos/builtin/packages/hip-examples/0001-add-inc-and-lib-paths-to-openmp-helloworld.patch create mode 100644 var/spack/repos/builtin/packages/hip-examples/0002-add-fpic-compile-to-add4.patch create mode 100644 var/spack/repos/builtin/packages/hip-examples/package.py diff --git a/var/spack/repos/builtin/packages/hip-examples/0001-add-inc-and-lib-paths-to-openmp-helloworld.patch b/var/spack/repos/builtin/packages/hip-examples/0001-add-inc-and-lib-paths-to-openmp-helloworld.patch new file mode 100644 index 0000000000..385b2d1116 --- /dev/null +++ b/var/spack/repos/builtin/packages/hip-examples/0001-add-inc-and-lib-paths-to-openmp-helloworld.patch @@ -0,0 +1,12 @@ +diff --git a/openmp-helloworld/Makefile b/openmp-helloworld/Makefile +index f048d26..3e0d5ac 100644 +--- a/openmp-helloworld/Makefile ++++ b/openmp-helloworld/Makefile +@@ -6,6 +6,8 @@ endif + HIPCC=$(HIP_PATH)/bin/hipcc + CXX=$(HIPCC) + CXXFLAGS =-fopenmp ++CXXFLAGS += -I$(ROCM_OPENMP_EXTRAS_DIR)/include ++CXXFLAGS += -L$(ROCM_OPENMP_EXTRAS_DIR)/lib + + SOURCES = openmp_helloworld.cpp diff --git a/var/spack/repos/builtin/packages/hip-examples/0002-add-fpic-compile-to-add4.patch b/var/spack/repos/builtin/packages/hip-examples/0002-add-fpic-compile-to-add4.patch new file mode 100644 index 0000000000..a858fd44e0 --- /dev/null +++ b/var/spack/repos/builtin/packages/hip-examples/0002-add-fpic-compile-to-add4.patch @@ -0,0 +1,9 @@ +diff --git a/add4/Makefile b/add4/Makefile +index a0c6826..d7b26b1 100644 +--- a/add4/Makefile ++++ b/add4/Makefile +@@ -1,4 +1,4 @@ +-CXXFLAGS += -std=c++11 -O3 ++CXXFLAGS += -std=c++11 -O3 -fPIC + + all: gpu-stream-hip diff --git a/var/spack/repos/builtin/packages/hip-examples/package.py b/var/spack/repos/builtin/packages/hip-examples/package.py new file mode 100644 index 0000000000..c625d0fe4b --- /dev/null +++ b/var/spack/repos/builtin/packages/hip-examples/package.py @@ -0,0 +1,64 @@ +# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import os + +from spack.package import * + + +class HipExamples(Package): + """Examples for HIP""" + + homepage = "https://github.com/ROCm-Developer-Tools/HIP-Examples/" + git = "https://github.com/ROCm-Developer-Tools/HIP-Examples.git" + url = "https://github.com/ROCm-Developer-Tools/HIP-Examples/archive/rocm-5.4.3.tar.gz" + tags = ["rocm"] + + maintainers("srekolam", "renjithravindrankannath", "afzpatel") + + version("master", branch="master") + + version("5.4.3", sha256="053b8b7892e2929e3f90bd978d8bb1c9801e4803eadd7d97fc6692ce60af1d47") + + patch("0001-add-inc-and-lib-paths-to-openmp-helloworld.patch") + patch("0002-add-fpic-compile-to-add4.patch") + depends_on("hip") + depends_on("rocm-openmp-extras") + + def install(self, spec, prefix): + stage = os.getcwd() + os.environ["ROCM_OPENMP_EXTRAS_DIR"] = self.spec["rocm-openmp-extras"].prefix + os.environ["LD_LIBRARY_PATH"] = self.spec["rocm-openmp-extras"].prefix.lib + for root, dirs, files in os.walk(stage): + if "Makefile" in files: + with working_dir(root, create=True): + make() + # itterate 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): + install(file, join_path(prefix, file)) + if file == "RecursiveGaussian": + install( + "RecursiveGaussian_Input.bmp", + join_path(prefix, "RecursiveGaussian_Input.bmp"), + ) + + def test_examples(self): + """ + run all hip example binaries + """ + + os.environ["LD_LIBRARY_PATH"] = self.spec["rocm-openmp-extras"].prefix.lib + test_dir = self.prefix + for file_name in os.listdir(test_dir): + file_path = join_path(test_dir, file_name) + if os.path.isfile(file_path) and os.access(file_path, os.X_OK): + with test_part( + self, + "test_example_{0}".format(file_name), + purpose="run installed {0}".format(file_name), + ): + exe = which(file_path) + exe() -- cgit v1.2.3-60-g2f50