libgomp/testsuite: Improve omp_get_device_num() tests

Related to r12-6208-gebc853deb7cc0487de9ef6e891a007ba853d1933
"libgomp: Fix GOMP_DEVICE_NUM_VAR stringification during offload image load"

That commit fixed an issue with omp_get_device_num() on gcn/nvptx that
resulted in having always the value 0.
This commit modifies the tests to iterate over all devices such that on a
multi-nonhost-device system it had detected that always-zero issue.

libgomp/ChangeLog:

	* testsuite/libgomp.c-c++-common/target-45.c: Iterate over all devices.
	* testsuite/libgomp.fortran/target10.f90: Likewise.
This commit is contained in:
Tobias Burnus 2022-01-04 14:58:06 +01:00
parent ebc853deb7
commit be661959a6
2 changed files with 25 additions and 17 deletions

View File

@ -14,17 +14,23 @@ int main (void)
int device_num; int device_num;
int initial_device; int initial_device;
#pragma omp target map(from: device_num, initial_device) for (int i = 0; i <= omp_get_num_devices (); i++)
{ {
initial_device = omp_is_initial_device (); #pragma omp target map(from: device_num, initial_device) device(i)
device_num = omp_get_device_num (); {
} initial_device = omp_is_initial_device ();
device_num = omp_get_device_num ();
}
if (initial_device && host_device_num != device_num) if (i != device_num)
abort (); abort ();
if (!initial_device && host_device_num == device_num) if (initial_device && host_device_num != device_num)
abort (); abort ();
if (!initial_device && host_device_num == device_num)
abort ();
}
return 0; return 0;
} }

View File

@ -4,18 +4,20 @@
program main program main
use omp_lib use omp_lib
implicit none implicit none
integer :: device_num, host_device_num integer :: device_num, host_device_num, i
logical :: initial_device logical :: initial_device
host_device_num = omp_get_device_num () host_device_num = omp_get_device_num ()
if (host_device_num .ne. omp_get_initial_device ()) stop 1 if (host_device_num .ne. omp_get_initial_device ()) stop 1
!$omp target map(from: device_num, initial_device) do i = 0, omp_get_num_devices ()
initial_device = omp_is_initial_device () !$omp target map(from: device_num, initial_device) device(i)
device_num = omp_get_device_num () initial_device = omp_is_initial_device ()
!$omp end target device_num = omp_get_device_num ()
!$omp end target
if (initial_device .and. (host_device_num .ne. device_num)) stop 2 if (i /= device_num) stop 2
if ((.not. initial_device) .and. (host_device_num .eq. device_num)) stop 3 if (initial_device .and. (host_device_num .ne. device_num)) stop 3
if ((.not. initial_device) .and. (host_device_num .eq. device_num)) stop 4
end do
end program main end program main