1 /* This testcase is mostly the same as alloc-8.c.
2 However, on systems where the numa and/or memkind libraries are
3 installed, libgomp uses those. This test ensures that the minimal
4 features work. Note: No attempt has been made to verify the parition
5 hints interleaved and nearest as the kernal purposely ignore them once
6 in a while and it would also require a 'dlopen' dance.
8 memkind is used for omp_high_bw_mem_space, omp_large_cap_mem_space
9 and partition = interleaved, albeit it won't be interleaved for
10 omp_large_cap_mem_space.
12 numa is used for partition = nearest, unless memkind is used. */
18 const omp_alloctrait_t traits2
[]
19 = { { omp_atk_alignment
, 16 },
20 { omp_atk_sync_hint
, omp_atv_default
},
21 { omp_atk_access
, omp_atv_default
},
22 { omp_atk_pool_size
, 1024 },
23 { omp_atk_fallback
, omp_atv_default_mem_fb
},
24 { omp_atk_partition
, omp_atv_nearest
} };
25 omp_alloctrait_t traits3
[]
26 = { { omp_atk_sync_hint
, omp_atv_uncontended
},
27 { omp_atk_alignment
, 32 },
28 { omp_atk_access
, omp_atv_all
},
29 { omp_atk_pool_size
, 512 },
30 { omp_atk_fallback
, omp_atv_allocator_fb
},
31 { omp_atk_fb_data
, 0 },
32 { omp_atk_partition
, omp_atv_interleaved
} };
33 const omp_alloctrait_t traits4
[]
34 = { { omp_atk_alignment
, 128 },
35 { omp_atk_pool_size
, 1024 },
36 { omp_atk_fallback
, omp_atv_null_fb
} };
39 check_all_zero (void *ptr
, size_t len
)
41 char *p
= (char *) ptr
;
42 for (size_t i
= 0; i
< len
; i
++)
50 int *volatile p
= (int *) omp_aligned_calloc (sizeof (int), 3, sizeof (int), omp_high_bw_mem_alloc
);
51 check_all_zero (p
, 3*sizeof (int));
55 omp_alloctrait_t traits
[3]
56 = { { omp_atk_alignment
, 64 },
57 { omp_atk_fallback
, omp_atv_null_fb
},
58 { omp_atk_pool_size
, 4096 } };
59 omp_allocator_handle_t a
, a2
;
61 if ((((uintptr_t) p
) % __alignof (int)) != 0 || p
[0] || p
[1] || p
[2])
66 omp_free (p
, omp_high_bw_mem_alloc
);
67 p
= (int *) omp_aligned_calloc (2 * sizeof (int), 1, 2 * sizeof (int), omp_large_cap_mem_alloc
);
68 check_all_zero (p
, 2*sizeof (int));
69 if ((((uintptr_t) p
) % (2 * sizeof (int))) != 0 || p
[0] || p
[1])
73 omp_free (p
, omp_null_allocator
);
74 omp_set_default_allocator (omp_large_cap_mem_alloc
);
75 p
= (int *) omp_aligned_calloc (1, 1, sizeof (int), omp_null_allocator
);
76 check_all_zero (p
, sizeof (int));
77 if ((((uintptr_t) p
) % __alignof (int)) != 0 || p
[0])
80 omp_free (p
, omp_get_default_allocator ());
82 a
= omp_init_allocator (omp_large_cap_mem_space
, 3, traits
);
83 if (a
== omp_null_allocator
)
85 p
= (int *) omp_aligned_calloc (32, 3, 1024, a
);
86 check_all_zero (p
, 3*1024);
87 if ((((uintptr_t) p
) % 64) != 0)
89 for (i
= 0; i
< 3072 / sizeof (int); i
++)
93 p
[3071 / sizeof (int)] = 2;
94 if (omp_aligned_calloc (8, 192, 16, a
) != NULL
)
97 p
= (int *) omp_aligned_calloc (128, 6, 512, a
);
98 check_all_zero (p
, 6*512);
99 if ((((uintptr_t) p
) % 128) != 0)
101 for (i
= 0; i
< 3072 / sizeof (int); i
++)
105 p
[3071 / sizeof (int)] = 4;
106 omp_free (p
, omp_null_allocator
);
107 omp_set_default_allocator (a
);
108 if (omp_get_default_allocator () != a
)
110 p
= (int *) omp_aligned_calloc (64, 12, 256, omp_null_allocator
);
111 check_all_zero (p
, 12*256);
112 for (i
= 0; i
< 3072 / sizeof (int); i
++)
115 if (omp_aligned_calloc (8, 128, 24, omp_null_allocator
) != NULL
)
118 omp_destroy_allocator (a
);
120 a
= omp_init_allocator (omp_default_mem_space
,
121 sizeof (traits2
) / sizeof (traits2
[0]),
123 if (a
== omp_null_allocator
)
125 if (traits3
[5].key
!= omp_atk_fb_data
)
127 traits3
[5].value
= (uintptr_t) a
;
128 a2
= omp_init_allocator (omp_default_mem_space
,
129 sizeof (traits3
) / sizeof (traits3
[0]),
131 if (a2
== omp_null_allocator
)
133 p
= (int *) omp_aligned_calloc (4, 5, 84, a2
);
134 check_all_zero (p
, 5*84);
135 for (i
= 0; i
< 420 / sizeof (int); i
++)
138 if ((((uintptr_t) p
) % 32) != 0)
141 p
[419 / sizeof (int)] = 6;
142 q
= (int *) omp_aligned_calloc (8, 24, 32, a2
);
143 check_all_zero (q
, 24*32);
144 if ((((uintptr_t) q
) % 16) != 0)
146 for (i
= 0; i
< 768 / sizeof (int); i
++)
150 q
[767 / sizeof (int)] = 8;
151 r
= (int *) omp_aligned_calloc (8, 64, 8, a2
);
152 check_all_zero (r
, 64*8);
153 if ((((uintptr_t) r
) % 8) != 0)
155 for (i
= 0; i
< 512 / sizeof (int); i
++)
159 r
[511 / sizeof (int)] = 10;
160 omp_free (p
, omp_null_allocator
);
162 omp_free (r
, omp_null_allocator
);
163 omp_destroy_allocator (a2
);
164 omp_destroy_allocator (a
);
166 a
= omp_init_allocator (omp_high_bw_mem_space
,
167 sizeof (traits4
) / sizeof (traits4
[0]),
169 if (a
== omp_null_allocator
)
171 if (traits3
[5].key
!= omp_atk_fb_data
)
173 traits3
[5].value
= (uintptr_t) a
;
174 a2
= omp_init_allocator (omp_high_bw_mem_space
,
175 sizeof (traits3
) / sizeof (traits3
[0]),
177 if (a2
== omp_null_allocator
)
179 omp_set_default_allocator (a2
);
181 p
= static_cast <int *> (omp_aligned_calloc (4, 21, 20));
183 p
= (int *) omp_aligned_calloc (4, 21, 20, omp_null_allocator
);
185 check_all_zero (p
, 21*20);
186 if ((((uintptr_t) p
) % 32) != 0)
188 for (i
= 0; i
< 420 / sizeof (int); i
++)
192 p
[419 / sizeof (int)] = 6;
193 q
= (int *) omp_aligned_calloc (64, 12, 64, omp_null_allocator
);
194 check_all_zero (q
, 12*64);
195 if ((((uintptr_t) q
) % 128) != 0)
197 for (i
= 0; i
< 768 / sizeof (int); i
++)
201 q
[767 / sizeof (int)] = 8;
202 if (omp_aligned_calloc (8, 24, 32, omp_null_allocator
) != NULL
)
209 omp_free (p
, omp_null_allocator
);
210 omp_free (q
, omp_null_allocator
);
211 omp_free (NULL
, omp_null_allocator
);
213 omp_free (NULL
, omp_null_allocator
);
214 omp_destroy_allocator (a2
);
215 omp_destroy_allocator (a
);