From 3fab76d95ef449250009fa366a56551c2bcae7bd Mon Sep 17 00:00:00 2001 From: "Venevtsev, Igor" Date: Tue, 10 Sep 2019 14:59:45 +0200 Subject: [PATCH] Add GfxPartition::initAdditionalRange() stub Related-To: NEO-2941 Change-Id: Iec74652a5ee2cc79af9093d520e892cb30045cdf Signed-off-by: Venevtsev, Igor --- Jenkinsfile | 2 +- core/memory_manager/CMakeLists.txt | 1 + core/memory_manager/gfx_partition.cpp | 2 +- core/memory_manager/gfx_partition.h | 2 + .../gfx_partition_init_additional_range.cpp | 16 +++ unit_tests/memory_manager/CMakeLists.txt | 3 +- .../memory_manager/gfx_partition_tests.cpp | 105 +-------------- .../memory_manager/gfx_partition_tests.inl | 126 ++++++++++++++++++ 8 files changed, 150 insertions(+), 107 deletions(-) create mode 100644 core/memory_manager/gfx_partition_init_additional_range.cpp create mode 100644 unit_tests/memory_manager/gfx_partition_tests.inl diff --git a/Jenkinsfile b/Jenkinsfile index 38a185928a..4049d306a3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy dependenciesRevision='3387a68d271545925f5ff091109728166e6f6d46-1309' strategy='EQUAL' -allowedCD=260 +allowedCD=259 allowedF=5 diff --git a/core/memory_manager/CMakeLists.txt b/core/memory_manager/CMakeLists.txt index 7378e0fa16..a36b9f5fad 100644 --- a/core/memory_manager/CMakeLists.txt +++ b/core/memory_manager/CMakeLists.txt @@ -9,6 +9,7 @@ set(NEO_CORE_MEMORY_MANAGER ${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/engine_limits.h ${CMAKE_CURRENT_SOURCE_DIR}/eviction_status.h ${CMAKE_CURRENT_SOURCE_DIR}/gfx_partition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${BRANCH_DIR_SUFFIX}/gfx_partition_init_additional_range.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gfx_partition.h ${CMAKE_CURRENT_SOURCE_DIR}/host_ptr_defines.h ${CMAKE_CURRENT_SOURCE_DIR}/local_memory_usage.cpp diff --git a/core/memory_manager/gfx_partition.cpp b/core/memory_manager/gfx_partition.cpp index f8d098e7d9..12dab7db67 100644 --- a/core/memory_manager/gfx_partition.cpp +++ b/core/memory_manager/gfx_partition.cpp @@ -125,7 +125,7 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe gfxBase = 0ull; heapInit(HeapIndex::HEAP_SVM, 0ull, 0ull); } else { - UNRECOVERABLE_IF("Invalid GPU Address Range!"); + initAdditionalRange(gpuAddressSpace, gfxBase, gfxTop); } } diff --git a/core/memory_manager/gfx_partition.h b/core/memory_manager/gfx_partition.h index 0fb816b298..7b778c5a10 100644 --- a/core/memory_manager/gfx_partition.h +++ b/core/memory_manager/gfx_partition.h @@ -70,6 +70,8 @@ class GfxPartition { static const std::array heapNonSvmNames; protected: + void initAdditionalRange(uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop); + class Heap { public: Heap() = default; diff --git a/core/memory_manager/gfx_partition_init_additional_range.cpp b/core/memory_manager/gfx_partition_init_additional_range.cpp new file mode 100644 index 0000000000..4461fe4de6 --- /dev/null +++ b/core/memory_manager/gfx_partition_init_additional_range.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "core/memory_manager/gfx_partition.h" + +namespace NEO { + +void GfxPartition::initAdditionalRange(uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop) { + UNRECOVERABLE_IF("Invalid GPU Address Range!"); +} + +} // namespace NEO diff --git a/unit_tests/memory_manager/CMakeLists.txt b/unit_tests/memory_manager/CMakeLists.txt index f7919f75f5..45b9ca4535 100644 --- a/unit_tests/memory_manager/CMakeLists.txt +++ b/unit_tests/memory_manager/CMakeLists.txt @@ -10,7 +10,8 @@ set(IGDRCL_SRCS_tests_memory_manager ${CMAKE_CURRENT_SOURCE_DIR}/cpu_page_fault_manager_memory_sync_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/deferrable_allocation_deletion_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter_mt_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gfx_partition_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${BRANCH_DIR_SUFFIX}/gfx_partition_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gfx_partition_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/host_ptr_manager_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/internal_allocation_storage_tests.cpp diff --git a/unit_tests/memory_manager/gfx_partition_tests.cpp b/unit_tests/memory_manager/gfx_partition_tests.cpp index 4f2b5107fd..3a2e9fa959 100644 --- a/unit_tests/memory_manager/gfx_partition_tests.cpp +++ b/unit_tests/memory_manager/gfx_partition_tests.cpp @@ -5,107 +5,4 @@ * */ -#include "core/helpers/aligned_memory.h" -#include "core/helpers/basic_math.h" -#include "core/helpers/ptr_math.h" -#include "core/os_interface/os_memory.h" -#include "unit_tests/mocks/mock_gfx_partition.h" - -#include "gtest/gtest.h" - -using namespace NEO; - -void testGfxPartition(uint64_t gpuAddressSpace) { - MockGfxPartition gfxPartition; - size_t reservedCpuAddressRangeSize = is64bit ? (6 * 4 * GB) : 0; - gfxPartition.init(gpuAddressSpace, reservedCpuAddressRangeSize); - - uint64_t gfxTop = gpuAddressSpace + 1; - uint64_t gfxBase = MemoryConstants::maxSvmAddress + 1; - const uint64_t sizeHeap32 = 4 * MemoryConstants::gigaByte; - - if (is32bit || maxNBitValue<48> == gpuAddressSpace) { - // Full range SVM 48/32-bit - EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); - EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), 0ull); - EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), gfxBase); - EXPECT_EQ(gfxPartition.getHeapLimit(HeapIndex::HEAP_SVM), MemoryConstants::maxSvmAddress); - } else if (maxNBitValue<47> == gpuAddressSpace) { - // Full range SVM 47-bit - gfxBase = (uint64_t)gfxPartition.getReservedCpuAddressRange(); - gfxTop = gfxBase + gfxPartition.getReservedCpuAddressRangeSize(); - EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); - EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), 0ull); - EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), is64bit ? gpuAddressSpace + 1 : gfxBase); - EXPECT_EQ(gfxPartition.getHeapLimit(HeapIndex::HEAP_SVM), MemoryConstants::maxSvmAddress); - } else { - // Limited range - EXPECT_FALSE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); - gfxBase = 0ull; - } - - for (auto heap32 : GfxPartition::heap32Names) { - EXPECT_TRUE(gfxPartition.heapInitialized(heap32)); - EXPECT_TRUE(isAligned(gfxPartition.getHeapBase(heap32))); - EXPECT_EQ(gfxPartition.getHeapBase(heap32), gfxBase); - EXPECT_EQ(gfxPartition.getHeapSize(heap32), sizeHeap32); - gfxBase += sizeHeap32; - } - - uint64_t sizeStandard = (gfxTop - gfxBase) >> 1; - - EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_STANDARD)); - auto heapStandardBase = gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD); - auto heapStandardSize = gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD); - EXPECT_TRUE(isAligned(heapStandardBase)); - EXPECT_EQ(heapStandardBase, gfxBase); - EXPECT_EQ(heapStandardSize, sizeStandard); - - gfxBase += sizeStandard; - EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_STANDARD64KB)); - auto heapStandard64KbBase = gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD64KB); - auto heapStandard64KbSize = gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD64KB); - EXPECT_TRUE(isAligned(heapStandard64KbBase)); - - EXPECT_EQ(heapStandard64KbBase, heapStandardBase + heapStandardSize); - EXPECT_EQ(heapStandard64KbSize, heapStandardSize); - EXPECT_EQ(heapStandard64KbBase + heapStandard64KbSize, gfxTop); - EXPECT_EQ(gfxBase + sizeStandard, gfxTop); - - size_t sizeSmall = MemoryConstants::pageSize; - size_t sizeBig = 4 * MemoryConstants::megaByte + MemoryConstants::pageSize; - for (auto heap : MockGfxPartition::allHeapNames) { - if (!gfxPartition.heapInitialized(heap)) { - EXPECT_TRUE(heap == HeapIndex::HEAP_SVM); - continue; - } - - EXPECT_GT(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap)); - EXPECT_EQ(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap) + GfxPartition::heapGranularity); - - auto ptrBig = gfxPartition.heapAllocate(heap, sizeBig); - EXPECT_NE(ptrBig, 0ull); - EXPECT_LT(gfxPartition.getHeapBase(heap), ptrBig); - EXPECT_EQ(ptrBig, gfxPartition.getHeapBase(heap) + GfxPartition::heapGranularity); - gfxPartition.heapFree(heap, ptrBig, sizeBig); - - auto ptrSmall = gfxPartition.heapAllocate(heap, sizeSmall); - EXPECT_NE(ptrSmall, 0ull); - EXPECT_LT(gfxPartition.getHeapBase(heap), ptrSmall); - EXPECT_GT(gfxPartition.getHeapLimit(heap), ptrSmall); - EXPECT_EQ(ptrSmall, gfxPartition.getHeapBase(heap) + gfxPartition.getHeapSize(heap) - GfxPartition::heapGranularity - sizeSmall); - gfxPartition.heapFree(heap, ptrSmall, sizeSmall); - } -} - -TEST(GfxPartitionTest, testGfxPartitionFullRange48BitSVM) { - testGfxPartition(maxNBitValue<48>); -} - -TEST(GfxPartitionTest, testGfxPartitionFullRange47BitSVM) { - testGfxPartition(maxNBitValue<47>); -} - -TEST(GfxPartitionTest, testGfxPartitionLimitedRange) { - testGfxPartition(maxNBitValue<47 - 1>); -} +#include "unit_tests/memory_manager/gfx_partition_tests.inl" diff --git a/unit_tests/memory_manager/gfx_partition_tests.inl b/unit_tests/memory_manager/gfx_partition_tests.inl new file mode 100644 index 0000000000..631f89ce0c --- /dev/null +++ b/unit_tests/memory_manager/gfx_partition_tests.inl @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "core/helpers/aligned_memory.h" +#include "core/helpers/basic_math.h" +#include "core/helpers/ptr_math.h" +#include "core/os_interface/os_memory.h" +#include "unit_tests/mocks/mock_gfx_partition.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +constexpr size_t reservedCpuAddressRangeSize = is64bit ? (6 * 4 * GB) : 0; +constexpr uint64_t sizeHeap32 = 4 * MemoryConstants::gigaByte; + +void testGfxPartition(MockGfxPartition &gfxPartition, uint64_t gfxBase, uint64_t gfxTop, uint64_t svmTop) { + if (svmTop) { + // SVM should be initialized + EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); + EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), 0ull); + EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), svmTop); + EXPECT_EQ(gfxPartition.getHeapLimit(HeapIndex::HEAP_SVM), svmTop - 1); + } else { + // Limited range + EXPECT_FALSE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); + } + + for (auto heap32 : GfxPartition::heap32Names) { + EXPECT_TRUE(gfxPartition.heapInitialized(heap32)); + EXPECT_TRUE(isAligned(gfxPartition.getHeapBase(heap32))); + EXPECT_EQ(gfxPartition.getHeapBase(heap32), gfxBase); + EXPECT_EQ(gfxPartition.getHeapSize(heap32), sizeHeap32); + gfxBase += sizeHeap32; + } + + uint64_t sizeStandard = (gfxTop - gfxBase) >> 1; + + EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_STANDARD)); + auto heapStandardBase = gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD); + auto heapStandardSize = gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD); + EXPECT_TRUE(isAligned(heapStandardBase)); + EXPECT_EQ(heapStandardBase, gfxBase); + EXPECT_EQ(heapStandardSize, sizeStandard); + + gfxBase += sizeStandard; + EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_STANDARD64KB)); + auto heapStandard64KbBase = gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD64KB); + auto heapStandard64KbSize = gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD64KB); + EXPECT_TRUE(isAligned(heapStandard64KbBase)); + + EXPECT_EQ(heapStandard64KbBase, heapStandardBase + heapStandardSize); + EXPECT_EQ(heapStandard64KbSize, heapStandardSize); + EXPECT_EQ(heapStandard64KbBase + heapStandard64KbSize, gfxTop); + EXPECT_EQ(gfxBase + sizeStandard, gfxTop); + + size_t sizeSmall = MemoryConstants::pageSize; + size_t sizeBig = 4 * MemoryConstants::megaByte + MemoryConstants::pageSize; + for (auto heap : MockGfxPartition::allHeapNames) { + if (!gfxPartition.heapInitialized(heap)) { + EXPECT_TRUE(heap == HeapIndex::HEAP_SVM); + continue; + } + + EXPECT_GT(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap)); + EXPECT_EQ(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap) + GfxPartition::heapGranularity); + + auto ptrBig = gfxPartition.heapAllocate(heap, sizeBig); + EXPECT_NE(ptrBig, 0ull); + EXPECT_LT(gfxPartition.getHeapBase(heap), ptrBig); + EXPECT_EQ(ptrBig, gfxPartition.getHeapBase(heap) + GfxPartition::heapGranularity); + gfxPartition.heapFree(heap, ptrBig, sizeBig); + + auto ptrSmall = gfxPartition.heapAllocate(heap, sizeSmall); + EXPECT_NE(ptrSmall, 0ull); + EXPECT_LT(gfxPartition.getHeapBase(heap), ptrSmall); + EXPECT_GT(gfxPartition.getHeapLimit(heap), ptrSmall); + EXPECT_EQ(ptrSmall, gfxPartition.getHeapBase(heap) + gfxPartition.getHeapSize(heap) - GfxPartition::heapGranularity - sizeSmall); + gfxPartition.heapFree(heap, ptrSmall, sizeSmall); + } +} + +TEST(GfxPartitionTest, testGfxPartitionFullRange48BitSVM) { + MockGfxPartition gfxPartition; + gfxPartition.init(maxNBitValue<48>, reservedCpuAddressRangeSize); + + uint64_t gfxTop = maxNBitValue<48> + 1; + uint64_t gfxBase = MemoryConstants::maxSvmAddress + 1; + + testGfxPartition(gfxPartition, gfxBase, gfxTop, gfxBase); +} + +TEST(GfxPartitionTest, testGfxPartitionFullRange47BitSVM) { + MockGfxPartition gfxPartition; + gfxPartition.init(maxNBitValue<47>, reservedCpuAddressRangeSize); + + uint64_t gfxBase = is32bit ? MemoryConstants::maxSvmAddress + 1 : (uint64_t)gfxPartition.getReservedCpuAddressRange(); + uint64_t gfxTop = is32bit ? maxNBitValue<47> + 1 : gfxBase + gfxPartition.getReservedCpuAddressRangeSize(); + uint64_t svmTop = MemoryConstants::maxSvmAddress + 1; + + testGfxPartition(gfxPartition, gfxBase, gfxTop, svmTop); +} + +TEST(GfxPartitionTest, testGfxPartitionLimitedRange) { + MockGfxPartition gfxPartition; + gfxPartition.init(maxNBitValue<47 - 1>, reservedCpuAddressRangeSize); + + uint64_t gfxBase = is32bit ? MemoryConstants::maxSvmAddress + 1 : 0ull; + uint64_t gfxTop = maxNBitValue<47 - 1> + 1; + uint64_t svmTop = gfxBase; + + testGfxPartition(gfxPartition, gfxBase, gfxTop, svmTop); +} + +TEST(GfxPartitionTest, testGfxPartitionUnsupportedRange) { + if (is32bit) { + GTEST_SKIP(); + } + + MockGfxPartition gfxPartition; + EXPECT_THROW(gfxPartition.init(maxNBitValue<48 + 1>, reservedCpuAddressRangeSize), std::exception); +}