2 Copyright (c) 2014 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_host.h"
37 void omp_set_default_device(int num
) __GOMP_NOTHROW
40 __omp_device_num
= num
;
44 int omp_get_default_device(void) __GOMP_NOTHROW
46 return __omp_device_num
;
49 int omp_get_num_devices() __GOMP_NOTHROW
51 __offload_init_library();
52 return mic_engines_total
;
55 // OpenMP API wrappers
57 static void omp_set_int_target(
58 TARGET_TYPE target_type
,
64 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
67 VarDesc vars
[1] = {0};
69 vars
[0].type
.src
= c_data
;
70 vars
[0].type
.dst
= c_data
;
71 vars
[0].direction
.bits
= c_parameter_in
;
72 vars
[0].size
= sizeof(int);
74 vars
[0].ptr
= &setting
;
76 OFFLOAD_OFFLOAD(ofld
, f_name
, 0, 1, vars
, NULL
, 0, 0, 0);
80 static int omp_get_int_target(
81 TARGET_TYPE target_type
,
88 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
91 VarDesc vars
[1] = {0};
93 vars
[0].type
.src
= c_data
;
94 vars
[0].type
.dst
= c_data
;
95 vars
[0].direction
.bits
= c_parameter_out
;
96 vars
[0].size
= sizeof(int);
98 vars
[0].ptr
= &setting
;
100 OFFLOAD_OFFLOAD(ofld
, f_name
, 0, 1, vars
, NULL
, 0, 0, 0);
105 void omp_set_num_threads_target(
106 TARGET_TYPE target_type
,
111 omp_set_int_target(target_type
, target_number
, num_threads
,
112 "omp_set_num_threads_target");
115 int omp_get_max_threads_target(
116 TARGET_TYPE target_type
,
120 return omp_get_int_target(target_type
, target_number
,
121 "omp_get_max_threads_target");
124 int omp_get_num_procs_target(
125 TARGET_TYPE target_type
,
129 return omp_get_int_target(target_type
, target_number
,
130 "omp_get_num_procs_target");
133 void omp_set_dynamic_target(
134 TARGET_TYPE target_type
,
139 omp_set_int_target(target_type
, target_number
, num_threads
,
140 "omp_set_dynamic_target");
143 int omp_get_dynamic_target(
144 TARGET_TYPE target_type
,
148 return omp_get_int_target(target_type
, target_number
,
149 "omp_get_dynamic_target");
152 void omp_set_nested_target(
153 TARGET_TYPE target_type
,
158 omp_set_int_target(target_type
, target_number
, nested
,
159 "omp_set_nested_target");
162 int omp_get_nested_target(
163 TARGET_TYPE target_type
,
167 return omp_get_int_target(target_type
, target_number
,
168 "omp_get_nested_target");
171 void omp_set_schedule_target(
172 TARGET_TYPE target_type
,
178 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
181 VarDesc vars
[2] = {0};
183 vars
[0].type
.src
= c_data
;
184 vars
[0].type
.dst
= c_data
;
185 vars
[0].direction
.bits
= c_parameter_in
;
186 vars
[0].size
= sizeof(omp_sched_t
);
190 vars
[1].type
.src
= c_data
;
191 vars
[1].type
.dst
= c_data
;
192 vars
[1].direction
.bits
= c_parameter_in
;
193 vars
[1].size
= sizeof(int);
195 vars
[1].ptr
= &modifier
;
197 OFFLOAD_OFFLOAD(ofld
, "omp_set_schedule_target",
198 0, 2, vars
, NULL
, 0, 0, 0);
202 void omp_get_schedule_target(
203 TARGET_TYPE target_type
,
209 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
212 VarDesc vars
[2] = {0};
214 vars
[0].type
.src
= c_data
;
215 vars
[0].type
.dst
= c_data
;
216 vars
[0].direction
.bits
= c_parameter_out
;
217 vars
[0].size
= sizeof(omp_sched_t
);
221 vars
[1].type
.src
= c_data
;
222 vars
[1].type
.dst
= c_data
;
223 vars
[1].direction
.bits
= c_parameter_out
;
224 vars
[1].size
= sizeof(int);
226 vars
[1].ptr
= modifier
;
228 OFFLOAD_OFFLOAD(ofld
, "omp_get_schedule_target",
229 0, 2, vars
, NULL
, 0, 0, 0);
233 // lock API functions
235 void omp_init_lock_target(
236 TARGET_TYPE target_type
,
238 omp_lock_target_t
*lock
241 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
244 VarDesc vars
[1] = {0};
246 vars
[0].type
.src
= c_data
;
247 vars
[0].type
.dst
= c_data
;
248 vars
[0].direction
.bits
= c_parameter_out
;
249 vars
[0].size
= sizeof(omp_lock_target_t
);
253 OFFLOAD_OFFLOAD(ofld
, "omp_init_lock_target",
254 0, 1, vars
, NULL
, 0, 0, 0);
258 void omp_destroy_lock_target(
259 TARGET_TYPE target_type
,
261 omp_lock_target_t
*lock
264 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
267 VarDesc vars
[1] = {0};
269 vars
[0].type
.src
= c_data
;
270 vars
[0].type
.dst
= c_data
;
271 vars
[0].direction
.bits
= c_parameter_in
;
272 vars
[0].size
= sizeof(omp_lock_target_t
);
276 OFFLOAD_OFFLOAD(ofld
, "omp_destroy_lock_target",
277 0, 1, vars
, NULL
, 0, 0, 0);
281 void omp_set_lock_target(
282 TARGET_TYPE target_type
,
284 omp_lock_target_t
*lock
287 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
290 VarDesc vars
[1] = {0};
292 vars
[0].type
.src
= c_data
;
293 vars
[0].type
.dst
= c_data
;
294 vars
[0].direction
.bits
= c_parameter_inout
;
295 vars
[0].size
= sizeof(omp_lock_target_t
);
299 OFFLOAD_OFFLOAD(ofld
, "omp_set_lock_target",
300 0, 1, vars
, NULL
, 0, 0, 0);
304 void omp_unset_lock_target(
305 TARGET_TYPE target_type
,
307 omp_lock_target_t
*lock
310 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
313 VarDesc vars
[1] = {0};
315 vars
[0].type
.src
= c_data
;
316 vars
[0].type
.dst
= c_data
;
317 vars
[0].direction
.bits
= c_parameter_inout
;
318 vars
[0].size
= sizeof(omp_lock_target_t
);
322 OFFLOAD_OFFLOAD(ofld
, "omp_unset_lock_target",
323 0, 1, vars
, NULL
, 0, 0, 0);
327 int omp_test_lock_target(
328 TARGET_TYPE target_type
,
330 omp_lock_target_t
*lock
335 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
338 VarDesc vars
[2] = {0};
340 vars
[0].type
.src
= c_data
;
341 vars
[0].type
.dst
= c_data
;
342 vars
[0].direction
.bits
= c_parameter_inout
;
343 vars
[0].size
= sizeof(omp_lock_target_t
);
347 vars
[1].type
.src
= c_data
;
348 vars
[1].type
.dst
= c_data
;
349 vars
[1].direction
.bits
= c_parameter_out
;
350 vars
[1].size
= sizeof(int);
352 vars
[1].ptr
= &result
;
354 OFFLOAD_OFFLOAD(ofld
, "omp_test_lock_target",
355 0, 2, vars
, NULL
, 0, 0, 0);
360 // nested lock API functions
362 void omp_init_nest_lock_target(
363 TARGET_TYPE target_type
,
365 omp_nest_lock_target_t
*lock
368 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
371 VarDesc vars
[1] = {0};
373 vars
[0].type
.src
= c_data
;
374 vars
[0].type
.dst
= c_data
;
375 vars
[0].direction
.bits
= c_parameter_out
;
376 vars
[0].size
= sizeof(omp_nest_lock_target_t
);
380 OFFLOAD_OFFLOAD(ofld
, "omp_init_nest_lock_target",
381 0, 1, vars
, NULL
, 0, 0, 0);
385 void omp_destroy_nest_lock_target(
386 TARGET_TYPE target_type
,
388 omp_nest_lock_target_t
*lock
391 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
394 VarDesc vars
[1] = {0};
396 vars
[0].type
.src
= c_data
;
397 vars
[0].type
.dst
= c_data
;
398 vars
[0].direction
.bits
= c_parameter_in
;
399 vars
[0].size
= sizeof(omp_nest_lock_target_t
);
403 OFFLOAD_OFFLOAD(ofld
, "omp_destroy_nest_lock_target",
404 0, 1, vars
, NULL
, 0, 0, 0);
408 void omp_set_nest_lock_target(
409 TARGET_TYPE target_type
,
411 omp_nest_lock_target_t
*lock
414 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
417 VarDesc vars
[1] = {0};
419 vars
[0].type
.src
= c_data
;
420 vars
[0].type
.dst
= c_data
;
421 vars
[0].direction
.bits
= c_parameter_inout
;
422 vars
[0].size
= sizeof(omp_nest_lock_target_t
);
426 OFFLOAD_OFFLOAD(ofld
, "omp_set_nest_lock_target",
427 0, 1, vars
, NULL
, 0, 0, 0);
431 void omp_unset_nest_lock_target(
432 TARGET_TYPE target_type
,
434 omp_nest_lock_target_t
*lock
437 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
440 VarDesc vars
[1] = {0};
442 vars
[0].type
.src
= c_data
;
443 vars
[0].type
.dst
= c_data
;
444 vars
[0].direction
.bits
= c_parameter_inout
;
445 vars
[0].size
= sizeof(omp_nest_lock_target_t
);
449 OFFLOAD_OFFLOAD(ofld
, "omp_unset_nest_lock_target",
450 0, 1, vars
, NULL
, 0, 0, 0);
454 int omp_test_nest_lock_target(
455 TARGET_TYPE target_type
,
457 omp_nest_lock_target_t
*lock
462 OFFLOAD ofld
= OFFLOAD_TARGET_ACQUIRE(target_type
, target_number
, 0, NULL
,
465 VarDesc vars
[2] = {0};
467 vars
[0].type
.src
= c_data
;
468 vars
[0].type
.dst
= c_data
;
469 vars
[0].direction
.bits
= c_parameter_inout
;
470 vars
[0].size
= sizeof(omp_nest_lock_target_t
);
474 vars
[1].type
.src
= c_data
;
475 vars
[1].type
.dst
= c_data
;
476 vars
[1].direction
.bits
= c_parameter_out
;
477 vars
[1].size
= sizeof(int);
479 vars
[1].ptr
= &result
;
481 OFFLOAD_OFFLOAD(ofld
, "omp_test_nest_lock_target",
482 0, 2, vars
, NULL
, 0, 0, 0);