summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/gptune/package.py
blob: e7d952efad164008752bd1694b40dd2229958656 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright 2013-2021 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 import *


class Gptune(CMakePackage):
    """GPTune is an autotuning framework that relies on multitask and transfer
    learnings to help solve the underlying black-box optimization problem using
    Bayesian optimization methodologies."""

    homepage = "https://gptune.lbl.gov/"
    git      = "https://github.com/gptune/GPTune.git"
    maintainers = ['liuyangzhuan']

    version('master', branch='master')

    variant('app', default=False, description='Build all HPC application examples')

    depends_on('mpi', type=('build', 'link', 'run'))
    depends_on('cmake@3.3:', type='build')
    depends_on('jq', type='run')
    depends_on('blas', type='link')
    depends_on('lapack', type='link')
    depends_on('scalapack', type='link')
    depends_on('py-setuptools', type='build')
    depends_on('py-ipyparallel', type=('build', 'run'))
    depends_on('py-numpy', type=('build', 'run'))
    depends_on('py-pandas', type=('build', 'run'))
    depends_on('py-joblib', type=('build', 'run'))
    depends_on('py-scikit-learn', type=('build', 'run'))
    depends_on('py-matplotlib', type=('build', 'run'))
    depends_on('py-pyyaml', type=('build', 'run'))
    depends_on('py-scikit-optimize@master+gptune', type=('build', 'run'))
    depends_on('py-gpy', type=('build', 'run'))
    depends_on('py-lhsmdu', type=('build', 'run'))
    depends_on('py-hpbandster', type=('build', 'run'))
    depends_on('py-opentuner', type=('build', 'run'))
    depends_on('py-ytopt-autotune@1.1.0', type=('build', 'run'))
    depends_on('py-filelock', type=('build', 'run'))
    depends_on('py-requests', type=('build', 'run'))
    depends_on('py-cython', type=('build', 'run'))
    depends_on('py-pyaml', type=('build', 'run'))
    depends_on('py-mpi4py@3.0.3:', type=('build', 'run'))
    depends_on('pygmo', type=('build', 'run'))
    depends_on('openturns', type=('build', 'run'))

    depends_on('superlu-dist@develop', when='+app', type=('build', 'run'))

    conflicts('openmpi@:3')

    def cmake_args(self):
        spec = self.spec
        fc_flags = []
        if '%gcc@10:' in spec or self.spec.satisfies('%apple-clang@11:'):
            fc_flags.append('-fallow-argument-mismatch')

        args = [
            '-DTPL_BLAS_LIBRARIES=%s' % spec['blas'].libs.joined(";"),
            '-DTPL_LAPACK_LIBRARIES=%s' % spec['lapack'].libs.joined(";"),
            '-DTPL_SCALAPACK_LIBRARIES=%s' % spec['scalapack'].
            libs.joined(";"),
            '-DCMAKE_Fortran_FLAGS=' + ''.join(fc_flags),
            '-DBUILD_SHARED_LIBS=ON',
        ]

        return args

    examples_src_dir = 'examples'
    src_dir = 'GPTune'
    nodes = 1
    cores = 4

    @run_after('install')
    def cache_test_sources(self):
        """Copy the example source files after the package is installed to an
        install test subdirectory for use during `spack test run`."""
        self.cache_extra_test_sources([self.examples_src_dir, self.src_dir])

    def test(self):
        spec = self.spec
        comp_name = self.compiler.name
        comp_version = str(self.compiler.version).replace('.', ',')
        test_dir = join_path(self.install_test_root, self.examples_src_dir)

        if '+app' in spec:
            superludriver = join_path(spec['superlu-dist'].prefix.bin, 'pddrive_spawn')
            op = ['-r', superludriver, '.']
            # copy superlu-dist executables to the correct place
            with working_dir(join_path(test_dir, 'SuperLU_DIST'), create=False):
                self.run_test('rm', options=['-rf', 'superlu_dist'], work_dir='.')
                self.run_test('git', options=['clone', 'https://github.com/xiaoyeli/superlu_dist.git'], work_dir='.')
                self.run_test('mkdir', options=['-p',
                                                'build'], work_dir='./superlu_dist')
                self.run_test('mkdir', options=['-p', 'EXAMPLE'],
                              work_dir='./superlu_dist/build')
                self.run_test('cp', options=op, work_dir='./superlu_dist/build/EXAMPLE')

        with working_dir(self.install_test_root, create=False):
            cdir = join_path(self.prefix, 'gptuneclcm')
            self.run_test('cp', options=['-r', cdir, '.'], work_dir='.')
            self.run_test('rm', options=['-rf', 'build'], work_dir='.')
            self.run_test('mv', options=['gptuneclcm', 'build'], work_dir='.')

            with open('{0}/run_env.sh'.format(self.install_test_root), 'w') as envfile:
                envfile.write('if [[ $NERSC_HOST = "cori" ]]; then\n')
                envfile.write('    export machine=cori\n')
                envfile.write('elif [[ $(uname -s) = "Darwin" ]]; then\n')
                envfile.write('    export machine=mac\n')
                envfile.write('elif [[ $(dnsdomainname) = ' +
                              '"summit.olcf.ornl.gov" ]]; then\n')
                envfile.write('    export machine=summit\n')
                envfile.write('elif [[ $(cat /etc/os-release | grep "PRETTY_NAME") ==' +
                              ' *"Ubuntu"* || $(cat /etc/os-release | grep' +
                              ' "PRETTY_NAME") == *"Debian"* ]]; then\n')
                envfile.write('    export machine=unknownlinux\n')
                envfile.write('fi\n')
                envfile.write('export GPTUNEROOT=$PWD\n')
                envfile.write('export MPIRUN={0}\n'.format
                              (which(spec['mpi'].prefix.bin + '/mpirun')))
                envfile.write('export proc=$(spack arch)\n')
                envfile.write('export mpi={0}\n'.format(spec['mpi'].name))
                envfile.write('export compiler={0}\n'.format(comp_name))
                envfile.write('export nodes={0} \n'.format(self.nodes))
                envfile.write('export cores={0} \n'.format(self.cores))
                envfile.write('export ModuleEnv=$machine-$proc-$mpi-$compiler \n')
                envfile.write('software_json=$(echo ",\\\"software_configuration\\\":' +
                              '{\\\"' + spec['blas'].name +
                              '\\\":{\\\"version_split\\\":' +
                              ' [' + str(spec['blas'].versions).replace('.', ',') +
                              ']},\\\"' + spec['mpi'].name +
                              '\\\":{\\\"version_split\\\": [' +
                              str(spec['mpi'].versions).replace('.', ',') + ']},\\\"' +
                              spec['scalapack'].name +
                              '\\\":{\\\"version_split\\\": [' +
                              str(spec['scalapack'].versions).replace('.', ',') +
                              ']},\\\"' +
                              str(comp_name) + '\\\":{\\\"version_split\\\": [' +
                              str(comp_version) + ']}}") \n')
                envfile.write('loadable_software_json=$(echo ",\\\"loadable_software_' +
                              'configurations\\\":{\\\"' + spec['blas'].name +
                              '\\\":{\\\"version_split\\\": [' +
                              str(spec['blas'].versions).replace('.', ',') +
                              ']},\\\"' + spec['mpi'].name +
                              '\\\":{\\\"version_split\\\": [' +
                              str(spec['mpi'].versions).replace('.', ',') + ']},\\\"' +
                              spec['scalapack'].name +
                              '\\\":{\\\"version_split\\\": [' +
                              str(spec['scalapack'].versions).replace('.', ',') +
                              ']},\\\"' + str(comp_name) +
                              '\\\":{\\\"version_split\\\": ['
                              + str(comp_version) + ']}}") \n')
                envfile.write('machine_json=$(echo ",\\\"machine_configuration\\\":' +
                              '{\\\"machine_name\\\":\\\"$machine\\\",\\\"$proc\\\":' +
                              '{\\\"nodes\\\":$nodes,\\\"cores\\\":$cores}}") \n')
                envfile.write('loadable_machine_json=$(echo ",\\\"loadable_machine_' +
                              'configurations\\\":{\\\"$machine\\\":{\\\"$proc\\\":' +
                              '{\\\"nodes\\\":$nodes,\\\"cores\\\":$cores}}}") \n')

        if '+app' in spec:
            apps = ['GPTune-Demo', 'SuperLU_DIST', 'SuperLU_DIST_RCI',
                    'Scalapack-PDGEQRF', 'Scalapack-PDGEQRF_RCI']
        else:
            apps = ['GPTune-Demo', 'Scalapack-PDGEQRF', 'Scalapack-PDGEQRF_RCI']

        for app in apps:
            with working_dir(join_path(test_dir, app), create=False):
                # PDGEQRF with GPTune
                self.run_test('bash', options=['run_examples.sh'], work_dir='.',
                              purpose='gptune smoke test for {0}'.format(app))