Support for OpenACC acc_on_device in offloading configurations.
[official-gcc.git] / libgomp / plugin / plugin-host.c
blob8bca9980f5a74c4ed89de1f2b9f90e99a0d7b538
1 /* OpenACC Runtime Library: acc_device_host, acc_device_host_nonshm.
3 Copyright (C) 2013-2014 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 /* Simple implementation of support routines for a shared-memory
30 acc_device_host, and a non-shared memory acc_device_host_nonshm, with the
31 latter built as a plugin. */
33 #include "openacc.h"
34 #include "config.h"
35 #include "libgomp.h"
36 #include "libgomp_target.h"
37 #ifdef HOST_NONSHM_PLUGIN
38 #include "libgomp-plugin.h"
39 #include "oacc-plugin.h"
40 #else
41 #include "oacc-int.h"
42 #endif
44 #include <stdint.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <stdio.h>
49 #ifdef HOST_NONSHM_PLUGIN
50 #define STATIC
51 #define GOMP(X) GOMP_PLUGIN_##X
52 #define SELF "host_nonshm plugin: "
53 #else
54 #define STATIC static
55 #define GOMP(X) gomp_##X
56 #define SELF "host: "
57 #endif
59 #ifndef HOST_NONSHM_PLUGIN
60 static struct gomp_device_descr host_dispatch;
61 #endif
63 STATIC const char *
64 GOMP_OFFLOAD_get_name (void)
66 #ifdef HOST_NONSHM_PLUGIN
67 return "host_nonshm";
68 #else
69 return "host";
70 #endif
73 STATIC int
74 GOMP_OFFLOAD_get_type (void)
76 #ifdef HOST_NONSHM_PLUGIN
77 return OFFLOAD_TARGET_TYPE_HOST_NONSHM;
78 #else
79 return OFFLOAD_TARGET_TYPE_HOST;
80 #endif
83 STATIC unsigned int
84 GOMP_OFFLOAD_get_caps (void)
86 unsigned int caps = TARGET_CAP_OPENACC_200 | TARGET_CAP_NATIVE_EXEC;
88 #ifndef HOST_NONSHM_PLUGIN
89 caps |= TARGET_CAP_SHARED_MEM;
90 #endif
92 return caps;
95 STATIC int
96 GOMP_OFFLOAD_get_num_devices (void)
98 return 1;
101 STATIC void
102 GOMP_OFFLOAD_register_image (void *host_table __attribute__((unused)),
103 void *target_data __attribute__((unused)))
107 STATIC void
108 GOMP_OFFLOAD_init_device (int n __attribute__((unused)))
112 STATIC void
113 GOMP_OFFLOAD_fini_device (int n __attribute__((unused)))
117 STATIC int
118 GOMP_OFFLOAD_get_table (int n __attribute__((unused)),
119 struct mapping_table **table __attribute__((unused)))
121 return 0;
124 STATIC void *
125 GOMP_OFFLOAD_openacc_open_device (int n)
127 return (void *) (intptr_t) n;
130 STATIC int
131 GOMP_OFFLOAD_openacc_close_device (void *hnd)
133 return 0;
136 STATIC int
137 GOMP_OFFLOAD_openacc_get_device_num (void)
139 return 0;
142 STATIC void
143 GOMP_OFFLOAD_openacc_set_device_num (int n)
145 if (n > 0)
146 GOMP(fatal) ("device number %u out of range for host execution", n);
149 STATIC void *
150 GOMP_OFFLOAD_alloc (int n __attribute__((unused)), size_t s)
152 return GOMP(malloc) (s);
155 STATIC void
156 GOMP_OFFLOAD_free (int n __attribute__((unused)), void *p)
158 free (p);
161 STATIC void *
162 GOMP_OFFLOAD_host2dev (int n __attribute__((unused)), void *d, const void *h,
163 size_t s)
165 #ifdef HOST_NONSHM_PLUGIN
166 memcpy (d, h, s);
167 #endif
169 return 0;
172 STATIC void *
173 GOMP_OFFLOAD_dev2host (int n __attribute__((unused)), void *h, const void *d,
174 size_t s)
176 #ifdef HOST_NONSHM_PLUGIN
177 memcpy (h, d, s);
178 #endif
180 return 0;
183 STATIC void
184 GOMP_OFFLOAD_run (int n __attribute__((unused)), void *fn_ptr, void *vars)
186 void (*fn)(void *) = (void (*)(void *)) fn_ptr;
188 fn (vars);
191 STATIC void
192 GOMP_OFFLOAD_openacc_parallel (void (*fn) (void *),
193 size_t mapnum __attribute__((unused)),
194 void **hostaddrs __attribute__((unused)),
195 void **devaddrs __attribute__((unused)),
196 size_t *sizes __attribute__((unused)),
197 unsigned short *kinds __attribute__((unused)),
198 int num_gangs __attribute__((unused)),
199 int num_workers __attribute__((unused)),
200 int vector_length __attribute__((unused)),
201 int async __attribute__((unused)),
202 void *targ_mem_desc __attribute__((unused)))
204 #ifdef HOST_NONSHM_PLUGIN
205 fn (devaddrs);
206 #else
207 fn (hostaddrs);
208 #endif
211 STATIC void
212 GOMP_OFFLOAD_openacc_register_async_cleanup (void *targ_mem_desc)
214 #ifdef HOST_NONSHM_PLUGIN
215 /* "Asynchronous" launches are executed synchronously on the (non-SHM) host,
216 so there's no point in delaying host-side cleanup -- just do it now. */
217 GOMP_PLUGIN_async_unmap_vars (targ_mem_desc);
218 #endif
221 STATIC void
222 GOMP_OFFLOAD_openacc_async_set_async (int async __attribute__((unused)))
226 STATIC int
227 GOMP_OFFLOAD_openacc_async_test (int async __attribute__((unused)))
229 return 1;
232 STATIC int
233 GOMP_OFFLOAD_openacc_async_test_all (void)
235 return 1;
238 STATIC void
239 GOMP_OFFLOAD_openacc_async_wait (int async __attribute__((unused)))
243 STATIC void
244 GOMP_OFFLOAD_openacc_async_wait_all (void)
248 STATIC void
249 GOMP_OFFLOAD_openacc_async_wait_async (int async1 __attribute__((unused)),
250 int async2 __attribute__((unused)))
254 STATIC void
255 GOMP_OFFLOAD_openacc_async_wait_all_async (int async __attribute__((unused)))
259 STATIC void *
260 GOMP_OFFLOAD_openacc_create_thread_data (void *targ_data
261 __attribute__((unused)))
263 return NULL;
266 STATIC void
267 GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data
268 __attribute__((unused)))