From patchwork Mon Feb 6 11:52:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 53195 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2188266wrn; Mon, 6 Feb 2023 03:52:51 -0800 (PST) X-Google-Smtp-Source: AK7set/8a5wkAoZHyFjMyFvZJgZrbdOndZtNLbJ7NAHzfMTZVw6A4FYEPXrylMKnQ5oOPSC4DbCt X-Received: by 2002:a05:6402:3488:b0:49d:9ff4:d82b with SMTP id v8-20020a056402348800b0049d9ff4d82bmr24856433edc.15.1675684371698; Mon, 06 Feb 2023 03:52:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675684371; cv=none; d=google.com; s=arc-20160816; b=bZSwiZoAhFgLoVa29cSCpi12IiWHi0GzKP12wTLyjlrPAByUq29tr85pXAsi3eAqz+ iUQMnCnCAKyvWZr08TaU5Pa4vueQCLvLmZNiXeEOHZwoP7Biein/oMMuLikfCIhZuDcR DmasCAblOFtqfVpeEJSEslCh32+Eas4w70xRrwTl9bT1Q8rv7DS9rZOW2MyuvyakOYZr OCtJ7KUKWNHc5oDWsJtTfsClQfhJySymQMRySI+Bk0Z4siV6XrFDVWfUSj79dCr2Yqlp yLd0TgOLVC1/GD5kEdn6GK7IrfrLKPgBZf3ipOuozIbTX1N3/hISYb9gKktZfsw4cf74 PDag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=2CJc6CmSZqRVKPcMWE+1//eEC2ES07/Sh/xtu8lOoQY=; b=EKpOuk3MIEGgKIj0ra4aT6UBqSjW8gN78FjBN797ArrVZ2E7aiWm/hn+otsjm13T/m OTG7j3o9rQiYfZF3qOqRLeZs1OytnpWBqVL4o/lJpOWHnhV2flifvmygd6vwHxgHOaXl amUvhOs2Nwftl14HvClm/71CnUaoDzT4O1ZutC4klj+lbZXbjeRZNYt3ior761/ciihV 5n4TPtNHjqXR5WIUXR8zEA5ZHYoc49CNIADD/NH4Zh3TlKH5a8+xGMxzJ/boQagm+Lwq YXfLxLlSTfzAqgxhV6Bb5GXPMCIw8t70o0Bh0t1RWlP4mb2fjZScmoZ7O5eZkLxuFXiD t0mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cs11-20020a0564020c4b00b004a0e0ca3f4csi12847046edb.488.2023.02.06.03.52.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 03:52:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB83F385840F for ; Mon, 6 Feb 2023 11:52:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id CD8A43858D1E for ; Mon, 6 Feb 2023 11:52:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD8A43858D1E 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,276,1669104000"; d="diff'?scan'208";a="95786985" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 06 Feb 2023 03:52:20 -0800 IronPort-SDR: MrmRfQNQNRSlnT7toGRUbYtA9wRIC5hcu2HwA/3EHZ+0tgfxzdYItR4777mciBvoC/7mNc92Ma e/i6ntiLLMxuh15SkhO0SqIhxHOokrHA0jxmE3kgWKywgNjEoGZkU0AuoJSSSDGzioEoNp/uXj I28qU2Z2Zc+yn0omEaSpRTmBQpED6svYH+Z7BtVvL373cM3Al99UJcMmwqijp2HutBuApNzt9I Wz0xz3Cb/2ehjRof2jnAAVcCmps4PEmDh2efhIuOslyCkEC3CXcZWLb3hCP5dRGYcQsVwRMEJ7 42U= Message-ID: <85ecf108-8249-21a3-b9ee-23b89b6816bd@codesourcery.com> Date: Mon, 6 Feb 2023 12:52:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] libgomp: Fix reverse-offload for GOMP_MAP_TO_PSET X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757082416011772177?= X-GMAIL-MSGID: =?utf-8?q?1757082416011772177?= Seems as if I missed a GOMP_MAP_TO_PSET issue before. As nvptx is XFAILed before, I only found it when testing on AMDGCN. For an array-descriptor 'ai' variable, omplower has: map(tofrom:MEM [(integer(kind=4)[0:] *)D.4346] [len: D.4345]) map(to:ai [pointer set, len: 64]) map(alloc:ai.data [pointer assign, bias: 0]) The latter reaches GCC with the same address as 'ai' – i.e. the one of the array descriptor. This then needs to be dereferenced to get the address of the actual pointer. The patch assumes (and asserts) that 'ai.data' is part of the 'ai' such that I can use the host address of 'ai' to access the data. If that's not guaranteed, we have to find another way (e.g. another lookup). But so far it seems to hold and I have not seen a bias other than 0. With that patch, libgomp.fortran/reverse-offload-5.f90 now works with AMDGCN. OK? Any comments to the attached patch? Tobias ----------------- 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 libgomp: Fix reverse-offload for GOMP_MAP_TO_PSET libgomp/ * target.c (gomp_target_rev): Dereference ptr to get device address. * libgomp.fortran/reverse-offload-5.f90: Add test for unallocated allocatable. libgomp/target.c | 7 ++++++- libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libgomp/target.c b/libgomp/target.c index c1682caea13..5cdd845291a 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -3579,8 +3579,13 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr, } int k; n2 = NULL; - cdata[i].present = true; + /* Dereference devaddrs[j] to get the device addr. */ + assert (devaddrs[j]-sizes[j] == cdata[i].devaddr); + devaddrs[j] = *(uint64_t *) (devaddrs[i] + sizes[j]); + cdata[j].present = true; cdata[j].devaddr = devaddrs[j]; + if (devaddrs[j] == 0) + continue; k = gomp_map_cdata_lookup (cdata, devaddrs, kinds, sizes, j, devaddrs[j], devaddrs[j] + sizeof (void*), diff --git a/libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 b/libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 index ef7eb7bdd52..16810eb47de 100644 --- a/libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 +++ b/libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 @@ -24,7 +24,7 @@ s2 = 55 !$omp target map(to: A, A2, s1, s2) block - integer, allocatable :: ai(:), ai2(:), si1, si2 + integer, allocatable :: ai(:), ai2(:), ai3(:), si1, si2, si3 a = a * 2 a2 = a2 * 3 @@ -38,7 +38,7 @@ block !$omp target device (ancestor:1) & !$omp& map(to: A, s1, ai, si1) map(always, to: a2, s2) & - !$omp& map(tofrom: ai2, si2) + !$omp& map(tofrom: ai2, si2, ai3, si3) if (shared_mem) then if (any (a /= 2 * [1,2,3,4])) stop 1 if (s1 /= 4 * 532) stop 2 @@ -52,6 +52,7 @@ block if (any (ai2 /= [8,4,7,1])) stop 8 if (si1 /= 64) stop 9 if (si2 /= 765) stop 10 + if (allocated (ai3) .or. allocated(si3)) stop 26 a = a*3 a2 = a2*7 @@ -80,6 +81,7 @@ block endif if (any (ai2 /= 21 * [8,4,7,1])) stop 24 if (si2 /= 31 * 765) stop 25 + if (allocated (ai3) .or. allocated(si3)) stop 27 deallocate (ai, ai2, si1, si2) end block