]> git.ipfire.org Git - people/ms/gcc.git/commit
openmp, nvptx: ompx_unified_shared_mem_alloc
authorAndrew Stubbs <ams@codesourcery.com>
Fri, 11 Mar 2022 12:37:58 +0000 (12:37 +0000)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 28 Jun 2022 20:55:23 +0000 (13:55 -0700)
commit84914e197d91a67b3d27db0e4c69a433462983a5
tree8293ca6aa739258ed641768f3163db4220562d4c
parentfa65fc45972d27f2fd79a44eaba1978348177ee9
openmp, nvptx: ompx_unified_shared_mem_alloc

This adds support for using Cuda Managed Memory with omp_alloc.  It will be
used as the underpinnings for "requires unified_shared_memory" in a later
patch.

There are two new predefined allocators, ompx_unified_shared_mem_alloc and
ompx_host_mem_alloc, plus corresponding memory spaces, which can be used to
allocate memory in the "managed" space and explicitly on the host (it is
intended that "malloc" will be intercepted by the compiler).

The nvptx plugin is modified to make the necessary Cuda calls, and libgomp
is modified to switch to shared-memory mode for USM allocated mappings.

Backport of the patch posted at
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591352.html

libgomp/ChangeLog:
* allocator.c (omp_max_predefined_alloc): Update.
(omp_aligned_alloc): Don't fallback ompx_host_mem_alloc.
(omp_aligned_calloc): Likewise.
(omp_realloc): Likewise.
* config/linux/allocator.c (linux_memspace_alloc): Handle USM.
(linux_memspace_calloc): Handle USM.
(linux_memspace_free): Handle USM.
(linux_memspace_realloc): Handle USM.
* config/nvptx/allocator.c (nvptx_memspace_alloc): Reject
ompx_host_mem_alloc.
(nvptx_memspace_calloc): Likewise.
(nvptx_memspace_realloc): Likewise.
* libgomp-plugin.h (GOMP_OFFLOAD_usm_alloc): New prototype.
(GOMP_OFFLOAD_usm_free): New prototype.
(GOMP_OFFLOAD_is_usm_ptr): New prototype.
* libgomp.h (gomp_usm_alloc): New prototype.
(gomp_usm_free): New prototype.
(gomp_is_usm_ptr): New prototype.
(struct gomp_device_descr): Add USM functions.
* omp.h.in (omp_memspace_handle_t): Add ompx_unified_shared_mem_space
and ompx_host_mem_space.
(omp_allocator_handle_t): Add ompx_unified_shared_mem_alloc and
ompx_host_mem_alloc.
* omp_lib.f90.in: Likewise.
* plugin/plugin-nvptx.c (nvptx_alloc): Add "usm" parameter.
Call cuMemAllocManaged as appropriate.
(GOMP_OFFLOAD_alloc): Move internals to ...
(GOMP_OFFLOAD_alloc_1): ... this, and add usm parameter.
(GOMP_OFFLOAD_usm_alloc): New function.
(GOMP_OFFLOAD_usm_free): New function.
(GOMP_OFFLOAD_is_usm_ptr): New function.
* target.c (gomp_map_vars_internal): Add USM support.
(gomp_usm_alloc): New function.
(gomp_usm_free): New function.
(gomp_load_plugin_for_device): New function.
* testsuite/libgomp.c/usm-1.c: New test.
* testsuite/libgomp.c/usm-2.c: New test.
* testsuite/libgomp.c/usm-3.c: New test.
* testsuite/libgomp.c/usm-4.c: New test.
* testsuite/libgomp.c/usm-5.c: New test.
15 files changed:
libgomp/ChangeLog.omp
libgomp/allocator.c
libgomp/config/linux/allocator.c
libgomp/config/nvptx/allocator.c
libgomp/libgomp-plugin.h
libgomp/libgomp.h
libgomp/omp.h.in
libgomp/omp_lib.f90.in
libgomp/plugin/plugin-nvptx.c
libgomp/target.c
libgomp/testsuite/libgomp.c/usm-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/usm-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/usm-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/usm-4.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/usm-5.c [new file with mode: 0644]