Skip to content

Commit 4958418

Browse files
Free allocations in 2MB heaps
Related-To: NEO-5750 Signed-off-by: Maciej Dziuban <[email protected]>
1 parent 0607118 commit 4958418

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

opencl/test/unit_test/memory_manager/gfx_partition_tests.inl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,51 @@ TEST(GfxPartitionTest, givenInternalHeapWhenAllocatingSmallOrBigChunkThenAddress
402402
gfxPartition.heapFree(heaps[i], address, sizeToAlloc);
403403
}
404404
}
405+
406+
using GfxPartitionTestForAllHeapTypes = ::testing::TestWithParam<HeapIndex>;
407+
408+
TEST_P(GfxPartitionTestForAllHeapTypes, givenHeapIndexWhenFreeGpuAddressRangeIsCalledThenFreeMemory) {
409+
MockGfxPartition gfxPartition;
410+
gfxPartition.init(maxNBitValue(48), reservedCpuAddressRangeSize, 0, 1);
411+
const HeapIndex heapIndex = GetParam();
412+
const size_t allocationSize = static_cast<size_t>(gfxPartition.getHeapSize(heapIndex)) * 3 / 4;
413+
if (allocationSize == 0) {
414+
GTEST_SKIP();
415+
}
416+
if (is32bit) {
417+
auto it = std::find(GfxPartition::heap32Names.begin(), GfxPartition::heap32Names.end(), heapIndex);
418+
auto is64bitHeap = it == GfxPartition::heap32Names.end();
419+
if (is64bitHeap) {
420+
GTEST_SKIP();
421+
}
422+
}
423+
size_t sizeToAllocate{};
424+
425+
// Allocate majority of the heap
426+
sizeToAllocate = allocationSize;
427+
auto address = gfxPartition.heapAllocate(heapIndex, sizeToAllocate);
428+
const size_t sizeAllocated = sizeToAllocate;
429+
EXPECT_NE(0ull, address);
430+
EXPECT_GE(sizeAllocated, allocationSize);
431+
432+
// Another one cannot be allocated
433+
sizeToAllocate = allocationSize;
434+
EXPECT_EQ(0ull, gfxPartition.heapAllocate(heapIndex, sizeToAllocate));
435+
436+
// Allocation is possible again after freeing
437+
gfxPartition.freeGpuAddressRange(address, sizeAllocated);
438+
sizeToAllocate = allocationSize;
439+
EXPECT_NE(0ull, gfxPartition.heapAllocate(heapIndex, sizeToAllocate));
440+
}
441+
442+
INSTANTIATE_TEST_SUITE_P(
443+
GfxPartitionTestForAllHeapTypesTests,
444+
GfxPartitionTestForAllHeapTypes,
445+
::testing::Values(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY,
446+
HeapIndex::HEAP_INTERNAL,
447+
HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY,
448+
HeapIndex::HEAP_EXTERNAL,
449+
HeapIndex::HEAP_STANDARD,
450+
HeapIndex::HEAP_STANDARD64KB,
451+
HeapIndex::HEAP_STANDARD2MB,
452+
HeapIndex::HEAP_EXTENDED));

opencl/test/unit_test/mocks/mock_gfx_partition.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class MockGfxPartition : public GfxPartition {
4848
}
4949
}
5050

51-
MOCK_METHOD(void, freeGpuAddressRange, (uint64_t gpuAddress, size_t size), (override));
52-
5351
static std::array<HeapIndex, static_cast<uint32_t>(HeapIndex::TOTAL_HEAPS)> allHeapNames;
5452

5553
OSMemory::ReservedCpuAddressRange reservedCpuAddressRange;
@@ -58,6 +56,11 @@ class MockGfxPartition : public GfxPartition {
5856
const uint64_t mockGpuVa = std::numeric_limits<uint64_t>::max();
5957
};
6058

59+
struct GmockGfxPartition : MockGfxPartition {
60+
using MockGfxPartition::MockGfxPartition;
61+
MOCK_METHOD(void, freeGpuAddressRange, (uint64_t gpuAddress, size_t size), (override));
62+
};
63+
6164
class MockGfxPartitionBasic : public GfxPartition {
6265
public:
6366
MockGfxPartitionBasic() : GfxPartition(reservedCpuAddressRange) {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3899,7 +3899,7 @@ TEST_F(DrmMemoryManagerTest, givenSvmCpuAllocationWhenSizeAndAlignmentProvidedBu
38993899
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndReleaseGpuRangeIsCalledThenGpuAddressIsDecanonized) {
39003900
constexpr size_t reservedCpuAddressRangeSize = is64bit ? (6 * 4 * GB) : 0;
39013901
auto hwInfo = defaultHwInfo.get();
3902-
auto mockGfxPartition = std::make_unique<MockGfxPartition>();
3902+
auto mockGfxPartition = std::make_unique<GmockGfxPartition>();
39033903
mockGfxPartition->init(hwInfo->capabilityTable.gpuAddressSpace, reservedCpuAddressRangeSize, 0, 1);
39043904
auto size = 2 * MemoryConstants::megaByte;
39053905
auto gpuAddress = mockGfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD, size);

shared/source/memory_manager/gfx_partition.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ const std::array<HeapIndex, 4> GfxPartition::heap32Names{{HeapIndex::HEAP_INTERN
1919
HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY,
2020
HeapIndex::HEAP_EXTERNAL}};
2121

22-
const std::array<HeapIndex, 7> GfxPartition::heapNonSvmNames{{HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY,
22+
const std::array<HeapIndex, 8> GfxPartition::heapNonSvmNames{{HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY,
2323
HeapIndex::HEAP_INTERNAL,
2424
HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY,
2525
HeapIndex::HEAP_EXTERNAL,
2626
HeapIndex::HEAP_STANDARD,
2727
HeapIndex::HEAP_STANDARD64KB,
28+
HeapIndex::HEAP_STANDARD2MB,
2829
HeapIndex::HEAP_EXTENDED}};
2930

3031
GfxPartition::GfxPartition(OSMemory::ReservedCpuAddressRange &sharedReservedCpuAddressRange) : reservedCpuAddressRange(sharedReservedCpuAddressRange), osMemory(OSMemory::create()) {}

shared/source/memory_manager/gfx_partition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class GfxPartition {
113113
static constexpr size_t internalFrontWindowPoolSize = 1 * MemoryConstants::megaByte;
114114

115115
static const std::array<HeapIndex, 4> heap32Names;
116-
static const std::array<HeapIndex, 7> heapNonSvmNames;
116+
static const std::array<HeapIndex, 8> heapNonSvmNames;
117117

118118
protected:
119119
bool initAdditionalRange(uint32_t cpuAddressWidth, uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop, uint32_t rootDeviceIndex, size_t numRootDevices);

0 commit comments

Comments
 (0)