mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
Move MemoryInfoImpl logic to MemoryInfo
Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
f138c5f881
commit
12777bd758
@@ -42,7 +42,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_memory_manager_local_memory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_memory_operations_handler_create.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_query.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}memory_info_impl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}memory_info_extended.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_drm.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.cpp
|
||||
@@ -55,6 +55,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}engine_info_impl.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/flags${BRANCH_DIR_SUFFIX}drm_query_flags.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_info.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_info.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#include "shared/source/helpers/hw_helper.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
#include "shared/source/os_interface/linux/cache_info_impl.h"
|
||||
#include "shared/source/os_interface/linux/drm_engine_mapper.h"
|
||||
#include "shared/source/os_interface/linux/engine_info_impl.h"
|
||||
#include "shared/source/os_interface/linux/local_memory_helper.h"
|
||||
#include "shared/source/os_interface/linux/memory_info_impl.h"
|
||||
#include "shared/source/os_interface/linux/memory_info.h"
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
#include "shared/source/os_interface/linux/system_info.h"
|
||||
|
||||
@@ -60,7 +61,7 @@ bool Drm::queryMemoryInfo() {
|
||||
auto localMemHelper = LocalMemoryHelper::get(pHwInfo->platform.eProductFamily);
|
||||
auto data = localMemHelper->translateIfRequired(dataQuery.release(), length);
|
||||
auto memRegions = reinterpret_cast<drm_i915_query_memory_regions *>(data.get());
|
||||
this->memoryInfo.reset(new MemoryInfoImpl(memRegions->regions, memRegions->num_regions));
|
||||
this->memoryInfo.reset(new MemoryInfo(memRegions->regions, memRegions->num_regions));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
77
shared/source/os_interface/linux/memory_info.cpp
Normal file
77
shared/source/os_interface/linux/memory_info.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/memory_info.h"
|
||||
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#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/local_memory_helper.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
uint32_t MemoryInfo::createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle) {
|
||||
auto pHwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
|
||||
return LocalMemoryHelper::get(pHwInfo->platform.eProductFamily)->createGemExt(drm, data, dataSize, allocSize, handle);
|
||||
}
|
||||
|
||||
drm_i915_gem_memory_class_instance MemoryInfo::getMemoryRegionClassAndInstance(uint32_t memoryBank, const HardwareInfo &hwInfo) {
|
||||
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
||||
if (!hwHelper.getEnableLocalMemory(hwInfo) || memoryBank == 0) {
|
||||
return systemMemoryRegion.region;
|
||||
}
|
||||
|
||||
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 MemoryInfo::getMemoryRegionSize(uint32_t memoryBank) {
|
||||
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;
|
||||
}
|
||||
|
||||
void MemoryInfo::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;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MemoryInfo::createGemExtWithSingleRegion(Drm *drm, uint32_t memoryBanks, size_t allocSize, uint32_t &handle) {
|
||||
auto pHwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto regionClassAndInstance = getMemoryRegionClassAndInstance(memoryBanks, *pHwInfo);
|
||||
auto ret = createGemExt(drm, ®ionClassAndInstance, 1, allocSize, handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -6,21 +6,44 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "drm/i915_drm.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace NEO {
|
||||
class Drm;
|
||||
struct HardwareInfo;
|
||||
|
||||
class MemoryInfo {
|
||||
public:
|
||||
MemoryInfo() = default;
|
||||
virtual ~MemoryInfo() = 0;
|
||||
virtual size_t getMemoryRegionSize(uint32_t memoryBank) = 0;
|
||||
virtual uint32_t createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle) = 0;
|
||||
virtual uint32_t createGemExtWithSingleRegion(Drm *drm, uint32_t memoryBanks, size_t allocSize, uint32_t &handle) = 0;
|
||||
using RegionContainer = std::vector<drm_i915_memory_region_info>;
|
||||
|
||||
virtual ~MemoryInfo(){};
|
||||
|
||||
MemoryInfo(const drm_i915_memory_region_info *regionInfo, size_t count);
|
||||
|
||||
void assignRegionsFromDistances(const void *distanceInfosPtr, size_t size);
|
||||
|
||||
MOCKABLE_VIRTUAL uint32_t createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle);
|
||||
|
||||
drm_i915_gem_memory_class_instance getMemoryRegionClassAndInstance(uint32_t memoryBank, const HardwareInfo &hwInfo);
|
||||
|
||||
MOCKABLE_VIRTUAL size_t getMemoryRegionSize(uint32_t memoryBank);
|
||||
|
||||
void printRegionSizes();
|
||||
|
||||
MOCKABLE_VIRTUAL uint32_t createGemExtWithSingleRegion(Drm *drm, uint32_t memoryBanks, size_t allocSize, uint32_t &handle);
|
||||
|
||||
const RegionContainer &getDrmRegionInfos() const { return drmQueryRegions; }
|
||||
|
||||
protected:
|
||||
const RegionContainer drmQueryRegions;
|
||||
|
||||
const drm_i915_memory_region_info &systemMemoryRegion;
|
||||
|
||||
RegionContainer localMemoryRegions;
|
||||
};
|
||||
|
||||
inline MemoryInfo::~MemoryInfo(){};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/memory_info_impl.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/os_interface/linux/memory_info.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
MemoryInfoImpl::MemoryInfoImpl(const drm_i915_memory_region_info *regionInfo, size_t count)
|
||||
MemoryInfo::MemoryInfo(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),
|
||||
@@ -20,7 +23,7 @@ MemoryInfoImpl::MemoryInfoImpl(const drm_i915_memory_region_info *regionInfo, si
|
||||
});
|
||||
}
|
||||
|
||||
void MemoryInfoImpl::assignRegionsFromDistances(const void *distanceInfosPtr, size_t size) {
|
||||
void MemoryInfo::assignRegionsFromDistances(const void *distanceInfosPtr, size_t size) {
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/execution_environment/root_device_environment.h"
|
||||
#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/local_memory_helper.h"
|
||||
#include "shared/source/os_interface/linux/memory_info.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
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);
|
||||
|
||||
void assignRegionsFromDistances(const void *distanceInfosPtr, size_t size);
|
||||
|
||||
uint32_t createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle) override {
|
||||
auto pHwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
|
||||
return LocalMemoryHelper::get(pHwInfo->platform.eProductFamily)->createGemExt(drm, data, dataSize, allocSize, handle);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t createGemExtWithSingleRegion(Drm *drm, uint32_t memoryBanks, size_t allocSize, uint32_t &handle) override {
|
||||
auto pHwInfo = drm->getRootDeviceEnvironment().getHardwareInfo();
|
||||
auto regionClassAndInstance = getMemoryRegionClassAndInstance(memoryBanks, *pHwInfo);
|
||||
auto ret = createGemExt(drm, ®ionClassAndInstance, 1, allocSize, handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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