From c02bffe38a706d8251442cf01095563c1bdcd61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20J=C3=A4=C3=A4skel=C3=A4inen?= Date: Mon, 25 Sep 2017 17:17:29 +0000 Subject: [PATCH] BRIGFE fixes: * brig-builtins.def: Treat HSAIL barrier builtins as setjmp/longjump style functions. * brigfrontend/brig-to-generic.cc: Ensure per WI copies of private variables are aligned too. * rt/workitems.c: Assume the host runtime allocates the work group memory. From-SVN: r253160 --- gcc/ChangeLog | 5 +++++ gcc/brig-builtins.def | 6 +++--- gcc/brig/ChangeLog | 5 +++++ gcc/brig/brigfrontend/brig-to-generic.cc | 22 +++++++++++++++++++--- libhsail-rt/ChangeLog | 4 ++++ libhsail-rt/rt/workitems.c | 23 ----------------------- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e27d0ba48d6..f0a5a3db664 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-09-25 Pekka Jaaskelainen + + * brig-builtins.def: Treat HSAIL barrier builtins as + setjmp/longjump style functions. + 2017-09-25 Richard Sandiford * target.def (constant_alignment): New hook. diff --git a/gcc/brig-builtins.def b/gcc/brig-builtins.def index f5256108635..39f403e0623 100644 --- a/gcc/brig-builtins.def +++ b/gcc/brig-builtins.def @@ -240,7 +240,7 @@ DEF_HSAIL_BUILTIN (BUILT_IN_HSAIL_FRACT_F64, BRIG_OPCODE_FRACT, DEF_HSAIL_BUILTIN (BUILT_IN_HSAIL_BARRIER, BRIG_OPCODE_BARRIER, BRIG_TYPE_NONE, "__hsail_barrier", BT_FN_VOID_PTR, - ATTR_NOTHROW_LIST) + ATTR_RT_NOTHROW_LEAF_LIST) DEF_HSAIL_BUILTIN (BUILT_IN_HSAIL_INITFBAR, BRIG_OPCODE_INITFBAR, BRIG_TYPE_NONE, "__hsail_initfbar", BT_FN_VOID_UINT_PTR, @@ -252,11 +252,11 @@ DEF_HSAIL_BUILTIN (BUILT_IN_HSAIL_JOINFBAR, BRIG_OPCODE_JOINFBAR, DEF_HSAIL_BUILTIN (BUILT_IN_HSAIL_WAITFBAR, BRIG_OPCODE_WAITFBAR, BRIG_TYPE_NONE, "__hsail_waitfbar", BT_FN_VOID_UINT_PTR, - ATTR_NOTHROW_LIST) + ATTR_RT_NOTHROW_LEAF_LIST) DEF_HSAIL_BUILTIN (BUILT_IN_HSAIL_ARRIVEFBAR, BRIG_OPCODE_ARRIVEFBAR, BRIG_TYPE_NONE, "__hsail_arrivefbar", BT_FN_VOID_UINT_PTR, - ATTR_NOTHROW_LIST) + ATTR_RT_NOTHROW_LEAF_LIST) DEF_HSAIL_BUILTIN (BUILT_IN_HSAIL_LEAVEFBAR, BRIG_OPCODE_LEAVEFBAR, BRIG_TYPE_NONE, "__hsail_leavefbar", BT_FN_VOID_UINT_PTR, diff --git a/gcc/brig/ChangeLog b/gcc/brig/ChangeLog index ebf31c43a82..69c57cbf80a 100644 --- a/gcc/brig/ChangeLog +++ b/gcc/brig/ChangeLog @@ -1,3 +1,8 @@ +2017-05-13 Pekka Jääskeläinen + + * brigfrontend/brig-to-generic.cc: Ensure per WI copies of + private variables are aligned too. + 2017-09-17 Thomas Schwinge * Make-lang.in (GO_TEXI_FILES): Rename to... diff --git a/gcc/brig/brigfrontend/brig-to-generic.cc b/gcc/brig/brigfrontend/brig-to-generic.cc index 7559c055c3b..2b1d94e0ff7 100644 --- a/gcc/brig/brigfrontend/brig-to-generic.cc +++ b/gcc/brig/brigfrontend/brig-to-generic.cc @@ -599,18 +599,34 @@ brig_to_generic::group_segment_size () const return m_next_group_offset; } -/* Appends a new group variable to the current kernel's private segment. */ +/* Appends a new variable to the current kernel's private segment. */ void brig_to_generic::append_private_variable (const std::string &name, size_t size, size_t alignment) { + /* We need to take care of two cases of alignment with private + variables because of the layout where the same variable for + each work-item is laid out in successive addresses. + + 1) Ensure the first work-item's variable is in an aligned + offset: */ size_t align_padding = m_next_private_offset % alignment == 0 ? 0 : (alignment - m_next_private_offset % alignment); + + /* 2) Each successive per-work-item copy should be aligned. + If the variable has wider alignment than size then we need + to add extra padding to ensure it. The padding must be + included in the size to allow per-work-item offset computation + to find their own aligned copy. */ + + size_t per_var_padding = size % alignment == 0 ? + 0 : (alignment - size % alignment); + m_private_data_sizes[name] = size + per_var_padding; + m_next_private_offset += align_padding; m_private_offsets[name] = m_next_private_offset; - m_next_private_offset += size; - m_private_data_sizes[name] = size + align_padding; + m_next_private_offset += size + per_var_padding; } size_t diff --git a/libhsail-rt/ChangeLog b/libhsail-rt/ChangeLog index 31ffff694c7..bf86278584d 100644 --- a/libhsail-rt/ChangeLog +++ b/libhsail-rt/ChangeLog @@ -1,3 +1,7 @@ +2017-09-25 Pekka Jääskeläinen + + * rt/workitems.c: Assume the host runtime allocates the work group + memory. 2017-05-03 Pekka Jääskeläinen * rt/workitems.c: Removed a leftover comment. diff --git a/libhsail-rt/rt/workitems.c b/libhsail-rt/rt/workitems.c index e2c2373757a..ed1185a5780 100644 --- a/libhsail-rt/rt/workitems.c +++ b/libhsail-rt/rt/workitems.c @@ -318,14 +318,6 @@ phsa_spawn_work_items (PHSAKernelLaunchData *context, void *group_base_ptr) hsa_kernel_dispatch_packet_t *dp = context->dp; size_t x, y, z; - /* TO DO: host-side memory management of group and private segment - memory. Agents in general are less likely to support efficient dynamic mem - allocation. */ - if (dp->group_segment_size > 0 - && posix_memalign (&group_base_ptr, PRIVATE_SEGMENT_ALIGN, - dp->group_segment_size) != 0) - phsa_fatal_error (3); - context->group_segment_start_addr = (size_t) group_base_ptr; /* HSA seems to allow the WG size to be larger than the grid size. We need to @@ -371,9 +363,6 @@ phsa_spawn_work_items (PHSAKernelLaunchData *context, void *group_base_ptr) phsa_execute_wi_gang (context, group_base_ptr, sat_wg_size_x, sat_wg_size_y, sat_wg_size_z); - - if (dp->group_segment_size > 0) - free (group_base_ptr); } #endif @@ -390,14 +379,6 @@ phsa_execute_work_groups (PHSAKernelLaunchData *context, void *group_base_ptr) hsa_kernel_dispatch_packet_t *dp = context->dp; size_t x, y, z, wg_x, wg_y, wg_z; - /* TODO: host-side memory management of group and private segment - memory. Agents in general are less likely to support efficient dynamic mem - allocation. */ - if (dp->group_segment_size > 0 - && posix_memalign (&group_base_ptr, GROUP_SEGMENT_ALIGN, - dp->group_segment_size) != 0) - phsa_fatal_error (3); - context->group_segment_start_addr = (size_t) group_base_ptr; /* HSA seems to allow the WG size to be larger than the grid size. We need @@ -509,10 +490,6 @@ phsa_execute_work_groups (PHSAKernelLaunchData *context, void *group_base_ptr) printf ("### %lu WIs executed in %lu s (%lu WIs / s)\n", wi_total, (uint64_t) spent_time_sec, (uint64_t) wis_per_sec); #endif - - if (dp->group_segment_size > 0) - free (group_base_ptr); - free (private_base_ptr); private_base_ptr = NULL; }