Skip to content
Snippets Groups Projects
  • Andrew Stubbs's avatar
    f6fff8a6
    amdgcn, libgomp: Manually allocated stacks · f6fff8a6
    Andrew Stubbs authored
    Switch from using stacks in the "private segment" to using a memory block
    allocated on the host side.  The primary reason is to permit the reverse
    offload implementation to access values located on the device stack, but
    there may also be performance benefits, especially with repeated kernel
    invocations.
    
    This implementation unifies the stacks with the "team arena" optimization
    feature, and now allows both to have run-time configurable sizes.
    
    A new ABI is needed, so all libraries must be rebuilt, and newlib must be
    version 4.3.0.20230120 or newer.
    
    gcc/ChangeLog:
    
    	* config/gcn/gcn-run.cc: Include libgomp-gcn.h.
    	(struct kernargs): Replace the common content with kernargs_abi.
    	(struct heap): Delete.
    	(main): Read GCN_STACK_SIZE envvar.
    	Allocate space for the device stacks.
    	Write the new kernargs fields.
    	* config/gcn/gcn.cc (gcn_option_override): Remove stack_size_opt.
    	(default_requested_args): Remove PRIVATE_SEGMENT_BUFFER_ARG and
    	PRIVATE_SEGMENT_WAVE_OFFSET_ARG.
    	(gcn_addr_space_convert): Mask the QUEUE_PTR_ARG content.
    	(gcn_expand_prologue): Move the TARGET_PACKED_WORK_ITEMS to the top.
    	Set up the stacks from the values in the kernargs, not private.
    	(gcn_expand_builtin_1): Match the stack configuration in the prologue.
    	(gcn_hsa_declare_function_name): Turn off the private segment.
    	(gcn_conditional_register_usage): Ensure QUEUE_PTR is fixed.
    	* config/gcn/gcn.h (FIXED_REGISTERS): Fix the QUEUE_PTR register.
    	* config/gcn/gcn.opt (mstack-size): Change the description.
    
    include/ChangeLog:
    
    	* gomp-constants.h (GOMP_VERSION_GCN): Bump.
    
    libgomp/ChangeLog:
    
    	* config/gcn/libgomp-gcn.h (DEFAULT_GCN_STACK_SIZE): New define.
    	(DEFAULT_TEAM_ARENA_SIZE): New define.
    	(struct heap): Move to this file.
    	(struct kernargs_abi): Likewise.
    	* config/gcn/team.c (gomp_gcn_enter_kernel): Use team arena size from
    	the kernargs.
    	* libgomp.h: Include libgomp-gcn.h.
    	(TEAM_ARENA_SIZE): Remove.
    	(team_malloc): Update the error message.
    	* plugin/plugin-gcn.c (struct kernargs): Move common content to
    	struct kernargs_abi.
    	(struct agent_info): Rename team arenas to ephemeral memories.
    	(struct team_arena_list): Rename ....
    	(struct ephemeral_memories_list): to this.
    	(struct heap): Delete.
    	(team_arena_size): New variable.
    	(stack_size): New variable.
    	(print_kernel_dispatch): Update debug messages.
    	(init_environment_variables): Read GCN_TEAM_ARENA_SIZE.
    	Read GCN_STACK_SIZE.
    	(get_team_arena): Rename ...
    	(configure_ephemeral_memories): ... to this, and set up stacks.
    	(release_team_arena): Rename ...
    	(release_ephemeral_memories): ... to this.
    	(destroy_team_arenas): Rename ...
    	(destroy_ephemeral_memories): ... to this.
    	(create_kernel_dispatch): Add num_threads parameter.
    	Adjust for kernargs_abi refactor and ephemeral memories.
    	(release_kernel_dispatch): Adjust for ephemeral memories.
    	(run_kernel): Pass thread-count to create_kernel_dispatch.
    	(GOMP_OFFLOAD_init_device): Adjust for ephemeral memories.
    	(GOMP_OFFLOAD_fini_device): Adjust for ephemeral memories.
    
    gcc/testsuite/ChangeLog:
    
    	* gcc.c-torture/execute/pr47237.c: Xfail on amdgcn.
    	* gcc.dg/builtin-apply3.c: Xfail for amdgcn.
    	* gcc.dg/builtin-apply4.c: Xfail for amdgcn.
    	* gcc.dg/torture/stackalign/builtin-apply-3.c: Xfail for amdgcn.
    	* gcc.dg/torture/stackalign/builtin-apply-4.c: Xfail for amdgcn.
    f6fff8a6
    History
    amdgcn, libgomp: Manually allocated stacks
    Andrew Stubbs authored
    Switch from using stacks in the "private segment" to using a memory block
    allocated on the host side.  The primary reason is to permit the reverse
    offload implementation to access values located on the device stack, but
    there may also be performance benefits, especially with repeated kernel
    invocations.
    
    This implementation unifies the stacks with the "team arena" optimization
    feature, and now allows both to have run-time configurable sizes.
    
    A new ABI is needed, so all libraries must be rebuilt, and newlib must be
    version 4.3.0.20230120 or newer.
    
    gcc/ChangeLog:
    
    	* config/gcn/gcn-run.cc: Include libgomp-gcn.h.
    	(struct kernargs): Replace the common content with kernargs_abi.
    	(struct heap): Delete.
    	(main): Read GCN_STACK_SIZE envvar.
    	Allocate space for the device stacks.
    	Write the new kernargs fields.
    	* config/gcn/gcn.cc (gcn_option_override): Remove stack_size_opt.
    	(default_requested_args): Remove PRIVATE_SEGMENT_BUFFER_ARG and
    	PRIVATE_SEGMENT_WAVE_OFFSET_ARG.
    	(gcn_addr_space_convert): Mask the QUEUE_PTR_ARG content.
    	(gcn_expand_prologue): Move the TARGET_PACKED_WORK_ITEMS to the top.
    	Set up the stacks from the values in the kernargs, not private.
    	(gcn_expand_builtin_1): Match the stack configuration in the prologue.
    	(gcn_hsa_declare_function_name): Turn off the private segment.
    	(gcn_conditional_register_usage): Ensure QUEUE_PTR is fixed.
    	* config/gcn/gcn.h (FIXED_REGISTERS): Fix the QUEUE_PTR register.
    	* config/gcn/gcn.opt (mstack-size): Change the description.
    
    include/ChangeLog:
    
    	* gomp-constants.h (GOMP_VERSION_GCN): Bump.
    
    libgomp/ChangeLog:
    
    	* config/gcn/libgomp-gcn.h (DEFAULT_GCN_STACK_SIZE): New define.
    	(DEFAULT_TEAM_ARENA_SIZE): New define.
    	(struct heap): Move to this file.
    	(struct kernargs_abi): Likewise.
    	* config/gcn/team.c (gomp_gcn_enter_kernel): Use team arena size from
    	the kernargs.
    	* libgomp.h: Include libgomp-gcn.h.
    	(TEAM_ARENA_SIZE): Remove.
    	(team_malloc): Update the error message.
    	* plugin/plugin-gcn.c (struct kernargs): Move common content to
    	struct kernargs_abi.
    	(struct agent_info): Rename team arenas to ephemeral memories.
    	(struct team_arena_list): Rename ....
    	(struct ephemeral_memories_list): to this.
    	(struct heap): Delete.
    	(team_arena_size): New variable.
    	(stack_size): New variable.
    	(print_kernel_dispatch): Update debug messages.
    	(init_environment_variables): Read GCN_TEAM_ARENA_SIZE.
    	Read GCN_STACK_SIZE.
    	(get_team_arena): Rename ...
    	(configure_ephemeral_memories): ... to this, and set up stacks.
    	(release_team_arena): Rename ...
    	(release_ephemeral_memories): ... to this.
    	(destroy_team_arenas): Rename ...
    	(destroy_ephemeral_memories): ... to this.
    	(create_kernel_dispatch): Add num_threads parameter.
    	Adjust for kernargs_abi refactor and ephemeral memories.
    	(release_kernel_dispatch): Adjust for ephemeral memories.
    	(run_kernel): Pass thread-count to create_kernel_dispatch.
    	(GOMP_OFFLOAD_init_device): Adjust for ephemeral memories.
    	(GOMP_OFFLOAD_fini_device): Adjust for ephemeral memories.
    
    gcc/testsuite/ChangeLog:
    
    	* gcc.c-torture/execute/pr47237.c: Xfail on amdgcn.
    	* gcc.dg/builtin-apply3.c: Xfail for amdgcn.
    	* gcc.dg/builtin-apply4.c: Xfail for amdgcn.
    	* gcc.dg/torture/stackalign/builtin-apply-3.c: Xfail for amdgcn.
    	* gcc.dg/torture/stackalign/builtin-apply-4.c: Xfail for amdgcn.