|
| 1 | +# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other |
| 2 | +# Spack Project Developers. See the top-level COPYRIGHT file for details. |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 5 | +# |
| 6 | +# ---------------------------------------------------------------------------- |
| 7 | + |
| 8 | +from spack import * |
| 9 | +from sys import platform |
| 10 | + |
| 11 | + |
| 12 | +class Timemory(CMakePackage): |
| 13 | + """Timing + Memory + Hardware Counter Utilities for C/C++/CUDA/Python""" |
| 14 | + |
| 15 | + homepage = 'https://timemory.readthedocs.io/en/latest/' |
| 16 | + git = 'https://github.com/NERSC/timemory.git' |
| 17 | + maintainers = ['jrmadsen'] |
| 18 | + |
| 19 | + version('master', branch='master', submodules=True) |
| 20 | + version('develop', branch='develop', submodules=True) |
| 21 | + version('3.0.1', commit='ef638e1cde90275ce7c0e12fc4902c27bcbdeefd', |
| 22 | + submodules=True) |
| 23 | + version('3.0.0', commit='b36b1673b2c6b7ff3126d8261bef0f8f176c7beb', |
| 24 | + submodules=True) |
| 25 | + |
| 26 | + linux = False if platform == 'darwin' else True |
| 27 | + |
| 28 | + variant('shared', default=True, description='Build shared libraries') |
| 29 | + variant('static', default=False, description='Build static libraries') |
| 30 | + variant('python', default=True, description='Enable Python support') |
| 31 | + variant('mpi', default=True, description='Enable MPI support') |
| 32 | + variant('tau', default=False, description='Enable TAU support') |
| 33 | + variant('papi', default=linux, description='Enable PAPI support') |
| 34 | + variant('cuda', default=linux, description='Enable CUDA support') |
| 35 | + variant('cupti', default=linux, description='Enable CUPTI support') |
| 36 | + variant('tools', default=True, description='Build/install extra tools') |
| 37 | + variant('vtune', default=False, description='Enable VTune support') |
| 38 | + variant('upcxx', default=False, description='Enable UPC++ support') |
| 39 | + variant('gotcha', default=linux, description='Enable GOTCHA support') |
| 40 | + variant('likwid', default=linux, description='Enable LIKWID support') |
| 41 | + variant('caliper', default=False, description='Enable Caliper support') |
| 42 | + variant('dyninst', default=linux, |
| 43 | + description='Build dynamic instrumentation tools') |
| 44 | + variant('examples', default=False, description='Build/install examples') |
| 45 | + variant('gperftools', default=True, |
| 46 | + description='Enable gperftools support') |
| 47 | + variant('kokkos_tools', default=True, |
| 48 | + description=('Build generic kokkos-tools libraries, e.g. ' |
| 49 | + 'kp_timemory, kp_timemory_filter')) |
| 50 | + variant('kokkos_build_config', default=False, |
| 51 | + description=('Build pre-configured (i.e. dedicated) kokkos-tools ' |
| 52 | + 'libraries, e.g. kp_timemory_cpu_flops')) |
| 53 | + variant('cuda_arch', default='auto', description='CUDA architecture name', |
| 54 | + values=('auto', 'kepler', 'tesla', 'maxwell', 'pascal', |
| 55 | + 'volta', 'turing'), multi=False) |
| 56 | + variant('cpu_target', default='auto', |
| 57 | + description=('Build for specific cpu architecture (specify ' |
| 58 | + 'cpu-model)')) |
| 59 | + variant('use_arch', default=False, |
| 60 | + description=('Build all of timemory w/ cpu_target architecture ' |
| 61 | + 'flags (default: roofline toolkit only)')) |
| 62 | + variant('tls_model', default='global-dynamic', |
| 63 | + description='Thread-local static model', multi=False, |
| 64 | + values=('global-dynamic', 'local-dynamic', 'initial-exec', |
| 65 | + 'local-exec')) |
| 66 | + variant('lto', default=False, |
| 67 | + description='Build w/ link-time optimization') |
| 68 | + variant('statistics', default=True, |
| 69 | + description=('Build components w/ support for statistics ' |
| 70 | + '(min/max/stddev)')) |
| 71 | + variant('extra_optimizations', default=True, |
| 72 | + description='Build timemory with extra optimization flags') |
| 73 | + variant('cxxstd', default='14', description='C++ language standard', |
| 74 | + values=('14', '17', '20'), multi=False) |
| 75 | + variant('mpip_library', default=linux, |
| 76 | + description='Build stand-alone timemory-mpip GOTCHA library') |
| 77 | + variant('ompt', default=True, description=('Enable OpenMP tools support')) |
| 78 | + variant('ompt_standalone', default=True, |
| 79 | + description=('Enable OpenMP tools support via drop-in ' |
| 80 | + 'replacement of libomp/libgomp/libiomp5')) |
| 81 | + variant('ompt_llvm', default=False, |
| 82 | + description='Enable OpenMP tools support as part of llvm build') |
| 83 | + variant('ompt_library', default=True, |
| 84 | + description='Build stand-alone timemory-ompt library') |
| 85 | + variant('allinea_map', default=False, |
| 86 | + description='Enable Allinea ARM-MAP support') |
| 87 | + variant('require_packages', default=False, |
| 88 | + description=('find_package(...) resulting in NOTFOUND ' |
| 89 | + 'generates error')) |
| 90 | + |
| 91 | + depends_on( '[email protected]:', type='build') |
| 92 | + |
| 93 | + extends('python', when='+python') |
| 94 | + depends_on('python@3:', when='+python', type=('build', 'run')) |
| 95 | + depends_on('py-numpy', when='+python', type=('run')) |
| 96 | + depends_on('py-pillow', when='+python', type=('run')) |
| 97 | + depends_on('py-matplotlib', when='+python', type=('run')) |
| 98 | + depends_on('mpi', when='+mpi') |
| 99 | + depends_on('tau', when='+tau') |
| 100 | + depends_on('papi', when='+papi') |
| 101 | + depends_on('cuda', when='+cuda') |
| 102 | + depends_on('cuda', when='+cupti') |
| 103 | + depends_on('upcxx', when='+upcxx') |
| 104 | + depends_on('likwid', when='+likwid') |
| 105 | + depends_on('gotcha', when='+gotcha') |
| 106 | + depends_on('caliper', when='+caliper') |
| 107 | + depends_on('dyninst', when='+dyninst') |
| 108 | + depends_on('gperftools', when='+gperftools') |
| 109 | + depends_on('intel-parallel-studio', when='+vtune') |
| 110 | + depends_on('llvm-openmp-ompt+standalone', when='+ompt_standalone') |
| 111 | + depends_on('llvm-openmp-ompt~standalone', when='+ompt_llvm') |
| 112 | + depends_on('arm-forge', when='+allinea_map') |
| 113 | + |
| 114 | + conflicts('+python', when='~shared', |
| 115 | + msg='+python requires building shared libraries') |
| 116 | + conflicts('+cupti', when='~cuda', msg='CUPTI requires CUDA') |
| 117 | + conflicts('+kokkos_tools', when='~tools', |
| 118 | + msg='+kokkos_tools requires +tools') |
| 119 | + conflicts('+kokkos_build_config', when='~tools', |
| 120 | + msg='+kokkos_build_config requires +tools') |
| 121 | + conflicts('+kokkos_build_config', when='~kokkos_tools', |
| 122 | + msg='+kokkos_build_config requires +kokkos_tools') |
| 123 | + conflicts('tls_model=local-dynamic', when='+python', |
| 124 | + msg='+python require tls_model=global-dynamic') |
| 125 | + conflicts('tls_model=initial-exec', when='+python', |
| 126 | + msg='+python require tls_model=global-dynamic') |
| 127 | + conflicts('tls_model=local-exec', when='+python', |
| 128 | + msg='+python require tls_model=global-dynamic') |
| 129 | + conflicts('+mpip_library', when='~mpi', msg='+mpip_library requires +mpi') |
| 130 | + conflicts('+mpip_library', when='~gotcha', |
| 131 | + msg='+mpip_library requires +gotcha') |
| 132 | + conflicts('+mpip_library', when='~shared', |
| 133 | + msg='+mpip_library requires building shared libraries') |
| 134 | + conflicts('+ompt_standalone', when='~ompt', |
| 135 | + msg='+ompt_standalone requires +ompt') |
| 136 | + conflicts('+ompt_llvm', when='~ompt', |
| 137 | + msg='+ompt_llvm requires +ompt') |
| 138 | + conflicts('+ompt_library', when='~ompt', |
| 139 | + msg='+ompt_library requires +ompt') |
| 140 | + conflicts('+ompt_library', when='~shared~static', |
| 141 | + msg='+ompt_library requires building shared or static libraries') |
| 142 | + conflicts('+ompt_standalone+ompt_llvm', |
| 143 | + msg=('+ompt_standalone and +ompt_llvm are not compatible. Use ' |
| 144 | + '+ompt_llvm~ompt_standalone if building LLVM, use ' |
| 145 | + '~ompt_llvm+ompt_standalone if ompt.h is not provided by ' |
| 146 | + 'the compiler')) |
| 147 | + |
| 148 | + def cmake_args(self): |
| 149 | + spec = self.spec |
| 150 | + |
| 151 | + args = [ |
| 152 | + '-DTIMEMORY_BUILD_PYTHON=ON', |
| 153 | + '-DTIMEMORY_BUILD_TESTING=OFF', |
| 154 | + '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON', |
| 155 | + ] |
| 156 | + |
| 157 | + cxxstd = spec.variants['cxxstd'].value |
| 158 | + args.append('-DCMAKE_CXX_STANDARD={0}'.format(cxxstd)) |
| 159 | + |
| 160 | + tls = spec.variants['tls_model'].value |
| 161 | + args.append('-DTIMEMORY_TLS_MODEL={0}'.format(tls)) |
| 162 | + |
| 163 | + if '+python' in spec: |
| 164 | + args.append('-DPYTHON_EXECUTABLE={0}'.format( |
| 165 | + spec['python'].command.path)) |
| 166 | + |
| 167 | + if '+mpi' in spec: |
| 168 | + args.append('-DTIMEMORY_USE_MPI_LINK_FLAGS=OFF') |
| 169 | + args.append('-DMPI_C_COMPILER={0}'.format(spec['mpi'].mpicc)) |
| 170 | + args.append('-DMPI_CXX_COMPILER={0}'.format(spec['mpi'].mpicxx)) |
| 171 | + |
| 172 | + if '+cuda' in spec: |
| 173 | + targ = spec.variants['cuda_arch'].value |
| 174 | + key = '' if spec.satisfies('@:3.0.1') else 'TIMEMORY_' |
| 175 | + # newer versions use 'TIMEMORY_CUDA_ARCH' |
| 176 | + args.append('-D{0}CUDA_ARCH={1}'.format(key, targ)) |
| 177 | + |
| 178 | + cpu_target = spec.variants['cpu_target'].value |
| 179 | + if cpu_target == 'auto': |
| 180 | + args.append('-DCpuArch_TARGET={0}'.format(cpu_target)) |
| 181 | + |
| 182 | + # forced disabling of submodule builds |
| 183 | + for dep in ('caliper', 'gotcha', 'ompt'): |
| 184 | + args.append('-DTIMEMORY_BUILD_{0}=OFF'.format(dep.upper())) |
| 185 | + |
| 186 | + # spack options which translate to TIMEMORY_<OPTION> |
| 187 | + for dep in ('require_packages', 'kokkos_build_config', 'use_arch'): |
| 188 | + args.append('-DTIMEMORY_{0}={1}'.format( |
| 189 | + dep.upper(), 'ON' if '+{0}'.format(dep) in spec else 'OFF')) |
| 190 | + |
| 191 | + # spack options which translate to BUILD_<OPTION>_LIBS |
| 192 | + for dep in ('shared', 'static'): |
| 193 | + args.append('-DBUILD_{0}_LIBS={1}'.format( |
| 194 | + dep.upper(), 'ON' if '+{0}'.format(dep) in spec else 'OFF')) |
| 195 | + |
| 196 | + # spack options which translate to TIMEMORY_BUILD_<OPTION> |
| 197 | + for dep in ('tools', 'examples', 'kokkos_tools', 'lto', |
| 198 | + 'extra_optimizations', 'mpip_library', 'ompt_library'): |
| 199 | + args.append('-DTIMEMORY_BUILD_{0}={1}'.format( |
| 200 | + dep.upper(), 'ON' if '+{0}'.format(dep) in spec else 'OFF')) |
| 201 | + |
| 202 | + # spack options which translate to TIMEMORY_USE_<OPTION> |
| 203 | + for dep in ('allinea_map', 'python', 'mpi', 'tau', 'papi', 'ompt', |
| 204 | + 'cuda', 'cupti', 'cupti', 'vtune', 'upcxx', 'gotcha', |
| 205 | + 'likwid', 'caliper', 'dyninst', 'gperftools', |
| 206 | + 'statistics'): |
| 207 | + args.append('-DTIMEMORY_USE_{0}={1}'.format( |
| 208 | + dep.upper(), 'ON' if '+{0}'.format(dep) in spec else 'OFF')) |
| 209 | + |
| 210 | + return args |
0 commit comments