1 /* Copyright (C) 2013-2014 Free Software Foundation, Inc.
2 Contributed by Jakub Jelinek <jakub@redhat.com>.
4 This file is part of the GNU OpenMP Library (libgomp).
6 Libgomp is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 /* This file handles the maintainence of threads in response to team
26 creation and termination. */
32 #include "splay-tree.h"
33 #include "gomp-constants.h"
35 struct target_mem_desc
{
36 /* Reference count. */
38 /* All the splay nodes allocated together. */
39 splay_tree_node array
;
40 /* Start of the target region. */
42 /* End of the targer region. */
46 /* Previous target_mem_desc. */
47 struct target_mem_desc
*prev
;
48 /* Number of items in following list. */
51 /* Corresponding target device descriptor. */
52 struct gomp_device_descr
*device_descr
;
54 /* Memory mapping info for the thread that created this descriptor. */
55 struct gomp_memory_mapping
*mem_map
;
57 /* List of splay keys to remove (or decrease refcount)
58 at the end of region. */
59 splay_tree_key list
[];
62 /* Keep in sync with openacc.h:acc_device_t. */
65 TARGET_TYPE_HOST
= GOMP_TARGET_HOST
,
66 TARGET_TYPE_HOST_NONSHM
= GOMP_TARGET_HOST_NONSHM
,
67 TARGET_TYPE_NVIDIA_PTX
= GOMP_TARGET_NVIDIA_PTX
,
68 TARGET_TYPE_INTEL_MIC
= GOMP_TARGET_INTEL_MIC
,
71 #define TARGET_CAP_SHARED_MEM 1
72 #define TARGET_CAP_NATIVE_EXEC 2
73 #define TARGET_CAP_OPENMP_400 4
74 #define TARGET_CAP_OPENACC_200 8
76 /* Information about mapped memory regions (per device/context). */
78 struct gomp_memory_mapping
80 /* Splay tree containing information about mapped memory regions. */
81 struct splay_tree_s splay_tree
;
83 /* Mutex for operating with the splay tree and other shared structures. */
86 /* True when tables have been added to this memory map. */
90 typedef struct ACC_dispatch_t
92 /* This is a linked list of data mapped using the
93 acc_map_data/acc_unmap_data or "acc enter data"/"acc exit data" pragmas
94 (TODO). Unlike mapped_data in the goacc_thread struct, unmapping can
95 happen out-of-order with respect to mapping. */
96 struct target_mem_desc
*data_environ
;
98 /* Open or close a device instance. */
99 void *(*open_device_func
) (int n
);
100 int (*close_device_func
) (void *h
);
102 /* Set or get the device number. */
103 int (*get_device_num_func
) (void);
104 void (*set_device_num_func
) (int);
107 void (*exec_func
) (void (*) (void *), size_t, void **, void **, size_t *,
108 unsigned short *, int, int, int, int, void *);
110 /* Async cleanup callback registration. */
111 void (*register_async_cleanup_func
) (void *);
113 /* Asynchronous routines. */
114 int (*async_test_func
) (int);
115 int (*async_test_all_func
) (void);
116 void (*async_wait_func
) (int);
117 void (*async_wait_async_func
) (int, int);
118 void (*async_wait_all_func
) (void);
119 void (*async_wait_all_async_func
) (int);
120 void (*async_set_async_func
) (int);
122 /* Create/destroy TLS data. */
123 void *(*create_thread_data_func
) (void *);
124 void (*destroy_thread_data_func
) (void *);
126 /* NVIDIA target specific routines. */
128 void *(*get_current_device_func
) (void);
129 void *(*get_current_context_func
) (void);
130 void *(*get_stream_func
) (int);
131 int (*set_stream_func
) (int, void *);
135 struct mapping_table
{
136 uintptr_t host_start
;
142 /* This structure describes accelerator device.
143 It contains name of the corresponding libgomp plugin, function handlers for
144 interaction with the device, ID-number of the device, and information about
146 struct gomp_device_descr
148 /* The name of the device. */
151 /* Capabilities of device (supports OpenACC, OpenMP). */
152 unsigned int capabilities
;
154 /* This is the ID number of device. It could be specified in DEVICE-clause of
158 /* The number of the device for this particular device type. */
161 /* This is the TYPE of device. */
162 enum target_type type
;
164 /* Set to true when device is initialized. */
167 /* True when offload regions have been registered with this device. */
168 bool offload_regions_registered
;
170 /* Plugin file handler. */
173 /* Function handlers. */
174 const char *(*get_name_func
) (void);
175 unsigned int (*get_caps_func
) (void);
176 int (*get_type_func
) (void);
177 int (*get_num_devices_func
) (void);
178 void (*offload_register_func
) (void *, void *);
179 int (*device_init_func
) (void);
180 int (*device_fini_func
) (void);
181 int (*device_get_table_func
) (struct mapping_table
**);
182 void *(*device_alloc_func
) (size_t);
183 void (*device_free_func
) (void *);
184 void *(*device_dev2host_func
) (void *, const void *, size_t);
185 void *(*device_host2dev_func
) (void *, const void *, size_t);
186 void (*device_run_func
) (void *, void *);
188 /* OpenACC-specific functions. */
189 ACC_dispatch_t openacc
;
191 /* Memory-mapping info for this device instance. */
192 struct gomp_memory_mapping mem_map
;
194 /* Extra information required for a device instance by a given target. */
198 extern struct target_mem_desc
*
199 gomp_map_vars (struct gomp_device_descr
*devicep
, size_t mapnum
,
200 void **hostaddrs
, void **devaddrs
, size_t *sizes
, void *kinds
,
201 bool is_openacc
, bool is_target
);
204 gomp_copy_from_async (struct target_mem_desc
*tgt
);
207 gomp_unmap_vars (struct target_mem_desc
*tgt
, bool);
209 extern attribute_hidden
void
210 gomp_init_device (struct gomp_device_descr
*devicep
);
212 extern attribute_hidden
void
213 gomp_init_tables (const struct gomp_device_descr
*devicep
,
214 struct gomp_memory_mapping
*mm
);
216 extern attribute_hidden
void
217 gomp_fini_device (struct gomp_device_descr
*devicep
);
219 extern attribute_hidden
void
220 gomp_free_memmap (struct gomp_device_descr
*devicep
);
222 #endif /* _TARGET_H */