]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/testsuite/lib/libgomp.exp
libgomp: Add offload_device_gcn check, add requires-4a.c test
[thirdparty/gcc.git] / libgomp / testsuite / lib / libgomp.exp
1 # Damn dejagnu for not having proper library search paths for load_lib.
2 # We have to explicitly load everything that gcc-dg.exp wants to load.
3
4 proc load_gcc_lib { filename } {
5 global srcdir loaded_libs
6
7 load_file $srcdir/../../gcc/testsuite/lib/$filename
8 set loaded_libs($filename) ""
9 }
10
11 load_lib dg.exp
12
13 # Required to use gcc-dg.exp - however, the latter should NOT be
14 # loaded until ${tool}_target_compile is defined since it uses that
15 # to determine default LTO options.
16
17 load_gcc_lib multiline.exp
18 load_gcc_lib prune.exp
19 load_gcc_lib target-libpath.exp
20 load_gcc_lib wrapper.exp
21 load_gcc_lib target-supports.exp
22 load_gcc_lib target-utils.exp
23 load_gcc_lib gcc-defs.exp
24 load_gcc_lib timeout.exp
25 load_gcc_lib file-format.exp
26 load_gcc_lib target-supports-dg.exp
27 load_gcc_lib scanasm.exp
28 load_gcc_lib scandump.exp
29 load_gcc_lib scanlang.exp
30 load_gcc_lib scanrtl.exp
31 load_gcc_lib scansarif.exp
32 load_gcc_lib scantree.exp
33 load_gcc_lib scanltranstree.exp
34 load_gcc_lib scanoffload.exp
35 load_gcc_lib scanoffloadtree.exp
36 load_gcc_lib scanoffloadrtl.exp
37 load_gcc_lib scanipa.exp
38 load_gcc_lib scanwpaipa.exp
39 load_gcc_lib timeout-dg.exp
40 load_gcc_lib torture-options.exp
41 load_gcc_lib fortran-modules.exp
42
43 # Try to load a test support file, built during libgomp configuration.
44 load_file libgomp-test-support.exp
45
46 set dg-do-what-default run
47
48 #
49 # GCC_UNDER_TEST is the compiler under test.
50 #
51
52 set libgomp_compile_options ""
53
54 #
55 # libgomp_init
56 #
57
58 if [info exists TOOL_OPTIONS] {
59 set multilibs [get_multilibs $TOOL_OPTIONS]
60 } else {
61 set multilibs [get_multilibs]
62 }
63
64 proc libgomp_init { args } {
65 global srcdir blddir objdir tool_root_dir
66 global libgomp_initialized
67 global tmpdir
68 global blddir
69 global gluefile wrap_flags
70 global ALWAYS_CFLAGS
71 global CFLAGS
72 global TOOL_EXECUTABLE TOOL_OPTIONS
73 global GCC_UNDER_TEST
74 global TESTING_IN_BUILD_TREE
75 global target_triplet
76 global always_ld_library_path
77
78 set blddir [lookfor_file [get_multilibs] libgomp]
79
80 # We set LC_ALL and LANG to C so that we get the same error
81 # messages as expected.
82 setenv LC_ALL C
83 setenv LANG C
84
85 # Many hosts now default to a non-ASCII C locale, however, so
86 # they can set a charset encoding here if they need.
87 if { [ishost "*-*-cygwin*"] } {
88 setenv LC_ALL C.ASCII
89 setenv LANG C.ASCII
90 }
91
92 if ![info exists GCC_UNDER_TEST] then {
93 if [info exists TOOL_EXECUTABLE] {
94 set GCC_UNDER_TEST $TOOL_EXECUTABLE
95 } else {
96 set GCC_UNDER_TEST "[find_gcc]"
97 }
98 }
99
100 if ![info exists tmpdir] {
101 set tmpdir "/tmp"
102 }
103
104 if [info exists gluefile] {
105 unset gluefile
106 }
107
108 if {![info exists CFLAGS]} {
109 set CFLAGS ""
110 }
111
112 # Locate libgcc.a so we don't need to account for different values of
113 # SHLIB_EXT on different platforms
114 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
115 if {$gccdir != ""} {
116 set gccdir [file dirname $gccdir]
117 }
118
119 # Compute what needs to be put into LD_LIBRARY_PATH
120 set always_ld_library_path ".:${blddir}/.libs"
121
122 # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
123 # Intel MIC offloading testing.
124 global offload_plugins
125 if { [string match "*,intelmic,*" ",$offload_plugins,"] } {
126 append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
127 append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
128 # libstdc++ is required by liboffloadmic
129 append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
130 # libgcc_s is required by libstdc++
131 append always_ld_library_path ":${blddir}/../libgcc"
132 }
133
134 global offload_additional_lib_paths
135 if { $offload_additional_lib_paths != "" } {
136 append always_ld_library_path "${offload_additional_lib_paths}"
137 }
138
139 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
140 if {$gccdir != ""} {
141 # Add AIX pthread directory first.
142 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
143 append always_ld_library_path ":${gccdir}/pthread"
144 }
145 append always_ld_library_path ":${gccdir}"
146 set compiler [lindex $GCC_UNDER_TEST 0]
147
148 if { [is_remote host] == 0 && [which $compiler] != 0 } {
149 foreach i "[exec $compiler --print-multi-lib]" {
150 set mldir ""
151 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
152 set mldir [string trimright $mldir "\;@"]
153 if { "$mldir" == "." } {
154 continue
155 }
156 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
157 append always_ld_library_path ":${gccdir}/${mldir}"
158 }
159 }
160 }
161 }
162
163 set ALWAYS_CFLAGS ""
164 if { $blddir != "" } {
165 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
166 # targets that use libgomp.a%s in their specs need a -B option
167 # for uninstalled testing.
168 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
169 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
170 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
171 }
172 # The top-level include directory, for gomp-constants.h.
173 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
174 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
175
176 # For build-tree testing, also consider the library paths used for builing.
177 # For installed testing, we assume all that to be provided in the sysroot.
178 if { $blddir != "" } {
179 # The `-fopenacc' and `-fopenmp' options imply `-pthread', and
180 # that implies `-latomic' on some hosts, so wire in libatomic
181 # build directories.
182 if [ishost "riscv*-*-linux*"] {
183 set shlib_ext [get_shlib_extension]
184 set atomic_library_path "${blddir}/../libatomic/.libs"
185 if { [file exists "${atomic_library_path}/libatomic.a"]
186 || [file exists \
187 "${atomic_library_path}/libatomic.${shlib_ext}"] } {
188 lappend ALWAYS_CFLAGS \
189 "additional_flags=-L${atomic_library_path}"
190 append always_ld_library_path ":${atomic_library_path}"
191 }
192 }
193 }
194
195 # We use atomic operations in the testcases to validate results.
196 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
197 && [check_effective_target_ia32]
198 && ![check_effective_target_cas_char] } {
199 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
200 }
201
202 if [istarget *-*-darwin*] {
203 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
204 }
205
206 if [istarget sparc*-*-*] {
207 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
208 }
209
210 if [info exists TOOL_OPTIONS] {
211 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
212 }
213
214 # Make sure that lines are not wrapped. That can confuse the
215 # error-message parsing machinery.
216 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
217
218 # Disable caret
219 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
220
221 # Disable color diagnostics
222 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
223
224 # Help GCC to find offload compilers' 'mkoffload'.
225 global offload_additional_options
226 if { $offload_additional_options != "" } {
227 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
228 }
229
230 # Tell warning from error diagnostics. This fits for C, C++, and Fortran.
231 global gcc_warning_prefix
232 set gcc_warning_prefix "\[Ww\]arning:"
233 global gcc_error_prefix
234 set gcc_error_prefix "(\[Ff\]atal )?\[Ee\]rror:"
235 }
236
237 #
238 # libgomp_target_compile -- compile a source file
239 #
240
241 proc libgomp_target_compile { source dest type options } {
242 global blddir
243 global libgomp_compile_options
244 global gluefile wrap_flags
245 global ALWAYS_CFLAGS
246 global GCC_UNDER_TEST
247 global lang_test_file
248 global lang_library_path
249 global lang_link_flags
250 global lang_include_flags
251 global lang_source_re
252
253 if { [info exists lang_test_file] } {
254 if { $blddir != "" } {
255 # Some targets use libgfortran.a%s in their specs, so they need
256 # a -B option for uninstalled testing.
257 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
258 lappend options "ldflags=-L${blddir}/${lang_library_path}"
259 }
260 lappend options "ldflags=${lang_link_flags}"
261 if { [info exists lang_include_flags] \
262 && [regexp ${lang_source_re} ${source}] } {
263 lappend options "additional_flags=${lang_include_flags}"
264 }
265 }
266
267 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
268 lappend options "libs=${gluefile}"
269 lappend options "ldflags=${wrap_flags}"
270 }
271
272 lappend options "additional_flags=[libio_include_flags]"
273 lappend options "timeout=[timeout_value]"
274 lappend options "compiler=$GCC_UNDER_TEST"
275
276 set options [concat $libgomp_compile_options $options]
277
278 if [info exists ALWAYS_CFLAGS] {
279 set options [concat "$ALWAYS_CFLAGS" $options]
280 }
281
282 set options [dg-additional-files-options $options $source]
283
284 set result [target_compile $source $dest $type $options]
285
286 return $result
287 }
288
289 proc libgomp_option_help { } {
290 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
291 }
292
293 proc libgomp_option_proc { option } {
294 if [regexp "^--additional_options," $option] {
295 global libgomp_compile_options
296 regsub "--additional_options," $option "" option
297 foreach x [split $option ","] {
298 lappend libgomp_compile_options "additional_flags=$x"
299 }
300 return 1
301 } else {
302 return 0
303 }
304 }
305
306 # Translate offload target to OpenACC device type. Return the empty string if
307 # not supported, and 'host' for offload target 'disable'.
308 proc offload_target_to_openacc_device_type { offload_target } {
309 switch -glob $offload_target {
310 amdgcn* {
311 return "radeon"
312 }
313 disable {
314 return "host"
315 }
316 *-intelmic* {
317 return ""
318 }
319 nvptx* {
320 return "nvidia"
321 }
322 default {
323 error "Unknown offload target: $offload_target"
324 }
325 }
326 }
327
328 # Return 1 if compiling for the specified offload target
329 # Takes -foffload=... into account by checking OFFLOAD_TARGET_NAMES=
330 # in the -v compiler output.
331 proc libgomp_check_effective_target_offload_target { target_name } {
332 # Consider all actual options, including the flags passed to
333 # 'gcc-dg-runtest', or 'gfortran-dg-runtest' (see the 'libgomp.*/*.exp'
334 # files; in particular, '-foffload', 'libgomp.oacc-*/*.exp'), which don't
335 # get passed on to 'check_effective_target_*' functions. (Not caching the
336 # result due to that.)
337 set options [list "additional_flags=[concat "-v" [current_compiler_flags]]"]
338 # Instead of inspecting command-line options, look what the compiler driver
339 # decides. This is somewhat modelled after
340 # 'gcc/testsuite/lib/target-supports.exp:check_configured_with'.
341 set gcc_output [libgomp_target_compile "" "" "none" $options]
342 if [regexp "(?n)^OFFLOAD_TARGET_NAMES=(.*)" $gcc_output dummy gcc_offload_targets] {
343 verbose "compiling for offload targets: $gcc_offload_targets"
344 return [string match "*:$target_name*:*" ":$gcc_offload_targets:"]
345 }
346
347 verbose "not compiling for $target_name offload target"
348 return 0
349 }
350
351 # Return 1 if compiling for any offload target.
352 proc check_effective_target_offload_target_any { } {
353 return [libgomp_check_effective_target_offload_target ""]
354 }
355
356 # Return 1 if compiling for offload target nvptx.
357 proc check_effective_target_offload_target_nvptx { } {
358 return [libgomp_check_effective_target_offload_target "nvptx"]
359 }
360
361 # Return 1 if compiling for offload target amdgcn
362 proc check_effective_target_offload_target_amdgcn { } {
363 return [libgomp_check_effective_target_offload_target "amdgcn"]
364 }
365
366 # Return 1 if offload device is available.
367 proc check_effective_target_offload_device { } {
368 return [check_runtime_nocache offload_device_available_ {
369 #include <omp.h>
370 int main ()
371 {
372 int a;
373 #pragma omp target map(from: a)
374 a = omp_is_initial_device ();
375 return a;
376 }
377 } ]
378 }
379
380 # Return 1 if offload device is available and it has non-shared address space.
381 proc check_effective_target_offload_device_nonshared_as { } {
382 return [check_runtime_nocache offload_device_nonshared_as {
383 int main ()
384 {
385 int a = 8;
386 #pragma omp target map(to: a)
387 a++;
388 return a != 8;
389 }
390 } ]
391 }
392
393 # Return 1 if offload device is available and it has shared address space.
394 proc check_effective_target_offload_device_shared_as { } {
395 return [check_runtime_nocache offload_device_shared_as {
396 int main ()
397 {
398 int x = 10;
399 #pragma omp target map(to: x)
400 x++;
401 return x == 10;
402 }
403 } ]
404 }
405
406 # Return 1 if using nvptx offload device.
407 proc check_effective_target_offload_device_nvptx { } {
408 return [check_runtime_nocache offload_device_nvptx {
409 #include <omp.h>
410 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
411 int main ()
412 {
413 return !on_device_arch_nvptx ();
414 }
415 } ]
416 }
417
418 # Return 1 if using a GCN offload device.
419 proc check_effective_target_offload_device_gcn { } {
420 return [check_runtime_nocache offload_device_gcn {
421 #include <omp.h>
422 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
423 int main ()
424 {
425 return !on_device_arch_gcn ();
426 }
427 } ]
428 }
429
430 # Return 1 if at least one Nvidia GPU is accessible.
431
432 proc check_effective_target_openacc_nvidia_accel_present { } {
433 return [check_runtime openacc_nvidia_accel_present {
434 #include <openacc.h>
435 int main () {
436 return !(acc_get_num_devices (acc_device_nvidia) > 0);
437 }
438 } "" ]
439 }
440
441 # Return 1 if at least one Nvidia GPU is accessible, and the OpenACC 'nvidia'
442 # device type is selected.
443
444 proc check_effective_target_openacc_nvidia_accel_selected { } {
445 if { ![check_effective_target_openacc_nvidia_accel_present] } {
446 return 0;
447 }
448 global openacc_device_type
449 return [string match "nvidia" $openacc_device_type]
450 }
451
452 # Return 1 if using Intel MIC offload device.
453 proc check_effective_target_offload_device_intel_mic { } {
454 return [check_runtime_nocache offload_device_intel_mic {
455 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
456 int main ()
457 {
458 return !on_device_arch_intel_mic ();
459 }
460 } ]
461 }
462
463 # Return 1 if any Intel MIC offload device is available.
464 proc check_effective_target_offload_device_any_intel_mic { } {
465 return [check_runtime_nocache offload_device_any_intel_mic {
466 #include "testsuite/libgomp.c-c++-common/on_device_arch.h"
467 int main ()
468 {
469 return !any_device_arch_intel_mic ();
470 }
471 } ]
472 }
473
474 # Return 1 if the OpenACC 'host' device type is selected.
475
476 proc check_effective_target_openacc_host_selected { } {
477 global openacc_device_type
478 return [string match "host" $openacc_device_type]
479 }
480
481 # Return 1 if at least one AMD GPU is accessible.
482
483 proc check_effective_target_openacc_radeon_accel_present { } {
484 return [check_runtime openacc_radeon_accel_present {
485 #include <openacc.h>
486 int main () {
487 return !(acc_get_num_devices (acc_device_radeon) > 0);
488 }
489 } "" ]
490 }
491
492 # Return 1 if at least one AMD GPU is accessible, and the OpenACC 'radeon'
493 # device type is selected.
494
495 proc check_effective_target_openacc_radeon_accel_selected { } {
496 if { ![check_effective_target_openacc_radeon_accel_present] } {
497 return 0;
498 }
499 global openacc_device_type
500 return [string match "radeon" $openacc_device_type]
501 }
502
503 # Return 1 if cuda.h and -lcuda are available.
504
505 proc check_effective_target_openacc_cuda { } {
506 return [check_no_compiler_messages openacc_cuda executable {
507 #include <cuda.h>
508 int main() {
509 CUdevice dev;
510 CUresult r = cuDeviceGet (&dev, 0);
511 if (r != CUDA_SUCCESS)
512 return 1;
513 return 0;
514 } } "-lcuda" ]
515 }
516
517 # Return 1 if cublas_v2.h and -lcublas are available.
518
519 proc check_effective_target_openacc_cublas { } {
520 return [check_no_compiler_messages openacc_cublas executable {
521 #include <cuda.h>
522 #include <cublas_v2.h>
523 int main() {
524 cublasStatus_t s;
525 cublasHandle_t h;
526 CUdevice dev;
527 CUresult r = cuDeviceGet (&dev, 0);
528 if (r != CUDA_SUCCESS)
529 return 1;
530 s = cublasCreate (&h);
531 if (s != CUBLAS_STATUS_SUCCESS)
532 return 1;
533 return 0;
534 } } "-lcuda -lcublas" ]
535 }
536
537 # Return 1 if cuda_runtime_api.h and -lcudart are available.
538
539 proc check_effective_target_openacc_cudart { } {
540 return [check_no_compiler_messages openacc_cudart executable {
541 #include <cuda.h>
542 #include <cuda_runtime_api.h>
543 int main() {
544 cudaError_t e;
545 int devn;
546 CUdevice dev;
547 CUresult r = cuDeviceGet (&dev, 0);
548 if (r != CUDA_SUCCESS)
549 return 1;
550 e = cudaGetDevice (&devn);
551 if (e != cudaSuccess)
552 return 1;
553 return 0;
554 } } "-lcuda -lcudart" ]
555 }