summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/llvm-flang/package.py
blob: 10001e23402190ace8fd7254f188ba0bce4297dc (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Copyright 2013-2020 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 LlvmFlang(CMakePackage, CudaPackage):
    """LLVM-Flang is the Flang fork of LLVM needed by the Flang package."""

    homepage = "https://github.com/flang-compiler"

    git      = "https://github.com/flang-compiler/llvm.git"

    maintainer = ['naromero77']

    version('master', branch='master')
    version('release_70', branch='release_70')
    version('release_60', branch='release_60')
    version('20190329', tag='flang_20190329')
    version('20181226_70', tag='20181226_70')
    version('20181226_60', tag='20181226_60')
    version('20180921', tag='20180921')
    version('20180319', tag='20180319')
    version('20180328', tag='20180308')

    # Variants
    variant('all_targets', default=False,
            description='Build all supported targets')

    variant('build_type', default='Release',
            description='The CMake build type to build',
            values=('Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'))

    # Universal dependency
    depends_on('cmake@3.8:', type='build')
    depends_on('python@2.7:', type='build')

    # openmp dependencies
    depends_on('perl-data-dumper', type=('build'))
    depends_on('hwloc')

    # libomptarget dependencies
    depends_on('libelf', when='+cuda')
    depends_on('libffi', when='+cuda')
    depends_on('cuda@:9', when='+cuda')  # llvm 7 not compatible with newer version of cuda

    # LLVM-Flang Componentes: Driver, OpenMP
    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             branch='master',
             destination='tools',
             placement='clang',
             when='@master')

    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             branch='release_70',
             destination='tools',
             placement='clang',
             when='@release_70')

    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             branch='release_60',
             destination='tools',
             placement='clang',
             when='@release_60')

    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             tag='flang_20190329',
             destination='tools',
             placement='clang',
             when='@20190329')

    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             tag='flang_20181226_70',
             destination='tools',
             placement='clang',
             when='@20181226_70')

    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             tag='flang_20181226_60',
             destination='tools',
             placement='clang',
             when='@20181226_60')

    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             tag='flang_20180921',
             destination='tools',
             placement='clang',
             when='@20180921')

    resource(name='flang-driver',
             git='https://github.com/flang-compiler/flang-driver.git',
             tag='flang_20180921',
             destination='tools',
             placement='clang',
             when='@20180308')

    resource(name='openmp',
             git='https://github.com/flang-compiler/openmp.git',
             branch='master',
             destination='projects',
             placement='openmp',
             when='@master')

    resource(name='openmp',
             git='https://github.com/flang-compiler/openmp.git',
             branch='release_70',
             destination='projects',
             placement='openmp',
             when='@release_70')

    resource(name='openmp',
             git='https://github.com/flang-compiler/openmp.git',
             branch='release_60',
             destination='projects',
             placement='openmp',
             when='@release_60')

    resource(name='openmp',
             git='https://github.com/flang-compiler/openmp.git',
             tag='flang_20190329',
             destination='projects',
             placement='openmp',
             when='@20190329')

    resource(name='openmp',
             git='https://github.com/flang-compiler/openmp.git',
             tag='flang_20181226_70',
             destination='projects',
             placement='openmp',
             when='@20181226_70')

    resource(name='openmp',
             git='https://github.com/flang-compiler/openmp.git',
             tag='flang_20181226_60',
             destination='projects',
             placement='openmp',
             when='@20181226_60')

    resource(name='openmp',
             git='https://github.com/flang-compiler/openmp.git',
             tag='flang_20180921',
             destination='projects',
             placement='openmp',
             when='@20180921')

    def cmake_args(self):
        spec = self.spec
        # universal
        args = [
            '-DLLVM_ENABLE_RTTI:BOOL=ON',
            '-DLLVM_ENABLE_EH:BOOL=ON',
            '-DCLANG_DEFAULT_OPENMP_RUNTIME:STRING=libomp',
        ]
        args.append('-DPYTHON_EXECUTABLE={0}'.format(
            spec['python'].command.path))

        # needed by flang-driver
        args.append('-DFLANG_LLVM_EXTENSIONS=ON')

        if '+all_targets' not in spec:  # all is default in cmake
            if spec.target.family == 'x86' or spec.target.family == 'x86_64':
                target = 'X86'
            elif spec.target.family == 'arm':
                target = 'ARM'
            elif spec.target.family == 'aarch64':
                target = 'AArch64'
            elif (spec.target.family == 'ppc64' or
                  spec.target.family == 'ppc64le' or
                  spec.target.family == 'ppc' or
                  spec.target.family == 'ppcle'):
                target = 'PowerPC'
            else:
                raise InstallError(
                    'Unsupported architecture: ' + spec.target.family)

            if '+cuda' in spec:
                args.append(
                    '-DLLVM_TARGETS_TO_BUILD:STRING=NVPTX;' + target)
            else:
                args.append(
                    '-DLLVM_TARGETS_TO_BUILD:STRING=' + target)

        # used by openmp
        args.append('-DLIBOMP_USE_HWLOC=On')
        args.append('-DLIBOMP_FORTRAN_MODULES=ON')
        args.append('-DLIBOMP_ENABLE_SHARED=TRUE')

        # used by libomptarget for NVidia gpu
        if '+cuda' in spec:
            args.append('-DOPENMP_ENABLE_LIBOMPTARGET=ON')
            cuda_arch_list = spec.variants['cuda_arch'].value
            args.append('-DCUDA_TOOLKIT_ROOT_DIR=%s' % spec['cuda'].prefix)
            args.append('-DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES={0}'.format(
                ','.join(cuda_arch_list)))
            args.append('-DCLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_{0}'.format(
                cuda_arch_list[-1]))
        else:
            args.append('-DOPENMP_ENABLE_LIBOMPTARGET=OFF')

        return args

    @run_after("install")
    def post_install(self):
        spec = self.spec

        # Manual bootstrap needed to get NVidia BC compiled with the
        # clang that was just built
        if '+cuda' in spec:
            ompdir = 'build-bootstrapped-omp'
            # rebuild libomptarget to get bytecode runtime library files
            with working_dir(ompdir, create=True):
                args = [
                    self.stage.source_path + '/projects/openmp',
                    '-DCMAKE_C_COMPILER:PATH={0}'.format(
                        spec.prefix.bin + '/clang'),
                    '-DCMAKE_CXX_COMPILER:PATH={0}'.format(
                        spec.prefix.bin + '/clang++'),
                    '-DCMAKE_INSTALL_PREFIX:PATH={0}'.format(
                        spec.prefix)
                ]
                args = args + self.cmake_args()
                # args = self.cmake_args()
                # enable CUDA bitcode
                args.append('-DLIBOMPTARGET_NVPTX_ENABLE_BCLIB=true')
                # work around bad libelf detection in libomptarget
                args.append(
                    '-DCMAKE_CXX_FLAGS:String=-I{0} -I{1}'.format(
                        spec['libelf'].prefix.include,
                        spec['hwloc'].prefix.include))

        cmake(*args)
        make()
        make('install')