!
! Copyright (C) 2022, MaX CoE
! Distributed under the MIT License 
! (license terms are at http://opensource.org/licenses/MIT).
!
!--
!
! Utility functions to perform device memory unmapping of host memory
! using CUDA-Fortran, OpenACC or OpenMP Offload
!
!==================================================================
!==================================================================
! *DO NOT EDIT*: automatically generated from device_mapping_unmap.jf90
!==================================================================
!==================================================================
!
#include<devxlib_macros.h>
#include<devxlib_defs.h>
!
!=======================================
!
submodule (devxlib_mapping) devxlib_mapping_unmap

   implicit none

   contains
{%- for t in types %}
{%- for p in kinds[t] %}
{%- for d in range(1,dimensions+1) %}
!
      module subroutine {{p.name}}_devxlib_mapping_unmap_{{t[0]|lower}}{{d}}d(array, ierr)
         implicit none
         !
         {{t}}({{p.val}}), allocatable DEV_ATTR :: array({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %})
         integer, optional, intent(out) :: ierr
         integer :: ierr_
         !
         ierr_=0
         !
#if defined __DXL_CUDAF
         if (allocated(array)) deallocate( array, stat=ierr_)
#elif defined __DXL_OPENACC || defined __DXL_OPENMP_GPU
         !DEV_ACC exit data delete(array)
         !DEV_OMPGPU target exit data map(delete:array)
#endif
         if (present(ierr)) ierr=ierr_
         !
      end subroutine {{p.name}}_devxlib_mapping_unmap_{{t[0]|lower}}{{d}}d
!
{%- endfor %}
{%- endfor %}
{%- endfor %}

endsubmodule devxlib_mapping_unmap
