30 use iso_c_binding,
only: c_null_ptr, c_size_t
31 use,
intrinsic :: iso_fortran_env
92 integer,
public,
parameter :: &
93 ACCEL_MEM_READ_ONLY = 0, &
100 type(c_ptr) :: cuda_context
108#if defined(HAVE_CUDA)
109 type(c_ptr) :: cuda_device
117 type(accel_context_t) :: context
118 type(accel_device_t) :: device
119 type(c_ptr) :: cublas_handle
120 type(c_ptr) :: cuda_stream
121 type(c_ptr) :: program_map
122 integer :: max_block_size
123 integer(int64) :: shared_memory_size
124 integer(int64) :: global_memory_size
126 logical :: allow_CPU_only
129 integer(int64) :: initialize_buffers
130 character(len=32) :: debug_flag
131 integer(int64) :: max_block_dim(3)
132 integer(int64) :: max_grid_dim(3)
138 integer(c_size_t) :: size = 0
141 logical :: allocated = .false.
147 type(c_ptr) :: cuda_kernel
148 type(c_ptr) :: arguments
150 logical :: initialized = .false.
151 type(accel_kernel_t),
pointer :: next
153 character(len=128) :: kernel_name
156 type(accel_t),
public :: accel
159 type(accel_mem_t),
public,
save :: zM_0_buffer, zM_1_buffer
160 type(accel_mem_t),
public,
save :: dM_0_buffer, dM_1_buffer
163 type(accel_kernel_t),
public,
target,
save :: kernel_vpsi
164 type(accel_kernel_t),
public,
target,
save :: kernel_vpsi_complex
165 type(accel_kernel_t),
public,
target,
save :: kernel_vpsi_spinors
166 type(accel_kernel_t),
public,
target,
save :: kernel_vpsi_spinors_complex
167 type(accel_kernel_t),
public,
target,
save :: kernel_daxpy
168 type(accel_kernel_t),
public,
target,
save :: kernel_zaxpy
169 type(accel_kernel_t),
public,
target,
save :: kernel_copy
170 type(accel_kernel_t),
public,
target,
save :: kernel_copy_complex_to_real
171 type(accel_kernel_t),
public,
target,
save :: kernel_copy_real_to_complex
172 type(accel_kernel_t),
public,
target,
save :: dpack
173 type(accel_kernel_t),
public,
target,
save :: zpack
174 type(accel_kernel_t),
public,
target,
save :: dunpack
175 type(accel_kernel_t),
public,
target,
save :: zunpack
176 type(accel_kernel_t),
public,
target,
save :: kernel_ghost_reorder
177 type(accel_kernel_t),
public,
target,
save :: kernel_density_real
178 type(accel_kernel_t),
public,
target,
save :: kernel_density_complex
179 type(accel_kernel_t),
public,
target,
save :: kernel_density_spinors
180 type(accel_kernel_t),
public,
target,
save :: kernel_phase
181 type(accel_kernel_t),
public,
target,
save :: kernel_phase_spiral
182 type(accel_kernel_t),
public,
target,
save :: zkernel_dot_matrix_spinors
183 type(accel_kernel_t),
public,
target,
save :: dzmul_batch
184 type(accel_kernel_t),
public,
target,
save :: zzmul_batch
292 integer :: buffer_alloc_count
293 integer(int64) :: allocated_mem
294 type(accel_kernel_t),
pointer :: head
295 type(alloc_cache_t) :: memcache
301 enabled = accel%enabled
311 allow = accel%allow_CPU_only
320 type(mpi_grp_t),
intent(inout) :: base_grp
321 type(namespace_t),
intent(in) :: namespace
323 logical :: disable, default, run_benchmark
328 character(len=256) :: sys_name
334 buffer_alloc_count = 0
352 accel%enabled = .not. disable
355 if (accel%enabled)
then
356 message(1) =
'Octopus was compiled without Cuda support.'
384 if (idevice < 0)
then
392 if (idevice<0) idevice = 0
393 call cuda_init(accel%context%cuda_context, accel%device%cuda_device, accel%cuda_stream, &
394 idevice, base_grp%rank)
397 write(
message(1),
'(A,I5,A,I5,2A)')
"Rank ", base_grp%rank,
" uses device number ", idevice, &
398 " on ", trim(sys_name)
402 call cublas_init(accel%cublas_handle, accel%cuda_stream)
413 accel%max_block_dim(1) = int(dim, int64)
415 accel%max_block_dim(2) = int(dim, int64)
417 accel%max_block_dim(3) = int(dim, int64)
419 accel%max_grid_dim(1) = int(dim, int64)
421 accel%max_grid_dim(2) = int(dim, int64)
423 accel%max_grid_dim(3) = int(dim, int64)
429 call alloc_cache_init(memcache, nint(0.25_real64*accel%global_memory_size, int64))
435 accel%debug_flag =
"-g"
436#elif defined(HAVE_CUDA)
437 accel%debug_flag =
"-lineinfo"
491 call parse_variable(namespace,
'AccelBenchmark', .false., run_benchmark)
495 if (run_benchmark)
then
516 call parse_variable(namespace,
'GPUAwareMPI', default, accel%cuda_mpi)
517 if (accel%cuda_mpi)
then
519 call messages_write(
"Warning: trying to use GPU-aware MPI, but we have not detected support in the linked MPI library.")
535#if defined (HAVE_ACCEL)
540 call parse_variable(namespace,
'AllowCPUonly', default, accel%allow_CPU_only)
556 call parse_variable(namespace,
'InitializeGPUBuffers', option__initializegpubuffers__no, accel%initialize_buffers)
571 character(kind=c_char) :: cval_str(257)
573 integer :: major, minor
574 character(len=256) :: val_str
583#ifdef __HIP_PLATFORM_AMD__
593#ifdef __HIP_PLATFORM_AMD__
601 cval_str = c_null_char
649 integer(int64) :: hits, misses
650 real(real64) :: volume_hits, volume_misses
666 if (.not. found)
exit
673 call alloc_cache_end(memcache, hits, misses, volume_hits, volume_misses)
684 if (hits + misses > 0)
then
685 call messages_write(hits/real(hits + misses, real64)*100, fmt=
'(f6.1)', align_left = .
true.)
691 if (volume_hits + volume_misses > 0)
then
692 call messages_write(volume_hits/(volume_hits + volume_misses)*100, fmt=
'(f6.1)', align_left = .
true.)
707 call cublas_end(accel%cublas_handle)
708 if (.not. accel%cuda_mpi)
then
709 call cuda_end(accel%context%cuda_context, accel%device%cuda_device)
713 if (buffer_alloc_count /= 0)
then
731 integer(int64),
intent(in) :: n(:)
732 integer(int64),
intent(in) :: blocksizes(:)
733 integer(int64),
intent(out) :: gridsizes(:)
737 dim = ubound(n, dim=1)
738 assert(dim == ubound(blocksizes, dim=1))
739 assert(dim == ubound(gridsizes, dim=1))
742 gridsizes(i) = (n(i) + blocksizes(i) - 1_int64) / blocksizes(i)
743 gridsizes(i) = min(gridsizes(i), accel%max_grid_dim(i))
751 integer,
intent(in) :: n(:)
752 integer,
intent(in) :: blocksizes(:)
753 integer,
intent(out) :: gridsizes(:)
755 integer(int64) :: gridsizes64(size(gridsizes))
759 gridsizes = int(gridsizes64, int32)
766 integer(int64),
intent(in) :: n
767 integer(int64),
intent(in) :: blocksizes
768 integer(int64),
intent(out) :: gridsizes
770 integer(int64) :: temp(1)
781 integer,
intent(in) :: n
782 integer,
intent(in) :: blocksizes
783 integer,
intent(out) :: gridsizes
785 integer(int64) :: temp(1)
789 gridsizes = int(temp(1), int32)
798 integer(int64),
intent(in) :: n
799 integer(int64),
intent(in) :: pack_size
800 integer(int64),
dimension(3),
intent(out) :: gridsizes
801 integer(int64),
dimension(3),
intent(out) :: blocksizes
804 integer(int64) :: bsize, dim2, dim3
805 integer(int64),
dimension(3) :: nn
807 if(
present(kernel))
then
816 nn = (/pack_size, dim2, dim3/)
817 blocksizes = (/pack_size, bsize, 1_int64/)
828 integer,
intent(in) :: n
829 integer,
intent(in) :: pack_size
830 integer,
dimension(3),
intent(out) :: gridsizes
831 integer,
dimension(3),
intent(out) :: blocksizes
834 integer(int64) :: gridsizes64(3), blocksizes64(3)
837 gridsizes64, blocksizes64, kernel=kernel)
839 gridsizes = int(gridsizes64, int32)
840 blocksizes = int(blocksizes64, int32)
846 integer(int64),
intent(in) :: nn
848 integer(int64) :: modnn, bsize
857 modnn = mod(nn, bsize)
858 if (modnn /= 0) psize = psize + bsize - modnn
867 integer(int32),
intent(in) :: nn
877 integer,
intent(in) :: flags
878 type(
type_t),
intent(in) :: type
879 integer,
intent(in) :: size
880 logical,
optional,
intent(in) :: set_zero
881 logical,
optional,
intent(in) :: async
890 integer,
intent(in) :: flags
891 type(
type_t),
intent(in) :: type
892 integer(int64),
intent(in) :: size
893 logical,
optional,
intent(in) :: set_zero
894 logical,
optional,
intent(in) :: async
896 integer(int64) :: fsize
898 integer(int64) :: initialize_buffers
906 this%allocated = .
true.
912 if (.not. found)
then
922 buffer_alloc_count = buffer_alloc_count + 1
923 allocated_mem = allocated_mem + fsize
927 if (
present(set_zero))
then
928 initialize_buffers = merge(option__initializegpubuffers__yes, option__initializegpubuffers__no, set_zero)
930 initialize_buffers = accel%initialize_buffers
932 select case (initialize_buffers)
933 case (option__initializegpubuffers__yes)
935 case (option__initializegpubuffers__nan)
946 logical,
optional,
intent(in) :: async
949 integer(int64) :: fsize
953 if (this%size > 0)
then
969 buffer_alloc_count = buffer_alloc_count - 1
970 allocated_mem = allocated_mem + fsize
977 this%allocated = .false.
996 buffer_to%mem = buffer_from%mem
997 buffer_to%size = buffer_from%size
998 buffer_to%type = buffer_from%type
999 buffer_to%flags = buffer_from%flags
1000 buffer_to%allocated = buffer_from%allocated
1018 this%mem = c_null_ptr
1022 this%allocated = .false.
1032 integer,
intent(in) :: flags
1033 type(
type_t),
intent(in) :: type
1034 integer,
intent(in) :: required_size
1035 logical,
intent(in) :: set_zero
1036 logical,
optional,
intent(in) :: async
1057 allocated = this%allocated
1076 integer,
intent(in) :: narg
1098 integer(int64),
intent(in) :: gridsizes(:)
1099 integer(int64),
intent(in) :: blocksizes(:)
1100 integer(int64),
optional,
intent(in) :: shared_memory_size
1103 integer(int64) :: gsizes(1:3)
1104 integer(int64) :: bsizes(1:3)
1112 dim = ubound(gridsizes, dim=1)
1114 assert(dim == ubound(blocksizes, dim=1))
1117 if (any(gridsizes == 0))
return
1119 assert(all(blocksizes > 0))
1121 gsizes(1:dim) = gridsizes(1:dim)
1122 bsizes(1:dim) = blocksizes(1:dim)
1126 if (any(bsizes(1:3) > accel%max_block_dim(1:3)))
then
1127 message(1) =
"Maximum dimension of a block too large in kernel "//trim(kernel%kernel_name)
1128 message(2) =
"The following conditions should be fulfilled:"
1129 write(
message(3),
"(A, I8, A, I8)")
"Dim 1: ", bsizes(1),
" <= ", accel%max_block_dim(1)
1130 write(
message(4),
"(A, I8, A, I8)")
"Dim 2: ", bsizes(2),
" <= ", accel%max_block_dim(2)
1131 write(
message(5),
"(A, I8, A, I8)")
"Dim 3: ", bsizes(3),
" <= ", accel%max_block_dim(3)
1132 message(6) =
"This is an internal error, please contact the developers."
1139 message(1) =
"Maximum number of threads per block too large in kernel "//trim(kernel%kernel_name)
1140 message(2) =
"The following condition should be fulfilled:"
1142 message(4) =
"This is an internal error, please contact the developers."
1147 if (any(gsizes(1:3) > accel%max_grid_dim(1:3)))
then
1148 message(1) =
"Maximum dimension of grid too large in kernel "//trim(kernel%kernel_name)
1149 message(2) =
"The following conditions should be fulfilled:"
1150 write(
message(3),
"(A, I8, A, I10)")
"Dim 1: ", gsizes(1),
" <= ", accel%max_grid_dim(1)
1151 write(
message(4),
"(A, I8, A, I10)")
"Dim 2: ", gsizes(2),
" <= ", accel%max_grid_dim(2)
1152 write(
message(5),
"(A, I8, A, I10)")
"Dim 3: ", gsizes(3),
" <= ", accel%max_grid_dim(3)
1153 message(6) =
"This is an internal error, please contact the developers."
1157 if(
present(shared_memory_size))
then
1159 if (shared_memory_size > accel%shared_memory_size)
then
1160 message(1) =
"Shared memory too large in kernel "//trim(kernel%kernel_name)
1161 message(2) =
"The following condition should be fulfilled:"
1162 message(3) =
"Requested shared memory <= Available shared memory"
1163 write(
message(4),
'(a,f12.6,a)')
"Requested shared memory: ", real(shared_memory_size, real64) /1024.0,
" Kb"
1164 write(
message(5),
'(a,f12.6,a)')
"Available shared memory: ", real(accel%shared_memory_size, real64) /1024.0,
" Kb"
1165 message(6) =
"This is an internal error, please contact the developers."
1167 else if (shared_memory_size <= 0)
then
1168 message(1) =
"Invalid shared memory size in kernel "//trim(kernel%kernel_name)
1169 write(
message(2),
'(a,f12.6,a)')
"Shared memory size requested: ", real(shared_memory_size, real64) /1024.0,
" Kb"
1170 message(3) =
"This is an internal error, please contact the developers."
1191 integer,
intent(in) :: gridsizes(:)
1192 integer,
intent(in) :: blocksizes(:)
1193 integer(int64),
optional,
intent(in) :: shared_memory_size
1195 call accel_kernel_run_8(kernel, int(gridsizes, int64), int(blocksizes, int64), shared_memory_size)
1202 max_block_size = accel%max_block_size
1211 integer :: max_block_size
1217 call cuda_kernel_max_threads_per_block(kernel%cuda_kernel, max_block_size)
1218 if (debug%info .and. max_block_size /=
accel%max_block_size)
then
1219 write(message(1),
"(A, I5, A)")
"A kernel can use only less threads per block (", max_block_size,
")", &
1220 "than available on the device (",
accel%max_block_size,
")"
1221 call messages_info(1)
1229 block_size = min(block_size, max_block_size)
1237 subroutine accel_copy_buffer(dest, src, type, nval, offset_dest, offset_src, async)
1240 type(type_t),
intent(in) :: type
1241 integer(int64),
intent(in) :: nval
1242 integer(int64),
optional,
intent(in) :: offset_dest
1243 integer(int64),
optional,
intent(in) :: offset_src
1244 logical,
optional,
intent(in) :: async
1246 integer(int64) :: type_size, offset_dest_, offset_src_
1249 call profiling_in(
"ACCEL_COPY_BUFFER")
1252 call profiling_out(
"ACCEL_COPY_BUFFER")
1258 type_size = types_get_size(type)
1260 offset_dest_ = 0_int64
1261 if (
present(offset_dest)) offset_dest_ = offset_dest*type_size
1262 offset_src_ = 0_int64
1263 if (
present(offset_src)) offset_src_ = offset_src*type_size
1265 assert(offset_dest_ + nval*type_size <= int(dest%size, int64)*types_get_size(dest%type))
1266 assert(offset_src_ + nval*type_size <= int(src%size, int64)*types_get_size(src%type))
1268 call cuda_memcpy_dtod(dest%mem, src%mem, nval*type_size, offset_dest_, offset_src_)
1270 if (.not. optional_default(async, .false.))
call accel_finish()
1272 call profiling_out(
"ACCEL_COPY_BUFFER")
1280 type(type_t),
intent(in) :: type
1281 integer(int8),
intent(in) :: val
1282 integer(int64),
intent(in) :: nval
1283 integer(int64),
optional,
intent(in) :: offset
1284 logical,
optional,
intent(in) :: async
1286 integer(int64) :: nval_, offset_, type_size
1296 if (
present(offset))
then
1298 if(offset > buffer%size)
then
1304 type_size = types_get_size(type)
1306 nval_ = nval*type_size
1309 if (
present(offset)) offset_ = offset*type_size
1311 call cuda_mem_set_async(buffer%mem, val, nval_, offset_)
1312 if(.not. optional_default(async, .false.))
call accel_finish()
1321 type(type_t),
intent(in) :: type
1322 integer(int64),
intent(in) :: nval
1323 integer(int64),
optional,
intent(in) :: offset
1324 logical,
optional,
intent(in) :: async
1337 type(type_t),
intent(in) :: type
1338 integer(int32),
intent(in) :: nval
1339 integer(int32),
optional,
intent(in) :: offset
1340 logical,
optional,
intent(in) :: async
1344 if (
present(offset))
then
1357 integer,
parameter :: times = 10
1359 real(real64) :: time, stime
1360 real(real64) :: read_bw, write_bw
1362 real(real64),
allocatable :: data(:)
1364 call messages_new_line()
1365 call messages_write(
'Info: Benchmarking the bandwidth between main memory and device memory')
1366 call messages_new_line()
1367 call messages_info()
1369 call messages_write(
' Buffer size Read bw Write bw')
1370 call messages_new_line()
1371 call messages_write(
' [MiB] [MiB/s] [MiB/s]')
1372 call messages_info()
1376 safe_allocate(
data(1:size))
1379 stime = loct_clock()
1384 time = (loct_clock() - stime)/real(times, real64)
1386 write_bw = real(
size, real64) *8.0_real64/time
1388 stime = loct_clock()
1394 time = (loct_clock() - stime)/real(times, real64)
1395 read_bw = real(
size, real64) *8.0_real64/time
1397 call messages_write(size*8.0_real64/1024.0_real64**2)
1398 call messages_write(write_bw/1024.0_real64**2, fmt =
'(f10.1)')
1399 call messages_write(read_bw/1024.0_real64**2, fmt =
'(f10.1)')
1400 call messages_info()
1404 safe_deallocate_a(data)
1406 size = int(size*2.0)
1408 if (
size > 50000000)
exit
1420 call cuda_program_map_init(
accel%program_map)
1453 'batch_axpy_function<double, DimSpin::D1>')
1455 'batch_axpy_function<double, DimSpin::D2>')
1457 'batch_axpy_function<complex<double>, DimSpin::D1>')
1459 'batch_axpy_function<complex<double>, DimSpin::D2>')
1461 'batch_ax_function_py<double, DimSpin::D1>')
1463 'batch_ax_function_py<double, DimSpin::D2>')
1465 'batch_ax_function_py<complex<double>, DimSpin::D1>')
1467 'batch_ax_function_py<complex<double>, DimSpin::D2>')
1471 call accel_program_add(
'batch_mul.cu',
'mul_batch<complex<double>, Conjugation::No>')
1472 call accel_program_add(
'batch_mul.cu',
'mul_batch<complex<double>, Conjugation::Yes>')
1473 call accel_program_add(
'batch_mul.cu',
'mul_mf<complex<double>, double, Conjugation::No>')
1474 call accel_program_add(
'batch_mul.cu',
'mul_mf<complex<double>, double, Conjugation::Yes>')
1475 call accel_program_add(
'batch_mul.cu',
'mul_mf<complex<double>, complex<double>, Conjugation::No>')
1476 call accel_program_add(
'batch_mul.cu',
'mul_mf<complex<double>, complex<double>, Conjugation::Yes>')
1481 call accel_program_add(
'boundaries.cu',
'boundaries_periodic_recv_corr<double>')
1500 call accel_program_add(
'dftu_projector.cu',
'dftu_pos_mat_elem_cmplx_submesh<double>')
1502 call accel_program_add(
'dftu_projector.cu',
'dftu_pos_mat_elem_submesh<double>')
1505 call accel_program_add(
'dftu_projector.cu',
'dftu_projector_bra_cmplx_submesh<double>')
1506 call accel_program_add(
'dftu_projector.cu',
'dftu_projector_bra_submesh<double>')
1509 call accel_program_add(
'dftu_projector.cu',
'dftu_projector_ket_cmplx_submesh<double>')
1510 call accel_program_add(
'dftu_projector.cu',
'dftu_projector_ket_submesh<double>')
1513 'exchange_accumulate_batch<double, double, DimSpin::D1>')
1515 'exchange_accumulate_return_batch<double, double, DimSpin::D1>')
1517 'exchange_codensity_batch<double, DimSpin::D1>')
1519 'exchange_accumulate_batch<double, double, DimSpin::D2>')
1521 'exchange_accumulate_return_batch<double, double, DimSpin::D2>')
1523 'exchange_codensity_batch<double, DimSpin::D2>')
1525 'exchange_accumulate_batch<double, complex<double>, DimSpin::D1>')
1527 'exchange_accumulate_return_batch<double, complex<double>, DimSpin::D1>')
1529 'exchange_codensity_batch<complex<double>, DimSpin::D1>')
1531 'exchange_accumulate_batch<double, complex<double>, DimSpin::D2>')
1533 'exchange_accumulate_return_batch<double, complex<double>, DimSpin::D2>')
1535 'exchange_codensity_batch<complex<double>, DimSpin::D2>')
1538 call accel_program_add(
'forces.cu',
'(density_gradient<double, complex<double>>)')
1548 'dbatch_dotpv_reduce<double, DimSpin::D1>')
1550 'dbatch_dotpv_reduce<double, DimSpin::D2>')
1552 'batch_mf_dotp<double, DimSpin::D1>')
1554 'batch_mf_dotp<double, DimSpin::D2>')
1557 'zbatch_dotpv_reduce<double, DimSpin::D1>')
1559 'zbatch_dotpv_reduce<double, DimSpin::D2>')
1561 'batch_mf_dotp<complex<double>, DimSpin::D1>')
1563 'batch_mf_dotp<complex<double>, DimSpin::D2>')
1566 'mesh_interpolate<double, double, Dim::D1>')
1568 'mesh_interpolate<double, double, Dim::D2>')
1570 'mesh_interpolate<double, double, Dim::D3>')
1572 'mesh_interpolate<double, complex<double>, Dim::D1>')
1574 'mesh_interpolate<double, complex<double>, Dim::D2>')
1576 'mesh_interpolate<double, complex<double>, Dim::D3>')
1580 call accel_program_add(
'mesh_to_cube.cu',
'cube_to_mesh_batch<complex<double>>')
1581 call accel_program_add(
'mesh_to_cube.cu',
'mesh_to_cube_batch<complex<double>>')
1589 call accel_program_add(
'operate.cu',
'operate_map<double, Indexing::Direct, Symmetry::Antisymmetric>')
1590 call accel_program_add(
'operate.cu',
'operate_map<double, Indexing::Direct, Symmetry::Symmetric>')
1591 call accel_program_add(
'operate.cu',
'operate_map<double, Indexing::Indirect, Symmetry::Antisymmetric>')
1592 call accel_program_add(
'operate.cu',
'operate_map<double, Indexing::Indirect, Symmetry::Symmetric>')
1621 call accel_program_add(
'projector.cu',
'projector_bra_force_phase<double, double>')
1623 call accel_program_add(
'projector.cu',
'projector_bra_scatter_real<double, double>')
1626 call accel_program_add(
'projector.cu',
'projector_ket_phase_spiral<double, double>')
1629 call accel_program_add(
'projector.cu',
'projector_r_vnl_bra_phase<double, double>')
1631 call accel_program_add(
'projector.cu',
'projector_r_vnl_ket_phase<double, double>')
1633 call accel_program_add(
'projector.cu',
'projector_bra_phase_spiral_gather<double>')
1634 call accel_program_add(
'projector.cu',
'projector_bra_force<double, complex<double>>')
1635 call accel_program_add(
'projector.cu',
'projector_bra_force_phase<double, complex<double>>')
1637 call accel_program_add(
'projector.cu',
'projector_bra_scatter_complex<double, complex<double>>')
1638 call accel_program_add(
'projector.cu',
'projector_bra_scatter_real<double, complex<double>>')
1640 call accel_program_add(
'projector.cu',
'projector_ket_phase<double, complex<double>>')
1641 call accel_program_add(
'projector.cu',
'projector_ket_phase_spiral<double, complex<double>>')
1643 call accel_program_add(
'projector.cu',
'projector_r_vnl_bra<double, complex<double>>')
1644 call accel_program_add(
'projector.cu',
'projector_r_vnl_bra_phase<double, complex<double>>')
1645 call accel_program_add(
'projector.cu',
'projector_r_vnl_ket<double, complex<double>>')
1646 call accel_program_add(
'projector.cu',
'projector_r_vnl_ket_phase<double, complex<double>>')
1648 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_bra<double, double>')
1649 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_bra_phase<double, double>')
1650 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_ket<double, double>')
1651 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_ket_phase<double, double>')
1652 call accel_program_add(
'projector_commutator.cu',
'dprojector_mix_commutator<double>')
1653 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_bra<double, complex<double>>')
1654 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_bra_phase<double, complex<double>>')
1655 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_ket<double, complex<double>>')
1656 call accel_program_add(
'projector_commutator.cu',
'projector_commutator_ket_phase<double, complex<double>>')
1657 call accel_program_add(
'projector_commutator.cu',
'zprojector_mix_commutator<double>')
1663 '(symmetrizer_apply_single_batch<double, Conjugation::No>)')
1665 '(symmetrizer_apply_single_batch<double, Conjugation::Yes>)')
1667 '(symmetrizer_apply_single_batch<complex<double>, Conjugation::No>)')
1669 '(symmetrizer_apply_single_batch<complex<double>, Conjugation::Yes>)')
1672 'uvw_to_xyz<double, Dim::D1, double*, int, double*, int>')
1674 'uvw_to_xyz<double, Dim::D2, double*, int, double*, int, double*, int, double*, int>')
1676 'uvw_to_xyz<double, Dim::D3, double*, int, double*, int, double*, int, double*, int, double*, int, double*, int>')
1697 character(len=*),
intent(in) :: file_name
1698 character(len=*),
intent(in) :: name
1702 call cuda_program_register(
accel%program_map, string_f_to_c(trim(file_name)), &
1703 string_f_to_c(trim(name)))
1716 if (.not.
associated(
head))
exit
1717 next_head =>
head%next
1723 call cuda_program_map_end(
accel%program_map)
1738 character(len=*),
intent(in) :: file_name
1739 character(len=*),
intent(in) :: kernel_name
1740 character(len=*),
optional,
intent(in) :: flags
1743 character(len=1000) :: all_flags
1748 call profiling_in(
"ACCEL_COMPILE", exclude = .
true.)
1751 all_flags =
'-I'//trim(conf%share)//
'/kernels/'//
" "//trim(
accel%debug_flag)
1753 if (
present(flags))
then
1754 all_flags = trim(all_flags)//
' '//trim(flags)
1757 call cuda_program_build(
accel%program_map,
accel%device%cuda_device, &
1758 string_f_to_c(trim(file_name)), string_f_to_c(trim(all_flags)))
1760 call cuda_program_get_kernel(this%cuda_kernel,
accel%program_map, &
1761 string_f_to_c(trim(file_name)), string_f_to_c(trim(all_flags)), &
1762 string_f_to_c(trim(kernel_name)))
1763 call cuda_alloc_arg_array(this%arguments)
1766 this%initialized = .
true.
1767 this%kernel_name = trim(kernel_name)
1769 call profiling_out(
"ACCEL_COMPILE")
1782 call cuda_free_arg_array(this%arguments)
1783 call cuda_release_kernel(this%cuda_kernel)
1787 this%initialized = .false.
1796 character(len=*),
intent(in) :: file_name
1797 character(len=*),
intent(in) :: kernel_name
1798 character(len=*),
optional,
intent(in) :: flags
1802 if (.not. this%initialized)
then
1815 size =
accel%global_memory_size
1823 size =
accel%shared_memory_size
1829 integer,
intent(in) :: dim
1834 if (dim == 1)
size = 2**30
1841 integer,
intent(in) :: stream_number
1847 call cuda_set_stream(
accel%cuda_stream, stream_number)
1848 call cublas_set_stream(
accel%cublas_handle,
accel%cuda_stream)
1858 integer,
intent(inout) :: stream_number
1864 call cuda_get_stream(stream_number)
1878 call cuda_synchronize_all_streams()
1886 type(c_ptr),
intent(in) :: buffer
1887 integer(int64),
intent(in) :: offset
1888 type(c_ptr) :: buffer_offset
1892 call cuda_get_pointer_with_offset(buffer, offset, buffer_offset)
1895 buffer_offset = buffer
1901 type(c_ptr),
intent(in) :: buffer
1902 integer(int64),
intent(in) :: offset
1903 type(c_ptr) :: buffer_offset
1907 call cuda_get_pointer_with_offset(buffer, 2_int64*offset, buffer_offset)
1910 buffer_offset = buffer
1916 type(c_ptr),
intent(in) :: buffer
1920 call cuda_clean_pointer(buffer)
1929 integer(int64),
intent(in) :: size
1930 integer(int64),
intent(out) :: grid_size
1931 integer(int64),
intent(out) :: thread_block_size
1934#ifdef __HIP_PLATFORM_AMD__
1937 thread_block_size =
size
1940 thread_block_size =
accel%warp_size
1947#include "accel_inc.F90"
1950#include "complex.F90"
1951#include "accel_inc.F90"
1954#include "integer.F90"
1955#include "accel_inc.F90"
1958#include "integer8.F90"
1959#include "accel_inc.F90"
subroutine accel_grid_size_i4(n, blocksizes, gridsizes)
Computes the grid size for a given problem size and block size (32-bit version).
subroutine laccel_get_device_pointer_3l(host_pointer, device_pointer, dimensions)
subroutine zaccel_get_device_pointer_2l(host_pointer, device_pointer, dimensions)
subroutine, public accel_clean_pointer(buffer)
subroutine accel_kernel_global_end()
subroutine zaccel_write_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine, public accel_get_unfolded_size(size, grid_size, thread_block_size)
Get unfolded size: some kernels (e.g. projectors) unfold the array across warps as an optimization....
subroutine laccel_read_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine laccel_read_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine iaccel_write_buffer_2(this, n1, n2, data, offset, async)
pure logical function, public accel_allow_cpu_only()
subroutine daccel_get_device_pointer_1(host_pointer, device_pointer, dimensions)
subroutine zaccel_read_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine daccel_read_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine zaccel_get_device_pointer_1(host_pointer, device_pointer, dimensions)
subroutine laccel_read_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine zaccel_create_blas_alpha_beta_buffer(this, data, async)
subroutine daccel_write_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine laccel_write_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine daccel_write_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine laccel_get_device_pointer_1(host_pointer, device_pointer, dimensions)
subroutine zaccel_read_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine zaccel_read_buffer_0(this, n1, data, offset, async)
integer function, public accel_kernel_block_size(kernel)
subroutine zaccel_write_buffer_single(this, data, async)
subroutine daccel_read_buffer_2(this, n1, n2, data, offset, async)
subroutine iaccel_get_device_pointer_3l(host_pointer, device_pointer, dimensions)
subroutine zaccel_read_buffer_2(this, n1, n2, data, offset, async)
subroutine laccel_get_device_pointer_2(host_pointer, device_pointer, dimensions)
subroutine iaccel_write_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine zaccel_write_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine accel_grid_size_array_i8(n, blocksizes, gridsizes)
Computes the grid size for a given problem size and block size (64-bit version).
subroutine laccel_write_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine zaccel_read_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine iaccel_write_buffer_1(this, n1, data, offset, async)
subroutine zaccel_release_blas_alpha_beta_buffer(this, data, async)
subroutine laccel_write_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine, public accel_free_buffer(this, async)
subroutine daccel_write_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine iaccel_write_buffer_0_int32(this, n1, data, offset, async)
subroutine, public accel_kernel_start_call(this, file_name, kernel_name, flags)
subroutine iaccel_write_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine zaccel_write_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine iaccel_release_blas_alpha_beta_buffer(this, data, async)
subroutine iaccel_read_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine zaccel_write_buffer_2_int32(this, n1, n2, data, offset, async)
subroutine, public accel_get_stream(stream_number)
subroutine accel_create_buffer_4(this, flags, type, size, set_zero, async)
subroutine zaccel_read_buffer_1_int32(this, n1, data, offset, async)
subroutine iaccel_write_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
integer(int64) pure function, public accel_global_memory_size()
subroutine daccel_read_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine laccel_write_buffer_1(this, n1, data, offset, async)
subroutine daccel_read_buffer_1(this, n1, data, offset, async)
subroutine daccel_write_buffer_2(this, n1, n2, data, offset, async)
subroutine zaccel_set_kernel_arg_data(kernel, narg, data)
subroutine daccel_get_device_pointer_3l(host_pointer, device_pointer, dimensions)
subroutine iaccel_read_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine daccel_get_device_pointer_2l(host_pointer, device_pointer, dimensions)
integer(int64) function accel_padded_size_i8(nn)
subroutine accel_check_bandwidth()
subroutine iaccel_write_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine daccel_read_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine laccel_read_buffer_0(this, n1, data, offset, async)
subroutine daccel_write_buffer_0(this, n1, data, offset, async)
subroutine iaccel_create_blas_alpha_beta_buffer(this, data, async)
subroutine zaccel_read_buffer_0_int32(this, n1, data, offset, async)
subroutine iaccel_get_device_pointer_1l(host_pointer, device_pointer, dimensions)
subroutine, public accel_finish()
subroutine laccel_write_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine accel_kernel_global_init()
subroutine zaccel_read_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine daccel_read_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine accel_kernel_run_4(kernel, gridsizes, blocksizes, shared_memory_size)
Run a kernel with 4-byte integer sizes.
subroutine zaccel_write_buffer_1(this, n1, data, offset, async)
subroutine iaccel_get_device_pointer_1(host_pointer, device_pointer, dimensions)
subroutine laccel_read_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine, public accel_copy_buffer(dest, src, type, nval, offset_dest, offset_src, async)
Copy nval elements of the given type between two device buffers.
subroutine accel_grid_size_extend_dim_i4(n, pack_size, gridsizes, blocksizes, kernel)
Helper function to compute the grid for the kernels that relies on the batch size (pack_size) and the...
subroutine laccel_create_blas_alpha_beta_buffer(this, data, async)
subroutine, public accel_ensure_buffer_size(buffer, flags, type, required_size, set_zero, async)
subroutine accel_set_buffer_to(buffer, type, val, nval, offset, async)
subroutine, public accel_move_buffer(buffer_from, buffer_to)
Move the buffer memory from the first buffer to the second.
subroutine, public accel_detach_buffer(this)
Clear a buffer handle without freeing device memory.
subroutine laccel_set_kernel_arg_data(kernel, narg, data)
subroutine iaccel_write_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine daccel_write_buffer_1(this, n1, data, offset, async)
subroutine daccel_read_buffer_0_int32(this, n1, data, offset, async)
subroutine zaccel_read_buffer_1(this, n1, data, offset, async)
subroutine iaccel_write_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine daccel_read_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine laccel_write_buffer_single(this, data, async)
subroutine laccel_read_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine daccel_get_device_pointer_2(host_pointer, device_pointer, dimensions)
subroutine accel_kernel_run_8(kernel, gridsizes, blocksizes, shared_memory_size)
Run a kernel with 8-byte integer sizes.
subroutine iaccel_read_buffer_2_int32(this, n1, n2, data, offset, async)
subroutine zaccel_write_buffer_0_int32(this, n1, data, offset, async)
subroutine zaccel_write_buffer_1_int32(this, n1, data, offset, async)
subroutine accel_set_buffer_to_zero_i8(buffer, type, nval, offset, async)
subroutine zaccel_get_device_pointer_1l(host_pointer, device_pointer, dimensions)
logical pure function, public accel_buffer_is_allocated(this)
integer, parameter, public accel_mem_read_write
subroutine daccel_create_blas_alpha_beta_buffer(this, data, async)
subroutine accel_kernel_end(this)
subroutine laccel_write_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine zaccel_write_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine zaccel_get_device_pointer_2(host_pointer, device_pointer, dimensions)
subroutine daccel_write_buffer_3(this, n1, n2, n3, data, offset, async)
subroutine laccel_read_buffer_2_int32(this, n1, n2, data, offset, async)
type(c_ptr) function, public daccel_get_pointer_with_offset(buffer, offset)
subroutine iaccel_write_buffer_single(this, data, async)
subroutine iaccel_get_device_pointer_2(host_pointer, device_pointer, dimensions)
integer pure function, public accel_max_size_per_dim(dim)
subroutine zaccel_read_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine iaccel_read_buffer_0(this, n1, data, offset, async)
subroutine daccel_read_buffer_0(this, n1, data, offset, async)
subroutine iaccel_read_buffer_1_int32(this, n1, data, offset, async)
subroutine accel_grid_size_array_i4(n, blocksizes, gridsizes)
Computes the grid size for a given problem size and block size (32-bit version).
subroutine iaccel_read_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine laccel_write_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine laccel_write_buffer_0_int32(this, n1, data, offset, async)
subroutine zaccel_write_buffer_2(this, n1, n2, data, offset, async)
subroutine laccel_read_buffer_0_int32(this, n1, data, offset, async)
subroutine laccel_get_device_pointer_2l(host_pointer, device_pointer, dimensions)
subroutine iaccel_get_device_pointer_3(host_pointer, device_pointer, dimensions)
subroutine zaccel_write_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine zaccel_write_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine daccel_set_kernel_arg_data(kernel, narg, data)
subroutine iaccel_read_buffer_1(this, n1, data, offset, async)
subroutine accel_grid_size_extend_dim_i8(n, pack_size, gridsizes, blocksizes, kernel)
Helper function to compute the grid for the kernels that relies on the batch size (pack_size) and the...
subroutine, public accel_kernel_build(this, file_name, kernel_name, flags)
Compile the program that contains a given kernel.
subroutine, public accel_init(base_grp, namespace)
subroutine, public accel_end(namespace)
subroutine laccel_write_buffer_0(this, n1, data, offset, async)
subroutine daccel_write_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine zaccel_read_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine, public accel_synchronize_all_streams()
subroutine, public accel_set_stream(stream_number)
subroutine laccel_read_buffer_2(this, n1, n2, data, offset, async)
subroutine daccel_release_blas_alpha_beta_buffer(this, data, async)
subroutine iaccel_read_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine iaccel_read_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine laccel_get_device_pointer_1l(host_pointer, device_pointer, dimensions)
subroutine iaccel_read_buffer_0_int32(this, n1, data, offset, async)
subroutine accel_grid_size_i8(n, blocksizes, gridsizes)
Computes the grid size for a given problem size and block size (64-bit version).
subroutine iaccel_write_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
integer(int32) function accel_padded_size_i4(nn)
subroutine accel_set_buffer_to_zero_i4(buffer, type, nval, offset, async)
subroutine daccel_write_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine laccel_write_buffer_1_int32(this, n1, data, offset, async)
subroutine iaccel_get_device_pointer_2l(host_pointer, device_pointer, dimensions)
subroutine iaccel_write_buffer_2_int32(this, n1, n2, data, offset, async)
pure logical function, public accel_is_enabled()
subroutine zaccel_read_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine daccel_write_buffer_0_int32(this, n1, data, offset, async)
subroutine iaccel_write_buffer_4(this, n1, n2, n3, n4, data, offset, async)
subroutine daccel_write_buffer_2_int32(this, n1, n2, data, offset, async)
subroutine iaccel_write_buffer_1_int32(this, n1, data, offset, async)
integer, parameter, public accel_mem_write_only
subroutine zaccel_write_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine daccel_read_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine laccel_write_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine laccel_read_buffer_1_int32(this, n1, data, offset, async)
subroutine daccel_read_buffer_1_int32(this, n1, data, offset, async)
subroutine laccel_read_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine daccel_write_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine daccel_get_device_pointer_1l(host_pointer, device_pointer, dimensions)
subroutine laccel_release_blas_alpha_beta_buffer(this, data, async)
subroutine iaccel_read_buffer_2(this, n1, n2, data, offset, async)
subroutine laccel_write_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine laccel_write_buffer_2(this, n1, n2, data, offset, async)
subroutine daccel_write_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine laccel_write_buffer_2_int32(this, n1, n2, data, offset, async)
subroutine zaccel_get_device_pointer_3(host_pointer, device_pointer, dimensions)
type(c_ptr) function, public zaccel_get_pointer_with_offset(buffer, offset)
subroutine iaccel_read_buffer_6_int32(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine laccel_read_buffer_3_int32(this, n1, n2, n3, data, offset, async)
subroutine daccel_write_buffer_single(this, data, async)
subroutine daccel_write_buffer_1_int32(this, n1, data, offset, async)
subroutine zaccel_write_buffer_0(this, n1, data, offset, async)
type(accel_t), public accel
subroutine laccel_get_device_pointer_3(host_pointer, device_pointer, dimensions)
subroutine iaccel_read_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
integer(int64) pure function, public accel_shared_memory_size()
integer pure function, public accel_max_block_size()
subroutine iaccel_set_kernel_arg_data(kernel, narg, data)
subroutine daccel_read_buffer_2_int32(this, n1, n2, data, offset, async)
subroutine iaccel_read_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine iaccel_write_buffer_0(this, n1, data, offset, async)
subroutine zaccel_get_device_pointer_3l(host_pointer, device_pointer, dimensions)
subroutine accel_create_buffer_8(this, flags, type, size, set_zero, async)
subroutine laccel_read_buffer_1(this, n1, data, offset, async)
subroutine daccel_read_buffer_5_int32(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine daccel_read_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine accel_program_add(file_name, name)
Register a kernel for later retrieval.
subroutine accel_set_kernel_arg_buffer(kernel, narg, buffer)
subroutine accel_kernel_list()
The kernels each source provides.
subroutine laccel_read_buffer_5(this, n1, n2, n3, n4, n5, data, offset, async)
subroutine zaccel_read_buffer_2_int32(this, n1, n2, data, offset, async)
subroutine zaccel_write_buffer_6(this, n1, n2, n3, n4, n5, n6, data, offset, async)
subroutine daccel_get_device_pointer_3(host_pointer, device_pointer, dimensions)
type(accel_kernel_t), pointer head
subroutine zaccel_read_buffer_4_int32(this, n1, n2, n3, n4, data, offset, async)
subroutine, public alloc_cache_put(alloc_cache, size, loc, put)
subroutine, public alloc_cache_get(alloc_cache, size, found, loc)
integer(int64), parameter, public alloc_cache_any_size
real(real64), parameter, public m_zero
complex(real64), parameter, public m_z0
complex(real64), parameter, public m_z1
real(real64), parameter, public m_one
System information (time, memory, sysname)
subroutine string_c_to_f(c_string, f_string)
convert a C string to a Fortran string
subroutine, public loct_sysname(name)
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
character(len=512), private msg
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
type(type_t), parameter, public type_cmplx
integer pure function, public types_get_size(this)
type(type_t), parameter, public type_float
type(type_t), parameter, public type_none
This module defines the unit system, used for input and output.
type(unit_t), public unit_gigabytes
For larger amounts of data (natural code units are bytes)
type(unit_t), public unit_megabytes
For large amounts of data (natural code units are bytes)
type(unit_t), public unit_kilobytes
For small amounts of data (natural code units are bytes)