diff options
author | iverbin <iverbin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-04-06 12:40:28 +0000 |
---|---|---|
committer | iverbin <iverbin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-04-06 12:40:28 +0000 |
commit | 0d8c703d61140ddf1309c647dcef237689fc0972 (patch) | |
tree | e7d774fabd484c0dd0c0c0e4c3452c47b0ee8b26 /libgomp/oacc-mem.c | |
parent | 0c57c0f96303cb534da20a178d4bfb595a050105 (diff) | |
download | gcc-0d8c703d61140ddf1309c647dcef237689fc0972.tar.gz |
libgomp: rework initialization of offloading
gcc/
* config/i386/intelmic-mkoffload.c (generate_host_descr_file): Call
GOMP_offload_unregister from the destructor.
libgomp/
* libgomp-plugin.h (struct mapping_table): Replace with addr_pair.
* libgomp.h (struct gomp_memory_mapping): Remove.
(struct target_mem_desc): Change type of mem_map from
gomp_memory_mapping * to splay_tree_s *.
(struct gomp_device_descr): Remove register_image_func, get_table_func.
Add load_image_func, unload_image_func.
Change type of mem_map from gomp_memory_mapping to splay_tree_s.
Remove offload_regions_registered.
(gomp_init_tables): Remove.
(gomp_free_memmap): Change type of argument from gomp_memory_mapping *
to splay_tree_s *.
* libgomp.map (GOMP_4.0.1): Add GOMP_offload_unregister.
* oacc-host.c (host_dispatch): Do not initialize register_image_func,
get_table_func, mem_map.is_initialized, mem_map.splay_tree.root,
offload_regions_registered.
Initialize load_image_func, unload_image_func, mem_map.root.
(goacc_host_init): Do not initialize host_dispatch.mem_map.lock.
* oacc-init.c (lazy_open): Don't call gomp_init_tables.
(acc_shutdown_1): Use dev's lock and splay_tree instead of mem_map's.
* oacc-mem.c (lookup_host): Get gomp_device_descr *dev instead of
gomp_memory_mapping *. Use dev's lock and splay_tree.
(lookup_dev): Use dev's lock.
(acc_deviceptr): Pass dev to lookup_host instead of mem_map.
(acc_is_present): Likewise.
(acc_map_data): Likewise.
(acc_unmap_data): Likewise. Use dev's lock.
(present_create_copy): Likewise.
(delete_copyout): Pass dev to lookup_host instead of mem_map.
(update_dev_host): Likewise.
(gomp_acc_remove_pointer): Likewise. Use dev's lock.
* oacc-parallel.c (GOACC_parallel): Use dev's lock and splay_tree.
* plugin/plugin-host.c (GOMP_OFFLOAD_register_image): Remove.
(GOMP_OFFLOAD_get_table): Remove
(GOMP_OFFLOAD_load_image): New function.
(GOMP_OFFLOAD_unload_image): New function.
* target.c (register_lock): New mutex for offload image registration.
(num_devices): Do not guard with PLUGIN_SUPPORT.
(gomp_realloc_unlock): New static function.
(gomp_map_vars_existing): Add device descriptor argument. Unlock mutex
before gomp_fatal.
(gomp_map_vars): Use dev's lock and splay_tree instead of mem_map's.
Pass devicep to gomp_map_vars_existing. Unlock mutex before gomp_fatal.
(gomp_copy_from_async): Use dev's lock and splay_tree instead of
mem_map's.
(gomp_unmap_vars): Likewise.
(gomp_update): Remove gomp_memory_mapping argument. Use dev's lock and
splay_tree instead of mm's. Unlock mutex before gomp_fatal.
(gomp_offload_image_to_device): New static function.
(GOMP_offload_register): Add mutex lock.
Call gomp_offload_image_to_device for all initialized devices.
Replace gomp_realloc with gomp_realloc_unlock.
(GOMP_offload_unregister): New function.
(gomp_init_tables): Replace with gomp_init_device. Replace a call to
get_table_func from the plugin with calls to init_device_func and
gomp_offload_image_to_device.
(gomp_free_memmap): Change type of argument from gomp_memory_mapping *
to splay_tree_s *.
(GOMP_target): Do not call gomp_init_tables. Use dev's lock and
splay_tree instead of mem_map's. Unlock mutex before gomp_fatal.
(GOMP_target_data): Do not call gomp_init_tables.
(GOMP_target_update): Likewise. Remove argument from gomp_update.
(gomp_load_plugin_for_device): Replace register_image and get_table
with load_image and unload_image in DLSYM ().
(gomp_register_images_for_device): Remove function.
(gomp_target_init): Do not initialize current_device.mem_map.*,
current_device.offload_regions_registered.
Remove call to gomp_register_images_for_device.
Do not free offload_images and num_offload_images.
liboffloadmic/
* plugin/libgomp-plugin-intelmic.cpp: Include map.
(AddrVect, DevAddrVect, ImgDevAddrMap): New typedefs.
(num_devices, num_images, address_table): New static vars.
(num_libraries, lib_descrs): Remove static vars.
(set_mic_lib_path): Rename to ...
(init): ... this. Allocate address_table and get num_devices.
(GOMP_OFFLOAD_get_num_devices): return num_devices.
(load_lib_and_get_table): Remove static function.
(offload_image): New static function.
(GOMP_OFFLOAD_get_table): Remove function.
(GOMP_OFFLOAD_load_image, GOMP_OFFLOAD_unload_image): New functions.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221878 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgomp/oacc-mem.c')
-rw-r--r-- | libgomp/oacc-mem.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c index 0096d514297..fdc82e654f9 100644 --- a/libgomp/oacc-mem.c +++ b/libgomp/oacc-mem.c @@ -38,7 +38,7 @@ /* Return block containing [H->S), or NULL if not contained. */ static splay_tree_key -lookup_host (struct gomp_memory_mapping *mem_map, void *h, size_t s) +lookup_host (struct gomp_device_descr *dev, void *h, size_t s) { struct splay_tree_key_s node; splay_tree_key key; @@ -46,11 +46,9 @@ lookup_host (struct gomp_memory_mapping *mem_map, void *h, size_t s) node.host_start = (uintptr_t) h; node.host_end = (uintptr_t) h + s; - gomp_mutex_lock (&mem_map->lock); - - key = splay_tree_lookup (&mem_map->splay_tree, &node); - - gomp_mutex_unlock (&mem_map->lock); + gomp_mutex_lock (&dev->lock); + key = splay_tree_lookup (&dev->mem_map, &node); + gomp_mutex_unlock (&dev->lock); return key; } @@ -65,14 +63,11 @@ lookup_dev (struct target_mem_desc *tgt, void *d, size_t s) { int i; struct target_mem_desc *t; - struct gomp_memory_mapping *mem_map; if (!tgt) return NULL; - mem_map = tgt->mem_map; - - gomp_mutex_lock (&mem_map->lock); + gomp_mutex_lock (&tgt->device_descr->lock); for (t = tgt; t != NULL; t = t->prev) { @@ -80,7 +75,7 @@ lookup_dev (struct target_mem_desc *tgt, void *d, size_t s) break; } - gomp_mutex_unlock (&mem_map->lock); + gomp_mutex_unlock (&tgt->device_descr->lock); if (!t) return NULL; @@ -176,7 +171,7 @@ acc_deviceptr (void *h) struct goacc_thread *thr = goacc_thread (); - n = lookup_host (&thr->dev->mem_map, h, 1); + n = lookup_host (thr->dev, h, 1); if (!n) return NULL; @@ -229,7 +224,7 @@ acc_is_present (void *h, size_t s) struct goacc_thread *thr = goacc_thread (); struct gomp_device_descr *acc_dev = thr->dev; - n = lookup_host (&acc_dev->mem_map, h, s); + n = lookup_host (acc_dev, h, s); if (n && ((uintptr_t)h < n->host_start || (uintptr_t)h + s > n->host_end @@ -271,7 +266,7 @@ acc_map_data (void *h, void *d, size_t s) gomp_fatal ("[%p,+%d]->[%p,+%d] is a bad map", (void *)h, (int)s, (void *)d, (int)s); - if (lookup_host (&acc_dev->mem_map, h, s)) + if (lookup_host (acc_dev, h, s)) gomp_fatal ("host address [%p, +%d] is already mapped", (void *)h, (int)s); @@ -296,7 +291,7 @@ acc_unmap_data (void *h) /* No need to call lazy open, as the address must have been mapped. */ size_t host_size; - splay_tree_key n = lookup_host (&acc_dev->mem_map, h, 1); + splay_tree_key n = lookup_host (acc_dev, h, 1); struct target_mem_desc *t; if (!n) @@ -320,7 +315,7 @@ acc_unmap_data (void *h) t->tgt_end = 0; t->to_free = 0; - gomp_mutex_lock (&acc_dev->mem_map.lock); + gomp_mutex_lock (&acc_dev->lock); for (tp = NULL, t = acc_dev->openacc.data_environ; t != NULL; tp = t, t = t->prev) @@ -334,7 +329,7 @@ acc_unmap_data (void *h) break; } - gomp_mutex_unlock (&acc_dev->mem_map.lock); + gomp_mutex_unlock (&acc_dev->lock); } gomp_unmap_vars (t, true); @@ -358,7 +353,7 @@ present_create_copy (unsigned f, void *h, size_t s) struct goacc_thread *thr = goacc_thread (); struct gomp_device_descr *acc_dev = thr->dev; - n = lookup_host (&acc_dev->mem_map, h, s); + n = lookup_host (acc_dev, h, s); if (n) { /* Present. */ @@ -389,13 +384,13 @@ present_create_copy (unsigned f, void *h, size_t s) tgt = gomp_map_vars (acc_dev, mapnum, &hostaddrs, NULL, &s, &kinds, true, false); - gomp_mutex_lock (&acc_dev->mem_map.lock); + gomp_mutex_lock (&acc_dev->lock); d = tgt->to_free; tgt->prev = acc_dev->openacc.data_environ; acc_dev->openacc.data_environ = tgt; - gomp_mutex_unlock (&acc_dev->mem_map.lock); + gomp_mutex_unlock (&acc_dev->lock); } return d; @@ -436,7 +431,7 @@ delete_copyout (unsigned f, void *h, size_t s) struct goacc_thread *thr = goacc_thread (); struct gomp_device_descr *acc_dev = thr->dev; - n = lookup_host (&acc_dev->mem_map, h, s); + n = lookup_host (acc_dev, h, s); /* No need to call lazy open, as the data must already have been mapped. */ @@ -479,7 +474,7 @@ update_dev_host (int is_dev, void *h, size_t s) struct goacc_thread *thr = goacc_thread (); struct gomp_device_descr *acc_dev = thr->dev; - n = lookup_host (&acc_dev->mem_map, h, s); + n = lookup_host (acc_dev, h, s); /* No need to call lazy open, as the data must already have been mapped. */ @@ -532,7 +527,7 @@ gomp_acc_remove_pointer (void *h, bool force_copyfrom, int async, int mapnum) struct target_mem_desc *t; int minrefs = (mapnum == 1) ? 2 : 3; - n = lookup_host (&acc_dev->mem_map, h, 1); + n = lookup_host (acc_dev, h, 1); if (!n) gomp_fatal ("%p is not a mapped block", (void *)h); @@ -543,7 +538,7 @@ gomp_acc_remove_pointer (void *h, bool force_copyfrom, int async, int mapnum) struct target_mem_desc *tp; - gomp_mutex_lock (&acc_dev->mem_map.lock); + gomp_mutex_lock (&acc_dev->lock); if (t->refcount == minrefs) { @@ -570,7 +565,7 @@ gomp_acc_remove_pointer (void *h, bool force_copyfrom, int async, int mapnum) if (force_copyfrom) t->list[0]->copy_from = 1; - gomp_mutex_unlock (&acc_dev->mem_map.lock); + gomp_mutex_unlock (&acc_dev->lock); /* If running synchronously, unmap immediately. */ if (async < acc_async_noval) |