]> gcc.gnu.org Git - gcc.git/blame - libgomp/testsuite/lib/libgomp.exp
Remove build dependence on HSA run-time
[gcc.git] / libgomp / testsuite / lib / libgomp.exp
CommitLineData
516f1ed8
UB
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
4proc 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
11load_lib dg.exp
1ef3b58e
IS
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
9e531d37 17load_gcc_lib multiline.exp
1ef3b58e
IS
18load_gcc_lib prune.exp
19load_gcc_lib target-libpath.exp
20load_gcc_lib wrapper.exp
3b41b583
KT
21load_gcc_lib target-supports.exp
22load_gcc_lib target-utils.exp
1ef3b58e
IS
23load_gcc_lib gcc-defs.exp
24load_gcc_lib timeout.exp
1ef3b58e 25load_gcc_lib file-format.exp
516f1ed8
UB
26load_gcc_lib target-supports-dg.exp
27load_gcc_lib scanasm.exp
28load_gcc_lib scandump.exp
29load_gcc_lib scanrtl.exp
30load_gcc_lib scantree.exp
31load_gcc_lib scanipa.exp
d4038ca2 32load_gcc_lib timeout-dg.exp
1ef3b58e 33load_gcc_lib torture-options.exp
6a26a74d 34load_gcc_lib fortran-modules.exp
516f1ed8 35
41dbbb37
TS
36# Try to load a test support file, built during libgomp configuration.
37load_file libgomp-test-support.exp
38
39# Populate offload_targets_s (offloading targets separated by a space), and
40# offload_targets_s_openacc (the same, but with OpenACC names; OpenACC spells
41# some of them a little differently).
42set offload_targets_s [split $offload_targets ","]
43set offload_targets_s_openacc {}
44foreach offload_target_openacc $offload_targets_s {
1a06f5e6 45 # Translate to OpenACC names, or skip if not yet supported.
41dbbb37
TS
46 switch $offload_target_openacc {
47 intelmic {
41dbbb37
TS
48 continue
49 }
50 nvptx {
51 set offload_target_openacc "nvidia"
52 }
1a06f5e6
TS
53 hsa {
54 continue
55 }
41dbbb37
TS
56 }
57 lappend offload_targets_s_openacc "$offload_target_openacc"
58}
59lappend offload_targets_s_openacc "host"
60
516f1ed8
UB
61set dg-do-what-default run
62
63#
64# GCC_UNDER_TEST is the compiler under test.
65#
66
67set libgomp_compile_options ""
68
69#
70# libgomp_init
71#
72
73if [info exists TOOL_OPTIONS] {
74 set multilibs [get_multilibs $TOOL_OPTIONS]
75} else {
76 set multilibs [get_multilibs]
77}
78
79proc libgomp_init { args } {
80 global srcdir blddir objdir tool_root_dir
81 global libgomp_initialized
82 global tmpdir
83 global blddir
84 global gluefile wrap_flags
85 global ALWAYS_CFLAGS
86 global CFLAGS
87 global TOOL_EXECUTABLE TOOL_OPTIONS
88 global GCC_UNDER_TEST
89 global TESTING_IN_BUILD_TREE
90 global target_triplet
91 global always_ld_library_path
92
93 set blddir [lookfor_file [get_multilibs] libgomp]
94
95 # We set LC_ALL and LANG to C so that we get the same error
96 # messages as expected.
97 setenv LC_ALL C
98 setenv LANG C
99
17f35e23
DK
100 # Many hosts now default to a non-ASCII C locale, however, so
101 # they can set a charset encoding here if they need.
102 if { [ishost "*-*-cygwin*"] } {
103 setenv LC_ALL C.ASCII
104 setenv LANG C.ASCII
105 }
106
516f1ed8
UB
107 if ![info exists GCC_UNDER_TEST] then {
108 if [info exists TOOL_EXECUTABLE] {
109 set GCC_UNDER_TEST $TOOL_EXECUTABLE
110 } else {
111 set GCC_UNDER_TEST "[find_gcc]"
112 }
113 }
114
115 if ![info exists tmpdir] {
116 set tmpdir "/tmp"
117 }
118
119 if [info exists gluefile] {
120 unset gluefile
121 }
122
123 if {![info exists CFLAGS]} {
124 set CFLAGS ""
125 }
126
33cde516
RS
127 # Locate libgcc.a so we don't need to account for different values of
128 # SHLIB_EXT on different platforms
129 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
130 if {$gccdir != ""} {
131 set gccdir [file dirname $gccdir]
132 }
133
134 # Compute what needs to be put into LD_LIBRARY_PATH
135 set always_ld_library_path ".:${blddir}/.libs"
136
d64ae614
AT
137 # Add liboffloadmic build directory in LD_LIBRARY_PATH to support
138 # non-fallback testing for Intel MIC targets
41dbbb37 139 global offload_targets
f9a0eca4 140 if { [string match "*,intelmic,*" ",$offload_targets,"] } {
d64ae614
AT
141 append always_ld_library_path ":${blddir}/../liboffloadmic/.libs"
142 append always_ld_library_path ":${blddir}/../liboffloadmic/plugin/.libs"
143 # libstdc++ is required by liboffloadmic
144 append always_ld_library_path ":${blddir}/../libstdc++-v3/src/.libs"
be9f7143
TS
145 # libgcc_s is required by libstdc++
146 append always_ld_library_path ":${blddir}/../libgcc"
d64ae614
AT
147 }
148
41dbbb37 149 global offload_additional_lib_paths
d64ae614
AT
150 if { $offload_additional_lib_paths != "" } {
151 append always_ld_library_path "${offload_additional_lib_paths}"
152 }
153
33cde516
RS
154 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
155 if {$gccdir != ""} {
156 # Add AIX pthread directory first.
157 if { [llength [glob -nocomplain ${gccdir}/pthread/libgcc_s*.a]] >= 1 } {
158 append always_ld_library_path ":${gccdir}/pthread"
159 }
160 append always_ld_library_path ":${gccdir}"
161 set compiler [lindex $GCC_UNDER_TEST 0]
162
163 if { [is_remote host] == 0 && [which $compiler] != 0 } {
164 foreach i "[exec $compiler --print-multi-lib]" {
165 set mldir ""
166 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
167 set mldir [string trimright $mldir "\;@"]
168 if { "$mldir" == "." } {
169 continue
170 }
171 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
172 append always_ld_library_path ":${gccdir}/${mldir}"
173 }
174 }
175 }
176 }
177
516f1ed8 178 set ALWAYS_CFLAGS ""
8c9570df
NF
179 if { $blddir != "" } {
180 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
1d32a772
IS
181 # targets that use libgomp.a%s in their specs need a -B option
182 # for uninstalled testing.
183 lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/.libs"
8c9570df
NF
184 lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
185 lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
41dbbb37
TS
186 # The top-level include directory, for gomp-constants.h.
187 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/../../include"
8c9570df 188 }
516f1ed8 189 lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
516f1ed8 190
033ff3d1 191 # For build-tree testing, also consider the library paths used for builing.
41dbbb37
TS
192 # For installed testing, we assume all that to be provided in the sysroot.
193 if { $blddir != "" } {
194 global cuda_driver_include
195 global cuda_driver_lib
196 if { $cuda_driver_include != "" } {
197 # Stop gfortran from freaking out:
198 # Warning: Nonexistent include directory "[...]"
199 if {[file exists $cuda_driver_include]} {
200 lappend ALWAYS_CFLAGS "additional_flags=-I$cuda_driver_include"
201 }
202 }
203 if { $cuda_driver_lib != "" } {
204 lappend ALWAYS_CFLAGS "additional_flags=-L$cuda_driver_lib"
205 append always_ld_library_path ":$cuda_driver_lib"
206 }
033ff3d1 207 global hsa_runtime_lib
033ff3d1
TS
208 if { $hsa_runtime_lib != "" } {
209 append always_ld_library_path ":$hsa_runtime_lib"
210 }
41dbbb37
TS
211 }
212
516f1ed8
UB
213 # We use atomic operations in the testcases to validate results.
214 if { ([istarget i?86-*-*] || [istarget x86_64-*-*])
f53d712f 215 && [check_effective_target_ia32] } {
516f1ed8
UB
216 lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
217 }
1850744b
AT
218
219 if [istarget *-*-darwin*] {
220 lappend ALWAYS_CFLAGS "additional_flags=-shared-libgcc"
221 }
222
516f1ed8
UB
223 if [istarget sparc*-*-*] {
224 lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
225 }
226
227 if [info exists TOOL_OPTIONS] {
228 lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
229 }
230
231 # Make sure that lines are not wrapped. That can confuse the
232 # error-message parsing machinery.
233 lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
234
559d990c
MLI
235 # Disable caret
236 lappend ALWAYS_CFLAGS "additional_flags=-fno-diagnostics-show-caret"
237
45548f30
MJ
238 # Disable HSA warnings by default.
239 lappend ALWAYS_CFLAGS "additional_flags=-Wno-hsa"
240
bd599dea
JJ
241 # Disable color diagnostics
242 lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
d64ae614
AT
243
244 # Used for support non-fallback offloading.
245 # Help GCC to find target mkoffload.
41dbbb37 246 global offload_additional_options
d64ae614
AT
247 if { $offload_additional_options != "" } {
248 lappend ALWAYS_CFLAGS "additional_flags=${offload_additional_options}"
249 }
516f1ed8
UB
250}
251
252#
253# libgomp_target_compile -- compile a source file
254#
255
256proc libgomp_target_compile { source dest type options } {
257 global blddir
258 global libgomp_compile_options
259 global gluefile wrap_flags
260 global ALWAYS_CFLAGS
261 global GCC_UNDER_TEST
262 global lang_test_file
263 global lang_library_path
264 global lang_link_flags
f707da16
JJ
265 global lang_include_flags
266 global lang_source_re
516f1ed8 267
8c9570df
NF
268 if { [info exists lang_test_file] } {
269 if { $blddir != "" } {
72c66596
IS
270 # Some targets use libgfortran.a%s in their specs, so they need
271 # a -B option for uninstalled testing.
272 lappend options "additional_flags=-B${blddir}/${lang_library_path}"
8c9570df
NF
273 lappend options "ldflags=-L${blddir}/${lang_library_path}"
274 }
275 lappend options "ldflags=${lang_link_flags}"
f707da16
JJ
276 if { [info exists lang_include_flags] \
277 && [regexp ${lang_source_re} ${source}] } {
278 lappend options "additional_flags=${lang_include_flags}"
279 }
516f1ed8
UB
280 }
281
282 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
283 lappend options "libs=${gluefile}"
284 lappend options "ldflags=${wrap_flags}"
285 }
286
287 lappend options "additional_flags=[libio_include_flags]"
d4038ca2 288 lappend options "timeout=[timeout_value]"
516f1ed8
UB
289 lappend options "compiler=$GCC_UNDER_TEST"
290
291 set options [concat $libgomp_compile_options $options]
292
293 if [info exists ALWAYS_CFLAGS] {
294 set options [concat "$ALWAYS_CFLAGS" $options]
295 }
296
297 set options [dg-additional-files-options $options $source]
298
299 set result [target_compile $source $dest $type $options]
300
301 return $result
302}
303
304proc libgomp_option_help { } {
305 send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
306}
307
308proc libgomp_option_proc { option } {
309 if [regexp "^--additional_options," $option] {
310 global libgomp_compile_options
311 regsub "--additional_options," $option "" option
312 foreach x [split $option ","] {
313 lappend libgomp_compile_options "additional_flags=$x"
314 }
315 return 1
316 } else {
317 return 0
318 }
319}
122d7303
AT
320
321# Return 1 if offload device is available.
322proc check_effective_target_offload_device { } {
323 return [check_runtime_nocache offload_device_available_ {
324 #include <omp.h>
325 int main ()
326 {
327 int a;
328 #pragma omp target map(from: a)
329 a = omp_is_initial_device ();
330 return a;
331 }
332 } ]
333}
41dbbb37 334
d9a6bd32
JJ
335# Return 1 if offload device is available and it has non-shared address space.
336proc check_effective_target_offload_device_nonshared_as { } {
337 return [check_runtime_nocache offload_device_nonshared_as {
338 int main ()
339 {
340 int a = 8;
341 #pragma omp target map(to: a)
342 a++;
343 return a != 8;
344 }
345 } ]
346}
622174b2
KM
347
348# Return 1 if offload device is available and it has shared address space.
349proc check_effective_target_offload_device_shared_as { } {
350 return [check_runtime_nocache offload_device_shared_as {
351 int main ()
352 {
353 int x = 10;
354 #pragma omp target map(to: x)
355 x++;
356 return x == 10;
357 }
358 } ]
359}
d9a6bd32 360
41dbbb37
TS
361# Return 1 if at least one nvidia board is present.
362
363proc check_effective_target_openacc_nvidia_accel_present { } {
364 return [check_runtime openacc_nvidia_accel_present {
365 #include <openacc.h>
366 int main () {
367 return !(acc_get_num_devices (acc_device_nvidia) > 0);
368 }
369 } "" ]
370}
371
372# Return 1 if at least one nvidia board is present, and the nvidia device type
373# is selected by default by means of setting the environment variable
374# ACC_DEVICE_TYPE.
375
376proc check_effective_target_openacc_nvidia_accel_selected { } {
377 if { ![check_effective_target_openacc_nvidia_accel_present] } {
378 return 0;
379 }
380 global offload_target_openacc
381 if { $offload_target_openacc == "nvidia" } {
382 return 1;
383 }
384 return 0;
385}
1309f1d2
JN
386
387# Return 1 if the host target is selected for offloaded
388
389proc check_effective_target_openacc_host_selected { } {
390 global offload_target_openacc
391 if { $offload_target_openacc == "host" } {
392 return 1;
393 }
394 return 0;
395}
96a71bd5
MJ
396
397# Return 1 if the selected OMP device is actually a HSA device
398
399proc check_effective_target_hsa_offloading_selected_nocache {} {
400 global tool
401
402 set src {
403 int main () {
404 int v = 1;
405 #pragma omp target map(from:v)
406 v = 0;
407 return v;
408 }
409 }
410
411 set result [eval [list check_compile hsa_offloading_src executable $src] ""]
412 set lines [lindex $result 0]
413 set output [lindex $result 1]
414
415 set ok 0
416 if { [string match "" $lines] } {
417 # No error messages, let us switch on HSA debugging output and run it
418 set prev_HSA_DEBUG [getenv HSA_DEBUG]
419 setenv HSA_DEBUG "1"
420 set result [remote_load target "./$output" "2>&1" ""]
421 if { [string match "" $prev_HSA_DEBUG] } {
422 unsetenv HSA_DEBUG
423 } else {
424 setenv HSA_DEBUG $prev_HSA_DEBUG
425 }
426 set status [lindex $result 0]
427 if { $status != "pass" } {
428 verbose "HSA availability test failed"
429 return 0
430 }
431 set output [lindex $result 1]
432 if { [string match "*HSA debug: Going to dispatch kernel*" $output] } {
433 verbose "HSA availability detected"
434 set ok 1
435 }
436 }
437 remote_file build delete $output
438 return $ok
439}
440
441# Return 1 if the selected OMP device is actually a HSA device and
442# cache the result
443
444proc check_effective_target_hsa_offloading_selected {} {
445 return [check_cached_effective_target hsa_offloading_selected {
446 check_effective_target_hsa_offloading_selected_nocache
447 }]
448}
This page took 0.88156 seconds and 5 git commands to generate.