]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgomp/plugin/plugin-host.c
libgomp: rework initialization of offloading
[thirdparty/gcc.git] / libgomp / plugin / plugin-host.c
CommitLineData
41dbbb37
TS
1/* OpenACC Runtime Library: acc_device_host, acc_device_host_nonshm.
2
3 Copyright (C) 2013-2015 Free Software Foundation, Inc.
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
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. */
32
33#include "openacc.h"
34#include "config.h"
35#ifdef HOST_NONSHM_PLUGIN
36#include "libgomp-plugin.h"
37#include "oacc-plugin.h"
38#else
39#include "libgomp.h"
40#include "oacc-int.h"
41#endif
42
43#include <stdint.h>
44#include <stdlib.h>
45#include <string.h>
46#include <stdio.h>
47
48#ifdef HOST_NONSHM_PLUGIN
49#define STATIC
50#define GOMP(X) GOMP_PLUGIN_##X
51#define SELF "host_nonshm plugin: "
52#else
53#define STATIC static
54#define GOMP(X) gomp_##X
55#define SELF "host: "
56#endif
57
58STATIC const char *
59GOMP_OFFLOAD_get_name (void)
60{
61#ifdef HOST_NONSHM_PLUGIN
62 return "host_nonshm";
63#else
64 return "host";
65#endif
66}
67
68STATIC unsigned int
69GOMP_OFFLOAD_get_caps (void)
70{
71 unsigned int caps = (GOMP_OFFLOAD_CAP_OPENACC_200
72 | GOMP_OFFLOAD_CAP_NATIVE_EXEC);
73
74#ifndef HOST_NONSHM_PLUGIN
75 caps |= GOMP_OFFLOAD_CAP_SHARED_MEM;
76#endif
77
78 return caps;
79}
80
81STATIC int
82GOMP_OFFLOAD_get_type (void)
83{
84#ifdef HOST_NONSHM_PLUGIN
85 return OFFLOAD_TARGET_TYPE_HOST_NONSHM;
86#else
87 return OFFLOAD_TARGET_TYPE_HOST;
88#endif
89}
90
91STATIC int
92GOMP_OFFLOAD_get_num_devices (void)
93{
94 return 1;
95}
96
41dbbb37
TS
97STATIC void
98GOMP_OFFLOAD_init_device (int n __attribute__ ((unused)))
99{
100}
101
102STATIC void
103GOMP_OFFLOAD_fini_device (int n __attribute__ ((unused)))
104{
105}
106
107STATIC int
a51df54e
IV
108GOMP_OFFLOAD_load_image (int n __attribute__ ((unused)),
109 void *i __attribute__ ((unused)),
110 struct addr_pair **r __attribute__ ((unused)))
41dbbb37
TS
111{
112 return 0;
113}
114
a51df54e
IV
115STATIC void
116GOMP_OFFLOAD_unload_image (int n __attribute__ ((unused)),
117 void *i __attribute__ ((unused)))
118{
119}
120
41dbbb37
TS
121STATIC void *
122GOMP_OFFLOAD_openacc_open_device (int n)
123{
124 return (void *) (intptr_t) n;
125}
126
127STATIC int
128GOMP_OFFLOAD_openacc_close_device (void *hnd)
129{
130 return 0;
131}
132
133STATIC int
134GOMP_OFFLOAD_openacc_get_device_num (void)
135{
136 return 0;
137}
138
139STATIC void
140GOMP_OFFLOAD_openacc_set_device_num (int n)
141{
142 if (n > 0)
143 GOMP (fatal) ("device number %u out of range for host execution", n);
144}
145
146STATIC void *
147GOMP_OFFLOAD_alloc (int n __attribute__ ((unused)), size_t s)
148{
149 return GOMP (malloc) (s);
150}
151
152STATIC void
153GOMP_OFFLOAD_free (int n __attribute__ ((unused)), void *p)
154{
155 free (p);
156}
157
158STATIC void *
159GOMP_OFFLOAD_host2dev (int n __attribute__ ((unused)), void *d, const void *h,
160 size_t s)
161{
162#ifdef HOST_NONSHM_PLUGIN
163 memcpy (d, h, s);
164#endif
165
166 return 0;
167}
168
169STATIC void *
170GOMP_OFFLOAD_dev2host (int n __attribute__ ((unused)), void *h, const void *d,
171 size_t s)
172{
173#ifdef HOST_NONSHM_PLUGIN
174 memcpy (h, d, s);
175#endif
176
177 return 0;
178}
179
180STATIC void
181GOMP_OFFLOAD_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars)
182{
183 void (*fn)(void *) = (void (*)(void *)) fn_ptr;
184
185 fn (vars);
186}
187
188STATIC void
189GOMP_OFFLOAD_openacc_parallel (void (*fn) (void *),
190 size_t mapnum __attribute__ ((unused)),
191 void **hostaddrs __attribute__ ((unused)),
192 void **devaddrs __attribute__ ((unused)),
193 size_t *sizes __attribute__ ((unused)),
194 unsigned short *kinds __attribute__ ((unused)),
195 int num_gangs __attribute__ ((unused)),
196 int num_workers __attribute__ ((unused)),
197 int vector_length __attribute__ ((unused)),
198 int async __attribute__ ((unused)),
199 void *targ_mem_desc __attribute__ ((unused)))
200{
201#ifdef HOST_NONSHM_PLUGIN
202 fn (devaddrs);
203#else
204 fn (hostaddrs);
205#endif
206}
207
208STATIC void
209GOMP_OFFLOAD_openacc_register_async_cleanup (void *targ_mem_desc)
210{
211#ifdef HOST_NONSHM_PLUGIN
212 /* "Asynchronous" launches are executed synchronously on the (non-SHM) host,
213 so there's no point in delaying host-side cleanup -- just do it now. */
214 GOMP_PLUGIN_async_unmap_vars (targ_mem_desc);
215#endif
216}
217
218STATIC void
219GOMP_OFFLOAD_openacc_async_set_async (int async __attribute__ ((unused)))
220{
221}
222
223STATIC int
224GOMP_OFFLOAD_openacc_async_test (int async __attribute__ ((unused)))
225{
226 return 1;
227}
228
229STATIC int
230GOMP_OFFLOAD_openacc_async_test_all (void)
231{
232 return 1;
233}
234
235STATIC void
236GOMP_OFFLOAD_openacc_async_wait (int async __attribute__ ((unused)))
237{
238}
239
240STATIC void
241GOMP_OFFLOAD_openacc_async_wait_all (void)
242{
243}
244
245STATIC void
246GOMP_OFFLOAD_openacc_async_wait_async (int async1 __attribute__ ((unused)),
247 int async2 __attribute__ ((unused)))
248{
249}
250
251STATIC void
252GOMP_OFFLOAD_openacc_async_wait_all_async (int async __attribute__ ((unused)))
253{
254}
255
256STATIC void *
257GOMP_OFFLOAD_openacc_create_thread_data (void *targ_data
258 __attribute__ ((unused)))
259{
260 return NULL;
261}
262
263STATIC void
264GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data
265 __attribute__ ((unused)))
266{
267}