Ensures that given devmem has at least the requested size.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(acc_devmem_type), | intent(inout) | :: | this |
device memory |
||
type(acc_stream_type), | intent(in) | :: | stream |
on which zeroing and memcopying is performed |
||
integer, | intent(in) | :: | requested_size_in_bytes |
requested size in bytes |
||
logical, | intent(in), | optional | :: | nocopy |
if after growin old content should NOT be copied over. Default: false. if after growing the new memory should be zeroed. Default: false. |
|
logical, | intent(in), | optional | :: | zero_pad |
if after growin old content should NOT be copied over. Default: false. if after growing the new memory should be zeroed. Default: false. |
SUBROUTINE acc_devmem_ensure_size_bytes(this, stream, requested_size_in_bytes, nocopy, zero_pad)
!! Ensures that given devmem has at least the requested size.
TYPE(acc_devmem_type), &
INTENT(INOUT) :: this
!! device memory
TYPE(acc_stream_type), INTENT(IN) :: stream
!! on which zeroing and memcopying is performed
INTEGER, INTENT(IN) :: requested_size_in_bytes
!! requested size in bytes
LOGICAL, INTENT(IN), OPTIONAL :: nocopy, zero_pad
!! if after growin old content should NOT be copied over. Default: false.
!! if after growing the new memory should be zeroed. Default: false.
#if ! defined (__DBCSR_ACC)
MARK_USED(this)
MARK_USED(stream)
MARK_USED(requested_size_in_bytes)
MARK_USED(nocopy)
MARK_USED(zero_pad)
DBCSR_ABORT("__DBCSR_ACC not compiled in.")
#else
LOGICAL :: my_nocopy, my_zero_pad
TYPE(C_PTR) :: old_cptr, new_cptr, stream_cptr
INTEGER :: new_size, old_size, istat
IF (this%size_in_bytes < 0) &
DBCSR_ABORT("acc_devmem_ensure_size_bytes: not allocated")
IF (.NOT. acc_stream_associated(stream)) &
DBCSR_ABORT("acc_devmem_ensure_size_bytes: stream not associated")
IF (this%size_in_bytes < requested_size_in_bytes) THEN
!WRITE (*,*) "acc_devmem_ensure_size_bytes: growing dev_mem to: ", data_size
new_size = requested_size_in_bytes
old_size = this%size_in_bytes
old_cptr = this%cptr
new_cptr = C_NULL_PTR
istat = acc_interface_dev_mem_alloc(new_cptr, INT(new_size, KIND=C_SIZE_T))
IF (istat /= 0) &
DBCSR_ABORT("acc_devmem_ensure_size_bytes: alloc failed")
this%cptr = new_cptr
this%size_in_bytes = requested_size_in_bytes
my_zero_pad = .FALSE.
IF (PRESENT(zero_pad)) my_zero_pad = zero_pad
IF (my_zero_pad) &
CALL acc_devmem_setzero_bytes(this, first_byte=old_size + 1, stream=stream)
my_nocopy = .FALSE.
IF (PRESENT(nocopy)) my_nocopy = nocopy
IF (.NOT. my_nocopy) THEN
stream_cptr = acc_stream_cptr(stream)
istat = acc_interface_memcpy_d2d(old_cptr, new_cptr, INT(old_size, KIND=C_SIZE_T), stream_cptr)
IF (istat /= 0) &
DBCSR_ABORT("acc_devmem_ensure_size_bytes: memcpy failed")
END IF
CALL acc_stream_synchronize(stream)
istat = acc_interface_dev_mem_dealloc(old_cptr)
IF (istat /= 0) &
DBCSR_ABORT("acc_devmem_ensure_size_bytes: dealloc failed")
END IF
#endif
END SUBROUTINE acc_devmem_ensure_size_bytes