20#if KMP_AFFINITY_SUPPORTED
22class KMPHwlocAffinity :
public KMPAffinity {
24 class Mask :
public KMPAffinity::Mask {
29 mask = hwloc_bitmap_alloc();
32 Mask(
const Mask &other) =
delete;
33 Mask &operator=(
const Mask &other) =
delete;
34 ~Mask() { hwloc_bitmap_free(
mask); }
35 void set(
int i)
override { hwloc_bitmap_set(
mask,
i); }
36 bool is_set(
int i)
const override {
return hwloc_bitmap_isset(
mask,
i); }
37 void clear(
int i)
override { hwloc_bitmap_clr(
mask,
i); }
38 void zero()
override { hwloc_bitmap_zero(
mask); }
39 bool empty()
const override {
return hwloc_bitmap_iszero(
mask); }
40 void copy(
const KMPAffinity::Mask *src)
override {
41 const Mask *convert =
static_cast<const Mask *
>(src);
42 hwloc_bitmap_copy(
mask, convert->mask);
44 void bitwise_and(
const KMPAffinity::Mask *rhs)
override {
45 const Mask *convert =
static_cast<const Mask *
>(rhs);
46 hwloc_bitmap_and(
mask,
mask, convert->mask);
48 void bitwise_or(
const KMPAffinity::Mask *rhs)
override {
49 const Mask *convert =
static_cast<const Mask *
>(rhs);
50 hwloc_bitmap_or(
mask,
mask, convert->mask);
52 void bitwise_not()
override { hwloc_bitmap_not(
mask,
mask); }
53 bool is_equal(
const KMPAffinity::Mask *rhs)
const override {
54 const Mask *convert =
static_cast<const Mask *
>(rhs);
55 return hwloc_bitmap_isequal(
mask, convert->mask);
57 int begin()
const override {
return hwloc_bitmap_first(
mask); }
58 int end()
const override {
return -1; }
59 int next(
int previous)
const override {
60 return hwloc_bitmap_next(
mask, previous);
62 int get_system_affinity(
bool abort_on_error)
override {
64 "Illegal get affinity operation when not capable");
66 hwloc_get_cpubind(__kmp_hwloc_topology,
mask, HWLOC_CPUBIND_THREAD);
77 int set_system_affinity(
bool abort_on_error)
const override {
79 "Illegal set affinity operation when not capable");
81 hwloc_set_cpubind(__kmp_hwloc_topology,
mask, HWLOC_CPUBIND_THREAD);
93 int set_process_affinity(
bool abort_on_error)
const override {
95 "Illegal set process affinity operation when not capable");
97 const hwloc_topology_support *support =
98 hwloc_topology_get_support(__kmp_hwloc_topology);
99 if (support->cpubind->set_proc_cpubind) {
101 retval = hwloc_set_cpubind(__kmp_hwloc_topology,
mask,
102 HWLOC_CPUBIND_PROCESS);
113 int get_proc_group()
const override {
116 if (__kmp_num_proc_groups == 1) {
119 for (
int i = 0;
i < __kmp_num_proc_groups;
i++) {
121 unsigned long first_32_bits = hwloc_bitmap_to_ith_ulong(
mask,
i * 2);
122 unsigned long second_32_bits =
123 hwloc_bitmap_to_ith_ulong(
mask,
i * 2 + 1);
124 if (first_32_bits == 0 && second_32_bits == 0) {
136 void determine_capable(
const char *var)
override {
137 const hwloc_topology_support *topology_support;
138 if (__kmp_hwloc_topology == NULL) {
139 if (hwloc_topology_init(&__kmp_hwloc_topology) < 0) {
140 __kmp_hwloc_error =
TRUE;
141 if (__kmp_affinity.flags.verbose) {
142 KMP_WARNING(AffHwlocErrorOccurred, var,
"hwloc_topology_init()");
145 if (hwloc_topology_load(__kmp_hwloc_topology) < 0) {
146 __kmp_hwloc_error =
TRUE;
147 if (__kmp_affinity.flags.verbose) {
148 KMP_WARNING(AffHwlocErrorOccurred, var,
"hwloc_topology_load()");
152 topology_support = hwloc_topology_get_support(__kmp_hwloc_topology);
157 if (topology_support && topology_support->cpubind->set_thisthread_cpubind &&
158 topology_support->cpubind->get_thisthread_cpubind &&
159 topology_support->discovery->pu && !__kmp_hwloc_error) {
161 KMP_AFFINITY_ENABLE(
TRUE);
164 __kmp_hwloc_error =
TRUE;
165 KMP_AFFINITY_DISABLE();
168 void bind_thread(
int which)
override {
170 "Illegal set affinity operation when not capable");
171 KMPAffinity::Mask *
mask;
172 KMP_CPU_ALLOC_ON_STACK(
mask);
174 KMP_CPU_SET(which,
mask);
175 __kmp_set_system_affinity(
mask,
TRUE);
176 KMP_CPU_FREE_FROM_STACK(
mask);
178 KMPAffinity::Mask *allocate_mask()
override {
return new Mask(); }
179 void deallocate_mask(KMPAffinity::Mask *m)
override {
delete m; }
180 KMPAffinity::Mask *allocate_mask_array(
int num)
override {
181 return new Mask[num];
183 void deallocate_mask_array(KMPAffinity::Mask *array)
override {
184 Mask *hwloc_array =
static_cast<Mask *
>(array);
185 delete[] hwloc_array;
187 KMPAffinity::Mask *index_mask_array(KMPAffinity::Mask *array,
188 int index)
override {
189 Mask *hwloc_array =
static_cast<Mask *
>(array);
190 return &(hwloc_array[index]);
192 api_type get_api_type()
const override {
return HWLOC; }
196#if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY || \
203#include <sys/syscall.h>
204#if KMP_ARCH_X86 || KMP_ARCH_ARM
205#ifndef __NR_sched_setaffinity
206#define __NR_sched_setaffinity 241
207#elif __NR_sched_setaffinity != 241
208#error Wrong code for setaffinity system call.
210#ifndef __NR_sched_getaffinity
211#define __NR_sched_getaffinity 242
212#elif __NR_sched_getaffinity != 242
213#error Wrong code for getaffinity system call.
215#elif KMP_ARCH_AARCH64
216#ifndef __NR_sched_setaffinity
217#define __NR_sched_setaffinity 122
218#elif __NR_sched_setaffinity != 122
219#error Wrong code for setaffinity system call.
221#ifndef __NR_sched_getaffinity
222#define __NR_sched_getaffinity 123
223#elif __NR_sched_getaffinity != 123
224#error Wrong code for getaffinity system call.
227#ifndef __NR_sched_setaffinity
228#define __NR_sched_setaffinity 203
229#elif __NR_sched_setaffinity != 203
230#error Wrong code for setaffinity system call.
232#ifndef __NR_sched_getaffinity
233#define __NR_sched_getaffinity 204
234#elif __NR_sched_getaffinity != 204
235#error Wrong code for getaffinity system call.
238#ifndef __NR_sched_setaffinity
239#define __NR_sched_setaffinity 222
240#elif __NR_sched_setaffinity != 222
241#error Wrong code for setaffinity system call.
243#ifndef __NR_sched_getaffinity
244#define __NR_sched_getaffinity 223
245#elif __NR_sched_getaffinity != 223
246#error Wrong code for getaffinity system call.
249#ifndef __NR_sched_setaffinity
250#define __NR_sched_setaffinity 4239
251#elif __NR_sched_setaffinity != 4239
252#error Wrong code for setaffinity system call.
254#ifndef __NR_sched_getaffinity
255#define __NR_sched_getaffinity 4240
256#elif __NR_sched_getaffinity != 4240
257#error Wrong code for getaffinity system call.
260#ifndef __NR_sched_setaffinity
261#define __NR_sched_setaffinity 5195
262#elif __NR_sched_setaffinity != 5195
263#error Wrong code for setaffinity system call.
265#ifndef __NR_sched_getaffinity
266#define __NR_sched_getaffinity 5196
267#elif __NR_sched_getaffinity != 5196
268#error Wrong code for getaffinity system call.
270#elif KMP_ARCH_LOONGARCH64
271#ifndef __NR_sched_setaffinity
272#define __NR_sched_setaffinity 122
273#elif __NR_sched_setaffinity != 122
274#error Wrong code for setaffinity system call.
276#ifndef __NR_sched_getaffinity
277#define __NR_sched_getaffinity 123
278#elif __NR_sched_getaffinity != 123
279#error Wrong code for getaffinity system call.
281#elif KMP_ARCH_RISCV64
282#ifndef __NR_sched_setaffinity
283#define __NR_sched_setaffinity 122
284#elif __NR_sched_setaffinity != 122
285#error Wrong code for setaffinity system call.
287#ifndef __NR_sched_getaffinity
288#define __NR_sched_getaffinity 123
289#elif __NR_sched_getaffinity != 123
290#error Wrong code for getaffinity system call.
293#ifndef __NR_sched_setaffinity
294#define __NR_sched_setaffinity 203
295#elif __NR_sched_setaffinity != 203
296#error Wrong code for setaffinity system call.
298#ifndef __NR_sched_getaffinity
299#define __NR_sched_getaffinity 204
300#elif __NR_sched_getaffinity != 204
301#error Wrong code for getaffinity system call.
304#ifndef __NR_sched_setaffinity
305#define __NR_sched_setaffinity 239
306#elif __NR_sched_setaffinity != 239
307#error Wrong code for setaffinity system call.
309#ifndef __NR_sched_getaffinity
310#define __NR_sched_getaffinity 240
311#elif __NR_sched_getaffinity != 240
312#error Wrong code for getaffinity system call.
315#ifndef __NR_sched_setaffinity
316#define __NR_sched_setaffinity 261
317#elif __NR_sched_setaffinity != 261
318#error Wrong code for setaffinity system call.
320#ifndef __NR_sched_getaffinity
321#define __NR_sched_getaffinity 260
322#elif __NR_sched_getaffinity != 260
323#error Wrong code for getaffinity system call.
326#error Unknown or unsupported architecture
328#elif KMP_OS_FREEBSD || KMP_OS_DRAGONFLY
330#include <pthread_np.h>
337#define VMI_MAXRADS 64
338#define GET_NUMBER_SMT_SETS 0x0004
339extern "C" int syssmt(
int flags,
int,
int,
int *);
341class KMPNativeAffinity :
public KMPAffinity {
342 class Mask :
public KMPAffinity::Mask {
343 typedef unsigned long mask_t;
344 typedef decltype(__kmp_affin_mask_size) mask_size_type;
345 static const unsigned int BITS_PER_MASK_T =
sizeof(mask_t) * CHAR_BIT;
346 static const mask_t ONE = 1;
347 mask_size_type get_num_mask_types()
const {
348 return __kmp_affin_mask_size /
sizeof(mask_t);
358 void set(
int i)
override {
359 mask[
i / BITS_PER_MASK_T] |= (ONE << (
i % BITS_PER_MASK_T));
361 bool is_set(
int i)
const override {
362 return (
mask[
i / BITS_PER_MASK_T] & (ONE << (
i % BITS_PER_MASK_T)));
364 void clear(
int i)
override {
365 mask[
i / BITS_PER_MASK_T] &= ~(ONE << (
i % BITS_PER_MASK_T));
367 void zero()
override {
368 mask_size_type e = get_num_mask_types();
369 for (mask_size_type
i = 0;
i < e; ++
i)
372 bool empty()
const override {
373 mask_size_type e = get_num_mask_types();
374 for (mask_size_type
i = 0;
i < e; ++
i)
375 if (
mask[
i] != (mask_t)0)
379 void copy(
const KMPAffinity::Mask *src)
override {
380 const Mask *convert =
static_cast<const Mask *
>(src);
381 mask_size_type e = get_num_mask_types();
382 for (mask_size_type
i = 0;
i < e; ++
i)
383 mask[
i] = convert->mask[
i];
385 void bitwise_and(
const KMPAffinity::Mask *rhs)
override {
386 const Mask *convert =
static_cast<const Mask *
>(rhs);
387 mask_size_type e = get_num_mask_types();
388 for (mask_size_type
i = 0;
i < e; ++
i)
389 mask[
i] &= convert->mask[
i];
391 void bitwise_or(
const KMPAffinity::Mask *rhs)
override {
392 const Mask *convert =
static_cast<const Mask *
>(rhs);
393 mask_size_type e = get_num_mask_types();
394 for (mask_size_type
i = 0;
i < e; ++
i)
395 mask[
i] |= convert->mask[
i];
397 void bitwise_not()
override {
398 mask_size_type e = get_num_mask_types();
399 for (mask_size_type
i = 0;
i < e; ++
i)
402 bool is_equal(
const KMPAffinity::Mask *rhs)
const override {
403 const Mask *convert =
static_cast<const Mask *
>(rhs);
404 mask_size_type e = get_num_mask_types();
405 for (mask_size_type
i = 0;
i < e; ++
i)
406 if (
mask[
i] != convert->mask[
i])
410 int begin()
const override {
412 while (retval <
end() && !is_set(retval))
416 int end()
const override {
421 int next(
int previous)
const override {
422 int retval = previous + 1;
423 while (retval <
end() && !is_set(retval))
430 int get_system_affinity(
bool abort_on_error)
override {
432 "Illegal get affinity operation when not capable");
434 (
void)abort_on_error;
438 KMP_CPU_SET(
i,
this);
441 int set_system_affinity(
bool abort_on_error)
const override {
444 "Illegal set affinity operation when not capable");
448 int tid = thread_self();
452 int retval = bindprocessor(BINDTHREAD, tid, PROCESSOR_CLASS_ANY);
456 KMP_CPU_SET_ITERATE(location,
this) {
457 if (KMP_CPU_ISSET(location,
this)) {
458 retval = bindprocessor(BINDTHREAD, tid, location);
459 if (retval == -1 && errno == 1) {
464 rsh = rs_alloc(RS_EMPTY);
465 rsid.at_pid = getpid();
466 if (RS_DEFAULT_RSET != ra_getrset(R_PROCESS, rsid, 0, rsh)) {
467 retval = ra_detachrset(R_PROCESS, rsid, 0);
468 retval = bindprocessor(BINDTHREAD, tid, location);
472 KA_TRACE(10, (
"__kmp_set_system_affinity: Done binding "
478 if (abort_on_error) {
481 KA_TRACE(10, (
"__kmp_set_system_affinity: Error binding "
482 "T#%d to cpu=%d, errno=%d.\n",
483 gtid, location, error));
491 int get_system_affinity(
bool abort_on_error)
override {
493 "Illegal get affinity operation when not capable");
496 syscall(__NR_sched_getaffinity, 0, __kmp_affin_mask_size,
mask);
497#elif KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY
498 int r = pthread_getaffinity_np(pthread_self(), __kmp_affin_mask_size,
499 reinterpret_cast<cpuset_t *
>(
mask));
500 int retval = (
r == 0 ? 0 : -1);
506 if (abort_on_error) {
512 int set_system_affinity(
bool abort_on_error)
const override {
514 "Illegal set affinity operation when not capable");
517 syscall(__NR_sched_setaffinity, 0, __kmp_affin_mask_size,
mask);
518#elif KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_DRAGONFLY
519 int r = pthread_setaffinity_np(pthread_self(), __kmp_affin_mask_size,
520 reinterpret_cast<cpuset_t *
>(
mask));
521 int retval = (
r == 0 ? 0 : -1);
527 if (abort_on_error) {
535 void determine_capable(
const char *env_var)
override {
539 KMPAffinity::Mask *allocate_mask()
override {
540 KMPNativeAffinity::Mask *retval =
new Mask();
543 void deallocate_mask(KMPAffinity::Mask *m)
override {
544 KMPNativeAffinity::Mask *native_mask =
545 static_cast<KMPNativeAffinity::Mask *
>(m);
548 KMPAffinity::Mask *allocate_mask_array(
int num)
override {
549 return new Mask[num];
551 void deallocate_mask_array(KMPAffinity::Mask *array)
override {
552 Mask *linux_array =
static_cast<Mask *
>(array);
553 delete[] linux_array;
555 KMPAffinity::Mask *index_mask_array(KMPAffinity::Mask *array,
556 int index)
override {
557 Mask *linux_array =
static_cast<Mask *
>(array);
558 return &(linux_array[index]);
560 api_type get_api_type()
const override {
return NATIVE_OS; }
566class KMPNativeAffinity :
public KMPAffinity {
567 class Mask :
public KMPAffinity::Mask {
568 typedef ULONG_PTR mask_t;
569 static const int BITS_PER_MASK_T =
sizeof(mask_t) * CHAR_BIT;
580 void set(
int i)
override {
581 mask[
i / BITS_PER_MASK_T] |= ((mask_t)1 << (
i % BITS_PER_MASK_T));
583 bool is_set(
int i)
const override {
584 return (
mask[
i / BITS_PER_MASK_T] & ((mask_t)1 << (
i % BITS_PER_MASK_T)));
586 void clear(
int i)
override {
587 mask[
i / BITS_PER_MASK_T] &= ~((mask_t)1 << (
i % BITS_PER_MASK_T));
589 void zero()
override {
590 for (
int i = 0;
i < __kmp_num_proc_groups; ++
i)
593 bool empty()
const override {
594 for (
size_t i = 0;
i < __kmp_num_proc_groups; ++
i)
599 void copy(
const KMPAffinity::Mask *src)
override {
600 const Mask *convert =
static_cast<const Mask *
>(src);
601 for (
int i = 0;
i < __kmp_num_proc_groups; ++
i)
602 mask[
i] = convert->mask[
i];
604 void bitwise_and(
const KMPAffinity::Mask *rhs)
override {
605 const Mask *convert =
static_cast<const Mask *
>(rhs);
606 for (
int i = 0;
i < __kmp_num_proc_groups; ++
i)
607 mask[
i] &= convert->mask[
i];
609 void bitwise_or(
const KMPAffinity::Mask *rhs)
override {
610 const Mask *convert =
static_cast<const Mask *
>(rhs);
611 for (
int i = 0;
i < __kmp_num_proc_groups; ++
i)
612 mask[
i] |= convert->mask[
i];
614 void bitwise_not()
override {
615 for (
int i = 0;
i < __kmp_num_proc_groups; ++
i)
618 bool is_equal(
const KMPAffinity::Mask *rhs)
const override {
619 const Mask *convert =
static_cast<const Mask *
>(rhs);
620 for (
size_t i = 0;
i < __kmp_num_proc_groups; ++
i)
621 if (
mask[
i] != convert->mask[
i])
625 int begin()
const override {
627 while (retval <
end() && !is_set(retval))
631 int end()
const override {
return __kmp_num_proc_groups * BITS_PER_MASK_T; }
632 int next(
int previous)
const override {
633 int retval = previous + 1;
634 while (retval <
end() && !is_set(retval))
638 int set_process_affinity(
bool abort_on_error)
const override {
639 if (__kmp_num_proc_groups <= 1) {
640 if (!SetProcessAffinityMask(GetCurrentProcess(), *
mask)) {
641 DWORD
error = GetLastError();
642 if (abort_on_error) {
651 int set_system_affinity(
bool abort_on_error)
const override {
652 if (__kmp_num_proc_groups > 1) {
655 int group = get_proc_group();
657 if (abort_on_error) {
658 KMP_FATAL(AffinityInvalidMask,
"kmp_set_affinity");
665 ga.Mask =
mask[group];
666 ga.Reserved[0] = ga.Reserved[1] = ga.Reserved[2] = 0;
669 if (__kmp_SetThreadGroupAffinity(GetCurrentThread(), &ga, NULL) == 0) {
670 DWORD
error = GetLastError();
671 if (abort_on_error) {
678 if (!SetThreadAffinityMask(GetCurrentThread(), *
mask)) {
679 DWORD
error = GetLastError();
680 if (abort_on_error) {
689 int get_system_affinity(
bool abort_on_error)
override {
690 if (__kmp_num_proc_groups > 1) {
694 if (__kmp_GetThreadGroupAffinity(GetCurrentThread(), &ga) == 0) {
695 DWORD
error = GetLastError();
696 if (abort_on_error) {
702 if ((ga.Group < 0) || (ga.Group > __kmp_num_proc_groups) ||
706 mask[ga.Group] = ga.Mask;
708 mask_t newMask, sysMask, retval;
709 if (!GetProcessAffinityMask(GetCurrentProcess(), &newMask, &sysMask)) {
710 DWORD
error = GetLastError();
711 if (abort_on_error) {
717 retval = SetThreadAffinityMask(GetCurrentThread(), newMask);
719 DWORD
error = GetLastError();
720 if (abort_on_error) {
726 newMask = SetThreadAffinityMask(GetCurrentThread(), retval);
728 DWORD
error = GetLastError();
729 if (abort_on_error) {
738 int get_proc_group()
const override {
740 if (__kmp_num_proc_groups == 1) {
743 for (
int i = 0;
i < __kmp_num_proc_groups;
i++) {
753 void determine_capable(
const char *env_var)
override {
757 KMPAffinity::Mask *allocate_mask()
override {
return new Mask(); }
758 void deallocate_mask(KMPAffinity::Mask *m)
override {
delete m; }
759 KMPAffinity::Mask *allocate_mask_array(
int num)
override {
760 return new Mask[num];
762 void deallocate_mask_array(KMPAffinity::Mask *array)
override {
763 Mask *windows_array =
static_cast<Mask *
>(array);
764 delete[] windows_array;
766 KMPAffinity::Mask *index_mask_array(KMPAffinity::Mask *array,
767 int index)
override {
768 Mask *windows_array =
static_cast<Mask *
>(array);
769 return &(windows_array[index]);
771 api_type get_api_type()
const override {
return NATIVE_OS; }
826#if KMP_AFFINITY_SUPPORTED
827 bool contains(
const kmp_affinity_attrs_t &attr)
const {
828 if (!
valid && !attr.valid)
830 if (
valid && attr.valid) {
848#if KMP_AFFINITY_SUPPORTED
900 int num_core_efficiencies;
922#if KMP_GROUP_AFFINITY
924 void _insert_windows_proc_groups();
930 void _gather_enumeration_information();
934 void _remove_radix1_layers();
937 void _discover_uniformity();
948 void _set_last_level_cache();
953 int _get_ncores_with_attr(
const kmp_hw_attr_t &attr,
int above,
954 bool find_all =
false)
const;
970 return hw_threads[index];
974 return hw_threads[index];
991 void canonicalize(
int pkgs,
int cores_per_pkg,
int thr_per_core,
int cores);
995#if KMP_AFFINITY_SUPPORTED
997 void set_granularity(kmp_affinity_t &stgs)
const;
998 bool is_close(
int hwt1,
int hwt2,
const kmp_affinity_t &stgs)
const;
999 bool restrict_to_mask(
const kmp_affin_mask_t *
mask);
1000 bool filter_hw_subset();
1008 return equivalent[
type];
1014 kmp_hw_t real_type2 = equivalent[type2];
1017 equivalent[type1] = real_type2;
1021 if (equivalent[
type] == type1) {
1022 equivalent[
type] = real_type2;
1038 return ratio[
level];
1043 return types[
level];
1047 int eq_type = equivalent[
type];
1050 for (
int i = 0;
i < depth; ++
i)
1051 if (types[
i] == eq_type)
1057 return count[
level];
1061 return _get_ncores_with_attr(attr, -1,
true);
1066 return _get_ncores_with_attr(attr, above,
false);
1069#if KMP_AFFINITY_SUPPORTED
1071 void sort_compact(kmp_affinity_t &affinity) {
1072 compact = affinity.compact;
1077 void print(
const char *env_var =
"KMP_AFFINITY")
const;
1095 const static int USE_ALL = (std::numeric_limits<int>::max)();
1107 static int hw_subset_compare(
const void *i1,
const void *i2) {
1112 return level1 - level2;
1124 int initial_capacity = 5;
1128 retval->capacity = initial_capacity;
1130 retval->absolute =
false;
1141 for (
int i = 0;
i < depth; ++
i) {
1145 int idx = items[
i].num_attrs++;
1146 if ((
size_t)idx >= MAX_ATTRS)
1148 items[
i].num[idx] = num;
1149 items[
i].offset[idx] = offset;
1150 items[
i].attr[idx] = attr;
1154 if (depth == capacity - 1) {
1157 for (
int i = 0;
i < depth; ++
i)
1158 new_items[
i] = items[
i];
1162 items[depth].num_attrs = 1;
1163 items[depth].type =
type;
1164 items[depth].num[0] = num;
1165 items[depth].offset[0] = offset;
1166 items[depth].attr[0] = attr;
1168 set |= (1ull <<
type);
1173 return items[index];
1177 return items[index];
1181 set &= ~(1ull << items[index].type);
1182 for (
int j = index + 1;
j < depth; ++
j) {
1183 items[
j - 1] = items[
j];
1189 qsort(items, depth,
sizeof(
item_t), hw_subset_compare);
1237 printf(
"**********************\n");
1238 printf(
"*** kmp_hw_subset: ***\n");
1239 printf(
"* depth: %d\n", depth);
1240 printf(
"* items:\n");
1241 for (
int i = 0;
i < depth; ++
i) {
1243 for (
int j = 0;
j < items[
i].num_attrs; ++
j) {
1244 printf(
" num: %d, offset: %d, attr: ", items[
i].num[
j],
1245 items[
i].offset[
j]);
1246 if (!items[
i].attr[
j]) {
1247 printf(
" (none)\n");
1250 " core_type = %s, core_eff = %d\n",
1252 items[
i].attr[
j].get_core_eff());
1256 printf(
"* set: 0x%llx\n", set);
1257 printf(
"* absolute: %d\n", absolute);
1258 printf(
"**********************\n");
1302 for (
int i = hier_depth - 1,
level = 0;
i >= 0; --
i, ++
level) {
1321 if (bool_result == 0) {
1376 branch = branch >> 1;
1394 while (bool_result == 0) {
1415 if (nproc > old_sz) {
1416 while (nproc > old_sz) {
kmp_uint32 * numPerLevel
Level 0 corresponds to leaves.
static const kmp_uint32 maxLeaves
kmp_uint32 * skipPerLevel
void resize(kmp_uint32 nproc)
kmp_uint32 base_num_threads
volatile kmp_int8 uninitialized
kmp_uint32 maxLevels
Number of levels in the hierarchy.
kmp_uint32 depth
This is specifically the depth of the machine configuration hierarchy, in terms of the number of leve...
volatile kmp_int8 resizing
static const kmp_uint32 minBranch
bool specified(kmp_hw_t type) const
void push_back(int num, kmp_hw_t type, int offset, kmp_hw_attr_t attr)
kmp_hw_subset_t(kmp_hw_subset_t &&t)=delete
void canonicalize(const kmp_topology_t *top)
static kmp_hw_subset_t * allocate()
static void deallocate(kmp_hw_subset_t *subset)
kmp_hw_subset_t(const kmp_hw_subset_t &t)=delete
const item_t & at(int index) const
kmp_hw_subset_t & operator=(kmp_hw_subset_t &&t)=delete
kmp_hw_subset_t & operator=(const kmp_hw_subset_t &t)=delete
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
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
const kmp_hw_thread_t & at(int index) const
void insert_layer(kmp_hw_t type, const int *ids)
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_topology_t & operator=(kmp_topology_t &&t)=delete
kmp_topology_t(const kmp_topology_t &t)=delete
kmp_hw_t get_type(int level) const
kmp_topology_t(kmp_topology_t &&t)=delete
kmp_topology_t & operator=(const kmp_topology_t &t)=delete
int get_ncores_with_attr(const kmp_hw_attr_t &attr) const
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 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 begin
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 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
#define KMP_HW_MAX_NUM_CORE_EFFS
#define KMP_FOREACH_HW_TYPE(type)
#define __kmp_entry_gtid()
const char * __kmp_hw_get_keyword(kmp_hw_t type, bool plural=false)
#define __kmp_allocate(size)
const char * __kmp_hw_get_core_type_string(kmp_hw_core_type_t type)
@ KMP_HW_MAX_NUM_CORE_TYPES
@ KMP_HW_CORE_TYPE_UNKNOWN
static void __kmp_type_convert(T1 src, T2 *dest)
#define KMP_DEBUG_ASSERT_VALID_HW_TYPE(type)
kmp_hw_subset_t * __kmp_hw_subset
kmp_topology_t * __kmp_topology
kmp_topology_t * __kmp_topology
KMP_ARCH_X86 KMP_ARCH_X86 KMP_ARCH_X86 kmp_int8
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
#define KMP_BUILD_ASSERT(expr)
#define KMP_DEBUG_ASSERT(cond)
#define KMP_ASSERT2(cond, msg)
unsigned long long kmp_uint64
void __kmp_fatal(kmp_msg_t message,...)
#define KMP_COMPARE_AND_STORE_ACQ8(p, cv, sv)
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 operator==(const kmp_hw_attr_t &rhs) const
bool is_core_eff_valid() const
bool operator!=(const kmp_hw_attr_t &rhs) const
kmp_hw_attr_t attr[MAX_ATTRS]
void __kmp_affinity_determine_capable(const char *env_var)
void __kmp_affinity_bind_thread(int proc)