Debian Codegraph @

libgomp/testsuite/libgomp.c/omp_alloc-1.c

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