On Tue, 23 Sep 2014 19:19:31 +0100 Julian Brown wrote: > This patch contains the bulk of the OpenACC 2.0 runtime support, > building around, or on top of, the OpenMP 4.0 support (as previously > posted or already extant upstream) where we could. [...] Here is a new version of the OpenACC support patch for libgomp, rebased on top of a version of Ilya Verbin's patches that I merged to a local clone of trunk, and tested as far as possible without the middle/front-end pieces, since those are not ready yet. This patch brings the OpenACC support in libgomp up-to-date with the various fixes that I have been making on the gomp4 branch, in particular I believe all of Jakub's earlier comments in the following email have been addressed: https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02095.html Since Ilya's most-recently posted patches, there is now somewhat of a mismatch in APIs between the OpenMP and OpenACC parts of libgomp with regard to handling of multiple devices of the same type. This is mostly handled by the "open" and "close" hooks for OpenACC (and per-thread state that tracks the active device number) but is now handled by the "init" hook for OpenMP (which OpenACC just uses for overall initialisation/shutdown), and explicit target_id parameters for several of the plugin hooks. This is only a problem for hypothetical plugins that support both multiple devices and both of OpenMP and OpenACC, and so far no such plugins exist, but we may need to think about how to unify the divergent approaches to multiple devices/multiple threads sooner or later. A few OpenMP tests fail with the new host_nonshm plugin (with failures of the form "libgomp: Trying to update [0x605820..0x605824) object that is not mapped"), probably because of middle-end bugs. I haven't investigated those in detail. OK for mainline? Thanks, Julian ChangeLog xxxx-xx-xx Nathan Sidwell James Norris Thomas Schwinge Tom de Vries Julian Brown Bernd Schmidt Cesar Philippidis include/ * gomp-constants.h: New file. libgomp/ * Makefile.am (search_path): Search in $(top_srcidr)/../include also. (libgomp_la_SOURCES): Add oacc-parallel.c, splay-tree.c, oacc-host.c, oacc-init.c, oacc-mem.c, oacc-async.c, oacc-plugin.c, oacc-cuda.c, libgomp-plugin.c. (Makefrag.am): Include. (libgomp_la_SOURCES): Add openacc.f90 if USE_FORTRAN is true. (nodist_libsubinclude_HEADERS): Add openacc.h, ../include/gomp-constants.h. (nodist_finclude_HEADERS): Add openacc_lib.h, openacc.f90, openacc.mod, openacc_kinds.mod. * configure.ac (plugin_support): Add check for accelerators if attempting to build plugins. (plugin/configfrag.ac): Include. (offload_targets): Add host_nonshm target by default, nvptx target conditionally if the corresponding offload target is enabled. (testsuite/libgomp-test-support.exp): Add to AC_CONFIG_FILES. * env.c (libgomp_target.h, oacc-int.h): Include. (goacc_notify_var, goacc_device_num, goacc_device_type): New globals. (goacc_parse_device_type): New functions. (initialize_env): Parse GCC_ACC_NOTIFY, ACC_DEVICE_TYPE, ACC_DEVICE_NUM environment variables. Call ACC_runtime_initialize. * error.c (gomp_verror): Make global. (gomp_vfatal, gomp_vnotify, gomp_notify): New functions. (gomp_fatal): Use gomp_vfatal instead of gomp_verror. * libgomp.h (stdarg.h): Include. (struct gomp_memory_mapping): Forward declaration. (goacc_notify_var, goacc_device_num, goacc_device_type): Add extern declarations. (gomp_vnotify, gomp_notify, gomp_verror, gomp_vfatal): Add prototypes. (gomp_init_targets_once): Add prototype. * libgomp.map (OACC_2.0): New symbol version. Add public acc_* interface functions. (PLUGIN_1.0): New symbol version. Add gomp plugin interface functions. * libgomp_g.h (GOACC_data_start, GOACC_data_end, GOACC_kernels) (GOACC_parallel, GOACC_wait): Add prototypes. * libgomp_target.h (gomp-constants.h, splay-tree.h): Include. (offload_target_type): Set enumeration values from constants in gomp-constants.h. Add OFFLOAD_TARGET_TYPE_HOST_NONSHM and OFFLOAD_TARGET_TYPE_NVIDIA_PTX. (struct target_mem_desc): Move to here. (TARGET_CAP_SHARED_MEM, TARGET_CAP_NATIVE_EXEC, TARGET_CAP_OPENMP_400) (TARGET_CAP_OPENACC_200): Define macros. (struct gomp_memory_mapping): New. (struct ACC_dispatch_t): New. (struct gomp_device_descr): Move here. Add offload_regions_registered, openacc dispatch functions, target_data. (gomp_map_vars, gomp_copy_from_async, gomp_unmap_vars, gomp_init_device) (gomp_init_tables, gomp_fini_device, gomp_free_memmap): Add prototypes. * target.c (oacc-plugin.h, gomp-constants.h, oacc-int.h, stdio.h) (assert.h): Include. (splay_tree_node, splay_tree, splay_tree_key, target_mem_desc) (splay_tree_key_s, gomp_device_descr): Don't declare here. (splay_compare): Change linkage to hidden not static. (gomp_init_targets_once): New function. (gomp_get_num_devices): Use above. (get_kind): New function. (gomp_map_vars): Add is_openacc parameter. Change KINDS to void *. Use lock from memory map not device. Use macros from gomp-constants.h instead of hard-coded values. Support OpenACC-specific mappings. (gomp_copy_from_async): New function. (gomp_unmap_vars): Add DO_COPYFROM argument. Only copy memory back from device if it is true. Use lock from memory map not device. (gomp_update): Add is_openacc parameter. Use lock from memory map not device. Use macros from gomp-constants.h instead of hard-coded values. (gomp_register_image_for_device): Add forward declaration. (GOMP_offload_register): Check realloc result. (gomp_init_device): Change linkage to hidden not static. (gomp_init_tables, gomp_init_dev_tables, gomp_free_memmap) (gomp_fini_device): New function. (GOMP_target): Adjust lazy initialization, check target capabilities for OpenMP 4.0 support. Update call to gomp_map_vars, gomp_unmap_vars. (GOMP_target_data): Adjust lazy initialization. Update call to gomp_map_vars. (GOMP_target_end_data): Update call to gomp_unmap_vars. (GOMP_target_update): Tweak lazy initialization. Add new args to gomp_update call. (gomp_load_plugin_for_device): Initialize get_name, get_caps, device_fini and OpenACC-specific plugin hooks. (gomp_register_images_for_device): Rename to... (gomp_register_image_for_device): This, and register a single device only, and only if it has not already had images registered. (gomp_find_available_plugins): Initialize OpenACC-specific bits, offload image registration, and other new device member data. Prefer device with TARGET_CAP_OPENMP_400 if more than one plugin is available. * libgomp-plugin.c: New file. * libgomp-plugin.h: New file. * oacc-async.c: New file. * oacc-cuda.c: New file. * oacc-host.c: New file. * oacc-init.c: New file. * oacc-int.h: New file. * oacc-mem.c: New file. * oacc-parallel.c: New file. * oacc-plugin.c: New file. * oacc-plugin.h: New file. * openacc.f90: New file. * openacc.h: New file. * openacc_lib.h: New file. * splay-tree.h: Move bulk of implementation to... * splay-tree.c: New file. * Makefile.in: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * plugin/Makefrag.am: New file. * plugin/configfrag.am: New file. * plugin/plugin-host.c: New file. * plugin/plugin-nvptx.c: New file. * testsuite/libgomp-test-support.exp.in: New file.