mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Refactor memory info
Related-To: NEO-6149 Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
c81c57ec71
commit
d61741dd9f
@@ -73,6 +73,7 @@ DECLARE_DEBUG_VARIABLE(bool, EnableFlushTaskSubmission, false, "true: driver use
|
||||
DECLARE_DEBUG_VARIABLE(bool, DoNotFreeResources, false, "true: driver stops freeing resources")
|
||||
DECLARE_DEBUG_VARIABLE(bool, AllowMixingRegularAndCooperativeKernels, false, "true: driver allows mixing regular and cooperative kernels in a single command list and in a single execute")
|
||||
DECLARE_DEBUG_VARIABLE(bool, AllowPatchingVfeStateInCommandLists, false, "true: MEDIA_VFE_STATE may be programmed in a command list")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintMemoryRegionSizes, false, "print memory bank type, instance and it's size")
|
||||
DECLARE_DEBUG_VARIABLE(std::string, ForceDeviceId, std::string("unk"), "DeviceId selected for testing")
|
||||
DECLARE_DEBUG_VARIABLE(std::string, LoadBinarySipFromFile, std::string("unk"), "Select binary file to load SIP kernel raw binary")
|
||||
DECLARE_DEBUG_VARIABLE(int64_t, OverrideMultiStoragePlacement, -1, "-1: disable, 0+: tile mask, each bit corresponds to tile")
|
||||
@@ -348,3 +349,4 @@ DECLARE_DEBUG_VARIABLE(bool, UseUmKmDataTranslator, false, "Use helper library f
|
||||
DECLARE_DEBUG_VARIABLE(bool, SkipFlushingEventsOnGetStatusCalls, false, "When set to 1, events are not causing internal flush when querying for CL_EVENT_COMMAND_EXECUTION_STATUS")
|
||||
DECLARE_DEBUG_VARIABLE(bool, AllowUnrestrictedSize, false, "Allow allocating memory with greater size than MAX_MEM_ALLOC_SIZE")
|
||||
DECLARE_DEBUG_VARIABLE(bool, ProgramAdditionalPipeControlBeforeStateComputeModeCommand, false, "Program additional PIPE CONTROL command before STATE_COMPUTE_MODE command")
|
||||
DECLARE_DEBUG_VARIABLE(int32_t, OverrideDrmRegion, -1, "-1: disable, 0+: override to given memory region for all allocations")
|
||||
|
||||
@@ -85,6 +85,7 @@ if(SUPPORT_DG1 AND "${BRANCH_TYPE}" STREQUAL "")
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_local_memory_dg1.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_create_multi_host_allocation_dg1.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_query_dg1.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_info_impl.cpp
|
||||
)
|
||||
else()
|
||||
list(APPEND NEO_CORE_OS_INTERFACE_LINUX
|
||||
|
||||
@@ -27,11 +27,8 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm,
|
||||
if (!memoryInfo) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto regionClassAndInstance = memoryInfo->getMemoryRegionClassAndInstance(memoryBanks);
|
||||
if (regionClassAndInstance.memory_class == MemoryInfoImpl::invalidMemoryRegion()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto pHwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto regionClassAndInstance = memoryInfo->getMemoryRegionClassAndInstance(memoryBanks, *pHwInfo);
|
||||
|
||||
drm_i915_gem_memory_class_instance memRegions{};
|
||||
memRegions.memory_class = regionClassAndInstance.memory_class;
|
||||
|
||||
33
shared/source/os_interface/linux/memory_info_impl.cpp
Normal file
33
shared/source/os_interface/linux/memory_info_impl.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/memory_info_impl.h"
|
||||
|
||||
#include "shared/source/helpers/basic_math.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
MemoryInfoImpl::MemoryInfoImpl(const drm_i915_memory_region_info *regionInfo, size_t count)
|
||||
: drmQueryRegions(regionInfo, regionInfo + count), systemMemoryRegion(drmQueryRegions[0]) {
|
||||
UNRECOVERABLE_IF(systemMemoryRegion.region.memory_class != I915_MEMORY_CLASS_SYSTEM);
|
||||
std::copy_if(drmQueryRegions.begin(), drmQueryRegions.end(), std::back_inserter(localMemoryRegions),
|
||||
[](const drm_i915_memory_region_info &memoryRegionInfo) {
|
||||
return (memoryRegionInfo.region.memory_class == I915_MEMORY_CLASS_DEVICE);
|
||||
});
|
||||
}
|
||||
|
||||
void MemoryInfoImpl::assignRegionsFromDistances(const void *distanceInfosPtr, size_t size) {
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include "shared/source/helpers/basic_math.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/helpers/hw_helper.h"
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
#include "shared/source/os_interface/linux/memory_info.h"
|
||||
|
||||
@@ -18,33 +19,68 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
struct MemoryInfoImpl : public MemoryInfo {
|
||||
class MemoryInfoImpl : public MemoryInfo {
|
||||
public:
|
||||
using RegionContainer = std::vector<drm_i915_memory_region_info>;
|
||||
|
||||
~MemoryInfoImpl() override = default;
|
||||
|
||||
MemoryInfoImpl(const drm_i915_memory_region_info *regionInfo, size_t count) : regions(regionInfo, regionInfo + count) {
|
||||
}
|
||||
MemoryInfoImpl(const drm_i915_memory_region_info *regionInfo, size_t count);
|
||||
|
||||
drm_i915_gem_memory_class_instance getMemoryRegionClassAndInstance(uint32_t memoryBank) {
|
||||
auto index = (memoryBank > 0) ? Math::log2(memoryBank) + 1 : 0;
|
||||
if (index < regions.size()) {
|
||||
return regions[index].region;
|
||||
void assignRegionsFromDistances(const void *distanceInfosPtr, size_t size);
|
||||
|
||||
drm_i915_gem_memory_class_instance getMemoryRegionClassAndInstance(uint32_t memoryBank, const HardwareInfo &hwInfo) {
|
||||
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
||||
if (!hwHelper.getEnableLocalMemory(hwInfo) || memoryBank == 0) {
|
||||
return systemMemoryRegion.region;
|
||||
}
|
||||
return {invalidMemoryRegion(), invalidMemoryRegion()};
|
||||
|
||||
auto index = Math::log2(memoryBank);
|
||||
|
||||
index = hwHelper.isBankOverrideRequired(hwInfo) ? 0 : index;
|
||||
|
||||
if (DebugManager.flags.OverrideDrmRegion.get() != -1) {
|
||||
index = DebugManager.flags.OverrideDrmRegion.get();
|
||||
}
|
||||
|
||||
UNRECOVERABLE_IF(index >= localMemoryRegions.size());
|
||||
|
||||
return localMemoryRegions[index].region;
|
||||
}
|
||||
|
||||
size_t getMemoryRegionSize(uint32_t memoryBank) override {
|
||||
auto index = (memoryBank > 0) ? Math::log2(memoryBank) + 1 : 0;
|
||||
if (index < regions.size()) {
|
||||
return regions[index].probed_size;
|
||||
if (DebugManager.flags.PrintMemoryRegionSizes.get()) {
|
||||
printRegionSizes();
|
||||
}
|
||||
if (memoryBank == 0) {
|
||||
return systemMemoryRegion.probed_size;
|
||||
}
|
||||
|
||||
auto index = Math::log2(memoryBank);
|
||||
|
||||
if (index < localMemoryRegions.size()) {
|
||||
return localMemoryRegions[index].probed_size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static constexpr uint16_t invalidMemoryRegion() {
|
||||
return static_cast<uint16_t>(-1);
|
||||
void printRegionSizes() {
|
||||
for (auto region : drmQueryRegions) {
|
||||
std::cout << "Memory type: " << region.region.memory_class
|
||||
<< ", memory instance: " << region.region.memory_instance
|
||||
<< ", region size: " << region.probed_size << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<drm_i915_memory_region_info> regions;
|
||||
const RegionContainer &getDrmRegionInfos() const { return drmQueryRegions; }
|
||||
|
||||
protected:
|
||||
const RegionContainer drmQueryRegions;
|
||||
|
||||
const drm_i915_memory_region_info &systemMemoryRegion;
|
||||
|
||||
RegionContainer localMemoryRegions;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user