Commit 6ce13072 by Chung-Lin Tang Committed by Chung-Lin Tang

target.c (gomp_device_copy): New function.

libgomp/
2016-05-26  Chung-Lin Tang  <cltang@codesourcery.com>

	* target.c (gomp_device_copy): New function.
	(gomp_copy_host2dev): Likewise.
	(gomp_copy_dev2host): Likewise.
	(gomp_free_device_memory): Likewise.
	(gomp_map_vars_existing): Adjust to call gomp_copy_host2dev.
	(gomp_map_pointer): Likewise.
	(gomp_map_vars): Adjust to call gomp_copy_host2dev, handle
	NULL value from alloc_func plugin hook.
	(gomp_unmap_tgt): Adjust to call gomp_free_device_memory.
	(gomp_copy_from_async): Adjust to call gomp_copy_dev2host.
	(gomp_unmap_vars): Likewise.
	(gomp_update): Adjust to call gomp_copy_dev2host and
	gomp_copy_host2dev functions.
	(gomp_unload_image_from_device): Handle false value from
	unload_image_func plugin hook.
	(gomp_init_device): Handle false value from init_device_func
	plugin hook.
	(gomp_exit_data): Adjust to call gomp_copy_dev2host.
	(omp_target_free): Adjust to call gomp_free_device_memory.
	(omp_target_memcpy): Handle return values from host2dev_func,
	dev2host_func, and dev2dev_func plugin hooks.
	(omp_target_memcpy_rect_worker): Likewise.
	(gomp_target_fini): Handle false value from fini_device_func
	plugin hook.
	* libgomp.h (struct gomp_device_descr): Adjust return type of
	init_device_func, fini_device_func, unload_image_func, free_func,
	dev2host_func,host2dev_func, and dev2dev_func plugin hooks to 'bool'.
	* oacc-init.c (acc_shutdown_1): Handle false value from
	fini_device_func plugin hook.
	* oacc-host.c (host_init_device): Change return type to bool.
	(host_fini_device): Likewise.
	(host_unload_image): Likewise.
	(host_free): Likewise.
	(host_dev2host): Likewise.
	(host_host2dev): Likewise.
	* oacc-mem.c (acc_free): Handle plugin hook fatal error case.
	(acc_memcpy_to_device): Likewise.
	(acc_memcpy_from_device): Likewise.
	(delete_copyout): Add libfnname parameter, handle free_func
	hook fatal error case.
	(acc_delete): Adjust delete_copyout call.
	(acc_copyout): Likewise.
	(update_dev_host): Move gomp_mutex_unlock to after
	host2dev/dev2host hook calls.

	* plugin/plugin-hsa.c (hsa_warn): Adjust 'hsa_error' local variable
	to 'hsa_error_msg', for clarity.
	(hsa_fatal): Likewise.
	(hsa_error): New function.
	(init_hsa_context): Change return type to bool, adjust to return
	false on error.
	(GOMP_OFFLOAD_get_num_devices): Adjust to handle init_hsa_context
	return value.
	(GOMP_OFFLOAD_init_device): Change return type to bool, adjust to
	return false on error.
	(get_agent_info): Adjust to return NULL on error.
	(destroy_hsa_program): Change return type to bool, adjust to
	return false on error.
	(GOMP_OFFLOAD_load_image): Adjust to return -1 on error.
	(destroy_module): Change return type to bool, adjust to
	return false on error.
	(GOMP_OFFLOAD_unload_image): Likewise.
	(GOMP_OFFLOAD_fini_device): Likewise.
	(GOMP_OFFLOAD_alloc): Change to return NULL when called.
	(GOMP_OFFLOAD_free): Change to return false when called.
	(GOMP_OFFLOAD_dev2host): Likewise.
	(GOMP_OFFLOAD_host2dev): Likewise.
	(GOMP_OFFLOAD_dev2dev): Likewise.

	* plugin/plugin-nvptx.c (CUDA_CALL_ERET): New convenience macro.
	(CUDA_CALL): Likewise.
	(CUDA_CALL_ASSERT): Likewise.
	(map_init): Change return type to bool, use CUDA_CALL* macros.
	(map_fini): Likewise.
	(init_streams_for_device): Change return type to bool, adjust
	call to map_init.
	(fini_streams_for_device): Change return type to bool, adjust
	call to map_fini.
	(select_stream_for_async): Release stream_lock before calls to
	GOMP_PLUGIN_fatal, adjust call to map_init.
	(nvptx_init): Use CUDA_CALL* macros.
	(nvptx_attach_host_thread_to_device): Change return type to bool,
	use CUDA_CALL* macros.
	(nvptx_open_device): Use CUDA_CALL* macros.
	(nvptx_close_device): Change return type to bool, use CUDA_CALL*
	macros.
	(nvptx_get_num_devices): Use CUDA_CALL* macros.
	(link_ptx): Change return type to bool, use CUDA_CALL* macros.
	(nvptx_exec): Use CUDA_CALL* macros.
	(nvptx_alloc): Use CUDA_CALL* macros.
	(nvptx_free): Change return type to bool, use CUDA_CALL* macros.
	(nvptx_host2dev): Likewise.
	(nvptx_dev2host): Likewise.
	(nvptx_wait): Use CUDA_CALL* macros.
	(nvptx_wait_async): Likewise.
	(nvptx_wait_all): Likewise.
	(nvptx_wait_all_async): Likewise.
	(nvptx_set_cuda_stream): Adjust order of stream_lock acquire,
	use CUDA_CALL* macros, adjust call to map_fini.
	(GOMP_OFFLOAD_init_device): Change return type to bool,
	adjust code accordingly.
	(GOMP_OFFLOAD_fini_device): Likewise.
	(GOMP_OFFLOAD_load_image): Adjust calls to
	nvptx_attach_host_thread_to_device/link_ptx to handle errors,
	use CUDA_CALL* macros.
	(GOMP_OFFLOAD_unload_image): Change return type to bool, adjust
	return code.
	(GOMP_OFFLOAD_alloc): Adjust calls to code to handle error return.
	(GOMP_OFFLOAD_free): Change return type to bool, adjust calls to
	handle error return.
	(GOMP_OFFLOAD_dev2host): Likewise.
	(GOMP_OFFLOAD_host2dev): Likewise.
	(GOMP_OFFLOAD_openacc_register_async_cleanup): Use CUDA_CALL* macros.
	(GOMP_OFFLOAD_openacc_create_thread_data): Likewise.

liboffloadmic/
2016-05-26  Chung-Lin Tang  <cltang@codesourcery.com>

	* plugin/libgomp-plugin-intelmic.cpp (offload): Change return type
	to bool, adjust return code.
	(GOMP_OFFLOAD_init_device): Likewise.
	(GOMP_OFFLOAD_fini_device): Likewise.
	(get_target_table): Likewise.
	(offload_image): Likwise.
	(GOMP_OFFLOAD_load_image): Adjust call to offload_image(), change
	to return -1 on error.
	(GOMP_OFFLOAD_unload_image): Change return type to bool, adjust return
	code.
	(GOMP_OFFLOAD_alloc): Likewise.
	(GOMP_OFFLOAD_free): Likewise.
	(GOMP_OFFLOAD_host2dev): Likewise.
	(GOMP_OFFLOAD_dev2host): Likewise.
	(GOMP_OFFLOAD_dev2dev): Likewise.

From-SVN: r236768
parent 1875b9a0
2016-05-26 Chung-Lin Tang <cltang@codesourcery.com>
* target.c (gomp_device_copy): New function.
(gomp_copy_host2dev): Likewise.
(gomp_copy_dev2host): Likewise.
(gomp_free_device_memory): Likewise.
(gomp_map_vars_existing): Adjust to call gomp_copy_host2dev.
(gomp_map_pointer): Likewise.
(gomp_map_vars): Adjust to call gomp_copy_host2dev, handle
NULL value from alloc_func plugin hook.
(gomp_unmap_tgt): Adjust to call gomp_free_device_memory.
(gomp_copy_from_async): Adjust to call gomp_copy_dev2host.
(gomp_unmap_vars): Likewise.
(gomp_update): Adjust to call gomp_copy_dev2host and
gomp_copy_host2dev functions.
(gomp_unload_image_from_device): Handle false value from
unload_image_func plugin hook.
(gomp_init_device): Handle false value from init_device_func
plugin hook.
(gomp_exit_data): Adjust to call gomp_copy_dev2host.
(omp_target_free): Adjust to call gomp_free_device_memory.
(omp_target_memcpy): Handle return values from host2dev_func,
dev2host_func, and dev2dev_func plugin hooks.
(omp_target_memcpy_rect_worker): Likewise.
(gomp_target_fini): Handle false value from fini_device_func
plugin hook.
* libgomp.h (struct gomp_device_descr): Adjust return type of
init_device_func, fini_device_func, unload_image_func, free_func,
dev2host_func,host2dev_func, and dev2dev_func plugin hooks to 'bool'.
* oacc-init.c (acc_shutdown_1): Handle false value from
fini_device_func plugin hook.
* oacc-host.c (host_init_device): Change return type to bool.
(host_fini_device): Likewise.
(host_unload_image): Likewise.
(host_free): Likewise.
(host_dev2host): Likewise.
(host_host2dev): Likewise.
* oacc-mem.c (acc_free): Handle plugin hook fatal error case.
(acc_memcpy_to_device): Likewise.
(acc_memcpy_from_device): Likewise.
(delete_copyout): Add libfnname parameter, handle free_func
hook fatal error case.
(acc_delete): Adjust delete_copyout call.
(acc_copyout): Likewise.
(update_dev_host): Move gomp_mutex_unlock to after
host2dev/dev2host hook calls.
* plugin/plugin-hsa.c (hsa_warn): Adjust 'hsa_error' local variable
to 'hsa_error_msg', for clarity.
(hsa_fatal): Likewise.
(hsa_error): New function.
(init_hsa_context): Change return type to bool, adjust to return
false on error.
(GOMP_OFFLOAD_get_num_devices): Adjust to handle init_hsa_context
return value.
(GOMP_OFFLOAD_init_device): Change return type to bool, adjust to
return false on error.
(get_agent_info): Adjust to return NULL on error.
(destroy_hsa_program): Change return type to bool, adjust to
return false on error.
(GOMP_OFFLOAD_load_image): Adjust to return -1 on error.
(destroy_module): Change return type to bool, adjust to
return false on error.
(GOMP_OFFLOAD_unload_image): Likewise.
(GOMP_OFFLOAD_fini_device): Likewise.
(GOMP_OFFLOAD_alloc): Change to return NULL when called.
(GOMP_OFFLOAD_free): Change to return false when called.
(GOMP_OFFLOAD_dev2host): Likewise.
(GOMP_OFFLOAD_host2dev): Likewise.
(GOMP_OFFLOAD_dev2dev): Likewise.
* plugin/plugin-nvptx.c (CUDA_CALL_ERET): New convenience macro.
(CUDA_CALL): Likewise.
(CUDA_CALL_ASSERT): Likewise.
(map_init): Change return type to bool, use CUDA_CALL* macros.
(map_fini): Likewise.
(init_streams_for_device): Change return type to bool, adjust
call to map_init.
(fini_streams_for_device): Change return type to bool, adjust
call to map_fini.
(select_stream_for_async): Release stream_lock before calls to
GOMP_PLUGIN_fatal, adjust call to map_init.
(nvptx_init): Use CUDA_CALL* macros.
(nvptx_attach_host_thread_to_device): Change return type to bool,
use CUDA_CALL* macros.
(nvptx_open_device): Use CUDA_CALL* macros.
(nvptx_close_device): Change return type to bool, use CUDA_CALL*
macros.
(nvptx_get_num_devices): Use CUDA_CALL* macros.
(link_ptx): Change return type to bool, use CUDA_CALL* macros.
(nvptx_exec): Use CUDA_CALL* macros.
(nvptx_alloc): Use CUDA_CALL* macros.
(nvptx_free): Change return type to bool, use CUDA_CALL* macros.
(nvptx_host2dev): Likewise.
(nvptx_dev2host): Likewise.
(nvptx_wait): Use CUDA_CALL* macros.
(nvptx_wait_async): Likewise.
(nvptx_wait_all): Likewise.
(nvptx_wait_all_async): Likewise.
(nvptx_set_cuda_stream): Adjust order of stream_lock acquire,
use CUDA_CALL* macros, adjust call to map_fini.
(GOMP_OFFLOAD_init_device): Change return type to bool,
adjust code accordingly.
(GOMP_OFFLOAD_fini_device): Likewise.
(GOMP_OFFLOAD_load_image): Adjust calls to
nvptx_attach_host_thread_to_device/link_ptx to handle errors,
use CUDA_CALL* macros.
(GOMP_OFFLOAD_unload_image): Change return type to bool, adjust
return code.
(GOMP_OFFLOAD_alloc): Adjust calls to code to handle error return.
(GOMP_OFFLOAD_free): Change return type to bool, adjust calls to
handle error return.
(GOMP_OFFLOAD_dev2host): Likewise.
(GOMP_OFFLOAD_host2dev): Likewise.
(GOMP_OFFLOAD_openacc_register_async_cleanup): Use CUDA_CALL* macros.
(GOMP_OFFLOAD_openacc_create_thread_data): Likewise.
2016-05-24 Cesar Philippidis <cesar@codesourcery.com>
* oacc-mem.c (acc_malloc): Update handling of shared-memory targets.
......
......@@ -930,16 +930,16 @@ struct gomp_device_descr
unsigned int (*get_caps_func) (void);
int (*get_type_func) (void);
int (*get_num_devices_func) (void);
void (*init_device_func) (int);
void (*fini_device_func) (int);
bool (*init_device_func) (int);
bool (*fini_device_func) (int);
unsigned (*version_func) (void);
int (*load_image_func) (int, unsigned, const void *, struct addr_pair **);
void (*unload_image_func) (int, unsigned, const void *);
bool (*unload_image_func) (int, unsigned, const void *);
void *(*alloc_func) (int, size_t);
void (*free_func) (int, void *);
void *(*dev2host_func) (int, void *, const void *, size_t);
void *(*host2dev_func) (int, void *, const void *, size_t);
void *(*dev2dev_func) (int, void *, const void *, size_t);
bool (*free_func) (int, void *);
bool (*dev2host_func) (int, void *, const void *, size_t);
bool (*host2dev_func) (int, void *, const void *, size_t);
bool (*dev2dev_func) (int, void *, const void *, size_t);
bool (*can_run_func) (void *);
void (*run_func) (int, void *, void *, void **);
void (*async_run_func) (int, void *, void *, void **, void *);
......
......@@ -60,14 +60,16 @@ host_get_num_devices (void)
return 1;
}
static void
static bool
host_init_device (int n __attribute__ ((unused)))
{
return true;
}
static void
static bool
host_fini_device (int n __attribute__ ((unused)))
{
return true;
}
static unsigned
......@@ -85,11 +87,12 @@ host_load_image (int n __attribute__ ((unused)),
return 0;
}
static void
static bool
host_unload_image (int n __attribute__ ((unused)),
unsigned v __attribute__ ((unused)),
const void *t __attribute__ ((unused)))
{
return true;
}
static void *
......@@ -98,28 +101,29 @@ host_alloc (int n __attribute__ ((unused)), size_t s)
return gomp_malloc (s);
}
static void
static bool
host_free (int n __attribute__ ((unused)), void *p)
{
free (p);
return true;
}
static void *
static bool
host_dev2host (int n __attribute__ ((unused)),
void *h __attribute__ ((unused)),
const void *d __attribute__ ((unused)),
size_t s __attribute__ ((unused)))
{
return NULL;
return true;
}
static void *
static bool
host_host2dev (int n __attribute__ ((unused)),
void *d __attribute__ ((unused)),
const void *h __attribute__ ((unused)),
size_t s __attribute__ ((unused)))
{
return NULL;
return true;
}
static void
......
......@@ -300,8 +300,8 @@ acc_shutdown_1 (acc_device_t d)
gomp_mutex_unlock (&goacc_thread_lock);
/* Close all the devices of this type that have been opened. */
bool ret = true;
for (i = 0; i < ndevs; i++)
{
struct gomp_device_descr *acc_dev = &base_dev[i];
......@@ -309,12 +309,15 @@ acc_shutdown_1 (acc_device_t d)
if (acc_dev->state == GOMP_DEVICE_INITIALIZED)
{
devices_active = true;
acc_dev->fini_device_func (acc_dev->target_id);
ret &= acc_dev->fini_device_func (acc_dev->target_id);
acc_dev->state = GOMP_DEVICE_UNINITIALIZED;
}
gomp_mutex_unlock (&acc_dev->lock);
}
if (!ret)
gomp_fatal ("device finalization failed");
if (!devices_active)
gomp_fatal ("no device initialized");
}
......
......@@ -149,7 +149,8 @@ acc_free (void *d)
else
gomp_mutex_unlock (&acc_dev->lock);
acc_dev->free_func (acc_dev->target_id, d);
if (!acc_dev->free_func (acc_dev->target_id, d))
gomp_fatal ("error in freeing device memory in %s", __FUNCTION__);
}
void
......@@ -167,7 +168,8 @@ acc_memcpy_to_device (void *d, void *h, size_t s)
return;
}
thr->dev->host2dev_func (thr->dev->target_id, d, h, s);
if (!thr->dev->host2dev_func (thr->dev->target_id, d, h, s))
gomp_fatal ("error in %s", __FUNCTION__);
}
void
......@@ -185,7 +187,8 @@ acc_memcpy_from_device (void *h, void *d, size_t s)
return;
}
thr->dev->dev2host_func (thr->dev->target_id, h, d, s);
if (!thr->dev->dev2host_func (thr->dev->target_id, h, d, s))
gomp_fatal ("error in %s", __FUNCTION__);
}
/* Return the device pointer that corresponds to host data H. Or NULL
......@@ -520,7 +523,7 @@ acc_present_or_copyin (void *h, size_t s)
#define FLAG_COPYOUT (1 << 0)
static void
delete_copyout (unsigned f, void *h, size_t s)
delete_copyout (unsigned f, void *h, size_t s, const char *libfnname)
{
size_t host_size;
splay_tree_key n;
......@@ -563,18 +566,20 @@ delete_copyout (unsigned f, void *h, size_t s)
acc_unmap_data (h);
acc_dev->free_func (acc_dev->target_id, d);
if (!acc_dev->free_func (acc_dev->target_id, d))
gomp_fatal ("error in freeing device memory in %s", libfnname);
}
void
acc_delete (void *h , size_t s)
{
delete_copyout (0, h, s);
delete_copyout (0, h, s, __FUNCTION__);
}
void acc_copyout (void *h, size_t s)
void
acc_copyout (void *h, size_t s)
{
delete_copyout (FLAG_COPYOUT, h, s);
delete_copyout (FLAG_COPYOUT, h, s, __FUNCTION__);
}
static void
......@@ -604,12 +609,12 @@ update_dev_host (int is_dev, void *h, size_t s)
d = (void *) (n->tgt->tgt_start + n->tgt_offset
+ (uintptr_t) h - n->host_start);
gomp_mutex_unlock (&acc_dev->lock);
if (is_dev)
acc_dev->host2dev_func (acc_dev->target_id, d, h, s);
else
acc_dev->dev2host_func (acc_dev->target_id, h, d, s);
gomp_mutex_unlock (&acc_dev->lock);
}
void
......
2016-05-26 Chung-Lin Tang <cltang@codesourcery.com>
* plugin/libgomp-plugin-intelmic.cpp (offload): Change return type
to bool, adjust return code.
(GOMP_OFFLOAD_init_device): Likewise.
(GOMP_OFFLOAD_fini_device): Likewise.
(get_target_table): Likewise.
(offload_image): Likwise.
(GOMP_OFFLOAD_load_image): Adjust call to offload_image(), change
to return -1 on error.
(GOMP_OFFLOAD_unload_image): Change return type to bool, adjust return
code.
(GOMP_OFFLOAD_alloc): Likewise.
(GOMP_OFFLOAD_free): Likewise.
(GOMP_OFFLOAD_host2dev): Likewise.
(GOMP_OFFLOAD_dev2host): Likewise.
(GOMP_OFFLOAD_dev2dev): Likewise.
2016-01-20 Ilya Verbin <ilya.verbin@intel.com>
* plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_run): Pass extra NULL
......
......@@ -205,7 +205,7 @@ GOMP_OFFLOAD_get_num_devices (void)
return num_devices;
}
static void
static bool
offload (const char *file, uint64_t line, int device, const char *name,
int num_vars, VarDesc *vars, const void **async_data)
{
......@@ -213,20 +213,21 @@ offload (const char *file, uint64_t line, int device, const char *name,
if (ofld)
{
if (async_data == NULL)
__offload_offload1 (ofld, name, 0, num_vars, vars, NULL, 0, NULL, NULL);
return __offload_offload1 (ofld, name, 0, num_vars, vars, NULL, 0,
NULL, NULL);
else
{
OffloadFlags flags;
flags.flags = 0;
flags.bits.omp_async = 1;
__offload_offload3 (ofld, name, 0, num_vars, vars, NULL, 0, NULL,
async_data, 0, NULL, flags, NULL);
return __offload_offload3 (ofld, name, 0, num_vars, vars, NULL, 0,
NULL, async_data, 0, NULL, flags, NULL);
}
}
else
{
fprintf (stderr, "%s:%d: Offload target acquire failed\n", file, line);
exit (1);
GOMP_PLUGIN_error ("%s:%d: Offload target acquire failed\n", file, line);
return false;
}
}
......@@ -244,25 +245,26 @@ register_main_image ()
/* liboffloadmic loads and runs offload_target_main on all available devices
during a first call to offload (). */
extern "C" void
extern "C" bool
GOMP_OFFLOAD_init_device (int device)
{
TRACE ("(device = %d)", device);
pthread_once (&main_image_is_registered, register_main_image);
offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0, NULL,
NULL);
return offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0,
NULL, NULL);
}
extern "C" void
extern "C" bool
GOMP_OFFLOAD_fini_device (int device)
{
TRACE ("(device = %d)", device);
/* liboffloadmic will finalize target processes on all available devices. */
__offload_unregister_image (&main_target_image);
return true;
}
static void
static bool
get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
{
VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
......@@ -271,8 +273,9 @@ get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
vd1[1].ptr = &num_vars;
vd1[1].size = sizeof (num_vars);
offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2, vd1,
NULL);
if (!offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2,
vd1, NULL))
return false;
int table_size = num_funcs + 2 * num_vars;
if (table_size > 0)
......@@ -284,15 +287,16 @@ get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
vd2.ptr = table;
vd2.size = table_size * sizeof (void *);
offload (__FILE__, __LINE__, device, "__offload_target_table_p2", 1, &vd2,
NULL);
return offload (__FILE__, __LINE__, device, "__offload_target_table_p2",
1, &vd2, NULL);
}
return true;
}
/* Offload TARGET_IMAGE to all available devices and fill address_table with
corresponding target addresses. */
static void
static bool
offload_image (const void *target_image)
{
void *image_start = ((void **) target_image)[0];
......@@ -306,8 +310,8 @@ offload_image (const void *target_image)
+ image_size);
if (!image)
{
fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
exit (1);
GOMP_PLUGIN_error ("%s: Can't allocate memory\n", __FILE__);
return false;
}
image->size = image_size;
......@@ -322,13 +326,14 @@ offload_image (const void *target_image)
/* Receive tables for target_image from all devices. */
DevAddrVect dev_table;
bool ret = true;
for (int dev = 0; dev < num_devices; dev++)
{
int num_funcs = 0;
int num_vars = 0;
void **table = NULL;
get_target_table (dev, num_funcs, num_vars, table);
ret &= get_target_table (dev, num_funcs, num_vars, table);
AddrVect curr_dev_table;
......@@ -357,6 +362,7 @@ offload_image (const void *target_image)
address_table->insert (std::make_pair (target_image, dev_table));
image_descriptors->insert (std::make_pair (target_image, image));
return ret;
}
/* Return the libgomp version number we're compatible with. There is
......@@ -375,22 +381,29 @@ GOMP_OFFLOAD_load_image (int device, const unsigned version,
TRACE ("(device = %d, target_image = %p)", device, target_image);
if (GOMP_VERSION_DEV (version) > GOMP_VERSION_INTEL_MIC)
GOMP_PLUGIN_fatal ("Offload data incompatible with intelmic plugin"
" (expected %u, received %u)",
GOMP_VERSION_INTEL_MIC, GOMP_VERSION_DEV (version));
{
GOMP_PLUGIN_error ("Offload data incompatible with intelmic plugin"
" (expected %u, received %u)",
GOMP_VERSION_INTEL_MIC, GOMP_VERSION_DEV (version));
return -1;
}
/* If target_image is already present in address_table, then there is no need
to offload it. */
if (address_table->count (target_image) == 0)
offload_image (target_image);
{
/* If fail, return -1 as error code. */
if (!offload_image (target_image))
return -1;
}
AddrVect *curr_dev_table = &(*address_table)[target_image][device];
int table_size = curr_dev_table->size ();
addr_pair *table = (addr_pair *) malloc (table_size * sizeof (addr_pair));
if (table == NULL)
{
fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
exit (1);
GOMP_PLUGIN_error ("%s: Can't allocate memory\n", __FILE__);
return -1;
}
std::copy (curr_dev_table->begin (), curr_dev_table->end (), table);
......@@ -398,12 +411,17 @@ GOMP_OFFLOAD_load_image (int device, const unsigned version,
return table_size;
}
extern "C" void
extern "C" bool
GOMP_OFFLOAD_unload_image (int device, unsigned version,
const void *target_image)
{
if (GOMP_VERSION_DEV (version) > GOMP_VERSION_INTEL_MIC)
return;
{
GOMP_PLUGIN_error ("Offload data incompatible with intelmic plugin"
" (expected %u, received %u)",
GOMP_VERSION_INTEL_MIC, GOMP_VERSION_DEV (version));
return false;
}
TRACE ("(device = %d, target_image = %p)", device, target_image);
......@@ -417,6 +435,7 @@ GOMP_OFFLOAD_unload_image (int device, unsigned version,
address_table->erase (target_image);
image_descriptors->erase (target_image);
}
return true;
}
extern "C" void *
......@@ -431,12 +450,14 @@ GOMP_OFFLOAD_alloc (int device, size_t size)
vd[1].ptr = &tgt_ptr;
vd[1].size = sizeof (void *);
offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2, vd, NULL);
if (!offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2,
vd, NULL))
return NULL;
return tgt_ptr;
}
extern "C" void
extern "C" bool
GOMP_OFFLOAD_free (int device, void *tgt_ptr)
{
TRACE ("(device = %d, tgt_ptr = %p)", device, tgt_ptr);
......@@ -445,17 +466,18 @@ GOMP_OFFLOAD_free (int device, void *tgt_ptr)
vd.ptr = &tgt_ptr;
vd.size = sizeof (void *);
offload (__FILE__, __LINE__, device, "__offload_target_free", 1, &vd, NULL);
return offload (__FILE__, __LINE__, device, "__offload_target_free", 1,
&vd, NULL);
}
extern "C" void *
extern "C" bool
GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
size_t size)
{
TRACE ("(device = %d, tgt_ptr = %p, host_ptr = %p, size = %d)",
device, tgt_ptr, host_ptr, size);
if (!size)
return tgt_ptr;
return true;
VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
vd1[0].ptr = &tgt_ptr;
......@@ -463,27 +485,26 @@ GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
vd1[1].ptr = &size;
vd1[1].size = sizeof (size);
offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2, vd1,
NULL);
if (!offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2,
vd1, NULL))
return false;
VarDesc vd2 = vd_host2tgt;
vd2.ptr = (void *) host_ptr;
vd2.size = size;
offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1, &vd2,
NULL);
return tgt_ptr;
return offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1,
&vd2, NULL);
}
extern "C" void *
extern "C" bool
GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
size_t size)
{
TRACE ("(device = %d, host_ptr = %p, tgt_ptr = %p, size = %d)",
device, host_ptr, tgt_ptr, size);
if (!size)
return host_ptr;
return true;
VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
vd1[0].ptr = &tgt_ptr;
......@@ -491,27 +512,26 @@ GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
vd1[1].ptr = &size;
vd1[1].size = sizeof (size);
offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2, vd1,
NULL);
if (!offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2,
vd1, NULL))
return false;
VarDesc vd2 = vd_tgt2host;
vd2.ptr = (void *) host_ptr;
vd2.size = size;
offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1, &vd2,
NULL);
return host_ptr;
return offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1,
&vd2, NULL);
}
extern "C" void *
extern "C" bool
GOMP_OFFLOAD_dev2dev (int device, void *dst_ptr, const void *src_ptr,
size_t size)
{
TRACE ("(device = %d, dst_ptr = %p, src_ptr = %p, size = %d)",
device, dst_ptr, src_ptr, size);
if (!size)
return dst_ptr;
return true;
VarDesc vd[3] = { vd_host2tgt, vd_host2tgt, vd_host2tgt };
vd[0].ptr = &dst_ptr;
......@@ -521,9 +541,8 @@ GOMP_OFFLOAD_dev2dev (int device, void *dst_ptr, const void *src_ptr,
vd[2].ptr = &size;
vd[2].size = sizeof (size);
offload (__FILE__, __LINE__, device, "__offload_target_tgt2tgt", 3, vd, NULL);
return dst_ptr;
return offload (__FILE__, __LINE__, device, "__offload_target_tgt2tgt", 3,
vd, NULL);
}
extern "C" void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment