Hello! I want to use curand library in Fortran. I write a module as follows:
module curand
integer, parameter, public :: CURAND_RNG_PSEUDO_DEFAULT=100
interface curandCreateGenerator
!curandCreateGenerator(curandGenerator_t* generator, curandRngType_t rng_type)
subroutine curandCreateGenerator(generator,rng_type) &
bind(C,name='curandCreateGenerator')
use iso_c_binding
integer(c_size_t)::generator
integer(c_int),value::rng_type
end subroutine
end interface
interface curandSetPseudoRandomGeneratorSeed
!curandSetPseudoRandomGeneratorSeed(curandGenerator_t generator, unsigned long long seed)
subroutine curandSetPseudoRandomGeneratorSeed(generator,seed) &
bind(C,name='curandSetPseudoRandomGeneratorSeed')
use iso_c_binding
integer(c_size_t),value::generator
integer(c_long_long),value::seed
end subroutine
end interface
interface curandGenerateUniform
!curandGenerateUniform(curandGenerator_t generator, float *outputPtr, size_t num)
subroutine curandGenerateUniform(generator, odata, numele) &
bind(C,name='curandGenerateUniform')
use iso_c_binding
integer(c_size_t),value::generator
!pgi$ ignore_tr odata
real(c_float),device::odata(*)
integer(c_int),value::numele
end subroutine
end interface
interface curandDestroyGenerator
!curandDestroyGenerator(curandGenerator_t generator)
subroutine curandDestroyGenerator(generator) &
bind(C,name='curandDestroyGenerator')
use iso_c_binding
integer(c_size_t),value::generator
end subroutine
end interface
end module
and a Main.cuf file, as:
!
! Main.cuf
!
! CUDA Fortran Source File
! Generated by PGI Visual Fortran(R)
! 2014/6/14 20:02:15
!
program testCurand
use cudafor
use curand
implicit none
real,allocatable,pinned :: hostData(:)
real,allocatable,device :: deviceData(:)
integer(kind=8) :: gen,N,seed=1234
N=10000000 ! Define how many numbers we want to generate
! Allocate arrays on CPU and GPU
allocate(hostData(N),deviceData(N))
! Create pseudonumber generator
call curandCreateGenerator(gen,CURAND_RNG_PSEUDO_DEFAULT)
! Set seed
call curandSetPseudoRandomGeneratorSeed(gen,seed)
! Generate N floats on device
call curandGenerateUniform(gen,deviceData,N)
! Copy the data back to CPU
hostData=deviceData
print *,hostData(1:5),hostData(N-4:N)
! Deallocate data on CPU and GPU
deallocate(hostData,deviceData)
! Destroy the generator
call curandDestroyGenerator(gen)
pause
stop
end program
the compile settings are:
Additional Include Directories: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include
Additional Library Directories: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include
Additional Dependencies: curand.lib
but it can not compile, the errors are:
Deleting intermediate and output files for project ‘CudaFortranCallCurand’, configuration ‘Debug’
Compiling Project …
curand_module.cuf
Main.cuf
D:\PGI Visual Fortran 13.9\CudaFortranCallCurand\CudaFortranCallCurand\Main.cuf(21) : error S0155 : Could not resolve generic procedure curandcreategenerator
D:\PGI Visual Fortran 13.9\CudaFortranCallCurand\CudaFortranCallCurand\Main.cuf(23) : error S0155 : Could not resolve generic procedure curandsetpseudorandomgeneratorseed
D:\PGI Visual Fortran 13.9\CudaFortranCallCurand\CudaFortranCallCurand\Main.cuf(25) : error S0155 : Could not resolve generic procedure curandgenerateuniform
D:\PGI Visual Fortran 13.9\CudaFortranCallCurand\CudaFortranCallCurand\Main.cuf(32) : error S0155 : Could not resolve generic procedure curanddestroygenerator
0 inform, 0 warnings, 4 severes, 0 fatal for testcurand
CudaFortranCallCurand build failed.
Can you give some advices about this problem? Thank you very much!
Nightwish