Skip to content

Commit

Permalink
BRIGFE fixes:
Browse files Browse the repository at this point in the history
* 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.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253160 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
visit0r committed Sep 25, 2017
1 parent 3eaed19 commit 749920a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
5 changes: 5 additions & 0 deletions gcc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-09-25 Pekka Jaaskelainen <[email protected]>

* brig-builtins.def: Treat HSAIL barrier builtins as
setjmp/longjump style functions.

2017-09-25 Richard Sandiford <[email protected]>

* target.def (constant_alignment): New hook.
Expand Down
6 changes: 3 additions & 3 deletions gcc/brig-builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions gcc/brig/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-05-13 Pekka Jääskeläinen <[email protected]>

* brigfrontend/brig-to-generic.cc: Ensure per WI copies of
private variables are aligned too.

2017-09-17 Thomas Schwinge <[email protected]>

* Make-lang.in (GO_TEXI_FILES): Rename to...
Expand Down
22 changes: 19 additions & 3 deletions gcc/brig/brigfrontend/brig-to-generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions libhsail-rt/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2017-09-25 Pekka Jääskeläinen <[email protected]>

* rt/workitems.c: Assume the host runtime allocates the work group
memory.
2017-05-03 Pekka Jääskeläinen <[email protected]>

* rt/workitems.c: Removed a leftover comment.
Expand Down
23 changes: 0 additions & 23 deletions libhsail-rt/rt/workitems.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 749920a

Please sign in to comment.