【问题标题】:CUDA Fortran CURAND Device API IssuesCUDA Fortran CURAND 设备 API 问题
【发布时间】:2014-10-21 15:10:49
【问题描述】:

上下文:我正在尝试使用 CURAND 在 GPU 上生成一些伪随机数,但由于我使用的是 CUDA fortran,我必须创建一个接口模块,该模块与用 C 编写的 CURAND LIBRARY 函数接口。这是接口代码:

    interface curand_init

      attributes(device) subroutine curand_init(seed,sequence,offset,state) &
        bind(C,name='curand_init')
        use iso_c_binding
        integer(c_long_long),value :: seed
        integer(c_long_long),value :: sequence
        integer(c_long_long),value :: offset
        !pgi$ ignore_tr state
        real(c_float), device :: state(*)   
      end subroutine curand_init

    end interface curand_init

    interface curand

      attributes(device) subroutine curand(state) &
        bind(C,name='curand')
        use iso_c_binding
        !pgi$ ignore_tr state
        real(c_float),device :: state(*)
      end subroutine curand

    end interface curand

    interface curand_uniform

      attributes(device) subroutine curand_uniform(state) &
        bind(C,name='curand_uniform')
        use iso_c_binding
        !pgi$ ignore_tr state
        real(c_float),device :: state(*)
      end subroutine curand_uniform

      attributes(device) subroutine curand_uniform_double(state) &
      bind(C,name='curand_uniform_double')
        use iso_c_binding
        !pgi$ ignore_tr state
        real(c_double),device :: state(*)
      end subroutine curand_uniform_double

    end interface curand_uniform

    interface curand_normal

      attributes(device) subroutine curand_normal(state) &
        bind(C,name='curand_normal')
        use iso_c_binding 
        !pgi$ ignore_tr state
        real(c_float),device :: state(*)
      end subroutine curand_normal 

      attributes(device) subroutine curand_normal_double(state) &
        bind(C,name='curand_normal_double')
        use iso_c_binding
        !pgi$ ignore_tr state
        real(c_double),device :: state(*)
      end subroutine curand_normal_double

    end interface curand_normal

在同一个模块中,我在全局内核中调用了这个设备子例程call curand_init(seed,id,0,tmpconf)。调用全局内核时出现此错误。

gpu_gen_m.CUF:
PGF90-S-0155-Could not resolve generic procedure curand_init (gpu_gen_m.CUF: 99)
  0 inform,   0 warnings,   1 severes, 0 fatal for gen_conf

任何想法我可以如何解决这个问题。

【问题讨论】:

  • 只是一个建议,在你的代码中使用一些缩进。您的界面很难阅读。
  • seed,id,0,tmpconf 是如何定义的?
  • curand_init的通用接口没有理由,改成普通接口会更直接的报错信息。
  • integer(kind=int_ptr_kind ()) :: seed , idreal(fp_kind), allocatable, device :: tmp_d(:) 其中fp_kind = singlePrecision

标签: cuda fortran gpu gpgpu pgi


【解决方案1】:

在你拥有的界面中

integer(c_long_long),value :: seed
integer(c_long_long),value :: sequence
integer(c_long_long),value :: offset
!pgi$ ignore_tr state
real(c_float), device :: state(*)   

但在你使用的通话中

两次integer(kind=int_ptr_kind ()),一次integer,一次real(fp_kind)

那不行,你的调用中必须有相同的类型。

如果你删除接口的表面名称,使接口泛型,你会从编译器得到更直接的错误信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 2014-06-14
    相关资源
    最近更新 更多