diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2022-11-19 10:36:27 +0100 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2022-11-19 10:36:27 +0100 |
commit | 8c05d8cd4300f74bf2698f0a6b96464b5be571be (patch) | |
tree | 0073b1875ad14dbadafb0c083eb34434c3ad0ff3 /libgomp/config | |
parent | b1115dbfea4d6df51d608cece7416d658d2e2822 (diff) | |
download | gcc-8c05d8cd4300f74bf2698f0a6b96464b5be571be.zip gcc-8c05d8cd4300f74bf2698f0a6b96464b5be571be.tar.gz gcc-8c05d8cd4300f74bf2698f0a6b96464b5be571be.tar.bz2 |
libgomp/gcn: Prepare for reverse-offload callback handling
libgomp/ChangeLog:
* config/gcn/libgomp-gcn.h: New file; contains
struct output, declared previously in plugin-gcn.c.
* config/gcn/target.c: Include it.
(GOMP_ADDITIONAL_ICVS): Declare as extern var.
(GOMP_target_ext): Handle reverse offload.
* plugin/plugin-gcn.c: Include libgomp-gcn.h.
(struct kernargs): Replace struct def by the one
from libgomp-gcn.h for output_data.
(process_reverse_offload): New.
(console_output): Call it.
Diffstat (limited to 'libgomp/config')
-rw-r--r-- | libgomp/config/gcn/libgomp-gcn.h | 61 | ||||
-rw-r--r-- | libgomp/config/gcn/target.c | 44 |
2 files changed, 98 insertions, 7 deletions
diff --git a/libgomp/config/gcn/libgomp-gcn.h b/libgomp/config/gcn/libgomp-gcn.h new file mode 100644 index 0000000..91560be --- /dev/null +++ b/libgomp/config/gcn/libgomp-gcn.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + Contributed by Tobias Burnus <tobias@codesourcery.com>. + + This file is part of the GNU Offloading and Multi Processing Library + (libgomp). + + Libgomp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + <http://www.gnu.org/licenses/>. */ + +/* This file contains defines and type definitions shared between the + nvptx target's libgomp.a and the plugin-nvptx.c, but that is only + needef for this target. */ + +#ifndef LIBGOMP_GCN_H +#define LIBGOMP_GCN_H 1 + +/* This struct is also used in Newlib's libc/sys/amdgcn/write.c. */ +struct output +{ + int return_value; + unsigned int next_output; + struct printf_data { + int written; + union { + char msg[128]; + uint64_t msg_u64[2]; + }; + int type; + union { + int64_t ivalue; + double dvalue; + char text[128]; + uint64_t value_u64[2]; + }; + } queue[1024]; + unsigned int consumed; +}; + +#if (__SIZEOF_SHORT__ != 2 \ + || __SIZEOF_SIZE_T__ != 8 \ + || __SIZEOF_POINTER__ != 8) +#error "Data-type conversion required for rev_offload" +#endif + +#endif /* LIBGOMP_GCN_H */ diff --git a/libgomp/config/gcn/target.c b/libgomp/config/gcn/target.c index c8484fa..2785456 100644 --- a/libgomp/config/gcn/target.c +++ b/libgomp/config/gcn/target.c @@ -24,8 +24,11 @@ <http://www.gnu.org/licenses/>. */ #include "libgomp.h" +#include "libgomp-gcn.h" #include <limits.h> +extern volatile struct gomp_offload_icvs GOMP_ADDITIONAL_ICVS; + bool GOMP_teams4 (unsigned int num_teams_lower, unsigned int num_teams_upper, unsigned int thread_limit, bool first) @@ -75,16 +78,43 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t mapnum, void **hostaddrs, size_t *sizes, unsigned short *kinds, unsigned int flags, void **depend, void **args) { - (void) device; - (void) fn; - (void) mapnum; - (void) hostaddrs; - (void) sizes; - (void) kinds; (void) flags; (void) depend; (void) args; - __builtin_unreachable (); + + if (device != GOMP_DEVICE_HOST_FALLBACK || fn == NULL) + return; + + /* The output data is at ((void*) kernargs)[2]. */ + register void **kernargs = (void**) __builtin_gcn_kernarg_ptr (); + struct output *data = (struct output *) kernargs[2]; + /* Reserve one slot. */ + unsigned int index = __atomic_fetch_add (&data->next_output, 1, + __ATOMIC_ACQUIRE); + + if ((unsigned int) (index + 1) < data->consumed) + abort (); /* Overflow. */ + + /* Spinlock while the host catches up. */ + if (index >= 1024) + while (__atomic_load_n (&data->consumed, __ATOMIC_ACQUIRE) + <= (index - 1024)) + asm ("s_sleep 64"); + + unsigned int slot = index % 1024; + uint64_t addrs_sizes_kind[3] = {(uint64_t) hostaddrs, (uint64_t) sizes, + (uint64_t) kinds}; + data->queue[slot].msg_u64[0] = (uint64_t) fn; + data->queue[slot].msg_u64[1] = (uint64_t) mapnum; + data->queue[slot].value_u64[0] = (uint64_t) &addrs_sizes_kind[0]; + data->queue[slot].value_u64[1] = (uint64_t) GOMP_ADDITIONAL_ICVS.device_num; + + data->queue[slot].type = 4; /* Reverse offload. */ + __atomic_store_n (&data->queue[slot].written, 1, __ATOMIC_RELEASE); + + /* Spinlock while the host catches up. */ + while (__atomic_load_n (&data->queue[slot].written, __ATOMIC_ACQUIRE) != 0) + asm ("s_sleep 64"); } void |