PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Using Streams

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
adityaks



Joined: 02 Oct 2012
Posts: 8

PostPosted: Tue Oct 02, 2012 3:45 am    Post subject: Using Streams Reply with quote

I'm trying to get a hand at using streams. Below is the code i've written. If proper, the code should print 2. Can somebody help find what is wrong?

Thanks.
Code:

module addnum
  use cudafor
    contains
   
  attributes(global) subroutine addnum_kernel( zn1, nz2, zn3 )
    integer, device :: zn1, nz2, zn3
    zn3 = zn1 + zn2
  end subroutine addnum_kernel


  subroutine plladdnum( zconst, zthreadidx, znewval )
    integer :: zconst, zthreadidx, znewval
    integer, device :: zdconst, zdthreadidx, zdnewval
 !   integer ( kind = cuda_stream_kind ) :: streamnum
    integer:: streamnum
    istat = cudaStreamCreate ( streamnum )

    call addnum_kernel <<< 1,1,0,streamnum >>> (zdconst, zdthreadidx, zdnewval)
    znewval = zdnewval

  end subroutine plladdnum

end module addnum

program hccode
  use addnum
  !     Program to test a heterogenous compute code using MPI an CUDA Fortran
  !     Each MPI thread copies a number to device, the device adds a thread specific number to it, the number is returned to host, the host prints it.
  integer :: zconst, zthreadidx, znewval
  integer :: idevice, istat

  idevice = 0
  zconst = 1
  zthreadidx = 1

  istat = cudaSetDevice(idevice) 
  print*,'calling plladdnum'
  call plladdnum( zconst, zthreadidx, znewval)

  print*,'znewval',znewval
end program hccode
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6119
Location: The Portland Group Inc.

PostPosted: Tue Oct 02, 2012 9:39 am    Post subject: Reply with quote

Hi iamaditya,

There are two issues here. First, you either need to assign the device variables, zdconst and zdthreadidx, before passing them to the kernel, or pass in the host variables by value. (Passing by value is preferred here). Secondly, you have a typo in your kernel where use the variable "zn2" but declared it as "nz2". Here the fixed code:
Code:
% cat test.cuf
module addnum
  use cudafor
    contains
   
  attributes(global) subroutine addnum_kernel( zn1, zn2, zn3 )
    integer, value :: zn1, zn2
    integer, device :: zn3
    zn3 = zn1 + zn2
  end subroutine addnum_kernel


  subroutine plladdnum( zconst, zthreadidx, znewval )
    integer :: zconst, zthreadidx, znewval
    integer, device :: zdnewval
 !   integer ( kind = cuda_stream_kind ) :: streamnum
    integer:: streamnum
    istat = cudaStreamCreate ( streamnum )

    call addnum_kernel <<< 1,1,0,streamnum >>> (zconst, zthreadidx, zdnewval)
    znewval = zdnewval

  end subroutine plladdnum

end module addnum

program hccode
  use addnum
  !     Program to test a heterogenous compute code using MPI an CUDA Fortran
  !     Each MPI thread copies a number to device, the device adds a thread specific number to it, the number is returned to host, the host prints it.
  integer :: zconst, zthreadidx, znewval
  integer :: idevice, istat

  idevice = 0
  zconst = 1
  zthreadidx = 1

  istat = cudaSetDevice(idevice)
  print*,'calling plladdnum'
  call plladdnum( zconst, zthreadidx, znewval)

  print*,'znewval',znewval
end program hccode

% pgf90 test.cuf
% a.out
 calling plladdnum
 znewval            2


Hope this helps,
Mat
Back to top
View user's profile
adityaks



Joined: 02 Oct 2012
Posts: 8

PostPosted: Wed Oct 03, 2012 2:12 am    Post subject: Reply with quote

Yes.
Thanks.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group