diff options
author | Hafiz Abid Qadeer <abidh@codesourcery.com> | 2022-03-11 12:50:26 +0000 |
---|---|---|
committer | Hafiz Abid Qadeer <abidh@codesourcery.com> | 2022-03-11 23:03:59 +0000 |
commit | 37e77cae79aeb42052453c62d8ea95076f1e22d9 (patch) | |
tree | bc1401aeaa00e727217d9ee9a325c50e28f3a89b /libgomp/testsuite/libgomp.c/usm-6.c | |
parent | 3c40959d65df50c5afaf6f22aaca7fac8b39f36b (diff) | |
download | gcc-37e77cae79aeb42052453c62d8ea95076f1e22d9.tar.gz |
openmp: Use libgomp memory allocation functions with unified shared memory.
This patches changes calls to malloc/free/calloc/realloc/aligned_alloc and
operator new to memory allocation functions in libgomp with
allocator=ompx_unified_shared_mem_alloc. This helps existing code to benefit
from the unified shared memory. The libgomp does the correct thing with all
the mapping constructs and there is no memory copies if the pointer is pointing
to unified shared memory.
We only replace replacable new operator and not the class member or placement new.
Backport of a patch posted at
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591353.html
gcc/ChangeLog:
* omp-low.c (usm_transform): New function.
(make_pass_usm_transform): Likewise.
(class pass_usm_transform): New.
* passes.def: Add pass_usm_transform.
* tree-pass.h (make_pass_usm_transform): New declaration.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/usm-2.c: New test.
* c-c++-common/gomp/usm-3.c: New test.
* g++.dg/gomp/usm-1.C: New test.
* g++.dg/gomp/usm-2.C: New test.
* g++.dg/gomp/usm-3.C: New test.
* gfortran.dg/gomp/usm-2.f90: New test.
* gfortran.dg/gomp/usm-3.f90: New test.
libgomp/ChangeLog:
* testsuite/libgomp.c/usm-6.c: New test.
* testsuite/libgomp.c++/usm-1.C: Likewise.
Diffstat (limited to 'libgomp/testsuite/libgomp.c/usm-6.c')
-rw-r--r-- | libgomp/testsuite/libgomp.c/usm-6.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.c/usm-6.c b/libgomp/testsuite/libgomp.c/usm-6.c new file mode 100644 index 00000000000..d2c828fdc9d --- /dev/null +++ b/libgomp/testsuite/libgomp.c/usm-6.c @@ -0,0 +1,83 @@ +/* { dg-do run } */ +/* { dg-skip-if "Only valid for nvptx" { ! offload_target_nvptx } } */ + +#include <stdint.h> +#include <stdlib.h> + +/* On old systems, the declaraition may not be present in stdlib.h which + will generate a warning. This function is going to be replaced with + omp_aligned_alloc so the purpose of this declaration is to avoid that + warning. */ +void *aligned_alloc(size_t alignment, size_t size); + +#pragma omp requires unified_shared_memory + +int +main () +{ + int *a = (int *) malloc(sizeof(int)*2); + int *b = (int *) calloc(sizeof(int), 3); + int *c = (int *) realloc(NULL, sizeof(int) * 4); + int *d = (int *) aligned_alloc(32, sizeof(int)); + if (!a || !b || !c || !d) + __builtin_abort (); + + a[0] = 42; + a[1] = 43; + b[0] = 52; + b[1] = 53; + b[2] = 54; + c[0] = 62; + c[1] = 63; + c[2] = 64; + c[3] = 65; + + uintptr_t a_p = (uintptr_t)a; + uintptr_t b_p = (uintptr_t)b; + uintptr_t c_p = (uintptr_t)c; + uintptr_t d_p = (uintptr_t)d; + + if (d_p & 31 != 0) + __builtin_abort (); + +#pragma omp target enter data map(to:a[0:2]) + +#pragma omp target is_device_ptr(c) + { + if (a[0] != 42 || a_p != (uintptr_t)a) + __builtin_abort (); + if (b[0] != 52 || b[2] != 54 || b_p != (uintptr_t)b) + __builtin_abort (); + if (c[0] != 62 || c[3] != 65 || c_p != (uintptr_t)c) + __builtin_abort (); + if (d_p != (uintptr_t)d) + __builtin_abort (); + a[0] = 72; + b[0] = 82; + c[0] = 92; + } + +#pragma omp target + { + if (a[1] != 43 || a_p != (uintptr_t)a) + __builtin_abort (); + if (b[1] != 53 || b_p != (uintptr_t)b) + __builtin_abort (); + if (c[1] != 63 || c[2] != 64 || c_p != (uintptr_t)c) + __builtin_abort (); + a[1] = 73; + b[1] = 83; + c[1] = 93; + } + +#pragma omp target exit data map(delete:a[0:2]) + + if (a[0] != 72 || a[1] != 73 + || b[0] != 82 || b[1] != 83 + || c[0] != 92 || c[1] != 93) + __builtin_abort (); + free(a); + free(b); + free(c); + return 0; +} |