From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2FfsCsl5QmqA0B0AWB0awg (envelope-from ) for ; Mon, 29 Jun 2026 09:57:29 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=GTzKKZtN; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1DACE1E098; Mon, 29 Jun 2026 09:57:29 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 8AF311E024 for ; Mon, 29 Jun 2026 09:57:27 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90F424BA2E37 for ; Mon, 29 Jun 2026 13:57:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90F424BA2E37 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=GTzKKZtN Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012038.outbound.protection.outlook.com [40.107.200.38]) by sourceware.org (Postfix) with ESMTPS id B76744BA2E2E for ; Mon, 29 Jun 2026 13:56:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B76744BA2E2E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B76744BA2E2E Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=40.107.200.38 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1782741420; cv=pass; b=YQOL2Jt2ZAeVqgM/gFc2qs/OuQHMoCTH3nV7TlQuon7m+9797/eBmQMeQhRBIKJ4BJK5fR2eJat8Krx0p6HVScffNGhrGqPW9Q1Myu3+RzoQNWbD+QWbXeUrTJN0y+uIB55g4v+tpBUTg7eLA/poLKHNCRPSFc5WQ+4XPIcMMds= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1782741420; c=relaxed/simple; bh=z0BaaKyYajCwo6N/Mjh5ESKg70qEzHDh+fo2qs3XrpU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hQX6AD0pCA32GuQohevLoT8CVXA2bbjpKPSO/Xe9StphpvaWhXDqQeXkLWuL9Rg5xPr1V7A4b7aYRkf0xbLbrmCVZDPUWblzxYZXIvDLwbGCV6ulbDhJ+XWiayyj4ugTwc9gOl4fPPYMG7c910z1wR6/BfE4FOqekObTpPAj12U= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=GTzKKZtN DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B76744BA2E2E ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JMJqka9kh5gAXkt7ZfqGY+07WG5p6Tg3ivPYYD2WkiYPcDVBh3yklbAMGN/eAXjFblLLE5WBfae/KdfUMP8B0cGfMx/OmA11hW2hOIPoILJ/1ShXOibi4+OkWdK72lndrn0cwe8XXn31edtQP7D3yC4M2HPcwb8CWrJGDLnvboIPnDwsEO3TS6nlsLY2a3ykhLYDV235HfqVO2hFBLiv+wV1F3Gar20fIAsDxwIYiDyw4vlsZ/buZT0fUHDCsrTsf6cKV/7s1yzC4BWM+5uDQ+c493JXtwGlrXf1wWDgBX2mPZMgcHZgtNBPQhsp8EwdIQ/ykSOY/fsIt2doVQjdIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E98xqbuvtWg23r3JwQDhw0JOiuWsiyfZos0gQhYioxk=; b=c3PUUJQPafZwtmrHe3gcMOq3tyicVWytgSBN5LmWjv+HdKjo1iNSz+2vJCRagR3AIAZ0a58SbOiKnI1b9AyfWKa8T5QzpDOcMd1kvgheCizCVcucyliyx6FOykRpgO8Ib6NCBK9SI4S2TwZHKaBR2eeNGasSbqwpA6K6rOe3CjlrRaK5A9K/byrUglrmyycHXocjIRkDfbSYIOOIkFmBG/j3w5JqehpDvTAErOEGDIvDXBOdAbaXif4rnFEfK0ftiA7e4/i3yBtpU1M2lJNk5ZS95g9qis38gAfU46REbExAPaZN4vpmbQWYZDR56Ow4PfbOICxOXtdoBl6+EN0JBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E98xqbuvtWg23r3JwQDhw0JOiuWsiyfZos0gQhYioxk=; b=GTzKKZtN9zkYG1YX4pGYcX/Wqb0Zc6WxzE3UJmvUd5Pqg9QpntchY89E0y+PfCr1Vn8U408CaRTonWZ6zR/x1HmaX+YgEZAionY5Fr74gzKxTF934/o3LAyWPooiOIQeVS66gv6rBW6yX1eNopdwAy4FF7eEkoItBFBtBpn/Xpo= Received: from BLAPR03CA0139.namprd03.prod.outlook.com (2603:10b6:208:32e::24) by MN2PR12MB4080.namprd12.prod.outlook.com (2603:10b6:208:1d9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.159.19; Mon, 29 Jun 2026 13:56:49 +0000 Received: from BL02EPF00021F68.namprd02.prod.outlook.com (2603:10b6:208:32e:cafe::3) by BLAPR03CA0139.outlook.office365.com (2603:10b6:208:32e::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.159.19 via Frontend Transport; Mon, 29 Jun 2026 13:56:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL02EPF00021F68.mail.protection.outlook.com (10.167.249.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Mon, 29 Jun 2026 13:56:46 +0000 Received: from ctr-rack32-mi300x-1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 29 Jun 2026 08:56:45 -0500 From: Luis Machado To: CC: Subject: [PATCH] gdb/testsuite: deduplicate --offload-arch targets in hcc_amdgpu_targets Date: Mon, 29 Jun 2026 08:56:13 -0500 Message-ID: <20260629135613.2738058-1-luis.machado@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00021F68:EE_|MN2PR12MB4080:EE_ X-MS-Office365-Filtering-Correlation-Id: 860af691-e3df-46a3-9c04-08ded5e6422d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700016|23010399003|376014|82310400026|6133799003|18002099003|56012099006|11063799006|5023799004; X-Microsoft-Antispam-Message-Info: Umy2332XQB8J+yyllWQL6Pt1NjthI50ojYlcwEHhWVpBeEMucOwIxy/JTKBnbONufGuwXq3HjFjqieXrad7Xa/KHrmFHzja+KWulEJPni7iD9oAl6PU2CyaQGhWEv9n8+PhXcyqiZD39wCA6c8TfiIpUzcEoPPJkur9mxJeC8/T7KgYw+OgcX8wnccDNW+wIJnLGzURh5pG6UNZztp9oD51m8nbFFIOtLdFzQITXDdp/lFW2f0tH9iz1YOX3u4W2VYl+0EsOkWz6w182u4ybfIeSi9Enn2BpdvFshfJd2WmP9+mzn2KPd2rXBCkQQNAi1UuKzN0OFw57WuhuGWoft+debXiWjg7IaieSbxx/Wa37HJ/sZ2S70NlAKbs3v01k7ioeDQPo4wEVXtOu3g0Kx7p7xZPuqFMnQCdrqYK6mXiyedPiRbQ+iETvPTsJuqFW6EIZGSkk+XuBw01wW9q3Ybqczj26JvZNI9BcgjJPhOO9iaozDcVnTAlL+Pt5Ouh+a7fWwo+50qpNZDB9wlof4hi813+F2cNxUTX76Eps0rh/iqAvJDETcWugQbTSGA9FZ/EPYfNO1SDeqhAGDAHVpenRZDcSM/WytSeiCPEAvUCKOop4sJOOv9VaNrlvaeiJ68veVjV/irw+eVXMuTVTyNeLR81eTiQoG+T+F6CGz/o= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(36860700016)(23010399003)(376014)(82310400026)(6133799003)(18002099003)(56012099006)(11063799006)(5023799004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: L4fCox01jAOl4rmGsNRS0T5tplNlbuMgQ7rvnbZ/iOvWPzHJdvV94pyG+uYmgkw4KxaFZTZDuZ+mM+t2aJwOy0Tr7+pCEmMY2gw8Issw2nvnv26kaYOIMO7ni1oY+AilDhSSZTewCj6TL1wsLWtZtrxrUr9nK+R6czxO5+U8jdxvLga5iswPCAwooeFB4DMb2LKwUuhTXkRfU8YZXxpQCemfTzX0mZhHB2KtYSUoQ8ERScl8Gc+5I99NXUgClyZZROxZIx8nM/ePWoYeQ8bpPdGFsIq67Gn7SesYidegP9SysEWwWJIDY2Kvt0h+zpU8D4AV9ZHmrA0St7QZV7BCJvlOiIxpX5WSvPASOKgUY3hg+fwkZhm2B2SqfpZTYSrmOGEBnZ/EgwSWfuwXyd8nCg7vfRJWJ4+yWcTMbP5MQ36uq5JW9LlbZOeWyT6t2VHx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2026 13:56:46.2237 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 860af691-e3df-46a3-9c04-08ded5e6422d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00021F68.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4080 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 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. --- 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 {} { -- 2.34.1