]>
Commit | Line | Data |
---|---|---|
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 | ||
58 | STATIC const char * | |
59 | GOMP_OFFLOAD_get_name (void) | |
60 | { | |
61 | #ifdef HOST_NONSHM_PLUGIN | |
62 | return "host_nonshm"; | |
63 | #else | |
64 | return "host"; | |
65 | #endif | |
66 | } | |
67 | ||
68 | STATIC unsigned int | |
69 | GOMP_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 | ||
81 | STATIC int | |
82 | GOMP_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 | ||
91 | STATIC int | |
92 | GOMP_OFFLOAD_get_num_devices (void) | |
93 | { | |
94 | return 1; | |
95 | } | |
96 | ||
41dbbb37 TS |
97 | STATIC void |
98 | GOMP_OFFLOAD_init_device (int n __attribute__ ((unused))) | |
99 | { | |
100 | } | |
101 | ||
102 | STATIC void | |
103 | GOMP_OFFLOAD_fini_device (int n __attribute__ ((unused))) | |
104 | { | |
105 | } | |
106 | ||
107 | STATIC int | |
a51df54e IV |
108 | GOMP_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 |
115 | STATIC void |
116 | GOMP_OFFLOAD_unload_image (int n __attribute__ ((unused)), | |
117 | void *i __attribute__ ((unused))) | |
118 | { | |
119 | } | |
120 | ||
41dbbb37 TS |
121 | STATIC void * |
122 | GOMP_OFFLOAD_openacc_open_device (int n) | |
123 | { | |
124 | return (void *) (intptr_t) n; | |
125 | } | |
126 | ||
127 | STATIC int | |
128 | GOMP_OFFLOAD_openacc_close_device (void *hnd) | |
129 | { | |
130 | return 0; | |
131 | } | |
132 | ||
133 | STATIC int | |
134 | GOMP_OFFLOAD_openacc_get_device_num (void) | |
135 | { | |
136 | return 0; | |
137 | } | |
138 | ||
139 | STATIC void | |
140 | GOMP_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 | ||
146 | STATIC void * | |
147 | GOMP_OFFLOAD_alloc (int n __attribute__ ((unused)), size_t s) | |
148 | { | |
149 | return GOMP (malloc) (s); | |
150 | } | |
151 | ||
152 | STATIC void | |
153 | GOMP_OFFLOAD_free (int n __attribute__ ((unused)), void *p) | |
154 | { | |
155 | free (p); | |
156 | } | |
157 | ||
158 | STATIC void * | |
159 | GOMP_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 | ||
169 | STATIC void * | |
170 | GOMP_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 | ||
180 | STATIC void | |
181 | GOMP_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 | ||
188 | STATIC void | |
189 | GOMP_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 | ||
208 | STATIC void | |
209 | GOMP_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 | ||
218 | STATIC void | |
219 | GOMP_OFFLOAD_openacc_async_set_async (int async __attribute__ ((unused))) | |
220 | { | |
221 | } | |
222 | ||
223 | STATIC int | |
224 | GOMP_OFFLOAD_openacc_async_test (int async __attribute__ ((unused))) | |
225 | { | |
226 | return 1; | |
227 | } | |
228 | ||
229 | STATIC int | |
230 | GOMP_OFFLOAD_openacc_async_test_all (void) | |
231 | { | |
232 | return 1; | |
233 | } | |
234 | ||
235 | STATIC void | |
236 | GOMP_OFFLOAD_openacc_async_wait (int async __attribute__ ((unused))) | |
237 | { | |
238 | } | |
239 | ||
240 | STATIC void | |
241 | GOMP_OFFLOAD_openacc_async_wait_all (void) | |
242 | { | |
243 | } | |
244 | ||
245 | STATIC void | |
246 | GOMP_OFFLOAD_openacc_async_wait_async (int async1 __attribute__ ((unused)), | |
247 | int async2 __attribute__ ((unused))) | |
248 | { | |
249 | } | |
250 | ||
251 | STATIC void | |
252 | GOMP_OFFLOAD_openacc_async_wait_all_async (int async __attribute__ ((unused))) | |
253 | { | |
254 | } | |
255 | ||
256 | STATIC void * | |
257 | GOMP_OFFLOAD_openacc_create_thread_data (void *targ_data | |
258 | __attribute__ ((unused))) | |
259 | { | |
260 | return NULL; | |
261 | } | |
262 | ||
263 | STATIC void | |
264 | GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data | |
265 | __attribute__ ((unused))) | |
266 | { | |
267 | } |