From db16ceabfcaaa6c9e41c01e289201e6a9fbe3b26 Mon Sep 17 00:00:00 2001 From: tschwinge Date: Wed, 17 Dec 2014 22:30:30 +0000 Subject: [PATCH] libgomp: Again make libgomp_target.h safe to use "from outside". libgomp/ * libgomp_g.h: Move internal stuff from here... * libgomp_target.h: ..., and here... * libgomp.h: ... into here. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@218841 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgomp/ChangeLog.gomp | 4 + libgomp/libgomp.h | 167 +++++++++++++++++++++++++++++ libgomp/libgomp_g.h | 5 - libgomp/libgomp_target.h | 266 +++++++++-------------------------------------- libgomp/splay-tree.h | 6 +- 5 files changed, 221 insertions(+), 227 deletions(-) rewrite libgomp/libgomp_target.h (76%) diff --git a/libgomp/ChangeLog.gomp b/libgomp/ChangeLog.gomp index dd37326ca9a..97eb045c65a 100644 --- a/libgomp/ChangeLog.gomp +++ b/libgomp/ChangeLog.gomp @@ -1,5 +1,9 @@ 2014-12-17 Thomas Schwinge + * libgomp_g.h: Move internal stuff from here... + * libgomp_target.h: ..., and here... + * libgomp.h: ... into here. + * Makefile.am: Don't add ../include/gomp-constants.h to nodist_libsubinclude_HEADERS. diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index dbf16288056..78de0b43390 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -632,6 +632,173 @@ extern void gomp_free_thread (void *); extern void gomp_init_targets_once (void); extern int gomp_get_num_devices (void); +#include "libgomp_target.h" +#include "splay-tree.h" + +struct target_mem_desc { + /* Reference count. */ + uintptr_t refcount; + /* All the splay nodes allocated together. */ + splay_tree_node array; + /* Start of the target region. */ + uintptr_t tgt_start; + /* End of the targer region. */ + uintptr_t tgt_end; + /* Handle to free. */ + void *to_free; + /* Previous target_mem_desc. */ + struct target_mem_desc *prev; + /* Number of items in following list. */ + size_t list_count; + + /* Corresponding target device descriptor. */ + struct gomp_device_descr *device_descr; + + /* Memory mapping info for the thread that created this descriptor. */ + struct gomp_memory_mapping *mem_map; + + /* List of splay keys to remove (or decrease refcount) + at the end of region. */ + splay_tree_key list[]; +}; + +#define TARGET_CAP_SHARED_MEM 1 +#define TARGET_CAP_NATIVE_EXEC 2 +#define TARGET_CAP_OPENMP_400 4 +#define TARGET_CAP_OPENACC_200 8 + +/* Information about mapped memory regions (per device/context). */ + +struct gomp_memory_mapping +{ + /* Splay tree containing information about mapped memory regions. */ + struct splay_tree_s splay_tree; + + /* Mutex for operating with the splay tree and other shared structures. */ + gomp_mutex_t lock; + + /* True when tables have been added to this memory map. */ + bool is_initialized; +}; + +typedef struct acc_dispatch_t +{ + /* This is a linked list of data mapped using the + acc_map_data/acc_unmap_data or "acc enter data"/"acc exit data" pragmas + (TODO). Unlike mapped_data in the goacc_thread struct, unmapping can + happen out-of-order with respect to mapping. */ + struct target_mem_desc *data_environ; + + /* Open or close a device instance. */ + void *(*open_device_func) (int n); + int (*close_device_func) (void *h); + + /* Set or get the device number. */ + int (*get_device_num_func) (void); + void (*set_device_num_func) (int); + + /* Execute. */ + void (*exec_func) (void (*) (void *), size_t, void **, void **, size_t *, + unsigned short *, int, int, int, int, void *); + + /* Async cleanup callback registration. */ + void (*register_async_cleanup_func) (void *); + + /* Asynchronous routines. */ + int (*async_test_func) (int); + int (*async_test_all_func) (void); + void (*async_wait_func) (int); + void (*async_wait_async_func) (int, int); + void (*async_wait_all_func) (void); + void (*async_wait_all_async_func) (int); + void (*async_set_async_func) (int); + + /* Create/destroy TLS data. */ + void *(*create_thread_data_func) (void *); + void (*destroy_thread_data_func) (void *); + + /* NVIDIA target specific routines. */ + struct { + void *(*get_current_device_func) (void); + void *(*get_current_context_func) (void); + void *(*get_stream_func) (int); + int (*set_stream_func) (int, void *); + } cuda; +} acc_dispatch_t; + +/* This structure describes accelerator device. + It contains name of the corresponding libgomp plugin, function handlers for + interaction with the device, ID-number of the device, and information about + mapped memory. */ +struct gomp_device_descr +{ + /* The name of the device. */ + const char *name; + + /* Capabilities of device (supports OpenACC, OpenMP). */ + unsigned int capabilities; + + /* This is the ID number of device. It could be specified in DEVICE-clause of + TARGET construct. */ + int id; + + /* This is the ID number of device among devices of the same type. */ + int target_id; + + /* This is the TYPE of device. */ + enum offload_target_type type; + + /* Set to true when device is initialized. */ + bool is_initialized; + + /* True when offload regions have been registered with this device. */ + bool offload_regions_registered; + + /* Function handlers. */ + const char *(*get_name_func) (void); + unsigned int (*get_caps_func) (void); + int (*get_type_func) (void); + int (*get_num_devices_func) (void); + void (*register_image_func) (void *, void *); + void (*init_device_func) (int); + void (*fini_device_func) (int); + int (*get_table_func) (int, struct mapping_table **); + 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 (*run_func) (int, void *, void *); + + /* OpenACC-specific functions. */ + acc_dispatch_t openacc; + + /* Memory-mapping info for this device instance. */ + struct gomp_memory_mapping mem_map; + + /* Extra information required for a device instance by a given target. */ + void *target_data; +}; + +extern void gomp_acc_insert_pointer (size_t, void **, size_t *, void *); +extern void gomp_acc_remove_pointer (void *, bool, int, int); + +extern struct target_mem_desc *gomp_map_vars (struct gomp_device_descr *, + size_t, void **, void **, + size_t *, void *, bool, bool); + +extern void gomp_copy_from_async (struct target_mem_desc *); + +extern void gomp_unmap_vars (struct target_mem_desc *, bool); + +extern void gomp_init_device (struct gomp_device_descr *); + +extern void gomp_init_tables (const struct gomp_device_descr *, + struct gomp_memory_mapping *); + +extern void gomp_fini_device (struct gomp_device_descr *); + +extern void gomp_free_memmap (struct gomp_device_descr *); + /* work.c */ extern void gomp_init_work_share (struct gomp_work_share *, bool, unsigned); diff --git a/libgomp/libgomp_g.h b/libgomp/libgomp_g.h index 4206d51f14e..07d1666a047 100644 --- a/libgomp/libgomp_g.h +++ b/libgomp/libgomp_g.h @@ -234,9 +234,4 @@ extern void GOACC_wait (int, int, ...); extern int GOACC_get_num_threads (void); extern int GOACC_get_thread_num (void); -/* oacc-mem.c */ - -extern void gomp_acc_insert_pointer (size_t, void **, size_t *, void *); -extern void gomp_acc_remove_pointer (void *, bool, int, int); - #endif /* LIBGOMP_G_H */ diff --git a/libgomp/libgomp_target.h b/libgomp/libgomp_target.h dissimilarity index 76% index 4d658cc9cf0..b6723fe153f 100644 --- a/libgomp/libgomp_target.h +++ b/libgomp/libgomp_target.h @@ -1,219 +1,47 @@ -/* Copyright (C) 2014 Free Software Foundation, Inc. - - This file is part of the GNU Offloading and Multi Processing Library - (libgomp). - - Libgomp is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - Under Section 7 of GPL version 3, you are granted additional - permissions described in the GCC Runtime Library Exception, version - 3.1, as published by the Free Software Foundation. - - You should have received a copy of the GNU General Public License and - a copy of the GCC Runtime Library Exception along with this program; - see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - . */ - -#ifndef LIBGOMP_TARGET_H -#define LIBGOMP_TARGET_H 1 - -#include "gomp-constants.h" - -/* Type of offload target device. Keep in sync with include/gomp-constants.h. */ -enum offload_target_type -{ - OFFLOAD_TARGET_TYPE_HOST = 2, - OFFLOAD_TARGET_TYPE_HOST_NONSHM = 3, - OFFLOAD_TARGET_TYPE_NVIDIA_PTX = 5, - OFFLOAD_TARGET_TYPE_INTEL_MIC = 6 -}; - -/* Auxiliary struct, used for transferring a host-target address range mapping - from plugin to libgomp. */ -struct mapping_table -{ - uintptr_t host_start; - uintptr_t host_end; - uintptr_t tgt_start; - uintptr_t tgt_end; -}; - -#include "splay-tree.h" - -struct target_mem_desc { - /* Reference count. */ - uintptr_t refcount; - /* All the splay nodes allocated together. */ - splay_tree_node array; - /* Start of the target region. */ - uintptr_t tgt_start; - /* End of the targer region. */ - uintptr_t tgt_end; - /* Handle to free. */ - void *to_free; - /* Previous target_mem_desc. */ - struct target_mem_desc *prev; - /* Number of items in following list. */ - size_t list_count; - - /* Corresponding target device descriptor. */ - struct gomp_device_descr *device_descr; - - /* Memory mapping info for the thread that created this descriptor. */ - struct gomp_memory_mapping *mem_map; - - /* List of splay keys to remove (or decrease refcount) - at the end of region. */ - splay_tree_key list[]; -}; - -#define TARGET_CAP_SHARED_MEM 1 -#define TARGET_CAP_NATIVE_EXEC 2 -#define TARGET_CAP_OPENMP_400 4 -#define TARGET_CAP_OPENACC_200 8 - -/* Information about mapped memory regions (per device/context). */ - -struct gomp_memory_mapping -{ - /* Splay tree containing information about mapped memory regions. */ - struct splay_tree_s splay_tree; - - /* Mutex for operating with the splay tree and other shared structures. */ - gomp_mutex_t lock; - - /* True when tables have been added to this memory map. */ - bool is_initialized; -}; - -typedef struct acc_dispatch_t -{ - /* This is a linked list of data mapped using the - acc_map_data/acc_unmap_data or "acc enter data"/"acc exit data" pragmas - (TODO). Unlike mapped_data in the goacc_thread struct, unmapping can - happen out-of-order with respect to mapping. */ - struct target_mem_desc *data_environ; - - /* Open or close a device instance. */ - void *(*open_device_func) (int n); - int (*close_device_func) (void *h); - - /* Set or get the device number. */ - int (*get_device_num_func) (void); - void (*set_device_num_func) (int); - - /* Execute. */ - void (*exec_func) (void (*) (void *), size_t, void **, void **, size_t *, - unsigned short *, int, int, int, int, void *); - - /* Async cleanup callback registration. */ - void (*register_async_cleanup_func) (void *); - - /* Asynchronous routines. */ - int (*async_test_func) (int); - int (*async_test_all_func) (void); - void (*async_wait_func) (int); - void (*async_wait_async_func) (int, int); - void (*async_wait_all_func) (void); - void (*async_wait_all_async_func) (int); - void (*async_set_async_func) (int); - - /* Create/destroy TLS data. */ - void *(*create_thread_data_func) (void *); - void (*destroy_thread_data_func) (void *); - - /* NVIDIA target specific routines. */ - struct { - void *(*get_current_device_func) (void); - void *(*get_current_context_func) (void); - void *(*get_stream_func) (int); - int (*set_stream_func) (int, void *); - } cuda; -} acc_dispatch_t; - -/* This structure describes accelerator device. - It contains name of the corresponding libgomp plugin, function handlers for - interaction with the device, ID-number of the device, and information about - mapped memory. */ -struct gomp_device_descr -{ - /* The name of the device. */ - const char *name; - - /* Capabilities of device (supports OpenACC, OpenMP). */ - unsigned int capabilities; - - /* This is the ID number of device. It could be specified in DEVICE-clause of - TARGET construct. */ - int id; - - /* This is the ID number of device among devices of the same type. */ - int target_id; - - /* This is the TYPE of device. */ - enum offload_target_type type; - - /* Set to true when device is initialized. */ - bool is_initialized; - - /* True when offload regions have been registered with this device. */ - bool offload_regions_registered; - - /* Function handlers. */ - const char *(*get_name_func) (void); - unsigned int (*get_caps_func) (void); - int (*get_type_func) (void); - int (*get_num_devices_func) (void); - void (*register_image_func) (void *, void *); - void (*init_device_func) (int); - void (*fini_device_func) (int); - int (*get_table_func) (int, struct mapping_table **); - 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 (*run_func) (int, void *, void *); - - /* OpenACC-specific functions. */ - acc_dispatch_t openacc; - - /* Memory-mapping info for this device instance. */ - struct gomp_memory_mapping mem_map; - - /* Extra information required for a device instance by a given target. */ - void *target_data; -}; - -extern struct target_mem_desc * -gomp_map_vars (struct gomp_device_descr *devicep, size_t mapnum, - void **hostaddrs, void **devaddrs, size_t *sizes, void *kinds, - bool is_openacc, bool is_target); - -extern void -gomp_copy_from_async (struct target_mem_desc *tgt); - -extern void -gomp_unmap_vars (struct target_mem_desc *tgt, bool); - -extern attribute_hidden void -gomp_init_device (struct gomp_device_descr *devicep); - -extern attribute_hidden void -gomp_init_tables (const struct gomp_device_descr *devicep, - struct gomp_memory_mapping *mm); - -extern attribute_hidden void -gomp_fini_device (struct gomp_device_descr *devicep); - -extern attribute_hidden void -gomp_free_memmap (struct gomp_device_descr *devicep); - -#endif /* LIBGOMP_TARGET_H */ +/* Copyright (C) 2014 Free Software Foundation, Inc. + + This file is part of the GNU Offloading and Multi Processing Library + (libgomp). + + Libgomp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +#ifndef LIBGOMP_TARGET_H +#define LIBGOMP_TARGET_H 1 + +/* Type of offload target device. Keep in sync with include/gomp-constants.h. */ +enum offload_target_type +{ + OFFLOAD_TARGET_TYPE_HOST = 2, + OFFLOAD_TARGET_TYPE_HOST_NONSHM = 3, + OFFLOAD_TARGET_TYPE_NVIDIA_PTX = 5, + OFFLOAD_TARGET_TYPE_INTEL_MIC = 6 +}; + +/* Auxiliary struct, used for transferring a host-target address range mapping + from plugin to libgomp. */ +struct mapping_table +{ + uintptr_t host_start; + uintptr_t host_end; + uintptr_t tgt_start; + uintptr_t tgt_end; +}; + +#endif /* LIBGOMP_TARGET_H */ diff --git a/libgomp/splay-tree.h b/libgomp/splay-tree.h index 2afbbc2ebf4..ffe5822219b 100644 --- a/libgomp/splay-tree.h +++ b/libgomp/splay-tree.h @@ -81,8 +81,8 @@ struct splay_tree_s { splay_tree_node root; }; -attribute_hidden splay_tree_key splay_tree_lookup (splay_tree, splay_tree_key); -attribute_hidden void splay_tree_insert (splay_tree, splay_tree_node); -attribute_hidden void splay_tree_remove (splay_tree, splay_tree_key); +extern splay_tree_key splay_tree_lookup (splay_tree, splay_tree_key); +extern void splay_tree_insert (splay_tree, splay_tree_node); +extern void splay_tree_remove (splay_tree, splay_tree_key); #endif /* _SPLAY_TREE_H */ -- 2.11.4.GIT