22typedef int (*bget_compact_t)(size_t,
int);
23typedef void *(*bget_acquire_t)(size_t);
24typedef void (*bget_release_t)(
void *);
29#if KMP_ARCH_X86 || KMP_ARCH_ARM
35typedef ssize_t bufsize;
40typedef enum bget_mode {
46static void bpool(
kmp_info_t *th,
void *buffer, bufsize len);
49static void *bgetr(
kmp_info_t *th,
void *buffer, bufsize newsize);
51static void bectl(
kmp_info_t *th, bget_compact_t compact,
52 bget_acquire_t acquire, bget_release_t
release,
62#if KMP_ARCH_X86 || !KMP_HAVE_QUAD
65#define AlignType double
70#define AlignType _Quad
106static bufsize bget_bin_size[] = {
116 1 << 16, 1 << 17, 1 << 18, 1 << 19, 1 << 20,
124#define MAX_BGET_BINS (int)(sizeof(bget_bin_size) / sizeof(bufsize))
131typedef struct qlinks {
132 struct bfhead *flink;
133 struct bfhead *blink;
137typedef struct bhead2 {
148 char b_pad[
sizeof(bhead2_t) + (SizeQuant - (
sizeof(bhead2_t) % SizeQuant))];
151#define BH(p) ((bhead_t *)(p))
154typedef struct bdhead {
158#define BDH(p) ((bdhead_t *)(p))
161typedef struct bfhead {
165#define BFH(p) ((bfhead_t *)(p))
167typedef struct thr_data {
168 bfhead_t freelist[MAX_BGET_BINS];
173 long numpget, numprel;
174 long numdget, numdrel;
178 bget_compact_t compfcn;
179 bget_acquire_t acqfcn;
180 bget_release_t relfcn;
193#define QLSize (sizeof(qlinks_t))
194#define SizeQ ((SizeQuant > QLSize) ? SizeQuant : QLSize)
197 ~(((bufsize)(1) << (sizeof(bufsize) * CHAR_BIT - 1)) | (SizeQuant - 1)))
205 ((bufsize)(-(((((bufsize)1) << ((int)sizeof(bufsize) * 8 - 2)) - 1) * 2) - 2))
208static int bget_get_bin(bufsize
size) {
210 int lo = 0, hi = MAX_BGET_BINS - 1;
214 while ((hi - lo) > 1) {
215 int mid = (lo + hi) >> 1;
216 if (
size < bget_bin_size[mid])
231 data = (thr_data_t *)((!th->th.th_local.bget_data)
233 : th->th.th_local.bget_data);
237 for (
i = 0;
i < MAX_BGET_BINS; ++
i) {
238 data->freelist[
i].ql.flink = &
data->freelist[
i];
239 data->freelist[
i].ql.blink = &
data->freelist[
i];
242 th->th.th_local.bget_data =
data;
243 th->th.th_local.bget_list = 0;
244#if !USE_CMP_XCHG_FOR_BGET
245#ifdef USE_QUEUING_LOCK_FOR_BGET
253static thr_data_t *get_thr_data(
kmp_info_t *th) {
256 data = (thr_data_t *)th->th.th_local.bget_data;
264static void __kmp_bget_dequeue(
kmp_info_t *th) {
268#if USE_CMP_XCHG_FOR_BGET
270 volatile void *old_value =
TCR_SYNC_PTR(th->th.th_local.bget_list);
272 CCAST(
void *, old_value),
nullptr)) {
276 p =
CCAST(
void *, old_value);
279#ifdef USE_QUEUING_LOCK_FOR_BGET
285 p = (
void *)th->th.th_local.bget_list;
286 th->th.th_local.bget_list = 0;
288#ifdef USE_QUEUING_LOCK_FOR_BGET
298 bfhead_t *
b = BFH(((
char *)
p) -
sizeof(bhead_t));
305 p = (
void *)
b->ql.flink;
314#ifdef USE_QUEUING_LOCK_FOR_BGET
319 bfhead_t *
b = BFH(((
char *)
buf) -
sizeof(bhead_t));
327 KC_TRACE(10, (
"__kmp_bget_enqueue: moving buffer to T#%d list\n",
330#if USE_CMP_XCHG_FOR_BGET
332 volatile void *old_value =
TCR_PTR(th->th.th_local.bget_list);
335 b->ql.flink = BFH(
CCAST(
void *, old_value));
340 old_value =
TCR_PTR(th->th.th_local.bget_list);
343 b->ql.flink = BFH(
CCAST(
void *, old_value));
347#ifdef USE_QUEUING_LOCK_FOR_BGET
353 b->ql.flink = BFH(th->th.th_local.bget_list);
354 th->th.th_local.bget_list = (
void *)
buf;
356#ifdef USE_QUEUING_LOCK_FOR_BGET
365static void __kmp_bget_insert_into_freelist(thr_data_t *thr, bfhead_t *
b) {
371 bin = bget_get_bin(
b->bh.bb.bsize);
374 &thr->freelist[bin]);
376 &thr->freelist[bin]);
378 b->ql.flink = &thr->freelist[bin];
379 b->ql.blink = thr->freelist[bin].ql.blink;
381 thr->freelist[bin].ql.blink =
b;
382 b->ql.blink->ql.flink =
b;
386static void __kmp_bget_remove_from_freelist(bfhead_t *
b) {
390 b->ql.blink->ql.flink =
b->ql.flink;
391 b->ql.flink->ql.blink =
b->ql.blink;
395static void bcheck(
kmp_info_t *th, bufsize *max_free, bufsize *total_free) {
396 thr_data_t *thr = get_thr_data(th);
399 *total_free = *max_free = 0;
401 for (bin = 0; bin < MAX_BGET_BINS; ++bin) {
404 best = &thr->freelist[bin];
407 while (
b != &thr->freelist[bin]) {
408 *total_free += (
b->bh.bb.bsize -
sizeof(bhead_t));
409 if ((best == &thr->freelist[bin]) || (
b->bh.bb.bsize < best->bh.bb.bsize))
416 if (*max_free < best->bh.bb.bsize)
417 *max_free = best->bh.bb.bsize;
420 if (*max_free > (bufsize)
sizeof(bhead_t))
421 *max_free -=
sizeof(bhead_t);
425static void *bget(
kmp_info_t *th, bufsize requested_size) {
426 thr_data_t *thr = get_thr_data(th);
427 bufsize
size = requested_size;
435 if (
size < 0 ||
size +
sizeof(bhead_t) > MaxSize) {
439 __kmp_bget_dequeue(th);
441 if (
size < (bufsize)SizeQ) {
444#if defined(SizeQuant) && (SizeQuant > 1)
445 size = (
size + (SizeQuant - 1)) & (~(SizeQuant - 1));
448 size +=
sizeof(bhead_t);
452 use_blink = (thr->mode == bget_mode_lifo);
461 for (bin = bget_get_bin(
size); bin < MAX_BGET_BINS; ++bin) {
463 b = (use_blink ? thr->freelist[bin].ql.blink
464 : thr->freelist[bin].ql.flink);
466 if (thr->mode == bget_mode_best) {
467 best = &thr->freelist[bin];
471 while (
b != &thr->freelist[bin]) {
472 if (
b->bh.bb.bsize >= (bufsize)
size) {
473 if ((best == &thr->freelist[bin]) ||
474 (
b->bh.bb.bsize < best->bh.bb.bsize)) {
480 b = (use_blink ?
b->ql.blink :
b->ql.flink);
485 while (
b != &thr->freelist[bin]) {
486 if ((bufsize)
b->bh.bb.bsize >= (bufsize)
size) {
495 if ((
b->bh.bb.bsize - (bufsize)
size) >
496 (bufsize)(SizeQ + (
sizeof(bhead_t)))) {
499 ba = BH(((
char *)
b) + (
b->bh.bb.bsize - (bufsize)
size));
500 bn = BH(((
char *)ba) +
size);
505 b->bh.bb.bsize -= (bufsize)
size;
508 ba->bb.prevfree =
b->bh.bb.bsize;
511 ba->bb.bsize = -
size;
520 __kmp_bget_remove_from_freelist(
b);
521 __kmp_bget_insert_into_freelist(thr,
b);
523 thr->totalloc += (size_t)
size;
526 buf = (
void *)((((
char *)ba) +
sizeof(bhead_t)));
532 ba = BH(((
char *)
b) +
b->bh.bb.bsize);
539 __kmp_bget_remove_from_freelist(
b);
541 thr->totalloc += (size_t)
b->bh.bb.bsize;
545 b->bh.bb.bsize = -(
b->bh.bb.bsize);
554 buf = (
void *)&(
b->ql);
561 b = (use_blink ?
b->ql.blink :
b->ql.flink);
569 if ((thr->compfcn == 0) || (!(*thr->compfcn)(
size, ++compactseq))) {
577 if (thr->acqfcn != 0) {
578 if (
size > (bufsize)(thr->exp_incr -
sizeof(bhead_t))) {
583 size +=
sizeof(bdhead_t) -
sizeof(bhead_t);
588 bdh = BDH((*thr->acqfcn)((bufsize)
size));
592 bdh->bh.bb.bsize = 0;
597 bdh->bh.bb.prevfree = 0;
600 thr->totalloc += (size_t)
size;
604 buf = (
void *)(bdh + 1);
614 KE_TRACE(10, (
"%%%%%% MALLOCB( %d )\n", (
int)thr->exp_incr));
617 newpool = (*thr->acqfcn)((bufsize)thr->exp_incr);
619 if (newpool != NULL) {
620 bpool(th, newpool, thr->exp_incr);
638 char *
buf = (
char *)bget(th,
size);
644 b = BH(
buf -
sizeof(bhead_t));
645 rsize = -(
b->bb.bsize);
649 bd = BDH(
buf -
sizeof(bdhead_t));
650 rsize = bd->tsize - (bufsize)
sizeof(bdhead_t);
652 rsize -=
sizeof(bhead_t);
657 (
void)memset(
buf, 0, (bufsize)rsize);
659 return ((
void *)
buf);
672 nbuf = bget(th,
size);
679 b = BH(((
char *)
buf) -
sizeof(bhead_t));
680 osize = -
b->bb.bsize;
685 bd = BDH(((
char *)
buf) -
sizeof(bdhead_t));
686 osize = bd->tsize - (bufsize)
sizeof(bdhead_t);
688 osize -=
sizeof(bhead_t);
694 (
size_t)((
size < osize) ?
size : osize));
702 thr_data_t *thr = get_thr_data(th);
709 b = BFH(((
char *)
buf) -
sizeof(bhead_t));
711 if (
b->bh.bb.bsize == 0) {
714 bdh = BDH(((
char *)
buf) -
sizeof(bdhead_t));
717 thr->totalloc -= (size_t)bdh->tsize;
722 (
void)memset((
char *)
buf, 0x55, (
size_t)(bdh->tsize -
sizeof(bdhead_t)));
725 KE_TRACE(10, (
"%%%%%% FREE( %p )\n", (
void *)bdh));
728 (*thr->relfcn)((
void *)bdh);
736 __kmp_bget_enqueue(bth,
buf
737#ifdef USE_QUEUING_LOCK_FOR_BGET
746 if (
b->bh.bb.bsize >= 0) {
757 thr->totalloc += (size_t)
b->bh.bb.bsize;
762 if (
b->bh.bb.prevfree != 0) {
767 bufsize
size =
b->bh.bb.bsize;
772 b = BFH(((
char *)
b) -
b->bh.bb.prevfree);
773 b->bh.bb.bsize -=
size;
776 __kmp_bget_remove_from_freelist(
b);
781 b->bh.bb.bsize = -
b->bh.bb.bsize;
785 __kmp_bget_insert_into_freelist(thr,
b);
791 bn = BFH(((
char *)
b) +
b->bh.bb.bsize);
792 if (bn->bh.bb.bsize > 0) {
799 __kmp_bget_remove_from_freelist(bn);
801 b->bh.bb.bsize += bn->bh.bb.bsize;
805 __kmp_bget_remove_from_freelist(
b);
806 __kmp_bget_insert_into_freelist(thr,
b);
814 bn = BFH(((
char *)
b) +
b->bh.bb.bsize);
817 (
void)memset(((
char *)
b) +
sizeof(bfhead_t), 0x55,
818 (
size_t)(
b->bh.bb.bsize -
sizeof(bfhead_t)));
825 bn->bh.bb.prevfree =
b->bh.bb.bsize;
831 if (thr->relfcn != 0 &&
832 b->bh.bb.bsize == (bufsize)(thr->pool_len -
sizeof(bhead_t))) {
844 __kmp_bget_remove_from_freelist(
b);
846 KE_TRACE(10, (
"%%%%%% FREE( %p )\n", (
void *)
b));
855 if (thr->last_pool ==
b)
865static void bectl(
kmp_info_t *th, bget_compact_t compact,
866 bget_acquire_t acquire, bget_release_t
release,
868 thr_data_t *thr = get_thr_data(th);
870 thr->compfcn = compact;
871 thr->acqfcn = acquire;
873 thr->exp_incr = pool_incr;
879 thr_data_t *thr = get_thr_data(th);
880 bfhead_t *
b = BFH(
buf);
883 __kmp_bget_dequeue(th);
886 len &= ~((bufsize)(SizeQuant - 1));
888 if (thr->pool_len == 0) {
890 }
else if (len != thr->pool_len) {
907 b->bh.bb.prevfree = 0;
916 len -=
sizeof(bhead_t);
917 b->bh.bb.bsize = (bufsize)len;
924 __kmp_bget_insert_into_freelist(thr,
b);
927 (
void)memset(((
char *)
b) +
sizeof(bfhead_t), 0x55,
928 (
size_t)(len -
sizeof(bfhead_t)));
930 bn = BH(((
char *)
b) + len);
931 bn->bb.prevfree = (bufsize)len;
935 bn->bb.bsize = ESent;
940 int bin = 0,
count = 0;
942 thr_data_t *thr = get_thr_data(th);
946 " get=%" KMP_INT64_SPEC
" rel=%" KMP_INT64_SPEC
947 " pblk=%" KMP_INT64_SPEC
" pget=%" KMP_INT64_SPEC
948 " prel=%" KMP_INT64_SPEC
" dget=%" KMP_INT64_SPEC
949 " drel=%" KMP_INT64_SPEC
"\n",
956 for (bin = 0; bin < MAX_BGET_BINS; ++bin) {
959 for (
b = thr->freelist[bin].ql.flink;
b != &thr->freelist[bin];
961 bufsize bs =
b->bh.bb.bsize;
970 "__kmp_printpool: T#%d Free block: 0x%p size %6ld bytes.\n", gtid,
b,
974 char *lerr = ((
char *)
b) +
sizeof(bfhead_t);
975 if ((bs >
sizeof(bfhead_t)) &&
977 (memcmp(lerr, lerr + 1, (
size_t)(bs - (
sizeof(bfhead_t) + 1))) !=
980 "free block have been overstored.)\n",
997 bectl(th, (bget_compact_t)0, (bget_acquire_t)malloc, (bget_release_t)free,
1008 thr = (thr_data_t *)th->th.th_local.bget_data;
1017 if (thr->relfcn != 0 &&
b != 0 && thr->numpblk != 0 &&
1018 b->bh.bb.bsize == (bufsize)(thr->pool_len -
sizeof(bhead_t))) {
1025 __kmp_bget_remove_from_freelist(
b);
1027 KE_TRACE(10, (
"%%%%%% FREE( %p )\n", (
void *)
b));
1037 if (th->th.th_local.bget_data != NULL) {
1039 th->th.th_local.bget_data = NULL;
1043void kmpc_set_poolsize(
size_t size) {
1045 (bget_release_t)free, (bufsize)
size);
1048size_t kmpc_get_poolsize(
void) {
1056void kmpc_set_poolmode(
int mode) {
1059 if (
mode == bget_mode_fifo ||
mode == bget_mode_lifo ||
1060 mode == bget_mode_best) {
1062 p->mode = (bget_mode_t)
mode;
1066int kmpc_get_poolmode(
void) {
1074void kmpc_get_poolstat(
size_t *maxmem,
size_t *allmem) {
1078 __kmp_bget_dequeue(th);
1086void kmpc_poolprint(
void) {
1089 __kmp_bget_dequeue(th);
1101 *(
void **)ptr = ptr;
1102 ptr = (
void **)ptr + 1;
1107#define IS_POWER_OF_TWO(n) (((n) & ((n)-1)) == 0)
1111 void *ptr_allocated;
1120 if (ptr_allocated != NULL) {
1124 *((
void **)ptr - 1) = ptr_allocated;
1136 *(
void **)ptr = ptr;
1137 ptr = (
void **)ptr + 1;
1152 }
else if (
size == 0) {
1162 (bufsize)(
size +
sizeof(ptr)));
1178 __kmp_bget_dequeue(th);
1181 brel(th, *((
void **)ptr - 1));
1187 KE_TRACE(30, (
"-> __kmp_thread_malloc( %p, %d ) called from %s:%d\n", th,
1189 ptr = bget(th, (bufsize)
size);
1190 KE_TRACE(30, (
"<- __kmp_thread_malloc() returns %p\n", ptr));
1197 KE_TRACE(30, (
"-> __kmp_thread_calloc( %p, %d, %d ) called from %s:%d\n", th,
1199 ptr = bgetz(th, (bufsize)(nelem * elsize));
1200 KE_TRACE(30, (
"<- __kmp_thread_calloc() returns %p\n", ptr));
1206 KE_TRACE(30, (
"-> __kmp_thread_realloc( %p, %p, %d ) called from %s:%d\n", th,
1208 ptr = bgetr(th, ptr, (bufsize)
size);
1209 KE_TRACE(30, (
"<- __kmp_thread_realloc() returns %p\n", ptr));
1214 KE_TRACE(30, (
"-> __kmp_thread_free( %p, %p ) called from %s:%d\n", th,
1217 __kmp_bget_dequeue(th);
1220 KE_TRACE(30, (
"<- __kmp_thread_free()\n"));
1228static void *(*kmp_mk_alloc)(
void *k,
size_t sz);
1245static void *(*kmp_target_alloc_host)(
size_t size,
int device);
1246static void *(*kmp_target_alloc_shared)(
size_t size,
int device);
1247static void *(*kmp_target_alloc_device)(
size_t size,
int device);
1248static void *(*kmp_target_lock_mem)(
void *ptr,
size_t size,
int device);
1249static void *(*kmp_target_unlock_mem)(
void *ptr,
int device);
1250static void *(*kmp_target_free_host)(
void *ptr,
int device);
1251static void *(*kmp_target_free_shared)(
void *ptr,
int device);
1252static void *(*kmp_target_free_device)(
void *ptr,
int device);
1254#define KMP_IS_TARGET_MEM_SPACE(MS) \
1255 (MS == llvm_omp_target_host_mem_space || \
1256 MS == llvm_omp_target_shared_mem_space || \
1257 MS == llvm_omp_target_device_mem_space)
1258#define KMP_IS_TARGET_MEM_ALLOC(MA) \
1259 (MA == llvm_omp_target_host_mem_alloc || \
1260 MA == llvm_omp_target_shared_mem_alloc || \
1261 MA == llvm_omp_target_device_mem_alloc)
1263#if KMP_OS_UNIX && KMP_DYNAMIC_LIB && !KMP_OS_DARWIN
1264static inline void chk_kind(
void ***pkind) {
1274#if KMP_OS_UNIX && KMP_DYNAMIC_LIB && !KMP_OS_DARWIN
1281 (
void *(*)(
void *,
size_t))dlsym(
h_memkind,
"memkind_malloc");
1300 (
void **)dlsym(
h_memkind,
"MEMKIND_HBW_PREFERRED_HUGETLB");
1307 (
void **)dlsym(
h_memkind,
"MEMKIND_DAX_KMEM_PREFERRED");
1309 KE_TRACE(25, (
"__kmp_init_memkind: memkind library initialized\n"));
1335#if KMP_OS_UNIX && KMP_DYNAMIC_LIB
1337 KE_TRACE(25, (
"__kmp_fini_memkind: finalize memkind library\n"));
1362 KMP_DLSYM(
"llvm_omp_target_alloc_shared");
1364 KMP_DLSYM(
"llvm_omp_target_alloc_device");
1367 KMP_DLSYM(
"llvm_omp_target_free_shared");
1369 KMP_DLSYM(
"llvm_omp_target_free_device");
1390 for (
i = 0;
i < ntraits; ++
i) {
1391 switch (traits[
i].
key) {
1504 KE_TRACE(25, (
"__kmpc_alloc: T#%d (%d, %p)\n", gtid, (
int)
size, allocator));
1506 KE_TRACE(25, (
"__kmpc_alloc returns %p, T#%d\n", ptr, gtid));
1512 KE_TRACE(25, (
"__kmpc_aligned_alloc: T#%d (%d, %d, %p)\n", gtid, (
int)algn,
1513 (
int)
size, allocator));
1515 KE_TRACE(25, (
"__kmpc_aligned_alloc returns %p, T#%d\n", ptr, gtid));
1521 KE_TRACE(25, (
"__kmpc_calloc: T#%d (%d, %d, %p)\n", gtid, (
int)nmemb,
1522 (
int)
size, allocator));
1524 KE_TRACE(25, (
"__kmpc_calloc returns %p, T#%d\n", ptr, gtid));
1531 KE_TRACE(25, (
"__kmpc_realloc: T#%d (%p, %d, %p, %p)\n", gtid, ptr, (
int)
size,
1532 allocator, free_allocator));
1534 KE_TRACE(25, (
"__kmpc_realloc returns %p, T#%d\n", nptr, gtid));
1539 KE_TRACE(25, (
"__kmpc_free: T#%d free(%p,%p)\n", gtid, ptr, allocator));
1541 KE_TRACE(10, (
"__kmpc_free: T#%d freed %p (%p)\n", gtid, ptr, allocator));
1556 __kmp_threads[gtid]->th.th_current_task->td_icvs.default_device;
1572 bool is_pinned =
false;
1584 __kmp_threads[gtid]->th.th_current_task->td_icvs.default_device;
1600 __kmp_threads[gtid]->th.th_current_task->td_icvs.default_device;
1684 KMP_WARNING(OmpNoAllocator,
"omp_high_bw_mem_alloc");
1686 KMP_WARNING(OmpNoAllocator,
"omp_large_cap_mem_alloc");
1688 KMP_WARNING(OmpNoAllocator,
"omp_const_mem_alloc");
1690 KMP_WARNING(OmpNoAllocator,
"omp_low_lat_mem_alloc");
1692 KMP_WARNING(OmpNoAllocator,
"omp_cgroup_mem_alloc");
1694 KMP_WARNING(OmpNoAllocator,
"omp_pteam_mem_alloc");
1696 KMP_WARNING(OmpNoAllocator,
"omp_thread_mem_alloc");
1698 use_default_allocator =
true;
1700 if (use_default_allocator) {
1702 use_default_allocator =
false;
1738 KE_TRACE(10, (
"__kmp_alloc: T#%d %p=alloc(%d)\n", gtid, ptr, desc.
size_a));
1746 addr_align = (
addr + sz_desc + align - 1) & ~(align - 1);
1747 addr_descr = addr_align - sz_desc;
1769 if (nmemb == 0 ||
size == 0)
1782 memset(ptr, 0x00, nmemb *
size);
1801 if (nptr != NULL && ptr != NULL) {
1838 __kmp_threads[gtid]->th.th_current_task->td_icvs.default_device;
1863 __kmp_threads[gtid]->th.th_current_task->td_icvs.default_device;
1935 KE_TRACE(25, (
"-> ___kmp_allocate_align( %d, %d ) called from %s:%d\n",
1964 KE_TRACE(26, (
" ___kmp_allocate_align: "
1965 "ptr_allocated=%p, size_allocated=%d, "
1966 "ptr_aligned=%p, size_aligned=%d\n",
1999 KE_TRACE(25, (
"-> __kmp_allocate( %d ) called from %s:%d\n",
2002 KE_TRACE(25, (
"<- __kmp_allocate() returns %p\n", ptr));
2011 int page_size = 8 * 1024;
2014 KE_TRACE(25, (
"-> __kmp_page_allocate( %d ) called from %s:%d\n",
2017 KE_TRACE(25, (
"<- __kmp_page_allocate( %d ) returns %p\n", (
int)
size, ptr));
2036 "ptr_allocated=%p, size_allocated=%d, "
2037 "ptr_aligned=%p, size_aligned=%d\n",
2062 KE_TRACE(25, (
"<- __kmp_free() returns\n"));
2065#if USE_FAST_MEMORY == 3
2071#define KMP_FREE_LIST_LIMIT 16
2074#define DCACHE_LINE 128
2078 size_t num_lines, idx;
2084 KE_TRACE(25, (
"-> __kmp_fast_allocate( T#%d, %d ) called from %s:%d\n",
2087 num_lines = (
size + DCACHE_LINE - 1) / DCACHE_LINE;
2088 idx = num_lines - 1;
2093 }
else if ((idx >>= 2) == 0) {
2096 }
else if ((idx >>= 2) == 0) {
2099 }
else if ((idx >>= 2) == 0) {
2106 ptr = this_thr->th.th_free_lists[index].th_free_list_self;
2109 this_thr->th.th_free_lists[index].th_free_list_self = *((
void **)ptr);
2115 ptr =
TCR_SYNC_PTR(this_thr->th.th_free_lists[index].th_free_list_sync);
2121 &this_thr->th.th_free_lists[index].th_free_list_sync, ptr,
nullptr)) {
2123 ptr =
TCR_SYNC_PTR(this_thr->th.th_free_lists[index].th_free_list_sync);
2127 this_thr->th.th_free_lists[index].th_free_list_self = *((
void **)ptr);
2136 size = num_lines * DCACHE_LINE;
2139 KE_TRACE(25, (
"__kmp_fast_allocate: T#%d Calling __kmp_thread_malloc with "
2142 alloc_ptr = bget(this_thr, (bufsize)alloc_size);
2147 ~(DCACHE_LINE - 1));
2158 KE_TRACE(25, (
"<- __kmp_fast_allocate( T#%d ) returns %p\n",
2172 KE_TRACE(25, (
"-> __kmp_fast_free( T#%d, %p ) called from %s:%d\n",
2178 KE_TRACE(26, (
" __kmp_fast_free: size_aligned=%d\n",
2183 idx = DCACHE_LINE * 2;
2186 }
else if ((idx <<= 1) ==
size) {
2188 }
else if ((idx <<= 2) ==
size) {
2190 }
else if ((idx <<= 2) ==
size) {
2198 if (alloc_thr == this_thr) {
2200 *((
void **)ptr) = this_thr->th.th_free_lists[index].th_free_list_self;
2201 this_thr->th.th_free_lists[index].th_free_list_self = ptr;
2203 void *
head = this_thr->th.th_free_lists[index].th_free_list_other;
2206 this_thr->th.th_free_lists[index].th_free_list_other = ptr;
2207 *((
void **)ptr) = NULL;
2217 if (q_th == alloc_thr && q_sz <= KMP_FREE_LIST_LIMIT) {
2219 *((
void **)ptr) =
head;
2221 this_thr->th.th_free_lists[index].th_free_list_other = ptr;
2228 void *next = *((
void **)
head);
2229 while (next != NULL) {
2238 next = *((
void **)next);
2242 old_ptr =
TCR_PTR(q_th->th.th_free_lists[index].th_free_list_sync);
2245 *((
void **)
tail) = old_ptr;
2248 &q_th->th.th_free_lists[index].th_free_list_sync, old_ptr,
head)) {
2250 old_ptr =
TCR_PTR(q_th->th.th_free_lists[index].th_free_list_sync);
2251 *((
void **)
tail) = old_ptr;
2255 this_thr->th.th_free_lists[index].th_free_list_other = ptr;
2256 *((
void **)ptr) = NULL;
2264 KE_TRACE(25, (
"__kmp_fast_free: T#%d Calling __kmp_thread_free for size %d\n",
2266 __kmp_bget_dequeue(this_thr);
2270 KE_TRACE(25, (
"<- __kmp_fast_free() returns\n"));
2276void __kmp_initialize_fast_memory(
kmp_info_t *this_thr) {
2277 KE_TRACE(10, (
"__kmp_initialize_fast_memory: Called from th %p\n", this_thr));
2279 memset(this_thr->th.th_free_lists, 0, NUM_LISTS *
sizeof(kmp_free_list_t));
2287 thr_data_t *thr = get_thr_data(th);
2293 __kmp_bget_dequeue(th);
2296 for (bin = 0; bin < MAX_BGET_BINS; ++bin) {
2297 bfhead_t *
b = thr->freelist[bin].ql.flink;
2298 while (
b != &thr->freelist[bin]) {
2307 while (lst != NULL) {
2309 KE_TRACE(10, (
"__kmp_free_fast_memory: freeing %p, next=%p th %p (%d)\n",
2311 (*thr->relfcn)(lst);
2317 lst = (
void **)next;
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 * data
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 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 mode
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 head
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 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 tail
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
int __kmp_memkind_available
omp_memspace_handle_t const omp_default_mem_space
void * omp_memspace_handle_t
void * omp_allocator_handle_t
omp_allocator_handle_t const omp_cgroup_mem_alloc
omp_memspace_handle_t const llvm_omp_target_host_mem_space
omp_memspace_handle_t const omp_low_lat_mem_space
#define __kmp_get_thread()
omp_allocator_handle_t const omp_default_mem_alloc
omp_allocator_handle_t const omp_large_cap_mem_alloc
omp_allocator_handle_t const omp_low_lat_mem_alloc
omp_allocator_handle_t const omp_high_bw_mem_alloc
omp_memspace_handle_t const omp_const_mem_space
static kmp_info_t * __kmp_entry_thread()
#define __kmp_thread_malloc(th, size)
omp_memspace_handle_t const omp_large_cap_mem_space
kmp_info_t ** __kmp_threads
void __kmp_finalize_bget(kmp_info_t *th)
omp_memspace_handle_t const llvm_omp_target_shared_mem_space
omp_memspace_handle_t const omp_high_bw_mem_space
omp_allocator_handle_t const omp_const_mem_alloc
omp_allocator_handle_t const omp_pteam_mem_alloc
omp_allocator_handle_t const llvm_omp_target_host_mem_alloc
omp_allocator_handle_t const kmp_max_mem_alloc
#define __kmp_allocate(size)
size_t __kmp_malloc_pool_incr
omp_allocator_handle_t const omp_thread_mem_alloc
void __kmp_initialize_bget(kmp_info_t *th)
static kmp_info_t * __kmp_thread_from_gtid(int gtid)
static int __kmp_gtid_from_thread(const kmp_info_t *thr)
omp_allocator_handle_t const llvm_omp_target_shared_mem_alloc
volatile int __kmp_init_serial
static void __kmp_type_convert(T1 src, T2 *dest)
union KMP_ALIGN_CACHE kmp_info kmp_info_t
omp_allocator_handle_t const llvm_omp_target_device_mem_alloc
omp_allocator_handle_t const omp_null_allocator
#define __kmp_thread_free(th, ptr)
void ___kmp_thread_free(kmp_info_t *th, void *ptr KMP_SRC_LOC_DECL)
void * __kmpc_alloc(int gtid, size_t size, omp_allocator_handle_t allocator)
static void ** mk_hbw_interleave
struct kmp_mem_desc kmp_mem_desc_t
static void ** mk_interleave
#define IS_POWER_OF_TWO(n)
void __kmp_init_target_mem()
static void ** mk_dax_kmem
static void *(* kmp_target_unlock_mem)(void *ptr, int device)
static void ** mk_dax_kmem_all
void kmpc_free(void *ptr)
static void *(* kmp_target_free_shared)(void *ptr, int device)
omp_allocator_handle_t __kmpc_get_default_allocator(int gtid)
void __kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator)
#define KMP_IS_TARGET_MEM_ALLOC(MA)
void * __kmpc_calloc(int gtid, size_t nmemb, size_t size, omp_allocator_handle_t allocator)
void * kmpc_malloc(size_t size)
static void ** mk_hugetlb
static void ** mk_hbw_preferred
static const char * kmp_mk_lib_name
static bool __kmp_target_mem_available
void * kmpc_calloc(size_t nelem, size_t elsize)
static void *(* kmp_target_alloc_shared)(size_t size, int device)
static void *(* kmp_target_free_device)(void *ptr, int device)
static void ** mk_dax_kmem_preferred
static void *(* kmp_mk_alloc)(void *k, size_t sz)
struct kmp_mem_descr kmp_mem_descr_t
#define KMP_IS_TARGET_MEM_SPACE(MS)
void * ___kmp_thread_malloc(kmp_info_t *th, size_t size KMP_SRC_LOC_DECL)
static int(* kmp_mk_check)(void *kind)
void __kmp_init_memkind()
void ___kmpc_free(int gtid, void *ptr, omp_allocator_handle_t allocator)
void * ___kmp_page_allocate(size_t size KMP_SRC_LOC_DECL)
void __kmpc_destroy_allocator(int gtid, omp_allocator_handle_t allocator)
void * __kmp_realloc(int gtid, void *ptr, size_t size, omp_allocator_handle_t allocator, omp_allocator_handle_t free_allocator)
static void *(* kmp_target_free_host)(void *ptr, int device)
static void ** mk_hbw_hugetlb
void __kmpc_set_default_allocator(int gtid, omp_allocator_handle_t allocator)
void * kmpc_realloc(void *ptr, size_t size)
static void *(* kmp_target_lock_mem)(void *ptr, size_t size, int device)
void * __kmpc_aligned_alloc(int gtid, size_t algn, size_t size, omp_allocator_handle_t allocator)
void * ___kmp_thread_realloc(kmp_info_t *th, void *ptr, size_t size KMP_SRC_LOC_DECL)
void * ___kmp_allocate(size_t size KMP_SRC_LOC_DECL)
static void ** mk_default
void * __kmpc_realloc(int gtid, void *ptr, size_t size, omp_allocator_handle_t allocator, omp_allocator_handle_t free_allocator)
omp_allocator_handle_t __kmpc_init_allocator(int gtid, omp_memspace_handle_t ms, int ntraits, omp_alloctrait_t traits[])
static void(* kmp_mk_free)(void *kind, void *ptr)
void * __kmp_alloc(int gtid, size_t algn, size_t size, omp_allocator_handle_t allocator)
static void ** mk_hbw_preferred_hugetlb
void * ___kmp_thread_calloc(kmp_info_t *th, size_t nelem, size_t elsize KMP_SRC_LOC_DECL)
void * kmpc_aligned_malloc(size_t size, size_t alignment)
void __kmp_fini_memkind()
static void *(* kmp_target_alloc_device)(size_t size, int device)
static void * ___kmp_allocate_align(size_t size, size_t alignment KMP_SRC_LOC_DECL)
static void *(* kmp_target_alloc_host)(size_t size, int device)
void ___kmp_free(void *ptr KMP_SRC_LOC_DECL)
void * __kmp_calloc(int gtid, size_t algn, size_t nmemb, size_t size, omp_allocator_handle_t allocator)
#define KMP_DEBUG_ASSERT(cond)
#define KMP_ASSERT2(cond, msg)
unsigned long long kmp_uint64
void __kmp_printf_no_lock(char const *format,...)
static void __kmp_release_bootstrap_lock(kmp_bootstrap_lock_t *lck)
static int __kmp_acquire_lock(kmp_lock_t *lck, kmp_int32 gtid)
static void __kmp_init_lock(kmp_lock_t *lck)
static int __kmp_acquire_bootstrap_lock(kmp_bootstrap_lock_t *lck)
static void __kmp_release_lock(kmp_lock_t *lck, kmp_int32 gtid)
static void __kmp_init_bootstrap_lock(kmp_bootstrap_lock_t *lck)
#define KMP_TEST_THEN_ADD64(p, v)
unsigned long kmp_uintptr_t
#define KMP_COMPARE_AND_STORE_PTR(p, cv, sv)
#define _malloc_src_loc(size)
#define malloc_src_loc(args)
#define _free_src_loc(ptr)
#define free_src_loc(args)
kmp_allocator_t * fb_data
omp_alloctrait_value_t fb
omp_memspace_handle_t memspace
kmp_allocator_t * allocator