[llvm] [openmp] [OpenMP][Runtime] Handling crash with OMP_TARGET_OFFLOAD=DISABLED and invalid default device (PR #173630)
Julian Brown via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 29 06:25:13 PST 2025
================
@@ -3295,30 +3295,43 @@ static kmp_internal_control_t __kmp_get_global_icvs(void) {
KMP_DEBUG_ASSERT(__kmp_nested_proc_bind.used > 0);
+ // When offload is disabled, default_device should be the initial device
+ // regardless of OMP_DEFAULT_DEVICE environment variable or explicit set
+ int default_device_icv = __kmp_default_device;
+ if (__kmp_target_offload == tgt_disabled) {
+ // Initial device is same as num_devices when offload is disabled
+ int (*fptr)();
+ if ((*(void **)(&fptr) = KMP_DLSYM("__tgt_get_num_devices"))) {
+ default_device_icv = (*fptr)();
+ } else {
+ default_device_icv = 0;
+ }
+ }
+
kmp_internal_control_t g_icvs = {
- 0, // int serial_nesting_level; //corresponds to value of th_team_serialized
- (kmp_int8)__kmp_global.g.g_dynamic, // internal control for dynamic
- // adjustment of threads (per thread)
- (kmp_int8)__kmp_env_blocktime, // int bt_set; //internal control for
- // whether blocktime is explicitly set
- __kmp_dflt_blocktime, // int blocktime; //internal control for blocktime
+ 0, // int serial_nesting_level; //corresponds to value of
+ // th_team_serialized
+ (kmp_int8)__kmp_global.g.g_dynamic, // internal control for dynamic
+ // adjustment of threads (per thread)
+ (kmp_int8)__kmp_env_blocktime, // int bt_set; //internal control for
+ // whether blocktime is explicitly set
+ __kmp_dflt_blocktime, // int blocktime; //internal control for blocktime
#if KMP_USE_MONITOR
- __kmp_bt_intervals, // int bt_intervals; //internal control for blocktime
+ __kmp_bt_intervals, // int bt_intervals; //internal control for blocktime
// intervals
#endif
- __kmp_dflt_team_nth, // int nproc; //internal control for # of threads for
- // next parallel region (per thread)
- // (use a max ub on value if __kmp_parallel_initialize not called yet)
- __kmp_cg_max_nth, // int thread_limit;
- __kmp_task_max_nth, // int task_thread_limit; // to set the thread_limit
- // on task. This is used in the case of target thread_limit
- __kmp_dflt_max_active_levels, // int max_active_levels; //internal control
- // for max_active_levels
- r_sched, // kmp_r_sched_t sched; //internal control for runtime schedule
- // {sched,chunk} pair
- __kmp_nested_proc_bind.bind_types[0],
- __kmp_default_device,
- NULL // struct kmp_internal_control *next;
+ __kmp_dflt_team_nth, // int nproc; //internal control for # of threads for
----------------
jtb20 wrote:
And here? (Just add the new field with the existing formatting.)
https://github.com/llvm/llvm-project/pull/173630
More information about the llvm-commits
mailing list