Skip to content

Commit 5be9d2d

Browse files
Add assignRegionsFromDistances logic
If prelim kernel is being used, use distances logic to assign memory regions. Signed-off-by: Szymon Morek <[email protected]>
1 parent 0c2f835 commit 5be9d2d

File tree

7 files changed

+78
-57
lines changed

7 files changed

+78
-57
lines changed

opencl/test/unit_test/os_interface/linux/drm_memory_info_tests.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,6 @@ TEST(MemoryInfo, givenMemoryInfoWithRegionsAndLocalMemoryEnabledWhenGettingMemor
103103
EXPECT_EQ(16 * GB, regionSize);
104104
}
105105

106-
TEST(MemoryInfo, givenMemoryInfoWithRegionsAndLocalMemoryEnabledWhenAssignRegionsFromDistancesThenRegionsNotChanged) {
107-
DebugManagerStateRestore restorer;
108-
DebugManager.flags.EnableLocalMemory.set(1);
109-
std::vector<MemoryRegion> regionInfo(2);
110-
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
111-
regionInfo[0].probedSize = 8 * GB;
112-
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
113-
regionInfo[1].probedSize = 16 * GB;
114-
115-
auto memoryInfo = std::make_unique<MemoryInfo>(regionInfo);
116-
ASSERT_NE(nullptr, memoryInfo);
117-
memoryInfo->assignRegionsFromDistances(&regionInfo, 2);
118-
auto regionClassAndInstance = memoryInfo->getMemoryRegionClassAndInstance(MemoryBanks::MainBank, *defaultHwInfo);
119-
EXPECT_EQ(regionInfo[0].region.memoryClass, regionClassAndInstance.memoryClass);
120-
EXPECT_EQ(regionInfo[0].region.memoryInstance, regionClassAndInstance.memoryInstance);
121-
auto regionSize = memoryInfo->getMemoryRegionSize(MemoryBanks::MainBank);
122-
EXPECT_EQ(8 * GB, regionSize);
123-
124-
regionClassAndInstance = memoryInfo->getMemoryRegionClassAndInstance(MemoryBanks::getBankForLocalMemory(0), *defaultHwInfo);
125-
EXPECT_EQ(regionInfo[1].region.memoryClass, regionClassAndInstance.memoryClass);
126-
EXPECT_EQ(regionInfo[1].region.memoryInstance, regionClassAndInstance.memoryInstance);
127-
regionSize = memoryInfo->getMemoryRegionSize(MemoryBanks::getBankForLocalMemory(0));
128-
EXPECT_EQ(16 * GB, regionSize);
129-
}
130-
131106
TEST(MemoryInfo, givenMemoryInfoWithoutDeviceRegionWhenGettingDeviceRegionSizeThenReturnCorrectSize) {
132107
std::vector<MemoryRegion> regionInfo(1);
133108
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5755,4 +5755,36 @@ TEST_F(DrmMemoryManagerTest, whenCallPaddedAllocationWithMmapPtrAndFailedMmapCal
57555755
mock->ioctl_res = 0;
57565756
}
57575757

5758+
TEST(DistanceInfoTest, givenDistanceInfosWhenAssignRegionsFromDistancesThenCorrectRegionsSet) {
5759+
std::vector<MemoryRegion> memRegions(4);
5760+
memRegions[0] = {{I915_MEMORY_CLASS_SYSTEM, 0}, 1024, 0};
5761+
memRegions[1] = {{I915_MEMORY_CLASS_DEVICE, 0}, 1024, 0};
5762+
memRegions[2] = {{I915_MEMORY_CLASS_DEVICE, 1}, 1024, 0};
5763+
memRegions[3] = {{I915_MEMORY_CLASS_DEVICE, 2}, 1024, 0};
5764+
auto memoryInfo = std::make_unique<MemoryInfo>(memRegions);
5765+
5766+
std::vector<EngineClassInstance> engines(3);
5767+
engines[0] = {I915_ENGINE_CLASS_RENDER, 0};
5768+
engines[1] = {I915_ENGINE_CLASS_COPY, 0};
5769+
engines[2] = {I915_ENGINE_CLASS_COPY, 2};
5770+
5771+
auto distances = std::vector<DistanceInfo>();
5772+
for (const auto &region : memRegions) {
5773+
if (region.region.memoryClass == I915_MEMORY_CLASS_SYSTEM) {
5774+
continue;
5775+
}
5776+
for (const auto &engine : engines) {
5777+
DistanceInfo dist{};
5778+
dist.engine = engine;
5779+
dist.region = {region.region.memoryClass, region.region.memoryInstance};
5780+
dist.distance = (region.region.memoryInstance == engine.engineInstance) ? 0 : 100;
5781+
distances.push_back(dist);
5782+
}
5783+
}
5784+
memoryInfo->assignRegionsFromDistances(distances);
5785+
EXPECT_EQ(1024u, memoryInfo->getMemoryRegionSize(1));
5786+
EXPECT_EQ(1024u, memoryInfo->getMemoryRegionSize(2));
5787+
EXPECT_EQ(0u, memoryInfo->getMemoryRegionSize(4));
5788+
}
5789+
57585790
} // namespace NEO

shared/source/os_interface/linux/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ set(NEO_CORE_OS_INTERFACE_LINUX
4242
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_memory_manager_local_memory.cpp
4343
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_memory_operations_handler_create.cpp
4444
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_query.cpp
45-
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}memory_info_extended.cpp
4645
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_drm.cpp
4746
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id.h
4847
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.cpp

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@ struct MemoryClassInstance {
2525
uint16_t memoryInstance;
2626
};
2727

28+
struct EngineClassInstance {
29+
uint16_t engineClass;
30+
uint16_t engineInstance;
31+
};
32+
2833
struct MemoryRegion {
2934
MemoryClassInstance region;
3035
uint64_t probedSize;
3136
uint64_t unallocatedSize;
3237
};
3338

39+
struct DistanceInfo {
40+
MemoryClassInstance region;
41+
EngineClassInstance engine;
42+
int32_t distance;
43+
};
44+
3445
class IoctlHelper {
3546
public:
3647
virtual ~IoctlHelper() {}

shared/source/os_interface/linux/memory_info.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@
1515

1616
namespace NEO {
1717

18+
MemoryInfo::MemoryInfo(const RegionContainer &regionInfo)
19+
: drmQueryRegions(regionInfo), systemMemoryRegion(drmQueryRegions[0]) {
20+
UNRECOVERABLE_IF(systemMemoryRegion.region.memoryClass != I915_MEMORY_CLASS_SYSTEM);
21+
std::copy_if(drmQueryRegions.begin(), drmQueryRegions.end(), std::back_inserter(localMemoryRegions),
22+
[](const MemoryRegion &memoryRegionInfo) {
23+
return (memoryRegionInfo.region.memoryClass == I915_MEMORY_CLASS_DEVICE);
24+
});
25+
}
26+
27+
void MemoryInfo::assignRegionsFromDistances(const std::vector<DistanceInfo> &distances) {
28+
localMemoryRegions.clear();
29+
30+
uint32_t memoryRegionCounter = 1;
31+
uint32_t tile = 0;
32+
33+
for (size_t i = 0; i < distances.size(); i++) {
34+
if (i > 0 && distances[i].region.memoryInstance != distances[i - 1].region.memoryInstance) {
35+
UNRECOVERABLE_IF(distances[i].distance == 0);
36+
37+
memoryRegionCounter++;
38+
tile++;
39+
}
40+
41+
if ((distances[i].distance != 0) || (localMemoryRegions.size() == (tile + 1))) {
42+
continue;
43+
}
44+
45+
UNRECOVERABLE_IF((drmQueryRegions[memoryRegionCounter].region.memoryClass != distances[i].region.memoryClass) ||
46+
(drmQueryRegions[memoryRegionCounter].region.memoryInstance != distances[i].region.memoryInstance));
47+
48+
localMemoryRegions.push_back(drmQueryRegions[memoryRegionCounter]);
49+
}
50+
}
51+
1852
uint32_t MemoryInfo::createGemExt(Drm *drm, const std::vector<MemoryClassInstance> &memClassInstances, size_t allocSize, uint32_t &handle) {
1953
return IoctlHelper::get(drm)->createGemExt(drm, memClassInstances, allocSize, handle);
2054
}

shared/source/os_interface/linux/memory_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MemoryInfo {
2424

2525
MemoryInfo(const RegionContainer &regionInfo);
2626

27-
void assignRegionsFromDistances(const void *distanceInfosPtr, size_t size);
27+
void assignRegionsFromDistances(const std::vector<DistanceInfo> &distances);
2828

2929
MOCKABLE_VIRTUAL uint32_t createGemExt(Drm *drm, const std::vector<MemoryClassInstance> &memClassInstances, size_t allocSize, uint32_t &handle);
3030

shared/source/os_interface/linux/memory_info_extended.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)