PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

matrix reduction using cuda fortran and GPU
Goto page 1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
Dolf



Joined: 22 Mar 2012
Posts: 100

PostPosted: Fri Dec 07, 2012 4:11 pm    Post subject: matrix reduction using cuda fortran and GPU Reply with quote

Hi all,

I have this short program which reduces a matrix A(nx,ny) to ak

integer :: nx,ny,i,j,ak
integer, allocatable, dimension (:,:) :: A

nx = 306
ny = 306
ak = 0

allocate (a(nx,ny))
A(1:nx,1:ny) = 2

do i = 1, nx
do j = 1, ny
ak = ak + A(i,j)
enddo
enddo

what is the easiest way to reduce A on GPU??

thanks,
Dolf
Back to top
View user's profile
mkcolg



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

PostPosted: Fri Dec 07, 2012 5:37 pm    Post subject: Reply with quote

Hi Dolf,

Just put an OpenACC kernels directive on the outer loop. The compiler is smart enough to auto-detect reductions and generate the appropriate code. If you want to make it explicit, you can also use the "reduction" clause.

Code:

% cat reduce.f90
integer :: nx,ny,i,j,ak
integer, allocatable, dimension (:,:) :: A

nx = 306
ny = 306
ak = 0

allocate (a(nx,ny))
A(1:nx,1:ny) = 2

!$acc kernels loop
do i = 1, nx
do j = 1, ny
ak = ak + A(i,j)
enddo
enddo

end
% pgf90 -acc -Minfo=accel reduce.f90
MAIN:
     11, Generating present_or_copyin(a(1:306,1:306))
         Generating compute capability 1.0 binary
         Generating compute capability 2.0 binary
     12, Loop is parallelizable
     13, Loop is parallelizable
         Accelerator kernel generated
         12, !$acc loop gang, vector(128) ! blockidx%x threadidx%x
         13, !$acc loop gang ! blockidx%y
             CC 1.0 : 11 registers; 48 shared, 36 constant, 0 local memory bytes
             CC 2.0 : 16 registers; 0 shared, 64 constant, 0 local memory bytes
         14, Sum reduction generated for ak


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



Joined: 22 Mar 2012
Posts: 100

PostPosted: Mon Dec 10, 2012 11:51 am    Post subject: RE: Reply with quote

Hi Matt,

this is very helpful, but where can I read up on that? I have not seen those clauses in any book or online forum.

many thanks.
Dolf
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Dec 10, 2012 1:02 pm    Post subject: Reply with quote

You can find information on openACC either at the OpenACC Community or on PGI's OpenACC page. Also, there are many posts about OpenACC in this forum and several articles in the PGInsider Newsletter.

- Mat
Back to top
View user's profile
Dolf



Joined: 22 Mar 2012
Posts: 100

PostPosted: Mon Dec 10, 2012 3:48 pm    Post subject: RE: Reply with quote

Awesome!

I just went to OpenACC and downloaded quick reference, does PGI compiler have openacc_lib.h ??

if I want to include acc clauses, what do I need to do first to compile the project??

Dolf
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, 3, 4, 5, 6, 7  Next
Page 1 of 7

 
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