我正在使用 OpenMP 4.5 将代码卸载到 GPU。到目前为止,一切都在 GPU 上运行,除非我尝试使用在卸载之前分配的私有变量创建并行部分。
我正在使用 gcc 7.2.0 和 cuda 9.2.88。我在 CentOS 7 上运行并使用
gfortran ./testCode.F90 -fopenmp -o ./test
这是一个示例代码:
#define LENGTH_X 4
#define LENGTH_Y 4
#define PRINT
program main
use omp_lib
implicit none
real, allocatable :: testVar(:,:)
real :: error = 0
logical :: onCPU
integer :: i, j,k
allocate(testVar(LENGTH_X,LENGTH_Y))
do i = 1, LENGTH_X
testVar(i,:) = i
#ifdef PRINT
print *, testVar(i,:)
#endif
end do
onCPU = omp_is_initial_device()
!$omp target map(tofrom:testVar, onCPU,error)
!$OMP TEAMS DISTRIBUTE PARALLEL DO private(testVar) reduction(max:error)
do i = 2, LENGTH_X-1
do j = 2, LENGTH_Y-1
testVar(i,j) = 0.25
end do
end do
!$OMP END TEAMS DISTRIBUTE PARALLEL DO
onCPU = omp_is_initial_device()
!$omp end target
print *, "Ran on CPU", onCPU
print *, "New vars"
do i = 1, LENGTH_X
#ifdef PRINT
print *, testVar(i,:)
#endif
end do
end program main
这无法编译
unresolved symbol _gfortran_os_error
collect2: error: ld returned 1 exit status
mkoffload: fatal error: x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /opt/software/GCC/7.2.0-cuda-9.2.88-offload/libexec/gcc/x86_64-pc-linux-gnu/7.2.0//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/opt/software/binutils/2.28-GCCcore-6.4.0/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
如果我将私有更改为共享,它工作正常。我对 fortran 并不陌生,但知道如何用 C/C++ 和 python 编程。任何意见,将不胜感激!