From patchwork Thu Feb 16 21:24:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 1743953 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PHnz93SGrz23yJ for ; Fri, 17 Feb 2023 08:25:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6357F385B52C for ; Thu, 16 Feb 2023 21:25:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id E9B543858D33 for ; Thu, 16 Feb 2023 21:24:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E9B543858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.97,302,1669104000"; d="scan'208,223";a="98526833" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 16 Feb 2023 13:24:30 -0800 IronPort-SDR: 1ZDdQHMJg+cR5NVWqZsFH+g7XAoKp4sqfdGFCXYAQ6mbaiFVPGsYAonhzHQ6a8VveCJtN/xLFY WgxffcD+IDXvZedeQvxqe+Elq6Sh4HjRFzuoJDTWRWkLOE6i0secuWBhQEncBokyIX1QrJF6iU xTS0ZudWUNdG0amJwpXH2wQxOB5G8ao+kAEp5N6QD2M8OjGQ1JZtQJor4L7riqRjvGVArkG0zM rG5Bl/p4wDBxB7YJJKw6J1D0VrUIXzeg1V0KNNuYF6zjD07RhRuO60lIQVvxtceG04MMapDOe8 4kc= From: Thomas Schwinge To: Andrew Stubbs , CC: Hafiz Abid Qadeer Subject: [og12] Miscellaneous clean-up re OpenMP 'ompx_unified_shared_mem_space', 'ompx_host_mem_space' (was: [PATCH 3/5] openmp, nvptx: ompx_unified_shared_mem_alloc) In-Reply-To: <4417d508-f9b1-8bf2-308d-f1a824b47303@codesourcery.com> References: <20220308113059.688551-1-abidh@codesourcery.com> <20220308113059.688551-4-abidh@codesourcery.com> <871qmx1tzo.fsf@euler.schwinge.homeip.net> <4417d508-f9b1-8bf2-308d-f1a824b47303@codesourcery.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Thu, 16 Feb 2023 22:24:20 +0100 Message-ID: <87wn4hxq0r.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP 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.29 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 Sender: "Gcc-patches" Hi! On 2023-02-10T15:31:47+0000, Andrew Stubbs wrote: > On 10/02/2023 14:21, Thomas Schwinge wrote: >> Is the correct fix the following [...] > > Yes, [...] >>> --- a/libgomp/config/nvptx/allocator.c >>> +++ b/libgomp/config/nvptx/allocator.c >>> @@ -125,6 +125,8 @@ nvptx_memspace_alloc (omp_memspace_handle_t memspace, size_t size) >>> __atomic_store_n (&__nvptx_lowlat_heap_root, root.raw, MEMMODEL_RELEASE); >>> return result; >>> } >>> + else if (memspace == ompx_host_mem_space) >>> + return NULL; >>> else >>> return malloc (size); >>> } >>> @@ -145,6 +147,8 @@ nvptx_memspace_calloc (omp_memspace_handle_t memspace, size_t size) >>> >>> return result; >>> } >>> + else if (memspace == ompx_host_mem_space) >>> + return NULL; >>> else >>> return calloc (1, size); >>> } >>> @@ -354,6 +358,8 @@ nvptx_memspace_realloc (omp_memspace_handle_t memspace, void *addr, >>> } >>> return result; >>> } >>> + else if (memspace == ompx_host_mem_space) >>> + return NULL; >>> else >>> return realloc (addr, size); >>> } >> >> (I'd have added an explicit no-op (or, 'abort'?) to >> 'nvptx_memspace_free', but that's maybe just me...) ;-\ > > Why? The host memspace is just the regular heap, which can be a thing on > any device. It's an extension though so we can define it either way. My point was: for nvptx libgomp, all 'ompx_host_mem_space' allocator functions (cited above) 'return NULL', and it's a cheap check to verify that in 'nvptx_memspace_free'. >>> --- a/libgomp/libgomp.h >>> +++ b/libgomp/libgomp.h >> >>> +extern void * gomp_usm_alloc (size_t size, int device_num); >>> +extern void gomp_usm_free (void *device_ptr, int device_num); >>> +extern bool gomp_is_usm_ptr (void *ptr); >> >> 'gomp_is_usm_ptr' isn't defined/used anywhere; I'll remove it. > > I think I started that and then decided against. Thanks. These three combined, I've pushed to devel/omp/gcc-12 branch commit 23f52e49368d7b26a1b1a72d6bb903d31666e961 "Miscellaneous clean-up re OpenMP 'ompx_unified_shared_mem_space', 'ompx_host_mem_space'", see attached. >>> --- a/libgomp/target.c >>> +++ b/libgomp/target.c >> >>> @@ -3740,6 +3807,9 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device, >>> DLSYM (unload_image); >>> DLSYM (alloc); >>> DLSYM (free); >>> + DLSYM_OPT (usm_alloc, usm_alloc); >>> + DLSYM_OPT (usm_free, usm_free); >>> + DLSYM_OPT (is_usm_ptr, is_usm_ptr); >>> DLSYM (dev2host); >>> DLSYM (host2dev); >> >> As a sanity check, shouldn't we check that either none or all three of >> those are defined, like in the 'if (cuda && cuda != 4) { [error] }' check >> a bit further down? > > This is only going to happen when somebody writes a new plugin, and then > they'll discover very quickly that there are issues. I've wasted more > time writing this sentence than it's worth already. :) Eh. ;-) OK, outvoted. Grüße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From 23f52e49368d7b26a1b1a72d6bb903d31666e961 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 14 Feb 2023 17:10:57 +0100 Subject: [PATCH] Miscellaneous clean-up re OpenMP 'ompx_unified_shared_mem_space', 'ompx_host_mem_space' Clean-up for og12 commit 84914e197d91a67b3d27db0e4c69a433462983a5 "openmp, nvptx: ompx_unified_shared_mem_alloc". No functional change. libgomp/ * config/linux/allocator.c (linux_memspace_calloc): Elide (innocuous) duplicate 'if' condition. * config/nvptx/allocator.c (nvptx_memspace_free): Explicitly handle 'memspace == ompx_host_mem_space'. * libgomp.h (gomp_is_usm_ptr): Remove. --- libgomp/ChangeLog.omp | 6 ++++++ libgomp/config/linux/allocator.c | 3 +-- libgomp/config/nvptx/allocator.c | 4 ++++ libgomp/libgomp.h | 1 - 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index b667c72b8ca..1c4b1833c0b 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,5 +1,11 @@ 2023-02-16 Thomas Schwinge + * config/linux/allocator.c (linux_memspace_calloc): Elide + (innocuous) duplicate 'if' condition. + * config/nvptx/allocator.c (nvptx_memspace_free): Explicitly + handle 'memspace == ompx_host_mem_space'. + * libgomp.h (gomp_is_usm_ptr): Remove. + * basic-allocator.c (BASIC_ALLOC_YIELD): instead of '#deine', '#define' it. diff --git a/libgomp/config/linux/allocator.c b/libgomp/config/linux/allocator.c index 07af3a2821a..8a9171c36df 100644 --- a/libgomp/config/linux/allocator.c +++ b/libgomp/config/linux/allocator.c @@ -95,8 +95,7 @@ linux_memspace_calloc (omp_memspace_handle_t memspace, size_t size, int pin) memset (ret, 0, size); return ret; } - else if (memspace == ompx_unified_shared_mem_space - || pin) + else if (pin) return linux_memspace_alloc (memspace, size, pin); else return calloc (1, size); diff --git a/libgomp/config/nvptx/allocator.c b/libgomp/config/nvptx/allocator.c index 7c2a7463bf7..cbf86b8a2ec 100644 --- a/libgomp/config/nvptx/allocator.c +++ b/libgomp/config/nvptx/allocator.c @@ -42,6 +42,7 @@ chunks. */ #include "libgomp.h" +#include #include #define BASIC_ALLOC_PREFIX __nvptx_lowlat @@ -93,6 +94,9 @@ nvptx_memspace_free (omp_memspace_handle_t memspace, void *addr, size_t size) __nvptx_lowlat_free (shared_pool, addr, size); } + else if (memspace == ompx_host_mem_space) + /* Just verify what all allocator functions return. */ + assert (addr == NULL); else free (addr); } diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index d1e45cc584e..c001b468252 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -1133,7 +1133,6 @@ extern void gomp_target_rev (uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, void *); extern void * gomp_usm_alloc (size_t size, int device_num); extern void gomp_usm_free (void *device_ptr, int device_num); -extern bool gomp_is_usm_ptr (void *ptr); /* Splay tree definitions. */ typedef struct splay_tree_node_s *splay_tree_node; -- 2.25.1