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