From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from poseidon.ceid.upatras.gr (poseidon.ceid.upatras.gr [150.140.141.169]) by sourceware.org (Postfix) with ESMTPS id F1586385702F for ; Sat, 5 Sep 2020 14:35:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F1586385702F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ceid.upatras.gr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=venetis@ceid.upatras.gr Received: from mail.ceid.upatras.gr (mail.ceid.upatras.gr [10.1.0.174]) by poseidon.ceid.upatras.gr (Postfix) with ESMTP id BB6BC7FBC2 for ; Sat, 5 Sep 2020 17:35:43 +0300 (EEST) Received: from [192.168.1.6] (ppp079166232254.access.hol.gr [79.166.232.254]) (Authenticated sender: venetis) by mail.ceid.upatras.gr (Postfix) with ESMTPSA id C0B3820659 for ; Sat, 5 Sep 2020 17:35:42 +0300 (EEST) Subject: Re: gfortran/OpenMP/declare target link issue From: "Ioannis E. Venetis" To: gcc-help@gcc.gnu.org References: <3623842f-ac71-795f-4b0f-4cda4267258d@ceid.upatras.gr> Message-ID: <2cae69e9-66e3-523b-dfad-de7ceab59ad4@ceid.upatras.gr> Date: Sat, 5 Sep 2020 17:35:41 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <3623842f-ac71-795f-4b0f-4cda4267258d@ceid.upatras.gr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Antivirus: Avast (VPS 200905-0, 05/09/2020), Outbound message X-Antivirus-Status: Clean X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no 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-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Sep 2020 14:35:49 -0000 Any comment on this? Are global variables defined in a module and used in subroutines in the target region supported through the declare target link mechanism currently on gcc? If so, am I doing something wrong on how to use that mechanism? If not, is there any other approach I could follow without too many changes in the code? In the real code I have about 20 such variables and the call tree in the target region goes up to 3 subroutines deep. Ioannis E. Venetis On 3/9/2020 9:36 μ.μ., Ioannis E. Venetis wrote: > Hello everyone, > > I have a larger program that I am trying to convert so that the > computationally intensive part will run on an NVidia GPU using OpenMP. > However, I am running into trouble when compiling the program. The > part of the program to run on the GPU contains calls to subroutines, > where variables declared in a separate module are used. This seems to > be creating issues. I have reduced the problem to the attached files. > > I compile as follows: > > gfortran test_link.f90 common_vars.f90 parameters.f90 -O0 -fopenmp > -Wall -Wextra -o test_link > > With the file test_link.f90 as attached, the program compiles and runs > without a problem. > > If I remove the comments for the subroutine TEST() and comment out > line 31 in test_link.f90 (the line "I = NR") the compilation gives the > following error: > > ptxas /tmp/ccw3FqJD.o, line 52; error   : Illegal operand type to > instruction 'ld' > ptxas /tmp/ccw3FqJD.o, line 52; error   : Unknown symbol > '__common_vars_MOD_nr$linkptr' > ptxas fatal   : Ptx assembly aborted due to errors > nvptx-as: ptxas returned 255 exit status > mkoffload: fatal error: > /home/myself/apps/gcc-10.2.0/bin/x86_64-pc-linux-gnu-accel-nvptx-none-gcc > returned 1 exit status > compilation terminated. > lto-wrapper: fatal error: > /home/myself/apps/gcc-10.2.0/libexec/gcc/x86_64-pc-linux-gnu/10.2.0//accel/nvptx-none/mkoffload > returned 1 exit status > compilation terminated. > /usr/bin/ld: error: lto-wrapper failed > collect2: error: ld returned 1 exit status > > Is this a bug in gfortran or have I misunderstood how DECLARE TARGET > LINK works in combination with using subroutines? > > And a last point: If I use -O3 during compilation the program compiles > and runs fine in both cases. I assume that TEST() is inlined in this > case and the error disappears? > > Any help to overcome this issue is more than welcome. > > Best regards, > > Ioannis E. Venetis > > PS1: The problem happens with gcc 10.2 that I compiled myself: > > $ ~/apps/gcc-10.2.0/bin/gfortran -v > Using built-in specs. > COLLECT_GCC=/home/myself/apps/gcc-10.2.0/bin/gfortran > COLLECT_LTO_WRAPPER=/home/myself/apps/gcc-10.2.0/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper > > OFFLOAD_TARGET_NAMES=nvptx-none > Target: x86_64-pc-linux-gnu > Configured with: ../gcc-10.2.0/configure > --enable-offload-targets=nvptx-none > --with-cuda-driver-include=/usr/local/cuda/include > --with-cuda-driver-lib=/usr/local/cuda/lib64 --disable-bootstrap > --disable-multilib --enable-languages=c,c++,fortran,lto > --prefix=/home/myself/apps/gcc-10.2.0 > Thread model: posix > Supported LTO compression algorithms: zlib > gcc version 10.2.0 (GCC) > > > PS2: Same problem also happens with gcc 9.3 as installed on Ubuntu > 16.04 from apt: > > $ gfortran -v > Using built-in specs. > COLLECT_GCC=gfortran > COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper > OFFLOAD_TARGET_NAMES=nvptx-none:hsa > OFFLOAD_TARGET_DEFAULT=1 > Target: x86_64-linux-gnu > Configured with: ../src/configure -v --with-pkgversion='Ubuntu > 9.3.0-10ubuntu2~16.04' > --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs > --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 > --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 > --program-prefix=x86_64-linux-gnu- --enable-shared > --enable-linker-build-id --libexecdir=/usr/lib > --without-included-gettext --enable-threads=posix --libdir=/usr/lib > --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug > --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new > --enable-gnu-unique-object --disable-vtable-verify --enable-plugin > --with-system-zlib --with-target-system-zlib=auto > --enable-objc-gc=auto --enable-multiarch --disable-werror > --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 > --enable-multilib --with-tune=generic > --enable-offload-targets=nvptx-none,hsa --without-cuda-driver > --enable-checking=release --build=x86_64-linux-gnu > --host=x86_64-linux-gnu --target=x86_64-linux-gnu > Thread model: posix > gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2~16.04) >