From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 6D242385B835 for ; Fri, 17 Apr 2020 15:55:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6D242385B835 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: Trrjo834O/IKb/NQekhox5l7uwEQi6es0+HkTf2II2UNNKtSeuW9gwTYHFNrHOz+JWyDE28Mcn kE9tcThVZiU8Qyuhq3juhOryukdyA0VBEj6nzUnR5N5LW5CrAQfCDr0aPwGfwxmjL7K8ol7at8 waOXE6UXxBJ1UgrfOd50h6tKULbEE/qNi+T0PCP7HG//y2CQbAd9DaH8cqprWjz7i2mk4s7X9m 3MzDodfynJU4d+0WgG2sSFj69uWnmTGIOq8Kfns9XSTizRG8Z059hysGSOlpcyhsFQ1XcaF5Kl /HQ= X-IronPort-AV: E=Sophos;i="5.72,395,1580803200"; d="f90'?scan'208";a="47829799" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 17 Apr 2020 07:55:06 -0800 IronPort-SDR: +WvDy3im3qZiZgHBzDL+EMyHwTdO9CVM75Q696kNscULTLQ2a+GFhIh80U2vpW4kA2n+vRBU85 GM6KW2I6aa70J5DOdtfWbRo82rnPgvKkrLk0xtViV+FS4JBhKIObQgBrrr/CvEq6kS/lO62CHx +b4V9gg59H8YaJDo1v83Aln75AX4Z2fN9XKXoHA2mbVY9hhU3hTj/zkC30XjeiI3mf/Ak5ODBf S8EqC7fxvbjQca1l2u5FTNGu0pcoA2qSUW47BWm8WZA2fYk4q92JqY501g+C/By8el0b4UB3I7 W9w= To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch][OpenMP] Fix 'omp exit data' for Fortran arrays (PR 94635) Message-ID: <1cef2b3b-f03f-888a-050e-e80176ad41d4@codesourcery.com> Date: Fri, 17 Apr 2020 17:54:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5571D4F012B0056834B933AF" Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , X-List-Received-Date: Fri, 17 Apr 2020 15:55:23 -0000 --------------5571D4F012B0056834B933AF Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable It turned out that doing omp enter data map(alloc:FortranArray) omp exit data map(delete:FortranArray) left the array descriptor (fortranarray [as opposed to fortranarray.data]) on the device. (cf. -fdump-tree-omplower in the PR.) Mapping FortranArray again (e.g. "map(tofrom:FortranArray)") then failed by returning garbage. This patch now removes the descriptor with 'data exit', which was passed as MAP_TO_PSET clause to the middle end, but got removed. Instead, the clause is now turned into MAP_DELETE. Build on x86-64-gnu-linux and tested without and with AMDGCN as offloading device. OK for the trunk? Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstra=C3=9Fe 201, 80634 M=C3=BCnch= en / Germany Registergericht M=C3=BCnchen HRB 106955, Gesch=C3=A4ftsf=C3=BChrer: Thomas = Heurung, Alexander Walter --------------5571D4F012B0056834B933AF Content-Type: text/x-fortran; charset="UTF-8"; name="test_target_enter_exit_data_allocate_array_alloc_delete.F90" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="test_target_enter_exit_data_allocate_array_alloc_delete.F90" !===--test_target_enter_exit_data_allocate_array_alloc_delete.F90 - alloc/delete--===! ! ! OpenMP API Version 4.5 Nov 2015 ! ! This tests covers the target enter/exit data with the ! map(alloc/delete) modifiers respectively, for arrays that have the ! allocatable modifier and that are dynamically generated. ! !!===----------------------------------------------------------------------===! #include "ompvv.F90" #define N 20 PROGRAM tests_target_enter_exit_data_allocate_array_alloc USE iso_fortran_env USE ompvv_lib USE omp_lib implicit none INTEGER, ALLOCATABLE, DIMENSION(:) :: my1DPtr INTEGER, ALLOCATABLE, DIMENSION(:,:) :: my2DPtr INTEGER, ALLOCATABLE, DIMENSION(:,:,:) :: my3DPtr ! Helper arrays INTEGER, DIMENSION(N) :: my1DArr INTEGER, DIMENSION(N,N) :: my2DArr INTEGER, DIMENSION(N,N,N) :: my3DArr ! Helper functions LOGICAL :: isSharedEnv CHARACTER (len = 400) :: helperMsg INTEGER :: errors, i OMPVV_TEST_OFFLOADING OMPVV_TEST_AND_SET_SHARED_ENVIRONMENT(isSharedEnv) WRITE(helperMsg, *) "Omitting part of the test due to & &shared data environment" OMPVV_WARNING_IF(isSharedEnv, helperMsg) OMPVV_TEST_VERBOSE(test_allocate_array1D_map_alloc() .ne. 0) OMPVV_TEST_VERBOSE(test_allocate_array2D_map_alloc() .ne. 0) OMPVV_TEST_VERBOSE(test_allocate_array3D_map_alloc() .ne. 0) OMPVV_REPORT_AND_RETURN() CONTAINS ! 1D Array test INTEGER FUNCTION test_allocate_array1D_map_alloc() OMPVV_INFOMSG("Testing map alloc/delete allocated 1D array") errors = 0 ! Allocate the arrays allocate(my1DPtr(N)) ! initialize my1DPtr(:) = 0 ! Mapping the array !$omp target enter data map(alloc: my1DPtr(:)) ! Assign a value to the allocated space !$omp target my1DPtr(:) = (/ (i , i = 1,N) /) !$omp end target ! Confirm mapping with target region !$omp target map(from: my1DArr) my1DArr = my1DPtr !$omp end target IF (.NOT. isSharedEnv) THEN ! Make sure data does not get transfered over the host OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my1DPtr /= 0)) END IF OMPVV_TEST_AND_SET_VERBOSE(errors, SUM(my1DArr) /= ((N*(N+1)/2))) ! Asign a host value my1DPtr(:) = 10 !$omp target exit data map(delete: my1DPtr(:)) ! Check if I can transfer data with a map(tofrom:) !$omp target map(from: my1DArr) map(tofrom: my1DPtr(:)) my1DArr = my1DPtr my1DPtr(:) = 20 !$omp end target ! test that the values are the expected ones OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my1DPtr /= 20)) OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my1DArr /= 10)) deallocate(my1DPtr) test_allocate_array1D_map_alloc = errors END FUNCTION test_allocate_array1D_map_alloc ! 2D Array test INTEGER FUNCTION test_allocate_array2D_map_alloc() OMPVV_INFOMSG("Testing map alloc/delete allocated 2D array") errors = 0 ! Allocate the arrays allocate(my2DPtr(N,N)) ! initialize my2DPtr(:,:) = 0 ! Mapping the array !$omp target enter data map(alloc: my2DPtr(:,:)) ! Assign a value to the allocated space !$omp target my2DPtr(:,:) = RESHAPE((/ (i , i = 1,N**2) /), (/ N,N /)) !$omp end target ! Confirm mapping with target region !$omp target map(from: my2DArr) my2DArr = my2DPtr !$omp end target IF (.NOT. isSharedEnv) THEN OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my2DPtr /= 0)) END IF OMPVV_TEST_AND_SET_VERBOSE(errors, SUM(my2DArr) /= ((N**2*(N**2+1)/2))) ! Asign a host value my2DPtr(:,:) = 10 !$omp target exit data map(delete: my2DPtr(:,:)) ! Check if I can transfer data with a map(tofrom:) !$omp target map(from: my2DArr) map(tofrom: my2DPtr(:,:)) my2DArr = my2DPtr my2DPtr(:,:) = 20 !$omp end target ! test that the values are the expected ones OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my2DPtr /= 20)) OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my2DArr /= 10)) deallocate(my2DPtr) test_allocate_array2D_map_alloc = errors END FUNCTION test_allocate_array2D_map_alloc ! 3D Array test INTEGER FUNCTION test_allocate_array3D_map_alloc() OMPVV_INFOMSG("Testing map alloc/delete allocated 3D array") errors = 0 ! Allocate the arrays allocate(my3DPtr(N,N,N)) ! initialize my3DPtr(:,:,:) = 0 ! Mapping the array !$omp target enter data map(alloc: my3DPtr(:,:,:)) ! Assign a value to the allocated space !$omp target my3DPtr(:,:,:) = RESHAPE((/ (i , i = 1,N**3) /), (/ N,N,N /)) !$omp end target ! Confirm mapping with target region !$omp target map(from: my3DArr) my3DArr = my3DPtr !$omp end target IF (.NOT. isSharedEnv) THEN OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my3DPtr /= 0)) END IF OMPVV_TEST_AND_SET_VERBOSE(errors, SUM(my3DArr) /= ((N**3*(N**3+1)/2))) ! Asign a host value my3DPtr(:,:,:) = 10 !$omp target exit data map(delete: my3DPtr(:,:,:)) ! Check if I can transfer data with a map(tofrom:) !$omp target map(from: my3DArr) map(tofrom: my3DPtr(:,:,:)) my3DArr = my3DPtr my3DPtr(:,:,:) = 20 !$omp end target ! test that the values are the expected ones OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my3DPtr /= 20)) OMPVV_TEST_AND_SET_VERBOSE(errors, ANY(my3DArr /= 10)) deallocate(my3DPtr) test_allocate_array3D_map_alloc = errors END FUNCTION test_allocate_array3D_map_alloc END PROGRAM tests_target_enter_exit_data_allocate_array_alloc --------------5571D4F012B0056834B933AF--