Re: openmp: Add basic library allocator support
On Tue, Jun 02, 2020 at 11:26:37AM +0200, Sebastian Huber wrote: > with this patch I get the following error for target arm-rtems6: > > ../../../gnu-mirror-gcc-86b14bb/libgomp/allocator.c: In function 'omp_free': > ../../../gnu-mirror-gcc-86b14bb/libgomp/allocator.c:351:42: error: 'struct > omp_mem_header' has no member named 'new_size' > Â 351 |Â Â Â allocator_data->used_pool_size -= data->new_size; > Â Â Â Â Â |Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â > Â Â Â Â Â Â Â Â ^~ Oops, sorry, fixed thusly, tested also with #undef HAVE_SYNC_BUILTINS early in the file, committed to trunk. 2020-06-02 Jakub Jelinek * allocator.c (omp_free): Fix up build if HAVE_SYNC_BUILTINS is not defined. --- libgomp/allocator.c +++ libgomp/allocator.c @@ -348,7 +348,7 @@ omp_free (void *ptr, omp_allocator_handle_t allocator) MEMMODEL_RELAXED); #else gomp_mutex_lock (_data->lock); - allocator_data->used_pool_size -= data->new_size; + allocator_data->used_pool_size -= data->size; gomp_mutex_unlock (_data->lock); #endif } Jakub
Re: openmp: Add basic library allocator support
Hello, On 19/05/2020 10:24, Jakub Jelinek via Gcc-patches wrote: + gomp_mutex_lock (_data->lock); + if (__builtin_add_overflow (allocator_data->used_pool_size, new_size, + _pool_size) + || used_pool_size > allocator_data->pool_size) + { + gomp_mutex_unlock (_data->lock); + goto fail; + } + allocator_data->used_pool_size = used_pool_size; + gomp_mutex_unlock (_data->lock); +#endif + ptr = malloc (new_size); + if (ptr == NULL) + { +#ifdef HAVE_SYNC_BUILTINS + __atomic_add_fetch (_data->used_pool_size, -new_size, + MEMMODEL_RELAXED); +#else + gomp_mutex_lock (_data->lock); + allocator_data->used_pool_size -= new_size; + gomp_mutex_unlock (_data->lock); +#endif with this patch I get the following error for target arm-rtems6: ../../../gnu-mirror-gcc-86b14bb/libgomp/allocator.c: In function 'omp_free': ../../../gnu-mirror-gcc-86b14bb/libgomp/allocator.c:351:42: error: 'struct omp_mem_header' has no member named 'new_size' 351 | allocator_data->used_pool_size -= data->new_size; | ^~
Re: openmp: Add basic library allocator support
On Tue, May 19, 2020 at 04:56:51AM -0700, H.J. Lu wrote: > > 2020-05-19 Jakub Jelinek > > > > * 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. > > Did you check in allocator.c? Forgot to git add it, fixed in r11-494-ge107157171af25f6c89be02d62b0a7235a5c988d On the bright side, Martin's pre-commit-hook would reject it because of that, but I've committed it immediately before installing the hook :(. Sorry. Jakub
Re: openmp: Add basic library allocator support
On Tue, May 19, 2020 at 1:27 AM Jakub Jelinek via Gcc-patches wrote: > > Hi! > > 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. > > Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. > > 2020-05-19 Jakub Jelinek > > * 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. Did you check in allocator.c? -- H.J.