2 Copyright (c) 2014-2015 Intel Corporation. All Rights Reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "compiler_if_target.h"
37 void omp_set_default_device(int num
) __GOMP_NOTHROW
41 int omp_get_default_device(void) __GOMP_NOTHROW
46 int omp_get_num_devices() __GOMP_NOTHROW
48 return mic_engines_total
;
51 // OpenMP API wrappers
53 static void omp_send_int_to_host(
58 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
59 VarDesc vars
[1] = {0};
61 vars
[0].type
.src
= c_data
;
62 vars
[0].type
.dst
= c_data
;
63 vars
[0].direction
.bits
= c_parameter_out
;
64 vars
[0].ptr
= &setting
;
66 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
67 OFFLOAD_TARGET_LEAVE(ofld
);
70 static int omp_get_int_from_host(
74 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
75 VarDesc vars
[1] = {0};
78 vars
[0].type
.src
= c_data
;
79 vars
[0].type
.dst
= c_data
;
80 vars
[0].direction
.bits
= c_parameter_in
;
81 vars
[0].ptr
= &setting
;
83 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
84 OFFLOAD_TARGET_LEAVE(ofld
);
89 DLL_LOCAL
void omp_set_num_threads_lrb(
95 num_threads
= omp_get_int_from_host(ofld
);
96 omp_set_num_threads(num_threads
);
99 DLL_LOCAL
void omp_get_max_threads_lrb(
105 num_threads
= omp_get_max_threads();
106 omp_send_int_to_host(ofld
, num_threads
);
109 DLL_LOCAL
void omp_get_num_procs_lrb(
115 num_procs
= omp_get_num_procs();
116 omp_send_int_to_host(ofld
, num_procs
);
119 DLL_LOCAL
void omp_set_dynamic_lrb(
125 dynamic
= omp_get_int_from_host(ofld
);
126 omp_set_dynamic(dynamic
);
129 DLL_LOCAL
void omp_get_dynamic_lrb(
135 dynamic
= omp_get_dynamic();
136 omp_send_int_to_host(ofld
, dynamic
);
139 DLL_LOCAL
void omp_set_nested_lrb(
145 nested
= omp_get_int_from_host(ofld
);
146 omp_set_nested(nested
);
149 DLL_LOCAL
void omp_get_nested_lrb(
155 nested
= omp_get_nested();
156 omp_send_int_to_host(ofld
, nested
);
159 DLL_LOCAL
void omp_set_schedule_lrb(
163 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
164 VarDesc vars
[2] = {0};
168 vars
[0].type
.src
= c_data
;
169 vars
[0].type
.dst
= c_data
;
170 vars
[0].direction
.bits
= c_parameter_in
;
173 vars
[1].type
.src
= c_data
;
174 vars
[1].type
.dst
= c_data
;
175 vars
[1].direction
.bits
= c_parameter_in
;
176 vars
[1].ptr
= &modifier
;
178 OFFLOAD_TARGET_ENTER(ofld
, 2, vars
, NULL
);
179 omp_set_schedule(kind
, modifier
);
180 OFFLOAD_TARGET_LEAVE(ofld
);
183 DLL_LOCAL
void omp_get_schedule_lrb(
187 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
188 VarDesc vars
[2] = {0};
192 vars
[0].type
.src
= c_data
;
193 vars
[0].type
.dst
= c_data
;
194 vars
[0].direction
.bits
= c_parameter_out
;
197 vars
[1].type
.src
= c_data
;
198 vars
[1].type
.dst
= c_data
;
199 vars
[1].direction
.bits
= c_parameter_out
;
200 vars
[1].ptr
= &modifier
;
202 OFFLOAD_TARGET_ENTER(ofld
, 2, vars
, NULL
);
203 omp_get_schedule(&kind
, &modifier
);
204 OFFLOAD_TARGET_LEAVE(ofld
);
207 // lock API functions
209 DLL_LOCAL
void omp_init_lock_lrb(
213 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
214 VarDesc vars
[1] = {0};
215 omp_lock_target_t lock
;
217 vars
[0].type
.src
= c_data
;
218 vars
[0].type
.dst
= c_data
;
219 vars
[0].direction
.bits
= c_parameter_out
;
222 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
223 omp_init_lock(&lock
.lock
);
224 OFFLOAD_TARGET_LEAVE(ofld
);
227 DLL_LOCAL
void omp_destroy_lock_lrb(
231 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
232 VarDesc vars
[1] = {0};
233 omp_lock_target_t lock
;
235 vars
[0].type
.src
= c_data
;
236 vars
[0].type
.dst
= c_data
;
237 vars
[0].direction
.bits
= c_parameter_in
;
240 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
241 omp_destroy_lock(&lock
.lock
);
242 OFFLOAD_TARGET_LEAVE(ofld
);
245 DLL_LOCAL
void omp_set_lock_lrb(
249 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
250 VarDesc vars
[1] = {0};
251 omp_lock_target_t lock
;
253 vars
[0].type
.src
= c_data
;
254 vars
[0].type
.dst
= c_data
;
255 vars
[0].direction
.bits
= c_parameter_inout
;
258 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
259 omp_set_lock(&lock
.lock
);
260 OFFLOAD_TARGET_LEAVE(ofld
);
263 DLL_LOCAL
void omp_unset_lock_lrb(
267 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
268 VarDesc vars
[1] = {0};
269 omp_lock_target_t lock
;
271 vars
[0].type
.src
= c_data
;
272 vars
[0].type
.dst
= c_data
;
273 vars
[0].direction
.bits
= c_parameter_inout
;
276 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
277 omp_unset_lock(&lock
.lock
);
278 OFFLOAD_TARGET_LEAVE(ofld
);
281 DLL_LOCAL
void omp_test_lock_lrb(
285 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
286 VarDesc vars
[2] = {0};
287 omp_lock_target_t lock
;
290 vars
[0].type
.src
= c_data
;
291 vars
[0].type
.dst
= c_data
;
292 vars
[0].direction
.bits
= c_parameter_inout
;
295 vars
[1].type
.src
= c_data
;
296 vars
[1].type
.dst
= c_data
;
297 vars
[1].direction
.bits
= c_parameter_out
;
298 vars
[1].ptr
= &result
;
300 OFFLOAD_TARGET_ENTER(ofld
, 2, vars
, NULL
);
301 result
= omp_test_lock(&lock
.lock
);
302 OFFLOAD_TARGET_LEAVE(ofld
);
305 // nested lock API functions
307 DLL_LOCAL
void omp_init_nest_lock_lrb(
311 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
312 VarDesc vars
[1] = {0};
313 omp_nest_lock_target_t lock
;
315 vars
[0].type
.src
= c_data
;
316 vars
[0].type
.dst
= c_data
;
317 vars
[0].direction
.bits
= c_parameter_out
;
320 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
321 omp_init_nest_lock(&lock
.lock
);
322 OFFLOAD_TARGET_LEAVE(ofld
);
325 DLL_LOCAL
void omp_destroy_nest_lock_lrb(
329 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
330 VarDesc vars
[1] = {0};
331 omp_nest_lock_target_t lock
;
333 vars
[0].type
.src
= c_data
;
334 vars
[0].type
.dst
= c_data
;
335 vars
[0].direction
.bits
= c_parameter_in
;
338 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
339 omp_destroy_nest_lock(&lock
.lock
);
340 OFFLOAD_TARGET_LEAVE(ofld
);
343 DLL_LOCAL
void omp_set_nest_lock_lrb(
347 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
348 VarDesc vars
[1] = {0};
349 omp_nest_lock_target_t lock
;
351 vars
[0].type
.src
= c_data
;
352 vars
[0].type
.dst
= c_data
;
353 vars
[0].direction
.bits
= c_parameter_inout
;
356 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
357 omp_set_nest_lock(&lock
.lock
);
358 OFFLOAD_TARGET_LEAVE(ofld
);
361 DLL_LOCAL
void omp_unset_nest_lock_lrb(
365 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
366 VarDesc vars
[1] = {0};
367 omp_nest_lock_target_t lock
;
369 vars
[0].type
.src
= c_data
;
370 vars
[0].type
.dst
= c_data
;
371 vars
[0].direction
.bits
= c_parameter_inout
;
374 OFFLOAD_TARGET_ENTER(ofld
, 1, vars
, NULL
);
375 omp_unset_nest_lock(&lock
.lock
);
376 OFFLOAD_TARGET_LEAVE(ofld
);
379 DLL_LOCAL
void omp_test_nest_lock_lrb(
383 OFFLOAD ofld
= (OFFLOAD
) ofld_
;
384 VarDesc vars
[2] = {0};
385 omp_nest_lock_target_t lock
;
388 vars
[0].type
.src
= c_data
;
389 vars
[0].type
.dst
= c_data
;
390 vars
[0].direction
.bits
= c_parameter_inout
;
393 vars
[1].type
.src
= c_data
;
394 vars
[1].type
.dst
= c_data
;
395 vars
[1].direction
.bits
= c_parameter_out
;
396 vars
[1].ptr
= &result
;
398 OFFLOAD_TARGET_ENTER(ofld
, 2, vars
, NULL
);
399 result
= omp_test_nest_lock(&lock
.lock
);
400 OFFLOAD_TARGET_LEAVE(ofld
);
403 // Target-side stubs for the host functions (to avoid unresolveds)
404 // These are needed for the offloadm table
406 void omp_set_num_threads_target(
407 TARGET_TYPE target_type
,
414 int omp_get_max_threads_target(
415 TARGET_TYPE target_type
,
422 int omp_get_num_procs_target(
423 TARGET_TYPE target_type
,
430 void omp_set_dynamic_target(
431 TARGET_TYPE target_type
,
438 int omp_get_dynamic_target(
439 TARGET_TYPE target_type
,
446 void omp_set_nested_target(
447 TARGET_TYPE target_type
,
454 int omp_get_nested_target(
455 TARGET_TYPE target_type
,
462 void omp_set_schedule_target(
463 TARGET_TYPE target_type
,
471 void omp_get_schedule_target(
472 TARGET_TYPE target_type
,
480 void omp_init_lock_target(
481 TARGET_TYPE target_type
,
483 omp_lock_target_t
*lock
488 void omp_destroy_lock_target(
489 TARGET_TYPE target_type
,
491 omp_lock_target_t
*lock
496 void omp_set_lock_target(
497 TARGET_TYPE target_type
,
499 omp_lock_target_t
*lock
504 void omp_unset_lock_target(
505 TARGET_TYPE target_type
,
507 omp_lock_target_t
*lock
512 int omp_test_lock_target(
513 TARGET_TYPE target_type
,
515 omp_lock_target_t
*lock
521 void omp_init_nest_lock_target(
522 TARGET_TYPE target_type
,
524 omp_nest_lock_target_t
*lock
529 void omp_destroy_nest_lock_target(
530 TARGET_TYPE target_type
,
532 omp_nest_lock_target_t
*lock
537 void omp_set_nest_lock_target(
538 TARGET_TYPE target_type
,
540 omp_nest_lock_target_t
*lock
545 void omp_unset_nest_lock_target(
546 TARGET_TYPE target_type
,
548 omp_nest_lock_target_t
*lock
553 int omp_test_nest_lock_target(
554 TARGET_TYPE target_type
,
556 omp_nest_lock_target_t
*lock