1*38fd1498Szrj /* OpenACC Runtime Library: acc_device_host.
2*38fd1498Szrj
3*38fd1498Szrj Copyright (C) 2013-2018 Free Software Foundation, Inc.
4*38fd1498Szrj
5*38fd1498Szrj Contributed by Mentor Embedded.
6*38fd1498Szrj
7*38fd1498Szrj This file is part of the GNU Offloading and Multi Processing Library
8*38fd1498Szrj (libgomp).
9*38fd1498Szrj
10*38fd1498Szrj Libgomp is free software; you can redistribute it and/or modify it
11*38fd1498Szrj under the terms of the GNU General Public License as published by
12*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
13*38fd1498Szrj any later version.
14*38fd1498Szrj
15*38fd1498Szrj Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
16*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17*38fd1498Szrj FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18*38fd1498Szrj more details.
19*38fd1498Szrj
20*38fd1498Szrj Under Section 7 of GPL version 3, you are granted additional
21*38fd1498Szrj permissions described in the GCC Runtime Library Exception, version
22*38fd1498Szrj 3.1, as published by the Free Software Foundation.
23*38fd1498Szrj
24*38fd1498Szrj You should have received a copy of the GNU General Public License and
25*38fd1498Szrj a copy of the GCC Runtime Library Exception along with this program;
26*38fd1498Szrj see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
27*38fd1498Szrj <http://www.gnu.org/licenses/>. */
28*38fd1498Szrj
29*38fd1498Szrj #include "libgomp.h"
30*38fd1498Szrj #include "oacc-int.h"
31*38fd1498Szrj #include "gomp-constants.h"
32*38fd1498Szrj
33*38fd1498Szrj #include <stdbool.h>
34*38fd1498Szrj #include <stddef.h>
35*38fd1498Szrj #include <stdint.h>
36*38fd1498Szrj
37*38fd1498Szrj static struct gomp_device_descr host_dispatch;
38*38fd1498Szrj
39*38fd1498Szrj static const char *
host_get_name(void)40*38fd1498Szrj host_get_name (void)
41*38fd1498Szrj {
42*38fd1498Szrj return host_dispatch.name;
43*38fd1498Szrj }
44*38fd1498Szrj
45*38fd1498Szrj static unsigned int
host_get_caps(void)46*38fd1498Szrj host_get_caps (void)
47*38fd1498Szrj {
48*38fd1498Szrj return host_dispatch.capabilities;
49*38fd1498Szrj }
50*38fd1498Szrj
51*38fd1498Szrj static int
host_get_type(void)52*38fd1498Szrj host_get_type (void)
53*38fd1498Szrj {
54*38fd1498Szrj return host_dispatch.type;
55*38fd1498Szrj }
56*38fd1498Szrj
57*38fd1498Szrj static int
host_get_num_devices(void)58*38fd1498Szrj host_get_num_devices (void)
59*38fd1498Szrj {
60*38fd1498Szrj return 1;
61*38fd1498Szrj }
62*38fd1498Szrj
63*38fd1498Szrj static bool
host_init_device(int n)64*38fd1498Szrj host_init_device (int n __attribute__ ((unused)))
65*38fd1498Szrj {
66*38fd1498Szrj return true;
67*38fd1498Szrj }
68*38fd1498Szrj
69*38fd1498Szrj static bool
host_fini_device(int n)70*38fd1498Szrj host_fini_device (int n __attribute__ ((unused)))
71*38fd1498Szrj {
72*38fd1498Szrj return true;
73*38fd1498Szrj }
74*38fd1498Szrj
75*38fd1498Szrj static unsigned
host_version(void)76*38fd1498Szrj host_version (void)
77*38fd1498Szrj {
78*38fd1498Szrj return GOMP_VERSION;
79*38fd1498Szrj }
80*38fd1498Szrj
81*38fd1498Szrj static int
host_load_image(int n,unsigned v,const void * t,struct addr_pair ** r)82*38fd1498Szrj host_load_image (int n __attribute__ ((unused)),
83*38fd1498Szrj unsigned v __attribute__ ((unused)),
84*38fd1498Szrj const void *t __attribute__ ((unused)),
85*38fd1498Szrj struct addr_pair **r __attribute__ ((unused)))
86*38fd1498Szrj {
87*38fd1498Szrj return 0;
88*38fd1498Szrj }
89*38fd1498Szrj
90*38fd1498Szrj static bool
host_unload_image(int n,unsigned v,const void * t)91*38fd1498Szrj host_unload_image (int n __attribute__ ((unused)),
92*38fd1498Szrj unsigned v __attribute__ ((unused)),
93*38fd1498Szrj const void *t __attribute__ ((unused)))
94*38fd1498Szrj {
95*38fd1498Szrj return true;
96*38fd1498Szrj }
97*38fd1498Szrj
98*38fd1498Szrj static void *
host_alloc(int n,size_t s)99*38fd1498Szrj host_alloc (int n __attribute__ ((unused)), size_t s)
100*38fd1498Szrj {
101*38fd1498Szrj return gomp_malloc (s);
102*38fd1498Szrj }
103*38fd1498Szrj
104*38fd1498Szrj static bool
host_free(int n,void * p)105*38fd1498Szrj host_free (int n __attribute__ ((unused)), void *p)
106*38fd1498Szrj {
107*38fd1498Szrj free (p);
108*38fd1498Szrj return true;
109*38fd1498Szrj }
110*38fd1498Szrj
111*38fd1498Szrj static bool
host_dev2host(int n,void * h,const void * d,size_t s)112*38fd1498Szrj host_dev2host (int n __attribute__ ((unused)),
113*38fd1498Szrj void *h __attribute__ ((unused)),
114*38fd1498Szrj const void *d __attribute__ ((unused)),
115*38fd1498Szrj size_t s __attribute__ ((unused)))
116*38fd1498Szrj {
117*38fd1498Szrj return true;
118*38fd1498Szrj }
119*38fd1498Szrj
120*38fd1498Szrj static bool
host_host2dev(int n,void * d,const void * h,size_t s)121*38fd1498Szrj host_host2dev (int n __attribute__ ((unused)),
122*38fd1498Szrj void *d __attribute__ ((unused)),
123*38fd1498Szrj const void *h __attribute__ ((unused)),
124*38fd1498Szrj size_t s __attribute__ ((unused)))
125*38fd1498Szrj {
126*38fd1498Szrj return true;
127*38fd1498Szrj }
128*38fd1498Szrj
129*38fd1498Szrj static void
host_run(int n,void * fn_ptr,void * vars,void ** args)130*38fd1498Szrj host_run (int n __attribute__ ((unused)), void *fn_ptr, void *vars,
131*38fd1498Szrj void **args __attribute__((unused)))
132*38fd1498Szrj {
133*38fd1498Szrj void (*fn)(void *) = (void (*)(void *)) fn_ptr;
134*38fd1498Szrj
135*38fd1498Szrj fn (vars);
136*38fd1498Szrj }
137*38fd1498Szrj
138*38fd1498Szrj 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)139*38fd1498Szrj host_openacc_exec (void (*fn) (void *),
140*38fd1498Szrj size_t mapnum __attribute__ ((unused)),
141*38fd1498Szrj void **hostaddrs,
142*38fd1498Szrj void **devaddrs __attribute__ ((unused)),
143*38fd1498Szrj int async __attribute__ ((unused)),
144*38fd1498Szrj unsigned *dims __attribute ((unused)),
145*38fd1498Szrj void *targ_mem_desc __attribute__ ((unused)))
146*38fd1498Szrj {
147*38fd1498Szrj fn (hostaddrs);
148*38fd1498Szrj }
149*38fd1498Szrj
150*38fd1498Szrj static void
host_openacc_register_async_cleanup(void * targ_mem_desc,int async)151*38fd1498Szrj host_openacc_register_async_cleanup (void *targ_mem_desc __attribute__ ((unused)),
152*38fd1498Szrj int async __attribute__ ((unused)))
153*38fd1498Szrj {
154*38fd1498Szrj }
155*38fd1498Szrj
156*38fd1498Szrj static int
host_openacc_async_test(int async)157*38fd1498Szrj host_openacc_async_test (int async __attribute__ ((unused)))
158*38fd1498Szrj {
159*38fd1498Szrj return 1;
160*38fd1498Szrj }
161*38fd1498Szrj
162*38fd1498Szrj static int
host_openacc_async_test_all(void)163*38fd1498Szrj host_openacc_async_test_all (void)
164*38fd1498Szrj {
165*38fd1498Szrj return 1;
166*38fd1498Szrj }
167*38fd1498Szrj
168*38fd1498Szrj static void
host_openacc_async_wait(int async)169*38fd1498Szrj host_openacc_async_wait (int async __attribute__ ((unused)))
170*38fd1498Szrj {
171*38fd1498Szrj }
172*38fd1498Szrj
173*38fd1498Szrj static void
host_openacc_async_wait_async(int async1,int async2)174*38fd1498Szrj host_openacc_async_wait_async (int async1 __attribute__ ((unused)),
175*38fd1498Szrj int async2 __attribute__ ((unused)))
176*38fd1498Szrj {
177*38fd1498Szrj }
178*38fd1498Szrj
179*38fd1498Szrj static void
host_openacc_async_wait_all(void)180*38fd1498Szrj host_openacc_async_wait_all (void)
181*38fd1498Szrj {
182*38fd1498Szrj }
183*38fd1498Szrj
184*38fd1498Szrj static void
host_openacc_async_wait_all_async(int async)185*38fd1498Szrj host_openacc_async_wait_all_async (int async __attribute__ ((unused)))
186*38fd1498Szrj {
187*38fd1498Szrj }
188*38fd1498Szrj
189*38fd1498Szrj static void
host_openacc_async_set_async(int async)190*38fd1498Szrj host_openacc_async_set_async (int async __attribute__ ((unused)))
191*38fd1498Szrj {
192*38fd1498Szrj }
193*38fd1498Szrj
194*38fd1498Szrj static void *
host_openacc_create_thread_data(int ord)195*38fd1498Szrj host_openacc_create_thread_data (int ord __attribute__ ((unused)))
196*38fd1498Szrj {
197*38fd1498Szrj return NULL;
198*38fd1498Szrj }
199*38fd1498Szrj
200*38fd1498Szrj static void
host_openacc_destroy_thread_data(void * tls_data)201*38fd1498Szrj host_openacc_destroy_thread_data (void *tls_data __attribute__ ((unused)))
202*38fd1498Szrj {
203*38fd1498Szrj }
204*38fd1498Szrj
205*38fd1498Szrj static struct gomp_device_descr host_dispatch =
206*38fd1498Szrj {
207*38fd1498Szrj .name = "host",
208*38fd1498Szrj .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
209*38fd1498Szrj | GOMP_OFFLOAD_CAP_NATIVE_EXEC
210*38fd1498Szrj | GOMP_OFFLOAD_CAP_OPENACC_200),
211*38fd1498Szrj .target_id = 0,
212*38fd1498Szrj .type = OFFLOAD_TARGET_TYPE_HOST,
213*38fd1498Szrj
214*38fd1498Szrj .get_name_func = host_get_name,
215*38fd1498Szrj .get_caps_func = host_get_caps,
216*38fd1498Szrj .get_type_func = host_get_type,
217*38fd1498Szrj .get_num_devices_func = host_get_num_devices,
218*38fd1498Szrj .init_device_func = host_init_device,
219*38fd1498Szrj .fini_device_func = host_fini_device,
220*38fd1498Szrj .version_func = host_version,
221*38fd1498Szrj .load_image_func = host_load_image,
222*38fd1498Szrj .unload_image_func = host_unload_image,
223*38fd1498Szrj .alloc_func = host_alloc,
224*38fd1498Szrj .free_func = host_free,
225*38fd1498Szrj .dev2host_func = host_dev2host,
226*38fd1498Szrj .host2dev_func = host_host2dev,
227*38fd1498Szrj .run_func = host_run,
228*38fd1498Szrj
229*38fd1498Szrj .mem_map = { NULL },
230*38fd1498Szrj /* .lock initilized in goacc_host_init. */
231*38fd1498Szrj .state = GOMP_DEVICE_UNINITIALIZED,
232*38fd1498Szrj
233*38fd1498Szrj .openacc = {
234*38fd1498Szrj .data_environ = NULL,
235*38fd1498Szrj
236*38fd1498Szrj .exec_func = host_openacc_exec,
237*38fd1498Szrj
238*38fd1498Szrj .register_async_cleanup_func = host_openacc_register_async_cleanup,
239*38fd1498Szrj
240*38fd1498Szrj .async_test_func = host_openacc_async_test,
241*38fd1498Szrj .async_test_all_func = host_openacc_async_test_all,
242*38fd1498Szrj .async_wait_func = host_openacc_async_wait,
243*38fd1498Szrj .async_wait_async_func = host_openacc_async_wait_async,
244*38fd1498Szrj .async_wait_all_func = host_openacc_async_wait_all,
245*38fd1498Szrj .async_wait_all_async_func = host_openacc_async_wait_all_async,
246*38fd1498Szrj .async_set_async_func = host_openacc_async_set_async,
247*38fd1498Szrj
248*38fd1498Szrj .create_thread_data_func = host_openacc_create_thread_data,
249*38fd1498Szrj .destroy_thread_data_func = host_openacc_destroy_thread_data,
250*38fd1498Szrj
251*38fd1498Szrj .cuda = {
252*38fd1498Szrj .get_current_device_func = NULL,
253*38fd1498Szrj .get_current_context_func = NULL,
254*38fd1498Szrj .get_stream_func = NULL,
255*38fd1498Szrj .set_stream_func = NULL,
256*38fd1498Szrj }
257*38fd1498Szrj }
258*38fd1498Szrj };
259*38fd1498Szrj
260*38fd1498Szrj /* Initialize and register this device type. */
261*38fd1498Szrj void
goacc_host_init(void)262*38fd1498Szrj goacc_host_init (void)
263*38fd1498Szrj {
264*38fd1498Szrj gomp_mutex_init (&host_dispatch.lock);
265*38fd1498Szrj goacc_register (&host_dispatch);
266*38fd1498Szrj }
267