From patchwork Thu Mar 7 11:53:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 86922 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 67C093857830 for ; Thu, 7 Mar 2024 11:54:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 8AB523858D35 for ; Thu, 7 Mar 2024 11:53:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8AB523858D35 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 8AB523858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709812421; cv=none; b=I/akpCBiautOKR/WUZxFJx7B7Ide0OhjvVGNJUmbJIPqpVMKT6LqgZYLapIZBxfNCBAjXFczf+BgEinR7+Kx067z7cPkqTBCMIZgYlLlojPrHqdBg0FRHBypn+BsrTtHZTITyeLgHnSXIUJVVytp0xjyPlR+CZVO+7njTRe7qQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709812421; c=relaxed/simple; bh=SBD3TYT0noC8NP5LrAwao48kD+jLYClZ8Q06Z3VN8YI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KrUhQ5Vdv3y0jmXlpU3fi8jv2aLbfVh4HYSqXVLMeVZ98Cdl8TirGFzSkZMmX1asb7WI6IIjEjqjxvxARwggXyfDeys1pM/C4pC21kAvHy+FJ5MZArWx61dDPvPscj8VXqDp8iRycp8dWMHKGi95sO7qhszkHBb9uZ+IOOovknY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33e1207bba1so515688f8f.1 for ; Thu, 07 Mar 2024 03:53:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1709812417; x=1710417217; 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=sdPup4g5Z09V11HEnhL/95BdGw/+BhNZslUHgCP7FK8=; b=fbhpnKvVYHTJ85fPAkry29B2NGrNAniuJtmNPtgK4IyJFyhYnAh60ly2ZEFXcCy3gf rdm3R5FUEieVB3AY6aJb0adViqM/3b1RrpCrfkga9RYpHFxXzFaoA+1x3SP6AyvyjPeQ EJgmO+zJCE1KOafW8nqenBF6oSQNv7YPSu1ln4O370tgvXfXXxNbQ+nSjGPsBnJl7RxV /WupjR07X+F9sthGfLhSV4US8yB0nuPWq6mMggah0A8Vqd3e3Q23d71uHmtkFcKMZEjy /nE1QPXbDZ9l17NZYyxi5AlKFVZjDlBkHZ6m5Bq+ei1g30G3047XEfrE7WW19EwMULwT rYqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709812417; x=1710417217; 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=sdPup4g5Z09V11HEnhL/95BdGw/+BhNZslUHgCP7FK8=; b=ESWR8QhZ7rfcNgeBHz2OLOfl0Z8Z5IDyUmIsb7FwRjwI94r25cq5xQkW63LNIQrG4v ueAfigBovQjK/ymUIJpyNEgnOy39EBVT4WDSqP8tNqfY8MwpFoXBGlgsgm7DHayyW1iF x4i0xiXggGM77iNIjTCHlocGkvI1sQrTeKqOuWUyg/UvFuw6I/QvC3F8AQSI8c2QfGLY aUoZVww8zWsmn0rqiSjitY8w1yn8thz0PUnVXe6DXfC3zq8JmI4ph5NPpWSeaStdO//b vvKgF6h2eYg0BRF3/yHkvndUet7RbikzHMGmr8WDoDY0PMpQwzZjTi1P9paEH0Eqewa+ uhnQ== X-Forwarded-Encrypted: i=1; AJvYcCVo/bQomqmlgfZkiCtfwDmmuYRfB+WeCLy1BhRhw3P4rrY94RLjD4VW2Mv6CRo26J/cGhoymmFdsj3lhrfQpQfNp0+eoM4YEg== X-Gm-Message-State: AOJu0YyCUx1S7sGeT+6k45aToox5HjPWjpz+p/HRGqx01ka23dGe/Qbv y/h56xLzHBBfnbEqd7QiF725ZYn79POwBqMzKPp8tvwDrKPJXN70p96AwdS9+Lw= X-Google-Smtp-Source: AGHT+IFmVZ54Am6DHlpSViEDeocGlF0Lvs/+tHeHbzNPDs91XEP77YCf1bNep3DpImEAloZij835kQ== X-Received: by 2002:a05:6000:81:b0:33e:1b4f:5dbb with SMTP id m1-20020a056000008100b0033e1b4f5dbbmr12589752wrx.3.1709812417162; Thu, 07 Mar 2024 03:53:37 -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 p18-20020adf9d92000000b0033e18f5714esm17999467wre.59.2024.03.07.03.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 03:53:36 -0800 (PST) From: Thomas Schwinge To: Jakub Jelinek , gcc-patches@gcc.gnu.org Cc: Tobias Burnus , Andrew Stubbs Subject: GCN, nvptx: Fatal error for missing symbols in 'libhsa-runtime64.so.1', 'libcuda.so.1' (was: [PATCH] Allow building GCC with PTX offloading even without CUDA being installed (gcc and nvptx-tools patches)) In-Reply-To: <20170113181123.GA1867@tucnak> References: <20170113181123.GA1867@tucnak> 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:53:31 +0100 Message-ID: <87v85ydzr8.fsf@euler.schwinge.ddns.net> MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_STOCKGEN, 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 Hi! On 2017-01-13T19:11:23+0100, Jakub Jelinek wrote: > [...] If the nvptx libgomp plugin is installed, but libcuda.so.1 > can't be found, then the plugin behaves as if there are no PTX devices > available. [...] ACK. > --- libgomp/plugin/plugin-nvptx.c.jj 2017-01-13 12:07:56.000000000 +0100 > +++ libgomp/plugin/plugin-nvptx.c 2017-01-13 18:00:39.693284346 +0100 > +/* -1 if init_cuda_lib has not been called yet, false > + if it has been and failed, true if it has been and succeeded. */ > +static char cuda_lib_inited = -1; > > - return desc; > +/* Dynamically load the CUDA runtime library and initialize function > + pointers, return false if unsuccessful, true if successful. */ > +static bool > +init_cuda_lib (void) > +{ > + if (cuda_lib_inited != -1) > + return cuda_lib_inited; > + const char *cuda_runtime_lib = "libcuda.so.1"; > + void *h = dlopen (cuda_runtime_lib, RTLD_LAZY); > + cuda_lib_inited = false; > + if (h == NULL) > + return false; ..., so this has to stay. > +# undef CUDA_ONE_CALL > +# define CUDA_ONE_CALL(call) CUDA_ONE_CALL_1 (call) > +# define CUDA_ONE_CALL_1(call) \ > + cuda_lib.call = dlsym (h, #call); \ > + if (cuda_lib.call == NULL) \ > + return false; However, this (missing symbol) I'd like to make a fatal error, instead of silently disabling the plugin/device. OK to push the attached "GCN, nvptx: Fatal error for missing symbols in 'libhsa-runtime64.so.1', 'libcuda.so.1'"? > + [...] > + cuda_lib_inited = true; > + return true; > } Grüße Thomas From 6a6520e01f7e7118b556683c2934f2c64c6dbc81 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 7 Mar 2024 12:31:52 +0100 Subject: [PATCH] GCN, nvptx: Fatal error for missing symbols in 'libhsa-runtime64.so.1', 'libcuda.so.1' If 'libhsa-runtime64.so.1', 'libcuda.so.1' are not available, the corresponding libgomp plugin/device gets disabled, as before. But if they are available, report any inconsistencies such as missing symbols, similar to how we fail in presence of other issues during device initialization. libgomp/ * plugin/plugin-gcn.c (init_hsa_runtime_functions): Fatal error for missing symbols. * plugin/plugin-nvptx.c (init_cuda_lib): Likewise. --- libgomp/plugin/plugin-gcn.c | 3 ++- libgomp/plugin/plugin-nvptx.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index 464164afb03..338225db6f4 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -1382,9 +1382,10 @@ init_hsa_runtime_functions (void) #define DLSYM_FN(function) \ hsa_fns.function##_fn = dlsym (handle, #function); \ if (hsa_fns.function##_fn == NULL) \ - return false; + GOMP_PLUGIN_fatal ("'%s' is missing '%s'", hsa_runtime_lib, #function); #define DLSYM_OPT_FN(function) \ hsa_fns.function##_fn = dlsym (handle, #function); + void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY); if (handle == NULL) return false; diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index 3fd6cd42fa6..ffb1db67d20 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -127,7 +127,7 @@ init_cuda_lib (void) # define CUDA_ONE_CALL_1(call, allow_null) \ cuda_lib.call = dlsym (h, #call); \ if (!allow_null && cuda_lib.call == NULL) \ - return false; + GOMP_PLUGIN_fatal ("'%s' is missing '%s'", cuda_runtime_lib, #call); #include "cuda-lib.def" # undef CUDA_ONE_CALL # undef CUDA_ONE_CALL_1 -- 2.34.1