Advertisement
Guest User

Untitled

a guest
Apr 11th, 2012
79
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_float(input,N) bind(C,name="min_float_wrapper")
  6.     use iso_c_binding
  7.     real(c_float),device:: input(*)
  8.     integer(c_int),value:: N, min_float
  9.     end function
  10.  
  11.     function min_double(input,N) bind(C,name="min_double_wrapper")
  12.     use iso_c_binding
  13.     real(c_double),device:: input(*)
  14.     integer(c_int),value:: N, min_double
  15.     end function
  16.  
  17. !   subroutine 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
  21. !   end subroutine
  22.  
  23. end interface
  24.  
  25. interface thrustsort
  26.  
  27. subroutine sort_float(input,N) bind(C,name="sort_float_wrapper")
  28. use iso_c_binding
  29. real(c_float),device:: input(*)
  30. integer(c_int),value:: N
  31. end subroutine
  32.  
  33. end interface
  34.  
  35.  
  36. end module thrust
  37.  
  38.  
  39. program GPU
  40.   use cudafor
  41.   use thrust
  42.   implicit none
  43.   real, allocatable, device :: dev_array(:)
  44.   real, allocatable :: host_array(:)
  45.   integer N / 20 /
  46.   integer :: x
  47.  
  48.   allocate(dev_array(N))
  49.   allocate(host_array(N))
  50.  
  51.   call random_seed
  52.   call random_number(host_array)
  53.  
  54.   print *, "host_array:"
  55.   print *, host_array
  56.  
  57.  
  58.   print *, "COPY!"
  59.   dev_array = host_array
  60.  
  61.   print *, "START CUDA! sort:"
  62.   !call thrustsort(dev_array, size(dev_array))
  63.   print *, "START CUDA! min:"
  64.   x = thrustmin(dev_array, size(dev_array))
  65.   print *, "DONE  CUDA!"
  66.  
  67.   print *, "Min:", x
  68.  
  69.   deallocate(dev_array)
  70.   deallocate(host_array)  
  71.  
  72.   end program GPU
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement