From patchwork Thu Jan 25 23:03:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 84760 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09C6538582A4 for ; Thu, 25 Jan 2024 23:04:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 70EA3385841E for ; Thu, 25 Jan 2024 23:03:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70EA3385841E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 70EA3385841E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706223793; cv=none; b=IWqnsKIIHP7HEXaUV5ZNnACggR7JMHBw9lYH5grDvosDNtGErUgrzN5nxWOCAiD938fLok5FrxWYZWMqtzZc6eW8jXUeVxPmc5GUrqPAKh6YZB8ew79jZrGme9reqEDY0m8P0XemlyB2NFNS108hgF5YUMwXI4bMtN63z6xtF/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706223793; c=relaxed/simple; bh=xdPWwn6D/OUoO7L2q6FqGP3T79TD1HyRdJC/uV+rG1o=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=f6ynAPYWLm6Y39NQJOBakJG+teKQdP8dZ2q8YIcTQiCueQUPg7pLMMs1+OTIJjPNR/NFYt4PH/IJ4Ka3dZVSDkhuS0Px7bJ3+L4+ZErmC18eG4LaQiBaM0xgm/nsDFInw7qex26JN/v6giifMuw0M2KkUuIgpKuhrcJj7zkCs0s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40ed232ea06so9655275e9.1 for ; Thu, 25 Jan 2024 15:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1706223789; x=1706828589; darn=gcc.gnu.org; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=U6m9epHTkjFyyU0yvUam3prK9m9lk0IN/WbZVAERE+8=; b=DTTVmnBn1qHKuKDZIP5FVd9MsWf6eFyvGzkY6IvW60R6qFbaMn32nGI8UfJK+W2wAO 7XO942N8i+RnppZsp15N6TGB1qiA80XcZTJ3rsGnBJBR4Vog+uY5G0NS2VyZyoxPxqVi SZwNPWWZVSIChQ4m/J2jzx2JpTzH2KZxsqKIy7X4G5ufugyS8ism6JBYh8qy76W0MDsQ FAxX8HX/BvmrfndZOFftKKOQOKRy3amU8btBqsWwgizjqCCte/0cCxK3/4usDdNjqAwx D+eQtyckuGPSA6KyGlU+eMdd86VkHs/hSyqnZVDJJmte5CO8QR4z4tqmsH5S1U2a78qi UFUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706223789; x=1706828589; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U6m9epHTkjFyyU0yvUam3prK9m9lk0IN/WbZVAERE+8=; b=QhH9+ToinIZsHb47bsnEQeQ1bYs9ayOgnYNuTcU8xRu2g5v7G23xpo4LHe0fvZLAXV 7bBDPO7yBJeUxSsPyZjlAxs5NyYlBh7APLlF5dYTRgxEQbRpey262VvntnhBv5NVR2xd i0oksFEazmMW3kY+absbuVRmrKAtkLuciobsJDc2LVi8cyZA9aDcODXtiuNwxM8SFRJ9 eJdDyIuLzw+PKsSTTysHowOwg30QZM43ZZtc1M+Eqjik8pH+zEBR52HxX2hNOoScWLCC Tr0FIMbkDurmEJoheevrP4OTWwoGImbsEHeRSSUwvvrOR8Csu6Cfmzm7WpqtFa775U63 Lryw== X-Gm-Message-State: AOJu0YwC14A8MjLK3KXXeO5baj7fzwKUDbhOKIZWMbcljVWJ6neow5// uzJHn8Cp5GVk+Eo8lbhVJ9/kdsZNLgTwLb1/n50yte27x++sJPuV9ye/G9lppiXIHVYyZUqpHnu XAUL7Hg== X-Google-Smtp-Source: AGHT+IGbR+hm06mk3FylL/tiCSd2u0RaMg4/bk31qmyAapYw/TywtK5J81OyGsayNZTzqXv1O/G2Hw== X-Received: by 2002:a05:600c:45c9:b0:40e:a0a3:f358 with SMTP id s9-20020a05600c45c900b0040ea0a3f358mr633355wmo.22.1706223788451; Thu, 25 Jan 2024 15:03:08 -0800 (PST) Received: from ?IPV6:2001:16b8:2afa:4100:be03:58ff:fe31:f74? (200116b82afa4100be0358fffe310f74.dip.versatel-1u1.de. [2001:16b8:2afa:4100:be03:58ff:fe31:f74]) by smtp.gmail.com with ESMTPSA id h9-20020a05600c314900b0040e8800fcf3sm4038037wmo.5.2024.01.25.15.03.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jan 2024 15:03:08 -0800 (PST) Message-ID: Date: Fri, 26 Jan 2024 00:03:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches , Andrew Stubbs From: Tobias Burnus Subject: [patch] gcn/gcn-hsa.h: Always pass --amdhsa-code-object-version= in ASM_SPEC X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org When targeting AMD GPUs, the LLVM assembler (and linker) are used. Two days ago LLVM changed the default for theAMDHSA code object version (COV) from 4 to 5. In principle, we do not care which COV is used as long as it works; unfortunately, "mkoffload.cc" also generates an object file directly, bypassing the AMD GPU compiler as it copies debugging data to that file. That object file must have the same COV version (ELF ABI version) as compiler + llvm-mc assembler generated files. In order to ensure those are the same, this patch forces the use of COV 4 instead of using the default. Once GCC requires LLVM >= 14 instead of LLVM >= 13.0.1 we could change it. (Assuming that COV 5 is sufficiently stable in LLVM 14.) - But for now COV 4 will do. If you wonder how this LLVM issue shows up, simply compile any OpenMP or OpenACC program with AMD GPU offloading and enable debugging ("-g"), e.g. gcc -fopenmp -g test.f90 -foffload=amdgcn-amdhsa -foffload-options=-march=gfx908 With LLVM main (to become LLVM 18), you will then get the error: ld: error: incompatible ABI version: /tmp/ccAKx5cz.mkoffload.dbg.o OK for mainline? Tobias gcn/gcn-hsa.h: Always pass --amdhsa-code-object-version= in ASM_SPEC Since LLVM commit 082f87c9d418 (Pull Req. #79038; will become LLVM 18) "[AMDGPU] Change default AMDHSA Code Object version to 5" the default - when no --amdhsa-code-object-version= is used - was bumped. Using --amdhsa-code-object-version=5 is supported (with unknown limitations) since LLVM 14. GCC required for proper support at least LLVM 13.0.1 such that explicitly using COV5 is not possible. Unfortunately, the COV number matters for debugging ("-g") as mkoffload.cc extracts debugging data from the host's object file and writes into an an AMD GPU object file it creates. And all object files linked together must have the same ABI version. gcc/ChangeLog: * config/gcn/gcn-hsa.h (ABI_VERSION_SPEC): New; creates the "--amdhsa-code-object-version=" argument. (ASM_SPEC): Use it; replace previous version of it. Signed-off-by: Tobias Burnus diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h index f5de0d2969f..e5b93f7d9e5 100644 --- a/gcc/config/gcn/gcn-hsa.h +++ b/gcc/config/gcn/gcn-hsa.h @@ -75,6 +75,21 @@ extern unsigned int gcn_local_sym_hash (const char *name); supported for gcn. */ #define GOMP_SELF_SPECS "" +/* Explicitly set the ABI version; in principle, we could use just the + default; however, when debugging symbols are turned on, mkoffload.cc + writes a new AMD GPU object file and the ABI version needs to be the + same. - LLVM <= 17 defaults to 4 while LLVM >= 18 defaults to 5. + GCC supports LLVM >= 13.0.1 and only LLVM >= 14 supports version 5. + Note that Fiji is only suppored with LLVM <= 17 as version 3 i no longer + supported in LLVM >= 18. */ +#define ABI_VERSION_SPEC "march=fiji:--amdhsa-code-object-version=3;" \ + "!march=*|march=*:--amdhsa-code-object-version=4" + +/* Note that the XNACK and SRAM-ECC settings must match those in mkoffload.cc + as the latter creates new ELF object file when debugging is enabled and + the ELF flags (e_flags) of that generated file must be identical to those + generated by the compiler. */ + #define NO_XNACK "march=fiji:;march=gfx1030:;march=gfx1100:;" \ /* These match the defaults set in gcn.cc. */ \ "!mxnack*|mxnack=default:%{march=gfx900|march=gfx906|march=gfx908:-mattr=-xnack};" @@ -88,7 +103,7 @@ extern unsigned int gcn_local_sym_hash (const char *name); /* Use LLVM assembler and linker options. */ #define ASM_SPEC "-triple=amdgcn--amdhsa " \ "%{march=*:-mcpu=%*} " \ - "%{!march=*|march=fiji:--amdhsa-code-object-version=3} " \ + "%{" ABI_VERSION_SPEC "} " \ "%{" NO_XNACK XNACKOPT "} " \ "%{" NO_SRAM_ECC SRAMOPT "} " \ "%{march=gfx1030|march=gfx1100:-mattr=+wavefrontsize64} " \