oacc-host.c revision 1.1.1.5
1/* OpenACC Runtime Library: acc_device_host.
2
3   Copyright (C) 2013-2017 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#include "libgomp.h"
30#include "oacc-int.h"
31#include "gomp-constants.h"
32
33#include <stdbool.h>
34#include <stddef.h>
35#include <stdint.h>
36
37static struct gomp_device_descr host_dispatch;
38
39static const char *
40host_get_name (void)
41{
42  return host_dispatch.name;
43}
44
45static unsigned int
46host_get_caps (void)
47{
48  return host_dispatch.capabilities;
49}
50
51static int
52host_get_type (void)
53{
54  return host_dispatch.type;
55}
56
57static int
58host_get_num_devices (void)
59{
60  return 1;
61}
62
63static bool
64host_init_device (int n __attribute__ ((unused)))
65{
66  return true;
67}
68
69static bool
70host_fini_device (int n __attribute__ ((unused)))
71{
72  return true;
73}
74
75static unsigned
76host_version (void)
77{
78  return GOMP_VERSION;
79}
80
81static int
82host_load_image (int n __attribute__ ((unused)),
83		 unsigned v __attribute__ ((unused)),
84		 const void *t __attribute__ ((unused)),
85		 struct addr_pair **r __attribute__ ((unused)))
86{
87  return 0;
88}
89
90static bool
91host_unload_image (int n __attribute__ ((unused)),
92		   unsigned v __attribute__ ((unused)),
93		   const void *t __attribute__ ((unused)))
94{
95  return true;
96}
97
98static void *
99host_alloc (int n __attribute__ ((unused)), size_t s)
100{
101  return gomp_malloc (s);
102}
103
104static bool
105host_free (int n __attribute__ ((unused)), void *p)
106{
107  free (p);
108  return true;
109}
110
111static bool
112host_dev2host (int n __attribute__ ((unused)),
113	       void *h __attribute__ ((unused)),
114	       const void *d __attribute__ ((unused)),
115	       size_t s __attribute__ ((unused)))
116{
117  return true;
118}
119
120static bool
121host_host2dev (int n __attribute__ ((unused)),
122	       void *d __attribute__ ((unused)),
123	       const void *h __attribute__ ((unused)),
124	       size_t s __attribute__ ((unused)))
125{
126  return true;
127}
128
129static void
130host_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars,
131	  void **args __attribute__((unused)))
132{
133  void (*fn)(void *) = (void (*)(void *)) fn_ptr;
134
135  fn (vars);
136}
137
138static void
139host_openacc_exec (void (*fn) (void *),
140		   size_t mapnum __attribute__ ((unused)),
141		   void **hostaddrs,
142		   void **devaddrs __attribute__ ((unused)),
143		   int async __attribute__ ((unused)),
144		   unsigned *dims __attribute ((unused)),
145		   void *targ_mem_desc __attribute__ ((unused)))
146{
147  fn (hostaddrs);
148}
149
150static void
151host_openacc_register_async_cleanup (void *targ_mem_desc __attribute__ ((unused)),
152				     int async __attribute__ ((unused)))
153{
154}
155
156static int
157host_openacc_async_test (int async __attribute__ ((unused)))
158{
159  return 1;
160}
161
162static int
163host_openacc_async_test_all (void)
164{
165  return 1;
166}
167
168static void
169host_openacc_async_wait (int async __attribute__ ((unused)))
170{
171}
172
173static void
174host_openacc_async_wait_async (int async1 __attribute__ ((unused)),
175			       int async2 __attribute__ ((unused)))
176{
177}
178
179static void
180host_openacc_async_wait_all (void)
181{
182}
183
184static void
185host_openacc_async_wait_all_async (int async __attribute__ ((unused)))
186{
187}
188
189static void
190host_openacc_async_set_async (int async __attribute__ ((unused)))
191{
192}
193
194static void *
195host_openacc_create_thread_data (int ord __attribute__ ((unused)))
196{
197  return NULL;
198}
199
200static void
201host_openacc_destroy_thread_data (void *tls_data __attribute__ ((unused)))
202{
203}
204
205static struct gomp_device_descr host_dispatch =
206  {
207    .name = "host",
208    .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
209		     | GOMP_OFFLOAD_CAP_NATIVE_EXEC
210		     | GOMP_OFFLOAD_CAP_OPENACC_200),
211    .target_id = 0,
212    .type = OFFLOAD_TARGET_TYPE_HOST,
213
214    .get_name_func = host_get_name,
215    .get_caps_func = host_get_caps,
216    .get_type_func = host_get_type,
217    .get_num_devices_func = host_get_num_devices,
218    .init_device_func = host_init_device,
219    .fini_device_func = host_fini_device,
220    .version_func = host_version,
221    .load_image_func = host_load_image,
222    .unload_image_func = host_unload_image,
223    .alloc_func = host_alloc,
224    .free_func = host_free,
225    .dev2host_func = host_dev2host,
226    .host2dev_func = host_host2dev,
227    .run_func = host_run,
228
229    .mem_map = { NULL },
230    /* .lock initilized in goacc_host_init.  */
231    .state = GOMP_DEVICE_UNINITIALIZED,
232
233    .openacc = {
234      .data_environ = NULL,
235
236      .exec_func = host_openacc_exec,
237
238      .register_async_cleanup_func = host_openacc_register_async_cleanup,
239
240      .async_test_func = host_openacc_async_test,
241      .async_test_all_func = host_openacc_async_test_all,
242      .async_wait_func = host_openacc_async_wait,
243      .async_wait_async_func = host_openacc_async_wait_async,
244      .async_wait_all_func = host_openacc_async_wait_all,
245      .async_wait_all_async_func = host_openacc_async_wait_all_async,
246      .async_set_async_func = host_openacc_async_set_async,
247
248      .create_thread_data_func = host_openacc_create_thread_data,
249      .destroy_thread_data_func = host_openacc_destroy_thread_data,
250
251      .cuda = {
252	.get_current_device_func = NULL,
253	.get_current_context_func = NULL,
254	.get_stream_func = NULL,
255	.set_stream_func = NULL,
256      }
257    }
258  };
259
260/* Initialize and register this device type.  */
261void
262goacc_host_init (void)
263{
264  gomp_mutex_init (&host_dispatch.lock);
265  goacc_register (&host_dispatch);
266}
267