blob: 6162f8aa2b0e0677b81f1fba3fed714e9f130fd4 [file] [log] [blame]
Jim Cownie33f7b242014-04-09 15:40:23 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.txt for details.
7//
8//===----------------------------------------------------------------------===//
9
10
11#include "offload_orsl.h"
12#include <stdlib.h>
13#include "offload_host.h"
14#include "orsl-lite/include/orsl-lite.h"
15
16namespace ORSL {
17
18static bool is_enabled = false;
19static const ORSLTag my_tag = "Offload";
20
21void init()
22{
23 const char *env_var = getenv("OFFLOAD_ENABLE_ORSL");
24 if (env_var != 0 && *env_var != '\0') {
25 int64_t new_val;
26 if (__offload_parse_int_string(env_var, new_val)) {
27 is_enabled = new_val;
28 }
29 else {
30 LIBOFFLOAD_ERROR(c_invalid_env_var_int_value,
31 "OFFLOAD_ENABLE_ORSL");
32 }
33 }
34
35 if (is_enabled) {
36 OFFLOAD_DEBUG_TRACE(2, "ORSL is enabled\n");
37 }
38 else {
39 OFFLOAD_DEBUG_TRACE(2, "ORSL is disabled\n");
40 }
41}
42
43bool reserve(int device)
44{
45 if (is_enabled) {
46 int pnum = mic_engines[device].get_physical_index();
47 ORSLBusySet bset;
48
49 bset.type = BUSY_SET_FULL;
50 if (ORSLReserve(1, &pnum, &bset, my_tag) != 0) {
51 return false;
52 }
53 }
54 return true;
55}
56
57bool try_reserve(int device)
58{
59 if (is_enabled) {
60 int pnum = mic_engines[device].get_physical_index();
61 ORSLBusySet bset;
62
63 bset.type = BUSY_SET_FULL;
64 if (ORSLTryReserve(1, &pnum, &bset, my_tag) != 0) {
65 return false;
66 }
67 }
68 return true;
69}
70
71void release(int device)
72{
73 if (is_enabled) {
74 int pnum = mic_engines[device].get_physical_index();
75 ORSLBusySet bset;
76
77 bset.type = BUSY_SET_FULL;
78 if (ORSLRelease(1, &pnum, &bset, my_tag) != 0) {
79 // should never get here
80 }
81 }
82}
83
84} // namespace ORSL