Advertisement
Guest User

Untitled

a guest
Apr 26th, 2012
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module thrust
  2.  
  3. interface thrustmin
  4.  
  5.     function min_integer(input,N) bind(C,name="min_int_wrapper")
  6.         use iso_c_binding
  7.         integer(c_int),device:: input(*)
  8.         integer(c_int),value:: N, min_integer
  9.     end function
  10.  
  11.     function min_float(input,N) bind(C,name="min_float_wrapper")
  12.         use iso_c_binding
  13.         real(c_float),device:: input(*)
  14.         integer(c_int),value:: N, min_float
  15.     end function
  16.  
  17.     function min_double(input,N) bind(C,name="min_double_wrapper")
  18.         use iso_c_binding
  19.         real(c_double),device:: input(*)
  20.         integer(c_int),value:: N, min_double
  21.     end function
  22.  
  23. end interface
  24.  
  25. interface thrustmax
  26.  
  27.     function max_integer(input,N) bind(C,name="max_int_wrapper")
  28.         use iso_c_binding
  29.         integer(c_int),device:: input(*)
  30.         integer(c_int),value:: N, max_integer
  31.     end function
  32.  
  33.     function max_float(input,N) bind(C,name="max_float_wrapper")
  34.         use iso_c_binding
  35.         real(c_float),device:: input(*)
  36.         integer(c_int),value:: N, max_float
  37.     end function
  38.  
  39.     function max_double(input,N) bind(C,name="max_double_wrapper")
  40.         use iso_c_binding
  41.         real(c_double),device:: input(*)
  42.         integer(c_int),value:: N, max_double
  43.     end function
  44.  
  45. end interface
  46.  
  47. interface thrustsort
  48.  
  49.     subroutine sort_integer(input,N) bind(C,name="sort_int_wrapper")
  50.         use iso_c_binding
  51.         integer(c_int),device:: input(*)
  52.         integer(c_int),value:: N
  53.     end subroutine
  54.  
  55.     subroutine sort_float(input,N) bind(C,name="sort_float_wrapper")
  56.         use iso_c_binding
  57.         real(c_float),device:: input(*)
  58.         integer(c_int),value:: N
  59.     end subroutine
  60.  
  61.     subroutine sort_double(input,N) bind(C,name="sort_double_wrapper")
  62.         use iso_c_binding
  63.         real(c_double),device:: input(*)
  64.         integer(c_int),value:: N
  65.     end subroutine
  66.  
  67. end interface
  68.  
  69. interface thrustsum
  70.  
  71.     function reduce_integer(input,N) bind(C,name="reduce_int_wrapper")
  72.         use iso_c_binding
  73.         integer(c_int),device:: input(*)
  74.         integer(c_int) :: reduce_integer
  75.         integer(c_int),value:: N
  76.     end function
  77.  
  78.     function reduce_float(input,N) bind(C,name="reduce_float_wrapper")
  79.         use iso_c_binding
  80.         real(c_float),device:: input(*)
  81.         real(c_float) :: reduce_float
  82.         integer(c_int),value:: N
  83.     end function
  84.  
  85.     function reduce_double(input,N) bind(C,name="reduce_double_wrapper")
  86.         use iso_c_binding
  87.         real(c_double),device:: input(*)
  88.         real(c_double) :: reduce_double
  89.         integer(c_int),value:: N
  90.     end function
  91.  
  92. end interface
  93.  
  94. end module thrust
  95.  
  96.  
  97. program GPU
  98.   use cudafor
  99.   use thrust
  100.   implicit none
  101.   real, allocatable, device :: dev_array(:)
  102.   real, allocatable :: host_array(:)
  103.   real :: varsum
  104.   integer N / 1024 /
  105.   integer :: x
  106.  
  107.   allocate(dev_array(N))
  108.   allocate(host_array(N))
  109.  
  110.   call random_seed
  111.   call random_number(host_array)
  112.  
  113.  
  114.   print *, "COPY!"
  115.   host_array = host_array * 10.0
  116.   dev_array  = host_array
  117.  
  118.   print *, "host_array:"
  119.   print *, host_array
  120.  
  121.   print *, "elements:", N
  122.   !call thrustsort(dev_array, size(dev_array))
  123.   print *, "START CUDA! min:"
  124.   x = thrustmin(dev_array, size(dev_array))
  125.   print *, "Min:", x
  126.  
  127.   x = thrustmax(dev_array, size(dev_array))
  128.   print *, "Max:", x
  129.  
  130.   varsum = thrustsum(dev_array, size(dev_array))
  131.   print *, "Sum:", varsum
  132.  
  133.   print *, "DONE  CUDA!"
  134.  
  135.  
  136.   deallocate(dev_array)
  137.   deallocate(host_array)  
  138.  
  139.   end program GPU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement