svn merge -r 217500:218679 svn+ssh://gcc.gnu.org/svn/gcc/trunk
[official-gcc.git] / libgomp / libgomp_target.h
blobb780259dbc536d065bb80f96ecea53ac4d0a65fb
1 /* Copyright (C) 2014 Free Software Foundation, Inc.
3 This file is part of the GNU OpenMP Library (libgomp).
5 Libgomp is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
8 any later version.
10 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 #ifndef LIBGOMP_TARGET_H
25 #define LIBGOMP_TARGET_H 1
27 #include "gomp-constants.h"
29 /* Type of offload target device. Keep in sync with openacc.h:acc_device_t. */
30 enum offload_target_type
32 OFFLOAD_TARGET_TYPE_HOST = GOMP_TARGET_HOST,
33 OFFLOAD_TARGET_TYPE_HOST_NONSHM = GOMP_TARGET_HOST_NONSHM,
34 OFFLOAD_TARGET_TYPE_NVIDIA_PTX = GOMP_TARGET_NVIDIA_PTX,
35 OFFLOAD_TARGET_TYPE_INTEL_MIC = GOMP_TARGET_INTEL_MIC
38 /* Auxiliary struct, used for transferring a host-target address range mapping
39 from plugin to libgomp. */
40 struct mapping_table
42 uintptr_t host_start;
43 uintptr_t host_end;
44 uintptr_t tgt_start;
45 uintptr_t tgt_end;
48 #include "splay-tree.h"
50 struct target_mem_desc {
51 /* Reference count. */
52 uintptr_t refcount;
53 /* All the splay nodes allocated together. */
54 splay_tree_node array;
55 /* Start of the target region. */
56 uintptr_t tgt_start;
57 /* End of the targer region. */
58 uintptr_t tgt_end;
59 /* Handle to free. */
60 void *to_free;
61 /* Previous target_mem_desc. */
62 struct target_mem_desc *prev;
63 /* Number of items in following list. */
64 size_t list_count;
66 /* Corresponding target device descriptor. */
67 struct gomp_device_descr *device_descr;
69 /* Memory mapping info for the thread that created this descriptor. */
70 struct gomp_memory_mapping *mem_map;
72 /* List of splay keys to remove (or decrease refcount)
73 at the end of region. */
74 splay_tree_key list[];
77 #define TARGET_CAP_SHARED_MEM 1
78 #define TARGET_CAP_NATIVE_EXEC 2
79 #define TARGET_CAP_OPENMP_400 4
80 #define TARGET_CAP_OPENACC_200 8
82 /* Information about mapped memory regions (per device/context). */
84 struct gomp_memory_mapping
86 /* Splay tree containing information about mapped memory regions. */
87 struct splay_tree_s splay_tree;
89 /* Mutex for operating with the splay tree and other shared structures. */
90 gomp_mutex_t lock;
92 /* True when tables have been added to this memory map. */
93 bool is_initialized;
96 typedef struct ACC_dispatch_t
98 /* This is a linked list of data mapped using the
99 acc_map_data/acc_unmap_data or "acc enter data"/"acc exit data" pragmas
100 (TODO). Unlike mapped_data in the goacc_thread struct, unmapping can
101 happen out-of-order with respect to mapping. */
102 struct target_mem_desc *data_environ;
104 /* Open or close a device instance. */
105 void *(*open_device_func) (int n);
106 int (*close_device_func) (void *h);
108 /* Set or get the device number. */
109 int (*get_device_num_func) (void);
110 void (*set_device_num_func) (int);
112 /* Execute. */
113 void (*exec_func) (void (*) (void *), size_t, void **, void **, size_t *,
114 unsigned short *, int, int, int, int, void *);
116 /* Async cleanup callback registration. */
117 void (*register_async_cleanup_func) (void *);
119 /* Asynchronous routines. */
120 int (*async_test_func) (int);
121 int (*async_test_all_func) (void);
122 void (*async_wait_func) (int);
123 void (*async_wait_async_func) (int, int);
124 void (*async_wait_all_func) (void);
125 void (*async_wait_all_async_func) (int);
126 void (*async_set_async_func) (int);
128 /* Create/destroy TLS data. */
129 void *(*create_thread_data_func) (void *);
130 void (*destroy_thread_data_func) (void *);
132 /* NVIDIA target specific routines. */
133 struct {
134 void *(*get_current_device_func) (void);
135 void *(*get_current_context_func) (void);
136 void *(*get_stream_func) (int);
137 int (*set_stream_func) (int, void *);
138 } cuda;
139 } ACC_dispatch_t;
141 /* This structure describes accelerator device.
142 It contains name of the corresponding libgomp plugin, function handlers for
143 interaction with the device, ID-number of the device, and information about
144 mapped memory. */
145 struct gomp_device_descr
147 /* The name of the device. */
148 const char *name;
150 /* Capabilities of device (supports OpenACC, OpenMP). */
151 unsigned int capabilities;
153 /* This is the ID number of device. It could be specified in DEVICE-clause of
154 TARGET construct. */
155 int id;
157 /* This is the ID number of device among devices of the same type. */
158 int target_id;
160 /* This is the TYPE of device. */
161 enum offload_target_type type;
163 /* Set to true when device is initialized. */
164 bool is_initialized;
166 /* True when offload regions have been registered with this device. */
167 bool offload_regions_registered;
169 /* Function handlers. */
170 const char *(*get_name_func) (void);
171 unsigned int (*get_caps_func) (void);
172 int (*get_type_func) (void);
173 int (*get_num_devices_func) (void);
174 void (*register_image_func) (void *, void *);
175 void (*init_device_func) (int);
176 void (*fini_device_func) (int);
177 int (*get_table_func) (int, struct mapping_table **);
178 void *(*alloc_func) (int, size_t);
179 void (*free_func) (int, void *);
180 void *(*dev2host_func) (int, void *, const void *, size_t);
181 void *(*host2dev_func) (int, void *, const void *, size_t);
182 void (*run_func) (int, void *, void *);
184 /* OpenACC-specific functions. */
185 ACC_dispatch_t openacc;
187 /* Memory-mapping info for this device instance. */
188 struct gomp_memory_mapping mem_map;
190 /* Extra information required for a device instance by a given target. */
191 void *target_data;
194 extern struct target_mem_desc *
195 gomp_map_vars (struct gomp_device_descr *devicep, size_t mapnum,
196 void **hostaddrs, void **devaddrs, size_t *sizes, void *kinds,
197 bool is_openacc, bool is_target);
199 extern void
200 gomp_copy_from_async (struct target_mem_desc *tgt);
202 extern void
203 gomp_unmap_vars (struct target_mem_desc *tgt, bool);
205 extern attribute_hidden void
206 gomp_init_device (struct gomp_device_descr *devicep);
208 extern attribute_hidden void
209 gomp_init_tables (const struct gomp_device_descr *devicep,
210 struct gomp_memory_mapping *mm);
212 extern attribute_hidden void
213 gomp_fini_device (struct gomp_device_descr *devicep);
215 extern attribute_hidden void
216 gomp_free_memmap (struct gomp_device_descr *devicep);
218 #endif /* LIBGOMP_TARGET_H */