summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/stream/package.py
blob: 842a9b2e8a8875ab4d5b30b0343731a9dcd85f61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 2013-2024 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)

from spack.package import *


class Stream(MakefilePackage):
    """The STREAM benchmark is a simple synthetic benchmark program that
    measures sustainable memory bandwidth (in MB/s) and the corresponding
    computation rate for simple vector kernels."""

    homepage = "https://www.cs.virginia.edu/stream/ref.html"
    git = "https://github.com/jeffhammond/STREAM.git"

    version("5.10")

    variant("openmp", default=False, description="Build with OpenMP support")

    variant("stream_array_size", default="none", description="Size of work arrays in elements")
    variant(
        "ntimes",
        default="none",
        description='STREAM runs each kernel "NTIMES" times and reports the *best* result',
    )
    variant("offset", default="none", description="Relative alignment between arrays")
    variant(
        "stream_type",
        default="none",
        values=("none", "float", "double", "int", "long"),
        description="Datatype of arrays elements",
    )

    def edit(self, spec, prefix):
        makefile = FileFilter("Makefile")

        # Use the Spack compiler wrappers
        makefile.filter("CC = .*", "CC = {0}".format(spack_cc))
        makefile.filter("FC = .*", "FC = {0}".format(spack_f77))

        cflags = "-O2"
        fflags = "-O2"
        if "+openmp" in self.spec:
            cflags += " " + self.compiler.openmp_flag
            fflags += " " + self.compiler.openmp_flag
        if "%aocc" in self.spec:
            cflags += " -mcmodel=large -ffp-contract=fast -fnt-store"

        if self.spec.variants["stream_array_size"].value != "none":
            cflags += " -DSTREAM_ARRAY_SIZE={0}".format(
                self.spec.variants["stream_array_size"].value
            )
        if self.spec.variants["ntimes"].value != "none":
            cflags += " -DNTIMES={0}".format(self.spec.variants["ntimes"].value)
        if self.spec.variants["offset"].value != "none":
            cflags += " -DOFFSET={0}".format(self.spec.variants["offset"].value)
        if self.spec.variants["stream_type"].value != "none":
            cflags += " -DSTREAM_TYPE={0}".format(self.spec.variants["stream_type"].value)

        # Set the appropriate flags for this compiler
        makefile.filter("CFLAGS = .*", "CFLAGS = {0}".format(cflags))
        makefile.filter("FFLAGS = .*", "FFLAGS = {0}".format(fflags))

    def install(self, spec, prefix):
        # Manual installation
        mkdir(prefix.bin)
        install("stream_c.exe", prefix.bin)
        install("stream_f.exe", prefix.bin)