From patchwork Fri Jun 28 10:24:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 1953877 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=xCKODTyv; 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 4W9WrK4Hj6z20X6 for ; Fri, 28 Jun 2024 20:29:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C50FC382EF3D for ; Fri, 28 Jun 2024 10:29:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 6F420382DB26 for ; Fri, 28 Jun 2024 10:25:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F420382DB26 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 6F420382DB26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719570306; cv=none; b=KuqOWEWuq6LBu0v0+3dDLN//3y6uTc49wWONmdWcN+35th2xsyTyJSoAK4a5WxTelKf1u66cqOwRyfBmlPiPGwqcQ5KUGDzb44gjU48XC6O4apE7PHMXsp3t5DcFPwmnhCA2eLuFPyRw/n/x3OYAA0+7yokNxN0sNPzmVpAeEw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719570306; c=relaxed/simple; bh=wOpk4zq128qr1C8kWe+WEmvda2ZjDp+paQZgvic21o4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VFeW7cw9r8Q3A81PhlmzXrFYoAGIxgmAtxjUAUk/Y8dytkJeNJlmT7uuQCpj9Fs14PR3NQ+DEli+G57vkRZoq8msPC5AtHb2Q1J10039yBXodHjOX24zt16cvUmgaewGVmoPpFwAGo7HNpc9YP/+gic+nRgMY0mX0wsdL/dHaQY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52cd87277d8so432205e87.2 for ; Fri, 28 Jun 2024 03:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1719570302; x=1720175102; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x8XVglCuiVWde/pZQlz+DF2BlTi4+IBZcC9dk56y9Y4=; b=xCKODTyvNKT1cM6wvAfmqCukbdTuNMFWMk42/k14PVEQCYS84l/s6/YmsyWe0XVwop ALeSIwn1Uc8mWQ5SBQlk9MoUY7vSo2UtKe4VowEOE+BjRi5ijsQPt521KnWFwyXjEZ7W MXJ+iTS4P44zUZFtEVXlL8IJwycRd7wTAoefq3rySpCDgpoP4wVWE2u41le+Al2p0BsA LdvJgJe/NI+yOc6qB9x2fbRcJGYaiw0Boxab/FrI3gNw5OXuBsQf8wIgQdsVF8WVAH87 pdpciCBT8z08JyNV+eer4QQBxRCDCnVS5qrYOTbsfvIHU4536EvFm73NzzKeyOlcM5hY pMVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719570302; x=1720175102; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x8XVglCuiVWde/pZQlz+DF2BlTi4+IBZcC9dk56y9Y4=; b=XApcLjjzmcGLam/qhGrGgOvqTSZCZNssyGgFDL9LgEpXM+AHnAQSETVE3bMrYgr7GS LrfnZDEc4negCiNbXnbjetqMbVf55kIEoiEIeskotnSe26zKLrkMtYLqSTJtQuj/qgBh XYRmTRpfSzEPRkqj8npnQJgYWRyX3hsgfiKoyQ0tLNoDUBfVoYDGozzC3f6QKssf0Eqo OcMWxUp/+S/OT+LLA/HBKW6CSzIfPnVDNx5nWD9m8UAc/9yk3r1wHU+ZuhCdW1TQYDxR kob4aaLxsuP6sDezvqbylnUErYzfCajolb7Ofp7L5W8HYxLHrcUrB+EeaiPUMq+HZGaq dGDw== X-Gm-Message-State: AOJu0Yw+Zc6rsSNxD/y6ZyFKsEWTeDkFuzkLRmYXNBuARkqotUfXGBwh q78nEOP34LdSJCuvtP3T+wkktsMugg8G8fV0SffI30sHKYFYYc8Q/SCjxWnb0Rcfe3CWQ7KrRnh 9ZE0= X-Google-Smtp-Source: AGHT+IGXzjoith0j+N8bib1mMPOI2Q7bqc+3uqDr+bPmRA44ZnqOVA0gKXjwqizsjnl6vhTDVNGEpQ== X-Received: by 2002:a05:6512:4884:b0:52c:896f:930d with SMTP id 2adb3069b0e04-52ce18613d1mr9767538e87.57.1719570301608; Fri, 28 Jun 2024 03:25:01 -0700 (PDT) Received: from arnold.baylibre (88-127-129-70.subs.proxad.net. [88.127.129.70]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4256b061006sm28014945e9.22.2024.06.28.03.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 03:25:01 -0700 (PDT) From: Andrew Stubbs To: gcc-patches@gcc.gnu.org Cc: tburnus@baylibre.com, jakub@redhat.com Subject: [PATCH v2 8/8] libgomp: Map omp_default_mem_space to USM Date: Fri, 28 Jun 2024 10:24:49 +0000 Message-ID: <20240628102449.562467-9-ams@baylibre.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240628102449.562467-1-ams@baylibre.com> References: <20240628102449.562467-1-ams@baylibre.com> 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 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 When unified shared memory is required, the default memory space should also be unified. libgomp/ChangeLog: * config/linux/allocator.c (linux_memspace_alloc): Check omp_requires_mask. (linux_memspace_calloc): Likewise. (linux_memspace_free): Likewise. (linux_memspace_realloc): Likewise. * libgomp.h (omp_requires_mask): New extern. * target.c (omp_requires_mask): Remove static. * testsuite/libgomp.c-c++-common/target-implicit-map-4.c: Add NO_USM_STACK conditional code. --- libgomp/config/linux/allocator.c | 16 ++++++++++++---- libgomp/libgomp.h | 1 + libgomp/target.c | 2 +- .../libgomp.c-c++-common/target-implicit-map-4.c | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/libgomp/config/linux/allocator.c b/libgomp/config/linux/allocator.c index 81d2877b8f1..a026f49be16 100644 --- a/libgomp/config/linux/allocator.c +++ b/libgomp/config/linux/allocator.c @@ -101,7 +101,9 @@ linux_memspace_alloc (omp_memspace_handle_t memspace, size_t size, int pin, /* Explicit pinning may not be required. */ pin = pin && !always_pinned_mode; - if (memspace == ompx_gnu_unified_shared_mem_space) + if (memspace == ompx_gnu_unified_shared_mem_space + || (memspace == omp_default_mem_space + && (omp_requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY))) addr = gomp_usm_alloc (size); else if (pin) { @@ -194,7 +196,9 @@ linux_memspace_calloc (omp_memspace_handle_t memspace, size_t size, int pin) /* Explicit pinning may not be required. */ pin = pin && !always_pinned_mode; - if (memspace == ompx_gnu_unified_shared_mem_space) + if (memspace == ompx_gnu_unified_shared_mem_space + || (memspace == omp_default_mem_space + && (omp_requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY))) { void *ret = gomp_usm_alloc (size); memset (ret, 0, size); @@ -216,7 +220,9 @@ linux_memspace_free (omp_memspace_handle_t memspace, void *addr, size_t size, /* Explicit pinning may not be required. */ pin = pin && !always_pinned_mode; - if (memspace == ompx_gnu_unified_shared_mem_space) + if (memspace == ompx_gnu_unified_shared_mem_space + || (memspace == omp_default_mem_space + && (omp_requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY))) gomp_usm_free (addr); else if (pin) { @@ -244,7 +250,9 @@ linux_memspace_realloc (omp_memspace_handle_t memspace, void *addr, /* Explicit pinning may not be required. */ pin = pin && !always_pinned_mode; - if (memspace == ompx_gnu_unified_shared_mem_space) + if (memspace == ompx_gnu_unified_shared_mem_space + || (memspace == omp_default_mem_space + && (omp_requires_mask & GOMP_REQUIRES_UNIFIED_SHARED_MEMORY))) /* Realloc is not implemented for USM. */ ; else if (oldpin && pin) diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index 707fcdb39d7..4c5c89c8454 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -1123,6 +1123,7 @@ extern int gomp_pause_host (void); /* target.c */ +extern int omp_requires_mask; extern void gomp_init_targets_once (void); extern int gomp_get_num_devices (void); extern bool gomp_target_task_fn (void *); diff --git a/libgomp/target.c b/libgomp/target.c index f0ee2c84197..455cac917c9 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -107,7 +107,7 @@ static int num_devices; static int num_devices_openmp; /* OpenMP requires mask. */ -static int omp_requires_mask; +int omp_requires_mask; /* Similar to gomp_realloc, but release register_lock before gomp_fatal. */ diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-implicit-map-4.c b/libgomp/testsuite/libgomp.c-c++-common/target-implicit-map-4.c index 2766312292b..de865352e9b 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/target-implicit-map-4.c +++ b/libgomp/testsuite/libgomp.c-c++-common/target-implicit-map-4.c @@ -6,6 +6,9 @@ /* { dg-skip-if "Not all devices allow USM" { offload_device_gcn && { ! omp_usm } } } */ +/* { dg-additional-options "-DNO_USM_STACK" { target offload_target_nvptx } } */ +/* { dg-additional-options "-DNO_USM_STACK" { target offload_target_amdgcn } } */ + #pragma omp requires unified_shared_memory /* Ensure that defaultmap(default : pointer) uses correct OpenMP 5.2 @@ -27,10 +30,23 @@ test_device (int dev) intptr_t ip = (intptr_t) p2; intptr_t ipa = (intptr_t) p2a; +#if NO_USM_STACK + int A_init[3] = {1,2,3}; + int B_init[5] = {4,5,6,7,8}; + int *A = (int*) malloc (sizeof (A_init)); + int *B = (int*) malloc (sizeof (B_init)); + int *p3 = &A[0]; + int *p3a = &B[0]; + + /* Not all USM supports stack variables. */ + __builtin_memcpy (A, A_init, sizeof (A_init)); + __builtin_memcpy (B, B_init, sizeof (B_init)); +#else int A[3] = {1,2,3}; int B[5] = {4,5,6,7,8}; int *p3 = &A[0]; int *p3a = &B[0]; +#endif const omp_alloctrait_t traits[] = { { omp_atk_alignment, 128 },