]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgomp/oacc-host.c
c++: Fix ICE with weird copy assignment operator [PR114572]
[thirdparty/gcc.git] / libgomp / oacc-host.c
CommitLineData
41dbbb37
TS
1/* OpenACC Runtime Library: acc_device_host.
2
a945c346 3 Copyright (C) 2013-2024 Free Software Foundation, Inc.
41dbbb37
TS
4
5 Contributed by Mentor Embedded.
6
7 This file is part of the GNU Offloading and Multi Processing Library
8 (libgomp).
9
10 Libgomp is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
13 any later version.
14
15 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 more details.
19
20 Under Section 7 of GPL version 3, you are granted additional
21 permissions described in the GCC Runtime Library Exception, version
22 3.1, as published by the Free Software Foundation.
23
24 You should have received a copy of the GNU General Public License and
25 a copy of the GCC Runtime Library Exception along with this program;
26 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
27 <http://www.gnu.org/licenses/>. */
28
b97e78b7
TS
29#include "libgomp.h"
30#include "oacc-int.h"
2a21ff19 31#include "gomp-constants.h"
b97e78b7
TS
32
33#include <stdbool.h>
34#include <stddef.h>
b97e78b7
TS
35
36static struct gomp_device_descr host_dispatch;
37
38static const char *
39host_get_name (void)
40{
41 return host_dispatch.name;
42}
43
44static unsigned int
45host_get_caps (void)
46{
47 return host_dispatch.capabilities;
48}
49
50static int
51host_get_type (void)
52{
53 return host_dispatch.type;
54}
55
56static int
683f1184 57host_get_num_devices (unsigned int omp_requires_mask __attribute__((unused)))
b97e78b7
TS
58{
59 return 1;
60}
61
6ce13072 62static bool
b97e78b7
TS
63host_init_device (int n __attribute__ ((unused)))
64{
6ce13072 65 return true;
b97e78b7
TS
66}
67
6ce13072 68static bool
b97e78b7
TS
69host_fini_device (int n __attribute__ ((unused)))
70{
6ce13072 71 return true;
b97e78b7
TS
72}
73
2a21ff19
NS
74static unsigned
75host_version (void)
76{
77 return GOMP_VERSION;
78}
79
b97e78b7
TS
80static int
81host_load_image (int n __attribute__ ((unused)),
2a21ff19 82 unsigned v __attribute__ ((unused)),
b97e78b7 83 const void *t __attribute__ ((unused)),
0fcc0cf9 84 struct addr_pair **r __attribute__ ((unused)),
a49c7d31
KCY
85 uint64_t **f __attribute__ ((unused)),
86 uint64_t *i __attribute__ ((unused)))
b97e78b7
TS
87{
88 return 0;
89}
90
6ce13072 91static bool
b97e78b7 92host_unload_image (int n __attribute__ ((unused)),
2a21ff19 93 unsigned v __attribute__ ((unused)),
b97e78b7
TS
94 const void *t __attribute__ ((unused)))
95{
6ce13072 96 return true;
b97e78b7
TS
97}
98
99static void *
100host_alloc (int n __attribute__ ((unused)), size_t s)
101{
102 return gomp_malloc (s);
103}
104
6ce13072 105static bool
b97e78b7
TS
106host_free (int n __attribute__ ((unused)), void *p)
107{
108 free (p);
6ce13072 109 return true;
b97e78b7
TS
110}
111
6ce13072 112static bool
b97e78b7
TS
113host_dev2host (int n __attribute__ ((unused)),
114 void *h __attribute__ ((unused)),
115 const void *d __attribute__ ((unused)),
116 size_t s __attribute__ ((unused)))
117{
6ce13072 118 return true;
b97e78b7
TS
119}
120
6ce13072 121static bool
b97e78b7
TS
122host_host2dev (int n __attribute__ ((unused)),
123 void *d __attribute__ ((unused)),
124 const void *h __attribute__ ((unused)),
125 size_t s __attribute__ ((unused)))
126{
6ce13072 127 return true;
b97e78b7
TS
128}
129
130static void
b2b40051
MJ
131host_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars,
132 void **args __attribute__((unused)))
b97e78b7
TS
133{
134 void (*fn)(void *) = (void (*)(void *)) fn_ptr;
135
136 fn (vars);
137}
138
139static void
140host_openacc_exec (void (*fn) (void *),
141 size_t mapnum __attribute__ ((unused)),
142 void **hostaddrs,
143 void **devaddrs __attribute__ ((unused)),
1f4c5b9b 144 unsigned *dims __attribute__ ((unused)),
b97e78b7
TS
145 void *targ_mem_desc __attribute__ ((unused)))
146{
147 fn (hostaddrs);
148}
149
150static void
1f4c5b9b
CLT
151host_openacc_async_exec (void (*fn) (void *),
152 size_t mapnum __attribute__ ((unused)),
153 void **hostaddrs,
154 void **devaddrs __attribute__ ((unused)),
155 unsigned *dims __attribute__ ((unused)),
156 void *targ_mem_desc __attribute__ ((unused)),
157 struct goacc_asyncqueue *aq __attribute__ ((unused)))
b97e78b7 158{
1f4c5b9b 159 fn (hostaddrs);
b97e78b7
TS
160}
161
162static int
1f4c5b9b 163host_openacc_async_test (struct goacc_asyncqueue *aq __attribute__ ((unused)))
b97e78b7
TS
164{
165 return 1;
166}
167
1f4c5b9b
CLT
168static bool
169host_openacc_async_synchronize (struct goacc_asyncqueue *aq
170 __attribute__ ((unused)))
b97e78b7 171{
1f4c5b9b 172 return true;
b97e78b7
TS
173}
174
1f4c5b9b
CLT
175static bool
176host_openacc_async_serialize (struct goacc_asyncqueue *aq1
177 __attribute__ ((unused)),
178 struct goacc_asyncqueue *aq2
179 __attribute__ ((unused)))
b97e78b7 180{
1f4c5b9b 181 return true;
b97e78b7
TS
182}
183
1f4c5b9b
CLT
184static bool
185host_openacc_async_host2dev (int ord __attribute__ ((unused)),
186 void *dst __attribute__ ((unused)),
187 const void *src __attribute__ ((unused)),
188 size_t n __attribute__ ((unused)),
189 struct goacc_asyncqueue *aq
190 __attribute__ ((unused)))
b97e78b7 191{
1f4c5b9b 192 return true;
b97e78b7
TS
193}
194
1f4c5b9b
CLT
195static bool
196host_openacc_async_dev2host (int ord __attribute__ ((unused)),
197 void *dst __attribute__ ((unused)),
198 const void *src __attribute__ ((unused)),
199 size_t n __attribute__ ((unused)),
200 struct goacc_asyncqueue *aq
201 __attribute__ ((unused)))
b97e78b7 202{
1f4c5b9b 203 return true;
b97e78b7
TS
204}
205
206static void
1f4c5b9b
CLT
207host_openacc_async_queue_callback (struct goacc_asyncqueue *aq
208 __attribute__ ((unused)),
209 void (*callback_fn)(void *)
210 __attribute__ ((unused)),
211 void *userptr __attribute__ ((unused)))
b97e78b7
TS
212{
213}
214
1f4c5b9b 215static struct goacc_asyncqueue *
d2903ce0 216host_openacc_async_construct (int device __attribute__((unused)))
b97e78b7 217{
1f4c5b9b
CLT
218 /* Non-NULL 0xffff... value as opaque dummy. */
219 return (struct goacc_asyncqueue *) -1;
220}
221
222static bool
223host_openacc_async_destruct (struct goacc_asyncqueue *aq
224 __attribute__ ((unused)))
225{
226 return true;
b97e78b7
TS
227}
228
6fc0385c
TS
229static union goacc_property_value
230host_openacc_get_property (int n, enum goacc_property prop)
231{
232 union goacc_property_value nullval = { .val = 0 };
233
683f1184 234 if (n >= host_get_num_devices (0))
6fc0385c
TS
235 return nullval;
236
237 switch (prop)
238 {
239 case GOACC_PROPERTY_NAME:
240 return (union goacc_property_value) { .ptr = "GOMP" };
241 case GOACC_PROPERTY_VENDOR:
242 return (union goacc_property_value) { .ptr = "GNU" };
243 case GOACC_PROPERTY_DRIVER:
244 return (union goacc_property_value) { .ptr = VERSION };
245 case GOACC_PROPERTY_MEMORY:
246 case GOACC_PROPERTY_FREE_MEMORY:
247 default:
248 return nullval;
249 }
250}
251
b97e78b7
TS
252static void *
253host_openacc_create_thread_data (int ord __attribute__ ((unused)))
254{
255 return NULL;
256}
257
258static void
259host_openacc_destroy_thread_data (void *tls_data __attribute__ ((unused)))
260{
261}
41dbbb37
TS
262
263static struct gomp_device_descr host_dispatch =
264 {
265 .name = "host",
b97e78b7 266 .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
41dbbb37 267 | GOMP_OFFLOAD_CAP_NATIVE_EXEC
b97e78b7 268 | GOMP_OFFLOAD_CAP_OPENACC_200),
41dbbb37
TS
269 .target_id = 0,
270 .type = OFFLOAD_TARGET_TYPE_HOST,
271
b97e78b7
TS
272 .get_name_func = host_get_name,
273 .get_caps_func = host_get_caps,
274 .get_type_func = host_get_type,
275 .get_num_devices_func = host_get_num_devices,
276 .init_device_func = host_init_device,
277 .fini_device_func = host_fini_device,
2a21ff19 278 .version_func = host_version,
b97e78b7
TS
279 .load_image_func = host_load_image,
280 .unload_image_func = host_unload_image,
281 .alloc_func = host_alloc,
282 .free_func = host_free,
283 .dev2host_func = host_dev2host,
284 .host2dev_func = host_host2dev,
25072a47
TB
285 .memcpy2d_func = NULL,
286 .memcpy3d_func = NULL,
b97e78b7
TS
287 .run_func = host_run,
288
289 .mem_map = { NULL },
ea4b23d9 290 .mem_map_rev = { NULL },
93d90219 291 /* .lock initialized in goacc_host_init. */
d84ffc0a 292 .state = GOMP_DEVICE_UNINITIALIZED,
41dbbb37
TS
293
294 .openacc = {
b97e78b7 295 .exec_func = host_openacc_exec,
41dbbb37 296
b97e78b7
TS
297 .create_thread_data_func = host_openacc_create_thread_data,
298 .destroy_thread_data_func = host_openacc_destroy_thread_data,
41dbbb37 299
1f4c5b9b
CLT
300 .async = {
301 .construct_func = host_openacc_async_construct,
302 .destruct_func = host_openacc_async_destruct,
303 .test_func = host_openacc_async_test,
304 .synchronize_func = host_openacc_async_synchronize,
305 .serialize_func = host_openacc_async_serialize,
306 .queue_callback_func = host_openacc_async_queue_callback,
307 .exec_func = host_openacc_async_exec,
308 .dev2host_func = host_openacc_async_dev2host,
309 .host2dev_func = host_openacc_async_host2dev,
310 },
311
6fc0385c
TS
312 .get_property_func = host_openacc_get_property,
313
41dbbb37
TS
314 .cuda = {
315 .get_current_device_func = NULL,
316 .get_current_context_func = NULL,
317 .get_stream_func = NULL,
318 .set_stream_func = NULL,
319 }
320 }
321 };
322
b97e78b7 323/* Initialize and register this device type. */
6bb4c3e2 324void
b97e78b7 325goacc_host_init (void)
41dbbb37 326{
41dbbb37
TS
327 gomp_mutex_init (&host_dispatch.lock);
328 goacc_register (&host_dispatch);
329}