| 1 |
! { dg-do run { target { offload_device } } } |
| 2 |
|
| 3 |
! OpenMP permits using the interop functions on the device, |
| 4 |
! but it is not really supported. Hence, check that the stubs |
| 5 |
! are working. |
| 6 |
|
| 7 |
module m |
| 8 |
contains |
| 9 |
subroutine target_test |
| 10 |
use iso_c_binding, only: c_intptr_t, c_ptr, c_associated |
| 11 |
#ifndef USE_OMP_HEADER |
| 12 |
use omp_lib |
| 13 |
#endif |
| 14 |
implicit none (type, external) |
| 15 |
|
| 16 |
#ifdef USE_OMP_HEADER |
| 17 |
include "omp_lib.h" |
| 18 |
#endif |
| 19 |
|
| 20 |
integer(omp_interop_kind) :: interop = omp_interop_none |
| 21 |
integer(omp_interop_rc_kind) :: ret_code |
| 22 |
integer(omp_interop_fr_kind) :: fr |
| 23 |
integer(omp_interop_property_kind) :: ipr |
| 24 |
|
| 25 |
integer(c_intptr_t) :: ival |
| 26 |
type(c_ptr) :: ptr |
| 27 |
character(len=:), pointer :: str |
| 28 |
|
| 29 |
if (omp_is_initial_device()) & |
| 30 |
! Already checked in interop-routines-1.F90 |
| 31 |
! And some assumptions below are only fulfilled for nonhost |
| 32 |
& return |
| 33 |
|
| 34 |
if (omp_irc_no_value /= 1) stop 1 |
| 35 |
if (omp_irc_success /= 0) stop 2 |
| 36 |
if (omp_irc_empty /= -1) stop 3 |
| 37 |
if (omp_irc_out_of_range /= -2) stop 4 |
| 38 |
if (omp_irc_type_int /= -3) stop 5 |
| 39 |
if (omp_irc_type_ptr /= -4) stop 6 |
| 40 |
if (omp_irc_type_str /= -5) stop 7 |
| 41 |
if (omp_irc_other /= -6) stop 8 |
| 42 |
|
| 43 |
! Check values, including invalid values. |
| 44 |
do ret_code = omp_irc_other - 1, omp_irc_no_value + 1 |
| 45 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 46 |
if (ret_code < omp_irc_other & |
| 47 |
& .or. ret_code > omp_irc_no_value) then |
| 48 |
! Assume disassociated for an invalid value. |
| 49 |
if (associated (str)) stop 9 |
| 50 |
else if (ret_code == omp_irc_other) then |
| 51 |
! Likely not to exist in an implementation; esp. not for |
| 52 |
! omp_interop_none. Thus, assume disassociated. |
| 53 |
! In GCC, omp_irc_other is used on the device side, only, to |
| 54 |
! complain about omp_get_interop_{int,ptr,str} usage. |
| 55 |
! See below for a check for the device side. |
| 56 |
if (len_trim (str) <= 5) stop 11 |
| 57 |
else |
| 58 |
! Assume that omp_get_interop_rc_desc handles all of those and |
| 59 |
! not only omp_irc_empty (and possibly omp_irc_out_of_range), |
| 60 |
! which do occur for omp_interop_none. |
| 61 |
! Assume some sensible message, i.e. at least 5 characters. |
| 62 |
if (len_trim (str) <= 5) stop 11 |
| 63 |
end if |
| 64 |
end do |
| 65 |
|
| 66 |
if (omp_ifr_last < omp_ifr_hsa) stop 12 |
| 67 |
|
| 68 |
do fr = omp_ifr_cuda, omp_ifr_last |
| 69 |
select case (fr) |
| 70 |
! Expect the id values from the additional-definition document. |
| 71 |
case (omp_ifr_cuda) |
| 72 |
if (fr /= 1) stop 13 |
| 73 |
case (omp_ifr_cuda_driver) |
| 74 |
if (fr /= 2) stop 14 |
| 75 |
case (omp_ifr_opencl) |
| 76 |
if (fr /= 3) stop 15 |
| 77 |
case (omp_ifr_sycl) |
| 78 |
if (fr /= 4) stop 16 |
| 79 |
case (omp_ifr_hip) |
| 80 |
if (fr /= 5) stop 17 |
| 81 |
case (omp_ifr_level_zero) |
| 82 |
if (fr /= 6) stop 18 |
| 83 |
case (omp_ifr_hsa) |
| 84 |
if (fr /= 7) stop 19 |
| 85 |
case default |
| 86 |
! Valid, but unexpected to have more interop types. |
| 87 |
stop 20 |
| 88 |
end select |
| 89 |
end do |
| 90 |
|
| 91 |
if (omp_ipr_first > omp_ipr_targetsync & |
| 92 |
& .or. (omp_ipr_fr_id & |
| 93 |
& >= omp_get_num_interop_properties (interop))) & |
| 94 |
& stop 21 |
| 95 |
|
| 96 |
do ipr = omp_ipr_first, & |
| 97 |
& omp_get_num_interop_properties (interop) - 1 |
| 98 |
! As interop == omp_interop_none, NULL is permissible; |
| 99 |
! nonetheless, require != NULL for the GCC implementation. |
| 100 |
str => omp_get_interop_name (interop, ipr) |
| 101 |
select case (ipr) |
| 102 |
case (omp_ipr_fr_id) |
| 103 |
if (ipr /= -1 .or. str /= "fr_id") & |
| 104 |
& stop 21 |
| 105 |
case (omp_ipr_fr_name) |
| 106 |
if (ipr /= -2 .or. str /= "fr_name") & |
| 107 |
& stop 22 |
| 108 |
case (omp_ipr_vendor) |
| 109 |
if (ipr /= -3 .or. str /= "vendor") & |
| 110 |
& stop 23 |
| 111 |
case (omp_ipr_vendor_name) |
| 112 |
if (ipr /= -4 .or. str /= "vendor_name") & |
| 113 |
& stop 24 |
| 114 |
case (omp_ipr_device_num) |
| 115 |
if (ipr /= -5 .or. str /= "device_num") & |
| 116 |
& stop 25 |
| 117 |
case (omp_ipr_platform) |
| 118 |
if (ipr /= -6 .or. str /= "platform") & |
| 119 |
& stop 26 |
| 120 |
case (omp_ipr_device) |
| 121 |
if (ipr /= -7 .or. str /= "device") & |
| 122 |
& stop 27 |
| 123 |
case (omp_ipr_device_context) |
| 124 |
if (ipr /= -8 .or. str /= "device_context") & |
| 125 |
& stop 28 |
| 126 |
case (omp_ipr_targetsync) |
| 127 |
if (ipr /= -9 .or. str /= "targetsync") & |
| 128 |
& stop 29 |
| 129 |
case default |
| 130 |
! Valid, but unexpected to have more interop types, |
| 131 |
! especially not for interop == omp_interop_none. |
| 132 |
stop 30 |
| 133 |
end select |
| 134 |
|
| 135 |
! As interop == omp_interop_none, expect NULL. |
| 136 |
if (associated (omp_get_interop_type_desc (interop, ipr))) & |
| 137 |
& stop 31 |
| 138 |
|
| 139 |
ret_code = omp_irc_success |
| 140 |
ival = omp_get_interop_int (interop, ipr, ret_code) |
| 141 |
if (ret_code /= omp_irc_empty) stop 32 |
| 142 |
if (ival /= 0) stop 33 ! Implementation choice |
| 143 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 144 |
if (len_trim (str) <= 5) stop 34 |
| 145 |
if (str /= "provided interoperability object is equal to " & |
| 146 |
& // "omp_interop_none") & |
| 147 |
& stop 35 ! GCC implementation choice. |
| 148 |
|
| 149 |
ret_code = omp_irc_success |
| 150 |
ptr = omp_get_interop_ptr (interop, ipr, ret_code) |
| 151 |
if (ret_code /= omp_irc_empty) stop 36 |
| 152 |
if (c_associated (ptr)) stop 37 ! Obvious implementation choice. |
| 153 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 154 |
if (len_trim (str) <= 5) stop 38 |
| 155 |
if (str /= "provided interoperability object is equal to " & |
| 156 |
& // "omp_interop_none") & |
| 157 |
& stop 39 ! GCC implementation choice. |
| 158 |
|
| 159 |
ret_code = omp_irc_success |
| 160 |
str => omp_get_interop_str (interop, ipr, ret_code) |
| 161 |
if (ret_code /= omp_irc_empty) stop 40 |
| 162 |
if (associated (str)) stop 41 ! Obvious mplementation choice |
| 163 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 164 |
if (len_trim (str) <= 5) stop 42 |
| 165 |
if (str /= "provided interoperability object is equal to " & |
| 166 |
& // "omp_interop_none") & |
| 167 |
& stop 43 ! GCC implementation choice. |
| 168 |
|
| 169 |
! Special case of GCC: For any non-'omp_interop_none' valued interop, |
| 170 |
! a device-side call to omp_get_interop_{int,ptr,src} will yield |
| 171 |
! omp_irc_other - with the error message as checked below. |
| 172 |
|
| 173 |
block |
| 174 |
integer(omp_interop_kind) :: interop_not_none_invalid & |
| 175 |
& = int(z'DEADBEEF', omp_interop_kind) |
| 176 |
|
| 177 |
ret_code = omp_irc_success |
| 178 |
ival = omp_get_interop_int (interop_not_none_invalid, ipr, ret_code) |
| 179 |
if (ret_code /= omp_irc_other) stop 101 |
| 180 |
if (ival /= 0) stop 102 ! Implementation choice |
| 181 |
str => omp_get_interop_rc_desc (interop_not_none_invalid, ret_code) |
| 182 |
if (len_trim (str) <= 5) stop 103 |
| 183 |
if (str /= "obtaining properties is only supported on the " & |
| 184 |
& // "initial device") & |
| 185 |
& stop 104 ! GCC implementation choice. |
| 186 |
|
| 187 |
ret_code = omp_irc_success |
| 188 |
ptr = omp_get_interop_ptr (interop_not_none_invalid, ipr, ret_code) |
| 189 |
if (ret_code /= omp_irc_other) stop 105 |
| 190 |
if (c_associated (ptr)) stop 106 ! Obvious implementation choice. |
| 191 |
str => omp_get_interop_rc_desc (interop_not_none_invalid, ret_code) |
| 192 |
if (len_trim (str) <= 5) stop 107 |
| 193 |
if (str /= "obtaining properties is only supported on the " & |
| 194 |
& // "initial device") & |
| 195 |
& stop 108 ! GCC implementation choice. |
| 196 |
|
| 197 |
ret_code = omp_irc_success |
| 198 |
str => omp_get_interop_str (interop_not_none_invalid, ipr, ret_code) |
| 199 |
if (ret_code /= omp_irc_other) stop 109 |
| 200 |
if (associated (str)) stop 110 ! Obvious mplementation choice |
| 201 |
str => omp_get_interop_rc_desc (interop_not_none_invalid, ret_code) |
| 202 |
if (len_trim (str) <= 5) stop 111 |
| 203 |
if (str /= "obtaining properties is only supported on the " & |
| 204 |
& // "initial device") & |
| 205 |
& stop 112 ! GCC implementation choice. |
| 206 |
end block |
| 207 |
end do |
| 208 |
|
| 209 |
! Invalid ipr. |
| 210 |
! Valid are either omp_irc_empty (due to omp_interop_none) or |
| 211 |
! omp_irc_out_of_range; assume omp_irc_out_of_range with GCC. |
| 212 |
|
| 213 |
! omp_ipr_targetsync-1, i.e < lower bound. |
| 214 |
|
| 215 |
ret_code = omp_irc_success |
| 216 |
ival = omp_get_interop_int (interop, omp_ipr_targetsync-1, & |
| 217 |
& ret_code) |
| 218 |
if (ret_code /= omp_irc_out_of_range) stop 44 |
| 219 |
if (ival /= 0) stop 45 ! Implementation choice. |
| 220 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 221 |
if (len_trim (str) <= 5) stop 46 |
| 222 |
! GCC implementation choice. |
| 223 |
if (str /= "property ID is out of range") stop 47 |
| 224 |
|
| 225 |
ret_code = omp_irc_success |
| 226 |
ptr = omp_get_interop_ptr (interop, omp_ipr_targetsync-1, & |
| 227 |
& ret_code) |
| 228 |
if (ret_code /= omp_irc_out_of_range) stop 48 |
| 229 |
if (c_associated (ptr)) stop 49 ! Obvious implementation choice. |
| 230 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 231 |
if (len_trim (str) <= 5) stop 50 |
| 232 |
! GCC implementation choice. |
| 233 |
if (str /= "property ID is out of range") stop 51 |
| 234 |
|
| 235 |
ret_code = omp_irc_success |
| 236 |
str => omp_get_interop_str (interop, omp_ipr_targetsync-1, & |
| 237 |
& ret_code) |
| 238 |
if (ret_code /= omp_irc_out_of_range) stop 52 |
| 239 |
if (associated (str)) stop 53 ! Obvious implementation choice. |
| 240 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 241 |
if (len_trim (str) <= 5) stop 54 |
| 242 |
! GCC implementation choice. |
| 243 |
if (str /= "property ID is out of range") stop 55 |
| 244 |
|
| 245 |
! omp_get_num_interop_properties (), i.e > upper bound. |
| 246 |
|
| 247 |
ret_code = omp_irc_success |
| 248 |
ival = omp_get_interop_int (interop, & |
| 249 |
& omp_get_num_interop_properties (interop), & |
| 250 |
& ret_code) |
| 251 |
if (ret_code /= omp_irc_out_of_range) stop 56 |
| 252 |
if (ival /= 0) stop 57 ! Implementation choice. |
| 253 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 254 |
if (len_trim (str) <= 5) stop 58 |
| 255 |
! GCC implementation choice. |
| 256 |
if (str /= "property ID is out of range") stop 59 |
| 257 |
|
| 258 |
ret_code = omp_irc_success |
| 259 |
ptr = omp_get_interop_ptr (interop, & |
| 260 |
& omp_get_num_interop_properties (interop), ret_code) |
| 261 |
if (ret_code /= omp_irc_out_of_range) stop 60 |
| 262 |
if (c_associated (ptr)) stop 61 ! Obvious implementation choice. |
| 263 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 264 |
if (len_trim (str) <= 5) stop 62 |
| 265 |
! GCC implementation choice. |
| 266 |
if (str /= "property ID is out of range") stop 63 |
| 267 |
|
| 268 |
ret_code = omp_irc_success |
| 269 |
str => omp_get_interop_str (interop, & |
| 270 |
& omp_get_num_interop_properties (interop), ret_code) |
| 271 |
if (ret_code /= omp_irc_out_of_range) stop 64 |
| 272 |
if (associated (str)) stop 65 ! Obvious implementation choice. |
| 273 |
str => omp_get_interop_rc_desc (interop, ret_code) |
| 274 |
if (len_trim (str) <= 5) stop 66 |
| 275 |
! GCC implementation choice. |
| 276 |
if (str /= "property ID is out of range") stop 67 |
| 277 |
end |
| 278 |
end module |
| 279 |
|
| 280 |
program main |
| 281 |
use omp_lib, only: omp_get_num_devices |
| 282 |
use m |
| 283 |
implicit none (type, external) |
| 284 |
integer :: dev |
| 285 |
do dev = 0, omp_get_num_devices () - 1 |
| 286 |
!$omp target device(device_num : dev) |
| 287 |
call target_test |
| 288 |
!$omp end target |
| 289 |
end do |
| 290 |
end |