File: execution_environment.h

package info (click to toggle)
intel-compute-runtime 25.35.35096.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,324 kB
  • sloc: cpp: 926,243; lisp: 3,433; sh: 715; makefile: 162; python: 21
file content (116 lines) | stat: -rw-r--r-- 4,768 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
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once
#include "shared/source/debugger/debugger.h"
#include "shared/source/helpers/device_hierarchy_mode.h"
#include "shared/source/utilities/reference_tracked_object.h"

#include <mutex>
#include <stdarg.h>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>

namespace NEO {
class DirectSubmissionController;
class UnifiedMemoryReuseCleaner;
class GfxCoreHelper;
class MemoryManager;
struct OsEnvironment;
struct RootDeviceEnvironment;

class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> {

  public:
    ExecutionEnvironment();
    ~ExecutionEnvironment() override;

    MOCKABLE_VIRTUAL bool initializeMemoryManager();
    void calculateMaxOsContextCount();
    int clearErrorDescription();
    virtual void prepareRootDeviceEnvironments(uint32_t numRootDevices);
    void prepareRootDeviceEnvironment(const uint32_t rootDeviceIndexForReInit);
    void parseAffinityMask();
    void adjustCcsCount();
    void adjustCcsCount(const uint32_t rootDeviceIndex) const;
    void sortNeoDevices();
    void setDeviceHierarchyMode(const GfxCoreHelper &gfxCoreHelper);
    void setDeviceHierarchyMode(const DeviceHierarchyMode deviceHierarchyMode) {
        this->deviceHierarchyMode = deviceHierarchyMode;
    }
    DeviceHierarchyMode getDeviceHierarchyMode() const { return deviceHierarchyMode; }
    void adjustRootDeviceEnvironments();
    void prepareForCleanup() const;
    void configureCcsMode();
    void setDebuggingMode(DebuggingMode debuggingMode) {
        debuggingEnabledMode = debuggingMode;
    }
    DebuggingMode getDebuggingMode() const { return debuggingEnabledMode; }
    bool isDebuggingEnabled() const { return debuggingEnabledMode != DebuggingMode::disabled; }
    void setMetricsEnabled(bool value) {
        this->metricsEnabled = value;
    }
    void getErrorDescription(const char **ppString);
    bool getSubDeviceHierarchy(uint32_t index, std::tuple<uint32_t, uint32_t, uint32_t> *subDeviceMap);
    bool areMetricsEnabled() { return this->metricsEnabled; }
    int setErrorDescription(const std::string &str);
    void setFP64EmulationEnabled() {
        fp64EmulationEnabled = true;
    }
    bool isFP64EmulationEnabled() const { return fp64EmulationEnabled; }
    void setDevicePermissionError(bool value) {
        devicePermissionError = value;
    }
    bool isDevicePermissionError() const { return devicePermissionError; }

    void setOneApiPvcWaEnv(bool val) {
        oneApiPvcWaEnv = val;
    }
    bool isOneApiPvcWaEnv() const { return oneApiPvcWaEnv; }

    DirectSubmissionController *initializeDirectSubmissionController();
    void initializeUnifiedMemoryReuseCleaner(bool isAnyDirectSubmissionLightEnabled);

    std::unique_lock<std::mutex> obtainPeerAccessQueryLock() {
        return std::unique_lock<std::mutex>(peerAccessQueryMutex);
    }

    std::unique_ptr<MemoryManager> memoryManager;
    std::unique_ptr<UnifiedMemoryReuseCleaner> unifiedMemoryReuseCleaner;
    std::unique_ptr<DirectSubmissionController> directSubmissionController;
    std::unique_ptr<OsEnvironment> osEnvironment;
    std::vector<std::unique_ptr<RootDeviceEnvironment>> rootDeviceEnvironments;
    void releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment);
    // Map of Sub Device Indices set during Affinity Mask in the form of:
    // <RootDeviceIndex, SubDeviceIndex, SubDeviceCount>
    // Primarily used by the Metrics Library to communicate the actual Sub Device Index being used in queries.
    std::unordered_map<uint32_t, std::tuple<uint32_t, uint32_t, uint32_t>> mapOfSubDeviceIndices;
    std::unordered_map<std::thread::id, std::string> errorDescs;
    std::mutex errorDescsMutex;
    std::mutex peerAccessQueryMutex;

  protected:
    static bool comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2);
    void parseCcsCountLimitations();
    void adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const;
    void configureNeoEnvironment();
    void restoreCcsMode();
    bool metricsEnabled = false;
    bool fp64EmulationEnabled = false;
    bool oneApiPvcWaEnv = true;
    bool devicePermissionError = false;

    DeviceHierarchyMode deviceHierarchyMode = DeviceHierarchyMode::composite;
    DebuggingMode debuggingEnabledMode = DebuggingMode::disabled;
    std::unordered_map<uint32_t, uint32_t> rootDeviceNumCcsMap;
    std::mutex initializeDirectSubmissionControllerMutex;
    std::mutex initializeUnifiedMemoryReuseCleanerMutex;
    std::vector<std::tuple<std::string, uint32_t>> deviceCcsModeVec;
};
} // namespace NEO