On Tue, Nov 12, 2019 at 01:29:14PM +0000, Andrew Stubbs wrote:
> 2019-11-12  Andrew Stubbs  <a...@codesourcery.com>
> 
>       libgomp/
>       * config/gcn/team.c (gomp_gcn_enter_kernel): Set up the team arena
>       and use team_malloc variants.
>       (gomp_gcn_exit_kernel): Use team_free.
>       * libgomp.h (TEAM_ARENA_SIZE): Define.
>       (TEAM_ARENA_FREE): Define.
>       (TEAM_ARENA_END): Define.
>       (team_malloc): New function.
>       (team_malloc_cleared): New function.
>       (team_free): New function.
>       * team.c (gomp_new_team): Use team_malloc.
>       (free_team): Use team_free.
>       (gomp_free_thread): Use team_free.
>       (gomp_pause_host): Use team_free.
>       * work.c (gomp_init_work_share): Use team_malloc.
>       (gomp_fini_work_share): Use team_free.

> +  /* Handle OOM.  */
> +  if (result + size > *(void * __lds *)TEAM_ARENA_END)
> +    {
> +      const char msg[] = "GCN team arena exhausted\n";
> +      write (2, msg, sizeof(msg)-1);
> +      /* It's better to continue with reeduced performance than abort.

s/reeduced/reduced/

Not really sure if it is a good idea to print anything, at least not when
in some debugging mode.  I mean, it is fairly easy to write code that will
trigger this.  And, what is the reason why you can't free the
gomp_malloced memory, like comparing if the team_freed pointer is in between
TEAM_ARENA_START and TEAM_ARENA_END or similar, don't do anything in that
case, otherwise use free?

> +         Beware that this won't get freed, which might cause more problems.  
> */
> +      result = gomp_malloc (size);
> +    }
> +  return result;
> +}
> +
> +static inline void * __attribute__((malloc)) __attribute__((optimize("-O3")))
> +team_malloc_cleared (size_t size)
> +{
> +  char *result = team_malloc (size);
> +
> +  /* Clear the allocated memory.
> +     This should vectorize.  The allocation has been rounded up to the next
> +     4-byte boundary, so this is safe.  */
> +  for (int i = 0; i<size; i+=4)
> +    *(int*)(result+i) = 0;

Formatting (spaces around <, +=, +, between int and *.  Shouldn't 4 be
sizeof (int)?  And wouldn't memset (result, 0, size); do the same job?

        Jakub

Reply via email to