needs help in loc and a pointer for device

Hi,
I am trying to process an array defined on the device and pass it to an external C++ module (see a previous topic under my name). The main program in fortran is below.
The array which I wish to define on the devide is called seqf. The compilation/linking seems correct. However, when I run the program I get the following error:
seq =
Calling external module…

---------- external modulde output start ----------

0: copyin Memcpy (dev=0x7fff6a11f318, host=0x7fff6a11f310, size=8) FAILED: 11(invalid argument)

Any clue what I have missed?
Barak


Here is the main program:
PROGRAM load_lib
!This program
IMPLICIT NONE
INTEGER, PARAMETER :: LEN = 1000, UB = LEN-1
INTEGER seq(0:UB)
INTEGER n
INTEGER l
INTEGER*8 pn
POINTER (pn, l)

REAL8, device, DIMENSION(0:UB) :: seqf
REAL
8, DIMENSION(0:UB) :: seqf_h
INTEGER8 :: pf
REAL
8 :: f
POINTER (pf, f)

print*
print*,'seq = ’
do n = 0, UB, 1
seq(n) = n
seqf(n) = n
!print*, ‘seq[’, n, '] = ', seq(n), ‘, seqf[’, n, '] = ', seqf(n)
end do

print*, ‘Calling external module…’
print*
print*, ‘---------- external modulde output start ----------’
print*
n = LEN
pn = loc(seq)
pf = loc(seqf)

!CALL external_processing_i(seq, n, pn)
CALL external_processing_f(n, pf)

print*
print*, ‘---------- external modulde output end ----------’
print*
500 print*,‘Done’

seqf_h=seqf
print*,'seq = ’
do n = 0, UB, 1
print*,seqf_h(n)
end do

print*

END PROGRAM load_lib

Hi Barak,

Instead of having pf be an integer*8, I’d change it’s type to “type(c_devptr)” and then use calls to “c_f_pointer” and “cudaHostGetDevicePointer” to get the CUDA device pointer. An example of this can be found on page 72 of the CUDA Fortran Reference Guide (http://www.pgroup.com/doc/pgicudaforug.pdf).

I’d also recommend adding an interface block to the C++ routine. It’s not absolutely necessary but will ensure the arguments are being passed correctly.

  • Mat