mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 23:56:36 +08:00
Add assignRegionsFromDistances logic
If prelim kernel is being used, use distances logic to assign memory regions. Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
0c2f83579c
commit
5be9d2d584
@@ -103,31 +103,6 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsAndLocalMemoryEnabledWhenGettingMemor
|
|||||||
EXPECT_EQ(16 * GB, regionSize);
|
EXPECT_EQ(16 * GB, regionSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MemoryInfo, givenMemoryInfoWithRegionsAndLocalMemoryEnabledWhenAssignRegionsFromDistancesThenRegionsNotChanged) {
|
|
||||||
DebugManagerStateRestore restorer;
|
|
||||||
DebugManager.flags.EnableLocalMemory.set(1);
|
|
||||||
std::vector<MemoryRegion> regionInfo(2);
|
|
||||||
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
|
|
||||||
regionInfo[0].probedSize = 8 * GB;
|
|
||||||
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
|
|
||||||
regionInfo[1].probedSize = 16 * GB;
|
|
||||||
|
|
||||||
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo);
|
|
||||||
ASSERT_NE(nullptr, memoryInfo);
|
|
||||||
memoryInfo->assignRegionsFromDistances(®ionInfo, 2);
|
|
||||||
auto regionClassAndInstance = memoryInfo->getMemoryRegionClassAndInstance(MemoryBanks::MainBank, *defaultHwInfo);
|
|
||||||
EXPECT_EQ(regionInfo[0].region.memoryClass, regionClassAndInstance.memoryClass);
|
|
||||||
EXPECT_EQ(regionInfo[0].region.memoryInstance, regionClassAndInstance.memoryInstance);
|
|
||||||
auto regionSize = memoryInfo->getMemoryRegionSize(MemoryBanks::MainBank);
|
|
||||||
EXPECT_EQ(8 * GB, regionSize);
|
|
||||||
|
|
||||||
regionClassAndInstance = memoryInfo->getMemoryRegionClassAndInstance(MemoryBanks::getBankForLocalMemory(0), *defaultHwInfo);
|
|
||||||
EXPECT_EQ(regionInfo[1].region.memoryClass, regionClassAndInstance.memoryClass);
|
|
||||||
EXPECT_EQ(regionInfo[1].region.memoryInstance, regionClassAndInstance.memoryInstance);
|
|
||||||
regionSize = memoryInfo->getMemoryRegionSize(MemoryBanks::getBankForLocalMemory(0));
|
|
||||||
EXPECT_EQ(16 * GB, regionSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(MemoryInfo, givenMemoryInfoWithoutDeviceRegionWhenGettingDeviceRegionSizeThenReturnCorrectSize) {
|
TEST(MemoryInfo, givenMemoryInfoWithoutDeviceRegionWhenGettingDeviceRegionSizeThenReturnCorrectSize) {
|
||||||
std::vector<MemoryRegion> regionInfo(1);
|
std::vector<MemoryRegion> regionInfo(1);
|
||||||
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
|
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
|
||||||
|
|||||||
@@ -5755,4 +5755,36 @@ TEST_F(DrmMemoryManagerTest, whenCallPaddedAllocationWithMmapPtrAndFailedMmapCal
|
|||||||
mock->ioctl_res = 0;
|
mock->ioctl_res = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(DistanceInfoTest, givenDistanceInfosWhenAssignRegionsFromDistancesThenCorrectRegionsSet) {
|
||||||
|
std::vector<MemoryRegion> memRegions(4);
|
||||||
|
memRegions[0] = {{I915_MEMORY_CLASS_SYSTEM, 0}, 1024, 0};
|
||||||
|
memRegions[1] = {{I915_MEMORY_CLASS_DEVICE, 0}, 1024, 0};
|
||||||
|
memRegions[2] = {{I915_MEMORY_CLASS_DEVICE, 1}, 1024, 0};
|
||||||
|
memRegions[3] = {{I915_MEMORY_CLASS_DEVICE, 2}, 1024, 0};
|
||||||
|
auto memoryInfo = std::make_unique<MemoryInfo>(memRegions);
|
||||||
|
|
||||||
|
std::vector<EngineClassInstance> engines(3);
|
||||||
|
engines[0] = {I915_ENGINE_CLASS_RENDER, 0};
|
||||||
|
engines[1] = {I915_ENGINE_CLASS_COPY, 0};
|
||||||
|
engines[2] = {I915_ENGINE_CLASS_COPY, 2};
|
||||||
|
|
||||||
|
auto distances = std::vector<DistanceInfo>();
|
||||||
|
for (const auto ®ion : memRegions) {
|
||||||
|
if (region.region.memoryClass == I915_MEMORY_CLASS_SYSTEM) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const auto &engine : engines) {
|
||||||
|
DistanceInfo dist{};
|
||||||
|
dist.engine = engine;
|
||||||
|
dist.region = {region.region.memoryClass, region.region.memoryInstance};
|
||||||
|
dist.distance = (region.region.memoryInstance == engine.engineInstance) ? 0 : 100;
|
||||||
|
distances.push_back(dist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memoryInfo->assignRegionsFromDistances(distances);
|
||||||
|
EXPECT_EQ(1024u, memoryInfo->getMemoryRegionSize(1));
|
||||||
|
EXPECT_EQ(1024u, memoryInfo->getMemoryRegionSize(2));
|
||||||
|
EXPECT_EQ(0u, memoryInfo->getMemoryRegionSize(4));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace NEO
|
} // namespace NEO
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ 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_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_memory_operations_handler_create.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_query.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_query.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_info_config_drm.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id.h
|
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.cpp
|
||||||
|
|||||||
@@ -25,12 +25,23 @@ struct MemoryClassInstance {
|
|||||||
uint16_t memoryInstance;
|
uint16_t memoryInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct EngineClassInstance {
|
||||||
|
uint16_t engineClass;
|
||||||
|
uint16_t engineInstance;
|
||||||
|
};
|
||||||
|
|
||||||
struct MemoryRegion {
|
struct MemoryRegion {
|
||||||
MemoryClassInstance region;
|
MemoryClassInstance region;
|
||||||
uint64_t probedSize;
|
uint64_t probedSize;
|
||||||
uint64_t unallocatedSize;
|
uint64_t unallocatedSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DistanceInfo {
|
||||||
|
MemoryClassInstance region;
|
||||||
|
EngineClassInstance engine;
|
||||||
|
int32_t distance;
|
||||||
|
};
|
||||||
|
|
||||||
class IoctlHelper {
|
class IoctlHelper {
|
||||||
public:
|
public:
|
||||||
virtual ~IoctlHelper() {}
|
virtual ~IoctlHelper() {}
|
||||||
|
|||||||
@@ -15,6 +15,40 @@
|
|||||||
|
|
||||||
namespace NEO {
|
namespace NEO {
|
||||||
|
|
||||||
|
MemoryInfo::MemoryInfo(const RegionContainer ®ionInfo)
|
||||||
|
: drmQueryRegions(regionInfo), systemMemoryRegion(drmQueryRegions[0]) {
|
||||||
|
UNRECOVERABLE_IF(systemMemoryRegion.region.memoryClass != I915_MEMORY_CLASS_SYSTEM);
|
||||||
|
std::copy_if(drmQueryRegions.begin(), drmQueryRegions.end(), std::back_inserter(localMemoryRegions),
|
||||||
|
[](const MemoryRegion &memoryRegionInfo) {
|
||||||
|
return (memoryRegionInfo.region.memoryClass == I915_MEMORY_CLASS_DEVICE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryInfo::assignRegionsFromDistances(const std::vector<DistanceInfo> &distances) {
|
||||||
|
localMemoryRegions.clear();
|
||||||
|
|
||||||
|
uint32_t memoryRegionCounter = 1;
|
||||||
|
uint32_t tile = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < distances.size(); i++) {
|
||||||
|
if (i > 0 && distances[i].region.memoryInstance != distances[i - 1].region.memoryInstance) {
|
||||||
|
UNRECOVERABLE_IF(distances[i].distance == 0);
|
||||||
|
|
||||||
|
memoryRegionCounter++;
|
||||||
|
tile++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((distances[i].distance != 0) || (localMemoryRegions.size() == (tile + 1))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
UNRECOVERABLE_IF((drmQueryRegions[memoryRegionCounter].region.memoryClass != distances[i].region.memoryClass) ||
|
||||||
|
(drmQueryRegions[memoryRegionCounter].region.memoryInstance != distances[i].region.memoryInstance));
|
||||||
|
|
||||||
|
localMemoryRegions.push_back(drmQueryRegions[memoryRegionCounter]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t MemoryInfo::createGemExt(Drm *drm, const std::vector<MemoryClassInstance> &memClassInstances, size_t allocSize, uint32_t &handle) {
|
uint32_t MemoryInfo::createGemExt(Drm *drm, const std::vector<MemoryClassInstance> &memClassInstances, size_t allocSize, uint32_t &handle) {
|
||||||
return IoctlHelper::get(drm)->createGemExt(drm, memClassInstances, allocSize, handle);
|
return IoctlHelper::get(drm)->createGemExt(drm, memClassInstances, allocSize, handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class MemoryInfo {
|
|||||||
|
|
||||||
MemoryInfo(const RegionContainer ®ionInfo);
|
MemoryInfo(const RegionContainer ®ionInfo);
|
||||||
|
|
||||||
void assignRegionsFromDistances(const void *distanceInfosPtr, size_t size);
|
void assignRegionsFromDistances(const std::vector<DistanceInfo> &distances);
|
||||||
|
|
||||||
MOCKABLE_VIRTUAL uint32_t createGemExt(Drm *drm, const std::vector<MemoryClassInstance> &memClassInstances, size_t allocSize, uint32_t &handle);
|
MOCKABLE_VIRTUAL uint32_t createGemExt(Drm *drm, const std::vector<MemoryClassInstance> &memClassInstances, size_t allocSize, uint32_t &handle);
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020-2021 Intel Corporation
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: MIT
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "shared/source/helpers/debug_helpers.h"
|
|
||||||
#include "shared/source/os_interface/linux/memory_info.h"
|
|
||||||
|
|
||||||
#include "drm/i915_drm.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <iterator>
|
|
||||||
|
|
||||||
namespace NEO {
|
|
||||||
|
|
||||||
MemoryInfo::MemoryInfo(const RegionContainer ®ionInfo)
|
|
||||||
: drmQueryRegions(regionInfo), systemMemoryRegion(drmQueryRegions[0]) {
|
|
||||||
UNRECOVERABLE_IF(systemMemoryRegion.region.memoryClass != I915_MEMORY_CLASS_SYSTEM);
|
|
||||||
std::copy_if(drmQueryRegions.begin(), drmQueryRegions.end(), std::back_inserter(localMemoryRegions),
|
|
||||||
[](const MemoryRegion &memoryRegionInfo) {
|
|
||||||
return (memoryRegionInfo.region.memoryClass == I915_MEMORY_CLASS_DEVICE);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryInfo::assignRegionsFromDistances(const void *distanceInfosPtr, size_t size) {
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace NEO
|
|
||||||
Reference in New Issue
Block a user