From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13570 invoked by alias); 30 Oct 2019 15:48:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 13556 invoked by uid 89); 30 Oct 2019 15:48:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=diagnosed, libgomps, var1, libgomp's X-HELO: esa3.mentor.iphmx.com Received: from esa3.mentor.iphmx.com (HELO esa3.mentor.iphmx.com) (68.232.137.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Oct 2019 15:48:52 +0000 IronPort-SDR: o6HPBLV+Y25nJmDsAZiXPFPboS0o0CM9S1DwwoVAvZcf/x8HHdE1L/RxIbWsGThBk6v6K4CmoC oPCo3d7po3a8PdjW9FqyHfhNN+0Y6RTGCVx41Sk0Jwyn8ZIcrUPcwMJ5N2dtb51L8g2+H7dqJX 028+uOA8km165YLGDLCATN3I23cgXcRG4oqhIQMu/+1JSmcR0YccplT2FzM930odbgSL/XTyyI wOehZSk/ckD2ZEVHh9kTmQVmy/6OujUoypaBjtQUlTFUN4qc1dleGNt0GzdpmGU+EbrB205vDk bfs= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 30 Oct 2019 07:48:50 -0800 IronPort-SDR: 5t7lvvS8dEwIjTqxVY1pUeKfWOjiwhnl5USgF6mJwM9J0UH1zut/ld43TnJB9YokClDYEKGbCo Sovviu9n33tqa5L0nkrNLyaRWUNVLGx6ECpbEh5ieIJDjY/enmwyCL9fDuBorvVWymqIWTuW+s SZjlFdihnEBpKz/ZvUoYEyukwHh26a9HDAF0r9PEZDSdIJZ6JnZ2EmEWTG96dkhIrAzj9QYw6c smG8eFJ8cUsE6JMiTVuEibm/ASwR7YHm8qxq+YYZxUGUVjGkIi+uJKscwASDnOlGUrjK8CKN66 xPY= Subject: Re: [Patch][Fortran/OpenMP] Don't create "alloc:" for 'target exit data' To: Jakub Jelinek , Tobias Burnus CC: gcc-patches , fortran References: <7a5f39e8-a33b-048a-f9c1-1355b941771e@codesourcery.com> <20191030101231.GS4650@tucnak> From: Tobias Burnus Message-ID: <444d3946-bad9-89bc-8cb5-475e8b9309ca@codesourcery.com> Date: Wed, 30 Oct 2019 15:50:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <20191030101231.GS4650@tucnak> Content-Type: multipart/mixed; boundary="------------6BA4B66A641CD2140D071A21" Return-Path: tobias@codesourcery.com X-IsSubscribed: yes X-SW-Source: 2019-10/txt/msg02152.txt.bz2 --------------6BA4B66A641CD2140D071A21 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-length: 1506 On 10/30/19 11:12 AM, Jakub Jelinek wrote: > I believe it is easier to handle it at the same spot as we do it e.g. > for C/C++ pointer attachments (where we create the same clauses > regardless of the exact construct and then drop them later), in > particular in gimplify_scan_omp_clauses. […] I concur. Semantically, it is not identical – but I think still okay. For 'omp exit data', 'to:'/'alloc:' mapping does not make sense and it not handled in libgomp's gomp_exit_data. Hence, I exclude GOMP_MAP_POINTER (dump: 'alloc:') and GOMP_MAP_TO_PSET (dump: 'to:'). – Those are only internally used, hence, user-specified 'alloc:' will get diagnosed. ['delete:'/'release:' in other directives than 'exit data' doesn't make much sense. Other directives accept it but their libgomp function silently ignore it.] 'omp update': The gomp_update function only handles GOMP_MAP_COPY_TO_P and GOMP_MAP_COPY_FROM_P (and silently ignores others). Both macros have !((X) & GOMP_MAP_FLAG_SPECIAL). Hence, we can save a few bytes and avoid calling 'omp update' with GOMP_MAP_POINTER and GOMP_MAP_TO_PSET. [TO_PSET only appears in gfc_trans_omp_clauses (once); POINTER appears there and in gfc_omp_finish_clause and in c/c-typeck.c's handle_omp_array_sections but only if "(ort != C_ORT_OMP && ort != C_ORT_ACC)".] I moved trans-openmp.c change to gimplify.c and left the test case unchanged. Then, I bootstrapped on a non-offloading system and regtested it also with a nvptx system. Tobias --------------6BA4B66A641CD2140D071A21 Content-Type: text/x-patch; charset="UTF-8"; name="exit-target-data-v3.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="exit-target-data-v3.diff" Content-length: 4332 gcc/ * gimplify.c (gimplify_scan_omp_clauses): Remove FE-generated GOMP_MAP_TO_PSET and GOMP_MAP_POINTER mapping for 'target update' and 'target exit data'. libgomp/ * testsuite/libgomp.fortran/target9.f90: New. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index fdf6b695003..12ed3f8eb21 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -8590,6 +8590,17 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, default: break; } + /* For Fortran, not only the pointer to the data is mapped but also + the address of the pointer, the array descriptor etc.; for + 'exit data' - and in particular for 'delete:' - having an 'alloc:' + does not make sense. Likewise, for 'update' only transferring the + data itself is needed as the rest has been handled in previous + directives. */ + if ((code == OMP_TARGET_EXIT_DATA || code == OMP_TARGET_UPDATE) + && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER + || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_TO_PSET)) + remove = true; + if (remove) break; if (DECL_P (decl) && outer_ctx && (region_type & ORT_ACC)) diff --git a/libgomp/testsuite/libgomp.fortran/target9.f90 b/libgomp/testsuite/libgomp.fortran/target9.f90 new file mode 100644 index 00000000000..91d60a33307 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/target9.f90 @@ -0,0 +1,123 @@ +! { dg-require-effective-target offload_device_nonshared_as } */ + +module target_test + implicit none (type, external) + integer, parameter :: N = 40 + integer :: sum + integer :: var1 = 1 + integer :: var2 = 2 + + !$omp declare target to(D) + integer :: D(N) = 0 +contains + subroutine enter_data (X) + integer :: X(:) + !$omp target enter data map(to: var1, var2, X) map(alloc: sum) + end subroutine enter_data + + subroutine exit_data_0 (D) + integer :: D(N) + !$omp target exit data map(delete: D) + end subroutine exit_data_0 + + subroutine exit_data_1 () + !$omp target exit data map(from: var1) + end subroutine exit_data_1 + + subroutine exit_data_2 (X) + integer :: X(N) + !$omp target exit data map(from: var2) map(release: X, sum) + end subroutine exit_data_2 + + subroutine exit_data_3 (p, idx) + integer :: p(:) + integer, value :: idx + !$omp target exit data map(from: p(idx)) + end subroutine exit_data_3 + + subroutine test_nested () + integer :: X, Y, Z + X = 0 + Y = 0 + Z = 0 + + !$omp target data map(from: X, Y, Z) + !$omp target data map(from: X, Y, Z) + !$omp target map(from: X, Y, Z) + X = 1337 + Y = 1337 + Z = 1337 + !$omp end target + if (X /= 0) stop 11 + if (Y /= 0) stop 12 + if (Z /= 0) stop 13 + + !$omp target exit data map(from: X) map(release: Y) + if (X /= 0) stop 14 + if (Y /= 0) stop 15 + + !$omp target exit data map(release: Y) map(delete: Z) + if (Y /= 0) stop 16 + if (Z /= 0) stop 17 + !$omp end target data + if (X /= 1337) stop 18 + if (Y /= 0) stop 19 + if (Z /= 0) stop 20 + + !$omp target map(from: X) + X = 2448 + !$omp end target + if (X /= 2448) stop 21 + if (Y /= 0) stop 22 + if (Z /= 0) stop 23 + + X = 4896 + !$omp end target data + if (X /= 4896) stop 24 + if (Y /= 0) stop 25 + if (Z /= 0) stop 26 + end subroutine test_nested +end module target_test + +program main + use target_test + implicit none (type, external) + + integer, allocatable :: X(:) + integer, pointer, contiguous :: Y(:) + + + allocate(X(N), Y(N)) + X(10) = 10 + Y(20) = 20 + call enter_data (X) + + call exit_data_0 (D) ! This should have no effect on D. + + !$omp target map(alloc: var1, var2, X) map(to: Y) map(always, from: sum) + var1 = var1 + X(10) + var2 = var2 + Y(20) + sum = var1 + var2 + D(sum) = D(sum) + 1 + !$omp end target + + if (var1 /= 1) stop 1 + if (var2 /= 2) stop 2 + if (sum /= 33) stop 3 + + call exit_data_1 () + if (var1 /= 11) stop 4 + if (var2 /= 2) stop 5 + + ! Increase refcount of already mapped X(1:N). + !$omp target enter data map(alloc: X(16:17)) + + call exit_data_2 (X) + if (var2 /= 22) stop 6 + + call exit_data_3 (X, 5) ! Unmap X(1:N). + + deallocate (X, Y) + + call test_nested () +end program main --------------6BA4B66A641CD2140D071A21--