summaryrefslogtreecommitdiffstats
path: root/openmp/offload/src/offload_orsl.cpp
blob: 6162f8aa2b0e0677b81f1fba3fed714e9f130fd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.txt for details.
//
//===----------------------------------------------------------------------===//


#include "offload_orsl.h"
#include <stdlib.h>
#include "offload_host.h"
#include "orsl-lite/include/orsl-lite.h"

namespace ORSL {

static bool            is_enabled = false;
static const ORSLTag   my_tag = "Offload";

void init()
{
    const char *env_var = getenv("OFFLOAD_ENABLE_ORSL");
    if (env_var != 0 && *env_var != '\0') {
        int64_t new_val;
        if (__offload_parse_int_string(env_var, new_val)) {
            is_enabled = new_val;
        }
        else {
            LIBOFFLOAD_ERROR(c_invalid_env_var_int_value,
                             "OFFLOAD_ENABLE_ORSL");
        }
    }

    if (is_enabled) {
        OFFLOAD_DEBUG_TRACE(2, "ORSL is enabled\n");
    }
    else {
        OFFLOAD_DEBUG_TRACE(2, "ORSL is disabled\n");
    }
}

bool reserve(int device)
{
    if (is_enabled) {
        int pnum = mic_engines[device].get_physical_index();
        ORSLBusySet bset;

        bset.type = BUSY_SET_FULL;
        if (ORSLReserve(1, &pnum, &bset, my_tag) != 0) {
            return false;
        }
    }
    return true;
}

bool try_reserve(int device)
{
    if (is_enabled) {
        int pnum = mic_engines[device].get_physical_index();
        ORSLBusySet bset;

        bset.type = BUSY_SET_FULL;
        if (ORSLTryReserve(1, &pnum, &bset, my_tag) != 0) {
            return false;
        }
    }
    return true;
}

void release(int device)
{
    if (is_enabled) {
        int pnum = mic_engines[device].get_physical_index();
        ORSLBusySet bset;

        bset.type = BUSY_SET_FULL;
        if (ORSLRelease(1, &pnum, &bset, my_tag) != 0) {
            // should never get here
        }
    }
}

} // namespace ORSL
OpenPOWER on IntegriCloud