From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2XhuExlVemplrxsAWB0awg (envelope-from ) for ; Mon, 10 Aug 2026 18:47:53 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=TLjSaOwh; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4C2961E09B; Mon, 10 Aug 2026 18:47:53 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9D2841E09B for ; Mon, 10 Aug 2026 18:47:52 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77DBA4BB3BAC for ; Mon, 10 Aug 2026 22:47:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77DBA4BB3BAC Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=TLjSaOwh Received: from toucan.tulip.relay.mailchannels.net (toucan.tulip.relay.mailchannels.net [23.83.218.254]) by sourceware.org (Postfix) with ESMTPS id E423A4BAE7EC for ; Mon, 10 Aug 2026 22:47:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E423A4BAE7EC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=palves.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E423A4BAE7EC Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.218.254 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786402034; cv=none; b=pIIg+fa5mZdsHkP0Thj8PzUa+nvWU75WFUwmtuTpKl+5/ph17j3Way85dhjLhWs3Mh01tWueXGADlXJiIFFW57tD83WIp38+oMghsq9SijtWAyX08IjdERJae+95zzKEWi83wkds18Vipg2RX0RIxhx/ja65NDfYvsMgxmfZIow= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786402034; c=relaxed/simple; bh=gCJPvUOdvdHzZvdfxjUpIv+jq8WN6s6keVzKgKRjI1k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=S9G2IgGCpug7Jt/b4g5/uDmO28Qmdm+0opb6OOysS6W4vHSizujYVqh+h/k1+0eB65bCCkOi573qJ/drwzBovheoIuEUfqYgO0GuVODbZnEF7KoBkGqOY9iJ50SmPQKtyPXWkZH0mQ5ImnQeYrxFFbjE0StuX00Yn9k1Ppg4ckY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=palves.net header.i=@palves.net header.a=rsa-sha256 header.s=dreamhost header.b=TLjSaOwh DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E423A4BAE7EC X-Sender-Id: dreamhost|x-authsender|pedro@palves.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id D749F402A40; Mon, 10 Aug 2026 22:47:12 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (100-108-76-70.trex-nlb.outbound.svc.cluster.local [100.108.76.70]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B6FE3403B22; Mon, 10 Aug 2026 22:47:12 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|pedro@palves.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|pedro@palves.net X-MailChannels-Auth-Id: dreamhost X-Snatch-Hook: 0a12a05514bb1815_1786402032801_3322950037 X-MC-Loop-Signature: 1786402032801:3044139647 X-MC-Ingress-Time: 1786402032801 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.108.76.70 (trex/8.0.2); Mon, 10 Aug 2026 22:47:12 +0000 Received: from localhost (bl21-204-140.dsl.telepac.pt [2.82.204.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pedro@palves.net) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4hJqdD0LyCz1056; Mon, 10 Aug 2026 15:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=palves.net; s=dreamhost; t=1786402032; bh=ocwattocjQl8D9fEfiJoLD6iGzMqFPNdbwfnLRp/VYs=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=TLjSaOwhq6ACmurccpBEUIVnVCG+TG+UBAyJ1h6bd0ok5h1KmjauZ4xHDNpNPWT31 XcY0rjZp/rCWdj6YxGreJBf8pTO63levBWF2POJaN35/41y831H6l7X8HQAZXYIQyZ NHNx6Po/yazqXB8h0/U71ff+iaZdzsq/3oAhWDcKGVVu9L6k+4B0mKCLKV3nQKtvU+ yDNFHmqAc8263m2dWJj1SzmU6OlSDcJMSBNZR4O/RiWX2i7fKwQEaokPf2mu0aojsL R19B13nBl87NAweI7xBYsiJD+nwTFzoMJQz3tWH05QgMQAE5qK9ODDPvpwmiEs/v50 ysWDZ2gbssbUw== From: Pedro Alves To: gdb-patches@sourceware.org Cc: Lancelot SIX Subject: [PATCH 1/2] gdb/testsuite: For ROCm/HIP, don't rely on rocm_agent_enumerator Date: Mon, 10 Aug 2026 23:46:31 +0100 Message-ID: <20260810224633.3455055-2-pedro@palves.net> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260810224633.3455055-1-pedro@palves.net> References: <20260810224633.3455055-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org The rocm_agent_enumerator program does not exist on all HIP supported platforms (such as e.g. the Windows HIP SDK). Fix this by compiling and running our own replacement HIP program that lists AMD GPU devices, instead of calling rocm_agent_enumerator. With this, we no longer need to check if we have a working HIP compiler available (by compiling a similar HIP program), as compiling the enumerator program achieves the same goal. In turn this means that the cost of having this replacement is essentially zero. Same number of external process invocations, and essentially the same number of lines of code. And we get to drop one dependency. We just need to be careful to not call hcc_amdgpu_targets when compiling the GPU device enumerator program, otherwise we hit infinite recursion. That is handled by passing a new hip_no_offload_arch option to gdb_compile. Both Linux and Windows ROCm builds nowadays ship with an alternative amdgpu-arch program (also installed as offload-arch) that we could use, but as explained above, having our own replacement has basically no cost, so I'm not proposing using it. Note also that the hip_no_offload_arch flag will be used in other places, in future patches. Change-Id: I45262f2fe24455ade6075eded2cd7df03979c6cc --- gdb/testsuite/lib/gdb.exp | 4 +- gdb/testsuite/lib/rocm.exp | 93 +++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index d4b8c9c24dc..9bb5a1446e6 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6554,6 +6554,7 @@ proc gdb_windows_manifest_obj {} { # - column-info/no-column-info: Enable/Disable generation of column table # information. # - dwarf5: Force compilation with dwarf-5 debug information. +# - hip_no_offload_arch: Do not pass --offload-arch to the HIP compiler. # # And here are some of the not too obscure options understood by DejaGnu that # influence the compilation: @@ -6974,7 +6975,8 @@ proc gdb_compile {source dest type options} { # amdclang++ requires explicit --offload-arch. Explicitly # pass one --offload-arch for each available device. But # don't do it if the testcase explicitly used --offload-arch. - if {[lsearch -regexp $options "--offload-arch="] == -1} { + if {[lsearch -exact $options hip_no_offload_arch] == -1 + && [lsearch -regexp $options "--offload-arch="] == -1} { foreach gpu_target [hcc_amdgpu_targets] { lappend new_options "early_flags=--offload-arch=$gpu_target" } diff --git a/gdb/testsuite/lib/rocm.exp b/gdb/testsuite/lib/rocm.exp index f8a3b233fae..025fa63da6f 100644 --- a/gdb/testsuite/lib/rocm.exp +++ b/gdb/testsuite/lib/rocm.exp @@ -46,38 +46,58 @@ proc log_host_exec { cmd } { # # Return a list of GPU devices that do exist on the system. # The list will be empty when there's no GPU or the execution -# of rocm_agent_enumerator does not succeed. It is up to the -# caller of this procedure that what should happen when an empty +# of the enumerator program does not succeed. It is up to the +# caller of this procedure what should happen when an empty # list is returned. gdb_caching_proc find_amdgpu_devices {} { - global rocm_path - set hip_gpu_devices [list] - set enumerator "rocm_agent_enumerator" - set targets "" + # Compile and run a simple custom HIP program that lists all GPU + # devices, one device per line. We don't rely on + # rocm_agent_enumerator because that does not exist on all + # supported platforms. + # + # Compile without --offload-arch (which is fine because this is a + # host-only program), because otherwise gdb_compile would call + # hcc_amdgpu_targets to know which --offload-arch flags to pass to + # the HIP compiler, and we'd end up here again, resulting in + # infinite recursion. + set options {hip hip_no_offload_arch} + if {![gdb_simple_compile device_enumerator { + #include + #include + #include - # Try the PATH first - set result [log_host_exec "$enumerator"] - if {[lindex $result 0] == 0} { - set targets [lindex $result 1] - } else { - # Now try the ROCM_PATH - set result [log_host_exec "$rocm_path/bin/$enumerator"] - if {[lindex $result 0] == 0} { - set targets [lindex $result 1] - } + int + main () + { + int device_count; + if (hipGetDeviceCount (&device_count) == hipSuccess) + for (int i = 0; i < device_count; i++) + { + hipDeviceProp_t props; + if (hipGetDeviceProperties (&props, i) == hipSuccess) + { + /* Strip out the supported features list, + like gfx90a:sramecc+:xnack-. */ + char *colon = strstr (props.gcnArchName, ":"); + if (colon != nullptr) + *colon = '\0'; + printf ("%s\n", props.gcnArchName); + } + } + } + } executable $options]} { + return {} } - if {$targets != ""} { - foreach dev $targets { - # Ignore the 'gfx000' device which identifies the host. - if {$dev != "gfx000"} { - lappend hip_gpu_devices $dev - } - } + set result [log_host_exec "$obj"] + if {[lindex $result 0] == 0} { + set targets [lindex $result 1] + # Convert newline-separated string to a list. + return [list {*}$targets] } - return $hip_gpu_devices + return {} } # Get the list of unique GPU targets to compile for. @@ -128,33 +148,14 @@ gdb_caching_proc allow_hip_tests {} { return {0 "amd-dbgapi not supported"} } - # Check if there's any GPU device to run the tests on. + # Check if there's any GPU device to run the tests on. If this + # works, then we also know we have a working HIP compiler + # available. set devices [find_amdgpu_devices] if {[llength $devices] == 0} { return {0 "no suitable amdgpu targets found"} } - # Check if we have a working hipcc compiler available. - # TARGETS won't be empty, because there's at least one GPU device. - set targets [hcc_amdgpu_targets] - set flags [list hip additional_flags=--offload-arch=[join $targets ","]] - if {![gdb_simple_compile hipprobe { - #include - __global__ void - kern () {} - - int - main () - { - kern<<<1, 1>>> (); - if (hipDeviceSynchronize () != hipSuccess) - return -1; - return 0; - } - } executable $flags]} { - return {0 "failed to compile hip program"} - } - return 1 } -- 2.54.0