annotate liboffloadmic/runtime/offload_orsl.cpp @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
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 #include "offload_orsl.h"
kono
parents:
diff changeset
32 #include <stdlib.h>
kono
parents:
diff changeset
33 #include "offload_host.h"
kono
parents:
diff changeset
34 #include "orsl-lite/include/orsl-lite.h"
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 namespace ORSL {
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 static bool is_enabled = false;
kono
parents:
diff changeset
39 static const ORSLTag my_tag = (const ORSLTag) "Offload";
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 void init()
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 const char *env_var = getenv("OFFLOAD_ENABLE_ORSL");
kono
parents:
diff changeset
44 if (env_var != 0 && *env_var != '\0') {
kono
parents:
diff changeset
45 int64_t new_val;
kono
parents:
diff changeset
46 if (__offload_parse_int_string(env_var, new_val)) {
kono
parents:
diff changeset
47 is_enabled = new_val;
kono
parents:
diff changeset
48 }
kono
parents:
diff changeset
49 else {
kono
parents:
diff changeset
50 LIBOFFLOAD_ERROR(c_invalid_env_var_int_value,
kono
parents:
diff changeset
51 "OFFLOAD_ENABLE_ORSL");
kono
parents:
diff changeset
52 }
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 if (is_enabled) {
kono
parents:
diff changeset
56 OFFLOAD_DEBUG_TRACE(2, "ORSL is enabled\n");
kono
parents:
diff changeset
57 }
kono
parents:
diff changeset
58 else {
kono
parents:
diff changeset
59 OFFLOAD_DEBUG_TRACE(2, "ORSL is disabled\n");
kono
parents:
diff changeset
60 }
kono
parents:
diff changeset
61 }
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 bool reserve(int device)
kono
parents:
diff changeset
64 {
kono
parents:
diff changeset
65 if (is_enabled) {
kono
parents:
diff changeset
66 int pnum = mic_engines[device].get_physical_index();
kono
parents:
diff changeset
67 ORSLBusySet bset;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 bset.type = BUSY_SET_FULL;
kono
parents:
diff changeset
70 if (ORSLReserve(1, &pnum, &bset, my_tag) != 0) {
kono
parents:
diff changeset
71 return false;
kono
parents:
diff changeset
72 }
kono
parents:
diff changeset
73 }
kono
parents:
diff changeset
74 return true;
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 bool try_reserve(int device)
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 if (is_enabled) {
kono
parents:
diff changeset
80 int pnum = mic_engines[device].get_physical_index();
kono
parents:
diff changeset
81 ORSLBusySet bset;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 bset.type = BUSY_SET_FULL;
kono
parents:
diff changeset
84 if (ORSLTryReserve(1, &pnum, &bset, my_tag) != 0) {
kono
parents:
diff changeset
85 return false;
kono
parents:
diff changeset
86 }
kono
parents:
diff changeset
87 }
kono
parents:
diff changeset
88 return true;
kono
parents:
diff changeset
89 }
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 void release(int device)
kono
parents:
diff changeset
92 {
kono
parents:
diff changeset
93 if (is_enabled) {
kono
parents:
diff changeset
94 int pnum = mic_engines[device].get_physical_index();
kono
parents:
diff changeset
95 ORSLBusySet bset;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 bset.type = BUSY_SET_FULL;
kono
parents:
diff changeset
98 if (ORSLRelease(1, &pnum, &bset, my_tag) != 0) {
kono
parents:
diff changeset
99 // should never get here
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101 }
kono
parents:
diff changeset
102 }
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 } // namespace ORSL