1f4c5b9bb2
Reviewed-by: Thomas Schwinge <thomas@codesourcery.com> libgomp/ * libgomp-plugin.h (struct goacc_asyncqueue): Declare. (struct goacc_asyncqueue_list): Likewise. (goacc_aq): Likewise. (goacc_aq_list): Likewise. (GOMP_OFFLOAD_openacc_register_async_cleanup): Remove. (GOMP_OFFLOAD_openacc_async_test): Remove. (GOMP_OFFLOAD_openacc_async_test_all): Remove. (GOMP_OFFLOAD_openacc_async_wait): Remove. (GOMP_OFFLOAD_openacc_async_wait_async): Remove. (GOMP_OFFLOAD_openacc_async_wait_all): Remove. (GOMP_OFFLOAD_openacc_async_wait_all_async): Remove. (GOMP_OFFLOAD_openacc_async_set_async): Remove. (GOMP_OFFLOAD_openacc_exec): Adjust declaration. (GOMP_OFFLOAD_openacc_cuda_get_stream): Likewise. (GOMP_OFFLOAD_openacc_cuda_set_stream): Likewise. (GOMP_OFFLOAD_openacc_async_exec): Declare. (GOMP_OFFLOAD_openacc_async_construct): Declare. (GOMP_OFFLOAD_openacc_async_destruct): Declare. (GOMP_OFFLOAD_openacc_async_test): Declare. (GOMP_OFFLOAD_openacc_async_synchronize): Declare. (GOMP_OFFLOAD_openacc_async_serialize): Declare. (GOMP_OFFLOAD_openacc_async_queue_callback): Declare. (GOMP_OFFLOAD_openacc_async_host2dev): Declare. (GOMP_OFFLOAD_openacc_async_dev2host): Declare. * libgomp.h (struct acc_dispatch_t): Define 'async' sub-struct. (gomp_acc_insert_pointer): Adjust declaration. (gomp_copy_host2dev): New declaration. (gomp_copy_dev2host): Likewise. (gomp_map_vars_async): Likewise. (gomp_unmap_tgt): Likewise. (gomp_unmap_vars_async): Likewise. (gomp_fini_device): Likewise. * oacc-async.c (get_goacc_thread): New function. (get_goacc_thread_device): New function. (lookup_goacc_asyncqueue): New function. (get_goacc_asyncqueue): New function. (acc_async_test): Adjust code to use new async design. (acc_async_test_all): Likewise. (acc_wait): Likewise. (acc_wait_async): Likewise. (acc_wait_all): Likewise. (acc_wait_all_async): Likewise. (goacc_async_free): New function. (goacc_init_asyncqueues): Likewise. (goacc_fini_asyncqueues): Likewise. * oacc-cuda.c (acc_get_cuda_stream): Adjust code to use new async design. (acc_set_cuda_stream): Likewise. * oacc-host.c (host_openacc_exec): Adjust parameters, remove 'async'. (host_openacc_register_async_cleanup): Remove. (host_openacc_async_exec): New function. (host_openacc_async_test): Adjust parameters. (host_openacc_async_test_all): Remove. (host_openacc_async_wait): Remove. (host_openacc_async_wait_async): Remove. (host_openacc_async_wait_all): Remove. (host_openacc_async_wait_all_async): Remove. (host_openacc_async_set_async): Remove. (host_openacc_async_synchronize): New function. (host_openacc_async_serialize): New function. (host_openacc_async_host2dev): New function. (host_openacc_async_dev2host): New function. (host_openacc_async_queue_callback): New function. (host_openacc_async_construct): New function. (host_openacc_async_destruct): New function. (struct gomp_device_descr host_dispatch): Remove initialization of old interface, add intialization of new async sub-struct. * oacc-init.c (acc_shutdown_1): Adjust to use gomp_fini_device. (goacc_attach_host_thread_to_device): Remove old async code usage. * oacc-int.h (goacc_init_asyncqueues): New declaration. (goacc_fini_asyncqueues): Likewise. (goacc_async_copyout_unmap_vars): Likewise. (goacc_async_free): Likewise. (get_goacc_asyncqueue): Likewise. (lookup_goacc_asyncqueue): Likewise. * oacc-mem.c (memcpy_tofrom_device): Adjust code to use new async design. (present_create_copy): Adjust code to use new async design. (delete_copyout): Likewise. (update_dev_host): Likewise. (gomp_acc_insert_pointer): Add async parameter, adjust code to use new async design. (gomp_acc_remove_pointer): Adjust code to use new async design. * oacc-parallel.c (GOACC_parallel_keyed): Adjust code to use new async design. (GOACC_enter_exit_data): Likewise. (goacc_wait): Likewise. (GOACC_update): Likewise. * oacc-plugin.c (GOMP_PLUGIN_async_unmap_vars): Change to assert fail when called, warn as obsolete in comment. * target.c (goacc_device_copy_async): New function. (gomp_copy_host2dev): Remove 'static', add goacc_asyncqueue parameter, add goacc_device_copy_async case. (gomp_copy_dev2host): Likewise. (gomp_map_vars_existing): Add goacc_asyncqueue parameter, adjust code. (gomp_map_pointer): Likewise. (gomp_map_fields_existing): Likewise. (gomp_map_vars_internal): New always_inline function, renamed from gomp_map_vars. (gomp_map_vars): Implement by calling gomp_map_vars_internal. (gomp_map_vars_async): Implement by calling gomp_map_vars_internal, passing goacc_asyncqueue argument. (gomp_unmap_tgt): Remove static, add attribute_hidden. (gomp_unref_tgt): New function. (gomp_unmap_vars_internal): New always_inline function, renamed from gomp_unmap_vars. (gomp_unmap_vars): Implement by calling gomp_unmap_vars_internal. (gomp_unmap_vars_async): Implement by calling gomp_unmap_vars_internal, passing goacc_asyncqueue argument. (gomp_fini_device): New function. (gomp_exit_data): Adjust gomp_copy_dev2host call. (gomp_load_plugin_for_device): Remove old interface, adjust to load new async interface. (gomp_target_fini): Adjust code to call gomp_fini_device. * plugin/plugin-nvptx.c (struct cuda_map): Remove. (struct ptx_stream): Remove. (struct nvptx_thread): Remove current_stream field. (cuda_map_create): Remove. (cuda_map_destroy): Remove. (map_init): Remove. (map_fini): Remove. (map_pop): Remove. (map_push): Remove. (struct goacc_asyncqueue): Define. (struct nvptx_callback): Define. (struct ptx_free_block): Define. (struct ptx_device): Remove null_stream, active_streams, async_streams, stream_lock, and next fields. (enum ptx_event_type): Remove. (struct ptx_event): Remove. (ptx_event_lock): Remove. (ptx_events): Remove. (init_streams_for_device): Remove. (fini_streams_for_device): Remove. (select_stream_for_async): Remove. (nvptx_init): Remove ptx_events and ptx_event_lock references. (nvptx_attach_host_thread_to_device): Remove CUDA_ERROR_NOT_PERMITTED case. (nvptx_open_device): Add free_blocks initialization, remove init_streams_for_device call. (nvptx_close_device): Remove fini_streams_for_device call, add free_blocks destruct code. (event_gc): Remove. (event_add): Remove. (nvptx_exec): Adjust parameters and code. (nvptx_free): Likewise. (nvptx_host2dev): Remove. (nvptx_dev2host): Remove. (nvptx_set_async): Remove. (nvptx_async_test): Remove. (nvptx_async_test_all): Remove. (nvptx_wait): Remove. (nvptx_wait_async): Remove. (nvptx_wait_all): Remove. (nvptx_wait_all_async): Remove. (nvptx_get_cuda_stream): Remove. (nvptx_set_cuda_stream): Remove. (GOMP_OFFLOAD_alloc): Adjust code. (GOMP_OFFLOAD_free): Likewise. (GOMP_OFFLOAD_openacc_register_async_cleanup): Remove. (GOMP_OFFLOAD_openacc_exec): Adjust parameters and code. (GOMP_OFFLOAD_openacc_async_test_all): Remove. (GOMP_OFFLOAD_openacc_async_wait): Remove. (GOMP_OFFLOAD_openacc_async_wait_async): Remove. (GOMP_OFFLOAD_openacc_async_wait_all): Remove. (GOMP_OFFLOAD_openacc_async_wait_all_async): Remove. (GOMP_OFFLOAD_openacc_async_set_async): Remove. (cuda_free_argmem): New function. (GOMP_OFFLOAD_openacc_async_exec): New plugin hook function. (GOMP_OFFLOAD_openacc_create_thread_data): Adjust code. (GOMP_OFFLOAD_openacc_cuda_get_stream): Adjust code. (GOMP_OFFLOAD_openacc_cuda_set_stream): Adjust code. (GOMP_OFFLOAD_openacc_async_construct): New plugin hook function. (GOMP_OFFLOAD_openacc_async_destruct): New plugin hook function. (GOMP_OFFLOAD_openacc_async_test): Remove and re-implement. (GOMP_OFFLOAD_openacc_async_synchronize): New plugin hook function. (GOMP_OFFLOAD_openacc_async_serialize): New plugin hook function. (GOMP_OFFLOAD_openacc_async_queue_callback): New plugin hook function. (cuda_callback_wrapper): New function. (cuda_memcpy_sanity_check): New function. (GOMP_OFFLOAD_host2dev): Remove and re-implement. (GOMP_OFFLOAD_dev2host): Remove and re-implement. (GOMP_OFFLOAD_openacc_async_host2dev): New plugin hook function. (GOMP_OFFLOAD_openacc_async_dev2host): New plugin hook function. From-SVN: r271128
303 lines
7.1 KiB
C
303 lines
7.1 KiB
C
/* OpenACC Runtime Library: acc_device_host.
|
|
|
|
Copyright (C) 2013-2019 Free Software Foundation, Inc.
|
|
|
|
Contributed by Mentor Embedded.
|
|
|
|
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/>. */
|
|
|
|
#include "libgomp.h"
|
|
#include "oacc-int.h"
|
|
#include "gomp-constants.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
static struct gomp_device_descr host_dispatch;
|
|
|
|
static const char *
|
|
host_get_name (void)
|
|
{
|
|
return host_dispatch.name;
|
|
}
|
|
|
|
static unsigned int
|
|
host_get_caps (void)
|
|
{
|
|
return host_dispatch.capabilities;
|
|
}
|
|
|
|
static int
|
|
host_get_type (void)
|
|
{
|
|
return host_dispatch.type;
|
|
}
|
|
|
|
static int
|
|
host_get_num_devices (void)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
static bool
|
|
host_init_device (int n __attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
host_fini_device (int n __attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static unsigned
|
|
host_version (void)
|
|
{
|
|
return GOMP_VERSION;
|
|
}
|
|
|
|
static int
|
|
host_load_image (int n __attribute__ ((unused)),
|
|
unsigned v __attribute__ ((unused)),
|
|
const void *t __attribute__ ((unused)),
|
|
struct addr_pair **r __attribute__ ((unused)))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static bool
|
|
host_unload_image (int n __attribute__ ((unused)),
|
|
unsigned v __attribute__ ((unused)),
|
|
const void *t __attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static void *
|
|
host_alloc (int n __attribute__ ((unused)), size_t s)
|
|
{
|
|
return gomp_malloc (s);
|
|
}
|
|
|
|
static bool
|
|
host_free (int n __attribute__ ((unused)), void *p)
|
|
{
|
|
free (p);
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
host_dev2host (int n __attribute__ ((unused)),
|
|
void *h __attribute__ ((unused)),
|
|
const void *d __attribute__ ((unused)),
|
|
size_t s __attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
host_host2dev (int n __attribute__ ((unused)),
|
|
void *d __attribute__ ((unused)),
|
|
const void *h __attribute__ ((unused)),
|
|
size_t s __attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static void
|
|
host_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars,
|
|
void **args __attribute__((unused)))
|
|
{
|
|
void (*fn)(void *) = (void (*)(void *)) fn_ptr;
|
|
|
|
fn (vars);
|
|
}
|
|
|
|
static void
|
|
host_openacc_exec (void (*fn) (void *),
|
|
size_t mapnum __attribute__ ((unused)),
|
|
void **hostaddrs,
|
|
void **devaddrs __attribute__ ((unused)),
|
|
unsigned *dims __attribute__ ((unused)),
|
|
void *targ_mem_desc __attribute__ ((unused)))
|
|
{
|
|
fn (hostaddrs);
|
|
}
|
|
|
|
static void
|
|
host_openacc_async_exec (void (*fn) (void *),
|
|
size_t mapnum __attribute__ ((unused)),
|
|
void **hostaddrs,
|
|
void **devaddrs __attribute__ ((unused)),
|
|
unsigned *dims __attribute__ ((unused)),
|
|
void *targ_mem_desc __attribute__ ((unused)),
|
|
struct goacc_asyncqueue *aq __attribute__ ((unused)))
|
|
{
|
|
fn (hostaddrs);
|
|
}
|
|
|
|
static int
|
|
host_openacc_async_test (struct goacc_asyncqueue *aq __attribute__ ((unused)))
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
static bool
|
|
host_openacc_async_synchronize (struct goacc_asyncqueue *aq
|
|
__attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
host_openacc_async_serialize (struct goacc_asyncqueue *aq1
|
|
__attribute__ ((unused)),
|
|
struct goacc_asyncqueue *aq2
|
|
__attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
host_openacc_async_host2dev (int ord __attribute__ ((unused)),
|
|
void *dst __attribute__ ((unused)),
|
|
const void *src __attribute__ ((unused)),
|
|
size_t n __attribute__ ((unused)),
|
|
struct goacc_asyncqueue *aq
|
|
__attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
host_openacc_async_dev2host (int ord __attribute__ ((unused)),
|
|
void *dst __attribute__ ((unused)),
|
|
const void *src __attribute__ ((unused)),
|
|
size_t n __attribute__ ((unused)),
|
|
struct goacc_asyncqueue *aq
|
|
__attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static void
|
|
host_openacc_async_queue_callback (struct goacc_asyncqueue *aq
|
|
__attribute__ ((unused)),
|
|
void (*callback_fn)(void *)
|
|
__attribute__ ((unused)),
|
|
void *userptr __attribute__ ((unused)))
|
|
{
|
|
}
|
|
|
|
static struct goacc_asyncqueue *
|
|
host_openacc_async_construct (void)
|
|
{
|
|
/* Non-NULL 0xffff... value as opaque dummy. */
|
|
return (struct goacc_asyncqueue *) -1;
|
|
}
|
|
|
|
static bool
|
|
host_openacc_async_destruct (struct goacc_asyncqueue *aq
|
|
__attribute__ ((unused)))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
static void *
|
|
host_openacc_create_thread_data (int ord __attribute__ ((unused)))
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static void
|
|
host_openacc_destroy_thread_data (void *tls_data __attribute__ ((unused)))
|
|
{
|
|
}
|
|
|
|
static struct gomp_device_descr host_dispatch =
|
|
{
|
|
.name = "host",
|
|
.capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
|
|
| GOMP_OFFLOAD_CAP_NATIVE_EXEC
|
|
| GOMP_OFFLOAD_CAP_OPENACC_200),
|
|
.target_id = 0,
|
|
.type = OFFLOAD_TARGET_TYPE_HOST,
|
|
|
|
.get_name_func = host_get_name,
|
|
.get_caps_func = host_get_caps,
|
|
.get_type_func = host_get_type,
|
|
.get_num_devices_func = host_get_num_devices,
|
|
.init_device_func = host_init_device,
|
|
.fini_device_func = host_fini_device,
|
|
.version_func = host_version,
|
|
.load_image_func = host_load_image,
|
|
.unload_image_func = host_unload_image,
|
|
.alloc_func = host_alloc,
|
|
.free_func = host_free,
|
|
.dev2host_func = host_dev2host,
|
|
.host2dev_func = host_host2dev,
|
|
.run_func = host_run,
|
|
|
|
.mem_map = { NULL },
|
|
/* .lock initilized in goacc_host_init. */
|
|
.state = GOMP_DEVICE_UNINITIALIZED,
|
|
|
|
.openacc = {
|
|
.data_environ = NULL,
|
|
|
|
.exec_func = host_openacc_exec,
|
|
|
|
.create_thread_data_func = host_openacc_create_thread_data,
|
|
.destroy_thread_data_func = host_openacc_destroy_thread_data,
|
|
|
|
.async = {
|
|
.construct_func = host_openacc_async_construct,
|
|
.destruct_func = host_openacc_async_destruct,
|
|
.test_func = host_openacc_async_test,
|
|
.synchronize_func = host_openacc_async_synchronize,
|
|
.serialize_func = host_openacc_async_serialize,
|
|
.queue_callback_func = host_openacc_async_queue_callback,
|
|
.exec_func = host_openacc_async_exec,
|
|
.dev2host_func = host_openacc_async_dev2host,
|
|
.host2dev_func = host_openacc_async_host2dev,
|
|
},
|
|
|
|
.cuda = {
|
|
.get_current_device_func = NULL,
|
|
.get_current_context_func = NULL,
|
|
.get_stream_func = NULL,
|
|
.set_stream_func = NULL,
|
|
}
|
|
}
|
|
};
|
|
|
|
/* Initialize and register this device type. */
|
|
void
|
|
goacc_host_init (void)
|
|
{
|
|
gomp_mutex_init (&host_dispatch.lock);
|
|
goacc_register (&host_dispatch);
|
|
}
|