mirror of
https://github.com/clang-retro/llvm.git
synced 2026-11-28 21:29:24 -08:00
In OpenMP v5.2, the constant `omp_initial_device` was introduced, which was defined as a value of `-1`. Support for this value was added to Clang and Flang in09cd294482and3c14034c55. However, runtime calls are not aware of this constant. As such, execution of a runtime function, passing `omp_initial_device` as the `device_num`, would abort with e.g.,: ``` omptarget fatal error -1: "invalid value" device number '-1' out of range, only 1 devices available ``` To fix this issue, also extend the host device checks in the API functions to also check for `omp_initial_device`. For testing, extend API tests using `omp_get_initial_device()` to also test `omp_initial_device` and extend `omp_device_uid.c` to check if the UID for `omp_initial_device` and `omp_get_initial_device()` matches. Partially addresses https://github.com/llvm/llvm-project/issues/192980 (see https://github.com/llvm/llvm-project/issues/192980#issuecomment-4404241994) --------- Signed-off-by: Jan André Reuter <j.reuter@fz-juelich.de> Signed-off-by: Jan André Reuter <jan@zyten.de>
50 lines
917 B
C
50 lines
917 B
C
// RUN: %libomptarget-compile-and-run-generic
|
|
|
|
#include "stdio.h"
|
|
#include <omp.h>
|
|
#include <stdlib.h>
|
|
|
|
int run_test(int hostDev) {
|
|
int d = omp_get_default_device();
|
|
int id = hostDev;
|
|
int q[128], i;
|
|
void *p;
|
|
void *result;
|
|
|
|
if (d < 0 || d >= omp_get_num_devices())
|
|
d = id;
|
|
|
|
p = omp_target_alloc(130 * sizeof(int), d);
|
|
if (p == NULL)
|
|
return 0;
|
|
|
|
for (i = 0; i < 128; i++)
|
|
q[i] = i;
|
|
|
|
result = omp_target_memset(p, 0, 130 * sizeof(int), d);
|
|
if (result != p) {
|
|
abort();
|
|
}
|
|
|
|
int q2[128];
|
|
for (i = 0; i < 128; ++i)
|
|
q2[i] = i;
|
|
if (omp_target_memcpy_async(q2, p, 128 * sizeof(int), 0, sizeof(int), id, d,
|
|
0, NULL))
|
|
abort();
|
|
|
|
#pragma omp taskwait
|
|
|
|
for (i = 0; i < 128; ++i)
|
|
if (q2[i] != 0)
|
|
abort();
|
|
|
|
omp_target_free(p, d);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
return run_test(omp_get_initial_device()) && run_test(omp_initial_device);
|
|
}
|