Skip to content

Commit 916a915

Browse files
authored
[OpenMP] Assign thread ids in the cpuinfo topology method (#91013)
On non-hyperthreaded machines, the thread id is not always explicit in the /proc/cpuinfo file. This patch adds a check to ensure the thread ids are put in.
1 parent 77ff969 commit 916a915

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,6 +3841,32 @@ static bool __kmp_affinity_create_cpuinfo_map(int *line,
38413841
__kmp_free(counts);
38423842
CLEANUP_THREAD_INFO;
38433843
__kmp_topology->sort_ids();
3844+
3845+
int tlevel = __kmp_topology->get_level(KMP_HW_THREAD);
3846+
if (tlevel > 0) {
3847+
// If the thread level does not have ids, then put them in.
3848+
if (__kmp_topology->at(0).ids[tlevel] == kmp_hw_thread_t::UNKNOWN_ID) {
3849+
__kmp_topology->at(0).ids[tlevel] = 0;
3850+
}
3851+
for (int i = 1; i < __kmp_topology->get_num_hw_threads(); ++i) {
3852+
kmp_hw_thread_t &hw_thread = __kmp_topology->at(i);
3853+
if (hw_thread.ids[tlevel] != kmp_hw_thread_t::UNKNOWN_ID)
3854+
continue;
3855+
kmp_hw_thread_t &prev_hw_thread = __kmp_topology->at(i - 1);
3856+
// Check if socket, core, anything above thread level changed.
3857+
// If the ids did change, then restart thread id at 0
3858+
// Otherwise, set thread id to prev thread's id + 1
3859+
for (int j = 0; j < tlevel; ++j) {
3860+
if (hw_thread.ids[j] != prev_hw_thread.ids[j]) {
3861+
hw_thread.ids[tlevel] = 0;
3862+
break;
3863+
}
3864+
}
3865+
if (hw_thread.ids[tlevel] == kmp_hw_thread_t::UNKNOWN_ID)
3866+
hw_thread.ids[tlevel] = prev_hw_thread.ids[tlevel] + 1;
3867+
}
3868+
}
3869+
38443870
if (!__kmp_topology->check_ids()) {
38453871
kmp_topology_t::deallocate(__kmp_topology);
38463872
__kmp_topology = nullptr;

0 commit comments

Comments
 (0)