annotate liboffloadmic/runtime/offload.h @ 118:fd00160c1b76

ifdef TARGET_64BIT
author mir3636
date Tue, 27 Feb 2018 15:01:35 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /*
kono
parents:
diff changeset
2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 Redistribution and use in source and binary forms, with or without
kono
parents:
diff changeset
5 modification, are permitted provided that the following conditions
kono
parents:
diff changeset
6 are met:
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 * Redistributions of source code must retain the above copyright
kono
parents:
diff changeset
9 notice, this list of conditions and the following disclaimer.
kono
parents:
diff changeset
10 * Redistributions in binary form must reproduce the above copyright
kono
parents:
diff changeset
11 notice, this list of conditions and the following disclaimer in the
kono
parents:
diff changeset
12 documentation and/or other materials provided with the distribution.
kono
parents:
diff changeset
13 * Neither the name of Intel Corporation nor the names of its
kono
parents:
diff changeset
14 contributors may be used to endorse or promote products derived
kono
parents:
diff changeset
15 from this software without specific prior written permission.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
kono
parents:
diff changeset
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
kono
parents:
diff changeset
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
kono
parents:
diff changeset
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
kono
parents:
diff changeset
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
kono
parents:
diff changeset
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
kono
parents:
diff changeset
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
kono
parents:
diff changeset
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
kono
parents:
diff changeset
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
kono
parents:
diff changeset
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
kono
parents:
diff changeset
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kono
parents:
diff changeset
28 */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 /*
kono
parents:
diff changeset
32 * Include file for Offload API.
kono
parents:
diff changeset
33 */
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 #ifndef OFFLOAD_H_INCLUDED
kono
parents:
diff changeset
36 #define OFFLOAD_H_INCLUDED
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 #ifdef __cplusplus
kono
parents:
diff changeset
39 #if defined(LINUX) || defined(FREEBSD)
kono
parents:
diff changeset
40 #include <bits/functexcept.h>
kono
parents:
diff changeset
41 #endif
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 #include <stddef.h>
kono
parents:
diff changeset
45 #include <omp.h>
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 #ifdef TARGET_WINNT
kono
parents:
diff changeset
48 // <stdint.h> is incompatible on Windows.
kono
parents:
diff changeset
49 typedef unsigned long long int uint64_t;
kono
parents:
diff changeset
50 typedef signed long long int int64_t;
kono
parents:
diff changeset
51 #else
kono
parents:
diff changeset
52 #include <stdint.h>
kono
parents:
diff changeset
53 #endif // TARGET_WINNT
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 #ifdef __cplusplus
kono
parents:
diff changeset
56 extern "C" {
kono
parents:
diff changeset
57 #endif
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 #define TARGET_ATTRIBUTE __declspec(target(mic))
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 /*
kono
parents:
diff changeset
62 * The target architecture.
kono
parents:
diff changeset
63 */
kono
parents:
diff changeset
64 typedef enum TARGET_TYPE {
kono
parents:
diff changeset
65 TARGET_NONE, /* Undefine target */
kono
parents:
diff changeset
66 TARGET_HOST, /* Host used as target */
kono
parents:
diff changeset
67 TARGET_MIC /* MIC target */
kono
parents:
diff changeset
68 } TARGET_TYPE;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 /*
kono
parents:
diff changeset
71 * The default target type.
kono
parents:
diff changeset
72 */
kono
parents:
diff changeset
73 #define DEFAULT_TARGET_TYPE TARGET_MIC
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 /*
kono
parents:
diff changeset
76 * The default target number.
kono
parents:
diff changeset
77 */
kono
parents:
diff changeset
78 #define DEFAULT_TARGET_NUMBER 0
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 /*
kono
parents:
diff changeset
81 * Offload status.
kono
parents:
diff changeset
82 */
kono
parents:
diff changeset
83 typedef enum {
kono
parents:
diff changeset
84 OFFLOAD_SUCCESS = 0,
kono
parents:
diff changeset
85 OFFLOAD_DISABLED, /* offload is disabled */
kono
parents:
diff changeset
86 OFFLOAD_UNAVAILABLE, /* card is not available */
kono
parents:
diff changeset
87 OFFLOAD_OUT_OF_MEMORY, /* not enough memory on device */
kono
parents:
diff changeset
88 OFFLOAD_PROCESS_DIED, /* target process has died */
kono
parents:
diff changeset
89 OFFLOAD_ERROR /* unspecified error */
kono
parents:
diff changeset
90 } _Offload_result;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 typedef struct {
kono
parents:
diff changeset
93 _Offload_result result; /* result, see above */
kono
parents:
diff changeset
94 int device_number; /* device number */
kono
parents:
diff changeset
95 size_t data_sent; /* number of bytes sent to the target */
kono
parents:
diff changeset
96 size_t data_received; /* number of bytes received by host */
kono
parents:
diff changeset
97 } _Offload_status;
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 typedef int64_t _Offload_stream;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 #define OFFLOAD_STATUS_INIT(x) \
kono
parents:
diff changeset
102 ((x).result = OFFLOAD_DISABLED)
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 #define OFFLOAD_STATUS_INITIALIZER \
kono
parents:
diff changeset
105 { OFFLOAD_DISABLED, -1, 0, 0 }
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 /* Offload runtime interfaces */
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 extern int _Offload_number_of_devices(void);
kono
parents:
diff changeset
110 extern int _Offload_get_device_number(void);
kono
parents:
diff changeset
111 extern int _Offload_get_physical_device_number(void);
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 /* Offload stream runtime interfaces */
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 extern _Offload_stream _Offload_stream_create(
kono
parents:
diff changeset
116 int device, // MIC device number
kono
parents:
diff changeset
117 int number_of_cpus // Cores allocated to the stream
kono
parents:
diff changeset
118 );
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 extern int _Offload_stream_destroy(
kono
parents:
diff changeset
121 int device, // MIC device number
kono
parents:
diff changeset
122 _Offload_stream stream // stream handle
kono
parents:
diff changeset
123 );
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 extern int _Offload_stream_delete(
kono
parents:
diff changeset
126 _Offload_stream handle // stream handle
kono
parents:
diff changeset
127 );
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 extern int _Offload_stream_completed(
kono
parents:
diff changeset
130 int device, // MIC device number
kono
parents:
diff changeset
131 _Offload_stream handle // stream handle
kono
parents:
diff changeset
132 );
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 extern int _Offload_device_streams_completed(
kono
parents:
diff changeset
135 int device // MIC device number
kono
parents:
diff changeset
136 );
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 extern int _Offload_stream_is_empty(
kono
parents:
diff changeset
139 _Offload_stream handle // stream handle
kono
parents:
diff changeset
140 );
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 /*
kono
parents:
diff changeset
143 * _Offload_shared_malloc/free are only supported when offload is enabled
kono
parents:
diff changeset
144 * else they are defined to malloc and free
kono
parents:
diff changeset
145 */
kono
parents:
diff changeset
146 #ifdef __INTEL_OFFLOAD
kono
parents:
diff changeset
147 extern void* _Offload_shared_malloc(size_t size);
kono
parents:
diff changeset
148 extern void _Offload_shared_free(void *ptr);
kono
parents:
diff changeset
149 extern void* _Offload_shared_aligned_malloc(size_t size, size_t align);
kono
parents:
diff changeset
150 extern void _Offload_shared_aligned_free(void *ptr);
kono
parents:
diff changeset
151 #else
kono
parents:
diff changeset
152 #include <malloc.h>
kono
parents:
diff changeset
153 #define _Offload_shared_malloc(size) malloc(size)
kono
parents:
diff changeset
154 #define _Offload_shared_free(ptr) free(ptr);
kono
parents:
diff changeset
155 #if defined(_WIN32)
kono
parents:
diff changeset
156 #define _Offload_shared_aligned_malloc(size, align) _aligned_malloc(size, align)
kono
parents:
diff changeset
157 #define _Offload_shared_aligned_free(ptr) _aligned_free(ptr);
kono
parents:
diff changeset
158 #else
kono
parents:
diff changeset
159 #define _Offload_shared_aligned_malloc(size, align) memalign(align, size)
kono
parents:
diff changeset
160 #define _Offload_shared_aligned_free(ptr) free(ptr);
kono
parents:
diff changeset
161 #endif
kono
parents:
diff changeset
162 #endif
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 extern int _Offload_signaled(int index, void *signal);
kono
parents:
diff changeset
166 extern void _Offload_report(int val);
kono
parents:
diff changeset
167 extern int _Offload_find_associated_mic_memory(
kono
parents:
diff changeset
168 int target,
kono
parents:
diff changeset
169 const void* cpu_addr,
kono
parents:
diff changeset
170 void** cpu_base_addr,
kono
parents:
diff changeset
171 uint64_t* buf_length,
kono
parents:
diff changeset
172 void** mic_addr,
kono
parents:
diff changeset
173 uint64_t* mic_buf_start_offset,
kono
parents:
diff changeset
174 int* is_static
kono
parents:
diff changeset
175 );
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 /* OpenMP API */
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 extern void omp_set_default_device(int num) __GOMP_NOTHROW;
kono
parents:
diff changeset
180 extern int omp_get_default_device(void) __GOMP_NOTHROW;
kono
parents:
diff changeset
181 extern int omp_get_num_devices(void) __GOMP_NOTHROW;
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 // OpenMP 4.5 APIs
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 /*! \fn omp_get_initial_device
kono
parents:
diff changeset
186 \brief Return the device id of the initial device.
kono
parents:
diff changeset
187 \return Returns the device id of the initial device.
kono
parents:
diff changeset
188 */
kono
parents:
diff changeset
189 extern int omp_get_initial_device(
kono
parents:
diff changeset
190 void
kono
parents:
diff changeset
191 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 /*! \fn omp_target_alloc
kono
parents:
diff changeset
194 \brief Allocate memory in the device data environment.
kono
parents:
diff changeset
195 \param size Number of bytes to allocate.
kono
parents:
diff changeset
196 \param device_num The device number on which to allocate.
kono
parents:
diff changeset
197 \return Returns a pointer to the allocated memory.
kono
parents:
diff changeset
198 */
kono
parents:
diff changeset
199 extern void* omp_target_alloc(
kono
parents:
diff changeset
200 size_t size,
kono
parents:
diff changeset
201 int device_num
kono
parents:
diff changeset
202 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 /*! \fn omp_target_free
kono
parents:
diff changeset
205 \brief Free memory in the device data environment.
kono
parents:
diff changeset
206 \param device_ptr Address of allocated device memory.
kono
parents:
diff changeset
207 \param device_num The device number on which to free.
kono
parents:
diff changeset
208 */
kono
parents:
diff changeset
209 extern void omp_target_free(
kono
parents:
diff changeset
210 void *device_ptr,
kono
parents:
diff changeset
211 int device_num
kono
parents:
diff changeset
212 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 /*! \fn omp_target_is_present
kono
parents:
diff changeset
215 \brief Test whether a host pointer has corresponding storage on a device.
kono
parents:
diff changeset
216 \param device_ptr Address of allocated device memory.
kono
parents:
diff changeset
217 \param device_num The device number on which to test..
kono
parents:
diff changeset
218 \return true if storage is found, false otherwise.
kono
parents:
diff changeset
219 */
kono
parents:
diff changeset
220 extern int omp_target_is_present(
kono
parents:
diff changeset
221 void *ptr,
kono
parents:
diff changeset
222 int device_num
kono
parents:
diff changeset
223 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 /*! \fn omp_target_memcpy
kono
parents:
diff changeset
226 \brief Copy memory between host/device pointers.
kono
parents:
diff changeset
227 \param dst Address of destination memory.
kono
parents:
diff changeset
228 \param src Address of source memory.
kono
parents:
diff changeset
229 \param length Number of bytes to copy.
kono
parents:
diff changeset
230 \param dst_offset Destination offset in bytes.
kono
parents:
diff changeset
231 \param src_offset Source offset in bytes.
kono
parents:
diff changeset
232 \param dst_device Destination device number.
kono
parents:
diff changeset
233 \param src_device Source device number.
kono
parents:
diff changeset
234 \return 0 on success, 1 otherwise.
kono
parents:
diff changeset
235 */
kono
parents:
diff changeset
236 extern int omp_target_memcpy(
kono
parents:
diff changeset
237 void *dst,
kono
parents:
diff changeset
238 void *src,
kono
parents:
diff changeset
239 size_t length,
kono
parents:
diff changeset
240 size_t dst_offset,
kono
parents:
diff changeset
241 size_t src_offset,
kono
parents:
diff changeset
242 int dst_device,
kono
parents:
diff changeset
243 int src_device
kono
parents:
diff changeset
244 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 /*! \fn omp_target_memcpy_rect
kono
parents:
diff changeset
247 \brief Copy a rectangular subsection from
kono
parents:
diff changeset
248 \brief one multi-dimensional array to another.
kono
parents:
diff changeset
249 \param dst Address of destination array.
kono
parents:
diff changeset
250 \param src Address of source array.
kono
parents:
diff changeset
251 \param element_size Number of bytes in each array element.
kono
parents:
diff changeset
252 \param num_dims Number of dimensions.
kono
parents:
diff changeset
253 \param volume Array of element counts to copy in each dimension.
kono
parents:
diff changeset
254 \param dst_offsets Destination offsets array.
kono
parents:
diff changeset
255 \param src_offsets Source offsets array.
kono
parents:
diff changeset
256 \param dst_dims Destination array dimensions array.
kono
parents:
diff changeset
257 \param src_dims Source array dimensions array.
kono
parents:
diff changeset
258 \param dst_device Destination device number.
kono
parents:
diff changeset
259 \param src_device Source device number.
kono
parents:
diff changeset
260 \return 0 on success, 1 otherwise.
kono
parents:
diff changeset
261 */
kono
parents:
diff changeset
262 extern int omp_target_memcpy_rect(
kono
parents:
diff changeset
263 void *dst,
kono
parents:
diff changeset
264 void *src,
kono
parents:
diff changeset
265 size_t element_size,
kono
parents:
diff changeset
266 int num_dims,
kono
parents:
diff changeset
267 const size_t *volume,
kono
parents:
diff changeset
268 const size_t *dst_offsets,
kono
parents:
diff changeset
269 const size_t *src_offsets,
kono
parents:
diff changeset
270 const size_t *dst_dimensions,
kono
parents:
diff changeset
271 const size_t *src_dimensions,
kono
parents:
diff changeset
272 int dst_device,
kono
parents:
diff changeset
273 int src_device
kono
parents:
diff changeset
274 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 /*! \fn omp_target_associate_ptr
kono
parents:
diff changeset
277 \brief Map a device pointer to a host pointer.
kono
parents:
diff changeset
278 \param host_ptr The host pointer.
kono
parents:
diff changeset
279 \param device_ptr The device pointer.
kono
parents:
diff changeset
280 \param size Number of bytes to map.
kono
parents:
diff changeset
281 \param device_offset Offset on device of mapped memory.
kono
parents:
diff changeset
282 \param device_num Device number.
kono
parents:
diff changeset
283 \return 0 on success, 1 otherwise.
kono
parents:
diff changeset
284 */
kono
parents:
diff changeset
285 extern int omp_target_associate_ptr(
kono
parents:
diff changeset
286 void *host_ptr,
kono
parents:
diff changeset
287 void *device_ptr,
kono
parents:
diff changeset
288 size_t size,
kono
parents:
diff changeset
289 size_t device_offset,
kono
parents:
diff changeset
290 int device_num
kono
parents:
diff changeset
291 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 /*! \fn omp_target_disassociate_ptr
kono
parents:
diff changeset
294 \brief Remove a host pointer to device pointer association.
kono
parents:
diff changeset
295 \param ptr The host pointer to disassociate.
kono
parents:
diff changeset
296 \param device_num Device number.
kono
parents:
diff changeset
297 \return 0 on success, 1 otherwise.
kono
parents:
diff changeset
298 */
kono
parents:
diff changeset
299 extern int omp_target_disassociate_ptr(
kono
parents:
diff changeset
300 void *host_ptr,
kono
parents:
diff changeset
301 int device_num
kono
parents:
diff changeset
302 ) __GOMP_NOTHROW;
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 // End of OpenMP 4.5 APIs
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 /* OpenMP API wrappers */
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 /* Set num_threads on target */
kono
parents:
diff changeset
309 extern void omp_set_num_threads_target(
kono
parents:
diff changeset
310 TARGET_TYPE target_type,
kono
parents:
diff changeset
311 int target_number,
kono
parents:
diff changeset
312 int num_threads
kono
parents:
diff changeset
313 );
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 /* Get max_threads from target */
kono
parents:
diff changeset
316 extern int omp_get_max_threads_target(
kono
parents:
diff changeset
317 TARGET_TYPE target_type,
kono
parents:
diff changeset
318 int target_number
kono
parents:
diff changeset
319 );
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 /* Get num_procs from target */
kono
parents:
diff changeset
322 extern int omp_get_num_procs_target(
kono
parents:
diff changeset
323 TARGET_TYPE target_type,
kono
parents:
diff changeset
324 int target_number
kono
parents:
diff changeset
325 );
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 /* Set dynamic on target */
kono
parents:
diff changeset
328 extern void omp_set_dynamic_target(
kono
parents:
diff changeset
329 TARGET_TYPE target_type,
kono
parents:
diff changeset
330 int target_number,
kono
parents:
diff changeset
331 int num_threads
kono
parents:
diff changeset
332 );
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 /* Get dynamic from target */
kono
parents:
diff changeset
335 extern int omp_get_dynamic_target(
kono
parents:
diff changeset
336 TARGET_TYPE target_type,
kono
parents:
diff changeset
337 int target_number
kono
parents:
diff changeset
338 );
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 /* Set nested on target */
kono
parents:
diff changeset
341 extern void omp_set_nested_target(
kono
parents:
diff changeset
342 TARGET_TYPE target_type,
kono
parents:
diff changeset
343 int target_number,
kono
parents:
diff changeset
344 int nested
kono
parents:
diff changeset
345 );
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 /* Get nested from target */
kono
parents:
diff changeset
348 extern int omp_get_nested_target(
kono
parents:
diff changeset
349 TARGET_TYPE target_type,
kono
parents:
diff changeset
350 int target_number
kono
parents:
diff changeset
351 );
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 extern void omp_set_num_threads_target(
kono
parents:
diff changeset
354 TARGET_TYPE target_type,
kono
parents:
diff changeset
355 int target_number,
kono
parents:
diff changeset
356 int num_threads
kono
parents:
diff changeset
357 );
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 extern int omp_get_max_threads_target(
kono
parents:
diff changeset
360 TARGET_TYPE target_type,
kono
parents:
diff changeset
361 int target_number
kono
parents:
diff changeset
362 );
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 extern int omp_get_num_procs_target(
kono
parents:
diff changeset
365 TARGET_TYPE target_type,
kono
parents:
diff changeset
366 int target_number
kono
parents:
diff changeset
367 );
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 extern void omp_set_dynamic_target(
kono
parents:
diff changeset
370 TARGET_TYPE target_type,
kono
parents:
diff changeset
371 int target_number,
kono
parents:
diff changeset
372 int num_threads
kono
parents:
diff changeset
373 );
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 extern int omp_get_dynamic_target(
kono
parents:
diff changeset
376 TARGET_TYPE target_type,
kono
parents:
diff changeset
377 int target_number
kono
parents:
diff changeset
378 );
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 extern void omp_set_nested_target(
kono
parents:
diff changeset
381 TARGET_TYPE target_type,
kono
parents:
diff changeset
382 int target_number,
kono
parents:
diff changeset
383 int num_threads
kono
parents:
diff changeset
384 );
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 extern int omp_get_nested_target(
kono
parents:
diff changeset
387 TARGET_TYPE target_type,
kono
parents:
diff changeset
388 int target_number
kono
parents:
diff changeset
389 );
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 extern void omp_set_schedule_target(
kono
parents:
diff changeset
392 TARGET_TYPE target_type,
kono
parents:
diff changeset
393 int target_number,
kono
parents:
diff changeset
394 omp_sched_t kind,
kono
parents:
diff changeset
395 int modifier
kono
parents:
diff changeset
396 );
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 extern void omp_get_schedule_target(
kono
parents:
diff changeset
399 TARGET_TYPE target_type,
kono
parents:
diff changeset
400 int target_number,
kono
parents:
diff changeset
401 omp_sched_t *kind,
kono
parents:
diff changeset
402 int *modifier
kono
parents:
diff changeset
403 );
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 /* lock API functions */
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 typedef struct {
kono
parents:
diff changeset
408 omp_lock_t lock;
kono
parents:
diff changeset
409 } omp_lock_target_t;
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 extern void omp_init_lock_target(
kono
parents:
diff changeset
412 TARGET_TYPE target_type,
kono
parents:
diff changeset
413 int target_number,
kono
parents:
diff changeset
414 omp_lock_target_t *lock
kono
parents:
diff changeset
415 );
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 extern void omp_destroy_lock_target(
kono
parents:
diff changeset
418 TARGET_TYPE target_type,
kono
parents:
diff changeset
419 int target_number,
kono
parents:
diff changeset
420 omp_lock_target_t *lock
kono
parents:
diff changeset
421 );
kono
parents:
diff changeset
422
kono
parents:
diff changeset
423 extern void omp_set_lock_target(
kono
parents:
diff changeset
424 TARGET_TYPE target_type,
kono
parents:
diff changeset
425 int target_number,
kono
parents:
diff changeset
426 omp_lock_target_t *lock
kono
parents:
diff changeset
427 );
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 extern void omp_unset_lock_target(
kono
parents:
diff changeset
430 TARGET_TYPE target_type,
kono
parents:
diff changeset
431 int target_number,
kono
parents:
diff changeset
432 omp_lock_target_t *lock
kono
parents:
diff changeset
433 );
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 extern int omp_test_lock_target(
kono
parents:
diff changeset
436 TARGET_TYPE target_type,
kono
parents:
diff changeset
437 int target_number,
kono
parents:
diff changeset
438 omp_lock_target_t *lock
kono
parents:
diff changeset
439 );
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 /* nested lock API functions */
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 typedef struct {
kono
parents:
diff changeset
444 omp_nest_lock_t lock;
kono
parents:
diff changeset
445 } omp_nest_lock_target_t;
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 extern void omp_init_nest_lock_target(
kono
parents:
diff changeset
448 TARGET_TYPE target_type,
kono
parents:
diff changeset
449 int target_number,
kono
parents:
diff changeset
450 omp_nest_lock_target_t *lock
kono
parents:
diff changeset
451 );
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 extern void omp_destroy_nest_lock_target(
kono
parents:
diff changeset
454 TARGET_TYPE target_type,
kono
parents:
diff changeset
455 int target_number,
kono
parents:
diff changeset
456 omp_nest_lock_target_t *lock
kono
parents:
diff changeset
457 );
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 extern void omp_set_nest_lock_target(
kono
parents:
diff changeset
460 TARGET_TYPE target_type,
kono
parents:
diff changeset
461 int target_number,
kono
parents:
diff changeset
462 omp_nest_lock_target_t *lock
kono
parents:
diff changeset
463 );
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 extern void omp_unset_nest_lock_target(
kono
parents:
diff changeset
466 TARGET_TYPE target_type,
kono
parents:
diff changeset
467 int target_number,
kono
parents:
diff changeset
468 omp_nest_lock_target_t *lock
kono
parents:
diff changeset
469 );
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 extern int omp_test_nest_lock_target(
kono
parents:
diff changeset
472 TARGET_TYPE target_type,
kono
parents:
diff changeset
473 int target_number,
kono
parents:
diff changeset
474 omp_nest_lock_target_t *lock
kono
parents:
diff changeset
475 );
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 #ifdef __cplusplus
kono
parents:
diff changeset
478 } /* extern "C" */
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 /* Namespace for the shared_allocator. */
kono
parents:
diff changeset
481 namespace __offload {
kono
parents:
diff changeset
482 /* This follows the specification for std::allocator. */
kono
parents:
diff changeset
483 /* Forward declaration of the class template. */
kono
parents:
diff changeset
484 template <typename T>
kono
parents:
diff changeset
485 class shared_allocator;
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 /* Specialization for shared_allocator<void>. */
kono
parents:
diff changeset
488 template <>
kono
parents:
diff changeset
489 class shared_allocator<void> {
kono
parents:
diff changeset
490 public:
kono
parents:
diff changeset
491 typedef void *pointer;
kono
parents:
diff changeset
492 typedef const void *const_pointer;
kono
parents:
diff changeset
493 typedef void value_type;
kono
parents:
diff changeset
494 template <class U> struct rebind { typedef shared_allocator<U> other; };
kono
parents:
diff changeset
495 };
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 /* Definition of shared_allocator<T>. */
kono
parents:
diff changeset
498 template <class T>
kono
parents:
diff changeset
499 class shared_allocator {
kono
parents:
diff changeset
500 public:
kono
parents:
diff changeset
501 typedef size_t size_type;
kono
parents:
diff changeset
502 typedef ptrdiff_t difference_type;
kono
parents:
diff changeset
503 typedef T *pointer;
kono
parents:
diff changeset
504 typedef const T *const_pointer;
kono
parents:
diff changeset
505 typedef T &reference;
kono
parents:
diff changeset
506 typedef const T &const_reference;
kono
parents:
diff changeset
507 typedef T value_type;
kono
parents:
diff changeset
508 template <class U> struct rebind { typedef shared_allocator<U> other; };
kono
parents:
diff changeset
509 shared_allocator() throw() { }
kono
parents:
diff changeset
510 shared_allocator(const shared_allocator&) throw() { }
kono
parents:
diff changeset
511 template <class U> shared_allocator(const shared_allocator<U>&) throw() { }
kono
parents:
diff changeset
512 ~shared_allocator() throw() { }
kono
parents:
diff changeset
513 pointer address(reference x) const { return &x; }
kono
parents:
diff changeset
514 const_pointer address(const_reference x) const { return &x; }
kono
parents:
diff changeset
515 pointer allocate(
kono
parents:
diff changeset
516 size_type, shared_allocator<void>::const_pointer hint = 0);
kono
parents:
diff changeset
517 void deallocate(pointer p, size_type n);
kono
parents:
diff changeset
518 size_type max_size() const throw() {
kono
parents:
diff changeset
519 return size_type(-1)/sizeof(T);
kono
parents:
diff changeset
520 } /* max_size */
kono
parents:
diff changeset
521 void construct(pointer p, const T& arg) {
kono
parents:
diff changeset
522 ::new (p) T(arg);
kono
parents:
diff changeset
523 } /* construct */
kono
parents:
diff changeset
524 void destroy(pointer p) {
kono
parents:
diff changeset
525 p->~T();
kono
parents:
diff changeset
526 } /* destroy */
kono
parents:
diff changeset
527 };
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 /* Definition for allocate. */
kono
parents:
diff changeset
530 template <class T>
kono
parents:
diff changeset
531 typename shared_allocator<T>::pointer
kono
parents:
diff changeset
532 shared_allocator<T>::allocate(shared_allocator<T>::size_type s,
kono
parents:
diff changeset
533 shared_allocator<void>::const_pointer) {
kono
parents:
diff changeset
534 /* Allocate from shared memory. */
kono
parents:
diff changeset
535 void *ptr = _Offload_shared_malloc(s*sizeof(T));
kono
parents:
diff changeset
536 #if (defined(_WIN32) || defined(_WIN64)) /* Windows */
kono
parents:
diff changeset
537 if (ptr == 0) throw std::bad_alloc();
kono
parents:
diff changeset
538 #else
kono
parents:
diff changeset
539 if (ptr == 0) std::__throw_bad_alloc();
kono
parents:
diff changeset
540 #endif
kono
parents:
diff changeset
541 return static_cast<pointer>(ptr);
kono
parents:
diff changeset
542 } /* allocate */
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 template <class T>
kono
parents:
diff changeset
545 void shared_allocator<T>::deallocate(pointer p,
kono
parents:
diff changeset
546 shared_allocator<T>::size_type) {
kono
parents:
diff changeset
547 /* Free the shared memory. */
kono
parents:
diff changeset
548 _Offload_shared_free(p);
kono
parents:
diff changeset
549 } /* deallocate */
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 template <typename _T1, typename _T2>
kono
parents:
diff changeset
552 inline bool operator==(const shared_allocator<_T1> &,
kono
parents:
diff changeset
553 const shared_allocator<_T2> &) throw() {
kono
parents:
diff changeset
554 return true;
kono
parents:
diff changeset
555 } /* operator== */
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 template <typename _T1, typename _T2>
kono
parents:
diff changeset
558 inline bool operator!=(const shared_allocator<_T1> &,
kono
parents:
diff changeset
559 const shared_allocator<_T2> &) throw() {
kono
parents:
diff changeset
560 return false;
kono
parents:
diff changeset
561 } /* operator!= */
kono
parents:
diff changeset
562 } /* __offload */
kono
parents:
diff changeset
563 #endif /* __cplusplus */
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 #endif /* OFFLOAD_H_INCLUDED */