Re: [RFC][gomp4] Offloading: Add device initialization and host-target function mapping
Ping. 2014-03-12 21:56 GMT+04:00 Ilya Verbin iver...@gmail.com: Hi Thomas, Here is a new version of this patch (it was discussed in other thread: http://gcc.gnu.org/ml/gcc-patches/2014-03/msg00573.html ) with ChangeLog. Bootstrap and make check passed. Ok to commit? -- Ilya
Re: [RFC][gomp4] Offloading: Add device initialization and host-target function mapping
Hi Thomas, Here is a new version of this patch (it was discussed in other thread: http://gcc.gnu.org/ml/gcc-patches/2014-03/msg00573.html ) with ChangeLog. Bootstrap and make check passed. Ok to commit? libgomp/ChangeLog.gomp | 29 libgomp/libgomp.map|1 + libgomp/plugin-host.c | 58 - libgomp/target.c | 170 4 files changed, 242 insertions(+), 16 deletions(-) diff --git a/libgomp/ChangeLog.gomp b/libgomp/ChangeLog.gomp index 7f9ce11..57a600e 100644 --- a/libgomp/ChangeLog.gomp +++ b/libgomp/ChangeLog.gomp @@ -1,3 +1,32 @@ +2014-03-12 Ilya Verbin ilya.ver...@intel.com + + * libgomp.map (GOMP_4.0): Add GOMP_offload_register. + * plugin-host.c (device_available): Replace with: + (get_num_devices): This. + (get_type): New. + (offload_register): Ditto. + (device_init): Ditto. + (device_get_table): Ditto. + (device_run): Ditto. + * target.c (target_type): New enum. + (offload_image_descr): New struct. + (offload_images, num_offload_images): New globals. + (struct gomp_device_descr): Remove device_available_func. + Add type, is_initialized, get_type_func, get_num_devices_func, + offload_register_func, device_init_func, device_get_table_func, + device_run_func. + (mapping_table): New struct. + (GOMP_offload_register): New function. + (gomp_init_device): Ditto. + (GOMP_target): Add device initialization and lookup for target fn. + (GOMP_target_data): Add device initialization. + (GOMP_target_update): Ditto. + (gomp_load_plugin_for_device): Take handles for get_type, + get_num_devices, offload_register, device_init, device_get_table, + device_run functions. + (gomp_register_images_for_device): New function. + (gomp_find_available_plugins): Add registration of offload images. + 2014-02-28 Thomas Schwinge tho...@codesourcery.com * testsuite/libgomp.oacc-c/goacc_kernels.c: New file. diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map index e9f8b55..9328767 100644 --- a/libgomp/libgomp.map +++ b/libgomp/libgomp.map @@ -208,6 +208,7 @@ GOMP_3.0 { GOMP_4.0 { global: + GOMP_offload_register; GOMP_barrier_cancel; GOMP_cancel; GOMP_cancellation_point; diff --git a/libgomp/plugin-host.c b/libgomp/plugin-host.c index 5354ebe..ec0c78c 100644 --- a/libgomp/plugin-host.c +++ b/libgomp/plugin-host.c @@ -33,14 +33,53 @@ #include stdlib.h #include string.h -bool -device_available (void) +const int TARGET_TYPE_HOST = 0; + +int +get_type (void) { #ifdef DEBUG printf (libgomp plugin: %s:%s\n, __FILE__, __FUNCTION__); #endif - return true; + return TARGET_TYPE_HOST; +} + +int +get_num_devices (void) +{ +#ifdef DEBUG + printf (libgomp plugin: %s:%s\n, __FILE__, __FUNCTION__); +#endif + + return 1; +} + +void +offload_register (void *host_table, void *target_data) +{ +#ifdef DEBUG + printf (libgomp plugin: %s:%s (%p, %p)\n, __FILE__, __FUNCTION__, + host_table, target_data); +#endif +} + +void +device_init (void) +{ +#ifdef DEBUG + printf (libgomp plugin: %s:%s\n, __FILE__, __FUNCTION__); +#endif +} + +int +device_get_table (void *table) +{ +#ifdef DEBUG + printf (libgomp plugin: %s:%s (%p)\n, __FILE__, __FUNCTION__, table); +#endif + + return 0; } void * @@ -82,3 +121,16 @@ void *device_host2dev (void *dest, const void *src, size_t n) return memcpy (dest, src, n); } + +void +device_run (void *fn_ptr, void *vars) +{ +#ifdef DEBUG + printf (libgomp plugin: %s:%s (%p, %p)\n, __FILE__, __FUNCTION__, fn_ptr, + vars); +#endif + + void (*fn)(void *) = (void (*)(void *)) fn_ptr; + + fn (vars); +} diff --git a/libgomp/target.c b/libgomp/target.c index a6a5505..0715b31 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -84,6 +84,26 @@ struct splay_tree_key_s { bool copy_from; }; +enum target_type { + TARGET_TYPE_HOST, + TARGET_TYPE_INTEL_MIC +}; + +/* This structure describes an offload image. + It contains type of the target, pointer to host table descriptor, and pointer + to target data. */ +struct offload_image_descr { + int type; + void *host_table; + void *target_data; +}; + +/* Array of descriptors of offload images. */ +static struct offload_image_descr *offload_images; + +/* Total number of offload images. */ +static int num_offload_images; + /* Array of descriptors of all available devices. */ static struct gomp_device_descr *devices; @@ -117,15 +137,26 @@ struct gomp_device_descr TARGET construct. */ int id; + /* This is the TYPE of device. */ + int type; + + /* Set to true when device is initialized. */ + bool is_initialized; + /* Plugin file handler. */ void *plugin_handle; /* Function handlers. */ - bool (*device_available_func) (void); + int (*get_type_func) (void); + int (*get_num_devices_func) (void); + void
Re: [RFC][gomp4] Offloading: Add device initialization and host-target function mapping
Ping.
Re: [RFC][gomp4] Offloading: Add device initialization and host-target function mapping
Ping. (Patch is slightly updated) On 20 Dec 21:18, Ilya Verbin wrote: Hi Jakub, Could you please take a look at this patch for libgomp? It adds new function GOMP_register_lib, that should be called from every exec/lib with target regions (that was done in patch [1]). This function maintains the array of pointers to the target shared library descriptors. Also this patch adds target device initialization into GOMP_target and GOMP_target_data. At first, it calls device_init function from the plugin. This function takes array of target-images as input, and returns the array of target-side addresses. Currently, it always uses the first target-image from the descriptor, this should be generalized later. Then libgomp reads the tables from host-side exec/libs. After that, it inserts host-target address mapping into the splay tree. [1] http://gcc.gnu.org/ml/gcc-patches/2013-12/msg01486.html Thanks, -- Ilya -- Ilya --- libgomp/libgomp.map |1 + libgomp/target.c| 154 --- 2 files changed, 146 insertions(+), 9 deletions(-) diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map index 2b64d05..792047f 100644 --- a/libgomp/libgomp.map +++ b/libgomp/libgomp.map @@ -208,6 +208,7 @@ GOMP_3.0 { GOMP_4.0 { global: + GOMP_register_lib; GOMP_barrier_cancel; GOMP_cancel; GOMP_cancellation_point; diff --git a/libgomp/target.c b/libgomp/target.c index d84a1fa..7677c28 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -84,6 +84,19 @@ struct splay_tree_key_s { bool copy_from; }; +enum library_descr { + DESCR_TABLE_START, + DESCR_TABLE_END, + DESCR_IMAGE_START, + DESCR_IMAGE_END +}; + +/* Array of pointers to target shared library descriptors. */ +static void **libraries; + +/* Total number of target shared libraries. */ +static int num_libraries; + /* Array of descriptors of all available devices. */ static struct gomp_device_descr *devices; @@ -117,11 +130,16 @@ struct gomp_device_descr TARGET construct. */ int id; + /* Set to true when device is initialized. */ + bool is_initialized; + /* Plugin file handler. */ void *plugin_handle; /* Function handlers. */ - bool (*device_available_func) (void); + bool (*device_available_func) (int); + void (*device_init_func) (void **, int *, int, void ***, int *); + void (*device_run_func) (void *, uintptr_t); /* Splay tree containing information about mapped memory regions. */ struct splay_tree_s dev_splay_tree; @@ -466,6 +484,89 @@ gomp_update (struct gomp_device_descr *devicep, size_t mapnum, gomp_mutex_unlock (devicep-dev_env_lock); } +void +GOMP_register_lib (const void *openmp_target) +{ + libraries = realloc (libraries, (num_libraries + 1) * sizeof (void *)); + + if (libraries == NULL) +return; + + libraries[num_libraries] = (void *) openmp_target; + + num_libraries++; +} + +static void +gomp_init_device (struct gomp_device_descr *devicep) +{ + void **target_images = malloc (num_libraries * sizeof (void *)); + int *target_img_sizes = malloc (num_libraries * sizeof (int)); + if (target_images == NULL || target_img_sizes == NULL) +gomp_fatal (Can not allocate memory); + + /* Collect target images from the library descriptors and calculate the total + size of host address table. */ + int i, host_table_size = 0; + for (i = 0; i num_libraries; i++) +{ + void **lib = libraries[i]; + void **host_table_start = lib[DESCR_TABLE_START]; + void **host_table_end = lib[DESCR_TABLE_END]; + /* FIXME: Select the proper target image. */ + target_images[i] = lib[DESCR_IMAGE_START]; + target_img_sizes[i] = lib[DESCR_IMAGE_END] - lib[DESCR_IMAGE_START]; + host_table_size += host_table_end - host_table_start; +} + + /* Initialize the target device and receive the address table from target. */ + void **target_table = NULL; + int target_table_size = 0; + devicep-device_init_func (target_images, target_img_sizes, num_libraries, +target_table, target_table_size); + free (target_images); + free (target_img_sizes); + + if (host_table_size != target_table_size) +gomp_fatal (Can't map target objects); + + /* Initialize the mapping data structure. */ + void **target_entry = target_table; + for (i = 0; i num_libraries; i++) +{ + void **lib = libraries[i]; + void **host_table_start = lib[DESCR_TABLE_START]; + void **host_table_end = lib[DESCR_TABLE_END]; + void **host_entry; + for (host_entry = host_table_start; host_entry host_table_end; + host_entry += 2, target_entry += 2) + { + struct target_mem_desc *tgt = gomp_malloc (sizeof (*tgt)); + tgt-refcount = 1; + tgt-array = gomp_malloc (sizeof (*tgt-array)); + tgt-tgt_start = (uintptr_t) *target_entry; + tgt-tgt_end = tgt-tgt_start + *((uint64_t *) target_entry + 1); +