diff options
author | Pekka Jääskeläinen <pekka@parmance.com> | 2017-01-24 12:45:56 +0000 |
---|---|---|
committer | Martin Jambor <jamborm@gcc.gnu.org> | 2017-01-24 13:45:56 +0100 |
commit | 5fd1486ce58297190c2b924e96e716087139a8b5 (patch) | |
tree | 80abae8778b2f25cc8bf5960402f20f16e4e7a8c /libhsail-rt/include | |
parent | e1e41b6f10c76dbdc8bfd2d4a345dffefd45968f (diff) |
Brig front-end
2017-01-24 Pekka Jääskeläinen <pekka@parmance.com>
Martin Jambor <mjambor@suse.cz>
* Makefile.def (target_modules): Added libhsail-rt.
(languages): Added language brig.
* Makefile.in: Regenerated.
* configure.ac (TOPLEVEL_CONFIGURE_ARGUMENTS): Added
tgarget-libhsail-rt. Make brig unsupported on untested architectures.
* configure: Regenerated.
gcc/
* brig-builtins.def: New file.
* builtins.def (DEF_HSAIL_BUILTIN): New macro.
(DEF_HSAIL_ATOMIC_BUILTIN): Likewise.
(DEF_HSAIL_SAT_BUILTIN): Likewise.
(DEF_HSAIL_INTR_BUILTIN): Likewise.
(DEF_HSAIL_CVT_ZEROI_SAT_BUILTIN): Likewise.
* builtin-types.def (BT_INT8): New.
(BT_INT16): Likewise.
(BT_UINT8): Likewise.
(BT_UINT16): Likewise.
(BT_FN_ULONG): Likewise.
(BT_FN_UINT_INT): Likewise.
(BT_FN_UINT_ULONG): Likewise.
(BT_FN_UINT_LONG): Likewise.
(BT_FN_UINT_PTR): Likewise.
(BT_FN_ULONG_PTR): Likewise.
(BT_FN_INT8_FLOAT): Likewise.
(BT_FN_INT16_FLOAT): Likewise.
(BT_FN_UINT32_FLOAT): Likewise.
(BT_FN_UINT16_FLOAT): Likewise.
(BT_FN_UINT8_FLOAT): Likewise.
(BT_FN_UINT64_FLOAT): Likewise.
(BT_FN_UINT16_UINT32): Likewise.
(BT_FN_UINT32_UINT16): Likewise.
(BT_FN_UINT16_UINT16_UINT16): Likewise.
(BT_FN_INT_PTR_INT): Likewise.
(BT_FN_UINT_PTR_UINT): Likewise.
(BT_FN_LONG_PTR_LONG): Likewise.
(BT_FN_ULONG_PTR_ULONG): Likewise.
(BT_FN_VOID_UINT64_UINT64): Likewise.
(BT_FN_UINT8_UINT8_UINT8): Likewise.
(BT_FN_INT8_INT8_INT8): Likewise.
(BT_FN_INT16_INT16_INT16): Likewise.
(BT_FN_INT_INT_INT): Likewise.
(BT_FN_UINT_FLOAT_UINT): Likewise.
(BT_FN_FLOAT_UINT_UINT): Likewise.
(BT_FN_ULONG_UINT_UINT): Likewise.
(BT_FN_ULONG_UINT_PTR): Likewise.
(BT_FN_ULONG_ULONG_ULONG): Likewise.
(BT_FN_UINT_UINT_UINT): Likewise.
(BT_FN_VOID_UINT_PTR): Likewise.
(BT_FN_UINT_UINT_PTR: Likewise.
(BT_FN_UINT32_UINT64_PTR): Likewise.
(BT_FN_INT_INT_UINT_UINT): Likewise.
(BT_FN_UINT_UINT_UINT_UINT): Likewise.
(BT_FN_UINT_UINT_UINT_PTR): Likewise.
(BT_FN_UINT_ULONG_ULONG_UINT): Likewise.
(BT_FN_ULONG_ULONG_ULONG_ULONG): Likewise.
(BT_FN_LONG_LONG_UINT_UINT): Likewise.
(BT_FN_ULONG_ULONG_UINT_UINT): Likewise.
(BT_FN_VOID_UINT32_UINT64_PTR): Likewise.
(BT_FN_VOID_UINT32_UINT32_PTR): Likewise.
(BT_FN_UINT_UINT_UINT_UINT_UINT): Likewise.
(BT_FN_UINT_FLOAT_FLOAT_FLOAT_FLOAT): Likewise.
(BT_FN_ULONG_ULONG_ULONG_UINT_UINT): Likewise.
* doc/frontends.texi: List BRIG FE.
* doc/install.texi (Testing): Add BRIG tesring requirements.
* doc/invoke.texi (Overall Options): Mention BRIG.
* doc/standards.texi (Standards): Doucment BRIG HSA version.
gcc/brig/
* Make-lang.in: New file.
* brig-builtins.h: Likewise.
* brig-c.h: Likewise.
* brig-lang.c: Likewise.
* brigspec.c: Likewise.
* config-lang.in: Likewise.
* lang-specs.h: Likewise.
* lang.opt: Likewise.
* brigfrontend/brig-arg-block-handler.cc: Likewise.
* brigfrontend/brig-atomic-inst-handler.cc: Likewise.
* brigfrontend/brig-basic-inst-handler.cc: Likewise.
* brigfrontend/brig-branch-inst-handler.cc: Likewise.
* brigfrontend/brig-cmp-inst-handler.cc: Likewise.
* brigfrontend/brig-code-entry-handler.cc: Likewise.
* brigfrontend/brig-code-entry-handler.h: Likewise.
* brigfrontend/brig-comment-handler.cc: Likewise.
* brigfrontend/brig-control-handler.cc: Likewise.
* brigfrontend/brig-copy-move-inst-handler.cc: Likewise.
* brigfrontend/brig-cvt-inst-handler.cc: Likewise.
* brigfrontend/brig-fbarrier-handler.cc: Likewise.
* brigfrontend/brig-function-handler.cc: Likewise.
* brigfrontend/brig-function.cc: Likewise.
* brigfrontend/brig-function.h: Likewise.
* brigfrontend/brig-inst-mod-handler.cc: Likewise.
* brigfrontend/brig-label-handler.cc: Likewise.
* brigfrontend/brig-lane-inst-handler.cc: Likewise.
* brigfrontend/brig-machine.c: Likewise.
* brigfrontend/brig-machine.h: Likewise.
* brigfrontend/brig-mem-inst-handler.cc: Likewise.
* brigfrontend/brig-module-handler.cc: Likewise.
* brigfrontend/brig-queue-inst-handler.cc: Likewise.
* brigfrontend/brig-seg-inst-handler.cc: Likewise.
* brigfrontend/brig-signal-inst-handler.cc: Likewise.
* brigfrontend/brig-to-generic.cc: Likewise.
* brigfrontend/brig-to-generic.h: Likewise.
* brigfrontend/brig-util.cc: Likewise.
* brigfrontend/brig-util.h: Likewise.
* brigfrontend/brig-variable-handler.cc: Likewise.
* brigfrontend/phsa.h: Likewise.
gcc/testsuite/
* lib/brig-dg.exp: New file.
* lib/brig.exp: Likewise.
* brig.dg/README: Likewise.
* brig.dg/dg.exp: Likewise.
* brig.dg/test/gimple/alloca.hsail: Likewise.
* brig.dg/test/gimple/atomics.hsail: Likewise.
* brig.dg/test/gimple/branches.hsail: Likewise.
* brig.dg/test/gimple/fbarrier.hsail: Likewise.
* brig.dg/test/gimple/function_calls.hsail: Likewise.
* brig.dg/test/gimple/kernarg.hsail: Likewise.
* brig.dg/test/gimple/mem.hsail: Likewise.
* brig.dg/test/gimple/mulhi.hsail: Likewise.
* brig.dg/test/gimple/packed.hsail: Likewise.
* brig.dg/test/gimple/smoke_test.hsail: Likewise.
* brig.dg/test/gimple/variables.hsail: Likewise.
* brig.dg/test/gimple/vector.hsail: Likewise.
include/
* hsa.h: Moved here from libgomp/plugin/hsa.h.
libgomp/
* plugin/hsa.h: Moved to top level include.
* plugin/plugin-hsa.c: Chanfgd include of hsa.h accordingly.
libhsail-rt/
* Makefile.am: New file.
* target-config.h.in: Likewise.
* configure.ac: Likewise.
* configure: Likewise.
* config.h.in: Likewise.
* aclocal.m4: Likewise.
* README: Likewise.
* Makefile.in: Likewise.
* include/internal/fibers.h: Likewise.
* include/internal/phsa-queue-interface.h: Likewise.
* include/internal/phsa-rt.h: Likewise.
* include/internal/workitems.h: Likewise.
* rt/arithmetic.c: Likewise.
* rt/atomics.c: Likewise.
* rt/bitstring.c: Likewise.
* rt/fbarrier.c: Likewise.
* rt/fibers.c: Likewise.
* rt/fp16.c: Likewise.
* rt/misc.c: Likewise.
* rt/multimedia.c: Likewise.
* rt/queue.c: Likewise.
* rt/sat_arithmetic.c: Likewise.
* rt/segment.c: Likewise.
* rt/workitems.c: Likewise.
Co-Authored-By: Martin Jambor <mjambor@suse.cz>
From-SVN: r244867
Diffstat (limited to 'libhsail-rt/include')
-rw-r--r-- | libhsail-rt/include/internal/fibers.h | 99 | ||||
-rw-r--r-- | libhsail-rt/include/internal/phsa-queue-interface.h | 60 | ||||
-rw-r--r-- | libhsail-rt/include/internal/phsa-rt.h | 94 | ||||
-rw-r--r-- | libhsail-rt/include/internal/workitems.h | 107 |
4 files changed, 360 insertions, 0 deletions
diff --git a/libhsail-rt/include/internal/fibers.h b/libhsail-rt/include/internal/fibers.h new file mode 100644 index 00000000000..033146c7b1c --- /dev/null +++ b/libhsail-rt/include/internal/fibers.h @@ -0,0 +1,99 @@ +/* fibers.h -- an extremely simple lightweight thread (fiber) implementation + Copyright (C) 2015-2016 Free Software Foundation, Inc. + Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com> + for General Processor Tech. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PHSA_RT_FIBERS_H +#define PHSA_RT_FIBERS_H + +#include <ucontext.h> + +typedef enum +{ + /* Ready to run. */ + FIBER_STATUS_READY, + /* Exited by calling fiber_thread_exit. */ + FIBER_STATUS_EXITED, + /* Joined by the main thread. */ + FIBER_STATUS_JOINED +} fiber_status_t; + +/* A light weight thread (fiber). */ +struct fiber_s +{ + ucontext_t context; + volatile fiber_status_t status; + struct fiber_s *next; + struct fiber_s *prev; +}; + +typedef struct fiber_s fiber_t; + +typedef void (*fiber_function_t)(int, int); + +/* Initializes the fiber with the start function given as the first + argument, and the argument to pass to the start function, + as the second. The allocated stack size is given as the last argument. */ +void +fiber_init (fiber_t *fiber, fiber_function_t start_function, void *arg, + size_t stack_size, size_t stack_align); + +/* Terminates the fiber execution from within the fiber itself. */ +void +fiber_exit (); + +/* Blocks until the given fiber returns. Frees the resources allocated + for the fiber. After join returns, the fiber itself can be deleted. */ +void +fiber_join (fiber_t *fiber); + +/* Co-operatively transfer execution turn to other fibers. */ +void +fiber_yield (); + +/* A multi-entry barrier. After the last fiber has reached the + barrier, it is automatically re-initialized to the threshold. */ +typedef struct +{ + /* The barrier participant count. */ + volatile size_t threshold; + /* Number of fibers that have reached the barrier. */ + volatile size_t reached; + /* Number of fibers that are waiting at the barrier. */ + volatile size_t waiting_count; +} fiber_barrier_t; + +/* Reach the given barrier. Blocks (co-operatively switches the execution + fibers) until all other parties have reached it. Returns 0 only in case + the calling fiber was the first one to return from the barrier. */ +size_t +fiber_barrier_reach (fiber_barrier_t *barrier); + +/* Initializes the given barrier. */ +void +fiber_barrier_init (fiber_barrier_t *barrier, size_t threshold); + +void * +fiber_int_args_to_ptr (int arg0, int arg1); + +#endif diff --git a/libhsail-rt/include/internal/phsa-queue-interface.h b/libhsail-rt/include/internal/phsa-queue-interface.h new file mode 100644 index 00000000000..646cee4eb55 --- /dev/null +++ b/libhsail-rt/include/internal/phsa-queue-interface.h @@ -0,0 +1,60 @@ +/* phsa_queue_interface.h -- Definition for a minimalistic generic in-memory + representation of a user mode queue to be used with the phsa/gccbrig + implementation. + + Copyright (C) 2015-2016 Free Software Foundation, Inc. + Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com> + for General Processor Tech. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PHSA_QUEUE_INTERFACE_H +#define PHSA_QUEUE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include "hsa.h" + +typedef __attribute__ ((aligned (64))) struct phsa_queue_s +{ + /* An HSA Architectured Queue object. Must be in the beginning + of the struct to enable direct pointer casting between hsa_queue_ + and phsa_queue_t. */ + hsa_queue_t hsa_queue; + + volatile uint64_t write_index; + volatile uint64_t read_index; + + /* True if global mem addresses are 64b. */ + uint64_t is_ptr64 : 1; + +} phsa_queue_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libhsail-rt/include/internal/phsa-rt.h b/libhsail-rt/include/internal/phsa-rt.h new file mode 100644 index 00000000000..40813cb9c23 --- /dev/null +++ b/libhsail-rt/include/internal/phsa-rt.h @@ -0,0 +1,94 @@ +/* phsa-rt.h -- Data structures and functions of the PHSA device side runtime + scheduler, and HSAIL built-ins. + + Copyright (C) 2015-2016 Free Software Foundation, Inc. + Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com> + for General Processor Tech. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PHSA_RT_H +#define PHSA_RT_H + +#include <stdbool.h> +#include <stdint.h> +#include "hsa.h" + +#define PHSA_MAX_WG_SIZE 1024 * 10 + +/* Pointer type for the public facing kernel launcher function generated + by gccbrig. This launches the actual kernel for all work groups and + work items in the grid. */ +typedef void (*gccbrigKernelLauncherFunc) (void *context, void *); + +/* Pointer type for kernel functions produced by gccbrig from the HSAIL. + This is private from outside the device binary and only called by + the launcher. */ +typedef void (*gccbrigKernelFunc) (unsigned char *, void *, void *, void *); + +/* Context data that is passed to the kernel function, initialized + by the runtime to the current launch information. The data is + used by different id functions etc. + + The struct is used by both the launcher and the targeted device, + thus the fields must have the same alignment/padding in both sides. +*/ +typedef struct +{ + + /* Data set by the HSA Runtime's kernel launcher. */ + hsa_kernel_dispatch_packet_t *dp; + + size_t packet_id; + + /* Data set by the device-side launcher. */ + gccbrigKernelFunc kernel; + + /* The range of a work groups this dispatch should execute. */ + size_t wg_min_x; + size_t wg_min_y; + size_t wg_min_z; + + size_t wg_max_x; + size_t wg_max_y; + size_t wg_max_z; + + /* The barrier used to synch the work-items before executing a new WG. */ + void *wg_start_barrier; + + /* The barrier to wait at after executing a work-group. */ + void *wg_completion_barrier; + + /* The barrier used to synchronize WIs in case of the 'barrier' HSAIL + instruction. */ + void *wg_sync_barrier; + + /* This should be set to the flat address of the beginning of the group + segment. */ + size_t group_segment_start_addr; + + /* This must be set to the correct aligned flat address space location from + where the kernel can actually read its arguments. Might point to the + original global kernarg space. */ + void *kernarg_addr; +} PHSAKernelLaunchData; + +#endif diff --git a/libhsail-rt/include/internal/workitems.h b/libhsail-rt/include/internal/workitems.h new file mode 100644 index 00000000000..6c96b2e4d26 --- /dev/null +++ b/libhsail-rt/include/internal/workitems.h @@ -0,0 +1,107 @@ +/* workitems.h -- Types for context data passed as hidden parameters to special + built-ins. + + Copyright (C) 2015-2016 Free Software Foundation, Inc. + Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com> + for General Processor Tech. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef PHSA_RT_WORKITEMS_H +#define PHSA_RT_WORKITEMS_H + +/* As the simple fibers implementation relies only on ucontext, we can + assume is found by default as it is part of glibc. However, for partial + HSAIL support on platforms without having it available, the following define + can be undefined. */ +#define HAVE_FIBERS + +#ifdef HAVE_FIBERS +#include "fibers.h" +#endif + +#include <stdint.h> +#include "phsa-rt.h" + +/* Data identifying a single work-group instance. */ + +typedef struct +{ + /* The group id of the currently executed WG. */ + size_t x; + size_t y; + size_t z; + + /* This is 1 in case there are more work groups to execute. + If 0, the work-item threads should finish themselves. */ + int more_wgs; + + /* If the local size does not evenly divide the grid size, will have + leftover WIs in the last execution. */ + int leftover_wg; + int last_wg; + + /* (Flat) pointer to the beginning of the group segment allocated + to the work-group. */ + void *group_base_ptr; + + /* Similarly to the private segment that gets space allocated for all + WIs in the work-group. */ + void *private_base_ptr; + uint32_t private_segment_total_size; + + /* The first flat address of the group segment allocated for + the given work group. */ + uint64_t group_segment_base_addr; + + /* Offset from the beginning of the private segment to the start of + the previously allocated chunk of dynamic work-item memory (alloca) + by any WI in the WG. + + Initially set to private_segment_total_size to denote no dynamic + allocations have been made. The dynamic allocations are done downwards + from the private segment end. */ + uint32_t alloca_stack_p; + /* The position of the first word in the current function's alloca + stack frame. Initialized to point outside the private segment. */ + uint32_t alloca_frame_p; + +} PHSAWorkGroup; + +/* Data identifying a single work-item, passed to the work-item thread in case + of a fiber based work-group execution. */ + +typedef struct +{ + PHSAKernelLaunchData *launch_data; + /* Identifies and keeps book of the currently executed WG of the WI swarm. */ + volatile PHSAWorkGroup *wg; + /* The local id of the current WI. */ + size_t x; + size_t y; + size_t z; +#ifdef HAVE_FIBERS + fiber_t fiber; +#endif +} PHSAWorkItem; + + +#endif |