|
| 1 | +! RUN: %flang %flags %openmp_flags -fopenmp-version=60 %s -o %t |
| 2 | +! RUN: %t | FileCheck %s |
| 3 | + |
| 4 | +program test_omp_device_uid_main |
| 5 | + use omp_lib |
| 6 | + use, intrinsic :: iso_c_binding |
| 7 | + implicit none |
| 8 | + |
| 9 | + integer(kind=omp_integer_kind) :: num_devices, i, num_failed |
| 10 | + logical :: success |
| 11 | + |
| 12 | + num_devices = omp_get_num_devices() |
| 13 | + num_failed = 0 |
| 14 | + |
| 15 | + ! Test all devices plus the initial device (num_devices) |
| 16 | + do i = 0, num_devices |
| 17 | + success = test_omp_device_uid(i) |
| 18 | + if (.not. success) then |
| 19 | + print '("FAIL for device ", I0)', i |
| 20 | + num_failed = num_failed + 1 |
| 21 | + end if |
| 22 | + end do |
| 23 | + |
| 24 | + if (num_failed /= 0) then |
| 25 | + print *, "FAIL" |
| 26 | + stop 1 |
| 27 | + end if |
| 28 | + |
| 29 | + print *, "PASS" |
| 30 | + stop 0 |
| 31 | + |
| 32 | +contains |
| 33 | + |
| 34 | + logical function test_omp_device_uid(device_num) |
| 35 | + use omp_lib |
| 36 | + use, intrinsic :: iso_c_binding |
| 37 | + implicit none |
| 38 | + integer(kind=omp_integer_kind), intent(in) :: device_num |
| 39 | + type(c_ptr) :: device_uid |
| 40 | + integer(kind=omp_integer_kind) :: device_num_from_uid |
| 41 | + |
| 42 | + device_uid = omp_get_uid_from_device(device_num) |
| 43 | + |
| 44 | + ! Check if device_uid is NULL |
| 45 | + if (.not. c_associated(device_uid)) then |
| 46 | + print '("FAIL for device ", I0, ": omp_get_uid_from_device returned NULL")', device_num |
| 47 | + test_omp_device_uid = .false. |
| 48 | + return |
| 49 | + end if |
| 50 | + |
| 51 | + device_num_from_uid = omp_get_device_from_uid(device_uid) |
| 52 | + if (device_num_from_uid /= device_num) then |
| 53 | + print '("FAIL for device ", I0, ": omp_get_device_from_uid returned ", I0)', & |
| 54 | + device_num, device_num_from_uid |
| 55 | + test_omp_device_uid = .false. |
| 56 | + return |
| 57 | + end if |
| 58 | + |
| 59 | + test_omp_device_uid = .true. |
| 60 | + end function test_omp_device_uid |
| 61 | + |
| 62 | +end program test_omp_device_uid_main |
| 63 | + |
| 64 | +! CHECK: PASS |
| 65 | + |
0 commit comments