72 integer,
public :: nst
73 integer,
public :: dim
76 integer,
allocatable :: ist_idim_index(:, :)
81 integer,
allocatable,
public :: ist(:)
88 logical :: is_allocated
91 integer,
public :: nst_linear
97 integer :: status_host
106 type(type_t) :: type_of
107 integer :: device_buffer_count
108 integer :: host_buffer_count
109 logical :: special_memory
110 logical :: needs_finish_unpack
114 real(real64),
pointer,
contiguous,
public :: dff(:, :, :)
116 complex(real64),
pointer,
contiguous,
public :: zff(:, :, :)
118 real(real64),
pointer,
contiguous,
public :: dff_linear(:, :)
120 complex(real64),
pointer,
contiguous,
public :: zff_linear(:, :)
124 real(real64),
pointer,
contiguous,
public :: dff_pack(:, :)
126 complex(real64),
pointer,
contiguous,
public :: zff_pack(:, :)
130 real(real32),
pointer,
contiguous,
public :: sff(:, :, :)
131 complex(real32),
pointer,
contiguous,
public :: cff(:, :, :)
132 real(real32),
pointer,
contiguous,
public :: sff_linear(:, :)
133 complex(real32),
pointer,
contiguous,
public :: cff_linear(:, :)
134 real(real32),
pointer,
contiguous,
public :: sff_pack(:, :)
135 complex(real32),
pointer,
contiguous,
public :: cff_pack(:, :)
137 integer(int64),
public :: pack_size(1:2)
139 integer(int64),
public :: pack_size_real(1:2)
143 type(accel_mem_t),
public :: ff_device
153 generic :: do_pack => do_pack_generic, do_pack_target
199 class(
batch_t),
allocatable :: p
221 integer,
public,
parameter :: &
241 logical,
optional,
intent(in) :: copy
246 if (this%own_memory .and. this%is_packed())
then
249 call this%deallocate_packed_device()
252 call this%deallocate_packed_host()
256 this%host_buffer_count = 0
257 this%device_buffer_count = 0
262 if (this%is_allocated)
then
263 call this%deallocate_unpacked_host()
266 safe_deallocate_a(this%ist_idim_index)
267 safe_deallocate_a(this%ist)
278 class(batch_t),
intent(inout) :: this
282 this%is_allocated = .false.
284 if (this%special_memory)
then
285 if (
associated(this%dff))
then
288 if (
associated(this%zff))
then
291 if (
associated(this%sff))
then
294 if (
associated(this%cff))
then
298 safe_deallocate_p(this%dff)
299 safe_deallocate_p(this%zff)
300 safe_deallocate_p(this%sff)
301 safe_deallocate_p(this%cff)
304 nullify(this%dff_linear)
306 nullify(this%zff_linear)
308 nullify(this%sff_linear)
310 nullify(this%cff_linear)
321 class(
batch_t),
intent(inout) :: this
325 if (this%special_memory)
then
326 if (
associated(this%dff_pack))
then
329 if (
associated(this%zff_pack))
then
332 if (
associated(this%sff_pack))
then
335 if (
associated(this%cff_pack))
then
339 safe_deallocate_p(this%dff_pack)
340 safe_deallocate_p(this%zff_pack)
341 safe_deallocate_p(this%sff_pack)
342 safe_deallocate_p(this%cff_pack)
344 nullify(this%dff_pack)
345 nullify(this%zff_pack)
346 nullify(this%sff_pack)
347 nullify(this%cff_pack)
356 class(
batch_t),
intent(inout) :: this
371 class(
batch_t),
intent(inout) :: this
376 call this%dallocate_unpacked_host()
378 call this%zallocate_unpacked_host()
380 call this%sallocate_unpacked_host()
382 call this%callocate_unpacked_host()
394 class(
batch_t),
intent(inout) :: this
399 call this%dallocate_packed_host()
401 call this%zallocate_packed_host()
403 call this%sallocate_packed_host()
405 call this%callocate_packed_host()
417 class(
batch_t),
intent(inout) :: this
422 product(this%pack_size))
435 type(
batch_t),
intent(out) :: this
436 integer,
intent(in) :: dim
437 integer,
intent(in) :: nst
438 integer,
intent(in) :: np
442 this%is_allocated = .false.
443 this%own_memory = .false.
444 this%special_memory = .false.
445 this%needs_finish_unpack = .false.
450 this%nst_linear = nst*dim
453 this%device_buffer_count = 0
454 this%host_buffer_count = 0
459 safe_allocate(this%ist_idim_index(1:this%nst_linear, 1:this%ndims))
460 safe_allocate(this%ist(1:this%nst))
462 nullify(this%dff, this%zff, this%dff_linear, this%zff_linear)
463 nullify(this%dff_pack, this%zff_pack)
464 nullify(this%sff, this%cff, this%sff_linear, this%cff_linear)
465 nullify(this%sff_pack, this%cff_pack)
476 subroutine batch_clone_to(this, dest, pack, copy_data, new_np, special, dest_type)
477 class(
batch_t),
intent(in) :: this
478 class(
batch_t),
allocatable,
intent(out) :: dest
479 logical,
optional,
intent(in) :: pack
481 logical,
optional,
intent(in) :: copy_data
483 integer,
optional,
intent(in) :: new_np
484 logical,
optional,
intent(in) :: special
486 type(
type_t),
optional,
intent(in) :: dest_type
490 if (.not.
allocated(dest))
then
491 safe_allocate_type(
batch_t, dest)
493 message(1) =
"Internal error: destination batch in batch_clone_to has been previously allocated."
497 call this%copy_to(dest, pack, copy_data, new_np, special, dest_type)
504 subroutine batch_clone_to_array(this, dest, n_batches, pack, copy_data, new_np, special, dest_type)
505 class(
batch_t),
intent(in) :: this
506 class(
batch_t),
allocatable,
intent(out) :: dest(:)
507 integer,
intent(in) :: n_batches
508 logical,
optional,
intent(in) :: pack
510 logical,
optional,
intent(in) :: copy_data
512 integer,
optional,
intent(in) :: new_np
513 logical,
optional,
intent(in) :: special
515 type(
type_t),
optional,
intent(in) :: dest_type
521 if (.not.
allocated(dest))
then
522 safe_allocate_type_array(
batch_t, dest, (1:n_batches))
524 message(1) =
"Internal error: destination batch in batch_clone_to_array has been previously allocated."
529 call this%copy_to(dest(ib), pack, copy_data, new_np, special, dest_type)
540 subroutine batch_copy_to(this, dest, pack, copy_data, new_np, special, dest_type)
541 class(
batch_t),
intent(in) :: this
542 class(
batch_t),
intent(out) :: dest
543 logical,
optional,
intent(in) :: pack
545 logical,
optional,
intent(in) :: copy_data
547 integer,
optional,
intent(in) :: new_np
548 logical,
optional,
intent(in) :: special
550 type(
type_t),
optional,
intent(in) :: dest_type
552 logical :: host_packed, special_
560 host_packed = this%host_buffer_count > 0
564 if (
present(special))
then
565 special_ = this%special_memory
567 special_ = this%special_memory .and. .not. this%device_buffer_count > 0
570 if (
present(dest_type))
then
577 call dbatch_init(dest, this%dim, 1, this%nst, np_, packed=host_packed, special=special_)
579 call zbatch_init(dest, this%dim, 1, this%nst, np_, packed=host_packed, special=special_)
581 call sbatch_init(dest, this%dim, 1, this%nst, np_, packed=host_packed, special=special_)
583 call cbatch_init(dest, this%dim, 1, this%nst, np_, packed=host_packed, special=special_)
585 message(1) =
"Internal error: unknown batch type in batch_copy_to."
589 if (this%status() /= dest%status() .and.
optional_default(pack, this%is_packed()))
call dest%do_pack(copy = .false.)
591 dest%ist_idim_index(1:this%nst_linear, 1:this%ndims) = this%ist_idim_index(1:this%nst_linear, 1:this%ndims)
592 dest%ist(1:this%nst) = this%ist(1:this%nst)
595 assert(np_ == this%np)
598 call this%copy_data_to(min(this%np, np_), dest)
609 type(
type_t)
pure function batch_type(this) result(btype)
610 class(
batch_t),
intent(in) :: this
618 integer pure function batch_type_as_integer(this) result(itype)
619 class(
batch_t),
intent(in) :: this
621 type(type_t) :: btype
625 if (btype == type_float) itype = 1
626 if (btype == type_cmplx) itype = 2
627 if (btype == type_float_single) itype = 3
628 if (btype == type_cmplx_single) itype = 4
637 integer pure function batch_status(this) result(bstatus)
638 class(
batch_t),
intent(in) :: this
640 bstatus = this%status_of
645 logical pure function batch_is_packed(this) result(in_buffer)
646 class(
batch_t),
intent(in) :: this
648 in_buffer = (this%device_buffer_count > 0) .or. (this%host_buffer_count > 0)
654 class(
batch_t),
intent(inout) :: this
657 if (accel_is_enabled())
size = accel_padded_size(size)
658 size = size*pad_pow2(this%nst_linear)*types_get_size(this%type())
670 class(
batch_t),
intent(inout) :: this
671 logical,
optional,
intent(in) :: copy
672 logical,
optional,
intent(in) :: async
675 integer :: source, target
680 source = this%status()
683 if (accel_is_enabled())
then
692 call this%do_pack(
target, copy, async)
701 class(
batch_t),
intent(inout) :: this
702 integer,
intent(in) ::
target
703 logical,
optional,
intent(in) :: copy
704 logical,
optional,
intent(in) :: async
706 logical,
optional,
intent(in) :: cpu_only
714 call profiling_in(
"BATCH_DO_PACK")
716 copy_ = optional_default(copy, .
true.)
718 async_ = optional_default(async, .false.)
721 source = this%status()
724 if (source /=
target)
then
727 call this%allocate_packed_device()
741 call this%allocate_packed_host()
746 if (this%type() == type_float)
then
748 else if (this%type() == type_cmplx)
then
750 else if (this%type() == type_float_single)
then
752 else if (this%type() == type_cmplx_single)
then
756 if (this%own_memory)
call this%deallocate_unpacked_host()
758 call messages_not_implemented(
"Error: batch_do_pack called with BATCH_NOT_PACKED as target.")
764 this%device_buffer_count = this%device_buffer_count + 1
766 this%host_buffer_count = this%host_buffer_count + 1
769 call profiling_out(
"BATCH_DO_PACK")
779 class(
batch_t),
intent(inout) :: this
780 logical,
optional,
intent(in) :: copy
781 logical,
optional,
intent(in) :: force
782 logical,
optional,
intent(in) :: async
785 logical :: copy_, force_, async_
786 integer :: source, target
790 call profiling_in(
"BATCH_DO_UNPACK")
792 copy_ = optional_default(copy, .
true.)
794 force_ = optional_default(force, .false.)
796 async_ = optional_default(async, .false.)
799 source = this%status()
806 target = this%status_host
810 if (source /=
target)
then
813 if (this%host_buffer_count == 1 .or. force_)
then
814 if (this%own_memory)
call this%allocate_unpacked_host()
816 if (copy_ .or. this%own_memory)
then
817 if (this%type() == type_float)
then
819 else if (this%type() == type_cmplx)
then
821 else if (this%type() == type_float_single)
then
823 else if (this%type() == type_cmplx_single)
then
827 call this%deallocate_packed_host()
828 this%status_host =
target
829 this%status_of =
target
830 this%host_buffer_count = 1
832 this%host_buffer_count = this%host_buffer_count - 1
834 if (this%device_buffer_count == 1 .or. force_)
then
846 this%needs_finish_unpack = .
true.
848 call this%deallocate_packed_device()
850 this%status_of =
target
851 this%device_buffer_count = 1
853 this%device_buffer_count = this%device_buffer_count - 1
857 call profiling_out(
"BATCH_DO_UNPACK")
865 class(
batch_t),
intent(inout) :: this
868 if (this%needs_finish_unpack)
then
870 call this%deallocate_packed_device()
871 this%needs_finish_unpack = .false.
879 class(
batch_t),
intent(inout) :: this
882 integer(int64) :: unroll, bsize, gsize
883 type(accel_mem_t) :: tmp
884 type(accel_kernel_t),
pointer :: kernel
888 call profiling_in(
"BATCH_WRT_UNPACK_ACCEL")
889 if (this%nst_linear == 1)
then
891 if (this%type() == type_float)
then
892 call accel_write_buffer(this%ff_device, ubound(this%dff_linear, dim=1), this%dff_linear(:, 1))
893 else if (this%type() == type_cmplx)
then
894 call accel_write_buffer(this%ff_device, ubound(this%zff_linear, dim=1), this%zff_linear(:, 1))
895 else if (this%type() == type_float_single)
then
896 call accel_write_buffer(this%ff_device, ubound(this%sff_linear, dim=1), this%sff_linear(:, 1))
898 call accel_write_buffer(this%ff_device, ubound(this%cff_linear, dim=1), this%cff_linear(:, 1))
904 if (this%type() == type_float)
then
906 else if (this%type() == type_cmplx)
then
908 else if (this%type() == type_float_single)
then
916 call accel_create_buffer(tmp, accel_mem_read_only, this%type(), unroll*this%pack_size(2))
918 do ist = 1, this%nst_linear, int(unroll, int32)
921 do ist2 = ist, min(ist + int(unroll, int32) - 1, this%nst_linear)
923 if (this%type() == type_float)
then
924 call accel_write_buffer(tmp, ubound(this%dff_linear, dim=1, kind=int64), this%dff_linear(:, ist2), &
925 offset = (ist2 - ist)*this%pack_size(2))
926 else if (this%type() == type_cmplx)
then
927 call accel_write_buffer(tmp, ubound(this%zff_linear, dim=1, kind=int64), this%zff_linear(:, ist2), &
928 offset = (ist2 - ist)*this%pack_size(2))
929 else if (this%type() == type_float_single)
then
930 call accel_write_buffer(tmp, ubound(this%sff_linear, dim=1, kind=int64), this%sff_linear(:, ist2), &
931 offset = (ist2 - ist)*this%pack_size(2))
933 call accel_write_buffer(tmp, ubound(this%cff_linear, dim=1, kind=int64), this%cff_linear(:, ist2), &
934 offset = (ist2 - ist)*this%pack_size(2))
939 call accel_set_kernel_arg(kernel, 0, int(this%pack_size(1), int32))
940 call accel_set_kernel_arg(kernel, 1, this%np)
941 call accel_set_kernel_arg(kernel, 2, this%nst_linear)
942 call accel_set_kernel_arg(kernel, 3, ist - 1)
943 call accel_set_kernel_arg(kernel, 4, tmp)
944 call accel_set_kernel_arg(kernel, 5, this%ff_device)
946 call profiling_in(
"GPU_PACK")
949 bsize = accel_max_block_size()/unroll
950 call accel_grid_size(this%pack_size(2), bsize, gsize)
952 call accel_kernel_run(kernel, (/gsize, 1_int64/), (/bsize, unroll/))
954 if (this%type() == type_float)
then
955 call profiling_count_transfers(unroll*this%pack_size(2), m_one)
957 call profiling_count_transfers(unroll*this%pack_size(2), m_zi)
961 call profiling_out(
"GPU_PACK")
965 call accel_free_buffer(tmp)
969 call profiling_out(
"BATCH_WRT_UNPACK_ACCEL")
976 class(
batch_t),
intent(inout) :: this
979 integer(int64) :: unroll, bsize, gsize
980 type(accel_mem_t) :: tmp
981 type(accel_kernel_t),
pointer :: kernel
984 call profiling_in(
"BATCH_READ_UNPACKED_ACCEL")
986 if (this%nst_linear == 1)
then
988 if (this%type() == type_float)
then
989 call accel_read_buffer(this%ff_device, ubound(this%dff_linear, dim=1), this%dff_linear(:, 1))
990 else if (this%type() == type_cmplx)
then
991 call accel_read_buffer(this%ff_device, ubound(this%zff_linear, dim=1), this%zff_linear(:, 1))
992 else if (this%type() == type_float_single)
then
993 call accel_read_buffer(this%ff_device, ubound(this%sff_linear, dim=1), this%sff_linear(:, 1))
995 call accel_read_buffer(this%ff_device, ubound(this%cff_linear, dim=1), this%cff_linear(:, 1))
1002 call accel_create_buffer(tmp, accel_mem_write_only, this%type(), unroll*this%pack_size(2))
1004 if (this%type() == type_float)
then
1006 else if (this%type() == type_cmplx)
then
1008 else if (this%type() == type_float_single)
then
1014 do ist = 1, this%nst_linear, int(unroll, int32)
1015 call accel_set_kernel_arg(kernel, 0, int(this%pack_size(1), int32))
1016 call accel_set_kernel_arg(kernel, 1, this%np)
1017 call accel_set_kernel_arg(kernel, 2, this%nst_linear)
1018 call accel_set_kernel_arg(kernel, 3, ist - 1)
1019 call accel_set_kernel_arg(kernel, 4, this%ff_device)
1020 call accel_set_kernel_arg(kernel, 5, tmp)
1022 call profiling_in(
"GPU_UNPACK")
1025 bsize = accel_max_block_size()/unroll
1026 call accel_grid_size(this%pack_size(2), bsize, gsize)
1028 call accel_kernel_run(kernel, (/1_int64, gsize/), (/unroll, bsize/))
1030 if (this%type() == type_float)
then
1031 call profiling_count_transfers(unroll*this%pack_size(2), m_one)
1033 call profiling_count_transfers(unroll*this%pack_size(2), m_zi)
1037 call profiling_out(
"GPU_UNPACK")
1040 do ist2 = ist, min(ist + int(unroll, int32) - 1, this%nst_linear)
1042 if (this%type() == type_float)
then
1043 call accel_read_buffer(tmp, ubound(this%dff_linear, dim=1, kind=int64), this%dff_linear(:, ist2), &
1044 offset = (ist2 - ist)*this%pack_size(2))
1045 else if (this%type() == type_cmplx)
then
1046 call accel_read_buffer(tmp, ubound(this%zff_linear, dim=1, kind=int64), this%zff_linear(:, ist2), &
1047 offset = (ist2 - ist)*this%pack_size(2))
1048 else if (this%type() == type_float_single)
then
1049 call accel_read_buffer(tmp, ubound(this%sff_linear, dim=1, kind=int64), this%sff_linear(:, ist2), &
1050 offset = (ist2 - ist)*this%pack_size(2))
1052 call accel_read_buffer(tmp, ubound(this%cff_linear, dim=1, kind=int64), this%cff_linear(:, ist2), &
1053 offset = (ist2 - ist)*this%pack_size(2))
1059 call accel_free_buffer(tmp)
1062 call profiling_out(
"BATCH_READ_UNPACKED_ACCEL")
1068 class(
batch_t),
intent(inout) :: this
1069 logical,
optional,
intent(in) :: async
1074 call profiling_in(
"BATCH_WRITE_PACKED_ACCEL")
1075 if (this%type() == type_float)
then
1076 call accel_write_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%dff_pack, async=async)
1077 else if (this%type() == type_cmplx)
then
1078 call accel_write_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%zff_pack, async=async)
1079 else if (this%type() == type_float_single)
then
1080 call accel_write_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%sff_pack, async=async)
1082 call accel_write_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%cff_pack, async=async)
1084 call profiling_out(
"BATCH_WRITE_PACKED_ACCEL")
1091 class(
batch_t),
intent(inout) :: this
1092 logical,
optional,
intent(in) :: async
1097 call profiling_in(
"BATCH_READ_PACKED_ACCEL")
1098 if (this%type() == type_float)
then
1099 call accel_read_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%dff_pack, async=async)
1100 else if (this%type() == type_cmplx)
then
1101 call accel_read_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%zff_pack, async=async)
1102 else if (this%type() == type_float_single)
then
1103 call accel_read_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%sff_pack, async=async)
1105 call accel_read_buffer(this%ff_device, this%pack_size(1), this%pack_size(2), this%cff_pack, async=async)
1107 call profiling_out(
"BATCH_READ_PACKED_ACCEL")
1118 class(
batch_t),
intent(in) :: this
1119 integer,
intent(in) :: cind(:)
1121 do index = 1, this%nst_linear
1122 if (all(cind(1:this%ndims) == this%ist_idim_index(index, 1:this%ndims)))
exit
1125 assert(index <= this%nst_linear)
1134 integer pure function batch_ist_idim_to_linear(this, cind) result(index)
1135 class(
batch_t),
intent(in) :: this
1136 integer,
intent(in) :: cind(:)
1138 if (ubound(cind, dim = 1) == 1)
then
1141 index = (cind(1) - 1)*this%dim + cind(2)
1153 class(
batch_t),
intent(in) :: this
1154 integer,
intent(in) :: linear_index
1156 ist = this%ist_idim_index(linear_index, 1)
1164 class(
batch_t),
intent(in) :: this
1165 integer,
intent(in) :: linear_index
1167 idim = this%ist_idim_index(linear_index, 2)
1182 class(
batch_t),
intent(inout) :: this
1183 type(mpi_grp_t),
intent(in) :: mpi_grp
1184 type(mpi_win),
intent(out) :: rma_win
1188 if (mpi_grp%size > 1)
then
1190 assert(.not. accel_is_enabled())
1194 assert(int(product(this%pack_size)*types_get_size(this%type())) > 0)
1195 if (this%type() == type_cmplx)
then
1197 call mpi_win_create(this%zff_pack(1, 1), int(product(this%pack_size)*types_get_size(this%type()), mpi_address_kind), &
1198 types_get_size(this%type()), mpi_info_null, mpi_grp%comm, rma_win)
1200 else if (this%type() == type_float)
then
1202 call mpi_win_create(this%dff_pack(1, 1), int(product(this%pack_size)*types_get_size(this%type()), mpi_address_kind), &
1203 types_get_size(this%type()), mpi_info_null, mpi_grp%comm, rma_win)
1205 else if (this%type() == type_cmplx_single)
then
1207 call mpi_win_create(this%cff_pack(1, 1), int(product(this%pack_size)*types_get_size(this%type()), mpi_address_kind), &
1208 types_get_size(this%type()), mpi_info_null, mpi_grp%comm, rma_win)
1210 else if (this%type() == type_float_single)
then
1212 call mpi_win_create(this%sff_pack(1, 1), int(product(this%pack_size)*types_get_size(this%type()), mpi_address_kind), &
1213 types_get_size(this%type()), mpi_info_null, mpi_grp%comm, rma_win)
1216 message(1) =
"Internal error: unknown batch type in batch_remote_access_start."
1217 call messages_fatal(1)
1221 rma_win = mpi_win_null
1236 type(mpi_win),
intent(inout) :: rma_win
1240 if (rma_win /= mpi_win_null)
then
1242 call mpi_win_free(rma_win)
1244 call this%do_unpack()
1254 class(
batch_t),
intent(in) :: this
1255 integer,
intent(in) :: np
1256 class(
batch_t),
intent(inout) :: dest
1257 logical,
optional,
intent(in) :: async
1259 integer(int64),
dimension(3) :: gsizes, bsizes
1261 type(accel_kernel_t),
pointer :: kernel
1264 call profiling_in(
"BATCH_COPY_DATA_TO")
1267 call this%check_compatibility_with(dest, type_check=.false.)
1269 if (this%type() == dest%type())
then
1270 select case (this%status())
1274 if (type_is_single(this%type()))
then
1275 kernel => kernel_scopy
1277 kernel => kernel_copy
1279 call accel_set_kernel_arg(kernel, 0, np)
1280 call accel_set_kernel_arg(kernel, 1, this%ff_device)
1281 call accel_set_kernel_arg(kernel, 2,
log2(int(this%pack_size_real(1), int32)))
1282 call accel_set_kernel_arg(kernel, 3, dest%ff_device)
1283 call accel_set_kernel_arg(kernel, 4,
log2(int(dest%pack_size_real(1), int32)))
1286 call accel_grid_size_extend_dim(int(np, int64), dest%pack_size_real(1), gsizes, bsizes, kernel)
1288 call accel_kernel_run(kernel, gsizes, bsizes)
1290 if(.not. optional_default(async, .false.))
call accel_finish()
1293 if (dest%type() == type_float_single)
then
1296 do ist = 1, int(this%pack_size(1), int32)
1297 dest%sff_pack(ist, ip) = this%sff_pack(ist, ip)
1300 else if (dest%type() == type_cmplx_single)
then
1303 do ist = 1, int(this%pack_size(1), int32)
1304 dest%cff_pack(ist, ip) = this%cff_pack(ist, ip)
1307 else if (np*this%pack_size(1) > huge(0_int32))
then
1310 if (dest%type() == type_float)
then
1311 call blas_copy(int(this%pack_size(1), int32), this%dff_pack(1, ip), 1, dest%dff_pack(1, ip), 1)
1313 call blas_copy(int(this%pack_size(1), int32), this%zff_pack(1, ip), 1, dest%zff_pack(1, ip), 1)
1317 if (dest%type() == type_float)
then
1318 call blas_copy(int(this%pack_size(1)*np, int32), this%dff_pack(1, 1), 1, dest%dff_pack(1, 1), 1)
1320 call blas_copy(int(this%pack_size(1)*np, int32), this%zff_pack(1, 1), 1, dest%zff_pack(1, 1), 1)
1325 do ist = 1, dest%nst_linear
1326 if (dest%type() == type_cmplx)
then
1327 call blas_copy(np, this%zff_linear(1, ist), 1, dest%zff_linear(1, ist), 1)
1328 else if (dest%type() == type_float_single)
then
1331 dest%sff_linear(ip, ist) = this%sff_linear(ip, ist)
1333 else if (dest%type() == type_cmplx_single)
then
1336 dest%cff_linear(ip, ist) = this%cff_linear(ip, ist)
1339 call blas_copy(np, this%dff_linear(1, ist), 1, dest%dff_linear(1, ist), 1)
1344 else if (this%type() == type_cmplx)
then
1346 select case (this%status())
1348 call accel_set_kernel_arg(kernel_copy_complex_to_real, 0, np)
1349 call accel_set_kernel_arg(kernel_copy_complex_to_real, 1, this%ff_device)
1350 call accel_set_kernel_arg(kernel_copy_complex_to_real, 2,
log2(int(this%pack_size_real(1), int32)))
1351 call accel_set_kernel_arg(kernel_copy_complex_to_real, 3, dest%ff_device)
1352 call accel_set_kernel_arg(kernel_copy_complex_to_real, 4,
log2(int(dest%pack_size_real(1), int32)))
1355 call accel_grid_size_extend_dim(int(np, int64), dest%pack_size_real(1), gsizes, bsizes, kernel_copy_complex_to_real)
1357 call accel_kernel_run(kernel_copy_complex_to_real, gsizes, bsizes)
1359 if(.not. optional_default(async, .false.))
call accel_finish()
1365 do ist = 1, dest%nst_linear
1366 dest%dff_pack(ist, ip) = real(this%zff_pack(ist, ip), real64)
1372 do ist = 1, dest%nst_linear
1375 dest%dff_linear(ip, ist) = real(this%zff_linear(ip, ist), real64)
1381 else if (this%type() == type_float)
then
1383 select case (this%status())
1385 call accel_set_kernel_arg(kernel_copy_real_to_complex, 0, np)
1386 call accel_set_kernel_arg(kernel_copy_real_to_complex, 1, this%ff_device)
1387 call accel_set_kernel_arg(kernel_copy_real_to_complex, 2,
log2(int(this%pack_size_real(1), int32)))
1388 call accel_set_kernel_arg(kernel_copy_real_to_complex, 3, dest%ff_device)
1389 call accel_set_kernel_arg(kernel_copy_real_to_complex, 4,
log2(int(dest%pack_size_real(1), int32)))
1392 call accel_grid_size_extend_dim(int(np, int64), this%pack_size_real(1), gsizes, bsizes, kernel_copy_real_to_complex)
1394 call accel_kernel_run(kernel_copy_real_to_complex, gsizes, bsizes)
1396 if(.not. optional_default(async, .false.))
call accel_finish()
1402 do ist = 1, dest%nst_linear
1403 dest%zff_pack(ist, ip) = cmplx(this%dff_pack(ist, ip), m_zero, real64)
1409 do ist = 1, dest%nst_linear
1412 dest%zff_linear(ip, ist) = cmplx(this%dff_linear(ip, ist), m_zero, real64)
1419 message(1) =
"Error! This should not happen."
1420 call messages_fatal(1)
1423 call profiling_out(
"BATCH_COPY_DATA_TO")
1431 class(
batch_t),
intent(in) :: this
1432 class(
batch_t),
intent(in) :: target
1433 logical,
optional,
intent(in) :: only_check_dim
1434 logical,
optional,
intent(in) :: type_check
1438 if (optional_default(type_check, .
true.))
then
1439 assert(this%type() ==
target%type())
1441 if (.not. optional_default(only_check_dim, .false.))
then
1442 assert(this%nst_linear ==
target%nst_linear)
1444 assert(this%status() ==
target%status())
1445 assert(this%dim ==
target%dim)
1455 class(
batch_t),
intent(inout) :: this
1456 integer,
intent(in) :: st_start
1457 integer,
intent(in) :: st_end
1459 integer :: idim, ii, ist
1463 do ist = st_start, st_end
1465 do idim = 1, this%dim
1466 ii = this%dim*(ist - st_start) + idim
1467 this%ist_idim_index(ii, 1) = ist
1468 this%ist_idim_index(ii, 2) = idim
1470 this%ist(ist - st_start + 1) = ist
1474 this%pack_size(1) = pad_pow2(this%nst_linear)
1475 this%pack_size(2) = this%np
1476 if (accel_is_enabled()) this%pack_size(2) = accel_padded_size(this%pack_size(2))
1478 this%pack_size_real = this%pack_size
1479 if (type_is_complex(this%type())) this%pack_size_real(1) = 2*this%pack_size_real(1)
1486#include "batch_inc.F90"
1489#include "complex.F90"
1490#include "batch_inc.F90"
1493#include "real32.F90"
1494#include "batch_inc.F90"
1497#include "complex32.F90"
1498#include "batch_inc.F90"
initialize a batch with existing memory
double log2(double __x) __attribute__((__nothrow__
subroutine, public accel_free_buffer(this, async)
integer, parameter, public accel_mem_read_write
This module contains interfaces for routines in allocate_hardware_aware.c.
subroutine, public deallocate_hardware_aware(array, size)
This module implements batches of mesh functions.
type(type_t) pure function batch_type(this)
return the type of a batch
subroutine zbatch_pack_copy(this)
copy data from the unpacked to the packed arrays
subroutine cbatch_init_with_memory_3(this, dim, st_start, st_end, psi)
initialize a batch with an rank-3 array of TYPE_CMPLX_SINGLE valued mesh functions psi.
subroutine, public batch_write_packed_to_device(this, async)
integer, parameter, public batch_not_packed
functions are stored in CPU memory, unpacked order
integer, parameter, public batch_device_packed
functions are stored in device memory in packed order
subroutine zbatch_init_with_memory_3(this, dim, st_start, st_end, psi)
initialize a batch with an rank-3 array of TYPE_CMPLX valued mesh functions psi.
subroutine batch_check_compatibility_with(this, target, only_check_dim, type_check)
check whether two batches have compatible dimensions (and type)
logical pure function batch_is_packed(this)
subroutine dbatch_unpack_copy(this)
copy data from the packed to the unpacked arrays
subroutine cbatch_pack_copy(this)
copy data from the unpacked to the packed arrays
subroutine dbatch_init_with_memory_1(this, psi)
initialize a batch with an rank-1 array of TYPE_FLOAT valued mesh functions psi.
subroutine cbatch_init_with_memory_2(this, dim, st_start, st_end, psi)
initialize a batch with an rank-2 array of TYPE_CMPLX_SINGLE valued mesh functions psi.
subroutine batch_write_unpacked_to_device(this)
subroutine batch_do_unpack(this, copy, force, async)
unpack a batch
subroutine batch_finish_unpack(this)
finish the unpacking if do_unpack() was called with async=.true.
subroutine zbatch_allocate_unpacked_host(this)
allocate host (CPU) memory for unpacked data of type TYPE_CMPLX
subroutine batch_deallocate_packed_device(this)
release packed device memory
integer pure function batch_type_as_integer(this)
For debuging purpose only.
subroutine sbatch_unpack_copy(this)
copy data from the packed to the unpacked arrays
subroutine batch_do_pack_generic(this, copy, async)
pack the data in a batch
integer function batch_inv_index(this, cind)
inverse index lookup
subroutine dbatch_init_with_memory_2(this, dim, st_start, st_end, psi)
initialize a batch with an rank-2 array of TYPE_FLOAT valued mesh functions psi.
subroutine batch_allocate_packed_host(this)
allocate host (CPU) memory for packed data
subroutine, public zbatch_init(this, dim, st_start, st_end, np, special, packed)
initialize a TYPE_CMPLX valued batch to given size without providing external memory
subroutine zbatch_allocate_packed_host(this)
allocate host (CPU) memory for packed data of type TYPE_CMPLX
subroutine batch_clone_to(this, dest, pack, copy_data, new_np, special, dest_type)
clone a batch to a new batch
subroutine cbatch_allocate_unpacked_host(this)
allocate host (CPU) memory for unpacked data of type TYPE_CMPLX_SINGLE
subroutine batch_remote_access_stop(this, rma_win)
stop the remote access to the batch
subroutine sbatch_allocate_unpacked_host(this)
allocate host (CPU) memory for unpacked data of type TYPE_FLOAT_SINGLE
subroutine batch_read_device_to_unpacked(this)
subroutine zbatch_init_with_memory_1(this, psi)
initialize a batch with an rank-1 array of TYPE_CMPLX valued mesh functions psi.
subroutine, public sbatch_init(this, dim, st_start, st_end, np, special, packed)
initialize a TYPE_FLOAT_SINGLE valued batch to given size without providing external memory
subroutine sbatch_pack_copy(this)
copy data from the unpacked to the packed arrays
subroutine dbatch_allocate_packed_host(this)
allocate host (CPU) memory for packed data of type TYPE_FLOAT
subroutine batch_clone_to_array(this, dest, n_batches, pack, copy_data, new_np, special, dest_type)
subroutine batch_allocate_packed_device(this)
allocate device (GPU) memory for packed data
subroutine batch_build_indices(this, st_start, st_end)
build the index ist(:) and ist_idim_index(:,:) and set pack_size
integer pure function batch_ist_idim_to_linear(this, cind)
direct index lookup
integer, parameter gpu_pack_max_buffer_size
this value controls the size (in number of wave-functions) of the buffer used to copy states to the G...
subroutine batch_do_pack_target(this, target, copy, async, cpu_only)
pack the data in a batch
subroutine sbatch_init_with_memory_1(this, psi)
initialize a batch with an rank-1 array of TYPE_FLOAT_SINGLE valued mesh functions psi.
integer pure function batch_linear_to_ist(this, linear_index)
get state index ist from linear (combined dim and nst) index
subroutine batch_copy_to(this, dest, pack, copy_data, new_np, special, dest_type)
make a copy of a batch
subroutine, public batch_read_device_to_packed(this, async)
subroutine cbatch_unpack_copy(this)
copy data from the packed to the unpacked arrays
subroutine dbatch_init_with_memory_3(this, dim, st_start, st_end, psi)
initialize a batch with an rank-3 array of TYPE_FLOAT valued mesh functions psi.
subroutine cbatch_init_with_memory_1(this, psi)
initialize a batch with an rank-1 array of TYPE_CMPLX_SINGLE valued mesh functions psi.
subroutine batch_allocate_unpacked_host(this)
allocate host (CPU) memory for unpacked data
subroutine, public cbatch_init(this, dim, st_start, st_end, np, special, packed)
initialize a TYPE_CMPLX_SINGLE valued batch to given size without providing external memory
subroutine batch_init_empty(this, dim, nst, np)
initialize an empty batch
subroutine, public dbatch_init(this, dim, st_start, st_end, np, special, packed)
initialize a TYPE_FLOAT valued batch to given size without providing external memory
subroutine zbatch_init_with_memory_2(this, dim, st_start, st_end, psi)
initialize a batch with an rank-2 array of TYPE_CMPLX valued mesh functions psi.
integer pure function batch_linear_to_idim(this, linear_index)
extract idim from linear index
subroutine batch_remote_access_start(this, mpi_grp, rma_win)
start remote access to a batch on another node
subroutine sbatch_allocate_packed_host(this)
allocate host (CPU) memory for packed data of type TYPE_FLOAT_SINGLE
subroutine batch_copy_data_to(this, np, dest, async)
copy data to another batch.
subroutine dbatch_allocate_unpacked_host(this)
allocate host (CPU) memory for unpacked data of type TYPE_FLOAT
subroutine dbatch_pack_copy(this)
copy data from the unpacked to the packed arrays
subroutine cbatch_allocate_packed_host(this)
allocate host (CPU) memory for packed data of type TYPE_CMPLX_SINGLE
subroutine sbatch_init_with_memory_2(this, dim, st_start, st_end, psi)
initialize a batch with an rank-2 array of TYPE_FLOAT_SINGLE valued mesh functions psi.
subroutine sbatch_init_with_memory_3(this, dim, st_start, st_end, psi)
initialize a batch with an rank-3 array of TYPE_FLOAT_SINGLE valued mesh functions psi.
integer pure function batch_status(this)
return the status of a batch
subroutine batch_deallocate_unpacked_host(this)
release unpacked host memory
integer, parameter, public batch_packed
functions are stored in CPU memory, in transposed (packed) order
subroutine batch_deallocate_packed_host(this)
release packed host memory
integer(int64) function batch_pack_total_size(this)
subroutine batch_end(this, copy)
finalize a batch and release allocated memory, if necessary
subroutine zbatch_unpack_copy(this)
copy data from the packed to the unpacked arrays
This module contains interfaces for BLAS routines You should not use these routines directly....
This module is intended to contain "only mathematical" functions and procedures.
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
type(type_t), parameter, public type_cmplx_single
type(type_t), parameter, public type_float_single
type(type_t), parameter, public type_cmplx
type(type_t), parameter, public type_float
logical pure function, public type_is_single(this)
type(type_t), parameter, public type_none
Class defining batches of mesh functions.