mod_compute_hh_trafo.f90 14.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
!    This file is part of ELPA.
!
!    The ELPA library was originally created by the ELPA consortium,
!    consisting of the following organizations:
!
!    - Max Planck Computing and Data Facility (MPCDF), formerly known as
!      Rechenzentrum Garching der Max-Planck-Gesellschaft (RZG),
!    - Bergische Universität Wuppertal, Lehrstuhl für angewandte
!      Informatik,
!    - Technische Universität München, Lehrstuhl für Informatik mit
!      Schwerpunkt Wissenschaftliches Rechnen ,
!    - Fritz-Haber-Institut, Berlin, Abt. Theorie,
!    - Max-Plack-Institut für Mathematik in den Naturwissenschaften,
!      Leipzig, Abt. Komplexe Strukutren in Biologie und Kognition,
!      and
!    - IBM Deutschland GmbH
!
!
!    More information can be found here:
!    http://elpa.mpcdf.mpg.de/
!
!    ELPA is free software: you can redistribute it and/or modify
!    it under the terms of the version 3 of the license of the
!    GNU Lesser General Public License as published by the Free
!    Software Foundation.
!
!    ELPA is distributed in the hope that it will be useful,
!    but WITHOUT ANY WARRANTY; without even the implied warranty of
!    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!    GNU Lesser General Public License for more details.
!
!    You should have received a copy of the GNU Lesser General Public License
!    along with ELPA.  If not, see <http://www.gnu.org/licenses/>
!
!    ELPA reflects a substantial effort on the part of the original
!    ELPA consortium, and we ask you to respect the spirit of the
!    license that we chose: i.e., please contribute any changes you
!    may have back to the original ELPA library distribution, and keep
!    any derivatives of ELPA under the same license that we chose for
!    the original distribution, the GNU Lesser General Public License.
!
! This file was written by A. Marek, MPCDF

module compute_hh_trafo
   use elpa_mpi
   implicit none

   public compute_hh_trafo_real_double

   public compute_hh_trafo_complex_double

   public compute_hh_trafo_real_single

   public compute_hh_trafo_complex_single
contains

   !real double precision

   subroutine compute_hh_trafo_&
   &real&
   &_&
   &double &
      (obj, useGPU, wantDebug, a, a_dev, stripe_width, a_dim2, stripe_count, max_threads, &
      a_off, nbw, max_blk_size, bcast_buffer, bcast_buffer_dev, &
      hh_tau_dev, kernel_flops, kernel_time, n_times, off, ncols, istripe, &
      last_stripe_width, &
      kernel)

      use precision
      use elpa_abstract_impl
      use, intrinsic :: iso_c_binding

      use cuda_c_kernel
      use cuda_functions

      use elpa_generated_fortran_interfaces

      implicit none
      class(elpa_abstract_impl_t), intent(inout) :: obj
      logical, intent(in)                        :: useGPU, wantDebug
      real(kind=c_double), intent(inout)         :: kernel_time  ! MPI_WTIME always needs double
      integer(kind=lik)                          :: kernel_flops
      integer(kind=ik), intent(in)               :: nbw, max_blk_size
      real(kind=c_double)                 :: bcast_buffer(nbw,max_blk_size)
      integer(kind=ik), intent(in)               :: a_off

      integer(kind=ik), intent(in)               :: stripe_width,a_dim2,stripe_count

      integer(kind=ik), intent(in)               :: max_threads
      integer(kind=ik), intent(in)               :: last_stripe_width
!         real(kind=c_double)                :: a(stripe_width,a_dim2,stripe_count)
      real(kind=c_double)        :: a(:,:,:)

      integer(kind=ik), intent(in)               :: kernel

      integer(kind=c_intptr_t)                   :: a_dev
      integer(kind=c_intptr_t)                   :: bcast_buffer_dev
      integer(kind=c_intptr_t)                   :: hh_tau_dev
      integer(kind=c_intptr_t)                   :: dev_offset, dev_offset_1, dev_offset_2

      ! Private variables in OMP regions (my_thread) should better be in the argument list!
      integer(kind=ik)                           :: off, ncols, istripe
      integer(kind=ik)                           :: j, nl, jj, jjj, n_times
      real(kind=c_double)                 :: w(nbw,6)
      real(kind=c_double)                        :: ttt ! MPI_WTIME always needs double

      integer(kind=c_intptr_t), parameter        :: size_of_datatype = size_of_&
      &double&
      &_&
      &real

      j = -99

      if (wantDebug) call obj%timer%start("compute_hh_trafo_&
      &real&
      &" // &
      &"_double" &
         )

      ttt = mpi_wtime()

      nl = merge(stripe_width, last_stripe_width, istripe<stripe_count)

! generic kernel real case
      do j = ncols, 2, -2
         w(:,1) = bcast_buffer(1:nbw,j+off)
         w(:,2) = bcast_buffer(1:nbw,j+off-1)

         call double_hh_trafo_&
         &real&
         &_generic_&
         &double&
133
         & (a(1,j+off+a_off-1,istripe),w, nbw, nl, stripe_width, nbw)
134 135 136 137 138 139 140

      enddo

      if (j==1) call single_hh_trafo_&
      &real&
      &_cpu_&
      &double&
141
      & (a(1,j+off+a_off,istripe), bcast_buffer(1,j+off),nbw,nl,stripe_width)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

      kernel_flops = kernel_flops + 4*int(nl,lik)*int(ncols,lik)*int(nbw,lik)
      kernel_time = kernel_time + mpi_wtime()-ttt
      n_times = n_times + 1

      if (wantDebug) call obj%timer%stop("compute_hh_trafo_&
      &real&
      &" // &
      &"_double" &
         )

   end subroutine

   ! real single precision

   subroutine compute_hh_trafo_&
   &real&
   &_&
   &single &
      (obj, useGPU, wantDebug, a, a_dev, stripe_width, a_dim2, stripe_count, max_threads, &
      a_off, nbw, max_blk_size, bcast_buffer, bcast_buffer_dev, &
      hh_tau_dev, kernel_flops, kernel_time, n_times, off, ncols, istripe, &
      last_stripe_width, &
      kernel)

      use precision
      use elpa_abstract_impl
      use, intrinsic :: iso_c_binding

      use cuda_c_kernel
      use cuda_functions

      use elpa_generated_fortran_interfaces

      implicit none
      class(elpa_abstract_impl_t), intent(inout) :: obj
      logical, intent(in)                        :: useGPU, wantDebug
      real(kind=c_double), intent(inout)         :: kernel_time  ! MPI_WTIME always needs double
      integer(kind=lik)                          :: kernel_flops
      integer(kind=ik), intent(in)               :: nbw, max_blk_size
      real(kind=c_float)                 :: bcast_buffer(nbw,max_blk_size)
      integer(kind=ik), intent(in)               :: a_off

      integer(kind=ik), intent(in)               :: stripe_width,a_dim2,stripe_count

      integer(kind=ik), intent(in)               :: max_threads
      integer(kind=ik), intent(in)               :: last_stripe_width
!         real(kind=c_float)                :: a(stripe_width,a_dim2,stripe_count)
      real(kind=c_float)        :: a(:,:,:)

      integer(kind=ik), intent(in)               :: kernel

      integer(kind=c_intptr_t)                   :: a_dev
      integer(kind=c_intptr_t)                   :: bcast_buffer_dev
      integer(kind=c_intptr_t)                   :: hh_tau_dev
      integer(kind=c_intptr_t)                   :: dev_offset, dev_offset_1, dev_offset_2

      ! Private variables in OMP regions (my_thread) should better be in the argument list!
      integer(kind=ik)                           :: off, ncols, istripe
      integer(kind=ik)                           :: j, nl, jj, jjj, n_times
      real(kind=c_float)                 :: w(nbw,6)
      real(kind=c_double)                        :: ttt ! MPI_WTIME always needs double

      integer(kind=c_intptr_t), parameter        :: size_of_datatype = size_of_&
      &single&
      &_&
      &real

      j = -99

      if (wantDebug) call obj%timer%start("compute_hh_trafo_&
      &real&
      &" // &
      &"_single" &
         )

      ttt = mpi_wtime()

      nl = merge(stripe_width, last_stripe_width, istripe<stripe_count)

! generic kernel real case
      do j = ncols, 2, -2
         w(:,1) = bcast_buffer(1:nbw,j+off)
         w(:,2) = bcast_buffer(1:nbw,j+off-1)

         call double_hh_trafo_&
         &real&
         &_generic_&
         &single&
231
         & (a(1,j+off+a_off-1,istripe),w, nbw, nl, stripe_width, nbw)
232 233 234 235 236 237 238

      enddo

      if (j==1) call single_hh_trafo_&
      &real&
      &_cpu_&
      &single&
239
      & (a(1,j+off+a_off,istripe), bcast_buffer(1,j+off),nbw,nl,stripe_width)
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326

      kernel_flops = kernel_flops + 4*int(nl,lik)*int(ncols,lik)*int(nbw,lik)
      kernel_time = kernel_time + mpi_wtime()-ttt
      n_times = n_times + 1

      if (wantDebug) call obj%timer%stop("compute_hh_trafo_&
      &real&
      &" // &
      &"_single" &
         )

   end subroutine

   !complex double precision

   subroutine compute_hh_trafo_&
   &complex&
   &_&
   &double &
      (obj, useGPU, wantDebug, a, a_dev, stripe_width, a_dim2, stripe_count, max_threads, &
      a_off, nbw, max_blk_size, bcast_buffer, bcast_buffer_dev, &
      hh_tau_dev, kernel_flops, kernel_time, n_times, off, ncols, istripe, &
      last_stripe_width, &
      kernel)

      use precision
      use elpa_abstract_impl
      use, intrinsic :: iso_c_binding

      use cuda_c_kernel
      use cuda_functions

      use elpa_generated_fortran_interfaces

      implicit none
      class(elpa_abstract_impl_t), intent(inout) :: obj
      logical, intent(in)                        :: useGPU, wantDebug
      real(kind=c_double), intent(inout)         :: kernel_time  ! MPI_WTIME always needs double
      integer(kind=lik)                          :: kernel_flops
      integer(kind=ik), intent(in)               :: nbw, max_blk_size
      complex(kind=c_double)              :: bcast_buffer(nbw,max_blk_size)
      integer(kind=ik), intent(in)               :: a_off

      integer(kind=ik), intent(in)               :: stripe_width,a_dim2,stripe_count

      integer(kind=ik), intent(in)               :: max_threads
      integer(kind=ik), intent(in)               :: last_stripe_width
!          complex(kind=c_double)            :: a(stripe_width,a_dim2,stripe_count)
      complex(kind=c_double)     :: a(:,:,:)

      integer(kind=ik), intent(in)               :: kernel

      integer(kind=c_intptr_t)                   :: a_dev
      integer(kind=c_intptr_t)                   :: bcast_buffer_dev
      integer(kind=c_intptr_t)                   :: hh_tau_dev
      integer(kind=c_intptr_t)                   :: dev_offset, dev_offset_1, dev_offset_2

      ! Private variables in OMP regions (my_thread) should better be in the argument list!
      integer(kind=ik)                           :: off, ncols, istripe
      integer(kind=ik)                           :: j, nl, jj, jjj, n_times
      complex(kind=c_double)              :: w(nbw,2)
      real(kind=c_double)                        :: ttt ! MPI_WTIME always needs double

      integer(kind=c_intptr_t), parameter        :: size_of_datatype = size_of_&
      &double&
      &_&
      &complex

      j = -99

      if (wantDebug) call obj%timer%start("compute_hh_trafo_&
      &complex&
      &" // &
      &"_double" &
         )

      ttt = mpi_wtime()

      nl = merge(stripe_width, last_stripe_width, istripe<stripe_count)

! generic kernel complex case
      do j = ncols, 1, -1

         call single_hh_trafo_&
         &complex&
         &_generic_&
         &double&
327
         & (a(1,j+off+a_off,istripe), bcast_buffer(1,j+off),nbw,nl,stripe_width)
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409

      enddo

      kernel_flops = kernel_flops + 4*int(nl,lik)*int(ncols,lik)*int(nbw,lik)
      kernel_time = kernel_time + mpi_wtime()-ttt
      n_times = n_times + 1

      if (wantDebug) call obj%timer%stop("compute_hh_trafo_&
      &complex&
      &" // &
      &"_double" &
         )

   end subroutine

   ! complex single precision

   subroutine compute_hh_trafo_&
   &complex&
   &_&
   &single &
      (obj, useGPU, wantDebug, a, a_dev, stripe_width, a_dim2, stripe_count, max_threads, &
      a_off, nbw, max_blk_size, bcast_buffer, bcast_buffer_dev, &
      hh_tau_dev, kernel_flops, kernel_time, n_times, off, ncols, istripe, &
      last_stripe_width, &
      kernel)

      use precision
      use elpa_abstract_impl
      use, intrinsic :: iso_c_binding

      use cuda_c_kernel
      use cuda_functions

      use elpa_generated_fortran_interfaces

      implicit none
      class(elpa_abstract_impl_t), intent(inout) :: obj
      logical, intent(in)                        :: useGPU, wantDebug
      real(kind=c_double), intent(inout)         :: kernel_time  ! MPI_WTIME always needs double
      integer(kind=lik)                          :: kernel_flops
      integer(kind=ik), intent(in)               :: nbw, max_blk_size
      complex(kind=c_float)              :: bcast_buffer(nbw,max_blk_size)
      integer(kind=ik), intent(in)               :: a_off

      integer(kind=ik), intent(in)               :: stripe_width,a_dim2,stripe_count

      integer(kind=ik), intent(in)               :: max_threads
      integer(kind=ik), intent(in)               :: last_stripe_width
!          complex(kind=c_float)            :: a(stripe_width,a_dim2,stripe_count)
      complex(kind=c_float)     :: a(:,:,:)

      integer(kind=ik), intent(in)               :: kernel

      integer(kind=c_intptr_t)                   :: a_dev
      integer(kind=c_intptr_t)                   :: bcast_buffer_dev
      integer(kind=c_intptr_t)                   :: hh_tau_dev
      integer(kind=c_intptr_t)                   :: dev_offset, dev_offset_1, dev_offset_2

      ! Private variables in OMP regions (my_thread) should better be in the argument list!
      integer(kind=ik)                           :: off, ncols, istripe
      integer(kind=ik)                           :: j, nl, jj, jjj, n_times
      complex(kind=c_float)              :: w(nbw,2)
      real(kind=c_double)                        :: ttt ! MPI_WTIME always needs double

      integer(kind=c_intptr_t), parameter        :: size_of_datatype = size_of_&
      &single&
      &_&
      &complex

      j = -99

      ttt = mpi_wtime()

      nl = merge(stripe_width, last_stripe_width, istripe<stripe_count)

      do j = ncols, 1, -1

         call single_hh_trafo_&
         &complex&
         &_generic_&
         &single&
410
         & (a(1,j+off+a_off,istripe), bcast_buffer(1,j+off),nbw,nl,stripe_width)
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426

      enddo

      kernel_flops = kernel_flops + 4*int(nl,lik)*int(ncols,lik)*int(nbw,lik)
      kernel_time = kernel_time + mpi_wtime()-ttt
      n_times = n_times + 1

      if (wantDebug) call obj%timer%stop("compute_hh_trafo_&
      &complex&
      &" // &
      &"_single" &
         )

   end subroutine

end module