1 # Copyright
(C
) 2019-2024 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
3 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
16 # Support library
for testing ROCm
(AMD GPU
) GDB features.
18 #
Get the list of gpu targets to
compile for.
20 #
If HCC_AMDGPU_TARGET is
set in the environment
, use it. Otherwise
,
21 # try reading it from the
system using the rocm_agent_enumerator
24 proc hcc_amdgpu_targets
{} {
25 # Look
for HCC_AMDGPU_TARGET
(same env var hipcc uses
).
If
26 # that fails
, try using rocm_agent_enumerator
(again
, same as
28 if {[info exists ::env
(HCC_AMDGPU_TARGET
)]} {
29 return [split $
::env
(HCC_AMDGPU_TARGET
) ","]
32 set rocm_agent_enumerator
"rocm_agent_enumerator"
34 #
If available
, use ROCM_PATH to locate rocm_agent_enumerator.
35 if { [info exists ::env
(ROCM_PATH
)] } {
36 set rocm_agent_enumerator \
37 "$::env(ROCM_PATH)/bin/rocm_agent_enumerator"
40 #
If we fail to locate the rocm_agent_enumerator
, just
return an empty
41 # list of targets and let the caller decide
if this should be an error.
42 if { [which $rocm_agent_enumerator
] == 0 } {
46 set result
[remote_exec host $rocm_agent_enumerator
]
47 if { [lindex $result
0] != 0 } {
48 error
"rocm_agent_enumerator failed"
52 foreach target
[lindex $result
1] {
53 # Ignore gfx000 which is the host CPU.
54 if { $target ne
"gfx000" } {
55 lappend targets $target
62 gdb_caching_proc allow_hipcc_tests
{} {
63 # Only the native target supports ROCm debugging. E.g.
, when
64 # testing against GDBserver
, there
's no point in running the ROCm
66 if {[target_info gdb_protocol] != ""} {
67 return {0 "remote debugging"}
70 if {![istarget "*-linux*"]} {
71 return {0 "target platform is not Linux"}
74 # Ensure that GDB is built with amd-dbgapi support.
75 set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS --configuration"]
76 if { [string first "--with-amd-dbgapi" $output] == -1 } {
77 return {0 "amd-dbgapi not supported"}
80 # Check we have a working hipcc compiler available.
81 set targets [hcc_amdgpu_targets]
82 if { [llength $targets] == 0} {
83 return {0 "no suitable amdgpu targets found"}
86 set flags [list hip additional_flags=--offload-arch=[join $targets ","]]
87 if {![gdb_simple_compile hipprobe {
88 #include <hip/hip_runtime.h>
96 if (hipDeviceSynchronize () != hipSuccess)
100 } executable $flags]} {
101 return {0 "failed to compile hip program"}
107 # The lock file used to ensure that only one GDB has access to the GPU
109 set gpu_lock_filename $objdir/gpu-parallel.lock
111 # Run body under the GPU lock. Also calls gdb_exit before releasing
114 proc with_rocm_gpu_lock { body } {
115 with_lock $::gpu_lock_filename $body
117 # In case BODY returned early due to some testcase failing, and
118 # left GDB running, debugging the GPU.
122 # Return true if all the devices support debugging multiple processes
125 proc hip_devices_support_debug_multi_process {} {
126 set unsupported_targets \
127 {gfx900 gfx906 gfx908 gfx1010 gfx1011 gfx1012 gfx1030 gfx1031 gfx1032}
129 set targets [hcc_amdgpu_targets]
130 if { [llength $targets] == 0 } {
134 foreach target $targets {
135 if { [lsearch -exact $unsupported_targets $target] != -1 } {
142 # Return true if all the devices on the host support precise memory.
144 proc hip_devices_support_precise_memory {} {
145 set unsupported_targets \
146 {gfx900 gfx906 gfx908 gfx1010 gfx1011 gfx1012 gfx1030 gfx1031 gfx1032}
148 set targets [hcc_amdgpu_targets]
149 if { [llength $targets] == 0 } {
153 foreach target $targets {
154 if { [lsearch -exact $unsupported_targets $target] != -1 } {