[Openmp-commits] [llvm] [openmp] [OpenMP][Runtime] Handling crash with `OMP_TARGET_OFFLOAD=DISABLED` and invoking `omp_get_default_device()` (PR #171789)
via Openmp-commits
openmp-commits at lists.llvm.org
Thu Dec 18 07:04:45 PST 2025
================
@@ -1197,6 +1189,17 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_INITIAL_DEVICE)(void) {
return KMP_EXPAND_NAME(FTN_GET_NUM_DEVICES)();
}
+int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_DEFAULT_DEVICE)(void) {
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+ return 0;
+#else
+ // When offloading is disabled, return the initial device (host)
+ if (__kmp_target_offload == tgt_disabled)
+ return KMP_EXPAND_NAME(FTN_GET_INITIAL_DEVICE)();
----------------
jprotze wrote:
I'm looking at this from the spec perspective. From OpenMP 6.0 ยง24.2:
> **Effect**
> The omp_get_default_device routine returns the value of the default-device-var ICV of the
> current task, which is the device number of the default target device. When called from within a
> target region the effect of this routine is unspecified.
I claim that, according to the spec, the implementation of the routine is wrong. Error handling should be done where the error occurs, which is during setting the wrong value. Setting the default device to a non-conforming device number is UB and anything can happen.
At the moment, you just cover the case of offload-disabled. Wouldn't `OMP_AVAILABLE_DEVICES=` result in the same issue?
https://github.com/llvm/llvm-project/pull/171789
More information about the Openmp-commits
mailing list