From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id skQNEw50R2p8byMAWB0awg (envelope-from ) for ; Fri, 03 Jul 2026 04:34:22 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oVwRdvPx; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2FFEE1E098; Fri, 03 Jul 2026 04:34:22 -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,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 623581E070 for ; Fri, 03 Jul 2026 04:34:20 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 320904BA23FB for ; Fri, 3 Jul 2026 08:34:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 320904BA23FB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oVwRdvPx Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 9091B4BA5439 for ; Fri, 3 Jul 2026 08:33:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9091B4BA5439 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9091B4BA5439 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783067634; cv=none; b=eFERTCd4PxxoH2s8dYFKhnvMtHHdICcJIFaScKicQxb0rgk62XA4C93rKqmT8qO5UdgRd/6lgVk1HzJhOa+uAQRQV26szlZ3/vRT3vdZ4qQRCxf3Q4LqE42VZySHXh46fkWAR2iIaKNb6Odci4ESlKAXEZuQSeLfMefuPz9p7lA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783067634; c=relaxed/simple; bh=2NuHJgI3AKSyGYGGEdHl2QL92cZVNT6JSUKqShmFOVs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=E/PakqKiD1Tn+G01uV1hnUoXRLa8ZEjzzqdZwmuuqoZyB7x2eblYePKLkBRveMCuE4o33sREsmZOiIllBdQP+sGYFjauitJ5SBg5FrZEEb3Wnb399sDASHOKfmTb8AnTm9+8vS/Xb9BARGbiLMA9XOg7DCIE0oQ1YmghkDaYlLE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oVwRdvPx DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9091B4BA5439 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-474303f3c72so185366f8f.0 for ; Fri, 03 Jul 2026 01:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783067633; x=1783672433; darn=sourceware.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=IcH8PgaGd2WNE7oQvCGIm7A3IfopijxAVsBMDRda3Nc=; b=oVwRdvPx8V59kohrlKmBOIcGpAb5Kvid2ZSVbWH8qgzmy3Pvl8T+kgyqlR1KpNwi7i /LBrXKbqlH1s46QM5ggSO7du1E3ZPS2T1vE0nMWLH5k6kTBOn1J8MN4FlFSmYDj8PggX 4P1F1bZ5SH3CnwHXCTDYyOmBHe8GPP0pNXuWJXdZ7+U7DafaJDJhMxkH+WSX191hpxo5 D0iHrhhmxx8lq6NS6pTvIyXhh/BjyEu3Z8eeOFuQJQuSxHkdi+CT9f6/n+XwpaHhIvLP OXXLkKyR2xAR5sa7niSbzD3AwC22MgegC6+kIt5AZ4Y0OkHJ7MG3REWWik6qDl8QuFeR HxQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783067633; x=1783672433; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IcH8PgaGd2WNE7oQvCGIm7A3IfopijxAVsBMDRda3Nc=; b=YbeO15UJu9hIi3l1lGveAp9rcltxGmRZlbi82wkSabaHx8y4lFSzqwQTjOc4Dt6gCa q1iuAGfTCBcmgMa8k1HfmnsRw/ePsOeCA6JMDYEQADkwkXmgrl+PJzT4ayh4JBtid/rI cYXkJljyHebjXiZzdS46BijXk71WMjQKI0L4G4qTkh1gc26ldYDZbnDWgcZcIpTebEaY A7U6jTF4Wb3paqT+EKTLdJlmdkWu0WcVwHkmJ+WQ9WR1p4C7odos74TiF/JmMaGGpWoC IL1kDoVzUXejYtmBSiY0Osbm0brpDeOTMKIMKBVMQaROFx2qvFxO1bXUdTLEVvkUMWr0 fPfw== X-Forwarded-Encrypted: i=1; AHgh+RpYV4UM9V+gxQ7T6cH04CGzWj03DojDihRIvjt+lLecKEnv0l8BSVyzT8AP2ETFjTNPq6XqoQAZhkoKzQ==@sourceware.org X-Gm-Message-State: AOJu0YxDKoA18EmjYrPNDOnLdbo9vxUP0kU/Hr52TcgvV+N8atr9Yvlf iAnt9fOj0CQ+3h8y+NU6YjKYdYZab/HQqQ+zcFy5o1MDmAyjzeqRw8oh X-Gm-Gg: AfdE7cnHfubsHzkay5yIKqFe6odpPnCJNGRVon3dfAIfQWwILNct+I7ynT9DMTwcAoT qY7QGa9g9fxaOtkSfNLKXQ2/KDiZ7J0bdWGyR/LK7x5P0IXT7hMNYQXvPi0JZVk8FFJ++OYMAMC D1cKJI9X7qXswY3mFkHyDi/RWgeLr+xccpOWJLAgmkA3Mcs3pkhoANuVOhlYtyj6JAuySS22Vyl O3VWlHqqTCxUB/2GdesfE4rduZGSatmkSxp+MgkuV6ETyKukU6IT/REoX+aDjmHbd7mrn7JtumM /KjY7qhIHgIXrnVLXLEOMoA3SVxfRrVgLl5Mui0gIE0WaaM1voGhnd156Uy6Uqe+RGT0LI1lCOW iSzBVeRjDftWOS/A5mgYUjj3oaHXZrrhXkCLIX6k/0hRSCCsO/AVMgE4O4YWTwT8GKeTMdnB95s GRLxfC5Q1r6hB2mYWypslMiu/JHg== X-Received: by 2002:a05:6000:230f:b0:474:57f0:49f8 with SMTP id ffacd0b85a97d-477573bbd26mr13308974f8f.4.1783067633057; Fri, 03 Jul 2026 01:33:53 -0700 (PDT) Received: from [192.168.0.38] ([86.12.216.189]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-477db3dba0esm15715933f8f.7.2026.07.03.01.33.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jul 2026 01:33:52 -0700 (PDT) Message-ID: <4dfd7ace-ade6-434f-8a63-f447f383dfb0@gmail.com> Date: Fri, 3 Jul 2026 09:33:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/testsuite: deduplicate --offload-arch targets in hcc_amdgpu_targets To: Lancelot SIX , Luis Machado , gdb-patches@sourceware.org References: <20260629135613.2738058-1-luis.machado@amd.com> <0cc2ad49-8ced-4f1b-a236-5f0efff00ddf@amd.com> Content-Language: en-US From: Luis In-Reply-To: <0cc2ad49-8ced-4f1b-a236-5f0efff00ddf@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed 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 On 01/07/2026 17:00, Lancelot SIX wrote: > > > On 29/06/2026 14:56, Luis Machado wrote: >> On systems with multiple identical GPUs, find_amdgpu_devices returns one >> entry per device, causing hcc_amdgpu_targets to emit redundant >> --offload-arch flags when compiling HIP test programs (e.g. eight >> --offload-arch=gfx942 flags on an 8-GPU MI300 system). >> >> Deduplicate the target list in hcc_amdgpu_targets, preserving order, so >> each unique architecture appears exactly once regardless of how many >> physical devices share it.  The same deduplication is applied when the >> list comes from the HCC_AMDGPU_TARGET environment variable.  An array >> is used for the seen-set to give O(1) membership tests. >> >> Add gdb.rocm/hcc-amdgpu-targets.exp to unit-test the deduplication >> logic across both the env-var and device-enumeration code paths, without >> requiring a GPU. > > Hi Luis, > > This LGTM.  Thanks for doing this. > > Best, > Lancelot. > > Approved-by: Lancelot Six (amdgpu) > Thanks. Pushed now. >> --- >>   gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp | 80 +++++++++++++++++++ >>   gdb/testsuite/lib/rocm.exp                    | 20 ++++- >>   2 files changed, 97 insertions(+), 3 deletions(-) >>   create mode 100644 gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp >> >> diff --git a/gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp b/gdb/ >> testsuite/gdb.rocm/hcc-amdgpu-targets.exp >> new file mode 100644 >> index 00000000000..8f04cca7981 >> --- /dev/null >> +++ b/gdb/testsuite/gdb.rocm/hcc-amdgpu-targets.exp >> @@ -0,0 +1,80 @@ >> +# Copyright (C) 2026 Free Software Foundation, Inc. >> + >> +# This file is part of GDB. >> + >> +# This program is free software; you can redistribute it and/or modify >> +# it under the terms of the GNU General Public License as published by >> +# the Free Software Foundation; either version 3 of the License, or >> +# (at your option) any later version. >> + >> +# This program is distributed in the hope that it will be useful, >> +# but WITHOUT ANY WARRANTY; without even the implied warranty of >> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the >> +# GNU General Public License for more details. >> + >> +# You should have received a copy of the GNU General Public License >> +# along with this program.  If not, see . >> + >> +# Unit tests for hcc_amdgpu_targets.  These exercise the deduplication >> +# logic across both the env-var and device-enumeration code paths, and >> +# do not require a GPU or a running GDB instance. >> + >> +load_lib rocm.exp >> + >> +# Run BODY with find_amdgpu_devices stubbed to return DEVICES, then >> +# restore the original proc. >> +proc with_stub_devices {devices body} { >> +    rename find_amdgpu_devices __saved_find_amdgpu_devices >> +    # tclint-disable-next-line command-args >> +    proc find_amdgpu_devices {} [list return $devices] >> +    set code [catch {uplevel 1 $body} result] >> +    rename find_amdgpu_devices {} >> +    rename __saved_find_amdgpu_devices find_amdgpu_devices >> +    return -code $code $result >> +} >> + >> +# Tests using find_amdgpu_devices (no HCC_AMDGPU_TARGET env var). >> + >> +save_vars { env(HCC_AMDGPU_TARGET) } { >> +    unset -nocomplain ::env(HCC_AMDGPU_TARGET) >> + >> +    with_stub_devices {gfx942 gfx942 gfx942} { >> +    set result [hcc_amdgpu_targets] >> +    verbose -log "hcc_amdgpu_targets: got $result" >> +    gdb_assert {$result eq {gfx942}} "duplicates removed: 3x gfx942 >> produces single entry" >> +    } >> + >> +    with_stub_devices {gfx942 gfx942 gfx1100 gfx1100 gfx942} { >> +    set result [hcc_amdgpu_targets] >> +    verbose -log "hcc_amdgpu_targets: got $result" >> +    gdb_assert {$result eq {gfx942 gfx1100}} "duplicates removed, >> order preserved: mixed list" >> +    } >> + >> +    with_stub_devices {gfx906 gfx90a} { >> +    set result [hcc_amdgpu_targets] >> +    verbose -log "hcc_amdgpu_targets: got $result" >> +    gdb_assert {$result eq {gfx906 gfx90a}} "no duplicates: distinct >> devices unchanged" >> +    } >> + >> +    with_stub_devices {} { >> +    set result [hcc_amdgpu_targets] >> +    verbose -log "hcc_amdgpu_targets: got $result" >> +    gdb_assert {$result eq {}} "empty device list returned as-is" >> +    } >> +} >> + >> +# Tests using HCC_AMDGPU_TARGET env var. >> + >> +save_vars { env(HCC_AMDGPU_TARGET) } { >> +    set ::env(HCC_AMDGPU_TARGET) "gfx942,gfx942,gfx942" >> +    set result [hcc_amdgpu_targets] >> +    verbose -log "hcc_amdgpu_targets: got $result" >> +    gdb_assert {$result eq {gfx942}} "env var: duplicates removed" >> +} >> + >> +save_vars { env(HCC_AMDGPU_TARGET) } { >> +    set ::env(HCC_AMDGPU_TARGET) "gfx906,gfx90a,gfx906" >> +    set result [hcc_amdgpu_targets] >> +    verbose -log "hcc_amdgpu_targets: got $result" >> +    gdb_assert {$result eq {gfx906 gfx90a}} "env var: order preserved >> when deduplicating" >> +} >> diff --git a/gdb/testsuite/lib/rocm.exp b/gdb/testsuite/lib/rocm.exp >> index 15ee22dad26..ca1ae3f1a8b 100644 >> --- a/gdb/testsuite/lib/rocm.exp >> +++ b/gdb/testsuite/lib/rocm.exp >> @@ -80,20 +80,34 @@ gdb_caching_proc find_amdgpu_devices {} { >>       return $hip_gpu_devices >>   } >> -# Get the list of GPU targets to compile for. >> +# Get the list of unique GPU targets to compile for. >>   # >>   # If HCC_AMDGPU_TARGET is set in the environment, use it. >>   # Otherwise, consider the devices available on the system. >> +# >> +# Duplicates are removed so that systems with multiple identical >> +# GPUs do not produce redundant --offload-arch flags. >>   proc hcc_amdgpu_targets {} { >>       # First, look for HCC_AMDGPU_TARGET (same env var hipcc uses). >>       if {[info exists ::env(HCC_AMDGPU_TARGET)]} { >>       # We don't verify the contents of HCC_AMDGPU_TARGET. >>       # That's the toolchain's job. >> -    return [split $::env(HCC_AMDGPU_TARGET) ","] >> +    set targets [split $::env(HCC_AMDGPU_TARGET) ","] >> +    } else { >> +    set targets [find_amdgpu_devices] >>       } >> -    return [find_amdgpu_devices] >> +    # Remove duplicates while preserving order. >> +    array set seen {} >> +    set unique {} >> +    foreach t $targets { >> +    if {![info exists seen($t)]} { >> +        set seen($t) 1 >> +        lappend unique $t >> +    } >> +    } >> +    return $unique >>   } >>   gdb_caching_proc allow_hipcc_tests {} { >