CUDA Fortran:具有单独名称的多个共享数组?

发布于 2024-10-24 07:41:00 字数 657 浏览 2 评论 0原文

是否确实可以在 CUDA Fortran 中分配多个共享数组,而不必只使用一个共享数组并使用索引偏移?

指针不起作用,“指针”和“目标”属性与“共享”属性冲突。

这就是我想要实现的目标:

  attributes(global) subroutine shared_sub_arrays()

    integer :: i

    real, shared, dimension(*), target :: alldata
    real, shared, dimension(:), pointer :: left
    real, shared, dimension(:), pointer :: centre
    real, shared, dimension(:), pointer :: right

    i = threadIdx%x

    left   => alldata(1:3)
    centre => alldata(4:6)
    right  => alldata(7:9)    

    left(i) = 1.0
    centre(i) = 2.0
    right(i) = 3.0

  end subroutine shared_sub_arrays

有人知道另一种方法吗?

预先感谢您的帮助

Is it indeed possible to allocate multiple shared arrays in CUDA Fortran without having to resort to having just one shared array and using index offsetting?

Pointers don't work, the 'pointer' and 'target' attributes conflict with the 'shared' attribute.

This is what I want to acheive:

  attributes(global) subroutine shared_sub_arrays()

    integer :: i

    real, shared, dimension(*), target :: alldata
    real, shared, dimension(:), pointer :: left
    real, shared, dimension(:), pointer :: centre
    real, shared, dimension(:), pointer :: right

    i = threadIdx%x

    left   => alldata(1:3)
    centre => alldata(4:6)
    right  => alldata(7:9)    

    left(i) = 1.0
    centre(i) = 2.0
    right(i) = 3.0

  end subroutine shared_sub_arrays

Does anyone know of another way to do this?

Thanks in advance for the help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻风 2024-10-31 07:41:00

来自 Portland CUDA Fortran 手册:

这些规则适用于设备数据:

  • 设备变量和数组可能没有指针或目标属性。

所以我想这是不可能的。至于其他方法,您可以手动跟踪索引(这似乎您不想这样做),或者使用具有 3 列的矩阵,例如

real, shared, dimension(:,:) :: alldata
allocate(data(N,3))

! name indices
left=1
centre=2
right=3

! access the columns
alldata(i,left)
alldata(i,centre)
alldata(i,right)

From the Portland CUDA Fortran manual:

These rules apply to device data:

  • Device variables and arrays may not have the Pointer or Target attributes.

So I guess that's just not possible. As for other ways to do it, you could manually keep track of the indices (which seems you don't want to do), or use a matrix with 3 columns, e.g.

real, shared, dimension(:,:) :: alldata
allocate(data(N,3))

! name indices
left=1
centre=2
right=3

! access the columns
alldata(i,left)
alldata(i,centre)
alldata(i,right)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文