S/390: Deprecate g5 and g6 CPU levels
[official-gcc.git] / liboffloadmic / runtime / offload_omp_target.cpp
blob91baef5da87d90148d551c9a4ae8a1eb0f056cfc
1 /*
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
6 are met:
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.
31 #include <omp.h>
32 #include "offload.h"
33 #include "compiler_if_target.h"
35 // OpenMP API
37 void omp_set_default_device(int num) __GOMP_NOTHROW
41 int omp_get_default_device(void) __GOMP_NOTHROW
43 return mic_index;
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(
54 void *ofld_,
55 int setting
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(
71 void *ofld_
74 OFFLOAD ofld = (OFFLOAD) ofld_;
75 VarDesc vars[1] = {0};
76 int setting;
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);
86 return setting;
89 DLL_LOCAL void omp_set_num_threads_lrb(
90 void *ofld
93 int num_threads;
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(
100 void *ofld
103 int num_threads;
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(
110 void *ofld
113 int num_procs;
115 num_procs = omp_get_num_procs();
116 omp_send_int_to_host(ofld, num_procs);
119 DLL_LOCAL void omp_set_dynamic_lrb(
120 void *ofld
123 int dynamic;
125 dynamic = omp_get_int_from_host(ofld);
126 omp_set_dynamic(dynamic);
129 DLL_LOCAL void omp_get_dynamic_lrb(
130 void *ofld
133 int dynamic;
135 dynamic = omp_get_dynamic();
136 omp_send_int_to_host(ofld, dynamic);
139 DLL_LOCAL void omp_set_nested_lrb(
140 void *ofld
143 int nested;
145 nested = omp_get_int_from_host(ofld);
146 omp_set_nested(nested);
149 DLL_LOCAL void omp_get_nested_lrb(
150 void *ofld
153 int nested;
155 nested = omp_get_nested();
156 omp_send_int_to_host(ofld, nested);
159 DLL_LOCAL void omp_set_schedule_lrb(
160 void *ofld_
163 OFFLOAD ofld = (OFFLOAD) ofld_;
164 VarDesc vars[2] = {0};
165 omp_sched_t kind;
166 int modifier;
168 vars[0].type.src = c_data;
169 vars[0].type.dst = c_data;
170 vars[0].direction.bits = c_parameter_in;
171 vars[0].ptr = &kind;
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(
184 void *ofld_
187 OFFLOAD ofld = (OFFLOAD) ofld_;
188 VarDesc vars[2] = {0};
189 omp_sched_t kind;
190 int modifier;
192 vars[0].type.src = c_data;
193 vars[0].type.dst = c_data;
194 vars[0].direction.bits = c_parameter_out;
195 vars[0].ptr = &kind;
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(
210 void *ofld_
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;
220 vars[0].ptr = &lock;
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(
228 void *ofld_
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;
238 vars[0].ptr = &lock;
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(
246 void *ofld_
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;
256 vars[0].ptr = &lock;
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(
264 void *ofld_
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;
274 vars[0].ptr = &lock;
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(
282 void *ofld_
285 OFFLOAD ofld = (OFFLOAD) ofld_;
286 VarDesc vars[2] = {0};
287 omp_lock_target_t lock;
288 int result;
290 vars[0].type.src = c_data;
291 vars[0].type.dst = c_data;
292 vars[0].direction.bits = c_parameter_inout;
293 vars[0].ptr = &lock;
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(
308 void *ofld_
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;
318 vars[0].ptr = &lock;
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(
326 void *ofld_
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;
336 vars[0].ptr = &lock;
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(
344 void *ofld_
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;
354 vars[0].ptr = &lock;
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(
362 void *ofld_
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;
372 vars[0].ptr = &lock;
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(
380 void *ofld_
383 OFFLOAD ofld = (OFFLOAD) ofld_;
384 VarDesc vars[2] = {0};
385 omp_nest_lock_target_t lock;
386 int result;
388 vars[0].type.src = c_data;
389 vars[0].type.dst = c_data;
390 vars[0].direction.bits = c_parameter_inout;
391 vars[0].ptr = &lock;
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,
408 int target_number,
409 int num_threads
414 int omp_get_max_threads_target(
415 TARGET_TYPE target_type,
416 int target_number
419 return 0;
422 int omp_get_num_procs_target(
423 TARGET_TYPE target_type,
424 int target_number
427 return 0;
430 void omp_set_dynamic_target(
431 TARGET_TYPE target_type,
432 int target_number,
433 int num_threads
438 int omp_get_dynamic_target(
439 TARGET_TYPE target_type,
440 int target_number
443 return 0;
446 void omp_set_nested_target(
447 TARGET_TYPE target_type,
448 int target_number,
449 int num_threads
454 int omp_get_nested_target(
455 TARGET_TYPE target_type,
456 int target_number
459 return 0;
462 void omp_set_schedule_target(
463 TARGET_TYPE target_type,
464 int target_number,
465 omp_sched_t kind,
466 int modifier
471 void omp_get_schedule_target(
472 TARGET_TYPE target_type,
473 int target_number,
474 omp_sched_t *kind,
475 int *modifier
480 void omp_init_lock_target(
481 TARGET_TYPE target_type,
482 int target_number,
483 omp_lock_target_t *lock
488 void omp_destroy_lock_target(
489 TARGET_TYPE target_type,
490 int target_number,
491 omp_lock_target_t *lock
496 void omp_set_lock_target(
497 TARGET_TYPE target_type,
498 int target_number,
499 omp_lock_target_t *lock
504 void omp_unset_lock_target(
505 TARGET_TYPE target_type,
506 int target_number,
507 omp_lock_target_t *lock
512 int omp_test_lock_target(
513 TARGET_TYPE target_type,
514 int target_number,
515 omp_lock_target_t *lock
518 return 0;
521 void omp_init_nest_lock_target(
522 TARGET_TYPE target_type,
523 int target_number,
524 omp_nest_lock_target_t *lock
529 void omp_destroy_nest_lock_target(
530 TARGET_TYPE target_type,
531 int target_number,
532 omp_nest_lock_target_t *lock
537 void omp_set_nest_lock_target(
538 TARGET_TYPE target_type,
539 int target_number,
540 omp_nest_lock_target_t *lock
545 void omp_unset_nest_lock_target(
546 TARGET_TYPE target_type,
547 int target_number,
548 omp_nest_lock_target_t *lock
553 int omp_test_nest_lock_target(
554 TARGET_TYPE target_type,
555 int target_number,
556 omp_nest_lock_target_t *lock
559 return 0;