[Openmp-commits] [llvm] [openmp] [OpenMP][Runtime] Handling crash with `OMP_TARGET_OFFLOAD=DISABLED` and invoking `omp_get_default_device()` (PR #171789)
Amit Tiwari via Openmp-commits
openmp-commits at lists.llvm.org
Thu Dec 18 05:36:51 PST 2025
================
@@ -0,0 +1,45 @@
+// RUN: %libomptarget-compile-generic
+// RUN: env OMP_TARGET_OFFLOAD=disabled %libomptarget-run-generic 2>&1 |
+// %fcheck-generic
+//
+// Test that setting default device before disabling offload doesn't crash
+
+#include <omp.h>
+#include <stdio.h>
+
+int main() {
+ // Set high default device number
+ omp_set_default_device(5);
+
+ // This simulates OMP_TARGET_OFFLOAD=disabled being set after device is chosen
+ // In practice, the environment variable is read at runtime init
+
+ // CHECK: num_devices: 0
+ printf("num_devices: %d\n", omp_get_num_devices());
+
+ // CHECK: initial_device: 0
+ printf("initial_device: %d\n", omp_get_initial_device());
----------------
amitamd7 wrote:
Modified the test so that it no longer relies on the “initial value” per se. It now simply validates that when offloading is disabled, the default device getter still returns the host device, even if the user code attempts to change it via a flag or setter.
https://github.com/llvm/llvm-project/pull/171789
More information about the Openmp-commits
mailing list