| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
/* Test calloc with omp_alloc. */ |
| 4 |
|
| 5 |
#include <omp.h> |
| 6 |
|
| 7 |
#pragma omp requires dynamic_allocators |
| 8 |
|
| 9 |
void |
| 10 |
test (int n, omp_allocator_handle_t allocator) |
| 11 |
{ |
| 12 |
#pragma omp target map(to:n) map(to:allocator) |
| 13 |
{ |
| 14 |
int *a; |
| 15 |
a = (int *) omp_calloc (n, sizeof (int), allocator); |
| 16 |
|
| 17 |
for (int i = 0; i < n; i++) |
| 18 |
if (a[i] != 0) |
| 19 |
{ |
| 20 |
__builtin_printf ("memory not zeroed at %i\n", i); |
| 21 |
__builtin_abort (); |
| 22 |
} |
| 23 |
|
| 24 |
#pragma omp parallel |
| 25 |
for (int i = 0; i < n; i++) |
| 26 |
a[i] = i; |
| 27 |
|
| 28 |
for (int i = 0; i < n; i++) |
| 29 |
if (a[i] != i) |
| 30 |
{ |
| 31 |
__builtin_printf ("data mismatch at %i\n", i); |
| 32 |
__builtin_abort (); |
| 33 |
} |
| 34 |
|
| 35 |
omp_free (a, allocator); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
int |
| 40 |
main () |
| 41 |
{ |
| 42 |
/* omp_low_lat_mem_alloc doesn't actually get low-latency memory on GPU. */ |
| 43 |
omp_alloctrait_t traits[1] = { { omp_atk_access, omp_atv_cgroup } }; |
| 44 |
omp_allocator_handle_t gpu_lowlat; |
| 45 |
#pragma omp target map(from:gpu_lowlat) |
| 46 |
gpu_lowlat = omp_init_allocator (omp_low_lat_mem_space, 1, traits); |
| 47 |
|
| 48 |
// Smaller than low-latency memory limit |
| 49 |
test (10, omp_default_mem_alloc); |
| 50 |
test (10, omp_large_cap_mem_alloc); |
| 51 |
test (10, omp_const_mem_alloc); |
| 52 |
test (10, omp_high_bw_mem_alloc); |
| 53 |
test (10, omp_low_lat_mem_alloc); |
| 54 |
test (10, gpu_lowlat); |
| 55 |
test (10, omp_cgroup_mem_alloc); |
| 56 |
test (10, omp_pteam_mem_alloc); |
| 57 |
test (10, omp_thread_mem_alloc); |
| 58 |
|
| 59 |
// Larger than low-latency memory limit |
| 60 |
test (100000, omp_default_mem_alloc); |
| 61 |
test (100000, omp_large_cap_mem_alloc); |
| 62 |
test (100000, omp_const_mem_alloc); |
| 63 |
test (100000, omp_high_bw_mem_alloc); |
| 64 |
test (100000, omp_low_lat_mem_alloc); |
| 65 |
test (100000, gpu_lowlat); |
| 66 |
test (100000, omp_cgroup_mem_alloc); |
| 67 |
test (100000, omp_pteam_mem_alloc); |
| 68 |
test (100000, omp_thread_mem_alloc); |
| 69 |
|
| 70 |
return 0; |
| 71 |
} |