PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

cublas<t>dot_v2
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
sslgamess



Joined: 23 Nov 2009
Posts: 35

PostPosted: Sat Mar 31, 2012 5:44 am    Post subject: cublas<t>dot_v2 Reply with quote

The code below fails at line 37 where it tries to perform a dot product using cublas and tries to store the result into an element of an array on the device.

Is this not allowed?

Code:

      program test
!GPU\
      use cudafor
      use cublas
!GPU/
      implicit none
      integer, parameter :: size = 10
      double precision, dimension (size) :: vec_a, vec_b, dotproduct
      double precision, allocatable, dimension (:), device :: Dvec_a,
     > Dvec_b, Ddotproduct
      integer, i, j, istat, imode
      type(cublashandle) :: h
c
      istat=0
c
      istat=istat+cublasInit()
      if(istat.ne.0) write(*,*) 'cublasInit'
      h=cublasgethandle()
      istat=istat+cublasCreate(h)
      if(istat.ne.0) write(*,*) 'cublasCreate'
      istat=istat+cublasalloc(size,8,Dvec_a)
      istat=istat+cublasalloc(size,8,Dvec_b)     
      istat=istat+cublasalloc(size,8,Ddotproduct)     
      if(istat.ne.0) write(*,*) 'cublasalloc'
     
      do i=1, size     
        do j=1, size
          vec_a(j)=dble(j)
          vec_b(j)=dble(size-j)
        enddo       
#ifdef _ACCEL
        istat=istat+cublassetvector(size,8,vec_a,1,Dvec_a,1)
        if(istat.ne.0) write(*,*) 'set vector Dvec_a'
        istat=istat+cublassetvector(size,8,vec_b,1,Dvec_b,1)
        if(istat.ne.0) write(*,*) 'set vector Dvec_b'
        istat=istat+
     >  cublasDdot_v2(h,size,Dvec_a,1,Dvec_b,1,Ddotproduct(i))  !<< code crashes here
        if(istat.ne.0) write(*,*) 'dot product'
        dotproduct(i)=dotproduct(i)+dble(i)
#else
        dotproduct(i)=dot_product(vec_a,vec_b)+dble(i)
#endif
      enddo
     
#ifdef _ACCEL
        istat=istat+cublasgetvector(size,8,Ddotproduct,1,dotproduct,1)
        if(istat.ne.0) write(*,*) 'get vector'     
#endif
     
      write(*,*) 'dotproduct := ', dotproduct
     
      istat=istat+cublasShutdown()
     
      end



Also, the cublas 4.0 manual states that cublasAlloc and cublasFree have been depreciated. Would the "in thing" be to use allocate and deallocate or cudaMalloc and cudaFree?

If either could be used is there a benefit to using one over the other (i.e. for 1D arrays vs. 2D or 3D arrays?) I do gather that their usage should not be mix.
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Apr 02, 2012 10:40 am    Post subject: Reply with quote

Hi Sarom,

The seg fault is being caused by pass in "Ddotproduct(i)" as the result. To fix use "dotproduct" instead.
Quote:
Also, the cublas 4.0 manual states that cublasAlloc and cublasFree have been depreciated. Would the "in thing" be to use allocate and deallocate or cudaMalloc and cudaFree?
I'm not much of an expert on using cuBlas so don't know for sure, but using "allocate" works for me and simplifies things.

For example:
Code:
% cat blas.F
      program test
!GPU\
      use cudafor
      use cublas
!GPU/
      implicit none
      integer, parameter :: size = 10
      double precision, dimension (size) :: vec_a, vec_b, dotproduct
      double precision, allocatable, dimension (:), device :: Dvec_a,
     > Dvec_b, Ddotproduct
      integer, i, j, istat, imode
      type(cublashandle) :: h
c
      istat=0
c
      istat=istat+cublasInit()
      if(istat.ne.0) write(*,*) 'cublasInit'
      h=cublasgethandle()
      istat=istat+cublasCreate(h)
      if(istat.ne.0) write(*,*) 'cublasalloc'
      allocate(Dvec_a(size), Dvec_b(size), Ddotproduct(size))
   
      do i=1, size     
        do j=1, size
          vec_a(j)=dble(j)
          vec_b(j)=dble(size-j)
        enddo       
#ifdef _CUDA
        Dvec_a=vec_a
        Dvec_b=vec_b
        istat=istat+
     >  cublasDdot_v2(h,size,Dvec_a,1,Dvec_b,1,dotproduct(i)) 
        if(istat.ne.0) write(*,*) 'dot product'
        dotproduct(i)=dotproduct(i)+dble(i)
#else
        dotproduct(i)=dot_product(vec_a,vec_b)+dble(i)
#endif
      enddo
     
#ifdef _ACCEL
        istat=istat+cublasgetvector(size,8,Ddotproduct,1,dotproduct,1)
        if(istat.ne.0) write(*,*) 'get vector'     
#endif
     
      write(*,*) 'dotproduct := ', dotproduct
     
      istat=istat+cublasShutdown()
     
      end
% pgf90 blas.F  -Mcuda -lcublas
% a.out
 dotproduct :=     166.0000000000000         167.0000000000000     
    168.0000000000000         169.0000000000000         170.0000000000000     
    171.0000000000000         172.0000000000000         173.0000000000000     
    174.0000000000000         175.0000000000000   


- Mat
Back to top
View user's profile
sslgamess



Joined: 23 Nov 2009
Posts: 35

PostPosted: Mon Apr 02, 2012 10:52 am    Post subject: Reply with quote

Thanks Mat.

The array dotproduct is allocated on the host.

The cublas 4.0 library manual states that the result of cublas<t>dot can be on either the device or the host.

I would like to store the result in an array allocated on the device, Ddotproduct.

Does the Fortran interface provided by the cublas module for the _v2 cublas calls not permit storing the results on the device?
Back to top
View user's profile
brentl



Joined: 20 Jul 2004
Posts: 132

PostPosted: Tue Apr 03, 2012 5:56 pm    Post subject: Reply with quote

Add these lines:

istat=istat+cublasSetPointerMode(h,CUBLAS_POINTER_MODE_DEVICE)
if(istat.ne.0) write(*,*) 'cublassetpointermode'
Back to top
View user's profile
sslgamess



Joined: 23 Nov 2009
Posts: 35

PostPosted: Wed Apr 04, 2012 4:10 am    Post subject: Reply with quote

Thanks!

Does changing the pointer mode affect cublasSet*, cublasGet* routines and their async counterpart?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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