|
| View previous topic :: View next topic |
| Author |
Message |
Dolf
Joined: 22 Mar 2012 Posts: 78
|
Posted: Fri Dec 07, 2012 4:11 pm Post subject: matrix reduction using cuda fortran and GPU |
|
|
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 |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Fri Dec 07, 2012 5:37 pm Post subject: |
|
|
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 |
|
 |
Dolf
Joined: 22 Mar 2012 Posts: 78
|
Posted: Mon Dec 10, 2012 11:51 am Post subject: RE: |
|
|
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 |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Mon Dec 10, 2012 1:02 pm Post subject: |
|
|
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 |
|
 |
Dolf
Joined: 22 Mar 2012 Posts: 78
|
Posted: Mon Dec 10, 2012 3:48 pm Post subject: RE: |
|
|
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 |
|
 |
|
|
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 © 2001, 2002 phpBB Group
|