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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
!
! Copyright (C) 2021, MaX CoE
! Distributed under the MIT License
! (license terms are at http://opensource.org/licenses/MIT).
!
!--
!
! Testing: devxlib_memcpy, devxlib_alloc, dev_auxfunc
!
!==================================================================
!==================================================================
! *DO NOT EDIT*: automatically generated from test_malloc.jf90
!==================================================================
!==================================================================
!
#include<devxlib_macros.h>
#include<devxlib_defs.h>
!
program test_malloc
!
! This program tests the routines and interfaces related to
! device_memcpy and some device_auxfunc.
!
use iso_fortran_env, only : int32, int64, real32, real64
use devxlib_memcpy
use devxlib_malloc
use devxlib_auxfunc
!
implicit none
!
integer(int64) :: cnt, count_max
real(real64), parameter :: thr=1.0d-6
integer, parameter :: nranks={{dimensions}}
integer(int64) :: ndim(nranks)
integer(int64) :: bounds(2*nranks)
real(real64):: t0, t1, count_rate
logical :: is_alloc, lfail_malloc
integer :: npass, nfail
integer(int32) :: ierr
integer :: nfail_malloc
{%- for t in types %}
{%- for p in kinds[t] %}
{%- for d in range(1,dimensions+1) %}
{{t}}({{p.val}}), allocatable :: A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %})
{{t}}({{p.val}}), allocatable :: A_hst2__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %})
{{t}}({{p.val}}), allocatable :: A_hst3__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %})
{{t}}({{p.val}}), pointer, contiguous DEV_ATTR :: A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %}) => null()
{{t}}({{p.val}}), pointer, contiguous DEV_ATTR :: A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %}) => null()
{% if t=="complex" or t=="integer" or t=="logical" %}
real({{p.val}}), allocatable :: A_rtmp__{{p.name}}_{{d}}d({% for dd in range(d) %}:{% if not loop.last %}, {%- endif %}{% endfor %})
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
integer :: i
character(256) :: arg, str
!
!============================
! get dims
!============================
!
! defaults
ndim(:)=100
do i=1,2*nranks,2
bounds(i) = 1
bounds(i+1) = ndim((i+1)/2)
enddo
i=0
do
call get_command_argument(i, arg)
if (len_trim(arg) == 0) exit
!
select case (trim(arg))
case("-h","--help")
write(6,"(a)") "Usage: "
write(6,"(a)") " ./test_malloc.x [--dims <vals>] [--bounds <vals>]"
stop
end select
!
i = i+1
call get_command_argument(i, str)
if (len_trim(str) == 0) exit
!
select case (trim(arg))
case("-dims","--dims")
read(str,*,iostat=ierr) ndim(:)
if (ierr/=0) STOP "reading cmd-line args: dims"
case("-bounds","--bounds")
read(str,*,iostat=ierr) bounds(:)
if (ierr/=0) STOP "reading cmd-line args: bounds"
end select
enddo
!
write(6,"(/,a,/)") "Running test with params: "
write(6,"(3x,a,10i5)") " ndim: ", ndim(:)
write(6,"(3x,a,10i5)") "bounds: ", bounds(:)
write(6,"()")
!
npass=0
nfail=0
nfail_malloc=0
!
!============================
! check memcpy
!============================
!
{%- for t in types %}
{%- for p in kinds[t] %}
{%- for d in range(1,dimensions+1) %}
!
!=====================
write(6,"(/,3x,a)") "checking {{p.name}}_{{t[0]|lower}}{{d}}d ..."
call system_clock(cnt, count_rate, count_max)
t0=cnt/count_rate
lfail_malloc=.false.
!
is_alloc = devxlib_allocated_p( A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d ) .or. &
devxlib_allocated_p( A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d )
if (is_alloc) then
nfail_malloc=nfail_malloc+1
lfail_malloc=.true.
write(6,"(3x,a)") "mem allocation check-pre FAILED"
endif
!
! allocations
allocate( A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(1,2*d,2)%}bounds({{dd}}):bounds({{dd+1}}){% if not loop.last %},{%- endif %}{%endfor%}) )
allocate( A_hst2__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(1,2*d,2)%}bounds({{dd}}):bounds({{dd+1}}){% if not loop.last %},{%- endif %}{%endfor%}) )
allocate( A_hst3__{{p.name}}_{{t[0]|lower}}{{d}}d({% for dd in range(1,2*d,2)%}bounds({{dd}}):bounds({{dd+1}}){% if not loop.last %},{%- endif %}{%endfor%}) )
{%- if d == 1 %}
call devxlib_alloc(A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d, ndim({{d}}), ierr)
call devxlib_alloc(A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d, ndim({{d}}), ierr)
{%- else %}
call devxlib_alloc(A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d, ndim(1:{{d}}), ierr)
call devxlib_alloc(A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d, ndim(1:{{d}}), ierr)
{%- endif %}
{%- if t=="complex" or t=="integer" or t=="logical" %}
allocate( A_rtmp__{{p.name}}_{{d}}d({% for dd in range(1,2*d,2)%}bounds({{dd}}):bounds({{dd+1}}){% if not loop.last %},{%- endif %}{%endfor%}) )
{%endif%}
!
is_alloc = devxlib_allocated_p( A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d )
if (.not.is_alloc) then
nfail_malloc=nfail_malloc+1
lfail_malloc=.true.
write(6,"(3x,a)") "mem allocation check-post FAILED"
endif
!
! init
{%- if t=="complex" %}
call random_number( A_rtmp__{{p.name}}_{{d}}d )
A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d=A_rtmp__{{p.name}}_{{d}}d
call random_number( A_rtmp__{{p.name}}_{{d}}d )
A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d=A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d+cmplx(0.0,1.0)*A_rtmp__{{p.name}}_{{d}}d
{% elif t=="integer" %}
call random_number( A_rtmp__{{p.name}}_{{d}}d )
A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d=int( 1000*A_rtmp__{{p.name}}_{{d}}d )
{% elif t=="logical" %}
call random_number( A_rtmp__{{p.name}}_{{d}}d )
A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d=( nint( A_rtmp__{{p.name}}_{{d}}d ) == 1 )
{%else%}
call random_number( A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d )
{%endif%}
!
! mem copy h2d
call devxlib_memcpy_h2d_p(A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d, A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d)
!
! mem copy
call devxlib_memcpy_d2d_p(A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d, A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d )
!
{%- if t=="complex" %}
! make cmplx conjg
call devxlib_conjg_d_p( A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d )
{%endif%}
!
! mem copy d2h
call devxlib_memcpy_d2h_p(A_hst2__{{p.name}}_{{t[0]|lower}}{{d}}d, A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d)
!
{%- if t=="complex" %}
! retrieve conjg data
A_hst2__{{p.name}}_{{t[0]|lower}}{{d}}d = conjg( A_hst2__{{p.name}}_{{t[0]|lower}}{{d}}d )
{%endif%}
!
! mem copy h2h
call devxlib_memcpy_h2h(A_hst3__{{p.name}}_{{t[0]|lower}}{{d}}d, A_hst2__{{p.name}}_{{t[0]|lower}}{{d}}d)
!
! check
if (lfail_malloc) write(6,"(3x,a)") "Malloc FAILED"
!
{%- if t=="logical" %}
if ( any( A_hst3__{{p.name}}_{{t[0]|lower}}{{d}}d .neqv. A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d ) ) then
{%- else %}
if ( any(abs(A_hst3__{{p.name}}_{{t[0]|lower}}{{d}}d -A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d )> thr) ) then
{%- endif %}
!
write(6,"(3x,a)") "FAILED"
nfail=nfail+1
else
write(6,"(3x,a)") "passed"
npass=npass+1
endif
!
deallocate(A_hst1__{{p.name}}_{{t[0]|lower}}{{d}}d)
deallocate(A_hst2__{{p.name}}_{{t[0]|lower}}{{d}}d)
deallocate(A_hst3__{{p.name}}_{{t[0]|lower}}{{d}}d)
!
call devxlib_free(A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d, ierr)
call devxlib_free(A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d, ierr)
!
is_alloc = devxlib_allocated_p( A_dev1__{{p.name}}_{{t[0]|lower}}{{d}}d ) .or. &
devxlib_allocated_p( A_dev2__{{p.name}}_{{t[0]|lower}}{{d}}d )
if (is_alloc) then
nfail_malloc=nfail_malloc+1
lfail_malloc=.true.
write(6,"(3x,a)") "mem allocation check-post2 FAILED"
endif
!
call system_clock(cnt, count_rate, count_max)
t1=cnt/count_rate
write(6,"(3x,a,f12.6,' sec')") "Timing: ", t1-t0
!
{% endfor %}
{% endfor %}
{% endfor %}
!
! summary
!
write(6,"(/,a)") "# Test SUMMARY:"
write(6,"(3x,a,i5)") "# passed: ", npass
write(6,"(3x,a,i5)") "# failed: ", nfail
write(6,"(3x,a,i5)") "# failed malloc: ", nfail_malloc
write(6,"()")
end program test_malloc
|