Calculate a maxOsContextCount variable

Change-Id: I7b2f7733be74abf4ae299396d616b249b67de58e
Signed-off-by: Jobczyk, Lukasz <lukasz.jobczyk@intel.com>
This commit is contained in:
Jobczyk, Lukasz 2019-12-17 08:11:16 +01:00 committed by sys_ocldev
parent 1021d8c6d2
commit eac48002ab
30 changed files with 110 additions and 64 deletions

View File

@ -9,9 +9,9 @@
#include <cstdint> #include <cstdint>
namespace NEO { namespace NEO {
namespace EngineLimits {
constexpr uint32_t numGpgpuEngineInstances = 3u;
constexpr uint32_t maxOsContextCount = numGpgpuEngineInstances;
constexpr uint32_t maxHandleCount = 1u; constexpr uint32_t maxHandleCount = 1u;
}; // namespace EngineLimits
} // namespace NEO } // namespace NEO

View File

@ -8,10 +8,10 @@
#include "graphics_allocation.h" #include "graphics_allocation.h"
#include "core/helpers/aligned_memory.h" #include "core/helpers/aligned_memory.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/utilities/logger.h" #include "runtime/utilities/logger.h"
namespace NEO { namespace NEO {
void GraphicsAllocation::setAllocationType(AllocationType allocationType) { void GraphicsAllocation::setAllocationType(AllocationType allocationType) {
this->allocationType = allocationType; this->allocationType = allocationType;
FileLoggerInstance().logAllocation(this); FileLoggerInstance().logAllocation(this);
@ -25,7 +25,8 @@ GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType
size(sizeIn), size(sizeIn),
cpuPtr(cpuPtrIn), cpuPtr(cpuPtrIn),
memoryPool(pool), memoryPool(pool),
allocationType(allocationType) { allocationType(allocationType),
usageInfos(MemoryManager::maxOsContextCount) {
} }
GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn,
@ -35,7 +36,8 @@ GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, AllocationType
size(sizeIn), size(sizeIn),
cpuPtr(cpuPtrIn), cpuPtr(cpuPtrIn),
memoryPool(pool), memoryPool(pool),
allocationType(allocationType) { allocationType(allocationType),
usageInfos(MemoryManager::maxOsContextCount) {
sharingInfo.sharedHandle = sharedHandleIn; sharingInfo.sharedHandle = sharedHandleIn;
} }

View File

@ -23,6 +23,7 @@
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
#include <mutex> #include <mutex>
#include <vector>
namespace NEO { namespace NEO {
@ -285,8 +286,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
MemoryPool::Type memoryPool = MemoryPool::MemoryNull; MemoryPool::Type memoryPool = MemoryPool::MemoryNull;
AllocationType allocationType = AllocationType::UNKNOWN; AllocationType allocationType = AllocationType::UNKNOWN;
std::array<UsageInfo, maxOsContextCount> usageInfos; std::vector<UsageInfo> usageInfos;
std::atomic<uint32_t> registeredContextsNum{0}; std::atomic<uint32_t> registeredContextsNum{0};
std::array<Gmm *, maxHandleCount> gmms{}; std::array<Gmm *, EngineLimits::maxHandleCount> gmms{};
}; };
} // namespace NEO } // namespace NEO

View File

@ -6,7 +6,6 @@
*/ */
#pragma once #pragma once
#include "core/memory_manager/residency.h"
#include <cinttypes> #include <cinttypes>
#include <cstdlib> #include <cstdlib>
@ -14,6 +13,7 @@
namespace NEO { namespace NEO {
struct OsHandle; struct OsHandle;
struct ResidencyData;
using OsGraphicsHandle = OsHandle; using OsGraphicsHandle = OsHandle;

View File

@ -6,20 +6,19 @@
*/ */
#pragma once #pragma once
#include "engine_limits.h" #include "runtime/memory_manager/memory_manager.h"
#include <array> #include <vector>
#include <cstdint>
namespace NEO { namespace NEO {
struct ResidencyData { struct ResidencyData {
bool resident[maxOsContextCount] = {}; std::vector<bool> resident = std::vector<bool>(MemoryManager::maxOsContextCount, 0);
void updateCompletionData(uint64_t newFenceValue, uint32_t contextId); void updateCompletionData(uint64_t newFenceValue, uint32_t contextId);
uint64_t getFenceValueForContextId(uint32_t contextId); uint64_t getFenceValueForContextId(uint32_t contextId);
protected: protected:
std::array<uint64_t, maxOsContextCount> lastFenceValues = {}; std::vector<uint64_t> lastFenceValues = std::vector<uint64_t>(MemoryManager::maxOsContextCount, 0);
}; };
} // namespace NEO } // namespace NEO

View File

@ -15,6 +15,7 @@
#include "runtime/built_ins/built_ins.h" #include "runtime/built_ins/built_ins.h"
#include "runtime/command_stream/tbx_command_stream_receiver_hw.h" #include "runtime/command_stream/tbx_command_stream_receiver_hw.h"
#include "runtime/compiler_interface/default_cl_cache_config.h" #include "runtime/compiler_interface/default_cl_cache_config.h"
#include "runtime/helpers/device_helpers.h"
#include "runtime/memory_manager/memory_manager.h" #include "runtime/memory_manager/memory_manager.h"
#include "runtime/os_interface/os_interface.h" #include "runtime/os_interface/os_interface.h"
#include "runtime/source_level_debugger/source_level_debugger.h" #include "runtime/source_level_debugger/source_level_debugger.h"
@ -36,9 +37,11 @@ void ExecutionEnvironment::initGmm() {
gmmHelper.reset(new GmmHelper(osInterface.get(), hwInfo.get())); gmmHelper.reset(new GmmHelper(osInterface.get(), hwInfo.get()));
} }
} }
void ExecutionEnvironment::setHwInfo(const HardwareInfo *hwInfo) { void ExecutionEnvironment::setHwInfo(const HardwareInfo *hwInfo) {
*this->hwInfo = *hwInfo; *this->hwInfo = *hwInfo;
} }
void ExecutionEnvironment::initializeMemoryManager() { void ExecutionEnvironment::initializeMemoryManager() {
if (this->memoryManager) { if (this->memoryManager) {
return; return;
@ -65,6 +68,7 @@ void ExecutionEnvironment::initializeMemoryManager() {
} }
DEBUG_BREAK_IF(!this->memoryManager); DEBUG_BREAK_IF(!this->memoryManager);
} }
void ExecutionEnvironment::initSourceLevelDebugger() { void ExecutionEnvironment::initSourceLevelDebugger() {
if (hwInfo->capabilityTable.sourceLevelDebuggerSupported) { if (hwInfo->capabilityTable.sourceLevelDebuggerSupported) {
sourceLevelDebugger.reset(SourceLevelDebugger::create()); sourceLevelDebugger.reset(SourceLevelDebugger::create());
@ -74,9 +78,20 @@ void ExecutionEnvironment::initSourceLevelDebugger() {
sourceLevelDebugger->initialize(localMemorySipAvailable); sourceLevelDebugger->initialize(localMemorySipAvailable);
} }
} }
void ExecutionEnvironment::calculateMaxOsContextCount() {
auto &hwHelper = HwHelper::get(this->hwInfo->platform.eRenderCoreFamily);
auto osContextCount = hwHelper.getGpgpuEngineInstances().size();
auto subDevicesCount = DeviceHelper::getSubDevicesCount(this->getHardwareInfo());
bool hasRootCsr = subDevicesCount > 1;
MemoryManager::maxOsContextCount = static_cast<uint32_t>(osContextCount * subDevicesCount * this->rootDeviceEnvironments.size() + hasRootCsr);
}
GmmHelper *ExecutionEnvironment::getGmmHelper() const { GmmHelper *ExecutionEnvironment::getGmmHelper() const {
return gmmHelper.get(); return gmmHelper.get();
} }
CompilerInterface *ExecutionEnvironment::getCompilerInterface() { CompilerInterface *ExecutionEnvironment::getCompilerInterface() {
if (this->compilerInterface.get() == nullptr) { if (this->compilerInterface.get() == nullptr) {
std::lock_guard<std::mutex> autolock(this->mtx); std::lock_guard<std::mutex> autolock(this->mtx);
@ -87,6 +102,7 @@ CompilerInterface *ExecutionEnvironment::getCompilerInterface() {
} }
return this->compilerInterface.get(); return this->compilerInterface.get();
} }
BuiltIns *ExecutionEnvironment::getBuiltIns() { BuiltIns *ExecutionEnvironment::getBuiltIns() {
if (this->builtins.get() == nullptr) { if (this->builtins.get() == nullptr) {
std::lock_guard<std::mutex> autolock(this->mtx); std::lock_guard<std::mutex> autolock(this->mtx);
@ -110,5 +126,6 @@ void ExecutionEnvironment::prepareRootDeviceEnvironments(uint32_t numRootDevices
rootDeviceEnvironments[rootDeviceIndex] = std::make_unique<RootDeviceEnvironment>(*this); rootDeviceEnvironments[rootDeviceIndex] = std::make_unique<RootDeviceEnvironment>(*this);
} }
} }
calculateMaxOsContextCount();
} }
} // namespace NEO } // namespace NEO

View File

@ -39,6 +39,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void initGmm(); void initGmm();
void initializeMemoryManager(); void initializeMemoryManager();
void initSourceLevelDebugger(); void initSourceLevelDebugger();
void calculateMaxOsContextCount();
void setHwInfo(const HardwareInfo *hwInfo); void setHwInfo(const HardwareInfo *hwInfo);
const HardwareInfo *getHardwareInfo() const { return hwInfo.get(); } const HardwareInfo *getHardwareInfo() const { return hwInfo.get(); }
HardwareInfo *getMutableHardwareInfo() const { return hwInfo.get(); } HardwareInfo *getMutableHardwareInfo() const { return hwInfo.get(); }

View File

@ -30,6 +30,8 @@
#include <algorithm> #include <algorithm>
namespace NEO { namespace NEO {
uint32_t MemoryManager::maxOsContextCount = 0u;
MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : executionEnvironment(executionEnvironment), hostPtrManager(std::make_unique<HostPtrManager>()), MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : executionEnvironment(executionEnvironment), hostPtrManager(std::make_unique<HostPtrManager>()),
multiContextResourceDestructor(std::make_unique<DeferredDeleter>()) { multiContextResourceDestructor(std::make_unique<DeferredDeleter>()) {
auto hwInfo = executionEnvironment.getHardwareInfo(); auto hwInfo = executionEnvironment.getHardwareInfo();

View File

@ -158,6 +158,8 @@ class MemoryManager {
void *getReservedMemory(size_t size, size_t alignment); void *getReservedMemory(size_t size, size_t alignment);
GfxPartition *getGfxPartition(uint32_t rootDeviceIndex) { return gfxPartitions.at(rootDeviceIndex).get(); } GfxPartition *getGfxPartition(uint32_t rootDeviceIndex) { return gfxPartitions.at(rootDeviceIndex).get(); }
static uint32_t maxOsContextCount;
protected: protected:
struct AllocationData { struct AllocationData {
union { union {

View File

@ -15,6 +15,7 @@
#include "core/helpers/options.h" #include "core/helpers/options.h"
#include "core/helpers/ptr_math.h" #include "core/helpers/ptr_math.h"
#include "core/memory_manager/host_ptr_manager.h" #include "core/memory_manager/host_ptr_manager.h"
#include "core/memory_manager/residency.h"
#include "core/os_interface/os_memory.h" #include "core/os_interface/os_memory.h"
#include "runtime/aub/aub_center.h" #include "runtime/aub/aub_center.h"
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
@ -188,7 +189,7 @@ void OsAgnosticMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocat
} }
void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) { void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) {
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) { for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
delete gfxAllocation->getGmm(handleId); delete gfxAllocation->getGmm(handleId);
} }

View File

@ -15,7 +15,7 @@ struct OsHandle {
BufferObject *bo = nullptr; BufferObject *bo = nullptr;
}; };
using BufferObjects = std::array<BufferObject *, maxHandleCount>; using BufferObjects = std::array<BufferObject *, EngineLimits::maxHandleCount>;
class DrmAllocation : public GraphicsAllocation { class DrmAllocation : public GraphicsAllocation {
public: public:

View File

@ -9,6 +9,7 @@
#include "core/gmm_helper/gmm_helper.h" #include "core/gmm_helper/gmm_helper.h"
#include "core/helpers/aligned_memory.h" #include "core/helpers/aligned_memory.h"
#include "core/helpers/preamble.h" #include "core/helpers/preamble.h"
#include "core/memory_manager/residency.h"
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/gmm_helper/page_table_mngr.h"
#include "runtime/helpers/flush_stamp.h" #include "runtime/helpers/flush_stamp.h"

View File

@ -12,6 +12,7 @@
#include "core/helpers/options.h" #include "core/helpers/options.h"
#include "core/helpers/ptr_math.h" #include "core/helpers/ptr_math.h"
#include "core/memory_manager/host_ptr_manager.h" #include "core/memory_manager/host_ptr_manager.h"
#include "core/memory_manager/residency.h"
#include "runtime/command_stream/command_stream_receiver.h" #include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/device/device.h" #include "runtime/device/device.h"
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
@ -538,7 +539,7 @@ void DrmMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocation *gf
} }
void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) { void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) {
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) { for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
if (gfxAllocation->getGmm(handleId)) { if (gfxAllocation->getGmm(handleId)) {
delete gfxAllocation->getGmm(handleId); delete gfxAllocation->getGmm(handleId);
} }

View File

@ -9,6 +9,7 @@
#define UMDF_USING_NTSTATUS #define UMDF_USING_NTSTATUS
#include "core/helpers/aligned_memory.h" #include "core/helpers/aligned_memory.h"
#include "core/memory_manager/graphics_allocation.h" #include "core/memory_manager/graphics_allocation.h"
#include "core/memory_manager/residency.h"
#include "core/os_interface/windows/windows_wrapper.h" #include "core/os_interface/windows/windows_wrapper.h"
#include <d3dkmthk.h> #include <d3dkmthk.h>
@ -26,23 +27,19 @@ constexpr size_t trimListUnusedPosition = std::numeric_limits<size_t>::max();
class WddmAllocation : public GraphicsAllocation { class WddmAllocation : public GraphicsAllocation {
public: public:
WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool) WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool)
: GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool) { : GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool), trimCandidateListPositions(MemoryManager::maxOsContextCount, trimListUnusedPosition) {
trimCandidateListPositions.fill(trimListUnusedPosition);
reservedAddressRangeInfo.addressPtr = reservedAddr; reservedAddressRangeInfo.addressPtr = reservedAddr;
reservedAddressRangeInfo.rangeSize = sizeIn; reservedAddressRangeInfo.rangeSize = sizeIn;
} }
WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool, uint32_t shareable) WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool, uint32_t shareable)
: GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool), shareable(shareable) { : GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool), shareable(shareable), trimCandidateListPositions(MemoryManager::maxOsContextCount, trimListUnusedPosition) {
trimCandidateListPositions.fill(trimListUnusedPosition);
reservedAddressRangeInfo.addressPtr = reservedAddr; reservedAddressRangeInfo.addressPtr = reservedAddr;
reservedAddressRangeInfo.rangeSize = sizeIn; reservedAddressRangeInfo.rangeSize = sizeIn;
} }
WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool) WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool)
: GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, sizeIn, sharedHandle, pool) { : GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, sizeIn, sharedHandle, pool), trimCandidateListPositions(MemoryManager::maxOsContextCount, trimListUnusedPosition) {}
trimCandidateListPositions.fill(trimListUnusedPosition);
}
void *getAlignedCpuPtr() const { void *getAlignedCpuPtr() const {
return alignDown(this->cpuPtr, MemoryConstants::pageSize); return alignDown(this->cpuPtr, MemoryConstants::pageSize);
@ -55,7 +52,7 @@ class WddmAllocation : public GraphicsAllocation {
ResidencyData &getResidencyData() { ResidencyData &getResidencyData() {
return residency; return residency;
} }
const std::array<D3DKMT_HANDLE, maxHandleCount> &getHandles() const { return handles; } const std::array<D3DKMT_HANDLE, EngineLimits::maxHandleCount> &getHandles() const { return handles; }
D3DKMT_HANDLE &getHandleToModify(uint32_t handleIndex) { return handles[handleIndex]; } D3DKMT_HANDLE &getHandleToModify(uint32_t handleIndex) { return handles[handleIndex]; }
D3DKMT_HANDLE getDefaultHandle() const { return handles[0]; } D3DKMT_HANDLE getDefaultHandle() const { return handles[0]; }
void setDefaultHandle(D3DKMT_HANDLE handle) { void setDefaultHandle(D3DKMT_HANDLE handle) {
@ -94,8 +91,8 @@ class WddmAllocation : public GraphicsAllocation {
} }
return ss.str(); return ss.str();
} }
std::array<D3DKMT_HANDLE, maxHandleCount> handles{}; std::array<D3DKMT_HANDLE, EngineLimits::maxHandleCount> handles{};
ResidencyData residency; ResidencyData residency;
std::array<size_t, maxOsContextCount> trimCandidateListPositions; std::vector<size_t> trimCandidateListPositions;
}; };
} // namespace NEO } // namespace NEO

View File

@ -341,7 +341,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
DEBUG_BREAK_IF(!status); DEBUG_BREAK_IF(!status);
} }
} }
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) { for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
delete gfxAllocation->getGmm(handleId); delete gfxAllocation->getGmm(handleId);
} }
@ -450,7 +450,7 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uint32_t
for (unsigned int i = 0; i < maxFragmentsCount; i++) { for (unsigned int i = 0; i < maxFragmentsCount; i++) {
if (handleStorage.fragmentStorageData[i].freeTheFragment) { if (handleStorage.fragmentStorageData[i].freeTheFragment) {
handles[allocationCount++] = handleStorage.fragmentStorageData[i].osHandleStorage->handle; handles[allocationCount++] = handleStorage.fragmentStorageData[i].osHandleStorage->handle;
std::fill_n(handleStorage.fragmentStorageData[i].residency->resident, maxOsContextCount, false); std::fill(handleStorage.fragmentStorageData[i].residency->resident.begin(), handleStorage.fragmentStorageData[i].residency->resident.end(), false);
} }
} }

View File

@ -7,12 +7,9 @@
#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "runtime/os_interface/windows/wddm_memory_operations_handler.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
#include "runtime/os_interface/windows/wddm_allocation.h" #include "runtime/os_interface/windows/wddm_allocation.h"
#include "runtime/os_interface/windows/wddm_residency_allocations_container.h" #include "runtime/os_interface/windows/wddm_residency_allocations_container.h"
#include "engine_limits.h"
namespace NEO { namespace NEO {
WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm) { WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm) {

View File

@ -300,7 +300,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) {
bool WddmResidencyController::makeResidentResidencyAllocations(const ResidencyContainer &allocationsForResidency) { bool WddmResidencyController::makeResidentResidencyAllocations(const ResidencyContainer &allocationsForResidency) {
const size_t residencyCount = allocationsForResidency.size(); const size_t residencyCount = allocationsForResidency.size();
std::unique_ptr<D3DKMT_HANDLE[]> handlesForResidency(new D3DKMT_HANDLE[residencyCount * maxFragmentsCount * maxHandleCount]); std::unique_ptr<D3DKMT_HANDLE[]> handlesForResidency(new D3DKMT_HANDLE[residencyCount * maxFragmentsCount * EngineLimits::maxHandleCount]);
uint32_t totalHandlesCount = 0; uint32_t totalHandlesCount = 0;
auto lock = this->acquireLock(); auto lock = this->acquireLock();

View File

@ -16,6 +16,7 @@
#include "runtime/built_ins/built_ins.h" #include "runtime/built_ins/built_ins.h"
#include "runtime/device/device.h" #include "runtime/device/device.h"
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/device_helpers.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/os_interface/os_interface.h" #include "runtime/os_interface/os_interface.h"
#include "runtime/platform/platform.h" #include "runtime/platform/platform.h"
@ -218,3 +219,18 @@ TEST(ExecutionEnvironment, givenUnproperSetCsrFlagValueWhenInitializingMemoryMan
executionEnvironment->initializeMemoryManager(); executionEnvironment->initializeMemoryManager();
EXPECT_NE(nullptr, executionEnvironment->memoryManager); EXPECT_NE(nullptr, executionEnvironment->memoryManager);
} }
TEST(ExecutionEnvironment, whenCalculateMaxOsContexCountThenGlobalVariableHasProperValue) {
VariableBackup<uint32_t> osContextCountBackup(&MemoryManager::maxOsContextCount);
ExecutionEnvironment executionEnvironment;
uint32_t numRootDevices = 17u;
auto &hwHelper = HwHelper::get(executionEnvironment.getHardwareInfo()->platform.eRenderCoreFamily);
auto osContextCount = hwHelper.getGpgpuEngineInstances().size();
auto subDevicesCount = DeviceHelper::getSubDevicesCount(executionEnvironment.getHardwareInfo());
bool hasRootCsr = subDevicesCount > 1;
executionEnvironment.prepareRootDeviceEnvironments(numRootDevices);
auto expectedOsContextCount = numRootDevices * osContextCount * subDevicesCount + hasRootCsr;
EXPECT_EQ(expectedOsContextCount, MemoryManager::maxOsContextCount);
}

View File

@ -17,16 +17,16 @@
namespace NEO { namespace NEO {
namespace MockSipData { namespace MockSipData {
static MockSipKernel mockSipKernel; std::unique_ptr<MockSipKernel> mockSipKernel;
SipKernelType calledType = SipKernelType::COUNT; SipKernelType calledType = SipKernelType::COUNT;
bool called = false; bool called = false;
} // namespace MockSipData } // namespace MockSipData
const SipKernel &initSipKernel(SipKernelType type, Device &device) { const SipKernel &initSipKernel(SipKernelType type, Device &device) {
MockSipData::calledType = type; MockSipData::calledType = type;
MockSipData::mockSipKernel.type = type; MockSipData::mockSipKernel->type = type;
MockSipData::called = true; MockSipData::called = true;
return MockSipData::mockSipKernel; return *MockSipData::mockSipKernel;
} }
Program *createProgramForSip(ExecutionEnvironment &executionEnvironment, Program *createProgramForSip(ExecutionEnvironment &executionEnvironment,
Context *context, Context *context,

View File

@ -49,6 +49,10 @@ extern TestMode testMode;
extern const char *executionDirectorySuffix; extern const char *executionDirectorySuffix;
std::thread::id tempThreadID; std::thread::id tempThreadID;
namespace MockSipData {
extern std::unique_ptr<MockSipKernel> mockSipKernel;
}
} // namespace NEO } // namespace NEO
namespace Os { namespace Os {
extern const char *gmmDllName; extern const char *gmmDllName;
@ -140,6 +144,7 @@ LONG WINAPI UltExceptionFilter(
void initializeTestHelpers() { void initializeTestHelpers() {
GlobalMockSipProgram::initSipProgram(); GlobalMockSipProgram::initSipProgram();
MockSipData::mockSipKernel.reset(new MockSipKernel());
} }
void cleanTestHelpers() { void cleanTestHelpers() {

View File

@ -27,7 +27,7 @@ TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenSetAdditionalDataThenAdd
TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenIsCreatedThenAllInspectionIdsAreSetToZero) { TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenIsCreatedThenAllInspectionIdsAreSetToZero) {
MockGraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, 0, MemoryPool::MemoryNull); MockGraphicsAllocation graphicsAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, 0, MemoryPool::MemoryNull);
for (auto i = 0u; i < maxOsContextCount; i++) { for (auto i = 0u; i < MemoryManager::maxOsContextCount; i++) {
EXPECT_EQ(0u, graphicsAllocation.getInspectionId(i)); EXPECT_EQ(0u, graphicsAllocation.getInspectionId(i));
} }
} }
@ -35,7 +35,7 @@ TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenIsCreatedThenAllInspecti
TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenIsCreatedThenTaskCountsAreInitializedProperly) { TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenIsCreatedThenTaskCountsAreInitializedProperly) {
GraphicsAllocation graphicsAllocation1(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, 0, MemoryPool::MemoryNull); GraphicsAllocation graphicsAllocation1(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, 0, MemoryPool::MemoryNull);
GraphicsAllocation graphicsAllocation2(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, 0, MemoryPool::MemoryNull); GraphicsAllocation graphicsAllocation2(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0u, 0u, 0, MemoryPool::MemoryNull);
for (auto i = 0u; i < maxOsContextCount; i++) { for (auto i = 0u; i < MemoryManager::maxOsContextCount; i++) {
EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation1.getTaskCount(i)); EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation1.getTaskCount(i));
EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation2.getTaskCount(i)); EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation2.getTaskCount(i));
EXPECT_EQ(MockGraphicsAllocation::objectNotResident, graphicsAllocation1.getResidencyTaskCount(i)); EXPECT_EQ(MockGraphicsAllocation::objectNotResident, graphicsAllocation1.getResidencyTaskCount(i));
@ -53,13 +53,13 @@ TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenUpdatedTaskCountThenOnly
MockGraphicsAllocation graphicsAllocation; MockGraphicsAllocation graphicsAllocation;
graphicsAllocation.updateTaskCount(1u, 0u); graphicsAllocation.updateTaskCount(1u, 0u);
EXPECT_EQ(1u, graphicsAllocation.getTaskCount(0u)); EXPECT_EQ(1u, graphicsAllocation.getTaskCount(0u));
for (auto i = 1u; i < maxOsContextCount; i++) { for (auto i = 1u; i < MemoryManager::maxOsContextCount; i++) {
EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation.getTaskCount(i)); EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation.getTaskCount(i));
} }
graphicsAllocation.updateTaskCount(2u, 1u); graphicsAllocation.updateTaskCount(2u, 1u);
EXPECT_EQ(1u, graphicsAllocation.getTaskCount(0u)); EXPECT_EQ(1u, graphicsAllocation.getTaskCount(0u));
EXPECT_EQ(2u, graphicsAllocation.getTaskCount(1u)); EXPECT_EQ(2u, graphicsAllocation.getTaskCount(1u));
for (auto i = 2u; i < maxOsContextCount; i++) { for (auto i = 2u; i < MemoryManager::maxOsContextCount; i++) {
EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation.getTaskCount(i)); EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation.getTaskCount(i));
} }
} }

View File

@ -9,6 +9,7 @@
#include "core/helpers/cache_policy.h" #include "core/helpers/cache_policy.h"
#include "core/memory_manager/graphics_allocation.h" #include "core/memory_manager/graphics_allocation.h"
#include "core/memory_manager/memory_constants.h" #include "core/memory_manager/memory_constants.h"
#include "core/memory_manager/residency.h"
#include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h"
#include "runtime/event/event.h" #include "runtime/event/event.h"
#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/gmm_helper/page_table_mngr.h"
@ -1690,9 +1691,9 @@ TEST(ResidencyDataTest, givenTwoOsContextsWhenTheyAreRegisteredFromHigherToLower
EXPECT_EQ(1, memoryManager.registeredEngines[1].osContext->getRefInternalCount()); EXPECT_EQ(1, memoryManager.registeredEngines[1].osContext->getRefInternalCount());
} }
TEST(ResidencyDataTest, givenGpgpuEnginesWhenAskedForMaxOscontextCountThenValueIsGreaterOrEqual) { TEST(ResidencyDataTest, givenGpgpuEnginesWhenAskedForMaxOsContextCountThenValueIsGreaterOrEqual) {
auto &engines = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances(); auto &engines = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances();
EXPECT_TRUE(maxOsContextCount >= engines.size()); EXPECT_TRUE(MemoryManager::maxOsContextCount >= engines.size());
} }
TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenItIsProperlyUpdated) { TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenItIsProperlyUpdated) {
@ -1709,16 +1710,16 @@ TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenIt
auto lastFenceValue2 = 23llu; auto lastFenceValue2 = 23llu;
auto lastFenceValue3 = 373llu; auto lastFenceValue3 = 373llu;
EXPECT_EQ(maxOsContextCount, residency.lastFenceValues.size()); EXPECT_EQ(MemoryManager::maxOsContextCount, residency.lastFenceValues.size());
residency.updateCompletionData(lastFenceValue, osContext.getContextId()); residency.updateCompletionData(lastFenceValue, osContext.getContextId());
EXPECT_EQ(maxOsContextCount, residency.lastFenceValues.size()); EXPECT_EQ(MemoryManager::maxOsContextCount, residency.lastFenceValues.size());
EXPECT_EQ(lastFenceValue, residency.lastFenceValues[0]); EXPECT_EQ(lastFenceValue, residency.lastFenceValues[0]);
EXPECT_EQ(lastFenceValue, residency.getFenceValueForContextId(osContext.getContextId())); EXPECT_EQ(lastFenceValue, residency.getFenceValueForContextId(osContext.getContextId()));
residency.updateCompletionData(lastFenceValue2, osContext2.getContextId()); residency.updateCompletionData(lastFenceValue2, osContext2.getContextId());
EXPECT_EQ(maxOsContextCount, residency.lastFenceValues.size()); EXPECT_EQ(MemoryManager::maxOsContextCount, residency.lastFenceValues.size());
EXPECT_EQ(lastFenceValue2, residency.lastFenceValues[1]); EXPECT_EQ(lastFenceValue2, residency.lastFenceValues[1]);
EXPECT_EQ(lastFenceValue2, residency.getFenceValueForContextId(osContext2.getContextId())); EXPECT_EQ(lastFenceValue2, residency.getFenceValueForContextId(osContext2.getContextId()));

View File

@ -36,14 +36,17 @@ cl_int GlobalMockSipProgram::processGenBinaryOnce() {
return ret; return ret;
} }
void GlobalMockSipProgram::resetAllocationState() { void GlobalMockSipProgram::resetAllocationState() {
for (uint32_t index = 0u; index < maxOsContextCount; index++) { auto allocation = static_cast<MockGraphicsAllocation *>(this->kernelInfoArray[0]->kernelAllocation);
for (uint32_t index = 0u; index < allocation->usageInfos.size(); index++) {
this->kernelInfoArray[0]->kernelAllocation->releaseResidencyInOsContext(index); this->kernelInfoArray[0]->kernelAllocation->releaseResidencyInOsContext(index);
} }
static_cast<MockGraphicsAllocation *>(this->kernelInfoArray[0]->kernelAllocation)->resetInspectionIds(); allocation->resetInspectionIds();
} }
void GlobalMockSipProgram::initSipProgram() { void GlobalMockSipProgram::initSipProgram() {
cl_int retVal = 0; cl_int retVal = 0;
std::vector<char> binary = MockCompilerInterface::getDummyGenBinary(); std::vector<char> binary = MockCompilerInterface::getDummyGenBinary();
executionEnvironment.setHwInfo(*platformDevices);
executionEnvironment.prepareRootDeviceEnvironments(1u);
sipProgram = Program::createFromGenBinary<GlobalMockSipProgram>(executionEnvironment, sipProgram = Program::createFromGenBinary<GlobalMockSipProgram>(executionEnvironment,
nullptr, nullptr,
binary.data(), binary.data(),

View File

@ -14,7 +14,6 @@
#include "runtime/os_interface/os_inc_base.h" #include "runtime/os_interface/os_inc_base.h"
#include "unit_tests/helpers/test_files.h" #include "unit_tests/helpers/test_files.h"
#include "unit_tests/mocks/mock_compilers.h" #include "unit_tests/mocks/mock_compilers.h"
#include "unit_tests/mocks/mock_execution_environment.h"
#include "unit_tests/mocks/mock_program.h" #include "unit_tests/mocks/mock_program.h"
#include "cif/macros/enable.h" #include "cif/macros/enable.h"
@ -24,9 +23,6 @@
#include <map> #include <map>
namespace NEO { namespace NEO {
static MockExecutionEnvironment mockExecEnv;
MockSipKernel::MockSipKernel(SipKernelType type, Program *sipProgram) : SipKernel(type, sipProgram) { MockSipKernel::MockSipKernel(SipKernelType type, Program *sipProgram) : SipKernel(type, sipProgram) {
this->mockSipMemoryAllocation = this->mockSipMemoryAllocation =
std::make_unique<MemoryAllocation>(0u, std::make_unique<MemoryAllocation>(0u,
@ -47,7 +43,7 @@ MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) {
0u, 0u,
MemoryConstants::pageSize, MemoryConstants::pageSize,
MemoryPool::System4KBPages); MemoryPool::System4KBPages);
this->program = new MockProgram(mockExecEnv, nullptr, false); this->program = new MockProgram(this->executionEnvironment, nullptr, false);
} }
MockSipKernel::~MockSipKernel() = default; MockSipKernel::~MockSipKernel() = default;

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#include "runtime/built_ins/sip.h" #include "runtime/built_ins/sip.h"
#include "unit_tests/mocks/mock_execution_environment.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -33,5 +34,6 @@ class MockSipKernel : public SipKernel {
GraphicsAllocation *getSipAllocation() const override; GraphicsAllocation *getSipAllocation() const override;
std::unique_ptr<MemoryAllocation> mockSipMemoryAllocation; std::unique_ptr<MemoryAllocation> mockSipMemoryAllocation;
MockExecutionEnvironment executionEnvironment;
}; };
} // namespace NEO } // namespace NEO

View File

@ -8,6 +8,7 @@
#include "core/command_stream/preemption.h" #include "core/command_stream/preemption.h"
#include "core/gmm_helper/gmm_helper.h" #include "core/gmm_helper/gmm_helper.h"
#include "core/memory_manager/graphics_allocation.h" #include "core/memory_manager/graphics_allocation.h"
#include "core/memory_manager/residency.h"
#include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h"
#include "runtime/gmm_helper/page_table_mngr.h" #include "runtime/gmm_helper/page_table_mngr.h"
#include "runtime/gmm_helper/resource_info.h" #include "runtime/gmm_helper/resource_info.h"
@ -818,15 +819,15 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenDrmAllocationWhenGetBuffer
auto allocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, size, (osHandle)0u, MemoryPool::MemoryNull); auto allocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, size, (osHandle)0u, MemoryPool::MemoryNull);
auto &bos = allocation->getBOs(); auto &bos = allocation->getBOs();
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) { for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
EXPECT_EQ(nullptr, bos[handleId]); EXPECT_EQ(nullptr, bos[handleId]);
} }
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) { for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
allocation->getBufferObjectToModify(handleId) = this->createBO(size); allocation->getBufferObjectToModify(handleId) = this->createBO(size);
} }
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) { for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
EXPECT_NE(nullptr, bos[handleId]); EXPECT_NE(nullptr, bos[handleId]);
} }

View File

@ -14,6 +14,7 @@
#include "core/helpers/ptr_math.h" #include "core/helpers/ptr_math.h"
#include "core/memory_manager/host_ptr_manager.h" #include "core/memory_manager/host_ptr_manager.h"
#include "core/memory_manager/memory_constants.h" #include "core/memory_manager/memory_constants.h"
#include "core/memory_manager/residency.h"
#include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h"
#include "runtime/command_stream/device_command_stream.h" #include "runtime/command_stream/device_command_stream.h"
#include "runtime/event/event.h" #include "runtime/event/event.h"
@ -3266,7 +3267,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn
{ {
::testing::InSequence inSequence; ::testing::InSequence inSequence;
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, true)).Times(maxHandleCount); EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, true)).Times(EngineLimits::maxHandleCount);
EXPECT_CALL(gmockDrmMemoryManager, releaseGpuRange(::testing::_, ::testing::_, ::testing::_)).Times(1); EXPECT_CALL(gmockDrmMemoryManager, releaseGpuRange(::testing::_, ::testing::_, ::testing::_)).Times(1);
EXPECT_CALL(gmockDrmMemoryManager, alignedFreeWrapper(::testing::_)).Times(1); EXPECT_CALL(gmockDrmMemoryManager, alignedFreeWrapper(::testing::_)).Times(1);
} }
@ -3286,7 +3287,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAnd
ASSERT_NE(nullptr, allocation); ASSERT_NE(nullptr, allocation);
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, false)).Times(1); EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, false)).Times(1);
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, true)).Times(maxHandleCount - 1); EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, true)).Times(EngineLimits::maxHandleCount - 1);
gmockDrmMemoryManager.freeGraphicsMemory(allocation); gmockDrmMemoryManager.freeGraphicsMemory(allocation);
} }

View File

@ -56,7 +56,7 @@ void WddmMemoryManagerFixture::SetUp() {
TEST(ResidencyData, givenNewlyConstructedResidencyDataThenItIsNotResidentOnAnyOsContext) { TEST(ResidencyData, givenNewlyConstructedResidencyDataThenItIsNotResidentOnAnyOsContext) {
ResidencyData residencyData; ResidencyData residencyData;
for (auto contextId = 0u; contextId < maxOsContextCount; contextId++) { for (auto contextId = 0u; contextId < MemoryManager::maxOsContextCount; contextId++) {
EXPECT_EQ(false, residencyData.resident[contextId]); EXPECT_EQ(false, residencyData.resident[contextId]);
} }
} }

View File

@ -9,6 +9,7 @@
#include "core/helpers/options.h" #include "core/helpers/options.h"
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/platform/platform.h" #include "runtime/platform/platform.h"
void NEO::UltConfigListener::OnTestStart(const ::testing::TestInfo &testInfo) { void NEO::UltConfigListener::OnTestStart(const ::testing::TestInfo &testInfo) {
@ -20,4 +21,5 @@ void NEO::UltConfigListener::OnTestStart(const ::testing::TestInfo &testInfo) {
void NEO::UltConfigListener::OnTestEnd(const ::testing::TestInfo &testInfo) { void NEO::UltConfigListener::OnTestEnd(const ::testing::TestInfo &testInfo) {
// Clear global platform that it shouldn't be reused between tests // Clear global platform that it shouldn't be reused between tests
platformImpl.reset(); platformImpl.reset();
MemoryManager::maxOsContextCount = 0u;
} }

View File

@ -26,11 +26,9 @@ HWTEST_F(GetDevicesTests, WhenGetDevicesIsCalledThenSuccessIsReturned) {
HWTEST_F(GetDevicesTests, whenGetDevicesIsCalledThenGmmIsBeingInitializedAfterFillingHwInfo) { HWTEST_F(GetDevicesTests, whenGetDevicesIsCalledThenGmmIsBeingInitializedAfterFillingHwInfo) {
platformImpl.reset(new Platform()); platformImpl.reset(new Platform());
size_t numDevicesReturned = 0; size_t numDevicesReturned = 0;
HardwareInfo hwInfo; auto hwInfo = platform()->peekExecutionEnvironment()->getMutableHardwareInfo();
hwInfo.platform.eProductFamily = PRODUCT_FAMILY::IGFX_UNKNOWN; hwInfo->platform.eProductFamily = PRODUCT_FAMILY::IGFX_UNKNOWN;
hwInfo.platform.eRenderCoreFamily = GFXCORE_FAMILY::IGFX_UNKNOWN_CORE; hwInfo->platform.ePCHProductFamily = PCH_PRODUCT_FAMILY::PCH_UNKNOWN;
hwInfo.platform.ePCHProductFamily = PCH_PRODUCT_FAMILY::PCH_UNKNOWN;
platform()->peekExecutionEnvironment()->setHwInfo(&hwInfo);
auto returnValue = DeviceFactory::getDevices(numDevicesReturned, *platform()->peekExecutionEnvironment()); auto returnValue = DeviceFactory::getDevices(numDevicesReturned, *platform()->peekExecutionEnvironment());
EXPECT_TRUE(returnValue); EXPECT_TRUE(returnValue);