File: os_context.h

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (144 lines) | stat: -rw-r--r-- 5,863 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once
#include "shared/source/helpers/engine_node_helper.h"
#include "shared/source/helpers/mt_helpers.h"
#include "shared/source/utilities/reference_tracked_object.h"

#include <mutex>
#include <optional>

namespace NEO {
class OSInterface;

struct DirectSubmissionProperties;
struct HardwareInfo;

class OsContext : public ReferenceTrackedObject<OsContext> {
  public:
    OsContext(uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor);
    static OsContext *create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor);

    bool isImmediateContextInitializationEnabled(bool isDefaultEngine) const;
    bool isInitialized() const { return contextInitialized; }
    bool ensureContextInitialized(bool allocateInterrupt);

    uint32_t getContextId() const { return contextId; }
    virtual uint64_t getOfflineDumpContextId(uint32_t deviceIndex) const { return 0; };
    uint32_t getNumSupportedDevices() const { return numSupportedDevices; }
    DeviceBitfield getDeviceBitfield() const { return deviceBitfield; }
    PreemptionMode getPreemptionMode() const { return preemptionMode; }
    const aub_stream::EngineType &getEngineType() const { return engineType; }
    EngineUsage getEngineUsage() const { return engineUsage; }
    void overrideEngineUsage(EngineUsage usage) { engineUsage = usage; }
    void overridePriority(int newPriority) {
        if (!priorityLevel.has_value()) {
            priorityLevel = newPriority;
        }
    }

    bool hasPriorityLevel() const { return priorityLevel.has_value(); }
    int getPriorityLevel() const { return priorityLevel.value_or(0); }
    bool isRegular() const { return engineUsage == EngineUsage::regular; }
    bool isLowPriority() const { return engineUsage == EngineUsage::lowPriority; }
    bool isHighPriority() const { return engineUsage == EngineUsage::highPriority; }
    bool isInternalEngine() const { return engineUsage == EngineUsage::internal; }
    bool isCooperativeEngine() const { return engineUsage == EngineUsage::cooperative; }
    bool isRootDevice() const { return rootDevice; }
    virtual bool isDirectSubmissionSupported() const { return false; }
    bool isDefaultContext() const { return defaultContext; }
    void setDefaultContext(bool value) { defaultContext = value; }
    bool isDirectSubmissionActive() const { return directSubmissionActive; }
    bool isDebuggableContext() { return debuggableContext; }
    void setDirectSubmissionActive() { directSubmissionActive = true; }

    bool isDirectSubmissionAvailable(const HardwareInfo &hwInfo, bool &submitOnInit);
    bool checkDirectSubmissionSupportsEngine(const DirectSubmissionProperties &directSubmissionProperty,
                                             aub_stream::EngineType contextEngineType,
                                             bool &startOnInit,
                                             bool &startInContext);
    virtual void reInitializeContext() {}

    static constexpr uint8_t getUmdPowerHintMax() { return NEO::OsContext::powerHintMax; }
    uint8_t getUmdPowerHintValue() { return powerHintValue; }
    void setUmdPowerHintValue(uint8_t powerHintValue) { this->powerHintValue = powerHintValue; }

    uint32_t getRootDeviceIndex() { return rootDeviceIndex; }

    void setNewResourceBound() {
        tlbFlushCounter++;
    };

    uint32_t peekTlbFlushCounter() const { return tlbFlushCounter.load(); }

    void setTlbFlushed(uint32_t newCounter) {
        NEO::MultiThreadHelpers::interlockedMax(lastFlushedTlbFlushCounter, newCounter);
    };
    bool isTlbFlushRequired() const {
        return (tlbFlushCounter.load() > lastFlushedTlbFlushCounter.load());
    };

    void setPrimaryContext(const OsContext *primary) {
        primaryContext = primary;
        contextGroupCount = primary->contextGroupCount;
    }
    const OsContext *getPrimaryContext() const {
        return primaryContext;
    }
    void setIsPrimaryEngine(const bool isPrimaryEngine) {
        this->isPrimaryEngine = isPrimaryEngine;
    }
    bool getIsPrimaryEngine() const {
        return this->isPrimaryEngine;
    }
    void setIsDefaultEngine(const bool isDefaultEngine) {
        this->isDefaultEngine = isDefaultEngine;
    }
    bool getIsDefaultEngine() const {
        return this->isDefaultEngine;
    }
    void setContextGroupCount(uint32_t contextGroupCount) {
        this->contextGroupCount = contextGroupCount;
    }
    uint32_t getContextGroupCount() {
        return contextGroupCount;
    }
    bool isPartOfContextGroup() const {
        return contextGroupCount > 0;
    }
    virtual bool isDirectSubmissionLightActive() const { return false; }

  protected:
    virtual bool initializeContext(bool allocateInterrupt) { return true; }

    std::atomic<uint32_t> tlbFlushCounter{0};
    std::atomic<uint32_t> lastFlushedTlbFlushCounter{0};

    const uint32_t rootDeviceIndex;
    const uint32_t contextId;
    const DeviceBitfield deviceBitfield;
    const PreemptionMode preemptionMode;
    const uint32_t numSupportedDevices;
    aub_stream::EngineType engineType = aub_stream::ENGINE_RCS;
    EngineUsage engineUsage;
    std::optional<int> priorityLevel;
    const bool rootDevice = false;
    bool defaultContext = false;
    bool directSubmissionActive = false;
    std::once_flag contextInitializedFlag = {};
    bool contextInitialized = false;
    bool debuggableContext = false;
    uint8_t powerHintValue = 0;
    static constexpr inline uint8_t powerHintMax = 100u; // by definition: 100% power-saving

    uint32_t contextGroupCount = 0;
    const OsContext *primaryContext = nullptr;
    bool isPrimaryEngine = false;
    bool isDefaultEngine = false;
};
} // namespace NEO