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
|
!
! Copyright (C) 2022, MaX CoE
! Distributed under the MIT License
! (license terms are at http://opensource.org/licenses/MIT).
!
!--
!
! Utility functions to perform memory deallocation on the device
! using CUDA-Fortran, OpenACC or OpenMP Offload
!
!==================================================================
!==================================================================
! *DO NOT EDIT*: automatically generated from devxlib_malloc_free.jf90
!==================================================================
!==================================================================
!
#include<devxlib_macros.h>
#include<devxlib_defs.h>
!
!=======================================
!
submodule (devxlib_malloc) devxlib_malloc_free
implicit none
contains
{%- for t in types %}
{%- for p in kinds[t] %}
{%- for d in range(1,dimensions+1) %}
!
module subroutine {{p.name}}_devxlib_malloc_free_{{t[0]|lower}}{{d}}d(dev_ptr, device_id)
implicit none
!
{{t}}({{p.val}}), pointer, contiguous, intent(inout) DEV_ATTR :: dev_ptr({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %})
integer, optional, intent(in) :: device_id
#if defined __DXL_CUDAF
integer :: istat
integer(kind=c_int) :: info
#endif
#if defined __DXL_OPENMP_GPU
integer :: device_id_local
#endif
!
#if defined __DXL_CUDAF
if (present(device_id)) istat = cudaSetDevice(device_id)
#elif defined __DXL_OPENMP_GPU
if (present(device_id)) then
device_id_local= device_id
else
device_id_local = omp_get_default_device()
endif
#endif
!
#if defined __DXL_CUDAF || defined __DXL_OPENACC || defined __DXL_OPENMP_GPU
if (associated(dev_ptr)) then
#if defined __DXL_CUDAF
info = cudaFree_f(c_loc(dev_ptr))
#elif defined __DXL_OPENACC
call acc_free_f(c_loc(dev_ptr))
#elif defined __DXL_OPENMP_GPU
call omp_target_free(c_loc(dev_ptr), device_id_local)
#endif
nullify(dev_ptr)
endif
#else
if (associated(dev_ptr)) deallocate( dev_ptr)
#endif
!
end subroutine {{p.name}}_devxlib_malloc_free_{{t[0]|lower}}{{d}}d
!
{%- endfor %}
{%- endfor %}
{%- endfor %}
endsubmodule devxlib_malloc_free
|