diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-05-19 10:11:01 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-05-19 10:11:01 +0200 |
commit | 800bcc8c00f3ce940aa174845bb61faca9e85d36 (patch) | |
tree | 6d47155dfd3312da918cf370cda1fd3e00ae0fe6 /libgomp/env.c | |
parent | c3b44e34085c16059da5a7a7a3d84abb46d40884 (diff) | |
download | gcc-800bcc8c00f3ce940aa174845bb61faca9e85d36.zip gcc-800bcc8c00f3ce940aa174845bb61faca9e85d36.tar.gz gcc-800bcc8c00f3ce940aa174845bb61faca9e85d36.tar.bz2 |
openmp: Add basic library allocator support.
This patch adds very basic allocator support (omp_{init,destroy}_allocator,
omp_{alloc,free}, omp_[sg]et_default_allocator).
The plan is to use memkind (likely dlopened) for high bandwidth memory, but
that part isn't implemented yet, probably mlock for pinned memory and see
what other options there are for other kinds of memory.
For offloading targets, we need to decide if we want to support the
dynamic allocators (and on which targets), or if e.g. all we do is at compile
time replace omp_alloc/omp_free calls with constexpr predefined allocators
with something special.
And allocate directive and allocator/uses_allocators clauses are future work
too.
2020-05-19 Jakub Jelinek <jakub@redhat.com>
* omp.h.in (omp_uintptr_t): New typedef.
(__GOMP_UINTPTR_T_ENUM): Define.
(omp_memspace_handle_t, omp_allocator_handle_t, omp_alloctrait_key_t,
omp_alloctrait_value_t, omp_alloctrait_t): New typedefs.
(__GOMP_DEFAULT_NULL_ALLOCATOR): Define.
(omp_init_allocator, omp_destroy_allocator, omp_set_default_allocator,
omp_get_default_allocator, omp_alloc, omp_free): Declare.
* libgomp.h (struct gomp_team_state): Add def_allocator field.
(gomp_def_allocator): Declare.
* libgomp.map (OMP_5.0.1): Export omp_set_default_allocator,
omp_get_default_allocator, omp_init_allocator, omp_destroy_allocator,
omp_alloc and omp_free.
* team.c (gomp_team_start): Copy over ts.def_allocator.
* env.c (gomp_def_allocator): New variable.
(parse_wait_policy): Adjust function comment.
(parse_allocator): New function.
(handle_omp_display_env): Print OMP_ALLOCATOR.
(initialize_env): Call parse_allocator.
* Makefile.am (libgomp_la_SOURCES): Add allocator.c.
* allocator.c: New file.
* icv.c (omp_set_default_allocator, omp_get_default_allocator): New
functions.
* testsuite/libgomp.c-c++-common/alloc-1.c: New test.
* testsuite/libgomp.c-c++-common/alloc-2.c: New test.
* testsuite/libgomp.c-c++-common/alloc-3.c: New test.
* Makefile.in: Regenerated.
Diffstat (limited to 'libgomp/env.c')
-rw-r--r-- | libgomp/env.c | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/libgomp/env.c b/libgomp/env.c index dbec3ae..c0c4730 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -86,6 +86,7 @@ char *gomp_bind_var_list; unsigned long gomp_bind_var_list_len; void **gomp_places_list; unsigned long gomp_places_list_len; +uintptr_t gomp_def_allocator = omp_default_mem_alloc; int gomp_debug_var; unsigned int gomp_num_teams_var; bool gomp_display_affinity_var; @@ -949,8 +950,7 @@ parse_boolean (const char *name, bool *value) gomp_error ("Invalid value for environment variable %s", name); } -/* Parse the OMP_WAIT_POLICY environment variable and store the - result in gomp_active_wait_policy. */ +/* Parse the OMP_WAIT_POLICY environment variable and return the value. */ static int parse_wait_policy (void) @@ -1084,6 +1084,47 @@ parse_affinity (bool ignore) return false; } +/* Parse the OMP_ALLOCATOR environment variable and return the value. */ + +static uintptr_t +parse_allocator (void) +{ + const char *env; + uintptr_t ret = omp_default_mem_alloc; + + env = getenv ("OMP_ALLOCATOR"); + if (env == NULL) + return ret; + + while (isspace ((unsigned char) *env)) + ++env; + if (0) + ; +#define C(v) \ + else if (strncasecmp (env, #v, sizeof (#v) - 1) == 0) \ + { \ + ret = v; \ + env += sizeof (#v) - 1; \ + } + C (omp_default_mem_alloc) + C (omp_large_cap_mem_alloc) + C (omp_const_mem_alloc) + C (omp_high_bw_mem_alloc) + C (omp_low_lat_mem_alloc) + C (omp_cgroup_mem_alloc) + C (omp_pteam_mem_alloc) + C (omp_thread_mem_alloc) +#undef C + else + env = "X"; + while (isspace ((unsigned char) *env)) + ++env; + if (*env == '\0') + return ret; + gomp_error ("Invalid value for environment variable OMP_ALLOCATOR"); + return omp_default_mem_alloc; +} + static void parse_acc_device_type (void) { @@ -1276,6 +1317,22 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy) gomp_display_affinity_var ? "TRUE" : "FALSE"); fprintf (stderr, " OMP_AFFINITY_FORMAT = '%s'\n", gomp_affinity_format_var); + fprintf (stderr, " OMP_ALLOCATOR = '"); + switch (gomp_def_allocator) + { +#define C(v) case v: fputs (#v, stderr); break; + C (omp_default_mem_alloc) + C (omp_large_cap_mem_alloc) + C (omp_const_mem_alloc) + C (omp_high_bw_mem_alloc) + C (omp_low_lat_mem_alloc) + C (omp_cgroup_mem_alloc) + C (omp_pteam_mem_alloc) + C (omp_thread_mem_alloc) +#undef C + default: break; + } + fputs ("'\n", stderr); if (verbose) { @@ -1312,6 +1369,7 @@ initialize_env (void) parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var, true); parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var, true); + gomp_def_allocator = parse_allocator (); if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var, false)) { gomp_global_icv.thread_limit_var |