From patchwork Thu Mar 7 11:29:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 1909192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=JgtXJHyL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr6Xs4ZnGz1yX4 for ; Thu, 7 Mar 2024 22:30:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC4E03857816 for ; Thu, 7 Mar 2024 11:30:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 4D04E3858D35 for ; Thu, 7 Mar 2024 11:29:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D04E3858D35 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 4D04E3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709810986; cv=none; b=Vc5fGDTWIYZIZIjI3sRPNM7H95cwh7cYh8pOEYiA1eZbVYaTOj/xbg1fqalw3HGHH1cD6S40iEhnvUAv6R+PyCDJQe0bHifXU0O17UtFC3fPbkIUSZll42tByeOtYCeou+uZsTjP7txwyUQs3yXuYvwnjfIweqqthGtEHp1umEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709810986; c=relaxed/simple; bh=HkzdqPtnK4NWR9LveY3Lj2ydCrgTrYpFF9FUEt4vSuc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m05yXlcQuO/6j2KpHlehI4zFo0ZyCc4NJ9SaMli7QajUVRSiXZyUOIxT3mVH+5+4J2m9z2wV6XhDeDW37JzeR8G6RWEZ07ZWxFXAsgyLu80/hp9E/UB5olOHlZOH2o7K1/2P85hmJNultuEZTapPvD2x/xNOjsxRCkqNXGjEGs0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-55a5e7fa471so1101038a12.1 for ; Thu, 07 Mar 2024 03:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1709810982; x=1710415782; darn=gcc.gnu.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=IMJ4J2ffaff0pX/JCuS8slvN2diF6fpFjHzI6FDmIm4=; b=JgtXJHyL8QHXr60UF9HrlvIx8aB29M1b26gpmamp5lGB6H4lrEoCxImtkqUWzjMY+m 4i6e6KIQknf4I5Lkn/I67N4sJreNbCgD+j2Q2EN8GpU1funPGlZw/dyMv8MoDPBfeSUj xCkiHbiOxoFgCNY7rO4i7fAKk7FSAQIrXwnwW69lIjU1WLHBbK8Y5o8OKJyYXgNDMlSJ tPIBl3cYsr+AgWPdIsTp0rRXDcIpihQ21oXq4TcLsn1RT791RKIwfcNFlKmTH5+Ifthp ISnWCJOb5GV9UtNhLp0AQbg2I0gyQsTS3anTxV/+FqE5fgRfofsycXP2delxXAQ4+x2t 2HtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709810982; x=1710415782; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IMJ4J2ffaff0pX/JCuS8slvN2diF6fpFjHzI6FDmIm4=; b=aI0yeNamjGEbjjb+3WI74Qy4FCznwptt45ftIiddsdkKd4eidUrqK5lZvf6Lv9jr2E PRMs1EHzxcN2DcStVksUW0bC2voqZ7tmhWTm6hfUJOxvX+fk1o8/pER+aCJY5RRB11AQ inNZUznKa+ofIleb0U7cxOBh7NM0mXlonqRzHYo9onhilPLwKU9j4o+e0tX69Kbo3U25 CUhUwH0/eNWo5PFUrLqN/JwcA7nvuF4mPsojMnajfi0eA75kpJWJrswXIlyPEynJnwmP apA+J0YGeKWU5mwikpd15ttIJ6HVyX+39Cl3TVR0v1NQogFGpgPyVGm10dpBfqeEmsn6 ACJw== X-Forwarded-Encrypted: i=1; AJvYcCUFFEHUmZQiSiLr6OGs6dczZ0y32Y3EV2tWfzDFgp5eMetX+Es7ku+5G6Qi6jM8HMqZpNX5ZfpFZeur8RBh+Gty5vXihhyIsQ== X-Gm-Message-State: AOJu0YyjX6/MRAw9/Ww+UTm9QO4fK+5R67WDysayTxAbtLaZu+Xl5Vl1 Pe5yZRnQb9Q9WR8JYllxXtvyetrS0wb13nn+S0eajkc6p7mLSAkVn2ihmUAb4IA= X-Google-Smtp-Source: AGHT+IERwTHsJu+71mTJyGU46UbnBNk81ZujNSzEVsY3+u5u47XIujDj+bpszhQLRwCL4u6d2vLVhg== X-Received: by 2002:a50:c943:0:b0:566:13a2:3008 with SMTP id p3-20020a50c943000000b0056613a23008mr12943433edh.6.1709810981741; Thu, 07 Mar 2024 03:29:41 -0800 (PST) Received: from euler.schwinge.homeip.net (p200300c8b70336000b0134869109dcb1.dip0.t-ipconnect.de. [2003:c8:b703:3600:b01:3486:9109:dcb1]) by smtp.gmail.com with ESMTPSA id cy24-20020a0564021c9800b00566850548fcsm7951059edb.20.2024.03.07.03.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 03:29:41 -0800 (PST) From: Thomas Schwinge To: Andrew Stubbs , gcc-patches@gcc.gnu.org Cc: Jakub Jelinek , Tobias Burnus Subject: GCN: Even with 'GCN_SUPPRESS_HOST_FALLBACK' set, failure to 'init_hsa_runtime_functions' is not fatal (was: [PATCH 7/7 libgomp,amdgcn] GCN Libgomp Plugin) In-Reply-To: <8c5112624e3cd17dd478d0ca5a59b2d24d1b16a5.1573560401.git.ams@codesourcery.com> References: <8c5112624e3cd17dd478d0ca5a59b2d24d1b16a5.1573560401.git.ams@codesourcery.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/29.1 (x86_64-pc-linux-gnu) Date: Thu, 07 Mar 2024 12:29:26 +0100 Message-ID: <87y1aue0vd.fsf@euler.schwinge.ddns.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! On 2019-11-12T13:29:16+0000, Andrew Stubbs wrote: > This patch contributes the GCN libgomp plugin, with the various > configure and make bits to go with it. An issue with libgomp GCN plugin 'GCN_SUPPRESS_HOST_FALLBACK' (which is different from the libgomp-level host-fallback execution): > --- /dev/null > +++ b/libgomp/plugin/plugin-gcn.c > +/* Flag to decide if the runtime should suppress a possible fallback to host > + execution. */ > + > +static bool suppress_host_fallback; > +static void > +init_environment_variables (void) > +{ > + [...] > + if (secure_getenv ("GCN_SUPPRESS_HOST_FALLBACK")) > + suppress_host_fallback = true; > + else > + suppress_host_fallback = false; > +/* Return true if the HSA runtime can run function FN_PTR. */ > + > +bool > +GOMP_OFFLOAD_can_run (void *fn_ptr) > +{ > + struct kernel_info *kernel = (struct kernel_info *) fn_ptr; > + > + init_kernel (kernel); > + if (kernel->initialization_failed) > + goto failure; > + > + return true; > + > +failure: > + if (suppress_host_fallback) > + GOMP_PLUGIN_fatal ("GCN host fallback has been suppressed"); > + GCN_WARNING ("GCN target cannot be launched, doing a host fallback\n"); > + return false; > +} This originates in the libgomp HSA plugin, where the idea was -- in my understanding -- that you wouldn't have device code available for all 'fn_ptr's, and in that case transparently (shared-memory system!) do host-fallback execution. Or, with 'GCN_SUPPRESS_HOST_FALLBACK' set, you'd get those diagnosed. This has then been copied into the libgomp GCN plugin (see above). However, is it really still applicable there; don't we assume that we're generating device code for all relevant functions? (I suppose everyone really is testing with 'GCN_SUPPRESS_HOST_FALLBACK' set?) Should we thus actually remove 'suppress_host_fallback' (that is, make it always-'true'), including removal of the 'can_run' hook? (I suppose that even in a future shared-memory "GCN" configuration, we're not expecting to use this again; expecting always-'true' for 'can_run'?) Now my actual issue: the libgomp GCN plugin then invented an additional use of 'GCN_SUPPRESS_HOST_FALLBACK': > +/* Initialize hsa_context if it has not already been done. > + Return TRUE on success. */ > + > +static bool > +init_hsa_context (void) > +{ > + hsa_status_t status; > + int agent_index = 0; > + > + if (hsa_context.initialized) > + return true; > + init_environment_variables (); > + if (!init_hsa_runtime_functions ()) > + { > + GCN_WARNING ("Run-time could not be dynamically opened\n"); > + if (suppress_host_fallback) > + GOMP_PLUGIN_fatal ("GCN host fallback has been suppressed"); > + return false; > + } That is, if 'GCN_SUPPRESS_HOST_FALLBACK' is (routinely) set (for its original purpose), and you have the libgomp GCN plugin configured, but don't have 'libhsa-runtime64.so.1' available, you run into a fatal error. The libgomp nvptx plugin in such cases silently disables the plugin/device (and thus lets libgomp proper do its thing), and I propose we do the same here. OK to push the attached "GCN: Even with 'GCN_SUPPRESS_HOST_FALLBACK' set, failure to 'init_hsa_runtime_functions' is not fatal"? Grüße Thomas From f037d2d8274940f042633a0ecb18a53942c075f5 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 7 Mar 2024 10:43:15 +0100 Subject: [PATCH] GCN: Even with 'GCN_SUPPRESS_HOST_FALLBACK' set, failure to 'init_hsa_runtime_functions' is not fatal 'GCN_SUPPRESS_HOST_FALLBACK' controls the libgomp GCN plugin's capability to transparently use host-fallback execution for certain device functions; it shouldn't control failure of libgomp GCN plugin initialization (which libgomp handles fine: triggering use of a different plugin/device, or general host-fallback execution, or fatal error, as applicable). libgomp/ * plugin/plugin-gcn.c (init_hsa_context): Even with 'GCN_SUPPRESS_HOST_FALLBACK' set, failure to 'init_hsa_runtime_functions' is not fatal. --- libgomp/plugin/plugin-gcn.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index 2771123252a..464164afb03 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -1524,8 +1524,6 @@ init_hsa_context (void) if (!init_hsa_runtime_functions ()) { GCN_WARNING ("Run-time could not be dynamically opened\n"); - if (suppress_host_fallback) - GOMP_PLUGIN_fatal ("GCN host fallback has been suppressed"); return false; } status = hsa_fns.hsa_init_fn (); -- 2.34.1