diff options
author | Andrew Stubbs <ams@codesourcery.com> | 2022-03-11 12:58:38 +0000 |
---|---|---|
committer | Kwok Cheung Yeung <kcy@codesourcery.com> | 2022-06-28 13:55:23 -0700 |
commit | 842df187487f5b16ae29bbe7e9acd79661a9df48 (patch) | |
tree | d939366ebafbafefef4e8c5b3943fa5a39dd9a21 /gcc | |
parent | 54c2d861ac62e30ebf34a4e62ee0d55478a742b9 (diff) | |
download | gcc-842df187487f5b16ae29bbe7e9acd79661a9df48.zip gcc-842df187487f5b16ae29bbe7e9acd79661a9df48.tar.gz gcc-842df187487f5b16ae29bbe7e9acd79661a9df48.tar.bz2 |
openmp: -foffload-memory=pinned
Implement the -foffload-memory=pinned option such that libgomp is
instructed to enable fully-pinned memory at start-up. The option is
intended to provide a performance boost to certain offload programs without
modifying the code.
This feature only works on Linux, at present, and simply calls mlockall to
enable always-on memory pinning. It requires that the ulimit feature is
set high enough to accommodate all the program's memory usage.
In this mode the ompx_pinned_memory_alloc feature is disabled as it is not
needed and may conflict.
Backport of the patch posted at
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591354.html
gcc/ChangeLog:
* omp-low.cc (omp_enable_pinned_mode): New function.
(execute_lower_omp): Call omp_enable_pinned_mode.
libgomp/ChangeLog:
* config/linux/allocator.c (always_pinned_mode): New variable.
(GOMP_enable_pinned_mode): New function.
(linux_memspace_alloc): Disable pinning when always_pinned_mode set.
(linux_memspace_calloc): Likewise.
(linux_memspace_free): Likewise.
(linux_memspace_realloc): Likewise.
* libgomp.map (GOMP_5.1.1): New version space with
GOMP_enable_pinned_mode.
* testsuite/libgomp.c/alloc-pinned-7.c: New test.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/alloc-pinned-1.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog.omp | 8 | ||||
-rw-r--r-- | gcc/omp-low.cc | 67 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog.omp | 7 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/gomp/alloc-pinned-1.c | 28 |
4 files changed, 110 insertions, 0 deletions
diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 069e2bf..34c1a09 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-03-11 Andrew Stubbs <ams@codesourcery.com> + + Backport of the patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591354.html + + * omp-low.cc (omp_enable_pinned_mode): New function. + (execute_lower_omp): Call omp_enable_pinned_mode. + 2022-03-11 Abid Qadeer <abidh@codesourcery.com> Backport of a patch posted at diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index e1a8d70..0962a6c 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -15639,6 +15639,70 @@ lower_omp (gimple_seq *body, omp_context *ctx) input_location = saved_location; } +/* Emit a constructor function to enable -foffload-memory=pinned + at runtime. Libgomp handles the OS mode setting, but we need to trigger + it by calling GOMP_enable_pinned mode before the program proper runs. */ + +static void +omp_enable_pinned_mode () +{ + static bool visited = false; + if (visited) + return; + visited = true; + + /* Create a new function like this: + + static void __attribute__((constructor)) + __set_pinned_mode () + { + GOMP_enable_pinned_mode (); + } + */ + + tree name = get_identifier ("__set_pinned_mode"); + tree voidfntype = build_function_type_list (void_type_node, NULL_TREE); + tree decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, name, voidfntype); + + TREE_STATIC (decl) = 1; + TREE_USED (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; + DECL_IGNORED_P (decl) = 0; + TREE_PUBLIC (decl) = 0; + DECL_UNINLINABLE (decl) = 1; + DECL_EXTERNAL (decl) = 0; + DECL_CONTEXT (decl) = NULL_TREE; + DECL_INITIAL (decl) = make_node (BLOCK); + BLOCK_SUPERCONTEXT (DECL_INITIAL (decl)) = decl; + DECL_STATIC_CONSTRUCTOR (decl) = 1; + DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("constructor"), + NULL_TREE, NULL_TREE); + + tree t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, + void_type_node); + DECL_ARTIFICIAL (t) = 1; + DECL_IGNORED_P (t) = 1; + DECL_CONTEXT (t) = decl; + DECL_RESULT (decl) = t; + + push_struct_function (decl); + init_tree_ssa (cfun); + + tree callname = get_identifier ("GOMP_enable_pinned_mode"); + tree calldecl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, callname, + voidfntype); + gcall *call = gimple_build_call (calldecl, 0); + + gimple_seq seq = NULL; + gimple_seq_add_stmt (&seq, call); + gimple_set_body (decl, gimple_build_bind (NULL_TREE, seq, NULL)); + + cfun->function_end_locus = UNKNOWN_LOCATION; + cfun->curr_properties |= PROP_gimple_any; + pop_cfun (); + cgraph_node::add_new_function (decl, true); +} + /* Main entry point. */ static unsigned int @@ -15692,6 +15756,9 @@ execute_lower_omp (void) == POINTER_TYPE)) remove_member_access_dummy_vars (DECL_INITIAL (current_function_decl)); + if (flag_offload_memory == OFFLOAD_MEMORY_PINNED) + omp_enable_pinned_mode (); + for (auto task_stmt : task_cpyfns) finalize_task_copyfn (task_stmt); task_cpyfns.release (); diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 842db09..6ff2e73 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,10 @@ +2022-03-11 Andrew Stubbs <ams@codesourcery.com> + + Backport of the patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591354.html + + * c-c++-common/gomp/alloc-pinned-1.c: New test. + 2022-03-11 Abid Qadeer <abidh@codesourcery.com> Backport of a patch posted at diff --git a/gcc/testsuite/c-c++-common/gomp/alloc-pinned-1.c b/gcc/testsuite/c-c++-common/gomp/alloc-pinned-1.c new file mode 100644 index 0000000..e0e0801 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/alloc-pinned-1.c @@ -0,0 +1,28 @@ +/* { dg-do run } */ +/* { dg-additional-options "-foffload-memory=pinned" } */ +/* { dg-xfail-run-if "Pinning not implemented on this host" { ! *-*-linux-gnu } } */ + +#if __cplusplus +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + +/* Intercept the libgomp initialization call to check it happens. */ + +int good = 0; + +EXTERNC void +GOMP_enable_pinned_mode () +{ + good = 1; +} + +int +main () +{ + if (!good) + __builtin_exit (1); + + return 0; +} |