Fortran: Fix non_overridable typebound proc problems [PR84674/117730].
[official-gcc.git] / libgomp / oacc-host.c
blob7d4362ebd6ce1461154897bbb91db1d6c23cecf3
1 /* OpenACC Runtime Library: acc_device_host.
3 Copyright (C) 2013-2024 Free Software Foundation, Inc.
5 Contributed by Mentor Embedded.
7 This file is part of the GNU Offloading and Multi Processing Library
8 (libgomp).
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.
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.
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.
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/>. */
29 #include "libgomp.h"
30 #include "oacc-int.h"
31 #include "gomp-constants.h"
33 #include <stdbool.h>
34 #include <stddef.h>
36 static struct gomp_device_descr host_dispatch;
38 static const char *
39 host_get_name (void)
41 return host_dispatch.name;
44 static unsigned int
45 host_get_caps (void)
47 return host_dispatch.capabilities;
50 static int
51 host_get_type (void)
53 return host_dispatch.type;
56 static int
57 host_get_num_devices (unsigned int omp_requires_mask __attribute__((unused)))
59 return 1;
62 static bool
63 host_init_device (int n __attribute__ ((unused)))
65 return true;
68 static bool
69 host_fini_device (int n __attribute__ ((unused)))
71 return true;
74 static unsigned
75 host_version (void)
77 return GOMP_VERSION;
80 static int
81 host_load_image (int n __attribute__ ((unused)),
82 unsigned v __attribute__ ((unused)),
83 const void *t __attribute__ ((unused)),
84 struct addr_pair **r __attribute__ ((unused)),
85 uint64_t **f __attribute__ ((unused)),
86 uint64_t *i __attribute__ ((unused)))
88 return 0;
91 static bool
92 host_unload_image (int n __attribute__ ((unused)),
93 unsigned v __attribute__ ((unused)),
94 const void *t __attribute__ ((unused)))
96 return true;
99 static void *
100 host_alloc (int n __attribute__ ((unused)), size_t s)
102 return gomp_malloc (s);
105 static bool
106 host_free (int n __attribute__ ((unused)), void *p)
108 free (p);
109 return true;
112 static bool
113 host_dev2host (int n __attribute__ ((unused)),
114 void *h __attribute__ ((unused)),
115 const void *d __attribute__ ((unused)),
116 size_t s __attribute__ ((unused)))
118 return true;
121 static bool
122 host_host2dev (int n __attribute__ ((unused)),
123 void *d __attribute__ ((unused)),
124 const void *h __attribute__ ((unused)),
125 size_t s __attribute__ ((unused)))
127 return true;
130 static void
131 host_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars,
132 void **args __attribute__((unused)))
134 void (*fn)(void *) = (void (*)(void *)) fn_ptr;
136 fn (vars);
139 static void
140 host_openacc_exec (void (*fn) (void *),
141 size_t mapnum __attribute__ ((unused)),
142 void **hostaddrs,
143 void **devaddrs __attribute__ ((unused)),
144 unsigned *dims __attribute__ ((unused)),
145 void *targ_mem_desc __attribute__ ((unused)))
147 fn (hostaddrs);
150 static void
151 host_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)))
159 fn (hostaddrs);
162 static int
163 host_openacc_async_test (struct goacc_asyncqueue *aq __attribute__ ((unused)))
165 return 1;
168 static bool
169 host_openacc_async_synchronize (struct goacc_asyncqueue *aq
170 __attribute__ ((unused)))
172 return true;
175 static bool
176 host_openacc_async_serialize (struct goacc_asyncqueue *aq1
177 __attribute__ ((unused)),
178 struct goacc_asyncqueue *aq2
179 __attribute__ ((unused)))
181 return true;
184 static bool
185 host_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)))
192 return true;
195 static bool
196 host_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)))
203 return true;
206 static void
207 host_openacc_async_queue_callback (struct goacc_asyncqueue *aq
208 __attribute__ ((unused)),
209 void (*callback_fn)(void *)
210 __attribute__ ((unused)),
211 void *userptr __attribute__ ((unused)))
215 static struct goacc_asyncqueue *
216 host_openacc_async_construct (int device __attribute__((unused)))
218 /* Non-NULL 0xffff... value as opaque dummy. */
219 return (struct goacc_asyncqueue *) -1;
222 static bool
223 host_openacc_async_destruct (struct goacc_asyncqueue *aq
224 __attribute__ ((unused)))
226 return true;
229 static union goacc_property_value
230 host_openacc_get_property (int n, enum goacc_property prop)
232 union goacc_property_value nullval = { .val = 0 };
234 if (n >= host_get_num_devices (0))
235 return nullval;
237 switch (prop)
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;
252 static void *
253 host_openacc_create_thread_data (int ord __attribute__ ((unused)))
255 return NULL;
258 static void
259 host_openacc_destroy_thread_data (void *tls_data __attribute__ ((unused)))
263 static struct gomp_device_descr host_dispatch =
265 .name = "host",
266 .uid = NULL,
267 .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
268 | GOMP_OFFLOAD_CAP_NATIVE_EXEC
269 | GOMP_OFFLOAD_CAP_OPENACC_200),
270 .target_id = 0,
271 .type = OFFLOAD_TARGET_TYPE_HOST,
273 .get_name_func = host_get_name,
274 .get_uid_func = NULL,
275 .get_caps_func = host_get_caps,
276 .get_type_func = host_get_type,
277 .get_num_devices_func = host_get_num_devices,
278 .init_device_func = host_init_device,
279 .fini_device_func = host_fini_device,
280 .version_func = host_version,
281 .load_image_func = host_load_image,
282 .unload_image_func = host_unload_image,
283 .alloc_func = host_alloc,
284 .free_func = host_free,
285 .dev2host_func = host_dev2host,
286 .host2dev_func = host_host2dev,
287 .memcpy2d_func = NULL,
288 .memcpy3d_func = NULL,
289 .run_func = host_run,
291 .mem_map = { NULL },
292 .mem_map_rev = { NULL },
293 /* .lock initialized in goacc_host_init. */
294 .state = GOMP_DEVICE_UNINITIALIZED,
296 .openacc = {
297 .exec_func = host_openacc_exec,
299 .create_thread_data_func = host_openacc_create_thread_data,
300 .destroy_thread_data_func = host_openacc_destroy_thread_data,
302 .async = {
303 .construct_func = host_openacc_async_construct,
304 .destruct_func = host_openacc_async_destruct,
305 .test_func = host_openacc_async_test,
306 .synchronize_func = host_openacc_async_synchronize,
307 .serialize_func = host_openacc_async_serialize,
308 .queue_callback_func = host_openacc_async_queue_callback,
309 .exec_func = host_openacc_async_exec,
310 .dev2host_func = host_openacc_async_dev2host,
311 .host2dev_func = host_openacc_async_host2dev,
314 .get_property_func = host_openacc_get_property,
316 .cuda = {
317 .get_current_device_func = NULL,
318 .get_current_context_func = NULL,
319 .get_stream_func = NULL,
320 .set_stream_func = NULL,
325 /* Initialize and register this device type. */
326 void
327 goacc_host_init (void)
329 gomp_mutex_init (&host_dispatch.lock);
330 goacc_register (&host_dispatch);