[Openmp-commits] [flang] [openmp] [Flang][OpenMP] Validate `omp_initial_device` `omp_invalid_device` as device IDs (PR #193669)

Jan André Reuter via Openmp-commits openmp-commits at lists.llvm.org
Thu Apr 23 01:34:42 PDT 2026


Thyre wrote:

Thanks a lot for working on this and providing a PR this quickly.

I tested this out and it seems to work as expected.
Unfortunately, I cannot comment much on the code itself, as I'm not too familiar with the internals.

Just as a note though (this shouldn't hold up this PR), `omp_initial_device` will, for now, point to the default device and not the initial device (see also #192980).

```fortran
program main
    use omp_lib
    logical :: is_host_device

    !$omp target device( omp_initial_device ) map(from: is_host_device)
        is_host_device = omp_is_initial_device()
    !$omp end target
    print *, "Target region with omp_initial_device was running on host? ", is_host_device

    !$omp target device( omp_get_initial_device() ) map(from: is_host_device)
        is_host_device = omp_is_initial_device()
    !$omp end target
    print *, "Target region with omp_get_initial_device() was running on host? ", is_host_device

    !$omp target device( omp_invalid_device )
    !$omp end target
end program main
```

```console
$ flang -fopenmp --offload-arch=gfx1101 test.f90
$ ./a.out
 Target region with omp_initial_device was running on host?  F
 Target region with omp_get_initial_device() was running on host?  T
omptarget fatal error -2: "invalid value" device number '-2' out of range, only 1 devices available
[1]    3419603 IOT instruction (core dumped)  ./a.out

https://github.com/llvm/llvm-project/pull/193669


More information about the Openmp-commits mailing list