From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7833) id A15183858C2D; Mon, 13 Feb 2023 09:52:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A15183858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676281965; bh=IwCyZbXeOmZNw6ixXFRFd6hfpBn+0OEQEJ5GAg1nYr8=; h=From:To:Subject:Date:From; b=QRSBlzsDgV3BBcFrFSPS3ZCAjQz9bM3IKWirtCRpLKEF0M3UEW5yflXLKxeFQ7hEW xmMcu1XLatQQ4HT9BPMeG5B/YlOpd4YCcd4e5/DAMtFa1zvb8PdY9YlYyoVZ4E0DLc awOf+TI7IUOTRW+chYsx/8meleNnbBebNA2FUcVc= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Lancelot SIX To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: allow_hipcc_tests tests the hipcc compiler X-Act-Checkin: binutils-gdb X-Git-Author: Lancelot SIX X-Git-Refname: refs/heads/master X-Git-Oldrev: 310943c20cdfbc9d5e3abe71a46c39ed0819b719 X-Git-Newrev: 39f6d7c6b06b06a0372284f30c86417a8c0d6ba5 Message-Id: <20230213095245.A15183858C2D@sourceware.org> Date: Mon, 13 Feb 2023 09:52:45 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D39f6d7c6b06b= 06a0372284f30c86417a8c0d6ba5 commit 39f6d7c6b06b06a0372284f30c86417a8c0d6ba5 Author: Lancelot SIX Date: Sat Feb 4 23:57:07 2023 +0000 gdb/testsuite: allow_hipcc_tests tests the hipcc compiler =20 Update allow_hipcc_tests so all gdb.rocm tests are skipped if we do not have a working hipcc compiler available. =20 To achieve this, adjust gdb_simple_compile to ensure that the hip program is saved in a ".cpp" file before calling hipcc otherwise compilation will fail. =20 One thing to note is that it is possible to have a hipcc installed with a CUDA backend. Compiling with this back-end will successfully result in an application, but GDB cannot debug it (at least for the offload part). In the context of the gdb.rocm tests, we want to detect such situation where gdb_simple_compile would give a false positive. =20 To achieve this, this patch checks that there is at least one AMDGPU device available and that hipcc can compile for this or those targets. Detecting the device is done using the rocm_agent_enumerator tool which is installed with the all ROCm installations (it is used by hipcc to detect identify targets if this is not specified on the comand line). =20 This patch also makes the allow_hipcc_tests proc a cached proc. =20 Co-Authored-By: Pedro Alves Approved-By: Simon Marchi Diff: --- gdb/testsuite/lib/gdb.exp | 4 +++ gdb/testsuite/lib/rocm.exp | 69 ++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index b90858a04cd..7f98f080328 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4585,6 +4585,10 @@ proc gdb_simple_compile {name code {type object} {co= mpile_flags {}} {object obj} set ext "go" break } + if { "$flag" eq "hip" } { + set ext "cpp" + break + } } set src [standard_temp_file $name-[pid].$ext] set obj [standard_temp_file $name-[pid].$postfix] diff --git a/gdb/testsuite/lib/rocm.exp b/gdb/testsuite/lib/rocm.exp index a78b9f63353..125fa000170 100644 --- a/gdb/testsuite/lib/rocm.exp +++ b/gdb/testsuite/lib/rocm.exp @@ -15,7 +15,51 @@ # # Support library for testing ROCm (AMD GPU) GDB features. =20 -proc allow_hipcc_tests { } { +# Get the list of gpu targets to compile for. +# +# If HCC_AMDGPU_TARGET is set in the environment, use it. Otherwise, +# try reading it from the system using the rocm_agent_enumerator +# utility. + +proc hcc_amdgpu_targets {} { + # Look for HCC_AMDGPU_TARGET (same env var hipcc uses). If + # that fails, try using rocm_agent_enumerator (again, same as + # hipcc does). + if {[info exists ::env(HCC_AMDGPU_TARGET)]} { + return [split $::env(HCC_AMDGPU_TARGET) ","] + } + + set rocm_agent_enumerator "rocm_agent_enumerator" + + # If available, use ROCM_PATH to locate rocm_agent_enumerator. + if { [info exists ::env(ROCM_PATH)] } { + set rocm_agent_enumerator \ + "$::env(ROCM_PATH)/bin/rocm_agent_enumerator" + } + + # If we fail to locate the rocm_agent_enumerator, just return an empty + # list of targets and let the caller decide if this should be an error. + if { [which $rocm_agent_enumerator] =3D=3D 0 } { + return [list] + } + + set result [remote_exec host $rocm_agent_enumerator] + if { [lindex $result 0] !=3D 0 } { + error "rocm_agent_enumerator failed" + } + + set targets [list] + foreach target [lindex $result 1] { + # Ignore gfx000 which is the host CPU. + if { $target ne "gfx000" } { + lappend targets $target + } + } + + return $targets +} + +gdb_caching_proc allow_hipcc_tests { # Only the native target supports ROCm debugging. E.g., when # testing against GDBserver, there's no point in running the ROCm # tests. @@ -29,6 +73,29 @@ proc allow_hipcc_tests { } { return 0 } =20 + # Check we have a working hipcc compiler available. + set targets [hcc_amdgpu_targets] + if { [llength $targets] =3D=3D 0} { + return 0 + } + + set flags [list hip additional_flags=3D--offload-arch=3D[join $targets= ","]] + if {![gdb_simple_compile hipprobe { + #include + __global__ void + kern () {} + + int + main () + { + kern<<<1, 1>>> (); + hipDeviceSynchronize (); + return 0; + } + } executable $flags]} { + return 0 + } + return 1 }