[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:16 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 think, it's a bad idea to fake the output. Having the icv set to an invalid value will just cause other issues.
Just as an example, `__kmp_alloc` uses `default_device` in a lot of places.

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


More information about the llvm-commits mailing list