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
|
/*
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/helpers/topology_map.h"
#include <limits>
#include <memory>
#include <string>
namespace NEO {
struct PhysicalDevicePciBusInfo;
struct PhysicalDevicePciSpeedInfo;
struct HardwareInfo;
enum class DriverModelType;
class ExecutionEnvironment;
class MemoryManager;
class OsContext;
class HwDeviceId : public NonCopyableClass {
public:
HwDeviceId(DriverModelType driverModel) : driverModelType(driverModel) {
}
virtual ~HwDeviceId() = default;
DriverModelType getDriverModelType() const {
return driverModelType;
}
template <typename DerivedType>
DerivedType *as() {
UNRECOVERABLE_IF(DerivedType::driverModelType != this->driverModelType);
return static_cast<DerivedType *>(this);
}
template <typename DerivedType>
DerivedType *as() const {
UNRECOVERABLE_IF(DerivedType::driverModelType != this->driverModelType);
return static_cast<const DerivedType *>(this);
}
protected:
DriverModelType driverModelType;
};
class DriverModel : public NonCopyableClass {
public:
DriverModel(DriverModelType driverModelType)
: driverModelType(driverModelType) {
}
virtual ~DriverModel() = default;
template <typename DerivedType>
DerivedType *as() {
UNRECOVERABLE_IF(DerivedType::driverModelType != this->driverModelType);
return static_cast<DerivedType *>(this);
}
template <typename DerivedType>
DerivedType *as() const {
UNRECOVERABLE_IF(DerivedType::driverModelType != this->driverModelType);
return static_cast<const DerivedType *>(this);
}
virtual void setGmmInputArgs(void *args) = 0;
virtual uint32_t getDeviceHandle() const = 0;
MOCKABLE_VIRTUAL DriverModelType getDriverModelType() const {
return driverModelType;
}
virtual PhysicalDevicePciBusInfo getPciBusInfo() const = 0;
virtual PhysicalDevicePciSpeedInfo getPciSpeedInfo() const = 0;
virtual size_t getMaxMemAllocSize() const {
return std::numeric_limits<size_t>::max();
}
virtual bool isDriverAvailable() {
return true;
}
bool skipResourceCleanup() const {
return skipResourceCleanupVar;
}
virtual void cleanup() {}
virtual bool isGpuHangDetected(OsContext &osContext) = 0;
virtual const HardwareInfo *getHardwareInfo() const = 0;
const TopologyMap &getTopologyMap() {
return topologyMap;
};
protected:
DriverModelType driverModelType;
TopologyMap topologyMap;
bool skipResourceCleanupVar = false;
};
class OSInterface : public NonCopyableClass {
public:
virtual ~OSInterface();
DriverModel *getDriverModel() const;
void setDriverModel(std::unique_ptr<DriverModel> driverModel);
MOCKABLE_VIRTUAL bool isDebugAttachAvailable() const;
MOCKABLE_VIRTUAL bool isLockablePointer(bool isLockable) const;
MOCKABLE_VIRTUAL bool isSizeWithinThresholdForStaging(size_t size, bool isIGPU) const;
MOCKABLE_VIRTUAL uint32_t getAggregatedProcessCount() const;
static bool osEnabled64kbPages;
static bool osEnableLocalMemory;
static bool are64kbPagesEnabled();
static bool newResourceImplicitFlush;
static bool gpuIdleImplicitFlush;
static bool requiresSupportForWddmTrimNotification;
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevices(ExecutionEnvironment &executionEnvironment);
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevice(ExecutionEnvironment &executionEnvironment, std::string &osPciPath);
protected:
std::unique_ptr<DriverModel> driverModel = nullptr;
};
} // namespace NEO
|