File: os_context_win.cpp

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 (130 lines) | stat: -rw-r--r-- 5,135 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
/*
 * Copyright (C) 2020-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/os_interface/windows/os_context_win.h"

#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/os_interface/product_helper.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
#include "shared/source/os_interface/windows/wddm/wddm_interface.h"

namespace NEO {

OsContext *OsContextWin::create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor) {
    if (osInterface && osInterface->getDriverModel()->getDriverModelType() == DriverModelType::wddm) {
        return new OsContextWin(*osInterface->getDriverModel()->as<Wddm>(), rootDeviceIndex, contextId, engineDescriptor);
    }
    return new OsContext(rootDeviceIndex, contextId, engineDescriptor);
}

OsContextWin::OsContextWin(Wddm &wddm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)
    : OsContext(rootDeviceIndex, contextId, engineDescriptor),
      residencyController(wddm),
      wddm(wddm) {
}

bool OsContextWin::initializeContext(bool allocateInterrupt) {

    NEO::EnvironmentVariableReader envReader;
    bool disableContextCreationFlag = envReader.getSetting("NEO_L0_SYSMAN_NO_CONTEXT_MODE", false);
    if (!disableContextCreationFlag) {
        if (wddm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled()) {
            debuggableContext = wddm.getRootDeviceEnvironment().osInterface->isDebugAttachAvailable() && !isInternalEngine();
        }
        auto wddmInterface = wddm.getWddmInterface();
        UNRECOVERABLE_IF(!wddm.createContext(*this));

        if (wddmInterface->hwQueuesSupported()) {
            UNRECOVERABLE_IF(!wddmInterface->createHwQueue(*this));
        }
        UNRECOVERABLE_IF(!wddmInterface->createMonitoredFence(*this));

        residencyController.registerCallback();
        UNRECOVERABLE_IF(!residencyController.isInitialized());
    }

    return true;
}

void OsContextWin::reInitializeContext() {
    NEO::EnvironmentVariableReader envReader;
    bool disableContextCreationFlag = envReader.getSetting("NEO_L0_SYSMAN_NO_CONTEXT_MODE", false);
    if (!disableContextCreationFlag && !isPartOfContextGroup()) {
        if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
            wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
            wddm.destroyContext(wddmContextHandle);
        }
        UNRECOVERABLE_IF(!wddm.createContext(*this));
        auto wddmInterface = wddm.getWddmInterface();
        if (wddmInterface->hwQueuesSupported()) {
            UNRECOVERABLE_IF(!wddmInterface->createHwQueue(*this));
            UNRECOVERABLE_IF(!wddmInterface->createMonitoredFence(*this));
        }
    }
}

void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cpuAddress, D3DGPU_VIRTUAL_ADDRESS &gpuAddress) {
    monitoredFence.lastSubmittedFence = 0;
    monitoredFence.currentFenceValue = 1;
    monitoredFence.fenceHandle = handle;
    monitoredFence.cpuAddress = cpuAddress;
    monitoredFence.gpuAddress = gpuAddress;
}

void OsContextWin::getDeviceLuidArray(std::vector<uint8_t> &luidData, size_t arraySize) {
    auto *wddm = this->getWddm();
    auto *hwDeviceID = wddm->getHwDeviceId();
    auto luid = hwDeviceID->getAdapterLuid();
    luidData.reserve(arraySize);
    for (size_t i = 0; i < arraySize; i++) {
        char *luidArray = nullptr;
        if (i < 4) {
            luidArray = (char *)&luid.LowPart;
            luidData.emplace(luidData.end(), luidArray[i]);
        } else {
            luidArray = (char *)&luid.HighPart;
            luidData.emplace(luidData.end(), luidArray[i - 4]);
        }
    }
}

uint32_t OsContextWin::getDeviceNodeMask() {
    auto *wddm = this->getWddm();
    auto *hwDeviceID = wddm->getHwDeviceId();
    return hwDeviceID->getAdapterNodeMask();
}

uint64_t OsContextWin::getOfflineDumpContextId(uint32_t deviceIndex) const {
    return 0;
}

bool OsContextWin::isDirectSubmissionSupported() const {
    auto &rootDeviceEnvironment = wddm.getRootDeviceEnvironment();
    auto &productHelper = rootDeviceEnvironment.getHelper<ProductHelper>();
    auto isWSL = rootDeviceEnvironment.isWddmOnLinux();

    return !isWSL && productHelper.isDirectSubmissionSupported();
}

OsContextWin::~OsContextWin() {
    if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
        wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
        if (getMonitoredFence().fenceHandle != hardwareQueue.progressFenceHandle) {
            wddm.getWddmInterface()->destroyMonitorFence(getMonitoredFence().fenceHandle);
        }

        if (!isPartOfContextGroup() ||
            (isPartOfContextGroup() && getPrimaryContext() == nullptr)) {
            wddm.destroyContext(wddmContextHandle);
        }
    }
}

} // namespace NEO