-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeson.build
More file actions
850 lines (770 loc) · 34 KB
/
meson.build
File metadata and controls
850 lines (770 loc) · 34 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
project(
'hpctoolkit',
'c',
'cpp',
version: '2024.01.99-next',
meson_version: '>=1.1.0',
license: 'BSD-3-Clause',
default_options: [
'buildtype=debugoptimized',
'c_std=gnu11',
'cpp_std=gnu++17',
'cuda_std=c++14',
'b_ndebug=if-release',
],
)
fs = import('fs')
pymod = import('python')
cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
# Find Python.
python = find_program('python3', 'python', version: '>=3.8', required: false)
if not python.found()
_pynames = []
foreach ver : range(8, 15)
_pynames += [f'python3.@ver@']
endforeach
python = find_program(_pynames, version: '>=3.8')
endif
# Find the Python installation, used for the Python unwinding support. This needs to be the same
# version as the Python we test with to make everything compatible.
python_inst = pymod.find_installation(python.full_path(), required: get_option('python'))
if python_inst.found()
assert(python_inst.language_version().version_compare('>=3.8'))
_py_dep = python_inst.dependency(required: get_option('python'))
# FIXME: Workaround for https://github.com/mesonbuild/meson/issues/12862
if not cc.has_header('Python.h', dependencies: _py_dep)
_py_dep = dependency('', required: false)
endif
# To support methods like extension_module(), we make the whole Python install object
# "not found" if the dependency was not found.
if not _py_dep.found()
python_inst = disabler()
endif
endif
if python_inst.found()
add_project_arguments('-DENABLE_LOGICAL_PYTHON', language: ['c', 'cpp'])
endif
# Find Elfutils. We search for libdw first because if libelf is installed but libdw isn't, the
# dependency('libdw') call will invoke the Elfutils subproject and call meson.override_dependency()
# for libelf, if we found libelf first this call causes a Meson setup failure.
# In all major distros you can't install libdw without libelf, so this shouldn't cause problems.
libdw_dep = dependency('libdw', version: '>=0.186', default_options: ['thread_safety=true'])
libelf_dep = dependency('libelf', version: '>=0.186', default_options: ['thread_safety=true'])
# Collect all the dependencies we require for HPCToolkit
boost_dep = dependency('boost', 'Boost', modules: ['graph'], version: '>=1.66.0')
bzip_dep = dependency('bzip2', 'BZip2', version: '>=1.0.0')
tbb_dep = dependency('tbb', 'TBB', components: ['tbb'])
tbb_malloc_dep = dependency('tbbmalloc', 'TBB', components: ['tbb', 'tbbmalloc'])
libunwind_dep = dependency('libunwind', version: ['>=1.6.2', '!=1.21'],
default_options: ['minidebuginfo=enabled', 'zlibdebuginfo=enabled'])
_xerces_c_ver = '>=3.2.2'
if meson.version().version_compare('>=1.4.0')
xerces_dep = dependency('xerces-c', version: _xerces_c_ver)
else
# Prior Meson versions don't provide versions for `method = cmake` wraps
xerces_dep = dependency('xerces-c')
if xerces_dep.type_name() != 'internal' and not xerces_dep.version().version_compare(_xerces_c_ver)
message('Dependency @0@ found @1@ but need: \'@2@\''.format(
xerces_dep.name(), xerces_dep.version(), _xerces_c_ver))
xerces_dep = dependency('xerces-c', method: 'system') # Force fallback to wrap
endif
endif
lzma_dep = dependency('liblzma', version: '>=5.2.0')
zlib_dep = dependency('zlib')
xxhash_dep = dependency('libxxhash', version: '>=0.8.1')
_yaml_cpp_ver = '>=0.6.2'
if meson.version().version_compare('>=1.4.0')
yaml_cpp_dep = dependency('yaml-cpp', version: _yaml_cpp_ver)
else
# Prior Meson versions don't provide versions for `method = cmake` wraps
yaml_cpp_dep = dependency('yaml-cpp')
if yaml_cpp_dep.type_name() != 'internal' and not yaml_cpp_dep.version().version_compare(_yaml_cpp_ver)
message('Dependency @0@ found @1@ but need: \'@2@\''.format(
yaml_cpp_dep.name(), yaml_cpp_dep.version(), _yaml_cpp_ver))
yaml_cpp_dep = dependency('yaml-cpp', method: 'system') # Force fallback to wrap
endif
endif
papi_dep = dependency('papi', required: get_option('papi'), version: '>=5.6.0')
papi_has_components = false
if papi_dep.found()
add_project_arguments('-DHPCRUN_SS_PAPI', language: ['c', 'cpp'])
papi_has_components = cc.has_header_symbol('papi.h', 'PAPI_get_eventset_component', dependencies: papi_dep)
if papi_has_components
add_project_arguments('-DHPCRUN_SS_PAPI_C_INTEL', language: ['c', 'cpp'])
endif
endif
# These dependencies don't ship any dependency files, so we use CMake by default and fall back to
# compiler checks as a robustness case. The final fallback to dependency() in each stanza is to
# provide a better error message and enable wrap fallbacks.
libiberty_dep = dependency('Libiberty', method: 'cmake', cmake_module_path: 'cmake', required: false)
if not libiberty_dep.found() and (cc.has_header('libiberty/demangle.h') or cc.has_header('demangle.h'))
_libiberty_lib = cc.find_library('iberty', required: false)
if _libiberty_lib.found()
libiberty_dep = declare_dependency(dependencies: _libiberty_lib, version: 'unknown')
endif
endif
if not libiberty_dep.found()
libiberty_dep = dependency('libiberty', method: 'system')
endif
xed_dep = dependency('', required: false)
if host_machine.cpu_family() in ['x86', 'x86_64']
xed_dep = dependency('Xed', method: 'cmake', cmake_module_path: 'cmake', version: '>=2022.08.11', required: false)
if not xed_dep.found() and (cc.has_header('xed/xed-interface.h') or cc.has_header('xed-interface.h'))
_xed_lib = cc.find_library('xed', required: false)
if _xed_lib.found()
_xed_ver = cc.get_define('XED_VERSION', prefix: '''
#if __has_include(<xed/xed-interface.h>)
#include <xed/xed-interface.h>
#else
#include <xed-interface.h>
#endif
''', dependencies: _xed_lib).strip('"')
if _xed_ver.startswith('v')
_xed_ver = _xed_ver.substring(1)
endif
xed_dep = declare_dependency(
dependencies: _xed_lib,
version: _xed_ver,
)
endif
endif
if not xed_dep.found()
xed_dep = dependency('xed', method: 'system', version: '>=2022.08.11')
endif
endif
if xed_dep.found()
if xed_dep.type_name() == 'internal'
assert(xed_dep.version() != 'undefined')
if xed_dep.version().version_compare('>=2023.08.21')
add_project_arguments('-DXED_DISPLACEMENT_INT64', language: ['c', 'cpp'])
endif
else
if (cc.has_header_symbol('xed/xed-operand-values-interface.h', 'xed_operand_values_get_branch_displacement_int64', dependencies: xed_dep) or
cc.has_header_symbol('xed-operand-values-interface.h', 'xed_operand_values_get_branch_displacement_int64', dependencies: xed_dep))
add_project_arguments('-DXED_DISPLACEMENT_INT64', language: ['c', 'cpp'])
endif
endif
endif
perfmon_dep = dependency('Perfmon2', method: 'cmake', cmake_module_path: 'cmake', version: '>=4.0', required: false)
if not perfmon_dep.found()
_perfmon_lib = cc.find_library('pfm', has_headers: ['perfmon/pfmlib.h'], required: false)
if _perfmon_lib.found()
perfmon_dep = declare_dependency(
dependencies: _perfmon_lib,
version: cc.get_define('LIBPFM_VERSION', prefix: '#include <perfmon/pfmlib.h>', dependencies: _perfmon_lib),
)
endif
endif
if not perfmon_dep.found()
perfmon_dep = dependency('libpfm', method: 'system', version: '>=4.0')
endif
# Dyninst ships config files, but up through 12.3 they aren't actually usable. We have a Find*
# script that fiddles with the exposed targets until it works, so if we can't get what we want
# directly use the find script to do so.
_dyninst_opts = ['openmp=enabled', 'debuginfod=disabled']
dyninst_dep = dependency('Dyninst',
components: ['parseAPI', 'instructionAPI', 'symtabAPI'],
modules: ['Dyninst::parseAPI', 'Dyninst::instructionAPI', 'Dyninst::symtabAPI'],
version: '>=12.3', required: false, default_options: _dyninst_opts)
if not dyninst_dep.found()
dyninst_dep = dependency('Dyninst', method: 'cmake',
cmake_module_path: 'cmake',
components: ['parseAPI', 'instructionAPI', 'symtabAPI'],
modules: ['Dyninst::parseAPI', 'Dyninst::instructionAPI', 'Dyninst::symtabAPI'],
version: '>=12.3', default_options: _dyninst_opts)
endif
# Set flags for features available in Dyninst
if dyninst_dep.type_name() == 'internal'
assert(dyninst_dep.version() != 'undefined')
if dyninst_dep.version().version_compare('>=13.0.0')
add_project_arguments('-DUSE_GET_CONTAINING_MODULE', language: ['c', 'cpp'])
if xed_dep.found()
add_project_arguments('-DUSE_XED_FOR_GAPS', language: ['c', 'cpp'])
endif
endif
if dyninst_dep.version().version_compare('>=11.0.0')
add_project_arguments('-DDYNINST_SUPPORTS_INTEL_GPU', language: ['c', 'cpp'])
endif
if dyninst_dep.version().version_compare('>=10.0.0')
add_project_arguments('-DDYNINST_USE_CUDA', language: ['c', 'cpp'])
endif
else
if xed_dep.found() and cpp.compiles('''
#include <InstructionDecoder.h>
void test() {
(void)Dyninst::InstructionAPI::InstructionDecoder::unknown_instruction::register_callback;
}
''',
name: 'Dyninst::InstructionAPI::InstructionDecoder has unknown_instruction::register_callback',
dependencies: dyninst_dep)
add_project_arguments('-DUSE_XED_FOR_GAPS', language: ['c', 'cpp'])
endif
if cpp.compiles('''
#include <Symtab.h>
void test() {
Dyninst::SymtabAPI::Symtab sym;
sym.getContainingModule(42);
}
''',
name: 'Dyninst::SymtabAPI::Symtab uses getContainingModule()',
dependencies: dyninst_dep)
add_project_arguments('-DUSE_GET_CONTAINING_MODULE', language: ['c', 'cpp'])
endif
if cpp.has_header_symbol('entryIDs.h', 'intel_gpu_op_general', dependencies: dyninst_dep)
add_project_arguments('-DDYNINST_SUPPORTS_INTEL_GPU', language: ['c', 'cpp'])
endif
if cpp.compiles('''
#include <Symtab.h>
void test() {
(void)Dyninst::Arch_cuda;
}
''',
name: 'Dyninst has Arch_cuda',
dependencies: dyninst_dep)
add_project_arguments('-DDYNINST_USE_CUDA', language: ['c', 'cpp'])
endif
endif
add_project_arguments('-DENABLE_OPENMP', '-DENABLE_OPENMP_SYMTAB', language: ['c', 'cpp'])
# Find rst2man, which is used to generate the man pages from source
rst2man = find_program('rst2man', 'rst2man.py', required: get_option('manpages'))
# Find MPI. We try different methods to handle the quirks of different systems.
mpi_dep = dependency('', required: false)
if get_option('hpcprof_mpi').allowed()
mpi_dep = dependency('MPI', language: 'cpp', required: false)
# Meson currently only properly supports OpenMPI. Search for other implementations via pkg-config.
if not mpi_dep.found()
mpi_dep = dependency('mpich-cxx', 'mvapich2', method: 'pkg-config', required: false)
endif
# Use a custom Python script to decode the MPI compiler's various flags
if not mpi_dep.found()
_mpicxx = find_program('mpicxx', 'mpic++', required: false)
if _mpicxx.found()
_decoded_mpi = run_command(python, files('meson/decode-mpi'), '--machine-readable', _mpicxx, check: false, capture: true)
if _decoded_mpi.returncode() == 0 and _decoded_mpi.stdout() != ''
_mpi_parts = _decoded_mpi.stdout().split('\0\0')
mpi_dep = declare_dependency(
compile_args: _mpi_parts[0].split('\0'),
link_args: _mpi_parts[1].split('\0'),
)
# Sanity check that the flags we get from the script do in fact work like they should.
assert(cpp.links('''
#include <mpi.h>
int main() {
MPI_Init(nullptr, nullptr);
int x = 42;
MPI_Bcast(&x, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
''', name: 'MPI sanity check', dependencies: mpi_dep))
endif
endif
endif
if not mpi_dep.found() and get_option('hpcprof_mpi').enabled()
error('hpcprof_mpi=enabled but unable to find MPI')
endif
endif
# For testing hpcprof-mpi, we also need mpiexec to actually launch the tool.
mpiexec = find_program(
'mpiexec',
required: get_option('hpcprof_mpi').disabled() ? get_option('hpcprof_mpi') : false,
)
if mpiexec.found()
mpiexec = [mpiexec.full_path(), '-host', 'localhost:1000', '-n']
else
_sh = find_program('sh')
mpiexec = [_sh.full_path(), '-c', 'exit 77']
endif
# Find support for CUDA performance monitoring
#
# NB: The CUDA dependency expects to be used with (implicit) `link_language: 'cuda'`, but we link
# it with `link_language: 'c'`. This causes link errors (`cannot find: -lcupti`) at build time.
# Fetching the dependency() before adding the 'cuda' language changes the search algorithm a bit and
# removes some fallbacks/checks, but it works when we link.
#
# There are a couple different Meson bugs and antifeatures at play here to cause this, but it works.
nvdisasm = find_program('nvdisasm', '/usr/local/cuda/bin/nvdisasm', required: get_option('cuda'))
cupti_dep = dependency('CUDA', modules: ['cupti'], required: get_option('cuda'), version: '>=11.2').partial_dependency(compile_args: true, includes: true)
if nvdisasm.found()
add_project_arguments('-DCUDA_NVDISASM_PATH="@0@"'.format(nvdisasm.full_path().replace('\\', '\\\\').replace('"', '\\"')), language: ['c', 'cpp'])
endif
if cupti_dep.found()
add_project_arguments(
'-DOPT_HAVE_CUDA',
'-DENABLE_CUDA',
'-DHPCRUN_SS_NVIDIA',
'-DCUPTI_INSTALL_PREFIX="/nonexistent"', # TODO
language: ['c', 'cpp'])
endif
if false # get_option('papi_cupti') # --enable-papi-c-cupti
add_project_arguments('-DHPCRUN_SS_PAPI_C_CUPTI', language: ['c', 'cpp'])
endif
# Note that we only need the CUDA language for the tests, so if cupti_dep wasn't found we don't
# enable this here either.
has_cuda = false
if cupti_dep.found()
has_cuda = add_languages('cuda', native: false, required: get_option('extended_tests'))
if has_cuda
# When we compile a CUDA kernel, we want to compile code for every available architecture the
# compiler can support, plus PTX.
cuda_cc = meson.get_compiler('cuda')
if cuda_cc.get_id() == 'nvcc'
_arches = 'All'
unstable_cuda = import('unstable-cuda')
message('Building for CUDA architectures: ' + ' '.join(unstable_cuda.nvcc_arch_readable(cuda_cc.version(), _arches)))
add_project_arguments(unstable_cuda.nvcc_arch_flags(cuda_cc.version(), _arches), language: 'cuda')
endif
endif
endif
if get_option('torch_monitor_dir') != ''
_torch_monitor_libdir = get_option('torch_monitor_dir') + '/lib'
torch_monitor_includedir = include_directories(get_option('torch_monitor_dir') + '/include')
torch_monitor_dep = cc.find_library('torch_monitor',
required: false,
dirs: [_torch_monitor_libdir],
has_headers: ['torch_monitor.h'],
header_include_directories: torch_monitor_includedir,
)
if torch_monitor_dep.found()
add_project_arguments(
'-DTORCH_MONITOR_ENABLE',
'-DHPCRUN_SS_TORCH_MONITOR',
language: ['c', 'cpp'])
endif
else
torch_monitor_includedir = include_directories('')
torch_monitor_dep = dependency('torch_monitor', required: false)
endif
# Find support for ROCm performance monitoring
hip_dep = dependency('hip', method: 'cmake', modules: ['hip::amdhip64'], required: get_option('rocm'), version: '>=5.1')
hsa_dep = dependency('hsa-runtime64', method: 'cmake', required: get_option('rocm'))
# Technically, ROCtracer and ROCprofiler don't ship any dependency files. It is extremely rare to
# see them outside of a complete "ROCm installation" that also includes hip and hsa (above), but for
# hardness we also support getting them via compiler checks.
roctracer_dep = dependency('', required: false)
if get_option('rocm').allowed()
roctracer_dep = dependency('ROCtracer', method: 'cmake', cmake_module_path: 'cmake', required: false)
if not roctracer_dep.found()
_roctracer_lib = cc.find_library('roctracer64', has_headers: ['roctracer/roctracer_hip.h'], required: false)
if _roctracer_lib.found()
roctracer_dep = declare_dependency(
dependencies: _roctracer_lib,
version: '@0@.@1@'.format(
cc.get_define('ROCTRACER_VERSION_MAJOR', prefix: '#include <roctracer/roctracer.h>', dependencies: _roctracer_lib),
cc.get_define('ROCTRACER_VERSION_MINOR', prefix: '#include <roctracer/roctracer.h>', dependencies: _roctracer_lib)
),
)
endif
endif
if not roctracer_dep.found()
roctracer_dep = dependency('ROCtracer', method: 'system', required: get_option('rocm'))
endif
endif
rocprofiler_dep = dependency('', required: false)
if get_option('rocm').allowed()
rocprofiler_dep = dependency('ROCprofiler', method: 'cmake', cmake_module_path: 'cmake', required: false)
if not rocprofiler_dep.found()
_rocprofiler_lib = cc.find_library('rocprofiler64', has_headers: ['rocprofiler/rocprofiler.h'], required: false)
if _rocprofiler_lib.found()
# As a very special case, we also need the path to a metrics.xml file in the ROCprofiler
# installation. We don't have any paths at hand to find it otherwise, so we require the user
# to specify the path via a project option. (We use an option to match the `c*_args` used for
# the compiler checks, usually one would add these options to a machine file.)
if get_option('rocprofiler_metrics_xml') == ''
error('-Drocprofiler_metrics_xml option must be set to use compiler fallback for ROCprofiler')
endif
_metrics_xml = fs.expanduser(get_option('rocprofiler_metrics_xml'))
if not fs.exists(_metrics_xml)
error(f'-Drocprofiler_metrics_xml set to an invalid path: no such file: @_metrics_xml@')
endif
rocprofiler_dep = declare_dependency(
dependencies: _rocprofiler_lib,
variables: {'metrics_xml': _metrics_xml},
version: '@0@.@1@'.format(
cc.get_define('ROCPROFILER_VERSION_MAJOR', prefix: '#include <rocprofiler/rocprofiler.h>', dependencies: _rocprofiler_lib),
cc.get_define('ROCPROFILER_VERSION_MINOR', prefix: '#include <rocprofiler/rocprofiler.h>', dependencies: _rocprofiler_lib)
),
)
endif
endif
if not rocprofiler_dep.found()
rocprofiler_dep = dependency('ROCprofiler', method: 'system', required: get_option('rocm'))
endif
endif
_rocm_subdeps = [rocprofiler_dep, roctracer_dep, hip_dep, hsa_dep]
rocm_dep = declare_dependency(
dependencies: _rocm_subdeps,
version: hip_dep.version(),
).partial_dependency(compile_args: true, includes: true)
rocprofiler_path = disabler()
foreach dep : _rocm_subdeps
if not dep.found()
rocm_dep = dependency('', required: false)
break
endif
endforeach
if rocm_dep.found()
add_project_arguments(
'-DUSE_ROCM',
'-DHPCRUN_SS_AMD',
language: ['c', 'cpp'])
if cc.has_member('roctracer_record_t', 'kernel_name', prefix: '#include <roctracer/roctracer_hip.h>', dependencies: rocm_dep)
add_project_arguments('-DHAVE_ROCM_ACTIVITY_KERNEL_NAME', language: ['c', 'cpp'])
endif
rocprofiler_path = fs.parent(rocprofiler_dep.get_variable(cmake: 'ROCprofiler_METRICS_XML', internal: 'metrics_xml'))
endif
if false # get_option('papi_rocm') # --enable-papi-c-rocm
add_project_arguments('-DHPCRUN_SS_PAPI_C_ROCM', language: ['c', 'cpp'])
endif
# Find HIP, the language used to test the ROCm support. Meson doesn't support it as a language, but
# we emulate Meson's basic behavior for languages.
# Similar to CUDA, we combine cpp_*args and hip_*args for the command lines here.
has_hip = false
if rocm_dep.found()
_hip_cc = find_program('hip', 'hipcc', required: get_option('extended_tests'))
has_hip = _hip_cc.found()
if has_hip
# For compilation:
hip = generator(
_hip_cc,
arguments: [get_option('cpp_args'), get_option('hip_args'), '-MD', '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@', '-o', '@OUTPUT@', '-c', '@INPUT@'],
output: '@PLAINNAME@.o',
depfile: '@PLAINNAME@.o.d',
)
# For linking (to be used with custom_target()):
hip_ld = [_hip_cc, get_option('cpp_link_args'), get_option('hip_link_args'), '-o', '@OUTPUT0@', '@INPUT@']
endif
endif
# Find OpenCL support. We only need the headers, but there are many ways to acquire them.
opencl_dep = dependency('', required: false)
if get_option('opencl').allowed()
_opencl_ver = '>=2.1'
# - As of OpenCL >=2023.02.06 (found in Debian >=12, Ubuntu >=23.04, and Fedora) the headers can
# be accessed via pkg-config as OpenCL-Headers.pc.
# - Before that, since OpenCL >=2020.12.18 (found in Debian >=10, Ubuntu >=20.04, and RHEL >=9)
# the headers can be accessed via CMake as OpenCLHeaders-config.cmake.
opencl_dep = dependency('OpenCL-Headers', 'OpenCLHeaders', required: false, version: _opencl_ver)
if not opencl_dep.found()
# For older distros, CMake >=3.1 ships a FindOpenCL.cmake script, but it requires a full OpenCL
# installation and not just the headers. If that's all we got, use it and cut out the link
# flags so we only get the headers.
opencl_dep = (dependency('OpenCL', required: false, version: _opencl_ver)
.partial_dependency(includes: true, compile_args: true))
endif
if not opencl_dep.found() and cc.has_header('CL/cl.h', required: false)
# For Spack builds and partial system installations, we also support the case where the header
# is already available on the standard include paths.
opencl_dep = declare_dependency()
endif
if not opencl_dep.found()
# Fall back to dependency() to get a good error message and enable wrap fallbacks.
opencl_dep = dependency('OpenCL-Headers', required: get_option('opencl'))
endif
endif
if opencl_dep.found()
add_project_arguments('-DENABLE_OPENCL', '-DHPCRUN_SS_OPENCL', language: ['c', 'cpp'])
endif
# Find a full OpenCL installation. We need this to run some of the tests.
opencl_full_dep = dependency('', required: false)
if opencl_dep.found()
opencl_full_dep = dependency('OpenCL', required: get_option('extended_tests'), version: _opencl_ver)
endif
# Find support for Intel performance monitoring via Level Zero.
level0_dep = dependency('', required: false)
if get_option('level0').allowed()
level0_dep = dependency('level-zero', required: false, version: '>=1.0')
if level0_dep.found() and level0_dep.type_name() != 'internal'
# Level Zero ships a pkg-config file, but it's untrustworthy due to a bug
# present since 1.0: https://github.com/oneapi-src/level-zero/issues/131.
# We try to reconstruct what the library path "should have been" here, using
# our own configuration as a reference.
#
# Note that we *always* manipulate the library path here. Compiler checks
# would succeed if Level Zero is also installed at the system level, so we
# can't trust them to determine if the Level Zero pkg-config file is borked.
_l0_libdir = level0_dep.get_variable('libdir', default_value: '')
_l0_prefix = level0_dep.get_variable('prefix', default_value: '')
if _l0_libdir != '' and _l0_prefix != ''
_l0_new_libdir = _l0_prefix / get_option('libdir')
if _l0_libdir != _l0_new_libdir and fs.exists(_l0_new_libdir)
# We use find_library here to produce an rpath for the build tree.
_l0_lib = cc.find_library('ze_loader', dirs: [_l0_libdir, _l0_new_libdir], required: false)
if _l0_lib.found()
message('Replacing Level Zero libdir: \'@0@\' -> \'@1@\''.format(_l0_libdir, _l0_new_libdir))
level0_dep = declare_dependency(
dependencies: [level0_dep, _l0_lib],
link_args: ['-L@0@'.format(_l0_new_libdir)],
version: level0_dep.version(),
)
endif
endif
endif
# Sanity-check the modified dependency before calling it done.
if not cc.links('''
#include <ze_api.h>
int main() {
zeInit(0);
return 0;
}
''', name: 'Level Zero sanity check', dependencies: level0_dep)
error('''Failed to reconstruct usable Level Zero dependency! This could be for many reasons, consider:
- Checking meson-logs/meson-log.txt for the compiler error, and
- Manually fixing the libdir variable in the pkg-config file shipped by Level Zero (pkg-config --path level-zero), or
- Appending the flags to use Level Zero to (c|cpp)(_link)?_args, or
- Removing Level Zero from your PKG_CONFIG_PATH.''')
endif
endif
if not level0_dep.found()
# To work around certain incomplete modulefiles, we also support the case
# where the library and headers are already available in compiler flags.
_l0_lib = cc.find_library('ze_loader', has_headers: ['ze_api.h'], required: false)
if _l0_lib.found()
_l0_ver = cc.compute_int('ZE_API_VERSION_CURRENT',
prefix: '#include <ze_api.h>', dependencies: _l0_lib,
low: 0x10000, guess: 0x10008, high: 0x30000)
level0_dep = declare_dependency(
dependencies: _l0_lib,
version: '@0@.@1@'.format(_l0_ver / 0x10000, _l0_ver % 0x10000),
)
endif
endif
if not level0_dep.found()
# Fall back to dependency() to get a good error message and enable wrap fallbacks
level0_dep = dependency('level-zero', required: get_option('level0'), version: '>=1.0')
endif
endif
if level0_dep.found()
add_project_arguments(
'-DUSE_LEVEL0',
'-DHPCRUN_SS_LEVEL0',
language: ['c', 'cpp'])
endif
# Find support for instruction level collection, which requires IGC and IGA
_gtpin_f = get_option('gtpin').require(level0_dep.found(), error_message: 'gtpin is only available with level0')
igc_dep = dependency('', required: false)
if _gtpin_f.allowed()
igc_dep = dependency('igc-opencl', required: false)
if not igc_dep.found()
# To work around certain incomplete deployments/modulefiles, we also support
# the case where the headers are already available by full path in the
# compiler flags. In this case IGC_INCLUDE_FULL_PATH is #defined and
# downstream sources #include a longer header path when this is set.
if (cc.has_header('igc/igc.opencl.h')
and cc.has_header('igc/ocl_igc_shared/executable_format/patch_list.h')
and cc.has_header('igc/ocl_igc_shared/device_enqueue/DeviceEnqueueInternalTypes.h'))
igc_dep = declare_dependency(
compile_args: ['-DIGC_INCLUDE_FULL_PATH'],
version: 'unknown',
)
endif
endif
if not igc_dep.found()
# Fall back to dependency() to get a good error message and enable wrap fallbacks
igc_dep = dependency('igc-opencl', required: _gtpin_f)
endif
endif
if igc_dep.found()
add_project_arguments('-DENABLE_IGC', language: ['c', 'cpp'])
endif
iga_dep = dependency('', required: false)
if _gtpin_f.allowed()
# IGA doesn't ship any dependency files, so we use a custom CMake script for the usual case.
iga_dep = dependency('IGA', method: 'cmake', cmake_module_path: 'cmake', required: false)
if not iga_dep.found()
# To work around certain incomplete modulefiles, we also support the case where the
# headers and library are already available in the compiler flags.
_iga_lib = cc.find_library('iga64', has_headers: ['iga/iga.h'], required: false)
if _iga_lib.found()
iga_dep = declare_dependency(dependencies: _iga_lib, version: 'unknown')
endif
endif
if not iga_dep.found()
# Fall back to dependency() to get a good error message and enable wrap fallbacks
iga_dep = dependency('IGA', method: 'cmake', cmake_module_path: 'cmake', required: _gtpin_f)
endif
endif
# GTPin is a snowflake of a case, it only comes in a binary tarball with non-standard names for
# all the paths like `Include` and `Lib`. This means we can't use CMake to find it, the user
# *has* to provide it through `cpp_args` and `cpp_link_args`.
# But since that's way too much trouble in most cases, we also support pulling it from a wrap,
# when the feature is explicitly requested.
gtpin_dep = cpp.find_library('gtpin', has_headers: ['api/gtpin_api.h', 'ged.h'], required: false)
if gtpin_dep.found()
# Wrap the result of find_library() as a dependency so we can query the nonexistent version later
gtpin_dep = declare_dependency(dependencies: gtpin_dep, version: 'unknown')
else
gtpin_dep = dependency('gtpin', method: 'system', required: get_option('gtpin'))
endif
if gtpin_dep.found()
add_project_arguments(
'-DENABLE_GTPIN',
'-DUSE_GTPIN',
language: ['c', 'cpp'])
endif
# Find SYCL, the language we use to test Level Zero support. Meson doesn't support it as a language,
# but we emulate Meson's basic behavior for languages.
# Similar to CUDA, we combine cpp_*args and hip_*args for the command lines here.
has_sycl = false
if level0_dep.found() and get_option('extended_tests').allowed()
# Path 1: If "sycl" has been registered as a binary in the machine file, use that.
_sycl_cc = find_program('sycl', required: false)
_sycl_args = []
_sycl_link_args = []
has_sycl = _sycl_cc.found()
sycl_is_cpp = false
# Path 2: If the C++ compiler supports compiling SYCL code, possibly with an extra flag, use that.
# This path is a bit different because we use Meson's native C++ support instead of implementing
# our own mess on top of things.
if not has_sycl
foreach sycl_dep : [
declare_dependency(
compile_args: [get_option('sycl_args')],
link_args: [get_option('sycl_link_args')],
),
declare_dependency(
compile_args: ['-fsycl', get_option('sycl_args')],
link_args: ['-fsycl', get_option('sycl_link_args')],
),
]
if cpp.compiles(files('meson/sanity.sycl.cpp'), dependencies: sycl_dep)
has_sycl = true
sycl_is_cpp = true
break
endif
endforeach
endif
# Path 3: Search for a known compiler that supports SYCL. These logics are tuned based on the
# history and quirks of the compilers being attempted.
if not has_sycl
_icpx = find_program('icpx', required: false)
if _icpx.found()
run_command(python, files('meson/in-tmpdir.py'),
_icpx, '-fsycl', '-c', '-o', 'sanity.sycl.cpp.o', files('meson/sanity.sycl.cpp'),
check: true)
_sycl_cc = _icpx
_sycl_args = ['-fsycl']
_sycl_link_args = ['-fsycl']
has_sycl = true
endif
endif
if not has_sycl
_dpcpp = find_program('dpcpp', required: false)
if _dpcpp.found()
run_command(python, files('meson/in-tmpdir.py'),
_dpcpp, '-c', '-o', 'sanity.sycl.cpp.o', files('meson/sanity.sycl.cpp'),
check: true)
_sycl_cc = _dpcpp
_sycl_args = []
_sycl_link_args = []
has_sycl = true
endif
endif
# Regardless of what route we take, if we need SYCL and don't have it, error out.
if get_option('extended_tests').enabled() and not has_sycl
error('Unable to find a SYCL compiler!')
endif
if has_sycl and not sycl_is_cpp
# For compilation:
sycl = generator(
_sycl_cc,
arguments: [_sycl_args, get_option('cpp_args'), get_option('sycl_args'), '-MD', '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@', '-o', '@OUTPUT@', '-c', '@INPUT@'],
output: '@PLAINNAME@.o',
depfile: '@PLAINNAME@.o.d',
)
# For linking (to be used with custom_target()):
sycl_ld = [_sycl_cc, _sycl_link_args, get_option('cpp_link_args'), get_option('sycl_link_args'), '-o', '@OUTPUT0@', '@INPUT@']
endif
endif
# Collect features from the compiler itself
math_dep = cc.find_library('m')
threads_dep = dependency('threads')
openmp_dep = dependency('openmp')
dl_dep = dependency('dl')
rt_dep = cc.find_library('rt')
_fs_code = '''
#include <filesystem>
int main() {
std::filesystem::path p("/foo/bar");
std::filesystem::remove(p);
return 0;
}
'''
if not cpp.links(_fs_code)
_found = false
foreach trial : ['stdc++fs', 'c++fs']
_dep = cpp.find_library(trial, required: false)
if _dep.found()
add_project_dependencies(_dep, language: ['c', 'cpp'])
_found = true
break
endif
endforeach
if not _found
error('Unable to find suitable flags for std::filesystem')
endif
endif
# If Valgrind annotations aren't requested, inject an option to disable them.
if not get_option('valgrind_annotations')
add_project_arguments('-DNVALGRIND', language: ['c', 'cpp'])
endif
# Enable a handful of useful non-default warnings
foreach lang : ['c', 'cpp']
_warnings = meson.get_compiler(lang).get_supported_arguments(
'-Wstack-usage=65536', # Warn if any functions use a lot or unbounded stack
)
set_variable(f'_@lang@_warnings', _warnings)
add_project_arguments(_warnings, language: lang)
endforeach
# Expose the results of various compile-time checks
add_project_arguments('-DSIZEOF_VOIDP=@0@'.format(cc.compute_int('sizeof(void*)', low: 1, high: 64, guess: 8)), language: ['c', 'cpp'])
if host_machine.cpu_family() == 'x86'
add_project_arguments('-DHOST_CPU_x86', language: ['c', 'cpp'])
elif host_machine.cpu_family() == 'x86_64'
add_project_arguments('-DHOST_CPU_x86_64', language: ['c', 'cpp'])
elif host_machine.cpu_family() == 'ia64'
add_project_arguments('-DHOST_CPU_IA64', language: ['c', 'cpp'])
elif host_machine.cpu_family() == 'ppc64'
add_project_arguments('-DHOST_CPU_PPC', language: ['c', 'cpp'])
elif host_machine.cpu_family() == 'aarch64'
add_project_arguments('-DHOST_CPU_ARM64', language: ['c', 'cpp'])
endif
if host_machine.endian() == 'big'
add_project_arguments('-DHOST_BIG_ENDIAN', language: ['c', 'cpp'])
elif host_machine.endian() == 'little'
add_project_arguments('-DHOST_LITTLE_ENDIAN', language: ['c', 'cpp'])
endif
if cc.has_header_symbol('byteswap.h', 'bswap_64')
add_project_arguments('-DUSE_SYSTEM_BYTESWAP', language: ['c', 'cpp'])
endif
if cc.has_header_symbol('linux/futex.h', 'SYS_futex', prefix: ['#include <sys/syscall.h>', '#include <unistd.h>'])
add_project_arguments('-DHAVE_FUTEX_H', language: ['c', 'cpp'])
endif
if cc.has_header_symbol('time.h', 'CLOCK_REALTIME') and cc.has_header_symbol('signal.h', 'SIGEV_THREAD_ID')
add_project_arguments('-DENABLE_CLOCK_REALTIME', language: ['c', 'cpp'])
if cc.has_header_symbol('time.h', 'CLOCK_THREAD_CPUTIME_ID')
add_project_arguments('-DENABLE_CLOCK_CPUTIME', language: ['c', 'cpp'])
endif
endif
has_perf_events = cc.has_type('struct perf_event_attr', prefix: ['#include <linux/perf_event.h>', '#include <linux/hw_breakpoint.h>', '#include <sys/syscall.h>', '#include <unistd.h>'])
if has_perf_events
add_project_arguments('-DHPCRUN_SS_LINUX_PERF', language: ['c', 'cpp'])
endif
# Inject some strings into the build
add_project_arguments(
'-DHPCTOOLKIT_INSTALL_PREFIX="@0@"'.format(get_option('prefix').replace('\\', '\\\\').replace('"', '\\"')),
language: ['c', 'cpp'])
subdir('src')
subdir('lib')
subdir('doc')
subdir('tests')
# Install a few files from this directory
install_data(
'README.md',
'README.Acknowledgments',
'README.Install',
'README.ReleaseNotes',
'LICENSE',
install_dir: docdir,
install_tag: 'docs',
)