]> git.ipfire.org Git - thirdparty/gcc.git/commit
libgomp, nvptx: Cuda pinned memory
authorAndrew Stubbs <ams@baylibre.com>
Fri, 18 Apr 2025 21:48:33 +0000 (21:48 +0000)
committerSandra Loosemore <sloosemore@baylibre.com>
Thu, 15 May 2025 20:25:47 +0000 (20:25 +0000)
commit86086c93cddee91aa5a5deda1f1a0ade0d868d66
treee0df606da56642a630c601b9376a325399908989
parente13ab24bf919a7c4dc30dcfc9fafa9c6349a90a7
libgomp, nvptx: Cuda pinned memory

https://patchwork.sourceware.org/project/gcc/list/?series=35022

This patch was already approved, in the v3 posting by Tobias Burnus
(with one caveat about initialization location), but wasn't committed at
that time as I didn't want to disentangle it from the textual
dependencies on the other patches in the series.

------

Use Cuda to pin memory, instead of Linux mlock, when available.

There are two advantages: firstly, this gives a significant speed boost for
NVPTX offloading, and secondly, it side-steps the usual OS ulimit/rlimit
setting.

The design adds a device independent plugin API for allocating pinned memory,
and then implements it for NVPTX.  At present, the other supported devices do
not have equivalent capabilities (or requirements).

libgomp/ChangeLog:

* config/linux/allocator.c: Include assert.h.
(using_device_for_page_locked): New variable.
(linux_memspace_alloc): Add init0 parameter. Support device pinning.
(linux_memspace_calloc): Set init0 to true.
(linux_memspace_free): Support device pinning.
(linux_memspace_realloc): Support device pinning.
(MEMSPACE_ALLOC): Set init0 to false.
* libgomp-plugin.h
(GOMP_OFFLOAD_page_locked_host_alloc): New prototype.
(GOMP_OFFLOAD_page_locked_host_free): Likewise.
* libgomp.h (gomp_page_locked_host_alloc): Likewise.
(gomp_page_locked_host_free): Likewise.
(struct gomp_device_descr): Add page_locked_host_alloc_func and
page_locked_host_free_func.
* libgomp.texi: Adjust the docs for the pinned trait.
* libgomp_g.h (GOMP_enable_pinned_mode): New prototype.
* plugin/plugin-nvptx.c
(GOMP_OFFLOAD_page_locked_host_alloc): New function.
(GOMP_OFFLOAD_page_locked_host_free): Likewise.
* target.c (device_for_page_locked): New variable.
(get_device_for_page_locked): New function.
(gomp_page_locked_host_alloc): Likewise.
(gomp_page_locked_host_free): Likewise.
(gomp_load_plugin_for_device): Add page_locked_host_alloc and
page_locked_host_free.
* testsuite/libgomp.c/alloc-pinned-1.c: Change expectations for NVPTX
devices.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-6.c: Likewise.

Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com>
13 files changed:
libgomp/config/linux/allocator.c
libgomp/libgomp-plugin.h
libgomp/libgomp.h
libgomp/libgomp.texi
libgomp/libgomp_g.h
libgomp/plugin/plugin-nvptx.c
libgomp/target.c
libgomp/testsuite/libgomp.c/alloc-pinned-1.c
libgomp/testsuite/libgomp.c/alloc-pinned-2.c
libgomp/testsuite/libgomp.c/alloc-pinned-3.c
libgomp/testsuite/libgomp.c/alloc-pinned-4.c
libgomp/testsuite/libgomp.c/alloc-pinned-5.c
libgomp/testsuite/libgomp.c/alloc-pinned-6.c