24#define HWLOC_GROUP_KIND_INTEL_MODULE 102
25#define HWLOC_GROUP_KIND_INTEL_TILE 103
26#define HWLOC_GROUP_KIND_INTEL_DIE 104
27#define HWLOC_GROUP_KIND_WINDOWS_PROCESSOR_GROUP 220
41#if KMP_AFFINITY_SUPPORTED
43class kmp_full_mask_modifier_t {
44 kmp_affin_mask_t *
mask;
47 kmp_full_mask_modifier_t() {
51 ~kmp_full_mask_modifier_t() {
55 void include(
const kmp_affin_mask_t *other) { KMP_CPU_UNION(
mask, other); }
58 bool restrict_to_mask() {
60 if (KMP_CPU_EQUAL(__kmp_affin_fullMask,
mask) || KMP_CPU_ISEMPTY(
mask))
66static inline const char *
67__kmp_get_affinity_env_var(
const kmp_affinity_t &affinity,
68 bool for_binding =
false) {
69 if (affinity.flags.omp_places) {
71 return "OMP_PROC_BIND";
74 return affinity.env_var;
92 thr_bar->depth = depth;
94 &(thr_bar->base_leaf_kids));
100#ifndef KMP_DFLT_NTH_CORES
134 KMP_ASSERT2(
false,
"Unhandled kmp_hw_t enumeration");
141 return ((plural) ?
"sockets" :
"socket");
143 return ((plural) ?
"dice" :
"die");
145 return ((plural) ?
"modules" :
"module");
147 return ((plural) ?
"tiles" :
"tile");
149 return ((plural) ?
"numa_domains" :
"numa_domain");
151 return ((plural) ?
"l3_caches" :
"l3_cache");
153 return ((plural) ?
"l2_caches" :
"l2_cache");
155 return ((plural) ?
"l1_caches" :
"l1_cache");
157 return ((plural) ?
"ll_caches" :
"ll_cache");
159 return ((plural) ?
"cores" :
"core");
161 return ((plural) ?
"threads" :
"thread");
163 return ((plural) ?
"proc_groups" :
"proc_group");
166 return ((plural) ?
"unknowns" :
"unknown");
168 KMP_ASSERT2(
false,
"Unhandled kmp_hw_t enumeration");
177#if KMP_ARCH_X86 || KMP_ARCH_X86_64
178 case KMP_HW_CORE_TYPE_ATOM:
179 return "Intel Atom(R) processor";
180 case KMP_HW_CORE_TYPE_CORE:
181 return "Intel(R) Core(TM) processor";
184 KMP_ASSERT2(
false,
"Unhandled kmp_hw_core_type_t enumeration");
188#if KMP_AFFINITY_SUPPORTED
191#define KMP_AFF_WARNING(s, ...) \
192 if (s.flags.verbose || (s.flags.warnings && (s.type != affinity_none))) { \
193 KMP_WARNING(__VA_ARGS__); \
196#define KMP_AFF_WARNING(s, ...) KMP_WARNING(__VA_ARGS__)
218#if KMP_AFFINITY_SUPPORTED
227 for (
i = 0;
i < compact;
i++) {
228 int j = depth -
i - 1;
234 for (;
i < depth;
i++) {
247 printf(
"%4d ",
os_id);
248 for (
int i = 0;
i < depth; ++
i) {
249 printf(
"%4d ",
ids[
i]);
267void kmp_topology_t::_insert_layer(
kmp_hw_t type,
const int *ids) {
276 for (target_layer = 0; target_layer < depth; ++target_layer) {
277 bool layers_equal =
true;
278 bool strictly_above_target_layer =
false;
279 for (
int i = 0;
i < num_hw_threads; ++
i) {
280 int id = hw_threads[
i].
ids[target_layer];
282 if (
id != previous_id && new_id == previous_new_id) {
284 strictly_above_target_layer =
true;
285 layers_equal =
false;
287 }
else if (
id == previous_id && new_id != previous_new_id) {
289 layers_equal =
false;
293 previous_new_id = new_id;
295 if (strictly_above_target_layer || layers_equal)
301 for (
int i = depth - 1,
j = depth;
i >= target_layer; --
i, --
j)
303 types[target_layer] =
type;
304 for (
int k = 0; k < num_hw_threads; ++k) {
305 for (
int i = depth - 1,
j = depth;
i >= target_layer; --
i, --
j)
306 hw_threads[k].ids[
j] = hw_threads[k].ids[
i];
307 hw_threads[k].
ids[target_layer] = ids[k];
313#if KMP_GROUP_AFFINITY
315void kmp_topology_t::_insert_windows_proc_groups() {
317 if (__kmp_num_proc_groups == 1)
319 kmp_affin_mask_t *
mask;
322 for (
int i = 0;
i < num_hw_threads; ++
i) {
324 KMP_CPU_SET(hw_threads[
i].os_id,
mask);
325 ids[
i] = __kmp_get_proc_group(
mask);
338void kmp_topology_t::_remove_radix1_layers() {
340 int top_index1, top_index2;
356 while (top_index1 < depth - 1 && top_index2 < depth) {
367 top_index1 = top_index2++;
371 bool all_same =
true;
372 int id1 = hw_threads[0].
ids[top_index1];
373 int id2 = hw_threads[0].
ids[top_index2];
374 int pref1 = preference[type1];
375 int pref2 = preference[type2];
376 for (
int hwidx = 1; hwidx < num_hw_threads; ++hwidx) {
377 if (hw_threads[hwidx].ids[top_index1] == id1 &&
378 hw_threads[hwidx].ids[top_index2] != id2) {
382 if (hw_threads[hwidx].ids[top_index2] != id2)
384 id1 = hw_threads[hwidx].
ids[top_index1];
385 id2 = hw_threads[hwidx].
ids[top_index2];
390 int remove_layer, remove_layer_ids;
393 remove_layer = remove_layer_ids = top_index2;
397 remove_layer = remove_layer_ids = top_index1;
403 remove_layer_ids = top_index2;
407 for (
int idx = 0; idx < num_hw_threads; ++idx) {
409 for (
int d = remove_layer_ids;
d < depth - 1; ++
d)
410 hw_thread.
ids[
d] = hw_thread.
ids[
d + 1];
412 for (
int idx = remove_layer; idx < depth - 1; ++idx)
413 types[idx] = types[idx + 1];
416 top_index1 = top_index2++;
422void kmp_topology_t::_set_last_level_cache() {
428 else if (__kmp_mic_type == mic3) {
451void kmp_topology_t::_gather_enumeration_information() {
455 for (
int i = 0;
i < depth; ++
i) {
462 for (
int i = 0;
i < num_hw_threads; ++
i) {
464 for (
int layer = 0; layer < depth; ++layer) {
465 int id = hw_thread.
ids[layer];
466 if (
id != previous_id[layer]) {
468 for (
int l = layer; l < depth; ++l)
472 for (
int l = layer + 1; l < depth; ++l) {
473 if (max[l] > ratio[l])
488 for (
int j = 0;
j < num_core_types; ++
j) {
503 for (
int layer = 0; layer < depth; ++layer) {
504 previous_id[layer] = hw_thread.
ids[layer];
507 for (
int layer = 0; layer < depth; ++layer) {
508 if (max[layer] > ratio[layer])
509 ratio[layer] = max[layer];
513int kmp_topology_t::_get_ncores_with_attr(
const kmp_hw_attr_t &attr,
515 bool find_all)
const {
516 int current, current_max;
518 for (
int i = 0;
i < depth; ++
i)
526 for (
int i = 0;
i < num_hw_threads; ++
i) {
528 if (!find_all && hw_thread.
ids[above_level] != previous_id[above_level]) {
529 if (current > current_max)
530 current_max = current;
544 if (current > current_max)
545 current_max = current;
550void kmp_topology_t::_discover_uniformity() {
554 flags.uniform = (num == count[depth - 1]);
558void kmp_topology_t::_set_sub_ids() {
562 for (
int i = 0;
i < depth; ++
i) {
566 for (
int i = 0;
i < num_hw_threads; ++
i) {
569 for (
int j = 0;
j < depth; ++
j) {
570 if (hw_thread.
ids[
j] != previous_id[
j]) {
572 for (
int k =
j + 1; k < depth; ++k) {
579 for (
int j = 0;
j < depth; ++
j) {
580 previous_id[
j] = hw_thread.
ids[
j];
583 for (
int j = 0;
j < depth; ++
j) {
589void kmp_topology_t::_set_globals() {
591 int core_level, thread_level, package_level;
593#if KMP_GROUP_AFFINITY
594 if (package_level == -1)
604 if (package_level != -1) {
612#ifndef KMP_DFLT_NTH_CORES
628 retval->hw_threads =
nullptr;
630 retval->num_hw_threads = nproc;
631 retval->depth = ndepth;
637 retval->num_core_efficiencies = 0;
638 retval->num_core_types = 0;
643 for (
int i = 0;
i < ndepth; ++
i) {
644 retval->types[
i] = types[
i];
645 retval->equivalent[types[
i]] = types[
i];
657 if (num_hw_threads == 0)
659 for (
int i = 1;
i < num_hw_threads; ++
i) {
663 for (
int j = 0;
j < depth; ++
j) {
664 if (previous_thread.
ids[
j] != current_thread.
ids[
j]) {
677 printf(
"***********************\n");
678 printf(
"*** __kmp_topology: ***\n");
679 printf(
"***********************\n");
680 printf(
"* depth: %d\n", depth);
683 for (
int i = 0;
i < depth; ++
i)
688 for (
int i = 0;
i < depth; ++
i) {
689 printf(
"%15d ", ratio[
i]);
694 for (
int i = 0;
i < depth; ++
i) {
695 printf(
"%15d ", count[
i]);
699 printf(
"* num_core_eff: %d\n", num_core_efficiencies);
700 printf(
"* num_core_types: %d\n", num_core_types);
701 printf(
"* core_types: ");
702 for (
int i = 0;
i < num_core_types; ++
i)
703 printf(
"%3d ", core_types[
i]);
706 printf(
"* equivalent map:\n");
710 printf(
"%-15s -> %-15s\n",
key,
value);
713 printf(
"* uniform: %s\n", (
is_uniform() ?
"Yes" :
"No"));
715 printf(
"* num_hw_threads: %d\n", num_hw_threads);
716 printf(
"* hw_threads:\n");
717 for (
int i = 0;
i < num_hw_threads; ++
i) {
720 printf(
"***********************\n");
725 int print_types_depth;
730 if (num_hw_threads) {
731 KMP_INFORM(AvailableOSProc, env_var, num_hw_threads);
757 print_types_depth = 0;
759 print_types[print_types_depth++] = types[
level];
781 for (
int plevel = 0,
level = 0; plevel < print_types_depth; ++plevel) {
784 numerator_type = print_types[plevel];
786 if (equivalent[numerator_type] != numerator_type)
799 denominator_type = numerator_type;
805 for (
int i = 0;
i < num_core_types; ++
i) {
815 for (
int eff = 0; eff < num_core_efficiencies; ++eff) {
818 if (ncores_with_eff > 0) {
819 KMP_INFORM(TopologyHybridCoreEff, env_var, ncores_with_eff, eff);
826 if (num_hw_threads <= 0) {
832 KMP_INFORM(OSProcToPhysicalThreadMap, env_var);
833 for (
int i = 0;
i < num_hw_threads;
i++) {
844 KMP_INFORM(OSProcMapToPack, env_var, hw_threads[
i].os_id,
buf.str);
850#if KMP_AFFINITY_SUPPORTED
851void kmp_topology_t::set_granularity(kmp_affinity_t &affinity)
const {
852 const char *env_var = __kmp_get_affinity_env_var(affinity);
857 if (affinity.core_attr_gran.valid) {
861 affinity, AffIgnoringNonHybrid, env_var,
864 affinity.gran_levels = -1;
865 affinity.core_attr_gran = KMP_AFFINITY_ATTRS_UNKNOWN;
866 affinity.flags.core_types_gran = affinity.flags.core_effs_gran = 0;
867 }
else if (affinity.flags.core_types_gran ||
868 affinity.flags.core_effs_gran) {
870 if (affinity.flags.omp_places) {
872 affinity, AffIgnoringNonHybrid, env_var,
877 "Intel(R) Hybrid Technology core attribute",
881 affinity.gran_levels = -1;
882 affinity.core_attr_gran = KMP_AFFINITY_ATTRS_UNKNOWN;
883 affinity.flags.core_types_gran = affinity.flags.core_effs_gran = 0;
887 if (affinity.gran_levels < 0) {
893 for (
auto g : gran_types) {
904 affinity.gran = gran_type;
906#if KMP_GROUP_AFFINITY
914 if (__kmp_num_proc_groups > 1) {
917 if (gran_depth >= 0 && proc_group_depth >= 0 &&
918 gran_depth < proc_group_depth) {
925 affinity.gran_levels = 0;
926 for (
int i = depth - 1;
i >= 0 &&
get_type(
i) != gran_type; --
i)
927 affinity.gran_levels++;
933#if KMP_GROUP_AFFINITY
934 _insert_windows_proc_groups();
936 _remove_radix1_layers();
937 _gather_enumeration_information();
938 _discover_uniformity();
941 _set_last_level_cache();
945 if (__kmp_mic_type == mic3) {
966 int nthreads_per_core,
int ncores) {
974 count[0] = npackages;
977 ratio[0] = npackages;
978 ratio[1] = ncores_per_pkg;
979 ratio[2] = nthreads_per_core;
987 _discover_uniformity();
990#if KMP_AFFINITY_SUPPORTED
1006bool kmp_topology_t::restrict_to_mask(
const kmp_affin_mask_t *
mask) {
1010 for (
int i = 0;
i < num_hw_threads; ++
i) {
1011 int os_id = hw_threads[
i].
os_id;
1012 if (KMP_CPU_ISSET(os_id,
mask)) {
1014 hw_threads[new_index] = hw_threads[
i];
1017 KMP_CPU_CLR(os_id, __kmp_affin_fullMask);
1023 affected = (num_hw_threads != new_index);
1024 num_hw_threads = new_index;
1028 _gather_enumeration_information();
1029 _discover_uniformity();
1031 _set_last_level_cache();
1034 if (__kmp_num_proc_groups <= 1)
1036 __kmp_affin_origMask->copy(__kmp_affin_fullMask);
1044bool kmp_topology_t::filter_hw_subset() {
1055 bool using_core_types =
false;
1056 bool using_core_effs =
false;
1060 int *topology_levels = (
int *)
KMP_ALLOCA(
sizeof(
int) * hw_subset_depth);
1064 for (
int i = 0;
i < hw_subset_depth; ++
i) {
1067 int num = item.
num[0];
1068 int offset = item.
offset[0];
1072 topology_levels[
i] =
level;
1091 specified[equivalent_type] =
type;
1096 if (max_count < 0 ||
1098 bool plural = (num > 1);
1106 if (core_level ==
level) {
1110 using_core_types =
true;
1112 using_core_effs =
true;
1122 if (using_core_effs) {
1129 using_core_effs =
false;
1130 using_core_types =
false;
1138 if (using_core_types && using_core_effs) {
1145 if (using_core_effs) {
1149 if (core_eff < 0 || core_eff >= num_core_efficiencies) {
1154 KMP_MSG(AffHWSubsetAttrInvalid,
"efficiency",
buf.str),
1155 KMP_HNT(ValidValuesRange, 0, num_core_efficiencies - 1),
1165 if ((using_core_types || using_core_effs) && !is_absolute) {
1167 int num = item.
num[
j];
1169 int level_above = core_level - 1;
1170 if (level_above >= 0) {
1172 if (max_count <= 0 ||
1175 __kmp_hw_get_catalog_core_string(item.
attr[
j], &
buf, num > 0);
1184 if ((using_core_types || using_core_effs) && item.
num_attrs > 1) {
1188 if (!item.
attr[
j]) {
1190 for (
int k = 0; k < item.
num_attrs; ++k) {
1192 other_attr = item.
attr[k];
1197 __kmp_hw_get_catalog_core_string(other_attr, &
buf, item.
num[
j] > 0);
1204 for (
int k = 0; k <
j; ++k) {
1209 __kmp_hw_get_catalog_core_string(item.
attr[
j], &
buf,
1228 abs_sub_ids[
i] = -1;
1229 prev_sub_ids[
i] = -1;
1232 core_eff_sub_ids[
i] = -1;
1234 core_type_sub_ids[
i] = -1;
1239 auto is_targeted = [&](
int level) {
1241 for (
int i = 0;
i < hw_subset_depth; ++
i)
1242 if (topology_levels[
i] ==
level)
1252 switch (t.attrs.get_core_type()) {
1256#if KMP_ARCH_X86 || KMP_ARCH_X86_64
1257 case KMP_HW_CORE_TYPE_ATOM:
1259 case KMP_HW_CORE_TYPE_CORE:
1263 KMP_ASSERT2(
false,
"Unhandled kmp_hw_thread_t enumeration");
1269 return t.attrs.get_core_eff();
1272 int num_filtered = 0;
1273 kmp_affin_mask_t *filtered_mask;
1274 KMP_CPU_ALLOC(filtered_mask);
1275 KMP_CPU_COPY(filtered_mask, __kmp_affin_fullMask);
1276 for (
int i = 0;
i < num_hw_threads; ++
i) {
1280 if (is_absolute || using_core_effs || using_core_types) {
1283 bool found_targeted =
false;
1285 bool targeted = is_targeted(
j);
1286 if (!found_targeted && targeted) {
1287 found_targeted =
true;
1289 if (
j == core_level && using_core_effs)
1290 core_eff_sub_ids[get_core_eff_index(hw_thread)]++;
1291 if (
j == core_level && using_core_types)
1292 core_type_sub_ids[get_core_type_index(hw_thread)]++;
1293 }
else if (targeted) {
1295 if (
j == core_level && using_core_effs)
1296 core_eff_sub_ids[get_core_eff_index(hw_thread)] = 0;
1297 if (
j == core_level && using_core_types)
1298 core_type_sub_ids[get_core_type_index(hw_thread)] = 0;
1309 bool should_be_filtered =
false;
1310 for (
int hw_subset_index = 0; hw_subset_index < hw_subset_depth;
1311 ++hw_subset_index) {
1313 int level = topology_levels[hw_subset_index];
1316 if ((using_core_effs || using_core_types) &&
level == core_level) {
1324 for (attr_idx = 0; attr_idx < hw_subset_item.num_attrs; ++attr_idx) {
1325 if (using_core_types &&
1326 hw_subset_item.attr[attr_idx].get_core_type() == core_type)
1328 if (using_core_effs &&
1329 hw_subset_item.attr[attr_idx].get_core_eff() == core_eff)
1333 if (attr_idx == hw_subset_item.num_attrs) {
1334 should_be_filtered =
true;
1338 int num = hw_subset_item.num[attr_idx];
1339 int offset = hw_subset_item.offset[attr_idx];
1340 if (using_core_types)
1341 sub_id = core_type_sub_ids[get_core_type_index(hw_thread)];
1343 sub_id = core_eff_sub_ids[get_core_eff_index(hw_thread)];
1344 if (sub_id < offset ||
1346 should_be_filtered =
true;
1351 int num = hw_subset_item.num[0];
1352 int offset = hw_subset_item.offset[0];
1354 sub_id = abs_sub_ids[
level];
1357 if (sub_id < offset ||
1359 should_be_filtered =
true;
1365 if (should_be_filtered) {
1366 KMP_CPU_CLR(hw_thread.
os_id, filtered_mask);
1372 if (num_filtered == num_hw_threads) {
1378 restrict_to_mask(filtered_mask);
1382bool kmp_topology_t::is_close(
int hwt1,
int hwt2,
1383 const kmp_affinity_t &stgs)
const {
1384 int hw_level = stgs.gran_levels;
1385 if (hw_level >= depth)
1390 if (stgs.flags.core_types_gran)
1392 if (stgs.flags.core_effs_gran)
1394 for (
int i = 0;
i < (depth - hw_level); ++
i) {
1403bool KMPAffinity::picked_api =
false;
1405void *KMPAffinity::Mask::operator
new(
size_t n) {
return __kmp_allocate(n); }
1406void *KMPAffinity::Mask::operator
new[](
size_t n) {
return __kmp_allocate(n); }
1407void KMPAffinity::Mask::operator
delete(
void *
p) {
__kmp_free(
p); }
1408void KMPAffinity::Mask::operator
delete[](
void *
p) {
__kmp_free(
p); }
1409void *KMPAffinity::operator
new(
size_t n) {
return __kmp_allocate(n); }
1410void KMPAffinity::operator
delete(
void *
p) {
__kmp_free(
p); }
1412void KMPAffinity::pick_api() {
1413 KMPAffinity *affinity_dispatch;
1419 if (__kmp_affinity_top_method == affinity_top_method_hwloc &&
1420 __kmp_affinity.type != affinity_disabled) {
1421 affinity_dispatch =
new KMPHwlocAffinity();
1425 affinity_dispatch =
new KMPNativeAffinity();
1427 __kmp_affinity_dispatch = affinity_dispatch;
1431void KMPAffinity::destroy_api() {
1432 if (__kmp_affinity_dispatch != NULL) {
1433 delete __kmp_affinity_dispatch;
1434 __kmp_affinity_dispatch = NULL;
1439#define KMP_ADVANCE_SCAN(scan) \
1440 while (*scan != '\0') { \
1448char *__kmp_affinity_print_mask(
char *
buf,
int buf_len,
1449 kmp_affin_mask_t *
mask) {
1450 int start = 0, finish = 0, previous = 0;
1456 char *
end =
buf + buf_len - 1;
1459 if (
mask->begin() ==
mask->end()) {
1461 KMP_ADVANCE_SCAN(scan);
1467 start =
mask->begin();
1471 for (finish =
mask->next(start), previous = start;
1472 finish == previous + 1 && finish !=
mask->end();
1473 finish =
mask->next(finish)) {
1481 KMP_ADVANCE_SCAN(scan);
1483 first_range =
false;
1486 if (previous - start > 1) {
1491 KMP_ADVANCE_SCAN(scan);
1492 if (previous - start > 0) {
1496 KMP_ADVANCE_SCAN(scan);
1499 if (start ==
mask->end())
1510#undef KMP_ADVANCE_SCAN
1517 kmp_affin_mask_t *
mask) {
1518 int start = 0, finish = 0, previous = 0;
1526 if (
mask->begin() ==
mask->end()) {
1532 start =
mask->begin();
1536 for (finish =
mask->next(start), previous = start;
1537 finish == previous + 1 && finish !=
mask->end();
1538 finish =
mask->next(finish)) {
1547 first_range =
false;
1550 if (previous - start > 1) {
1555 if (previous - start > 0) {
1561 if (start ==
mask->end())
1569kmp_affin_mask_t *__kmp_affinity_get_offline_cpus() {
1570 kmp_affin_mask_t *offline;
1571 KMP_CPU_ALLOC(offline);
1572 KMP_CPU_ZERO(offline);
1574 int n, begin_cpu, end_cpu;
1576 auto skip_ws = [](FILE *
f) {
1580 }
while (isspace(c));
1586 int status = offline_file.
try_open(
"/sys/devices/system/cpu/offline",
"r");
1589 while (!feof(offline_file)) {
1590 skip_ws(offline_file);
1591 n = fscanf(offline_file,
"%d", &begin_cpu);
1594 skip_ws(offline_file);
1595 int c = fgetc(offline_file);
1596 if (c == EOF || c ==
',') {
1598 end_cpu = begin_cpu;
1599 }
else if (c ==
'-') {
1601 skip_ws(offline_file);
1602 n = fscanf(offline_file,
"%d", &end_cpu);
1605 skip_ws(offline_file);
1606 c = fgetc(offline_file);
1612 if (begin_cpu < 0 || begin_cpu >=
__kmp_xproc || end_cpu < 0 ||
1617 for (
int cpu = begin_cpu; cpu <= end_cpu; ++cpu) {
1618 KMP_CPU_SET(cpu, offline);
1626int __kmp_affinity_entire_machine_mask(kmp_affin_mask_t *
mask) {
1630#if KMP_GROUP_AFFINITY
1632 if (__kmp_num_proc_groups > 1) {
1635 for (group = 0; group < __kmp_num_proc_groups; group++) {
1637 int num = __kmp_GetActiveProcessorCount(group);
1638 for (
i = 0;
i < num;
i++) {
1639 KMP_CPU_SET(
i + group * (CHAR_BIT *
sizeof(DWORD_PTR)),
mask);
1649 kmp_affin_mask_t *offline_cpus = __kmp_affinity_get_offline_cpus();
1652 if (KMP_CPU_ISSET(proc, offline_cpus))
1654 KMP_CPU_SET(proc,
mask);
1657 KMP_CPU_FREE(offline_cpus);
1666kmp_affin_mask_t *__kmp_affin_fullMask = NULL;
1668kmp_affin_mask_t *__kmp_affin_origMask = NULL;
1671static inline bool __kmp_hwloc_is_cache_type(hwloc_obj_t obj) {
1672#if HWLOC_API_VERSION >= 0x00020000
1673 return hwloc_obj_type_is_cache(obj->type);
1675 return obj->type == HWLOC_OBJ_CACHE;
1680static inline kmp_hw_t __kmp_hwloc_type_2_topology_type(hwloc_obj_t obj) {
1682 if (__kmp_hwloc_is_cache_type(obj)) {
1683 if (obj->attr->cache.type == HWLOC_OBJ_CACHE_INSTRUCTION)
1685 switch (obj->attr->cache.depth) {
1689#if KMP_MIC_SUPPORTED
1690 if (__kmp_mic_type == mic3) {
1701 switch (obj->type) {
1702 case HWLOC_OBJ_PACKAGE:
1704 case HWLOC_OBJ_NUMANODE:
1706 case HWLOC_OBJ_CORE:
1710 case HWLOC_OBJ_GROUP:
1711#if HWLOC_API_VERSION >= 0x00020000
1712 if (obj->attr->group.kind == HWLOC_GROUP_KIND_INTEL_DIE)
1714 else if (obj->attr->group.kind == HWLOC_GROUP_KIND_INTEL_TILE)
1716 else if (obj->attr->group.kind == HWLOC_GROUP_KIND_INTEL_MODULE)
1718 else if (obj->attr->group.kind == HWLOC_GROUP_KIND_WINDOWS_PROCESSOR_GROUP)
1722#if HWLOC_API_VERSION >= 0x00020100
1734static int __kmp_hwloc_get_nobjs_under_obj(hwloc_obj_t obj,
1735 hwloc_obj_type_t
type) {
1738 for (first = hwloc_get_obj_below_by_type(__kmp_hwloc_topology, obj->type,
1739 obj->logical_index,
type, 0);
1740 first != NULL && hwloc_get_ancestor_obj_by_type(__kmp_hwloc_topology,
1741 obj->type, first) == obj;
1742 first = hwloc_get_next_obj_by_type(__kmp_hwloc_topology, first->type,
1751static int __kmp_hwloc_get_sub_id(hwloc_topology_t t, hwloc_obj_t higher,
1752 hwloc_obj_t lower) {
1754 hwloc_obj_type_t ltype = lower->type;
1755 int lindex = lower->logical_index - 1;
1758 obj = hwloc_get_obj_by_type(t, ltype, lindex);
1759 while (obj && lindex >= 0 &&
1760 hwloc_bitmap_isincluded(obj->cpuset, higher->cpuset)) {
1761 if (obj->userdata) {
1767 obj = hwloc_get_obj_by_type(t, ltype, lindex);
1770 lower->userdata =
RCAST(
void *, sub_id + 1);
1774static bool __kmp_affinity_create_hwloc_map(kmp_i18n_id_t *
const msg_id) {
1776 int hw_thread_index, sub_id;
1778 hwloc_obj_t pu, obj, root, prev;
1782 hwloc_topology_t tp = __kmp_hwloc_topology;
1783 *msg_id = kmp_i18n_null;
1784 if (__kmp_affinity.flags.verbose) {
1788 if (!KMP_AFFINITY_CAPABLE()) {
1791 KMP_ASSERT(__kmp_affinity.type == affinity_none);
1793 hwloc_obj_t o = hwloc_get_obj_by_type(tp, HWLOC_OBJ_PACKAGE, 0);
1795 nCoresPerPkg = __kmp_hwloc_get_nobjs_under_obj(o, HWLOC_OBJ_CORE);
1798 o = hwloc_get_obj_by_type(tp, HWLOC_OBJ_CORE, 0);
1812#if HWLOC_API_VERSION >= 0x00020400
1814 int nr_cpu_kinds = hwloc_cpukinds_get_nr(tp, 0);
1816 typedef struct kmp_hwloc_cpukinds_info_t {
1819 hwloc_bitmap_t
mask;
1820 } kmp_hwloc_cpukinds_info_t;
1821 kmp_hwloc_cpukinds_info_t *cpukinds =
nullptr;
1823 if (nr_cpu_kinds > 0) {
1825 struct hwloc_info_s *infos;
1827 sizeof(kmp_hwloc_cpukinds_info_t) * nr_cpu_kinds);
1828 for (
unsigned idx = 0; idx < (unsigned)nr_cpu_kinds; ++idx) {
1829 cpukinds[idx].efficiency = -1;
1831 cpukinds[idx].mask = hwloc_bitmap_alloc();
1832 if (hwloc_cpukinds_get_info(tp, idx, cpukinds[idx].
mask,
1833 &cpukinds[idx].efficiency, &nr_infos, &infos,
1835 for (
unsigned i = 0;
i < nr_infos; ++
i) {
1837#if KMP_ARCH_X86 || KMP_ARCH_X86_64
1839 cpukinds[idx].core_type = KMP_HW_CORE_TYPE_ATOM;
1842 cpukinds[idx].core_type = KMP_HW_CORE_TYPE_CORE;
1853 root = hwloc_get_root_obj(tp);
1857 obj = hwloc_get_pu_obj_by_os_index(tp, __kmp_affin_fullMask->begin());
1858 while (obj && obj != root) {
1859#if HWLOC_API_VERSION >= 0x00020000
1860 if (obj->memory_arity) {
1862 for (memory = obj->memory_first_child; memory;
1863 memory = hwloc_get_next_child(tp, obj, memory)) {
1864 if (memory->type == HWLOC_OBJ_NUMANODE)
1867 if (memory && memory->type == HWLOC_OBJ_NUMANODE) {
1869 hwloc_types[depth] = memory->type;
1874 type = __kmp_hwloc_type_2_topology_type(obj);
1876 types[depth] =
type;
1877 hwloc_types[depth] = obj->type;
1885 for (
int i = 0,
j = depth - 1;
i <
j; ++
i, --
j) {
1886 hwloc_obj_type_t hwloc_temp = hwloc_types[
i];
1888 types[
i] = types[
j];
1890 hwloc_types[
i] = hwloc_types[
j];
1891 hwloc_types[
j] = hwloc_temp;
1897 hw_thread_index = 0;
1899 while ((pu = hwloc_get_next_obj_by_type(tp, HWLOC_OBJ_PU, pu))) {
1900 int index = depth - 1;
1901 bool included = KMP_CPU_ISSET(pu->os_index, __kmp_affin_fullMask);
1905 hw_thread.
ids[index] = pu->logical_index;
1906 hw_thread.
os_id = pu->os_index;
1908#if HWLOC_API_VERSION >= 0x00020400
1910 int cpukind_index = -1;
1911 for (
int i = 0;
i < nr_cpu_kinds; ++
i) {
1912 if (hwloc_bitmap_isset(cpukinds[
i].
mask, hw_thread.
os_id)) {
1917 if (cpukind_index >= 0) {
1927 while (obj != root && obj != NULL) {
1929#if HWLOC_API_VERSION >= 0x00020000
1933 if (obj->memory_arity) {
1935 for (memory = obj->memory_first_child; memory;
1936 memory = hwloc_get_next_child(tp, obj, memory)) {
1937 if (memory->type == HWLOC_OBJ_NUMANODE)
1940 if (memory && memory->type == HWLOC_OBJ_NUMANODE) {
1941 sub_id = __kmp_hwloc_get_sub_id(tp, memory, prev);
1943 hw_thread.
ids[index] = memory->logical_index;
1944 hw_thread.
ids[index + 1] = sub_id;
1952 type = __kmp_hwloc_type_2_topology_type(obj);
1954 sub_id = __kmp_hwloc_get_sub_id(tp, obj, prev);
1956 hw_thread.
ids[index] = obj->logical_index;
1957 hw_thread.
ids[index + 1] = sub_id;
1967#if HWLOC_API_VERSION >= 0x00020400
1970 for (
int idx = 0; idx < nr_cpu_kinds; ++idx)
1971 hwloc_bitmap_free(cpukinds[idx].
mask);
1983static bool __kmp_affinity_create_flat_map(kmp_i18n_id_t *
const msg_id) {
1984 *msg_id = kmp_i18n_null;
1988 if (__kmp_affinity.flags.verbose) {
1995 if (!KMP_AFFINITY_CAPABLE()) {
1996 KMP_ASSERT(__kmp_affinity.type == affinity_none);
2013 KMP_CPU_SET_ITERATE(
i, __kmp_affin_fullMask) {
2015 if (!KMP_CPU_ISSET(
i, __kmp_affin_fullMask)) {
2021 hw_thread.
ids[0] =
i;
2022 hw_thread.
ids[1] = 0;
2023 hw_thread.
ids[2] = 0;
2026 if (__kmp_affinity.flags.verbose) {
2032#if KMP_GROUP_AFFINITY
2037static bool __kmp_affinity_create_proc_group_map(kmp_i18n_id_t *
const msg_id) {
2038 *msg_id = kmp_i18n_null;
2041 const static size_t BITS_PER_GROUP = CHAR_BIT *
sizeof(DWORD_PTR);
2043 if (__kmp_affinity.flags.verbose) {
2044 KMP_INFORM(AffWindowsProcGroupMap,
"KMP_AFFINITY");
2048 if (!KMP_AFFINITY_CAPABLE()) {
2049 KMP_ASSERT(__kmp_affinity.type == affinity_none);
2061 KMP_CPU_SET_ITERATE(
i, __kmp_affin_fullMask) {
2063 if (!KMP_CPU_ISSET(
i, __kmp_affin_fullMask)) {
2069 hw_thread.
ids[0] =
i / BITS_PER_GROUP;
2070 hw_thread.
ids[1] = hw_thread.
ids[2] =
i % BITS_PER_GROUP;
2076#if KMP_ARCH_X86 || KMP_ARCH_X86_64
2078template <kmp_u
int32 LSB, kmp_u
int32 MSB>
2079static inline unsigned __kmp_extract_bits(
kmp_uint32 v) {
2083 retval <<= SHIFT_LEFT;
2084 retval >>= (SHIFT_LEFT + SHIFT_RIGHT);
2088static int __kmp_cpuid_mask_width(
int count) {
2096class apicThreadInfo {
2100 unsigned maxCoresPerPkg;
2101 unsigned maxThreadsPerPkg;
2107static int __kmp_affinity_cmp_apicThreadInfo_phys_id(
const void *
a,
2109 const apicThreadInfo *aa = (
const apicThreadInfo *)
a;
2110 const apicThreadInfo *bb = (
const apicThreadInfo *)
b;
2111 if (aa->pkgId < bb->pkgId)
2113 if (aa->pkgId > bb->pkgId)
2115 if (aa->coreId < bb->coreId)
2117 if (aa->coreId > bb->coreId)
2119 if (aa->threadId < bb->threadId)
2121 if (aa->threadId > bb->threadId)
2126class kmp_cache_info_t {
2131 kmp_cache_info_t() : depth(0) { get_leaf4_levels(); }
2132 size_t get_depth()
const {
return depth; }
2133 info_t &operator[](
size_t index) {
return table[index]; }
2134 const info_t &operator[](
size_t index)
const {
return table[index]; }
2150 static const int MAX_CACHE_LEVEL = 3;
2153 info_t table[MAX_CACHE_LEVEL];
2155 void get_leaf4_levels() {
2157 while (depth < MAX_CACHE_LEVEL) {
2158 unsigned cache_type, max_threads_sharing;
2159 unsigned cache_level, cache_mask_width;
2161 __kmp_x86_cpuid(4,
level, &buf2);
2162 cache_type = __kmp_extract_bits<0, 4>(buf2.eax);
2166 if (cache_type == 2) {
2170 max_threads_sharing = __kmp_extract_bits<14, 25>(buf2.eax) + 1;
2171 cache_mask_width = __kmp_cpuid_mask_width(max_threads_sharing);
2172 cache_level = __kmp_extract_bits<5, 7>(buf2.eax);
2173 table[depth].level = cache_level;
2174 table[depth].mask = ((-1) << cache_mask_width);
2185static bool __kmp_affinity_create_apicid_map(kmp_i18n_id_t *
const msg_id) {
2187 *msg_id = kmp_i18n_null;
2189 if (__kmp_affinity.flags.verbose) {
2194 __kmp_x86_cpuid(0, 0, &
buf);
2196 *msg_id = kmp_i18n_str_NoLeaf4Support;
2205 if (!KMP_AFFINITY_CAPABLE()) {
2208 KMP_ASSERT(__kmp_affinity.type == affinity_none);
2214 __kmp_x86_cpuid(1, 0, &
buf);
2215 int maxThreadsPerPkg = (
buf.ebx >> 16) & 0xff;
2216 if (maxThreadsPerPkg == 0) {
2217 maxThreadsPerPkg = 1;
2231 __kmp_x86_cpuid(0, 0, &
buf);
2233 __kmp_x86_cpuid(4, 0, &
buf);
2263 kmp_affinity_raii_t previous_affinity;
2293 unsigned nApics = 0;
2294 KMP_CPU_SET_ITERATE(
i, __kmp_affin_fullMask) {
2296 if (!KMP_CPU_ISSET(
i, __kmp_affin_fullMask)) {
2301 __kmp_affinity_dispatch->bind_thread(
i);
2302 threadInfo[nApics].osId =
i;
2305 __kmp_x86_cpuid(1, 0, &
buf);
2306 if (((
buf.edx >> 9) & 1) == 0) {
2308 *msg_id = kmp_i18n_str_ApicNotPresent;
2311 threadInfo[nApics].apicId = (
buf.ebx >> 24) & 0xff;
2312 threadInfo[nApics].maxThreadsPerPkg = (
buf.ebx >> 16) & 0xff;
2313 if (threadInfo[nApics].maxThreadsPerPkg == 0) {
2314 threadInfo[nApics].maxThreadsPerPkg = 1;
2323 __kmp_x86_cpuid(0, 0, &
buf);
2325 __kmp_x86_cpuid(4, 0, &
buf);
2326 threadInfo[nApics].maxCoresPerPkg = ((
buf.eax >> 26) & 0x3f) + 1;
2328 threadInfo[nApics].maxCoresPerPkg = 1;
2332 int widthCT = __kmp_cpuid_mask_width(threadInfo[nApics].maxThreadsPerPkg);
2333 threadInfo[nApics].pkgId = threadInfo[nApics].apicId >> widthCT;
2335 int widthC = __kmp_cpuid_mask_width(threadInfo[nApics].maxCoresPerPkg);
2336 int widthT = widthCT - widthC;
2342 *msg_id = kmp_i18n_str_InvalidCpuidInfo;
2346 int maskC = (1 << widthC) - 1;
2347 threadInfo[nApics].coreId = (threadInfo[nApics].apicId >> widthT) & maskC;
2349 int maskT = (1 << widthT) - 1;
2350 threadInfo[nApics].threadId = threadInfo[nApics].apicId & maskT;
2357 previous_affinity.restore();
2360 qsort(threadInfo, nApics,
sizeof(*threadInfo),
2361 __kmp_affinity_cmp_apicThreadInfo_phys_id);
2379 unsigned nCores = 1;
2382 unsigned lastPkgId = threadInfo[0].pkgId;
2383 unsigned coreCt = 1;
2384 unsigned lastCoreId = threadInfo[0].coreId;
2385 unsigned threadCt = 1;
2386 unsigned lastThreadId = threadInfo[0].threadId;
2389 unsigned prevMaxCoresPerPkg = threadInfo[0].maxCoresPerPkg;
2390 unsigned prevMaxThreadsPerPkg = threadInfo[0].maxThreadsPerPkg;
2392 for (
i = 1;
i < nApics;
i++) {
2393 if (threadInfo[
i].pkgId != lastPkgId) {
2396 lastPkgId = threadInfo[
i].pkgId;
2400 lastCoreId = threadInfo[
i].coreId;
2404 lastThreadId = threadInfo[
i].threadId;
2408 prevMaxCoresPerPkg = threadInfo[
i].maxCoresPerPkg;
2409 prevMaxThreadsPerPkg = threadInfo[
i].maxThreadsPerPkg;
2413 if (threadInfo[
i].coreId != lastCoreId) {
2416 lastCoreId = threadInfo[
i].coreId;
2420 lastThreadId = threadInfo[
i].threadId;
2421 }
else if (threadInfo[
i].threadId != lastThreadId) {
2423 lastThreadId = threadInfo[
i].threadId;
2426 *msg_id = kmp_i18n_str_LegacyApicIDsNotUnique;
2432 if ((prevMaxCoresPerPkg != threadInfo[
i].maxCoresPerPkg) ||
2433 (prevMaxThreadsPerPkg != threadInfo[
i].maxThreadsPerPkg)) {
2435 *msg_id = kmp_i18n_str_InconsistentCpuidInfo;
2456 int threadLevel = 2;
2458 int depth = (pkgLevel >= 0) + (coreLevel >= 0) + (threadLevel >= 0);
2464 if (threadLevel >= 0)
2470 for (
i = 0;
i < nApics; ++
i) {
2472 unsigned os = threadInfo[
i].osId;
2476 if (pkgLevel >= 0) {
2477 hw_thread.
ids[idx++] = threadInfo[
i].pkgId;
2479 if (coreLevel >= 0) {
2480 hw_thread.
ids[idx++] = threadInfo[
i].coreId;
2482 if (threadLevel >= 0) {
2483 hw_thread.
ids[idx++] = threadInfo[
i].threadId;
2485 hw_thread.
os_id = os;
2493 *msg_id = kmp_i18n_str_LegacyApicIDsNotUnique;
2502 unsigned *native_model_id) {
2504 __kmp_x86_cpuid(0x1a, 0, &
buf);
2507 case KMP_HW_CORE_TYPE_ATOM:
2510 case KMP_HW_CORE_TYPE_CORE:
2516 *native_model_id = __kmp_extract_bits<0, 23>(
buf.eax);
2538 INTEL_LEVEL_TYPE_INVALID = 0,
2539 INTEL_LEVEL_TYPE_SMT = 1,
2540 INTEL_LEVEL_TYPE_CORE = 2,
2541 INTEL_LEVEL_TYPE_MODULE = 3,
2542 INTEL_LEVEL_TYPE_TILE = 4,
2543 INTEL_LEVEL_TYPE_DIE = 5,
2544 INTEL_LEVEL_TYPE_LAST = 6,
2547struct cpuid_level_info_t {
2548 unsigned level_type,
mask, mask_width, nitems, cache_mask;
2551static kmp_hw_t __kmp_intel_type_2_topology_type(
int intel_type) {
2552 switch (intel_type) {
2553 case INTEL_LEVEL_TYPE_INVALID:
2555 case INTEL_LEVEL_TYPE_SMT:
2557 case INTEL_LEVEL_TYPE_CORE:
2559 case INTEL_LEVEL_TYPE_TILE:
2561 case INTEL_LEVEL_TYPE_MODULE:
2563 case INTEL_LEVEL_TYPE_DIE:
2573__kmp_x2apicid_get_levels(
int leaf,
2574 cpuid_level_info_t levels[INTEL_LEVEL_TYPE_LAST],
2576 unsigned level, levels_index;
2577 unsigned level_type, mask_width, nitems;
2587 level = levels_index = 0;
2589 __kmp_x86_cpuid(leaf,
level, &
buf);
2590 level_type = __kmp_extract_bits<8, 15>(
buf.ecx);
2591 mask_width = __kmp_extract_bits<0, 4>(
buf.eax);
2592 nitems = __kmp_extract_bits<0, 15>(
buf.ebx);
2593 if (level_type != INTEL_LEVEL_TYPE_INVALID && nitems == 0)
2596 if (known_levels & (1ull << level_type)) {
2598 KMP_ASSERT(levels_index < INTEL_LEVEL_TYPE_LAST);
2599 levels[levels_index].level_type = level_type;
2600 levels[levels_index].mask_width = mask_width;
2601 levels[levels_index].nitems = nitems;
2605 if (levels_index > 0) {
2606 levels[levels_index - 1].mask_width = mask_width;
2607 levels[levels_index - 1].nitems = nitems;
2611 }
while (level_type != INTEL_LEVEL_TYPE_INVALID);
2614 if (levels_index == 0 || levels[0].level_type == INTEL_LEVEL_TYPE_INVALID)
2618 for (
unsigned i = 0;
i < levels_index; ++
i) {
2619 if (levels[
i].level_type != INTEL_LEVEL_TYPE_INVALID) {
2620 levels[
i].mask = ~((-1) << levels[
i].mask_width);
2621 levels[
i].cache_mask = (-1) << levels[
i].mask_width;
2622 for (
unsigned j = 0;
j <
i; ++
j)
2626 levels[
i].mask = (-1) << levels[
i - 1].mask_width;
2627 levels[
i].cache_mask = 0;
2630 return levels_index;
2633static bool __kmp_affinity_create_x2apicid_map(kmp_i18n_id_t *
const msg_id) {
2635 cpuid_level_info_t levels[INTEL_LEVEL_TYPE_LAST];
2636 kmp_hw_t types[INTEL_LEVEL_TYPE_LAST];
2637 unsigned levels_index;
2640 int topology_leaf, highest_leaf, apic_id;
2642 static int leaves[] = {0, 0};
2644 kmp_i18n_id_t leaf_message_id;
2648 *msg_id = kmp_i18n_null;
2649 if (__kmp_affinity.flags.verbose) {
2654 known_levels = 0ull;
2655 for (
int i = 0;
i < INTEL_LEVEL_TYPE_LAST; ++
i) {
2657 known_levels |= (1ull <<
i);
2662 __kmp_x86_cpuid(0, 0, &
buf);
2663 highest_leaf =
buf.eax;
2668 if (__kmp_affinity_top_method == affinity_top_method_x2apicid) {
2671 leaf_message_id = kmp_i18n_str_NoLeaf11Support;
2672 }
else if (__kmp_affinity_top_method == affinity_top_method_x2apicid_1f) {
2675 leaf_message_id = kmp_i18n_str_NoLeaf31Support;
2680 leaf_message_id = kmp_i18n_str_NoLeaf11Support;
2686 for (
int i = 0;
i < num_leaves; ++
i) {
2687 int leaf = leaves[
i];
2688 if (highest_leaf < leaf)
2690 __kmp_x86_cpuid(leaf, 0, &
buf);
2693 topology_leaf = leaf;
2694 levels_index = __kmp_x2apicid_get_levels(leaf, levels, known_levels);
2695 if (levels_index == 0)
2699 if (topology_leaf == -1 || levels_index == 0) {
2700 *msg_id = leaf_message_id;
2703 KMP_ASSERT(levels_index <= INTEL_LEVEL_TYPE_LAST);
2710 if (!KMP_AFFINITY_CAPABLE()) {
2713 KMP_ASSERT(__kmp_affinity.type == affinity_none);
2714 for (
unsigned i = 0;
i < levels_index; ++
i) {
2715 if (levels[
i].level_type == INTEL_LEVEL_TYPE_SMT) {
2717 }
else if (levels[
i].level_type == INTEL_LEVEL_TYPE_CORE) {
2727 int depth = levels_index;
2728 for (
int i = depth - 1,
j = 0;
i >= 0; --
i, ++
j)
2729 types[
j] = __kmp_intel_type_2_topology_type(levels[
i].level_type);
2734 kmp_cache_info_t cache_info;
2735 for (
size_t i = 0;
i < cache_info.get_depth(); ++
i) {
2736 const kmp_cache_info_t::info_t &info = cache_info[
i];
2737 unsigned cache_mask = info.mask;
2738 unsigned cache_level = info.level;
2739 for (
unsigned j = 0;
j < levels_index; ++
j) {
2740 unsigned hw_cache_mask = levels[
j].cache_mask;
2741 kmp_hw_t cache_type = kmp_cache_info_t::get_topology_type(cache_level);
2742 if (hw_cache_mask == cache_mask &&
j < levels_index - 1) {
2744 __kmp_intel_type_2_topology_type(levels[
j + 1].level_type);
2755 kmp_affinity_raii_t previous_affinity;
2760 int hw_thread_index = 0;
2761 KMP_CPU_SET_ITERATE(proc, __kmp_affin_fullMask) {
2762 cpuid_level_info_t my_levels[INTEL_LEVEL_TYPE_LAST];
2763 unsigned my_levels_index;
2766 if (!KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) {
2771 __kmp_affinity_dispatch->bind_thread(proc);
2774 __kmp_x86_cpuid(topology_leaf, 0, &
buf);
2778 __kmp_x2apicid_get_levels(topology_leaf, my_levels, known_levels);
2779 if (my_levels_index == 0 || my_levels_index != levels_index) {
2780 *msg_id = kmp_i18n_str_InvalidCpuidInfo;
2784 hw_thread.
os_id = proc;
2786 for (
unsigned j = 0, idx = depth - 1;
j < my_levels_index; ++
j, --idx) {
2787 hw_thread.
ids[idx] = apic_id & my_levels[
j].mask;
2789 hw_thread.
ids[idx] >>= my_levels[
j - 1].mask_width;
2795 unsigned native_model_id;
2797 __kmp_get_hybrid_info(&
type, &efficiency, &native_model_id);
2808 *msg_id = kmp_i18n_str_x2ApicIDsNotUnique;
2816#define threadIdIndex 1
2817#define coreIdIndex 2
2819#define nodeIdIndex 4
2821typedef unsigned *ProcCpuInfo;
2822static unsigned maxIndex = pkgIdIndex;
2824static int __kmp_affinity_cmp_ProcCpuInfo_phys_id(
const void *
a,
2827 const unsigned *aa = *(
unsigned *
const *)
a;
2828 const unsigned *bb = *(
unsigned *
const *)
b;
2829 for (
i = maxIndex;;
i--) {
2840#if KMP_USE_HIER_SCHED
2842static void __kmp_dispatch_set_hierarchy_values() {
2851#if KMP_ARCH_X86_64 && \
2852 (KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
2853 KMP_OS_WINDOWS) && \
2855 if (__kmp_mic_type >= mic3)
2868#if KMP_ARCH_X86_64 && \
2869 (KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
2870 KMP_OS_WINDOWS) && \
2872 if (__kmp_mic_type >= mic3)
2890 int index =
type + 1;
2898 if (tid >= num_hw_threads)
2899 tid = tid % num_hw_threads;
2916static inline const char *__kmp_cpuinfo_get_filename() {
2917 const char *filename;
2918 if (__kmp_cpuinfo_file !=
nullptr)
2919 filename = __kmp_cpuinfo_file;
2921 filename =
"/proc/cpuinfo";
2925static inline const char *__kmp_cpuinfo_get_envvar() {
2926 const char *envvar =
nullptr;
2927 if (__kmp_cpuinfo_file !=
nullptr)
2928 envvar =
"KMP_CPUINFO_FILE";
2935static bool __kmp_affinity_create_cpuinfo_map(
int *line,
2936 kmp_i18n_id_t *
const msg_id) {
2937 *msg_id = kmp_i18n_null;
2942 const char *filename = __kmp_cpuinfo_get_filename();
2943 const char *envvar = __kmp_cpuinfo_get_envvar();
2945 if (__kmp_affinity.flags.verbose) {
2946 KMP_INFORM(AffParseFilename,
"KMP_AFFINITY", filename);
2954 unsigned num_records = 0;
2956 buf[
sizeof(
buf) - 1] = 1;
2957 if (!fgets(
buf,
sizeof(
buf),
f)) {
2962 char s1[] =
"processor";
2963 if (strncmp(
buf, s1,
sizeof(s1) - 1) == 0) {
2975 if (nodeIdIndex +
level >= maxIndex) {
2976 maxIndex = nodeIdIndex +
level;
2984 if (num_records == 0) {
2985 *msg_id = kmp_i18n_str_NoProcRecords;
2989 *msg_id = kmp_i18n_str_TooManyProcRecords;
2998 if (fseek(
f, 0, SEEK_SET) != 0) {
2999 *msg_id = kmp_i18n_str_CantRewindCpuinfo;
3006 unsigned **threadInfo =
3007 (
unsigned **)
__kmp_allocate((num_records + 1) *
sizeof(
unsigned *));
3009 for (
i = 0;
i <= num_records;
i++) {
3014#define CLEANUP_THREAD_INFO \
3015 for (i = 0; i <= num_records; i++) { \
3016 __kmp_free(threadInfo[i]); \
3018 __kmp_free(threadInfo);
3023#define INIT_PROC_INFO(p) \
3024 for (__index = 0; __index <= maxIndex; __index++) { \
3025 (p)[__index] = UINT_MAX; \
3028 for (
i = 0;
i <= num_records;
i++) {
3029 INIT_PROC_INFO(threadInfo[
i]);
3034 lpar_info_format1_t cpuinfo;
3037 if (__kmp_affinity.flags.verbose)
3038 KMP_INFORM(AffParseFilename,
"KMP_AFFINITY",
"system info for topology");
3041 smt_threads = syssmt(GET_NUMBER_SMT_SETS, 0, 0, NULL);
3044 rsethandle_t sys_rset = rs_alloc(RS_SYSTEM);
3045 if (sys_rset == NULL) {
3046 CLEANUP_THREAD_INFO;
3047 *msg_id = kmp_i18n_str_UnknownTopology;
3051 rsethandle_t srad = rs_alloc(RS_EMPTY);
3054 CLEANUP_THREAD_INFO;
3055 *msg_id = kmp_i18n_str_UnknownTopology;
3060 int sradsdl = rs_getinfo(NULL, R_SRADSDL, 0);
3064 CLEANUP_THREAD_INFO;
3065 *msg_id = kmp_i18n_str_UnknownTopology;
3069 int num_rads = rs_numrads(sys_rset, sradsdl, 0);
3073 CLEANUP_THREAD_INFO;
3074 *msg_id = kmp_i18n_str_UnknownTopology;
3079 int max_procs = rs_getinfo(NULL, R_MAXPROCS, 0);
3080 if (max_procs < 0) {
3083 CLEANUP_THREAD_INFO;
3084 *msg_id = kmp_i18n_str_UnknownTopology;
3090 for (
int srad_idx = 0; cur_rad < num_rads && srad_idx < VMI_MAXRADS;
3093 if (rs_getrad(sys_rset, srad, sradsdl, srad_idx, 0) < 0)
3096 for (
int cpu = 0; cpu < max_procs; cpu++) {
3098 if (rs_op(RS_TESTRESOURCE, srad, NULL, R_PROCS, cpu)) {
3099 threadInfo[cpu][osIdIndex] = cpu;
3100 threadInfo[cpu][pkgIdIndex] = cur_rad;
3101 threadInfo[cpu][coreIdIndex] = cpu / smt_threads;
3103 if (num_set >= num_avail) {
3117 unsigned num_avail = 0;
3120 bool reading_s390x_sys_info =
true;
3127 buf[
sizeof(
buf) - 1] = 1;
3128 bool long_line =
false;
3129 if (!fgets(
buf,
sizeof(
buf),
f)) {
3134 for (
i = 0;
i <= maxIndex;
i++) {
3135 if (threadInfo[num_avail][
i] != UINT_MAX) {
3143 }
else if (!
buf[
sizeof(
buf) - 1]) {
3150 CLEANUP_THREAD_INFO; \
3151 *msg_id = kmp_i18n_str_LongLineCpuinfo; \
3157#if KMP_ARCH_LOONGARCH64
3164 if (*
buf ==
'\n' && *line == 2)
3170 if (reading_s390x_sys_info) {
3172 reading_s390x_sys_info =
false;
3178 char s1[] =
"cpu number";
3180 char s1[] =
"processor";
3182 if (strncmp(
buf, s1,
sizeof(s1) - 1) == 0) {
3184 char *
p = strchr(
buf +
sizeof(s1) - 1,
':');
3188 if (threadInfo[num_avail][osIdIndex] != UINT_MAX)
3198 threadInfo[num_avail][osIdIndex] =
val;
3199#if KMP_OS_LINUX && !(KMP_ARCH_X86 || KMP_ARCH_X86_64)
3203 "/sys/devices/system/cpu/cpu%u/topology/physical_package_id",
3204 threadInfo[num_avail][osIdIndex]);
3211 "/sys/devices/system/cpu/cpu%u/topology/book_id",
3212 threadInfo[num_avail][osIdIndex]);
3214 threadInfo[num_avail][pkgIdIndex] |= (book_id << 8);
3218 "/sys/devices/system/cpu/cpu%u/topology/drawer_id",
3219 threadInfo[num_avail][osIdIndex]);
3221 threadInfo[num_avail][pkgIdIndex] |= (drawer_id << 16);
3225 "/sys/devices/system/cpu/cpu%u/topology/core_id",
3226 threadInfo[num_avail][osIdIndex]);
3231 char s2[] =
"physical id";
3232 if (strncmp(
buf, s2,
sizeof(s2) - 1) == 0) {
3234 char *
p = strchr(
buf +
sizeof(s2) - 1,
':');
3238 if (threadInfo[num_avail][pkgIdIndex] != UINT_MAX)
3240 threadInfo[num_avail][pkgIdIndex] =
val;
3243 char s3[] =
"core id";
3244 if (strncmp(
buf, s3,
sizeof(s3) - 1) == 0) {
3246 char *
p = strchr(
buf +
sizeof(s3) - 1,
':');
3250 if (threadInfo[num_avail][coreIdIndex] != UINT_MAX)
3252 threadInfo[num_avail][coreIdIndex] =
val;
3256 char s4[] =
"thread id";
3257 if (strncmp(
buf, s4,
sizeof(s4) - 1) == 0) {
3259 char *
p = strchr(
buf +
sizeof(s4) - 1,
':');
3263 if (threadInfo[num_avail][threadIdIndex] != UINT_MAX)
3265 threadInfo[num_avail][threadIdIndex] =
val;
3271 char *
p = strchr(
buf +
sizeof(s4) - 1,
':');
3279 if (threadInfo[num_avail][nodeIdIndex +
level] != UINT_MAX)
3281 threadInfo[num_avail][nodeIdIndex +
level] =
val;
3288 if ((*
buf != 0) && (*
buf !=
'\n')) {
3293 while (((ch = fgetc(
f)) != EOF) && (ch !=
'\n'))
3302 CLEANUP_THREAD_INFO;
3303 *msg_id = kmp_i18n_str_TooManyEntries;
3309 if (threadInfo[num_avail][osIdIndex] == UINT_MAX) {
3310 CLEANUP_THREAD_INFO;
3311 *msg_id = kmp_i18n_str_MissingProcField;
3314 if (threadInfo[0][pkgIdIndex] == UINT_MAX) {
3315 CLEANUP_THREAD_INFO;
3316 *msg_id = kmp_i18n_str_MissingPhysicalIDField;
3321 if (KMP_AFFINITY_CAPABLE() &&
3322 !KMP_CPU_ISSET(threadInfo[num_avail][osIdIndex],
3323 __kmp_affin_fullMask)) {
3324 INIT_PROC_INFO(threadInfo[num_avail]);
3332 INIT_PROC_INFO(threadInfo[num_avail]);
3337 CLEANUP_THREAD_INFO;
3338 *msg_id = kmp_i18n_str_MissingValCpuinfo;
3342 CLEANUP_THREAD_INFO;
3343 *msg_id = kmp_i18n_str_DuplicateFieldCpuinfo;
3348#if KMP_MIC && REDUCE_TEAM_SIZE
3349 unsigned teamSize = 0;
3361 qsort(threadInfo, num_avail,
sizeof(*threadInfo),
3362 __kmp_affinity_cmp_ProcCpuInfo_phys_id);
3384 bool assign_thread_ids =
false;
3385 unsigned threadIdCt;
3392 if (assign_thread_ids) {
3393 if (threadInfo[0][threadIdIndex] == UINT_MAX) {
3394 threadInfo[0][threadIdIndex] = threadIdCt++;
3395 }
else if (threadIdCt <= threadInfo[0][threadIdIndex]) {
3396 threadIdCt = threadInfo[0][threadIdIndex] + 1;
3399 for (index = 0; index <= maxIndex; index++) {
3403 lastId[index] = threadInfo[0][index];
3408 for (
i = 1;
i < num_avail;
i++) {
3411 for (index = maxIndex; index >= threadIdIndex; index--) {
3412 if (assign_thread_ids && (index == threadIdIndex)) {
3414 if (threadInfo[
i][threadIdIndex] == UINT_MAX) {
3415 threadInfo[
i][threadIdIndex] = threadIdCt++;
3419 else if (threadIdCt <= threadInfo[
i][threadIdIndex]) {
3420 threadIdCt = threadInfo[
i][threadIdIndex] + 1;
3423 if (threadInfo[
i][index] != lastId[index]) {
3428 for (index2 = threadIdIndex; index2 < index; index2++) {
3430 if (counts[index2] > maxCt[index2]) {
3431 maxCt[index2] = counts[index2];
3434 lastId[index2] = threadInfo[
i][index2];
3438 lastId[index] = threadInfo[
i][index];
3440 if (assign_thread_ids && (index > threadIdIndex)) {
3442#if KMP_MIC && REDUCE_TEAM_SIZE
3445 teamSize += (threadIdCt <= 2) ? (threadIdCt) : (threadIdCt - 1);
3452 if (threadInfo[
i][threadIdIndex] == UINT_MAX) {
3453 threadInfo[
i][threadIdIndex] = threadIdCt++;
3459 else if (threadIdCt <= threadInfo[
i][threadIdIndex]) {
3460 threadIdCt = threadInfo[
i][threadIdIndex] + 1;
3466 if (index < threadIdIndex) {
3470 if ((threadInfo[
i][threadIdIndex] != UINT_MAX) || assign_thread_ids) {
3475 CLEANUP_THREAD_INFO;
3476 *msg_id = kmp_i18n_str_PhysicalIDsNotUnique;
3482 assign_thread_ids =
true;
3483 goto restart_radix_check;
3487#if KMP_MIC && REDUCE_TEAM_SIZE
3490 teamSize += (threadIdCt <= 2) ? (threadIdCt) : (threadIdCt - 1);
3493 for (index = threadIdIndex; index <= maxIndex; index++) {
3494 if (counts[index] > maxCt[index]) {
3495 maxCt[index] = counts[index];
3508 if (!KMP_AFFINITY_CAPABLE()) {
3509 KMP_ASSERT(__kmp_affinity.type == affinity_none);
3513#if KMP_MIC && REDUCE_TEAM_SIZE
3517 KA_TRACE(20, (
"__kmp_affinity_create_cpuinfo_map: setting "
3518 "__kmp_dflt_team_nth = %d\n",
3531 for (index = threadIdIndex; index < maxIndex; index++) {
3532 KMP_ASSERT(totals[index] >= totals[index + 1]);
3533 inMap[index] = (totals[index] > totals[index + 1]);
3535 inMap[maxIndex] = (totals[maxIndex] > 1);
3536 inMap[pkgIdIndex] =
true;
3537 inMap[coreIdIndex] =
true;
3538 inMap[threadIdIndex] =
true;
3545 int threadLevel = -1;
3546 for (index = threadIdIndex; index <= maxIndex; index++) {
3551 if (inMap[pkgIdIndex]) {
3555 if (inMap[coreIdIndex]) {
3559 if (inMap[threadIdIndex]) {
3568 for (
i = 0;
i < num_avail; ++
i) {
3569 unsigned os = threadInfo[
i][osIdIndex];
3573 hw_thread.
os_id = os;
3576 for (src_index = maxIndex; src_index >= threadIdIndex; src_index--) {
3577 if (!inMap[src_index]) {
3580 if (src_index == pkgIdIndex) {
3581 hw_thread.
ids[pkgLevel] = threadInfo[
i][src_index];
3582 }
else if (src_index == coreIdIndex) {
3583 hw_thread.
ids[coreLevel] = threadInfo[
i][src_index];
3584 }
else if (src_index == threadIdIndex) {
3585 hw_thread.
ids[threadLevel] = threadInfo[
i][src_index];
3595 CLEANUP_THREAD_INFO;
3600 *msg_id = kmp_i18n_str_PhysicalIDsNotUnique;
3609template <
typename FindNextFunctionType>
3610static void __kmp_create_os_id_masks(
unsigned *numUnique,
3611 kmp_affinity_t &affinity,
3612 FindNextFunctionType find_next) {
3618 const char *env_var = __kmp_get_affinity_env_var(affinity);
3629 for (
i = numAddrs - 1;; --
i) {
3631 if (osId > maxOsId) {
3637 affinity.num_os_id_masks = maxOsId + 1;
3638 KMP_CPU_ALLOC_ARRAY(affinity.os_id_masks, affinity.num_os_id_masks);
3640 if (affinity.flags.verbose && (affinity.gran_levels > 0)) {
3641 KMP_INFORM(ThreadsMigrate, env_var, affinity.gran_levels);
3643 if (affinity.gran_levels >= (
int)depth) {
3654 kmp_affin_mask_t *
sum;
3655 KMP_CPU_ALLOC_ON_STACK(
sum);
3658 i =
j = leader = find_next(-1);
3661 for (
i = find_next(
i);
i < numAddrs;
i = find_next(
i)) {
3672 for (;
j <
i;
j = find_next(
j)) {
3675 kmp_affin_mask_t *
mask = KMP_CPU_INDEX(affinity.os_id_masks, osId);
3690 for (;
j <
i;
j = find_next(
j)) {
3693 kmp_affin_mask_t *
mask = KMP_CPU_INDEX(affinity.os_id_masks, osId);
3699 KMP_CPU_FREE_FROM_STACK(
sum);
3702 if (
full_mask.restrict_to_mask() && affinity.flags.verbose) {
3706 *numUnique = unique;
3712static kmp_affin_mask_t *newMasks;
3713static int numNewMasks;
3714static int nextNewMask;
3716#define ADD_MASK(_mask) \
3718 if (nextNewMask >= numNewMasks) { \
3721 kmp_affin_mask_t *temp; \
3722 KMP_CPU_INTERNAL_ALLOC_ARRAY(temp, numNewMasks); \
3723 for (i = 0; i < numNewMasks / 2; i++) { \
3724 kmp_affin_mask_t *src = KMP_CPU_INDEX(newMasks, i); \
3725 kmp_affin_mask_t *dest = KMP_CPU_INDEX(temp, i); \
3726 KMP_CPU_COPY(dest, src); \
3728 KMP_CPU_INTERNAL_FREE_ARRAY(newMasks, numNewMasks / 2); \
3731 KMP_CPU_COPY(KMP_CPU_INDEX(newMasks, nextNewMask), (_mask)); \
3735#define ADD_MASK_OSID(_osId, _osId2Mask, _maxOsId) \
3737 if (((_osId) > _maxOsId) || \
3738 (!KMP_CPU_ISSET((_osId), KMP_CPU_INDEX((_osId2Mask), (_osId))))) { \
3739 KMP_AFF_WARNING(affinity, AffIgnoreInvalidProcID, _osId); \
3741 ADD_MASK(KMP_CPU_INDEX(_osId2Mask, (_osId))); \
3747static void __kmp_affinity_process_proclist(kmp_affinity_t &affinity) {
3749 kmp_affin_mask_t **out_masks = &affinity.masks;
3750 unsigned *out_numMasks = &affinity.num_masks;
3751 const char *proclist = affinity.proclist;
3752 kmp_affin_mask_t *osId2Mask = affinity.os_id_masks;
3753 int maxOsId = affinity.num_os_id_masks - 1;
3754 const char *scan = proclist;
3755 const char *next = proclist;
3760 KMP_CPU_INTERNAL_ALLOC_ARRAY(newMasks, numNewMasks);
3762 kmp_affin_mask_t *sumMask;
3763 KMP_CPU_ALLOC(sumMask);
3767 int start,
end, stride;
3771 if (*next ==
'\0') {
3783 KMP_ASSERT2((*next >=
'0') && (*next <=
'9'),
"bad proclist");
3789 if ((num > maxOsId) ||
3790 (!KMP_CPU_ISSET(num, KMP_CPU_INDEX(osId2Mask, num)))) {
3792 KMP_CPU_ZERO(sumMask);
3794 KMP_CPU_COPY(sumMask, KMP_CPU_INDEX(osId2Mask, num));
3814 KMP_ASSERT2((*next >=
'0') && (*next <=
'9'),
"bad explicit proc list");
3821 if ((num > maxOsId) ||
3822 (!KMP_CPU_ISSET(num, KMP_CPU_INDEX(osId2Mask, num)))) {
3825 KMP_CPU_UNION(sumMask, KMP_CPU_INDEX(osId2Mask, num));
3842 KMP_ASSERT2((*next >=
'0') && (*next <=
'9'),
"bad explicit proc list");
3845 KMP_ASSERT2(start >= 0,
"bad explicit proc list");
3850 ADD_MASK_OSID(start, osId2Mask, maxOsId);
3864 KMP_ASSERT2((*next >=
'0') && (*next <=
'9'),
"bad explicit proc list");
3884 KMP_ASSERT2((*next >=
'0') && (*next <=
'9'),
"bad explicit proc list");
3887 KMP_ASSERT2(stride >= 0,
"bad explicit proc list");
3892 KMP_ASSERT2(stride != 0,
"bad explicit proc list");
3898 KMP_ASSERT2((
end - start) / stride <= 65536,
"bad explicit proc list");
3903 ADD_MASK_OSID(start, osId2Mask, maxOsId);
3905 }
while (start <=
end);
3908 ADD_MASK_OSID(start, osId2Mask, maxOsId);
3910 }
while (start >=
end);
3921 *out_numMasks = nextNewMask;
3922 if (nextNewMask == 0) {
3924 KMP_CPU_INTERNAL_FREE_ARRAY(newMasks, numNewMasks);
3927 KMP_CPU_ALLOC_ARRAY((*out_masks), nextNewMask);
3928 for (
i = 0;
i < nextNewMask;
i++) {
3929 kmp_affin_mask_t *src = KMP_CPU_INDEX(newMasks,
i);
3930 kmp_affin_mask_t *
dest = KMP_CPU_INDEX((*out_masks),
i);
3931 KMP_CPU_COPY(dest, src);
3933 KMP_CPU_INTERNAL_FREE_ARRAY(newMasks, numNewMasks);
3934 KMP_CPU_FREE(sumMask);
3957static void __kmp_process_subplace_list(
const char **scan,
3958 kmp_affinity_t &affinity,
int maxOsId,
3959 kmp_affin_mask_t *tempMask,
3962 kmp_affin_mask_t *osId2Mask = affinity.os_id_masks;
3965 int start,
count, stride,
i;
3969 KMP_ASSERT2((**scan >=
'0') && (**scan <=
'9'),
"bad explicit places list");
3978 if (**scan ==
'}' || **scan ==
',') {
3979 if ((start > maxOsId) ||
3980 (!KMP_CPU_ISSET(start, KMP_CPU_INDEX(osId2Mask, start)))) {
3983 KMP_CPU_UNION(tempMask, KMP_CPU_INDEX(osId2Mask, start));
3986 if (**scan ==
'}') {
3992 KMP_ASSERT2(**scan ==
':',
"bad explicit places list");
3997 KMP_ASSERT2((**scan >=
'0') && (**scan <=
'9'),
"bad explicit places list");
4006 if (**scan ==
'}' || **scan ==
',') {
4008 if ((start > maxOsId) ||
4009 (!KMP_CPU_ISSET(start, KMP_CPU_INDEX(osId2Mask, start)))) {
4013 KMP_CPU_UNION(tempMask, KMP_CPU_INDEX(osId2Mask, start));
4018 if (**scan ==
'}') {
4024 KMP_ASSERT2(**scan ==
':',
"bad explicit places list");
4031 if (**scan ==
'+') {
4035 if (**scan ==
'-') {
4043 KMP_ASSERT2((**scan >=
'0') && (**scan <=
'9'),
"bad explicit places list");
4053 if (**scan ==
'}' || **scan ==
',') {
4055 if ((start > maxOsId) ||
4056 (!KMP_CPU_ISSET(start, KMP_CPU_INDEX(osId2Mask, start)))) {
4060 KMP_CPU_UNION(tempMask, KMP_CPU_INDEX(osId2Mask, start));
4065 if (**scan ==
'}') {
4076static void __kmp_process_place(
const char **scan, kmp_affinity_t &affinity,
4077 int maxOsId, kmp_affin_mask_t *tempMask,
4080 kmp_affin_mask_t *osId2Mask = affinity.os_id_masks;
4084 if (**scan ==
'{') {
4086 __kmp_process_subplace_list(scan, affinity, maxOsId, tempMask, setSize);
4087 KMP_ASSERT2(**scan ==
'}',
"bad explicit places list");
4089 }
else if (**scan ==
'!') {
4091 __kmp_process_place(scan, affinity, maxOsId, tempMask, setSize);
4092 KMP_CPU_COMPLEMENT(maxOsId, tempMask);
4093 }
else if ((**scan >=
'0') && (**scan <=
'9')) {
4098 if ((num > maxOsId) ||
4099 (!KMP_CPU_ISSET(num, KMP_CPU_INDEX(osId2Mask, num)))) {
4102 KMP_CPU_UNION(tempMask, KMP_CPU_INDEX(osId2Mask, num));
4112void __kmp_affinity_process_placelist(kmp_affinity_t &affinity) {
4113 int i,
j,
count, stride, sign;
4114 kmp_affin_mask_t **out_masks = &affinity.masks;
4115 unsigned *out_numMasks = &affinity.num_masks;
4116 const char *placelist = affinity.proclist;
4117 kmp_affin_mask_t *osId2Mask = affinity.os_id_masks;
4118 int maxOsId = affinity.num_os_id_masks - 1;
4119 const char *scan = placelist;
4120 const char *next = placelist;
4123 KMP_CPU_INTERNAL_ALLOC_ARRAY(newMasks, numNewMasks);
4129 kmp_affin_mask_t *tempMask;
4130 kmp_affin_mask_t *previousMask;
4131 KMP_CPU_ALLOC(tempMask);
4132 KMP_CPU_ZERO(tempMask);
4133 KMP_CPU_ALLOC(previousMask);
4134 KMP_CPU_ZERO(previousMask);
4138 __kmp_process_place(&scan, affinity, maxOsId, tempMask, &setSize);
4142 if (*scan ==
'\0' || *scan ==
',') {
4146 KMP_CPU_ZERO(tempMask);
4148 if (*scan ==
'\0') {
4155 KMP_ASSERT2(*scan ==
':',
"bad explicit places list");
4160 KMP_ASSERT2((*scan >=
'0') && (*scan <=
'9'),
"bad explicit places list");
4169 if (*scan ==
'\0' || *scan ==
',') {
4172 KMP_ASSERT2(*scan ==
':',
"bad explicit places list");
4191 KMP_ASSERT2((*scan >=
'0') && (*scan <=
'9'),
"bad explicit places list");
4206 KMP_CPU_COPY(previousMask, tempMask);
4207 ADD_MASK(previousMask);
4208 KMP_CPU_ZERO(tempMask);
4210 KMP_CPU_SET_ITERATE(
j, previousMask) {
4211 if (!KMP_CPU_ISSET(
j, previousMask)) {
4214 if ((
j + stride > maxOsId) || (
j + stride < 0) ||
4215 (!KMP_CPU_ISSET(
j, __kmp_affin_fullMask)) ||
4216 (!KMP_CPU_ISSET(
j + stride,
4217 KMP_CPU_INDEX(osId2Mask,
j + stride)))) {
4223 KMP_CPU_SET(
j + stride, tempMask);
4227 KMP_CPU_ZERO(tempMask);
4232 if (*scan ==
'\0') {
4243 *out_numMasks = nextNewMask;
4244 if (nextNewMask == 0) {
4246 KMP_CPU_INTERNAL_FREE_ARRAY(newMasks, numNewMasks);
4249 KMP_CPU_ALLOC_ARRAY((*out_masks), nextNewMask);
4250 KMP_CPU_FREE(tempMask);
4251 KMP_CPU_FREE(previousMask);
4252 for (
i = 0;
i < nextNewMask;
i++) {
4253 kmp_affin_mask_t *src = KMP_CPU_INDEX(newMasks,
i);
4254 kmp_affin_mask_t *
dest = KMP_CPU_INDEX((*out_masks),
i);
4255 KMP_CPU_COPY(dest, src);
4257 KMP_CPU_INTERNAL_FREE_ARRAY(newMasks, numNewMasks);
4265static int __kmp_affinity_find_core_level(
int nprocs,
int bottom_level) {
4268 for (
int i = 0;
i < nprocs;
i++) {
4270 for (
int j = bottom_level;
j > 0;
j--) {
4271 if (hw_thread.
ids[
j] > 0) {
4272 if (core_level < (
j - 1)) {
4282static int __kmp_affinity_compute_ncores(
int nprocs,
int bottom_level,
4287static int __kmp_affinity_find_core(
int proc,
int bottom_level,
4290 KMP_DEBUG_ASSERT(proc >= 0 && proc < __kmp_topology->get_num_hw_threads());
4291 for (
int i = 0;
i <= proc; ++
i) {
4292 if (
i + 1 <= proc) {
4293 for (
int j = 0;
j <= core_level; ++
j) {
4307static int __kmp_affinity_max_proc_per_core(
int nprocs,
int bottom_level,
4309 if (core_level >= bottom_level)
4315static int *procarr = NULL;
4316static int __kmp_aff_depth = 0;
4317static int *__kmp_osid_to_hwthread_map = NULL;
4319static void __kmp_affinity_get_mask_topology_info(
const kmp_affin_mask_t *
mask,
4320 kmp_affinity_ids_t &ids,
4321 kmp_affinity_attrs_t &attrs) {
4322 if (!KMP_AFFINITY_CAPABLE())
4328 attrs = KMP_AFFINITY_ATTRS_UNKNOWN;
4334 KMP_CPU_SET_ITERATE(cpu,
mask) {
4335 int osid_idx = __kmp_osid_to_hwthread_map[cpu];
4367static void __kmp_affinity_get_thread_topology_info(
kmp_info_t *th) {
4368 if (!KMP_AFFINITY_CAPABLE())
4370 const kmp_affin_mask_t *
mask = th->th.th_affin_mask;
4371 kmp_affinity_ids_t &ids = th->th.th_topology_ids;
4372 kmp_affinity_attrs_t &attrs = th->th.th_topology_attrs;
4373 __kmp_affinity_get_mask_topology_info(
mask, ids, attrs);
4379static void __kmp_affinity_get_topology_info(kmp_affinity_t &affinity) {
4380 if (!KMP_AFFINITY_CAPABLE())
4382 if (affinity.type != affinity_none) {
4390 int max_cpu = __kmp_affin_fullMask->get_max_cpu();
4394 if (!affinity.ids) {
4396 sizeof(kmp_affinity_ids_t) * affinity.num_masks);
4398 if (!affinity.attrs) {
4400 sizeof(kmp_affinity_attrs_t) * affinity.num_masks);
4402 if (!__kmp_osid_to_hwthread_map) {
4404 __kmp_osid_to_hwthread_map =
4409 for (
int hw_thread = 0; hw_thread < num_hw_threads; ++hw_thread) {
4411 if (KMP_CPU_ISSET(os_id, __kmp_affin_fullMask))
4412 __kmp_osid_to_hwthread_map[os_id] = hw_thread;
4415 for (
unsigned i = 0;
i < affinity.num_masks; ++
i) {
4416 kmp_affinity_ids_t &ids = affinity.ids[
i];
4417 kmp_affinity_attrs_t &attrs = affinity.attrs[
i];
4418 kmp_affin_mask_t *
mask = KMP_CPU_INDEX(affinity.masks,
i);
4419 __kmp_affinity_get_mask_topology_info(
mask, ids, attrs);
4424static void __kmp_aux_affinity_initialize_other_data(kmp_affinity_t &affinity) {
4428 __kmp_affinity_get_topology_info(affinity);
4429#if KMP_WEIGHTED_ITERATIONS_SUPPORTED
4430 __kmp_first_osid_with_ecore = __kmp_get_first_osid_with_ecore();
4437static void __kmp_create_affinity_none_places(kmp_affinity_t &affinity) {
4441 affinity.num_masks = 1;
4442 KMP_CPU_ALLOC_ARRAY(affinity.masks, affinity.num_masks);
4443 kmp_affin_mask_t *
dest = KMP_CPU_INDEX(affinity.masks, 0);
4444 KMP_CPU_COPY(dest, __kmp_affin_fullMask);
4445 __kmp_aux_affinity_initialize_other_data(affinity);
4448static void __kmp_aux_affinity_initialize_masks(kmp_affinity_t &affinity) {
4453 int verbose = affinity.flags.verbose;
4454 const char *env_var = affinity.env_var;
4457 if (__kmp_affin_fullMask && __kmp_affin_origMask)
4460 if (__kmp_affin_fullMask == NULL) {
4461 KMP_CPU_ALLOC(__kmp_affin_fullMask);
4463 if (__kmp_affin_origMask == NULL) {
4464 KMP_CPU_ALLOC(__kmp_affin_origMask);
4466 if (KMP_AFFINITY_CAPABLE()) {
4467 __kmp_get_system_affinity(__kmp_affin_fullMask,
TRUE);
4469 __kmp_affin_origMask->copy(__kmp_affin_fullMask);
4470 if (affinity.flags.respect) {
4474 KMP_CPU_SET_ITERATE(
i, __kmp_affin_fullMask) {
4475 if (!KMP_CPU_ISSET(
i, __kmp_affin_fullMask)) {
4482 affinity.type = affinity_none;
4483 KMP_AFFINITY_DISABLE();
4488 char buf[KMP_AFFIN_MASK_PRINT_LEN];
4489 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
4490 __kmp_affin_fullMask);
4495 char buf[KMP_AFFIN_MASK_PRINT_LEN];
4496 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
4497 __kmp_affin_fullMask);
4501 __kmp_affinity_entire_machine_mask(__kmp_affin_fullMask);
4503 if (__kmp_num_proc_groups <= 1) {
4505 __kmp_affin_origMask->copy(__kmp_affin_fullMask);
4509 __kmp_affin_fullMask->set_process_affinity(
true);
4515static bool __kmp_aux_affinity_initialize_topology(kmp_affinity_t &affinity) {
4516 bool success =
false;
4517 const char *env_var = affinity.env_var;
4518 kmp_i18n_id_t msg_id = kmp_i18n_null;
4519 int verbose = affinity.flags.verbose;
4523 if ((__kmp_cpuinfo_file != NULL) &&
4524 (__kmp_affinity_top_method == affinity_top_method_all)) {
4525 __kmp_affinity_top_method = affinity_top_method_cpuinfo;
4528 if (__kmp_affinity_top_method == affinity_top_method_all) {
4534 __kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC) {
4535 if (!__kmp_hwloc_error) {
4536 success = __kmp_affinity_create_hwloc_map(&msg_id);
4537 if (!success && verbose) {
4540 }
else if (verbose) {
4546#if KMP_ARCH_X86 || KMP_ARCH_X86_64
4548 success = __kmp_affinity_create_x2apicid_map(&msg_id);
4549 if (!success && verbose && msg_id != kmp_i18n_null) {
4554 success = __kmp_affinity_create_apicid_map(&msg_id);
4555 if (!success && verbose && msg_id != kmp_i18n_null) {
4561#if KMP_OS_LINUX || KMP_OS_AIX
4564 success = __kmp_affinity_create_cpuinfo_map(&line, &msg_id);
4565 if (!success && verbose && msg_id != kmp_i18n_null) {
4571#if KMP_GROUP_AFFINITY
4572 if (!success && (__kmp_num_proc_groups > 1)) {
4573 success = __kmp_affinity_create_proc_group_map(&msg_id);
4574 if (!success && verbose && msg_id != kmp_i18n_null) {
4581 success = __kmp_affinity_create_flat_map(&msg_id);
4582 if (!success && verbose && msg_id != kmp_i18n_null) {
4593 else if (__kmp_affinity_top_method == affinity_top_method_hwloc) {
4594 KMP_ASSERT(__kmp_affinity_dispatch->get_api_type() == KMPAffinity::HWLOC);
4595 success = __kmp_affinity_create_hwloc_map(&msg_id);
4603#if KMP_ARCH_X86 || KMP_ARCH_X86_64
4604 else if (__kmp_affinity_top_method == affinity_top_method_x2apicid ||
4605 __kmp_affinity_top_method == affinity_top_method_x2apicid_1f) {
4606 success = __kmp_affinity_create_x2apicid_map(&msg_id);
4611 }
else if (__kmp_affinity_top_method == affinity_top_method_apicid) {
4612 success = __kmp_affinity_create_apicid_map(&msg_id);
4620 else if (__kmp_affinity_top_method == affinity_top_method_cpuinfo) {
4622 success = __kmp_affinity_create_cpuinfo_map(&line, &msg_id);
4625 const char *filename = __kmp_cpuinfo_get_filename();
4627 KMP_FATAL(FileLineMsgExiting, filename, line,
4635#if KMP_GROUP_AFFINITY
4636 else if (__kmp_affinity_top_method == affinity_top_method_group) {
4637 success = __kmp_affinity_create_proc_group_map(&msg_id);
4646 else if (__kmp_affinity_top_method == affinity_top_method_flat) {
4647 success = __kmp_affinity_create_flat_map(&msg_id);
4654 if (KMP_AFFINITY_CAPABLE()) {
4674 if (filtered && verbose)
4679static void __kmp_aux_affinity_initialize(kmp_affinity_t &affinity) {
4680 bool is_regular_affinity = (&affinity == &__kmp_affinity);
4681 bool is_hidden_helper_affinity = (&affinity == &__kmp_hh_affinity);
4682 const char *env_var = __kmp_get_affinity_env_var(affinity);
4684 if (affinity.flags.initialized) {
4689 if (is_regular_affinity && (!__kmp_affin_fullMask || !__kmp_affin_origMask))
4690 __kmp_aux_affinity_initialize_masks(affinity);
4693 bool success = __kmp_aux_affinity_initialize_topology(affinity);
4697 affinity.type = affinity_none;
4698 KMP_AFFINITY_DISABLE();
4705 if (affinity.type == affinity_none) {
4706 __kmp_create_affinity_none_places(affinity);
4707#if KMP_USE_HIER_SCHED
4708 __kmp_dispatch_set_hierarchy_values();
4710 affinity.flags.initialized =
TRUE;
4722 if (affinity.core_attr_gran.valid) {
4723 __kmp_create_os_id_masks(&numUnique, affinity, [&](
int idx) {
4725 for (
int i = idx + 1;
i < numAddrs; ++
i)
4730 if (!affinity.os_id_masks) {
4731 const char *core_attribute;
4733 core_attribute =
"core_efficiency";
4735 core_attribute =
"core_type";
4743 if (!affinity.os_id_masks) {
4744 __kmp_create_os_id_masks(&numUnique, affinity, [](
int idx) {
4749 if (affinity.gran_levels == 0) {
4753 switch (affinity.type) {
4755 case affinity_explicit:
4757 if (is_hidden_helper_affinity ||
4759 __kmp_affinity_process_proclist(affinity);
4761 __kmp_affinity_process_placelist(affinity);
4763 if (affinity.num_masks == 0) {
4765 affinity.type = affinity_none;
4766 __kmp_create_affinity_none_places(affinity);
4767 affinity.flags.initialized =
TRUE;
4776 case affinity_logical:
4777 affinity.compact = 0;
4778 if (affinity.offset) {
4784 case affinity_physical:
4786 affinity.compact = 1;
4787 if (affinity.compact >= depth) {
4788 affinity.compact = 0;
4791 affinity.compact = 0;
4793 if (affinity.offset) {
4799 case affinity_scatter:
4800 if (affinity.compact >= depth) {
4801 affinity.compact = 0;
4803 affinity.compact = depth - 1 - affinity.compact;
4807 case affinity_compact:
4808 if (affinity.compact >= depth) {
4809 affinity.compact = depth - 1;
4813 case affinity_balanced:
4814 if (depth <= 1 || is_hidden_helper_affinity) {
4816 affinity.type = affinity_none;
4817 __kmp_create_affinity_none_places(affinity);
4818 affinity.flags.initialized =
TRUE;
4822 __kmp_aff_depth = depth;
4828 int maxprocpercore = __kmp_affinity_max_proc_per_core(
4831 int nproc = ncores * maxprocpercore;
4834 affinity.type = affinity_none;
4835 __kmp_create_affinity_none_places(affinity);
4836 affinity.flags.initialized =
TRUE;
4841 for (
int i = 0;
i < nproc;
i++) {
4849 int core = __kmp_affinity_find_core(
i, depth - 1, core_level);
4851 if (core == lastcore) {
4858 procarr[core * maxprocpercore + inlastcore] = proc;
4861 if (affinity.compact >= depth) {
4862 affinity.compact = depth - 1;
4867 if (affinity.flags.dups) {
4870 affinity.num_masks = numUnique;
4876 !is_hidden_helper_affinity) {
4880 KMP_CPU_ALLOC_ARRAY(affinity.masks, affinity.num_masks);
4890 for (
i = 0,
j = 0;
i < num_hw_threads;
i++) {
4896 kmp_affin_mask_t *src = KMP_CPU_INDEX(affinity.os_id_masks, osId);
4897 kmp_affin_mask_t *
dest = KMP_CPU_INDEX(affinity.masks,
j);
4899 KMP_CPU_COPY(dest, src);
4901 if (++
j >= affinity.num_masks) {
4907 if (
full_mask.restrict_to_mask() && affinity.flags.verbose) {
4918 __kmp_aux_affinity_initialize_other_data(affinity);
4919 affinity.flags.initialized =
TRUE;
4922void __kmp_affinity_initialize(kmp_affinity_t &affinity) {
4931 int disabled = (affinity.type == affinity_disabled);
4932 if (!KMP_AFFINITY_CAPABLE())
4935 affinity.type = affinity_none;
4936 __kmp_aux_affinity_initialize(affinity);
4938 affinity.type = affinity_disabled;
4941void __kmp_affinity_uninitialize(
void) {
4942 for (kmp_affinity_t *affinity : __kmp_affinities) {
4943 if (affinity->masks != NULL)
4944 KMP_CPU_FREE_ARRAY(affinity->masks, affinity->num_masks);
4945 if (affinity->os_id_masks != NULL)
4946 KMP_CPU_FREE_ARRAY(affinity->os_id_masks, affinity->num_os_id_masks);
4947 if (affinity->proclist != NULL)
4949 if (affinity->ids != NULL)
4951 if (affinity->attrs != NULL)
4953 *affinity = KMP_AFFINITY_INIT(affinity->env_var);
4955 if (__kmp_affin_origMask != NULL) {
4956 if (KMP_AFFINITY_CAPABLE()) {
4959 bindprocessor(BINDTHREAD, thread_self(), PROCESSOR_CLASS_ANY);
4961 __kmp_set_system_affinity(__kmp_affin_origMask,
FALSE);
4964 KMP_CPU_FREE(__kmp_affin_origMask);
4965 __kmp_affin_origMask = NULL;
4968 if (procarr != NULL) {
4972 if (__kmp_osid_to_hwthread_map) {
4974 __kmp_osid_to_hwthread_map = NULL;
4977 if (__kmp_hwloc_topology != NULL) {
4978 hwloc_topology_destroy(__kmp_hwloc_topology);
4979 __kmp_hwloc_topology = NULL;
4990 KMPAffinity::destroy_api();
4993static void __kmp_select_mask_by_gtid(
int gtid,
const kmp_affinity_t *affinity,
4994 int *place, kmp_affin_mask_t **
mask) {
4997 if (is_hidden_helper)
5000 mask_idx = gtid - 2;
5004 *place = (mask_idx + affinity->offset) % affinity->num_masks;
5005 *
mask = KMP_CPU_INDEX(affinity->masks, *place);
5010void __kmp_affinity_set_init_mask(
int gtid,
int isa_root) {
5017 th->th.th_topology_attrs = KMP_AFFINITY_ATTRS_UNKNOWN;
5019 if (!KMP_AFFINITY_CAPABLE()) {
5023 if (th->th.th_affin_mask == NULL) {
5024 KMP_CPU_ALLOC(th->th.th_affin_mask);
5026 KMP_CPU_ZERO(th->th.th_affin_mask);
5034 kmp_affin_mask_t *
mask;
5036 const kmp_affinity_t *affinity;
5039 if (is_hidden_helper)
5040 affinity = &__kmp_hh_affinity;
5042 affinity = &__kmp_affinity;
5044 if (KMP_AFFINITY_NON_PROC_BIND || is_hidden_helper) {
5045 if ((affinity->type == affinity_none) ||
5046 (affinity->type == affinity_balanced) ||
5048#if KMP_GROUP_AFFINITY
5049 if (__kmp_num_proc_groups > 1) {
5055 mask = __kmp_affin_fullMask;
5057 __kmp_select_mask_by_gtid(gtid, affinity, &
i, &
mask);
5061#if KMP_GROUP_AFFINITY
5062 if (__kmp_num_proc_groups > 1) {
5068 mask = __kmp_affin_fullMask;
5070 __kmp_select_mask_by_gtid(gtid, affinity, &
i, &
mask);
5074 th->th.th_current_place =
i;
5075 if (isa_root && !is_hidden_helper) {
5076 th->th.th_new_place =
i;
5077 th->th.th_first_place = 0;
5078 th->th.th_last_place = affinity->num_masks - 1;
5079 }
else if (KMP_AFFINITY_NON_PROC_BIND) {
5082 th->th.th_first_place = 0;
5083 th->th.th_last_place = affinity->num_masks - 1;
5087 th->th.th_topology_ids = __kmp_affinity.ids[
i];
5088 th->th.th_topology_attrs = __kmp_affinity.attrs[
i];
5091 if (
i == KMP_PLACE_ALL) {
5092 KA_TRACE(100, (
"__kmp_affinity_set_init_mask: setting T#%d to all places\n",
5095 KA_TRACE(100, (
"__kmp_affinity_set_init_mask: setting T#%d to place %d\n",
5099 KMP_CPU_COPY(th->th.th_affin_mask,
mask);
5102void __kmp_affinity_bind_init_mask(
int gtid) {
5103 if (!KMP_AFFINITY_CAPABLE()) {
5107 const kmp_affinity_t *affinity;
5108 const char *env_var;
5111 if (is_hidden_helper)
5112 affinity = &__kmp_hh_affinity;
5114 affinity = &__kmp_affinity;
5115 env_var = __kmp_get_affinity_env_var(*affinity,
true);
5117 if (affinity->flags.verbose && (affinity->type == affinity_none ||
5118 (th->th.th_current_place != KMP_PLACE_ALL &&
5119 affinity->type != affinity_balanced)) &&
5121 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5122 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5123 th->th.th_affin_mask);
5132 if (affinity->type == affinity_none) {
5133 __kmp_set_system_affinity(th->th.th_affin_mask,
FALSE);
5138 __kmp_set_system_affinity(th->th.th_affin_mask,
TRUE);
5142void __kmp_affinity_bind_place(
int gtid) {
5150 KA_TRACE(100, (
"__kmp_affinity_bind_place: binding T#%d to place %d (current "
5152 gtid, th->th.th_new_place, th->th.th_current_place));
5157 KMP_ASSERT((
unsigned)th->th.th_new_place <= __kmp_affinity.num_masks);
5158 if (th->th.th_first_place <= th->th.th_last_place) {
5159 KMP_ASSERT((th->th.th_new_place >= th->th.th_first_place) &&
5160 (th->th.th_new_place <= th->th.th_last_place));
5162 KMP_ASSERT((th->th.th_new_place <= th->th.th_first_place) ||
5163 (th->th.th_new_place >= th->th.th_last_place));
5168 kmp_affin_mask_t *
mask =
5169 KMP_CPU_INDEX(__kmp_affinity.masks, th->th.th_new_place);
5170 KMP_CPU_COPY(th->th.th_affin_mask,
mask);
5171 th->th.th_current_place = th->th.th_new_place;
5173 if (__kmp_affinity.flags.verbose) {
5174 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5175 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5176 th->th.th_affin_mask);
5178 __kmp_gettid(), gtid,
buf);
5180 __kmp_set_system_affinity(th->th.th_affin_mask,
TRUE);
5183int __kmp_aux_set_affinity(
void **
mask) {
5188 if (!KMP_AFFINITY_CAPABLE()) {
5195 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5196 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5197 (kmp_affin_mask_t *)(*
mask));
5199 "kmp_set_affinity: setting affinity mask for thread %d = %s\n",
5204 if ((
mask == NULL) || (*
mask == NULL)) {
5205 KMP_FATAL(AffinityInvalidMask,
"kmp_set_affinity");
5210 KMP_CPU_SET_ITERATE(proc, ((kmp_affin_mask_t *)(*
mask))) {
5211 if (!KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) {
5212 KMP_FATAL(AffinityInvalidMask,
"kmp_set_affinity");
5214 if (!KMP_CPU_ISSET(proc, (kmp_affin_mask_t *)(*
mask))) {
5219 if (num_procs == 0) {
5220 KMP_FATAL(AffinityInvalidMask,
"kmp_set_affinity");
5223#if KMP_GROUP_AFFINITY
5224 if (__kmp_get_proc_group((kmp_affin_mask_t *)(*
mask)) < 0) {
5225 KMP_FATAL(AffinityInvalidMask,
"kmp_set_affinity");
5233 retval = __kmp_set_system_affinity((kmp_affin_mask_t *)(*
mask),
FALSE);
5235 KMP_CPU_COPY(th->th.th_affin_mask, (kmp_affin_mask_t *)(*
mask));
5238 th->th.th_current_place = KMP_PLACE_UNDEFINED;
5239 th->th.th_new_place = KMP_PLACE_UNDEFINED;
5240 th->th.th_first_place = 0;
5241 th->th.th_last_place = __kmp_affinity.num_masks - 1;
5249int __kmp_aux_get_affinity(
void **
mask) {
5252#if KMP_OS_WINDOWS || KMP_OS_AIX || KMP_DEBUG
5255 if (!KMP_AFFINITY_CAPABLE()) {
5260#if KMP_OS_WINDOWS || KMP_OS_AIX || KMP_DEBUG
5269 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5270 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5271 th->th.th_affin_mask);
5273 "kmp_get_affinity: stored affinity mask for thread %d = %s\n", gtid,
5278 if ((
mask == NULL) || (*
mask == NULL)) {
5279 KMP_FATAL(AffinityInvalidMask,
"kmp_get_affinity");
5283#if !KMP_OS_WINDOWS && !KMP_OS_AIX
5285 retval = __kmp_get_system_affinity((kmp_affin_mask_t *)(*
mask),
FALSE);
5288 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5289 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5290 (kmp_affin_mask_t *)(*
mask));
5292 "kmp_get_affinity: system affinity mask for thread %d = %s\n", gtid,
5300 KMP_CPU_COPY((kmp_affin_mask_t *)(*
mask), th->th.th_affin_mask);
5306int __kmp_aux_get_affinity_max_proc() {
5307 if (!KMP_AFFINITY_CAPABLE()) {
5310#if KMP_GROUP_AFFINITY
5311 if (__kmp_num_proc_groups > 1) {
5312 return (
int)(__kmp_num_proc_groups *
sizeof(DWORD_PTR) * CHAR_BIT);
5318int __kmp_aux_set_affinity_mask_proc(
int proc,
void **
mask) {
5319 if (!KMP_AFFINITY_CAPABLE()) {
5326 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5327 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5328 (kmp_affin_mask_t *)(*
mask));
5330 "affinity mask for thread %d = %s\n",
5335 if ((
mask == NULL) || (*
mask == NULL)) {
5336 KMP_FATAL(AffinityInvalidMask,
"kmp_set_affinity_mask_proc");
5340 if ((proc < 0) || (proc >= __kmp_aux_get_affinity_max_proc())) {
5343 if (!KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) {
5347 KMP_CPU_SET(proc, (kmp_affin_mask_t *)(*
mask));
5351int __kmp_aux_unset_affinity_mask_proc(
int proc,
void **
mask) {
5352 if (!KMP_AFFINITY_CAPABLE()) {
5359 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5360 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5361 (kmp_affin_mask_t *)(*
mask));
5363 "affinity mask for thread %d = %s\n",
5368 if ((
mask == NULL) || (*
mask == NULL)) {
5369 KMP_FATAL(AffinityInvalidMask,
"kmp_unset_affinity_mask_proc");
5373 if ((proc < 0) || (proc >= __kmp_aux_get_affinity_max_proc())) {
5376 if (!KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) {
5380 KMP_CPU_CLR(proc, (kmp_affin_mask_t *)(*
mask));
5384int __kmp_aux_get_affinity_mask_proc(
int proc,
void **
mask) {
5385 if (!KMP_AFFINITY_CAPABLE()) {
5392 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5393 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
5394 (kmp_affin_mask_t *)(*
mask));
5396 "affinity mask for thread %d = %s\n",
5401 if ((
mask == NULL) || (*
mask == NULL)) {
5402 KMP_FATAL(AffinityInvalidMask,
"kmp_get_affinity_mask_proc");
5406 if ((proc < 0) || (proc >= __kmp_aux_get_affinity_max_proc())) {
5409 if (!KMP_CPU_ISSET(proc, __kmp_affin_fullMask)) {
5413 return KMP_CPU_ISSET(proc, (kmp_affin_mask_t *)(*
mask));
5416#if KMP_WEIGHTED_ITERATIONS_SUPPORTED
5418int __kmp_get_first_osid_with_ecore(
void) {
5422 while (high - low > 1) {
5423 mid = (high + low) / 2;
5425 KMP_HW_CORE_TYPE_CORE) {
5439void __kmp_balanced_affinity(
kmp_info_t *th,
int nthreads) {
5441 bool fine_gran =
true;
5442 int tid = th->th.th_info.ds.ds_tid;
5443 const char *env_var =
"KMP_AFFINITY";
5449 switch (__kmp_affinity.gran) {
5473 if ((
nPackages > 1) && (__kmp_nth_per_core <= 1)) {
5478 int chunk = nthreads / ncores;
5480 int big_cores = nthreads % ncores;
5482 int big_nth = (chunk + 1) * big_cores;
5483 if (tid < big_nth) {
5484 coreID = tid / (chunk + 1);
5485 threadID = (tid % (chunk + 1)) % __kmp_nth_per_core;
5487 coreID = (tid - big_cores) / chunk;
5488 threadID = ((tid - big_cores) % chunk) % __kmp_nth_per_core;
5491 "Illegal set affinity operation when not capable");
5493 kmp_affin_mask_t *
mask = th->th.th_affin_mask;
5499 KMP_CPU_SET(osID,
mask);
5501 for (
int i = 0;
i < __kmp_nth_per_core;
i++) {
5504 KMP_CPU_SET(osID,
mask);
5507 if (__kmp_affinity.flags.verbose) {
5508 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5509 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
mask);
5513 __kmp_affinity_get_thread_topology_info(th);
5514 __kmp_set_system_affinity(
mask,
TRUE);
5517 kmp_affin_mask_t *
mask = th->th.th_affin_mask;
5523 __kmp_aff_depth - 1, core_level);
5524 int nth_per_core = __kmp_affinity_max_proc_per_core(
5532 KMP_CPU_SET(osID,
mask);
5535 __kmp_affinity_find_core(tid, __kmp_aff_depth - 1, core_level);
5538 if (__kmp_affinity_find_core(
i, __kmp_aff_depth - 1, core_level) ==
5540 KMP_CPU_SET(osID,
mask);
5544 }
else if (nthreads <= ncores) {
5547 for (
int i = 0;
i < ncores;
i++) {
5550 for (
int j = 0;
j < nth_per_core;
j++) {
5551 if (procarr[
i * nth_per_core +
j] != -1) {
5558 for (
int j = 0;
j < nth_per_core;
j++) {
5559 int osID = procarr[
i * nth_per_core +
j];
5561 KMP_CPU_SET(osID,
mask);
5577 int *nproc_at_core = (
int *)
KMP_ALLOCA(
sizeof(
int) * ncores);
5579 int *ncores_with_x_procs =
5580 (
int *)
KMP_ALLOCA(
sizeof(
int) * (nth_per_core + 1));
5582 int *ncores_with_x_to_max_procs =
5583 (
int *)
KMP_ALLOCA(
sizeof(
int) * (nth_per_core + 1));
5585 for (
int i = 0;
i <= nth_per_core;
i++) {
5586 ncores_with_x_procs[
i] = 0;
5587 ncores_with_x_to_max_procs[
i] = 0;
5590 for (
int i = 0;
i < ncores;
i++) {
5592 for (
int j = 0;
j < nth_per_core;
j++) {
5593 if (procarr[
i * nth_per_core +
j] != -1) {
5597 nproc_at_core[
i] = cnt;
5598 ncores_with_x_procs[cnt]++;
5601 for (
int i = 0;
i <= nth_per_core;
i++) {
5602 for (
int j =
i;
j <= nth_per_core;
j++) {
5603 ncores_with_x_to_max_procs[
i] += ncores_with_x_procs[
j];
5608 int nproc = nth_per_core * ncores;
5611 for (
int i = 0;
i < nproc;
i++) {
5618 for (
int j = 1;
j <= nth_per_core;
j++) {
5619 int cnt = ncores_with_x_to_max_procs[
j];
5620 for (
int i = 0;
i < ncores;
i++) {
5622 if (nproc_at_core[
i] == 0) {
5625 for (
int k = 0; k < nth_per_core; k++) {
5626 if (procarr[
i * nth_per_core + k] != -1) {
5627 if (newarr[
i * nth_per_core + k] == 0) {
5628 newarr[
i * nth_per_core + k] = 1;
5634 newarr[
i * nth_per_core + k]++;
5642 if (cnt == 0 || nth == 0) {
5653 for (
int i = 0;
i < nproc;
i++) {
5657 int osID = procarr[
i];
5658 KMP_CPU_SET(osID,
mask);
5660 int coreID =
i / nth_per_core;
5661 for (
int ii = 0;
ii < nth_per_core;
ii++) {
5662 int osID = procarr[coreID * nth_per_core +
ii];
5664 KMP_CPU_SET(osID,
mask);
5674 if (__kmp_affinity.flags.verbose) {
5675 char buf[KMP_AFFIN_MASK_PRINT_LEN];
5676 __kmp_affinity_print_mask(
buf, KMP_AFFIN_MASK_PRINT_LEN,
mask);
5680 __kmp_affinity_get_thread_topology_info(th);
5681 __kmp_set_system_affinity(
mask,
TRUE);
5685#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
5700 kmp_set_thread_affinity_mask_initial()
5708 KA_TRACE(30, (
"kmp_set_thread_affinity_mask_initial: "
5709 "non-omp thread, returning\n"));
5713 KA_TRACE(30, (
"kmp_set_thread_affinity_mask_initial: "
5714 "affinity not initialized, returning\n"));
5717 KA_TRACE(30, (
"kmp_set_thread_affinity_mask_initial: "
5718 "set full mask for thread %d\n",
5722 return bindprocessor(BINDTHREAD, thread_self(), PROCESSOR_CLASS_ANY);
5724 return __kmp_set_system_affinity(__kmp_affin_fullMask,
FALSE);
kmp_uint32 * numPerLevel
Level 0 corresponds to leaves.
kmp_uint32 * skipPerLevel
void resize(kmp_uint32 nproc)
kmp_uint32 base_num_threads
volatile kmp_int8 uninitialized
kmp_uint32 depth
This is specifically the depth of the machine configuration hierarchy, in terms of the number of leve...
void canonicalize(const kmp_topology_t *top)
static void deallocate(kmp_hw_subset_t *subset)
const item_t & at(int index) const
static const int UNKNOWN_ID
static int compare_compact(const void *a, const void *b)
static int compare_ids(const void *a, const void *b)
static const int MULTIPLE_ID
This class safely opens and closes a C-style FILE* object using RAII semantics.
int try_open(const char *filename, const char *mode)
Instead of erroring out, return non-zero when unsuccessful fopen() for any reason.
kmp_hw_thread_t & at(int index)
int get_level(kmp_hw_t type) const
int get_count(int level) const
int get_ratio(int level) const
static void deallocate(kmp_topology_t *)
kmp_hw_t get_equivalent_type(kmp_hw_t type) const
void set_equivalent_type(kmp_hw_t type1, kmp_hw_t type2)
int get_num_hw_threads() const
int get_ncores_with_attr_per(const kmp_hw_attr_t &attr, int above) const
int calculate_ratio(int level1, int level2) const
static kmp_topology_t * allocate(int nproc, int ndepth, const kmp_hw_t *types)
void print(const char *env_var="KMP_AFFINITY") const
kmp_hw_t get_type(int level) const
int get_ncores_with_attr(const kmp_hw_attr_t &attr) const
__itt_string_handle * name
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int mask
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d __itt_event ITT_FORMAT __itt_group_mark d void const wchar_t const wchar_t int ITT_FORMAT __itt_group_sync __itt_group_fsync x void const wchar_t int const wchar_t int int ITT_FORMAT __itt_group_sync __itt_group_fsync x void ITT_FORMAT __itt_group_sync __itt_group_fsync p void ITT_FORMAT __itt_group_sync __itt_group_fsync p void size_t ITT_FORMAT lu no args __itt_obj_prop_t __itt_obj_state_t ITT_FORMAT d const char ITT_FORMAT s const char ITT_FORMAT s __itt_frame ITT_FORMAT p __itt_counter ITT_FORMAT p __itt_counter unsigned long long ITT_FORMAT lu __itt_counter unsigned long long ITT_FORMAT lu __itt_counter __itt_clock_domain unsigned long long void ITT_FORMAT p const wchar_t ITT_FORMAT S __itt_mark_type const wchar_t ITT_FORMAT S __itt_mark_type const char ITT_FORMAT s __itt_mark_type ITT_FORMAT d __itt_caller ITT_FORMAT p __itt_caller ITT_FORMAT p no args const __itt_domain __itt_clock_domain unsigned long long __itt_id ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_id __itt_id void ITT_FORMAT p const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_id __itt_string_handle __itt_scope ITT_FORMAT d const __itt_domain __itt_scope __itt_string_handle const char size_t ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_relation __itt_id ITT_FORMAT lu __itt_track_group __itt_string_handle __itt_track_group_type ITT_FORMAT d __itt_track ITT_FORMAT p void int const int int const char int ITT_FORMAT d void void const char * path
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t count
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t size
void const char const char int ITT_FORMAT __itt_group_sync p
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle * key
#define KMP_HW_MAX_NUM_CORE_EFFS
#define KMP_FOREACH_HW_TYPE(type)
kmp_nested_proc_bind_t __kmp_nested_proc_bind
#define KMP_HIDDEN_HELPER_MAIN_THREAD(gtid)
#define __kmp_entry_gtid()
#define KMP_ASSERT_VALID_HW_TYPE(type)
const char * __kmp_hw_get_catalog_string(kmp_hw_t type, bool plural=false)
volatile int __kmp_init_middle
const char * __kmp_hw_get_keyword(kmp_hw_t type, bool plural=false)
int __kmp_affinity_num_places
kmp_info_t ** __kmp_threads
#define KMP_HIDDEN_HELPER_THREAD(gtid)
#define __kmp_allocate(size)
static bool __kmp_is_hybrid_cpu()
int __kmp_env_consistency_check
static int __kmp_adjust_gtid_for_hidden_helpers(int gtid)
const char * __kmp_hw_get_core_type_string(kmp_hw_core_type_t type)
static int __kmp_gtid_from_thread(const kmp_info_t *thr)
@ KMP_HW_MAX_NUM_CORE_TYPES
@ KMP_HW_CORE_TYPE_UNKNOWN
static void __kmp_type_convert(T1 src, T2 *dest)
struct KMP_ALIGN_CACHE kmp_bstate kmp_bstate_t
union KMP_ALIGN_CACHE kmp_info kmp_info_t
kmp_hw_subset_t * __kmp_hw_subset
static hierarchy_info machine_hierarchy
kmp_topology_t * __kmp_topology
void __kmp_get_hierarchy(kmp_uint32 nproc, kmp_bstate_t *thr_bar)
#define KMP_AFF_WARNING(s,...)
static int __kmp_nThreadsPerCore
const char * __kmp_hw_get_catalog_string(kmp_hw_t type, bool plural)
const char * __kmp_hw_get_core_type_string(kmp_hw_core_type_t type)
void __kmp_cleanup_hierarchy()
const char * __kmp_hw_get_keyword(kmp_hw_t type, bool plural)
kmp_hw_subset_t * __kmp_hw_subset
kmp_topology_t * __kmp_topology
KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86<<, 2i, 1, KMP_ARCH_X86) ATOMIC_CMPXCHG(fixed2, shr, kmp_int16, 16, > KMP_ARCH_X86 KMP_ARCH_X86 kmp_uint32
void __kmp_debug_printf(char const *format,...)
#define KMP_BUILD_ASSERT(expr)
#define KMP_DEBUG_ASSERT2(cond, msg)
#define KMP_DEBUG_ASSERT(cond)
#define KMP_ASSERT2(cond, msg)
unsigned long long kmp_uint64
int __kmp_hier_threads_per[kmp_hier_layer_e::LAYER_LAST+1]
int __kmp_dispatch_get_index(int tid, kmp_hier_layer_e type)
int __kmp_hier_max_units[kmp_hier_layer_e::LAYER_LAST+1]
int __kmp_dispatch_get_t1_per_t2(kmp_hier_layer_e t1, kmp_hier_layer_e t2)
static volatile kmp_i18n_cat_status_t status
static void __kmp_msg(kmp_msg_severity_t severity, kmp_msg_t message, va_list ap)
char const * __kmp_i18n_catgets(kmp_i18n_id_t id)
void __kmp_printf(char const *format,...)
#define KMP_BUILTIN_UNREACHABLE
int __kmp_str_to_int(char const *str, char sentinel)
void __kmp_str_buf_clear(kmp_str_buf_t *buffer)
int __kmp_str_match(char const *target, int len, char const *data)
void __kmp_str_buf_free(kmp_str_buf_t *buffer)
int __kmp_str_buf_print(kmp_str_buf_t *buffer, char const *format,...)
#define __kmp_str_buf_init(b)
affinity_mask_t * full_mask
bool contains(const kmp_hw_attr_t &other) const
bool is_core_type_valid() const
kmp_hw_core_type_t get_core_type() const
void set_core_type(kmp_hw_core_type_t type)
static const int UNKNOWN_CORE_EFF
void set_core_eff(int eff)
bool is_core_eff_valid() const
kmp_hw_attr_t attr[MAX_ATTRS]
kmp_proc_bind_t * bind_types
int __kmp_read_from_file(char const *path, char const *format,...)