当我编译单个cuda fortran代码时,编译器给我以下错误,
PGF90-F-0000-内部编译器错误。设备编译器退出并显示错误状态代码,并且
尝试在没有人字形的情况下调用全局子例程:增量
Arch Linux,pgf90 2013
代码如下:
module simple
contains
attributes (global) subroutine increment(a,b)
implicit none
integer, intent(inout) :: a(:)
integer , intent(in) :: b
integer :: i , n
n = size( a )
do i = 1 , n
a ( i ) = a ( i )+ b
end do
end subroutine increment
end module simple
program incrementTestCPU
use simple
implicit none
integer :: n = 256
integer :: a ( n ) , b
a = 1
b = 3
call increment ( a , b )
if ( any ( a /= 4)) then
write (* ,*) "pass"
else
write(*,*) "not passed"
end if
end program incrementTestCPU
最佳答案
您将其称为“cuda fortran”代码,但是从句法上讲,无论是最终要在主机(CPU)还是设备(GPU)上运行子例程,这在语法上都是不正确的。您不妨引用此blog post作为快速入门指南。
如果要在GPU上运行子例程increment
,则未正确调用它:
通话增量(a,b)
GPU子例程调用需要内核启动参数,这些参数包含在“triple chevron” <<<...>>>
语法中,该语法应放在increment
及其参数列表之间,如下所示:
call increment<<<1,1>>> ( a , b )
这会引起错误消息:
Attempt to call global subroutine without chevrons
相反,如果您打算在CPU上运行此子例程,而只是将其传递给CUDA fortran编译器,则在子例程中指定
global
属性是不正确的:attributes (global) subroutine increment(a,b)
以下是对代码的修改,该代码将在GPU上运行子例程,并使用PGI 14.9工具为我进行干净地编译:
$ cat test3.cuf
module simple
contains
attributes (global) subroutine increment(a,b)
implicit none
integer :: a(:)
integer, value :: b
integer :: i , n
n = size( a )
do i = 1 , n
a ( i ) = a ( i )+ b
end do
end subroutine increment
end module simple
program incrementTestCPU
use simple
use cudafor
implicit none
integer, parameter :: n = 256
integer, device :: a_d(n), b_d
integer :: a ( n ) , b
a = 1
b = 3
a_d = a
b_d = b
call increment<<<1,1>>> ( a_d , b_d )
a = a_d
if ( any ( a /= 4)) then
write (* ,*) "pass"
else
write(*,*) "not passed"
end if
end program incrementTestCPU
$ pgf90 -Mcuda -ta=nvidia,cc20,cuda6.5 -Minfo test3.cuf -o test3
incrementtestcpu:
23, Memory set idiom, loop replaced by call to __c_mset4
29, any reduction inlined
$ pgf90 --version
pgf90 14.9-0 64-bit target on x86-64 Linux -tp nehalem
The Portland Group - PGI Compilers and Tools
Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
$
如果要创建仅CPU版本,请从程序中删除所有CUDA Fortran语法。如果您仍然有困难,可以提出一个Fortran指导的问题,因为在那时,这不是CUDA问题。例如,以下(非CUDA)代码为我干净地编译:
module simple
contains
subroutine increment(a,b)
implicit none
integer, intent(inout) :: a(:)
integer , intent(in) :: b
integer :: i , n
n = size( a )
do i = 1 , n
a ( i ) = a ( i )+ b
end do
end subroutine increment
end module simple
program incrementTestCPU
use simple
implicit none
integer, parameter :: n = 256
integer :: a ( n ) , b
a = 1
b = 3
call increment ( a , b )
if ( any ( a /= 4)) then
write (* ,*) "pass"
else
write(*,*) "not passed"
end if
end program incrementTestCPU
关于cuda - pgi cuda fortran编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29309241/