diff options
author | Michael F. Herbst <info@michael-herbst.com> | 2017-11-27 21:55:29 +0100 |
---|---|---|
committer | Christoph Junghans <christoph.junghans@gmail.com> | 2017-11-27 13:55:29 -0700 |
commit | 3d4e51fad25be6d4c654684d700d6c175a1b73c7 (patch) | |
tree | e6891ef55c43b9bf2eb898bbcc01de2297b38e59 | |
parent | dbb329637b1c7fdb1183bd5dd9ade65301b5e66d (diff) | |
download | spack-3d4e51fad25be6d4c654684d700d6c175a1b73c7.tar.gz spack-3d4e51fad25be6d4c654684d700d6c175a1b73c7.tar.bz2 spack-3d4e51fad25be6d4c654684d700d6c175a1b73c7.tar.xz spack-3d4e51fad25be6d4c654684d700d6c175a1b73c7.zip |
Add two test examples to bohrium (#6459)
-rw-r--r-- | var/spack/repos/builtin/packages/bohrium/cxxadd.cpp | 24 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/bohrium/package.py | 85 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/bohrium/pyadd.py | 10 |
3 files changed, 110 insertions, 9 deletions
diff --git a/var/spack/repos/builtin/packages/bohrium/cxxadd.cpp b/var/spack/repos/builtin/packages/bohrium/cxxadd.cpp new file mode 100644 index 0000000000..94c9287807 --- /dev/null +++ b/var/spack/repos/builtin/packages/bohrium/cxxadd.cpp @@ -0,0 +1,24 @@ +#include <bhxx/bhxx.hpp> + +int main() { + const size_t dim = 3; + bhxx::BhArray<double> a({dim}); + bhxx::BhArray<double> b({dim}); + bhxx::BhArray<double> c({dim}); + + bhxx::identity(a, 1); + bhxx::identity(b, 2); + bhxx::add(c, a, b); + + bhxx::Runtime::instance().sync(c.base); + bhxx::Runtime::instance().flush(); + + for (auto it = c.data(); it < c.data() + dim; ++it) { + if (*it != 3) { + std::cout << "Failure, values not as expected." << std::endl; + return 1; + } + } + std::cout << "Success!" << std::endl; + return 0; +} diff --git a/var/spack/repos/builtin/packages/bohrium/package.py b/var/spack/repos/builtin/packages/bohrium/package.py index a4202688d2..f54cb8a34d 100644 --- a/var/spack/repos/builtin/packages/bohrium/package.py +++ b/var/spack/repos/builtin/packages/bohrium/package.py @@ -24,6 +24,9 @@ ############################################################################## from spack.build_systems.cuda import CudaPackage from spack import * +from spack.package_test import compare_output +from spack.util.executable import Executable +import llnl.util.tty as tty import os @@ -96,14 +99,14 @@ class Bohrium(CMakePackage, CudaPackage): depends_on('blas', when="+blas") # Make sure an appropriate opencv is used - depends_on('opencv', when="+opencv") - depends_on('opencv+cuda', when="+opencv+cuda") - depends_on('opencv+openmp', when="+opencv+openmp") - depends_on('opencv+openmp+cuda', when="+opencv+openmp+cuda") + depends_on('opencv+imgproc', when="+opencv") + depends_on('opencv+imgproc+cuda', when="+opencv+cuda") + depends_on('opencv+imgproc+openmp', when="+opencv+openmp") + depends_on('opencv+imgproc+openmp+cuda', when="+opencv+openmp+cuda") depends_on('python', type="build", when="~python") - depends_on('python', when="+python") - depends_on('py-numpy', when="+python") + depends_on('python', type=("build", "link", "test"), when="+python") + depends_on('py-numpy', type=("build", "test", "run"), when="+python") depends_on('swig', type="build", when="+python") depends_on('py-cython', type="build", when="+python") @@ -177,7 +180,7 @@ class Bohrium(CMakePackage, CudaPackage): args += [ "-DEXT_BLAS=ON", "-DCBLAS_FOUND=True", - "-DCBLAS_LIBRARIES=" + ";".join(spec["blas"].libs), + "-DCBLAS_LIBRARIES=" + spec["blas"].libs.joined(";"), "-DCBLAS_INCLUDES=" + spec["blas"].prefix.include, ] else: @@ -187,7 +190,7 @@ class Bohrium(CMakePackage, CudaPackage): args += [ "-DEXT_LAPACK=ON", "-DLAPACKE_FOUND=True", - "-DLAPACKE_LIBRARIES=" + ";".join(spec["lapack"].libs), + "-DLAPACKE_LIBRARIES=" + spec["lapack"].libs.joined(";"), "-DLAPACKE_INCLUDE_DIR=" + spec["lapack"].prefix.include, ] else: @@ -198,7 +201,7 @@ class Bohrium(CMakePackage, CudaPackage): "-DEXT_OPENCV=ON", "-DOpenCV_FOUND=True", "-DOpenCV_INCLUDE_DIRS=" + spec["opencv"].prefix.include, - "-DOpenCV_LIBS=" + ";".join(spec["opencv"].prefix.libs), + "-DOpenCV_LIBS=" + spec["opencv"].libs.joined(";"), ] else: args += ["-DEXT_OPENCV=OFF", "-DOpenCV_FOUND=False"] @@ -220,3 +223,67 @@ class Bohrium(CMakePackage, CudaPackage): # the self.prefix.include dir run_env.prepend_path("CPATH", self.prefix.include.bohrium) run_env.set("BH_CONFIG", self.config_file) + + # + # Quick tests + # + @run_after('install') + @on_package_attributes(run_tests=True) + def check_install(self): + spec = self.spec + test_env = {} + + # Make sure the correct config is found + test_env["BH_CONFIG"] = self.config_file + + # Remove the lib/spackenv directory from the PATH variable when + # executing the tests, becauses it messes with the JIT compilation + # inside Bohrium + paths = os.environ['PATH'].split(':') + paths = [p for p in paths if "spack/env" not in p] + test_env["PATH"] = ":".join(paths) + + # Add the PYTHONPATH to bohrium to the PYTHONPATH environment + pythonpaths = [p for p in os.environ["PYTHONPATH"].split(":")] + pythonpaths.append(join_path(self.prefix, + spec['python'].package.site_packages_dir)) + test_env["PYTHONPATH"] = ":".join(pythonpaths) + + # Collect the stacks which should be available: + stacks = ["default"] + if "+openmp" in spec: + stacks.append("openmp") + if "+cuda" in spec: + stacks.append("cuda") + if "+opencl" in spec: + stacks.append("opencl") + + # C++ compiler and compiler flags + cxx = Executable(self.compiler.cxx) + cxx_flags = ["-I", self.prefix.include, + "-I", self.prefix.include.bohrium, + "-L", self.prefix.lib, "-lbh", "-lbhxx"] + + # Compile C++ test program + file_cxxadd = join_path(os.path.dirname(self.module.__file__), + "cxxadd.cpp") + cxx("-o", "test_cxxadd", file_cxxadd, *cxx_flags) + test_cxxadd = Executable("./test_cxxadd") + + # Build python test commandline + file_pyadd = join_path(os.path.dirname(self.module.__file__), + "pyadd.py") + test_pyadd = Executable(spec['python'].command.path + " " + file_pyadd) + + # Run tests for each available stack + for bh_stack in stacks: + tty.info("Testing with bohrium stack '" + bh_stack + "'") + test_env["BH_STACK"] = bh_stack + + cpp_output = test_cxxadd(output=str, env=test_env) + compare_output(cpp_output, "Success!\n") + + # Python test (if +python) + if "+python" in spec: + py_output = test_pyadd(output=str, env=test_env) + compare_output(py_output, "Success!\n") diff --git a/var/spack/repos/builtin/packages/bohrium/pyadd.py b/var/spack/repos/builtin/packages/bohrium/pyadd.py new file mode 100644 index 0000000000..fc9f6968df --- /dev/null +++ b/var/spack/repos/builtin/packages/bohrium/pyadd.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import bohrium as bh +a = bh.array([1, 2, 3]) +b = bh.array([3, 4, 5]) +c = a + b + +if bh.all(c == bh.array([4, 6, 8])): + print("Success!") +else: + print("Failure, values not as expected.") |