2018-01-12 Richard Biener <rguenther@suse.de>
[official-gcc.git] / liboffloadmic / runtime / offload_orsl.cpp
bloba2ab6743ab5a4baf1793e3e9a03228c50a4d0219
1 /*
2 Copyright (c) 2014-2016 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 "offload_orsl.h"
32 #include <stdlib.h>
33 #include "offload_host.h"
34 #include "orsl-lite/include/orsl-lite.h"
36 namespace ORSL {
38 static bool is_enabled = false;
39 static const ORSLTag my_tag = (const ORSLTag) "Offload";
41 void init()
43 const char *env_var = getenv("OFFLOAD_ENABLE_ORSL");
44 if (env_var != 0 && *env_var != '\0') {
45 int64_t new_val;
46 if (__offload_parse_int_string(env_var, new_val)) {
47 is_enabled = new_val;
49 else {
50 LIBOFFLOAD_ERROR(c_invalid_env_var_int_value,
51 "OFFLOAD_ENABLE_ORSL");
55 if (is_enabled) {
56 OFFLOAD_DEBUG_TRACE(2, "ORSL is enabled\n");
58 else {
59 OFFLOAD_DEBUG_TRACE(2, "ORSL is disabled\n");
63 bool reserve(int device)
65 if (is_enabled) {
66 int pnum = mic_engines[device].get_physical_index();
67 ORSLBusySet bset;
69 bset.type = BUSY_SET_FULL;
70 if (ORSLReserve(1, &pnum, &bset, my_tag) != 0) {
71 return false;
74 return true;
77 bool try_reserve(int device)
79 if (is_enabled) {
80 int pnum = mic_engines[device].get_physical_index();
81 ORSLBusySet bset;
83 bset.type = BUSY_SET_FULL;
84 if (ORSLTryReserve(1, &pnum, &bset, my_tag) != 0) {
85 return false;
88 return true;
91 void release(int device)
93 if (is_enabled) {
94 int pnum = mic_engines[device].get_physical_index();
95 ORSLBusySet bset;
97 bset.type = BUSY_SET_FULL;
98 if (ORSLRelease(1, &pnum, &bset, my_tag) != 0) {
99 // should never get here
104 } // namespace ORSL