From be661959a6b6d8f9c3c8608a746789e7b2ec3ca4 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Tue, 4 Jan 2022 14:58:06 +0100 Subject: [PATCH] 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. --- libgomp/testsuite/libgomp.c-c++-common/target-45.c | 28 +++++++++++++--------- libgomp/testsuite/libgomp.fortran/target10.f90 | 18 +++++++------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-45.c b/libgomp/testsuite/libgomp.c-c++-common/target-45.c index 81acee8..8375039 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/target-45.c +++ b/libgomp/testsuite/libgomp.c-c++-common/target-45.c @@ -14,17 +14,23 @@ int main (void) int device_num; int initial_device; - #pragma omp target map(from: device_num, initial_device) - { - initial_device = omp_is_initial_device (); - device_num = omp_get_device_num (); - } - - if (initial_device && host_device_num != device_num) - abort (); - - if (!initial_device && host_device_num == device_num) - abort (); + for (int i = 0; i <= omp_get_num_devices (); i++) + { + #pragma omp target map(from: device_num, initial_device) device(i) + { + initial_device = omp_is_initial_device (); + device_num = omp_get_device_num (); + } + + if (i != device_num) + abort (); + + if (initial_device && host_device_num != device_num) + abort (); + + if (!initial_device && host_device_num == device_num) + abort (); + } return 0; } diff --git a/libgomp/testsuite/libgomp.fortran/target10.f90 b/libgomp/testsuite/libgomp.fortran/target10.f90 index f41a726..f6951fc 100644 --- a/libgomp/testsuite/libgomp.fortran/target10.f90 +++ b/libgomp/testsuite/libgomp.fortran/target10.f90 @@ -4,18 +4,20 @@ program main use omp_lib implicit none - integer :: device_num, host_device_num + integer :: device_num, host_device_num, i logical :: initial_device host_device_num = omp_get_device_num () if (host_device_num .ne. omp_get_initial_device ()) stop 1 - !$omp target map(from: device_num, initial_device) - initial_device = omp_is_initial_device () - device_num = omp_get_device_num () - !$omp end target - - if (initial_device .and. (host_device_num .ne. device_num)) stop 2 - if ((.not. initial_device) .and. (host_device_num .eq. device_num)) stop 3 + do i = 0, omp_get_num_devices () + !$omp target map(from: device_num, initial_device) device(i) + initial_device = omp_is_initial_device () + device_num = omp_get_device_num () + !$omp end target + if (i /= device_num) stop 2 + 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 -- 2.7.4