CUDA-Fortran设备数据结构中的可分配数组 [英] Allocatable arrays in CUDA-Fortran device data structures
问题描述
我试图在驻留在GPU内存中的设备数据结构中使用可分配数组。代码(粘贴在下面)编译,但给出了段错误。我做了什么明显错误?
$ b
模块文件名为'gpu_modules.F90',如下所示:
!=============
!该模块包含数据结构的定义和数据
!存储在设备上
!=============
模块GPU_variables
使用cudafor
类型:: data_str_def
!=============
!单数量的数量
!=============
integer :: i,j
real(kind = 8):: a
!=============
! Arrays
!=============
real(kind = 8),allocatable :: b(:)
real(kind = 8) ),allocatable :: c(:, :)
real(kind = 8),allocatable :: d(:,::)
real(kind = 8),allocatable :: e ,:,:,:)
结束类型data_str_def
!=============
!实际数据在这里
!=============
type(data_str_def),device,allocatable :: data_str(:)
包含
!=============
!子程序分配内存
!=============
子程序allocate_mem(n1)
隐式无
整数,意图(in ):: n1
call deallocate_mem()
write(*,*)'works here'
allocate(data_str(n1))
write(*,*)'如何分配内存?'
allocate(data_str(n1)%b(10))
write(*,*)'success!'
返回
结束子程序allocate_mem
!=============
!子程序释放内存
!=============
子程序deallocate_mem()
隐式无
if(allocated(data_str) )deallocate(data_str)
return
end subroutine deallocate_mem
end module GPU_variables
主程序为'gpu_test.F90',如下所示:
!====== =======
!主程序
!=============
程序gpu_test
使用gpu_variables
隐含无
!=============
!局部变量
!=============
整数:: i,j,n
!===== ========
!分配数据
!=============
n = 2!数据结构的数量
调用allocate_mem(n)
!=============
!分配设备数据结构并退出
!=============
调用deallocate_mem()
结束程序
$ c编辑命令(来自当前文件夹)是:
$ pre $ code> pgfortran -Mcuda = cc5x * .F90
终端输出:
$ ./a.out
在这里工作
如何分配内存?
分段错误(核心转储)
任何帮助/洞察力和解决方案将不胜感激。编辑:另一个可能相关的细节:我使用pgfortran版本16.10
$ b $编辑:另一个可能相关的细节:我使用pgfortran版本16.10 $ b $因此,我将这个问题发布在PGI论坛上,PGI的一个人确认这个功能不支持,因为我试图使用它。http:/ /www.pgroup.com/userforum/viewtopic.php?t=5661
他的建议是使用托管属性或使用固定大小数据结构中的数组。
I'm trying to use allocatable arrays inside "device" data structures that reside in GPU memory. Code (pasted below) compiles, but gives a segfault. Am I doing something obviously wrong?
Module file is called 'gpu_modules.F90', given below:
!=============
! This module contains definitions for data structures and the data
! stored on the device
!=============
module GPU_variables
use cudafor
type :: data_str_def
!=============
! single number quantities
!=============
integer :: i, j
real(kind=8) :: a
!=============
! Arrays
!=============
real(kind=8), allocatable :: b(:)
real(kind=8), allocatable :: c(:,:)
real(kind=8), allocatable :: d(:,:,:)
real(kind=8), allocatable :: e(:,:,:,:)
end type data_str_def
!=============
! Actual data is here
!=============
type(data_str_def), device, allocatable :: data_str(:)
contains
!=============
! subroutine to allocate memory
!=============
subroutine allocate_mem(n1)
implicit none
integer, intent(in) :: n1
call deallocate_mem()
write(*,*) 'works here'
allocate(data_str(n1))
write(*,*) 'what about allocating memory?'
allocate(data_str(n1) % b(10))
write(*,*) 'success!'
return
end subroutine allocate_mem
!=============
! subroutine to deallocate memory
!=============
subroutine deallocate_mem()
implicit none
if(allocated(data_str)) deallocate(data_str)
return
end subroutine deallocate_mem
end module GPU_variables
Main program is 'gpu_test.F90', given below:
!=============
! main program
!=============
program gpu_test
use gpu_variables
implicit none
!=============
! local variables
!=============
integer :: i, j, n
!=============
! allocate data
!=============
n = 2 ! number of data structures
call allocate_mem(n)
!=============
! dallocate device data structures and exit
!=============
call deallocate_mem()
end program
Compilation command (from current folder) is:
pgfortran -Mcuda=cc5x *.F90
Terminal output:
$ ./a.out
works here
what about allocating memory?
Segmentation fault (core dumped)
Any help/insight and solution would be appreciated.. and no, use of pointers is not a viable option.
Edit: another detail that may be relevant: I'm using pgfortran version 16.10
So I posted this question on the PGI forums, and a guy from PGI confirms that the feature is not supported as I'm trying to use it.
http://www.pgroup.com/userforum/viewtopic.php?t=5661
His recommendation was to use the "managed" attribute or use fixed-sized arrays inside the data structure.
这篇关于CUDA-Fortran设备数据结构中的可分配数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!