[llvm] [openmp] [OpenMP][Runtime] Handling crash with `OMP_TARGET_OFFLOAD=DISABLED` and invoking `omp_get_default_device()` (PR #171789)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 11 07:13:15 PST 2025
================
@@ -0,0 +1,69 @@
+// RUN: %libomp-compile-and-run
+// REQUIRES: ompt
+//
+// Test that omp_get_default_device() returns the initial device (0) when
+// called from within a target region when OMP_TARGET_OFFLOAD=DISABLED.
+// The target region should execute on the host.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <omp.h>
+
+extern void kmp_set_defaults(char const *str);
+
+int main() {
+ // Set non-zero default device using API (more direct than env var)
+ omp_set_default_device(4);
+
+ // Now disable offload
+ kmp_set_defaults("OMP_TARGET_OFFLOAD=DISABLED");
+
+// Force parallel region to initialize runtime
+#pragma omp parallel
+ {
+ }
+
+ int initial_device = omp_get_initial_device();
+ int host_default_device = omp_get_default_device();
+ int target_default_device = -1;
+ int target_is_initial = -1;
+
+ printf("Host context:\n");
+ printf(" initial_device = %d\n", initial_device);
+ printf(" default_device = %d\n", host_default_device);
+
+// Call omp_get_default_device() from within target region
+// When offload is disabled, this should execute on host
+#pragma omp target map(from : target_default_device, target_is_initial)
+ {
+ target_default_device = omp_get_default_device();
----------------
jprotze wrote:
> When called from within a target region the effect of this routine is unspecified.
https://github.com/llvm/llvm-project/pull/171789
More information about the llvm-commits
mailing list