-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
increment kernel
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module simpleOps_m | ||
contains | ||
attributes (global) subroutine increment (a, b) | ||
implicit none | ||
integer , intent (inout) :: a (:) | ||
integer , value :: b | ||
integer :: i , n | ||
|
||
i = blockDim%x * (blockIdx%x-1) + threadIdx%x | ||
n = size(a) | ||
if ( i <= n ) a(i) = a(i) + b | ||
|
||
end subroutine increment | ||
end module simpleOps_m | ||
|
||
program incrementTest | ||
use cudafor | ||
use simpleOps_m | ||
implicit none | ||
integer, parameter :: n = 1024*1024*1024 | ||
integer, allocatable :: a(:) | ||
integer, device , allocatable :: a_d(:) | ||
integer :: b , tPB = 256 | ||
type(cudaEvent) :: startEvent, stopEvent | ||
integer :: istat | ||
real :: time | ||
|
||
allocate(a(n),a_d(n)) | ||
a = 1 | ||
b = 3 | ||
|
||
istat = cudaEventCreate(startEvent) | ||
istat = cudaEventCreate(stopEvent) | ||
|
||
a_d = a | ||
istat = cudaEventRecord(startEvent, 0) | ||
call increment <<< ceiling(real(n)/ tPB) , tPB >>> (a_d, b) | ||
istat = cudaEventRecord(stopEvent, 0) | ||
istat = cudaEventSynchronize(stopEvent) | ||
istat = cudaEventElapsedTime(time, startEvent, stopEvent) | ||
a = a_d | ||
|
||
if (any ( a /= 4)) then | ||
write (* ,*) "**** ProgramFailed ******" | ||
else | ||
write (* ,*) "ProgramPassed " | ||
endif | ||
|
||
write(*,*) "Device. kernel took", real(time*1.d-6,4), "sec" | ||
|
||
deallocate(a, a_d) | ||
|
||
istat = cudaEventDestroy(startEvent) | ||
istat = cudaEventDestroy(stopEvent) | ||
|
||
end program incrementTest | ||
|