Update 'Q' constraint documentation.
[official-gcc.git] / libgomp / oacc-host.c
blob22c18942752e6690f8e21dddba7752d7d231d6d8
1 /* OpenACC Runtime Library: acc_device_host.
3 Copyright (C) 2013-2020 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 (void)
59 return 1;
62 static union gomp_device_property_value
63 host_get_property (int n, int prop)
65 union gomp_device_property_value nullval = { .val = 0 };
67 if (n >= host_get_num_devices ())
68 return nullval;
70 switch (prop)
72 case GOMP_DEVICE_PROPERTY_NAME:
73 return (union gomp_device_property_value) { .ptr = "GOMP" };
74 case GOMP_DEVICE_PROPERTY_VENDOR:
75 return (union gomp_device_property_value) { .ptr = "GNU" };
76 case GOMP_DEVICE_PROPERTY_DRIVER:
77 return (union gomp_device_property_value) { .ptr = VERSION };
78 default:
79 return nullval;
83 static bool
84 host_init_device (int n __attribute__ ((unused)))
86 return true;
89 static bool
90 host_fini_device (int n __attribute__ ((unused)))
92 return true;
95 static unsigned
96 host_version (void)
98 return GOMP_VERSION;
101 static int
102 host_load_image (int n __attribute__ ((unused)),
103 unsigned v __attribute__ ((unused)),
104 const void *t __attribute__ ((unused)),
105 struct addr_pair **r __attribute__ ((unused)))
107 return 0;
110 static bool
111 host_unload_image (int n __attribute__ ((unused)),
112 unsigned v __attribute__ ((unused)),
113 const void *t __attribute__ ((unused)))
115 return true;
118 static void *
119 host_alloc (int n __attribute__ ((unused)), size_t s)
121 return gomp_malloc (s);
124 static bool
125 host_free (int n __attribute__ ((unused)), void *p)
127 free (p);
128 return true;
131 static bool
132 host_dev2host (int n __attribute__ ((unused)),
133 void *h __attribute__ ((unused)),
134 const void *d __attribute__ ((unused)),
135 size_t s __attribute__ ((unused)))
137 return true;
140 static bool
141 host_host2dev (int n __attribute__ ((unused)),
142 void *d __attribute__ ((unused)),
143 const void *h __attribute__ ((unused)),
144 size_t s __attribute__ ((unused)))
146 return true;
149 static void
150 host_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars,
151 void **args __attribute__((unused)))
153 void (*fn)(void *) = (void (*)(void *)) fn_ptr;
155 fn (vars);
158 static void
159 host_openacc_exec (void (*fn) (void *),
160 size_t mapnum __attribute__ ((unused)),
161 void **hostaddrs,
162 void **devaddrs __attribute__ ((unused)),
163 unsigned *dims __attribute__ ((unused)),
164 void *targ_mem_desc __attribute__ ((unused)))
166 fn (hostaddrs);
169 static void
170 host_openacc_async_exec (void (*fn) (void *),
171 size_t mapnum __attribute__ ((unused)),
172 void **hostaddrs,
173 void **devaddrs __attribute__ ((unused)),
174 unsigned *dims __attribute__ ((unused)),
175 void *targ_mem_desc __attribute__ ((unused)),
176 struct goacc_asyncqueue *aq __attribute__ ((unused)))
178 fn (hostaddrs);
181 static int
182 host_openacc_async_test (struct goacc_asyncqueue *aq __attribute__ ((unused)))
184 return 1;
187 static bool
188 host_openacc_async_synchronize (struct goacc_asyncqueue *aq
189 __attribute__ ((unused)))
191 return true;
194 static bool
195 host_openacc_async_serialize (struct goacc_asyncqueue *aq1
196 __attribute__ ((unused)),
197 struct goacc_asyncqueue *aq2
198 __attribute__ ((unused)))
200 return true;
203 static bool
204 host_openacc_async_host2dev (int ord __attribute__ ((unused)),
205 void *dst __attribute__ ((unused)),
206 const void *src __attribute__ ((unused)),
207 size_t n __attribute__ ((unused)),
208 struct goacc_asyncqueue *aq
209 __attribute__ ((unused)))
211 return true;
214 static bool
215 host_openacc_async_dev2host (int ord __attribute__ ((unused)),
216 void *dst __attribute__ ((unused)),
217 const void *src __attribute__ ((unused)),
218 size_t n __attribute__ ((unused)),
219 struct goacc_asyncqueue *aq
220 __attribute__ ((unused)))
222 return true;
225 static void
226 host_openacc_async_queue_callback (struct goacc_asyncqueue *aq
227 __attribute__ ((unused)),
228 void (*callback_fn)(void *)
229 __attribute__ ((unused)),
230 void *userptr __attribute__ ((unused)))
234 static struct goacc_asyncqueue *
235 host_openacc_async_construct (int device __attribute__((unused)))
237 /* Non-NULL 0xffff... value as opaque dummy. */
238 return (struct goacc_asyncqueue *) -1;
241 static bool
242 host_openacc_async_destruct (struct goacc_asyncqueue *aq
243 __attribute__ ((unused)))
245 return true;
248 static void *
249 host_openacc_create_thread_data (int ord __attribute__ ((unused)))
251 return NULL;
254 static void
255 host_openacc_destroy_thread_data (void *tls_data __attribute__ ((unused)))
259 static struct gomp_device_descr host_dispatch =
261 .name = "host",
262 .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
263 | GOMP_OFFLOAD_CAP_NATIVE_EXEC
264 | GOMP_OFFLOAD_CAP_OPENACC_200),
265 .target_id = 0,
266 .type = OFFLOAD_TARGET_TYPE_HOST,
268 .get_name_func = host_get_name,
269 .get_caps_func = host_get_caps,
270 .get_type_func = host_get_type,
271 .get_num_devices_func = host_get_num_devices,
272 .get_property_func = host_get_property,
273 .init_device_func = host_init_device,
274 .fini_device_func = host_fini_device,
275 .version_func = host_version,
276 .load_image_func = host_load_image,
277 .unload_image_func = host_unload_image,
278 .alloc_func = host_alloc,
279 .free_func = host_free,
280 .dev2host_func = host_dev2host,
281 .host2dev_func = host_host2dev,
282 .run_func = host_run,
284 .mem_map = { NULL },
285 /* .lock initialized in goacc_host_init. */
286 .state = GOMP_DEVICE_UNINITIALIZED,
288 .openacc = {
289 .exec_func = host_openacc_exec,
291 .create_thread_data_func = host_openacc_create_thread_data,
292 .destroy_thread_data_func = host_openacc_destroy_thread_data,
294 .async = {
295 .construct_func = host_openacc_async_construct,
296 .destruct_func = host_openacc_async_destruct,
297 .test_func = host_openacc_async_test,
298 .synchronize_func = host_openacc_async_synchronize,
299 .serialize_func = host_openacc_async_serialize,
300 .queue_callback_func = host_openacc_async_queue_callback,
301 .exec_func = host_openacc_async_exec,
302 .dev2host_func = host_openacc_async_dev2host,
303 .host2dev_func = host_openacc_async_host2dev,
306 .cuda = {
307 .get_current_device_func = NULL,
308 .get_current_context_func = NULL,
309 .get_stream_func = NULL,
310 .set_stream_func = NULL,
315 /* Initialize and register this device type. */
316 void
317 goacc_host_init (void)
319 gomp_mutex_init (&host_dispatch.lock);
320 goacc_register (&host_dispatch);