From patchwork Thu Mar 7 12:38:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 86925 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 8C3413857833 for ; Thu, 7 Mar 2024 12:38:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 408F13858D35 for ; Thu, 7 Mar 2024 12:38:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 408F13858D35 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 408F13858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709815110; cv=none; b=WJ/ymrYQO5335o6tU3pfekwgmsJBhb9j40cF4WFHm2z+qmWGGuOcK2I94WXsxjz8zhSHmwzZmnFAMCKxo9whtUUz+linAYzha5g7tajC29ewyj+u7dYBVWRPl7/KVat8dTd+o9puSZ3XQXdXgQ9WBVZObS6QRLLOURWRK3EW78M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709815110; c=relaxed/simple; bh=LRU1Jum2Yr+ZbCnj1QUZWwJm96zK29u+l+tMRS3PmPo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GnpdEDy2aN2ndVKbQkWKvk34ceXx2S1D9w5RurIex65iAKULrBr29bFl4rmjo+gX+WXVTfSX0Tr/QkcpcP4cDEM4kj4DzO+PoEAXaPSe1jKrpjvhvb3v/CNgWiFds2AYi9f6XRUWNOxpCjkjQNSZBRGW9W46ENhd3VEsfUfvYps= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a44628725e3so117568866b.0 for ; Thu, 07 Mar 2024 04:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1709815107; x=1710419907; 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=48YZdEQTOHgNW/1Px2L/FHV1LoJn8HfXev6AQD0/l5c=; b=RtgKPYp6tXKQbEGkFz0lTE9IiI4/hdtwK5FBsQ2xI0OtgWejwUhHu/jK2wbmSt1we1 hQX8zn8R+GoKgBEgqJXioR4KOFyJ7nNQDOIQsOIhU977cvul8dT2wYikSftuxCsHuvND hsdil4Q3ZFc81uihf1TFb4oBdp9NAZhstKXhvysX/GLMSHglAhMG2CFtWanCVw7CdGD+ HVNLvTmcmh1stIzkMI7MH7CIFRGGsh2Q1HoCWqYSUA1RJlGMZbEGgvCO2PqZ+VFE9k+F 8WIVGpUWBL3ENdo0i4F1FBdZxNgm+mwCZjfoLeA7t/LrxYdPaPukz2md2fVwNw3Tnsn/ cHKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709815107; x=1710419907; 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=48YZdEQTOHgNW/1Px2L/FHV1LoJn8HfXev6AQD0/l5c=; b=o4fcRzukcqz6fzzws2lhyQrJNdohi4MAHW4MgH63/XiHhoBW8OrAx+JyEjHj4WtPxQ 7eWfRcyf9jtxATvl5P357kRlwrZNlhBTZRXLTe6iHTKvIb+cXSOnl5mZImdlwep4XriA 6IWlN5YEdgzbH1rgz4zvNvzQEYcfozT5AuEVYL0w0dvGrE2vlrQ+NGA+X6q7p7S/oAPV 1CJPvulnO2GlcIfgxuHqPISgJcQhBJS7JH4zc6thJ8JHAP+FxhdAoa7OVsWNwHS+H7nt ASLEUTLOGAUaf4o4RDzpZw7rdYcr9FDXdt+G4IWqFwZpj51Ovkjdwi1vx31KyKjRwOt7 T1iQ== X-Forwarded-Encrypted: i=1; AJvYcCWEfgctHDcxPIq30YuEIQsSHQJgKY48TSnl281C3SSGFfxsAMxF6WjF0WSersY/BTOsPeejEH76oM6ufA2+qk60LHM0/KPYFQ== X-Gm-Message-State: AOJu0YyiTvsElYa2ovV+Qqy0tX1XnLV0O0XBp9T0U9Z3CIKFhDMRKIk1 K79uSEfwegsmRDwnY/sarg/1cJzbAt6zDkC6ovxDX6mtsvE0r72IrYc5IIMqc1E= X-Google-Smtp-Source: AGHT+IErbgow6bk44d9/1+MA70ff9Ftb09/R7xyxae/jxvukrYfSmM0J7BvUyd5nyBNoJwbESxpQug== X-Received: by 2002:a17:906:54c7:b0:a41:3e39:b918 with SMTP id c7-20020a17090654c700b00a413e39b918mr12269797ejp.24.1709815106868; Thu, 07 Mar 2024 04:38:26 -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 af1-20020a170906998100b00a45aa7cb029sm2716768ejc.36.2024.03.07.04.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 04:38:26 -0800 (PST) From: Thomas Schwinge To: Tobias Burnus , gcc-patches@gcc.gnu.org Cc: Jakub Jelinek Subject: nvptx: 'cuDeviceGetCount' failure is fatal (was: [Patch] OpenMP: Move omp requires checks to libgomp) In-Reply-To: <07fec82a-41cf-fdc5-6307-c068dd95ef1a@mentor.com> References: <07fec82a-41cf-fdc5-6307-c068dd95ef1a@mentor.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 13:38:16 +0100 Message-ID: <87sf12dxon.fsf@euler.schwinge.ddns.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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+patchwork=sourceware.org@gcc.gnu.org Hi! On 2022-06-08T05:56:02+0200, Tobias Burnus wrote: > [...] On the libgomp side: The devices which do not fulfill the requirements are > now filtered out. [...] > --- a/libgomp/plugin/plugin-gcn.c > +++ b/libgomp/plugin/plugin-gcn.c > /* Return the number of GCN devices on the system. */ > > int > -GOMP_OFFLOAD_get_num_devices (void) > +GOMP_OFFLOAD_get_num_devices (unsigned int omp_requires_mask) > { > if (!init_hsa_context ()) > return 0; > + /* Return -1 if no omp_requires_mask cannot be fulfilled but > + devices were present. */ > + if (hsa_context.agent_count > 0 && omp_requires_mask != 0) > + return -1; > return hsa_context.agent_count; > } > --- a/libgomp/plugin/plugin-nvptx.c > +++ b/libgomp/plugin/plugin-nvptx.c > int > -GOMP_OFFLOAD_get_num_devices (void) > +GOMP_OFFLOAD_get_num_devices (unsigned int omp_requires_mask) > { > - return nvptx_get_num_devices (); > + int num_devices = nvptx_get_num_devices (); > + /* Return -1 if no omp_requires_mask cannot be fulfilled but > + devices were present. */ > + if (num_devices > 0 && omp_requires_mask != 0) > + return -1; > + return num_devices; > } > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -4132,8 +4183,19 @@ gomp_target_init (void) > > if (gomp_load_plugin_for_device (¤t_device, plugin_name)) > { > - new_num_devs = current_device.get_num_devices_func (); > - if (new_num_devs >= 1) > + new_num_devs = current_device.get_num_devices_func (requires_mask); > + if (new_num_devs < 0) > + { > + [...] > + } > + else if (new_num_devs >= 1) > { > /* Augment DEVICES and NUM_DEVICES. */ OK to push the attached "nvptx: 'cuDeviceGetCount' failure is fatal"? Grüße Thomas From 8090da93cb00e4aa47a8b21b6548d739b2cebc49 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 7 Mar 2024 13:18:23 +0100 Subject: [PATCH] nvptx: 'cuDeviceGetCount' failure is fatal Per commit 683f11843974f0bdf42f79cdcbb0c2b43c7b81b0 "OpenMP: Move omp requires checks to libgomp", we're now using 'return -1' from 'GOMP_OFFLOAD_get_num_devices' for 'omp_requires_mask' purposes. This missed that via 'nvptx_get_num_devices', we could also 'return -1' for 'cuDeviceGetCount' failure. Before, this meant (in 'gomp_target_init') to silently ignore the plugin/device -- which also has been doubtful behavior. Let's instead turn 'cuDeviceGetCount' failure into a fatal error, similar to other errors during device initialization. libgomp/ * plugin/plugin-nvptx.c (nvptx_get_num_devices): 'cuDeviceGetCount' failure is fatal. --- libgomp/plugin/plugin-nvptx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index ffb1db67d20..81b4a7f499a 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -630,7 +630,7 @@ nvptx_get_num_devices (void) } } - CUDA_CALL_ERET (-1, cuDeviceGetCount, &n); + CUDA_CALL_ASSERT (cuDeviceGetCount, &n); return n; } -- 2.34.1