[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:35:00 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:
Addressed these in all the tests which now compares `omp_get_default_device() == omp_get_initial_device()` instead of assuming either equals `0`.
https://github.com/llvm/llvm-project/pull/171789
More information about the Openmp-commits
mailing list