summaryrefslogtreecommitdiff
path: root/liboffloadmic
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-16 15:14:01 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-16 15:14:01 +0000
commitdd329d30040f8c9e493bf85514c364d5ac5d6551 (patch)
tree009b43e2a42820164aa4dc34cf57b12d25d56b3a /liboffloadmic
parent2eb0fcbc8f9d73d8061a4634e4e3c9169fc862d8 (diff)
downloadgcc-dd329d30040f8c9e493bf85514c364d5ac5d6551.tar.gz
2016-04-16 Basile Starynkevitch <basile@starynkevitch.net>
{{merging with even more of GCC 6, using subversion 1.9 svn merge -r230196:230700 ^/trunk }} git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@235061 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'liboffloadmic')
-rw-r--r--liboffloadmic/ChangeLog53
-rw-r--r--liboffloadmic/plugin/libgomp-plugin-intelmic.cpp197
-rw-r--r--liboffloadmic/plugin/offload_target_main.cpp121
-rw-r--r--liboffloadmic/runtime/offload_host.cpp9
-rw-r--r--liboffloadmic/runtime/offload_host.h3
5 files changed, 241 insertions, 142 deletions
diff --git a/liboffloadmic/ChangeLog b/liboffloadmic/ChangeLog
index 93419bdfaaf..fb9fa851512 100644
--- a/liboffloadmic/ChangeLog
+++ b/liboffloadmic/ChangeLog
@@ -1,3 +1,56 @@
+2015-11-19 Ilya Verbin <ilya.verbin@intel.com>
+
+ * plugin/libgomp-plugin-intelmic.cpp (struct TargetImageDesc): New.
+ (ImgDescMap): New typedef.
+ (image_descriptors): New static var.
+ (init): Allocate image_descriptors.
+ (offload): Remove vars2 argument. Pass NULL to __offload_offload1
+ instead of vars2.
+ (unregister_main_image): New static function.
+ (register_main_image): Call unregister_main_image at exit.
+ (GOMP_OFFLOAD_init_device): Print device number, fix offload args.
+ (GOMP_OFFLOAD_fini_device): Likewise.
+ (get_target_table): Remove vd1g and vd2g, don't pass them to offload.
+ (offload_image): Remove declaration of the struct TargetImage.
+ Free table. Insert new descriptor into image_descriptors.
+ (GOMP_OFFLOAD_unload_image): Call __offload_unregister_image, free
+ the corresponding descriptor, and remove it from address_table and
+ image_descriptors.
+ (GOMP_OFFLOAD_alloc): Print device number, remove vd1g.
+ (GOMP_OFFLOAD_free): Likewise.
+ (GOMP_OFFLOAD_host2dev): Print device number, remove vd1g and vd2g.
+ (GOMP_OFFLOAD_dev2host): Likewise.
+ (GOMP_OFFLOAD_run): Print device number, remove vd1g.
+ * plugin/offload_target_main.cpp (__offload_target_table_p1): Remove
+ vd2, don't pass it to __offload_target_enter.
+ (__offload_target_table_p2): Likewise.
+ (__offload_target_alloc): Likewise.
+ (__offload_target_free): Likewise.
+ (__offload_target_host2tgt_p1): Likewise.
+ (__offload_target_host2tgt_p2): Likewise.
+ (__offload_target_tgt2host_p1): Likewise.
+ (__offload_target_tgt2host_p2): Likewise.
+ (__offload_target_run): Likewise.
+ (__offload_target_tgt2tgt): Remove vd1g, don't pass it to
+ __offload_target_enter.
+
+2015-11-14 Ilya Verbin <ilya.verbin@intel.com>
+
+ * runtime/offload_host.cpp (task_completion_callback): New
+ variable.
+ (offload_proxy_task_completed_ooo): Call task_completion_callback.
+ (__offload_register_task_callback): New function.
+ * runtime/offload_host.h (__offload_register_task_callback): New
+ declaration.
+ * plugin/libgomp-plugin-intelmic.cpp (offload): Add async_data
+ argument, handle async offloading.
+ (register_main_image): Call register_main_image.
+ (GOMP_OFFLOAD_init_device, get_target_table, GOMP_OFFLOAD_alloc,
+ GOMP_OFFLOAD_free, GOMP_OFFLOAD_host2dev, GOMP_OFFLOAD_dev2host,
+ GOMP_OFFLOAD_dev2dev): Adjust offload callers.
+ (GOMP_OFFLOAD_async_run): New function.
+ (GOMP_OFFLOAD_run): Implement using GOMP_OFFLOAD_async_run.
+
2015-10-26 Ilya Verbin <ilya.verbin@intel.com>
Aleksander Ivanushenko <aleksander.ivanushenko@intel.com>
diff --git a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
index 26ac6fed982..f8c172562ae 100644
--- a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
+++ b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp
@@ -65,6 +65,17 @@ typedef std::vector<AddrVect> DevAddrVect;
/* Addresses for all images and all devices. */
typedef std::map<const void *, DevAddrVect> ImgDevAddrMap;
+/* Image descriptor needed by __offload_[un]register_image. */
+struct TargetImageDesc {
+ int64_t size;
+ /* 10 characters is enough for max int value. */
+ char name[sizeof ("lib0000000000.so")];
+ char data[];
+};
+
+/* Image descriptors, indexed by a pointer obtained from libgomp. */
+typedef std::map<const void *, TargetImageDesc *> ImgDescMap;
+
/* Total number of available devices. */
static int num_devices;
@@ -76,6 +87,9 @@ static int num_images;
second key is number of device. Contains a vector of pointer pairs. */
static ImgDevAddrMap *address_table;
+/* Descriptors of all images, registered in liboffloadmic. */
+static ImgDescMap *image_descriptors;
+
/* Thread-safe registration of the main image. */
static pthread_once_t main_image_is_registered = PTHREAD_ONCE_INIT;
@@ -156,6 +170,7 @@ init (void)
out:
address_table = new ImgDevAddrMap;
+ image_descriptors = new ImgDescMap;
num_devices = _Offload_number_of_devices ();
}
@@ -192,11 +207,22 @@ GOMP_OFFLOAD_get_num_devices (void)
static void
offload (const char *file, uint64_t line, int device, const char *name,
- int num_vars, VarDesc *vars, VarDesc2 *vars2)
+ int num_vars, VarDesc *vars, const void **async_data)
{
OFFLOAD ofld = __offload_target_acquire1 (&device, file, line);
if (ofld)
- __offload_offload1 (ofld, name, 0, num_vars, vars, vars2, 0, NULL, NULL);
+ {
+ if (async_data == NULL)
+ __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);
+ }
+ }
else
{
fprintf (stderr, "%s:%d: Offload target acquire failed\n", file, line);
@@ -205,9 +231,27 @@ offload (const char *file, uint64_t line, int device, const char *name,
}
static void
+unregister_main_image ()
+{
+ __offload_unregister_image (&main_target_image);
+}
+
+static void
register_main_image ()
{
+ /* Do not check the return value, because old versions of liboffloadmic did
+ not have return values. */
__offload_register_image (&main_target_image);
+
+ /* liboffloadmic will call GOMP_PLUGIN_target_task_completion when
+ asynchronous task on target is completed. */
+ __offload_register_task_callback (GOMP_PLUGIN_target_task_completion);
+
+ if (atexit (unregister_main_image) != 0)
+ {
+ fprintf (stderr, "%s: atexit failed\n", __FILE__);
+ exit (1);
+ }
}
/* liboffloadmic loads and runs offload_target_main on all available devices
@@ -215,16 +259,16 @@ register_main_image ()
extern "C" void
GOMP_OFFLOAD_init_device (int device)
{
- TRACE ("");
+ TRACE ("(device = %d)", device);
pthread_once (&main_image_is_registered, register_main_image);
- offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0,
- NULL, NULL);
+ offload (__FILE__, __LINE__, device, "__offload_target_init_proc", 0, NULL,
+ NULL);
}
extern "C" void
GOMP_OFFLOAD_fini_device (int device)
{
- TRACE ("");
+ TRACE ("(device = %d)", device);
/* Unreachable for GOMP_OFFLOAD_CAP_OPENMP_400. */
abort ();
}
@@ -237,10 +281,9 @@ get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
vd1[0].size = sizeof (num_funcs);
vd1[1].ptr = &num_vars;
vd1[1].size = sizeof (num_vars);
- VarDesc2 vd1g[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
- offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2,
- vd1, vd1g);
+ offload (__FILE__, __LINE__, device, "__offload_target_table_p1", 2, vd1,
+ NULL);
int table_size = num_funcs + 2 * num_vars;
if (table_size > 0)
@@ -251,10 +294,9 @@ get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
vd2 = vd_tgt2host;
vd2.ptr = table;
vd2.size = table_size * sizeof (void *);
- VarDesc2 vd2g = { "table", 0 };
- offload (__FILE__, __LINE__, device, "__offload_target_table_p2", 1,
- &vd2, &vd2g);
+ offload (__FILE__, __LINE__, device, "__offload_target_table_p2", 1, &vd2,
+ NULL);
}
}
@@ -264,13 +306,6 @@ get_target_table (int device, int &num_funcs, int &num_vars, void **&table)
static void
offload_image (const void *target_image)
{
- struct TargetImage {
- int64_t size;
- /* 10 characters is enough for max int value. */
- char name[sizeof ("lib0000000000.so")];
- char data[];
- } __attribute__ ((packed));
-
void *image_start = ((void **) target_image)[0];
void *image_end = ((void **) target_image)[1];
@@ -278,9 +313,8 @@ offload_image (const void *target_image)
target_image, image_start, image_end);
int64_t image_size = (uintptr_t) image_end - (uintptr_t) image_start;
- TargetImage *image
- = (TargetImage *) malloc (sizeof (int64_t) + sizeof ("lib0000000000.so")
- + image_size);
+ TargetImageDesc *image = (TargetImageDesc *) malloc (offsetof (TargetImageDesc, data)
+ + image_size);
if (!image)
{
fprintf (stderr, "%s: Can't allocate memory\n", __FILE__);
@@ -293,6 +327,8 @@ offload_image (const void *target_image)
TRACE ("() __offload_register_image %s { %p, %d }",
image->name, image_start, image->size);
+ /* Do not check the return value, because old versions of liboffloadmic did
+ not have return values. */
__offload_register_image (image);
/* Receive tables for target_image from all devices. */
@@ -327,11 +363,11 @@ offload_image (const void *target_image)
}
dev_table.push_back (curr_dev_table);
+ delete [] table;
}
address_table->insert (std::make_pair (target_image, dev_table));
-
- free (image);
+ image_descriptors->insert (std::make_pair (target_image, image));
}
/* Return the libgomp version number we're compatible with. There is
@@ -382,26 +418,31 @@ GOMP_OFFLOAD_unload_image (int device, unsigned version,
TRACE ("(device = %d, target_image = %p)", device, target_image);
- /* TODO: Currently liboffloadmic doesn't support __offload_unregister_image
- for libraries. */
+ /* liboffloadmic unloads the image from all available devices. */
+ if (image_descriptors->count (target_image) > 0)
+ {
+ TargetImageDesc *image_desc = (*image_descriptors)[target_image];
+ __offload_unregister_image (image_desc);
+ free (image_desc);
- address_table->erase (target_image);
+ address_table->erase (target_image);
+ image_descriptors->erase (target_image);
+ }
}
extern "C" void *
GOMP_OFFLOAD_alloc (int device, size_t size)
{
- TRACE ("(size = %d)", size);
+ TRACE ("(device = %d, size = %d)", device, size);
void *tgt_ptr;
- VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
- vd1[0].ptr = &size;
- vd1[0].size = sizeof (size);
- vd1[1].ptr = &tgt_ptr;
- vd1[1].size = sizeof (void *);
- VarDesc2 vd1g[2] = { { "size", 0 }, { "tgt_ptr", 0 } };
+ VarDesc vd[2] = { vd_host2tgt, vd_tgt2host };
+ vd[0].ptr = &size;
+ vd[0].size = sizeof (size);
+ vd[1].ptr = &tgt_ptr;
+ vd[1].size = sizeof (void *);
- offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2, vd1, vd1g);
+ offload (__FILE__, __LINE__, device, "__offload_target_alloc", 2, vd, NULL);
return tgt_ptr;
}
@@ -409,21 +450,21 @@ GOMP_OFFLOAD_alloc (int device, size_t size)
extern "C" void
GOMP_OFFLOAD_free (int device, void *tgt_ptr)
{
- TRACE ("(tgt_ptr = %p)", tgt_ptr);
+ TRACE ("(device = %d, tgt_ptr = %p)", device, tgt_ptr);
- VarDesc vd1 = vd_host2tgt;
- vd1.ptr = &tgt_ptr;
- vd1.size = sizeof (void *);
- VarDesc2 vd1g = { "tgt_ptr", 0 };
+ VarDesc vd = vd_host2tgt;
+ vd.ptr = &tgt_ptr;
+ vd.size = sizeof (void *);
- offload (__FILE__, __LINE__, device, "__offload_target_free", 1, &vd1, &vd1g);
+ offload (__FILE__, __LINE__, device, "__offload_target_free", 1, &vd, NULL);
}
extern "C" void *
GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
size_t size)
{
- TRACE ("(tgt_ptr = %p, host_ptr = %p, size = %d)", tgt_ptr, host_ptr, size);
+ TRACE ("(device = %d, tgt_ptr = %p, host_ptr = %p, size = %d)",
+ device, tgt_ptr, host_ptr, size);
if (!size)
return tgt_ptr;
@@ -432,18 +473,16 @@ GOMP_OFFLOAD_host2dev (int device, void *tgt_ptr, const void *host_ptr,
vd1[0].size = sizeof (void *);
vd1[1].ptr = &size;
vd1[1].size = sizeof (size);
- VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
- offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2,
- vd1, vd1g);
+ offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p1", 2, vd1,
+ NULL);
VarDesc vd2 = vd_host2tgt;
vd2.ptr = (void *) host_ptr;
vd2.size = size;
- VarDesc2 vd2g = { "var", 0 };
- offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1,
- &vd2, &vd2g);
+ offload (__FILE__, __LINE__, device, "__offload_target_host2tgt_p2", 1, &vd2,
+ NULL);
return tgt_ptr;
}
@@ -452,7 +491,8 @@ extern "C" void *
GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
size_t size)
{
- TRACE ("(host_ptr = %p, tgt_ptr = %p, size = %d)", host_ptr, tgt_ptr, size);
+ TRACE ("(device = %d, host_ptr = %p, tgt_ptr = %p, size = %d)",
+ device, host_ptr, tgt_ptr, size);
if (!size)
return host_ptr;
@@ -461,18 +501,16 @@ GOMP_OFFLOAD_dev2host (int device, void *host_ptr, const void *tgt_ptr,
vd1[0].size = sizeof (void *);
vd1[1].ptr = &size;
vd1[1].size = sizeof (size);
- VarDesc2 vd1g[2] = { { "tgt_ptr", 0 }, { "size", 0 } };
- offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2,
- vd1, vd1g);
+ offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p1", 2, vd1,
+ NULL);
VarDesc vd2 = vd_tgt2host;
vd2.ptr = (void *) host_ptr;
vd2.size = size;
- VarDesc2 vd2g = { "var", 0 };
- offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1,
- &vd2, &vd2g);
+ offload (__FILE__, __LINE__, device, "__offload_target_tgt2host_p2", 1, &vd2,
+ NULL);
return host_ptr;
}
@@ -481,36 +519,45 @@ extern "C" void *
GOMP_OFFLOAD_dev2dev (int device, void *dst_ptr, const void *src_ptr,
size_t size)
{
- TRACE ("(dst_ptr = %p, src_ptr = %p, size = %d)", dst_ptr, src_ptr, size);
+ TRACE ("(device = %d, dst_ptr = %p, src_ptr = %p, size = %d)",
+ device, dst_ptr, src_ptr, size);
if (!size)
return dst_ptr;
- VarDesc vd1[3] = { vd_host2tgt, vd_host2tgt, vd_host2tgt };
- vd1[0].ptr = &dst_ptr;
- vd1[0].size = sizeof (void *);
- vd1[1].ptr = &src_ptr;
- vd1[1].size = sizeof (void *);
- vd1[2].ptr = &size;
- vd1[2].size = sizeof (size);
- VarDesc2 vd1g[3] = { { "dst_ptr", 0 }, { "src_ptr", 0 }, { "size", 0 } };
+ VarDesc vd[3] = { vd_host2tgt, vd_host2tgt, vd_host2tgt };
+ vd[0].ptr = &dst_ptr;
+ vd[0].size = sizeof (void *);
+ vd[1].ptr = &src_ptr;
+ vd[1].size = sizeof (void *);
+ vd[2].ptr = &size;
+ vd[2].size = sizeof (size);
- offload (__FILE__, __LINE__, device, "__offload_target_tgt2tgt", 3, vd1,
- vd1g);
+ offload (__FILE__, __LINE__, device, "__offload_target_tgt2tgt", 3, vd, NULL);
return dst_ptr;
}
extern "C" void
-GOMP_OFFLOAD_run (int device, void *tgt_fn, void *tgt_vars)
+GOMP_OFFLOAD_async_run (int device, void *tgt_fn, void *tgt_vars,
+ void *async_data)
{
- TRACE ("(tgt_fn = %p, tgt_vars = %p)", tgt_fn, tgt_vars);
+ TRACE ("(device = %d, tgt_fn = %p, tgt_vars = %p, async_data = %p)", device,
+ tgt_fn, tgt_vars, async_data);
- VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
- vd1[0].ptr = &tgt_fn;
- vd1[0].size = sizeof (void *);
- vd1[1].ptr = &tgt_vars;
- vd1[1].size = sizeof (void *);
- VarDesc2 vd1g[2] = { { "tgt_fn", 0 }, { "tgt_vars", 0 } };
+ VarDesc vd[2] = { vd_host2tgt, vd_host2tgt };
+ vd[0].ptr = &tgt_fn;
+ vd[0].size = sizeof (void *);
+ vd[1].ptr = &tgt_vars;
+ vd[1].size = sizeof (void *);
+
+ offload (__FILE__, __LINE__, device, "__offload_target_run", 2, vd,
+ (const void **) async_data);
+}
+
+extern "C" void
+GOMP_OFFLOAD_run (int device, void *tgt_fn, void *tgt_vars)
+{
+ TRACE ("(device = %d, tgt_fn = %p, tgt_vars = %p)", device, tgt_fn, tgt_vars);
- offload (__FILE__, __LINE__, device, "__offload_target_run", 2, vd1, vd1g);
+ GOMP_OFFLOAD_async_run (device, tgt_fn, tgt_vars, NULL);
}
diff --git a/liboffloadmic/plugin/offload_target_main.cpp b/liboffloadmic/plugin/offload_target_main.cpp
index 18b014641b6..58438107684 100644
--- a/liboffloadmic/plugin/offload_target_main.cpp
+++ b/liboffloadmic/plugin/offload_target_main.cpp
@@ -1,6 +1,6 @@
/* Plugin for offload execution on Intel MIC devices.
- Copyright (C) 2014 Free Software Foundation, Inc.
+ Copyright (C) 2014-2015 Free Software Foundation, Inc.
Contributed by Ilya Verbin <ilya.verbin@intel.com>.
@@ -139,14 +139,13 @@ __offload_target_table_p1 (OFFLOAD ofldt)
int num_vars = (var_table_end - var_table_begin) / 2;
TRACE ("(num_funcs = %d, num_vars = %d)", num_funcs, num_vars);
- VarDesc vd1[2] = { vd_tgt2host, vd_tgt2host };
- vd1[0].ptr = &num_funcs;
- vd1[0].size = sizeof (num_funcs);
- vd1[1].ptr = &num_vars;
- vd1[1].size = sizeof (num_vars);
- VarDesc2 vd2[2] = { { "num_funcs", 0 }, { "num_vars", 0 } };
+ VarDesc vd[2] = { vd_tgt2host, vd_tgt2host };
+ vd[0].ptr = &num_funcs;
+ vd[0].size = sizeof (num_funcs);
+ vd[1].ptr = &num_vars;
+ vd[1].size = sizeof (num_vars);
- __offload_target_enter (ofldt, 2, vd1, vd2);
+ __offload_target_enter (ofldt, 2, vd, NULL);
__offload_target_leave (ofldt);
}
@@ -166,13 +165,11 @@ __offload_target_table_p2 (OFFLOAD ofldt)
void **table = (void **) malloc (table_size);
TRACE ("(table_size = %d)", table_size);
- VarDesc vd1;
- vd1 = vd_tgt2host;
- vd1.ptr = table;
- vd1.size = table_size;
- VarDesc2 vd2 = { "table", 0 };
+ VarDesc vd = vd_tgt2host;
+ vd.ptr = table;
+ vd.size = table_size;
- __offload_target_enter (ofldt, 1, &vd1, &vd2);
+ __offload_target_enter (ofldt, 1, &vd, NULL);
void **p;
int i = 0;
@@ -193,14 +190,13 @@ __offload_target_alloc (OFFLOAD ofldt)
size_t size = 0;
void *ptr = NULL;
- VarDesc vd1[2] = { vd_host2tgt, vd_tgt2host };
- vd1[0].ptr = &size;
- vd1[0].size = sizeof (size);
- vd1[1].ptr = &ptr;
- vd1[1].size = sizeof (void *);
- VarDesc2 vd2[2] = { { "size", 0 }, { "ptr", 0 } };
+ VarDesc vd[2] = { vd_host2tgt, vd_tgt2host };
+ vd[0].ptr = &size;
+ vd[0].size = sizeof (size);
+ vd[1].ptr = &ptr;
+ vd[1].size = sizeof (void *);
- __offload_target_enter (ofldt, 2, vd1, vd2);
+ __offload_target_enter (ofldt, 2, vd, NULL);
ptr = malloc (size);
TRACE ("(size = %d): ptr = %p", size, ptr);
__offload_target_leave (ofldt);
@@ -212,12 +208,11 @@ __offload_target_free (OFFLOAD ofldt)
{
void *ptr = 0;
- VarDesc vd1 = vd_host2tgt;
- vd1.ptr = &ptr;
- vd1.size = sizeof (void *);
- VarDesc2 vd2 = { "ptr", 0 };
+ VarDesc vd = vd_host2tgt;
+ vd.ptr = &ptr;
+ vd.size = sizeof (void *);
- __offload_target_enter (ofldt, 1, &vd1, &vd2);
+ __offload_target_enter (ofldt, 1, &vd, NULL);
TRACE ("(ptr = %p)", ptr);
free (ptr);
__offload_target_leave (ofldt);
@@ -231,14 +226,13 @@ __offload_target_host2tgt_p1 (OFFLOAD ofldt)
void *var_ptr = NULL;
size_t var_size = 0;
- VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
- vd1[0].ptr = &var_ptr;
- vd1[0].size = sizeof (void *);
- vd1[1].ptr = &var_size;
- vd1[1].size = sizeof (var_size);
- VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+ VarDesc vd[2] = { vd_host2tgt, vd_host2tgt };
+ vd[0].ptr = &var_ptr;
+ vd[0].size = sizeof (void *);
+ vd[1].ptr = &var_size;
+ vd[1].size = sizeof (var_size);
- __offload_target_enter (ofldt, 2, vd1, vd2);
+ __offload_target_enter (ofldt, 2, vd, NULL);
TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
last_var_ptr = var_ptr;
last_var_size = var_size;
@@ -252,12 +246,11 @@ __offload_target_host2tgt_p2 (OFFLOAD ofldt)
TRACE ("(last_var_ptr = %p, last_var_size = %d)",
last_var_ptr, last_var_size);
- VarDesc vd1 = vd_host2tgt;
- vd1.ptr = last_var_ptr;
- vd1.size = last_var_size;
- VarDesc2 vd2 = { "var", 0 };
+ VarDesc vd = vd_host2tgt;
+ vd.ptr = last_var_ptr;
+ vd.size = last_var_size;
- __offload_target_enter (ofldt, 1, &vd1, &vd2);
+ __offload_target_enter (ofldt, 1, &vd, NULL);
__offload_target_leave (ofldt);
}
@@ -269,14 +262,13 @@ __offload_target_tgt2host_p1 (OFFLOAD ofldt)
void *var_ptr = NULL;
size_t var_size = 0;
- VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
- vd1[0].ptr = &var_ptr;
- vd1[0].size = sizeof (void *);
- vd1[1].ptr = &var_size;
- vd1[1].size = sizeof (var_size);
- VarDesc2 vd2[2] = { { "var_ptr", 0 }, { "var_size", 0 } };
+ VarDesc vd[2] = { vd_host2tgt, vd_host2tgt };
+ vd[0].ptr = &var_ptr;
+ vd[0].size = sizeof (void *);
+ vd[1].ptr = &var_size;
+ vd[1].size = sizeof (var_size);
- __offload_target_enter (ofldt, 2, vd1, vd2);
+ __offload_target_enter (ofldt, 2, vd, NULL);
TRACE ("(var_ptr = %p, var_size = %d)", var_ptr, var_size);
last_var_ptr = var_ptr;
last_var_size = var_size;
@@ -290,12 +282,11 @@ __offload_target_tgt2host_p2 (OFFLOAD ofldt)
TRACE ("(last_var_ptr = %p, last_var_size = %d)",
last_var_ptr, last_var_size);
- VarDesc vd1 = vd_tgt2host;
- vd1.ptr = last_var_ptr;
- vd1.size = last_var_size;
- VarDesc2 vd2 = { "var", 0 };
+ VarDesc vd = vd_tgt2host;
+ vd.ptr = last_var_ptr;
+ vd.size = last_var_size;
- __offload_target_enter (ofldt, 1, &vd1, &vd2);
+ __offload_target_enter (ofldt, 1, &vd, NULL);
__offload_target_leave (ofldt);
}
@@ -307,16 +298,15 @@ __offload_target_tgt2tgt (OFFLOAD ofldt)
void *dst_ptr = NULL;
size_t size = 0;
- VarDesc vd1[3] = { vd_host2tgt, vd_host2tgt, vd_host2tgt };
- vd1[0].ptr = &dst_ptr;
- vd1[0].size = sizeof (void *);
- vd1[1].ptr = &src_ptr;
- vd1[1].size = sizeof (void *);
- vd1[2].ptr = &size;
- vd1[2].size = sizeof (size);
- VarDesc2 vd1g[3] = { { "dst_ptr", 0 }, { "src_ptr", 0 }, { "size", 0 } };
+ VarDesc vd[3] = { vd_host2tgt, vd_host2tgt, vd_host2tgt };
+ vd[0].ptr = &dst_ptr;
+ vd[0].size = sizeof (void *);
+ vd[1].ptr = &src_ptr;
+ vd[1].size = sizeof (void *);
+ vd[2].ptr = &size;
+ vd[2].size = sizeof (size);
- __offload_target_enter (ofldt, 3, vd1, vd1g);
+ __offload_target_enter (ofldt, 3, vd, NULL);
TRACE ("(dst_ptr = %p, src_ptr = %p, size = %d)", dst_ptr, src_ptr, size);
memcpy (dst_ptr, src_ptr, size);
__offload_target_leave (ofldt);
@@ -329,14 +319,13 @@ __offload_target_run (OFFLOAD ofldt)
void *fn_ptr;
void *vars_ptr;
- VarDesc vd1[2] = { vd_host2tgt, vd_host2tgt };
- vd1[0].ptr = &fn_ptr;
- vd1[0].size = sizeof (void *);
- vd1[1].ptr = &vars_ptr;
- vd1[1].size = sizeof (void *);
- VarDesc2 vd2[2] = { { "fn_ptr", 0 }, { "vars_ptr", 0 } };
+ VarDesc vd[2] = { vd_host2tgt, vd_host2tgt };
+ vd[0].ptr = &fn_ptr;
+ vd[0].size = sizeof (void *);
+ vd[1].ptr = &vars_ptr;
+ vd[1].size = sizeof (void *);
- __offload_target_enter (ofldt, 2, vd1, vd2);
+ __offload_target_enter (ofldt, 2, vd, NULL);
TRACE ("(fn_ptr = %p, vars_ptr = %p)", fn_ptr, vars_ptr);
void (*fn)(void *) = (void (*)(void *)) fn_ptr;
fn (vars_ptr);
diff --git a/liboffloadmic/runtime/offload_host.cpp b/liboffloadmic/runtime/offload_host.cpp
index c10dc4efb55..e52019dfb28 100644
--- a/liboffloadmic/runtime/offload_host.cpp
+++ b/liboffloadmic/runtime/offload_host.cpp
@@ -64,6 +64,8 @@ static void __offload_fini_library(void);
#define GET_OFFLOAD_NUMBER(timer_data) \
timer_data? timer_data->offload_number : 0
+static void (*task_completion_callback)(void *);
+
extern "C" {
#ifdef TARGET_WINNT
// Windows does not support imports from libraries without actually
@@ -2507,7 +2509,7 @@ extern "C" {
const void *info
)
{
- /* TODO: Call callback function, pass info. */
+ task_completion_callback ((void *) info);
}
}
@@ -5669,6 +5671,11 @@ extern "C" void __offload_unregister_image(const void *target_image)
}
}
+extern "C" void __offload_register_task_callback(void (*cb)(void *))
+{
+ task_completion_callback = cb;
+}
+
// Runtime trace interface for user programs
void __offload_console_trace(int level)
diff --git a/liboffloadmic/runtime/offload_host.h b/liboffloadmic/runtime/offload_host.h
index afd5c9936ca..2a43fd6a68a 100644
--- a/liboffloadmic/runtime/offload_host.h
+++ b/liboffloadmic/runtime/offload_host.h
@@ -376,6 +376,9 @@ extern "C" bool __offload_target_image_is_executable(const void *target_image);
extern "C" bool __offload_register_image(const void* image);
extern "C" void __offload_unregister_image(const void* image);
+// Registers asynchronous task completion callback
+extern "C" void __offload_register_task_callback(void (*cb)(void *));
+
// Initializes offload runtime library.
DLL_LOCAL extern int __offload_init_library(void);