diff --git a/Jenkinsfile b/Jenkinsfile index 0708450ed0..f42a4d51b8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy dependenciesRevision='03eca0b06275854df960e425756318fc68ac6d3c-1215' strategy='EQUAL' -allowedCD=274 +allowedCD=275 allowedF=4 diff --git a/runtime/memory_manager/CMakeLists.txt b/runtime/memory_manager/CMakeLists.txt index a53b90f100..245e5a3e13 100644 --- a/runtime/memory_manager/CMakeLists.txt +++ b/runtime/memory_manager/CMakeLists.txt @@ -16,6 +16,8 @@ set(RUNTIME_SRCS_MEMORY_MANAGER ${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter.h ${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/storage_info.cpp ${CMAKE_CURRENT_SOURCE_DIR}/definitions${BRANCH_DIR_SUFFIX}/storage_info.h + ${CMAKE_CURRENT_SOURCE_DIR}/gfx_partition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gfx_partition.h ${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation.h ${CMAKE_CURRENT_SOURCE_DIR}/host_ptr_defines.h diff --git a/runtime/memory_manager/gfx_partition.cpp b/runtime/memory_manager/gfx_partition.cpp new file mode 100644 index 0000000000..4cb226dfa9 --- /dev/null +++ b/runtime/memory_manager/gfx_partition.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/memory_manager/gfx_partition.h" + +#include "runtime/helpers/ptr_math.h" + +namespace OCLRT { + +const std::array GfxPartition::heap32Names{HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, + HeapIndex::HEAP_INTERNAL, + HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY, + HeapIndex::HEAP_EXTERNAL}; + +void GfxPartition::init(uint64_t gpuAddressSpace) { + + // 1) Full Range SVM gfx layout: + // + // SVM H0 H1 H2 H3 STANDARD STANDARD64K + // |__________________________________|____|____|____|____|________________|______________| + // | | | | | | | | + // | gfxBase gfxTop + // 0x0 0x0000800000000000/0x10000000 for 32 bit 0x0000FFFFFFFFFFFFFFFF + // + // 2) Limited Range gfx layout (no SVM): + // + // H0 H1 H2 H3 STANDARD STANDARD64K + // |____|____|____|____|____________________|__________________| + // | | | | | | | + // gfxBase gfxTop + // 0x0 0xFFF...FFF < 48 bit + + uint64_t gfxTop = gpuAddressSpace + 1; + uint64_t gfxBase = is64bit ? MemoryConstants::max64BitAppAddress + 1 : MemoryConstants::max32BitAddress + 1; + const uint64_t gfxHeap32Size = 4 * MemoryConstants::gigaByte; + const uint64_t gfxGranularity = 2 * MemoryConstants::megaByte; + + if (gpuAddressSpace == MemoryConstants::max48BitAddress) { // Full Range SVM + // Heap base should be greater than zero and 2MB aligned + heapInit(HeapIndex::HEAP_SVM, gfxGranularity, gfxBase - gfxGranularity); + } else { + // There is no SVM in LimitedRange - all memory except 4 32-bit heaps + // goes to STANDARD and STANDARD64KB partitions + gfxBase = 0ull; + } + + for (auto heap : GfxPartition::heap32Names) { + heapInit(heap, gfxBase ? gfxBase : gfxGranularity, gfxBase ? gfxHeap32Size : gfxHeap32Size - gfxGranularity); + gfxBase += gfxHeap32Size; + } + + uint64_t gfxStandardSize = (gfxTop - gfxBase) >> 1; + + heapInit(HeapIndex::HEAP_STANDARD, gfxBase, gfxStandardSize); + gfxBase += gfxStandardSize; + + auto gfxBaseAligned = alignUp(gfxBase, gfxGranularity); + heapInit(HeapIndex::HEAP_STANDARD64KB, gfxBaseAligned, gfxStandardSize - ptrDiff(gfxBaseAligned, gfxBase)); +} + +} // namespace OCLRT diff --git a/runtime/memory_manager/gfx_partition.h b/runtime/memory_manager/gfx_partition.h new file mode 100644 index 0000000000..ef2d1bc72b --- /dev/null +++ b/runtime/memory_manager/gfx_partition.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "runtime/memory_manager/memory_constants.h" +#include "runtime/utilities/heap_allocator.h" + +#include + +namespace OCLRT { + +enum class HeapIndex : uint32_t { + HEAP_INTERNAL_DEVICE_MEMORY = 0u, + HEAP_INTERNAL = 1u, + HEAP_EXTERNAL_DEVICE_MEMORY = 2u, + HEAP_EXTERNAL = 3u, + HEAP_STANDARD, + HEAP_STANDARD64KB, + HEAP_SVM, + HEAP_LIMITED, + + // Please put new heap indexes above this line + TOTAL_HEAPS +}; + +constexpr auto internalHeapIndex = is32bit ? HeapIndex::HEAP_INTERNAL : HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY; + +class GfxPartition { + public: + GfxPartition() {} + + void init(uint64_t gpuAddressSpace); + + void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) { + getHeap(heapIndex).init(base, size); + } + + uint64_t heapAllocate(HeapIndex heapIndex, size_t &size) { + return getHeap(heapIndex).allocate(size); + } + + void heapFree(HeapIndex heapIndex, uint64_t ptr, size_t size) { + getHeap(heapIndex).free(ptr, size); + } + + uint64_t getHeapBase(HeapIndex heapIndex) { + return getHeap(heapIndex).getBase(); + } + + static const std::array heap32Names; + + protected: + class Heap { + public: + Heap() = default; + uint64_t getBase() const { return base; } + uint64_t getSize() const { return size; } + void init(uint64_t base, uint64_t size) { + this->base = base; + this->size = size; + alloc = std::make_unique(base, size); + } + uint64_t allocate(size_t &size) { return alloc->allocate(size); } + void free(uint64_t ptr, size_t size) { alloc->free(ptr, size); } + + protected: + uint64_t base = 0, size = 0; + std::unique_ptr alloc; + }; + + Heap &getHeap(HeapIndex heapIndex) { + return heap[static_cast(heapIndex)]; + } + + std::array(HeapIndex::TOTAL_HEAPS)> heap; +}; + +} // namespace OCLRT diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index e6b940a428..7ba6db6efd 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -26,19 +26,7 @@ namespace OCLRT { using osHandle = unsigned int; - -enum class HeapIndex : uint32_t { - HEAP_INTERNAL_DEVICE_MEMORY = 0u, - HEAP_INTERNAL = 1u, - HEAP_EXTERNAL_DEVICE_MEMORY = 2u, - HEAP_EXTERNAL = 3u, - HEAP_STANDARD, - HEAP_STANDARD64KB, - HEAP_SVM, - HEAP_LIMITED -}; - -constexpr auto internalHeapIndex = is32bit ? HeapIndex::HEAP_INTERNAL : HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY; +enum class HeapIndex : uint32_t; namespace Sharing { constexpr auto nonSharedResource = 0u; diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 836491ce5c..a4c6174b31 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -34,7 +34,7 @@ namespace OCLRT { MemoryManager::MemoryManager(bool enable64kbpages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : allocator32Bit(nullptr), enable64kbpages(enable64kbpages), localMemorySupported(enableLocalMemory), executionEnvironment(executionEnvironment), hostPtrManager(std::make_unique()), - multiContextResourceDestructor(std::make_unique()){}; + multiContextResourceDestructor(std::make_unique()) {} MemoryManager::~MemoryManager() { for (auto &engine : registeredEngines) { diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 51de86fc1e..6360d2dc9e 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -10,6 +10,7 @@ #include "runtime/command_stream/preemption_mode.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/engine_control.h" +#include "runtime/memory_manager/gfx_partition.h" #include "runtime/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/host_ptr_defines.h" #include "runtime/os_interface/32bit_memory.h" @@ -279,6 +280,7 @@ class MemoryManager { uint32_t latestContextId = std::numeric_limits::max(); uint32_t defaultEngineIndex = 0; std::unique_ptr multiContextResourceDestructor; + GfxPartition gfxPartition; }; std::unique_ptr createDeferredDeleter(); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index c468052e10..02b8742fb5 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -7,6 +7,8 @@ #pragma once #include "runtime/helpers/basic_math.h" +#include "runtime/helpers/hw_info.h" +#include "runtime/helpers/options.h" #include "runtime/memory_manager/memory_manager.h" namespace OCLRT { @@ -35,10 +37,11 @@ class OsAgnosticMemoryManager : public MemoryManager { public: using MemoryManager::allocateGraphicsMemory; - OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, false, executionEnvironment){}; + OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, false, executionEnvironment) {} OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, bool aubUsage, ExecutionEnvironment &executionEnvironment) : MemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment) { allocator32Bit = std::unique_ptr(create32BitAllocator(aubUsage)); + gfxPartition.init(platformDevices[0]->capabilityTable.gpuAddressSpace); } ~OsAgnosticMemoryManager() override; diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 1bd462493b..46ba696fa3 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -12,6 +12,7 @@ #include "runtime/gmm_helper/gmm.h" #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/gmm_helper/resource_info.h" +#include "runtime/helpers/hw_info.h" #include "runtime/helpers/options.h" #include "runtime/helpers/ptr_math.h" #include "runtime/helpers/surface_formats.h" @@ -31,6 +32,7 @@ DrmMemoryManager::DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool force pinBB(nullptr), forcePinEnabled(forcePinAllowed), validateHostPtrMemory(validateHostPtrMemory) { + gfxPartition.init(platformDevices[0]->capabilityTable.gpuAddressSpace); MemoryManager::virtualPaddingAvailable = true; if (mode != gemCloseWorkerMode::gemCloseWorkerInactive) { gemCloseWorker.reset(new DrmGemCloseWorker(*this)); diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index 143c00e730..e68c85faa2 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -797,6 +797,21 @@ bool Wddm::waitFromCpu(uint64_t lastFenceValue, const MonitoredFence &monitoredF return status == STATUS_SUCCESS; } +void Wddm::initGfxPartition(GfxPartition &outGfxPartition) const { + if (gfxPartition.SVM.Limit != 0) { + outGfxPartition.heapInit(HeapIndex::HEAP_SVM, gfxPartition.SVM.Base, gfxPartition.SVM.Limit - gfxPartition.SVM.Base + 1); + } + + outGfxPartition.heapInit(HeapIndex::HEAP_STANDARD, gfxPartition.Standard.Base, gfxPartition.Standard.Limit - gfxPartition.Standard.Base + 1); + + outGfxPartition.heapInit(HeapIndex::HEAP_STANDARD64KB, gfxPartition.Standard64KB.Base, gfxPartition.Standard64KB.Limit - gfxPartition.Standard64KB.Base + 1); + + for (auto heap : GfxPartition::heap32Names) { + outGfxPartition.heapInit(heap, gfxPartition.Heap32[static_cast(heap)].Base, + gfxPartition.Heap32[static_cast(heap)].Limit - gfxPartition.Heap32[static_cast(heap)].Base + 1); + } +} + uint64_t Wddm::getSystemSharedMemory() const { return systemSharedMemory; } diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index 3cafbea21e..b218098997 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -9,6 +9,7 @@ #include "runtime/command_stream/preemption_mode.h" #include "runtime/gmm_helper/gmm_lib.h" #include "runtime/helpers/debug_helpers.h" +#include "runtime/memory_manager/gfx_partition.h" #include "runtime/os_interface/os_context.h" #include "runtime/utilities/spinlock.h" @@ -106,6 +107,8 @@ class Wddm { return gfxPartition; } + void initGfxPartition(GfxPartition &outGfxPartition) const; + const std::string &getDeviceRegistryPath() const { return deviceRegistryPath; } diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 4a021ed717..c12683c822 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -40,6 +40,7 @@ WddmMemoryManager::WddmMemoryManager(bool enable64kbPages, bool enableLocalMemor if (asyncDeleterEnabled) deferredDeleter = createDeferredDeleter(); mallocRestrictions.minAddress = wddm->getWddmMinAddress(); + wddm->initGfxPartition(gfxPartition); } GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr gmm) { diff --git a/unit_tests/memory_manager/CMakeLists.txt b/unit_tests/memory_manager/CMakeLists.txt index 77163a465c..a599e45822 100644 --- a/unit_tests/memory_manager/CMakeLists.txt +++ b/unit_tests/memory_manager/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2017-2018 Intel Corporation +# Copyright (C) 2017-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -9,6 +9,7 @@ set(IGDRCL_SRCS_tests_memory_manager ${CMAKE_CURRENT_SOURCE_DIR}/address_mapper_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}/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 new file mode 100644 index 0000000000..688d16dca0 --- /dev/null +++ b/unit_tests/memory_manager/gfx_partition_tests.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/helpers/aligned_memory.h" +#include "runtime/helpers/ptr_math.h" +#include "unit_tests/mocks/mock_gfx_partition.h" + +#include "gtest/gtest.h" + +using namespace OCLRT; + +void testGfxPartition(uint64_t gpuAddressSpace) { + MockGfxPartition gfxPartition; + gfxPartition.init(gpuAddressSpace); + + uint64_t gfxTop = gpuAddressSpace + 1; + uint64_t gfxBase = is64bit ? MemoryConstants::max64BitAppAddress + 1 : MemoryConstants::max32BitAddress + 1; + const uint64_t sizeHeap32 = 4 * MemoryConstants::gigaByte; + const uint64_t gfxGranularity = 2 * MemoryConstants::megaByte; + + if (MemoryConstants::max48BitAddress == gpuAddressSpace) { + // Full range SVM + EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); + EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), gfxGranularity); + EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), gfxBase - gfxGranularity); + } 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 ? gfxBase : gfxGranularity); + EXPECT_EQ(gfxPartition.getHeapSize(heap32), gfxBase ? sizeHeap32 : sizeHeap32 - gfxGranularity); + 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)); + + uint64_t heapStandard64KbBaseOffset = 0; + if (gfxBase != heapStandard64KbBase) { + EXPECT_TRUE(gfxBase < heapStandard64KbBase); + heapStandard64KbBaseOffset = ptrDiff(heapStandard64KbBase, gfxBase); + } + + EXPECT_EQ(heapStandard64KbBase, heapStandardBase + heapStandardSize + heapStandard64KbBaseOffset); + EXPECT_EQ(heapStandard64KbSize, heapStandardSize - heapStandard64KbBaseOffset); + 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 || heap == HeapIndex::HEAP_LIMITED); + continue; + } + + auto ptrBig = gfxPartition.heapAllocate(heap, sizeBig); + EXPECT_NE(ptrBig, 0ull); + EXPECT_EQ(ptrBig, gfxPartition.getHeapBase(heap)); + gfxPartition.heapFree(heap, ptrBig, sizeBig); + + auto ptrSmall = gfxPartition.heapAllocate(heap, sizeSmall); + EXPECT_NE(ptrSmall, 0ull); + EXPECT_EQ(ptrSmall, gfxPartition.getHeapBase(heap) + gfxPartition.getHeapSize(heap) - sizeSmall); + gfxPartition.heapFree(heap, ptrSmall, sizeSmall); + } +} + +TEST(GfxPartitionTest, testGfxPartitionFullRangeSVM) { + testGfxPartition(MemoryConstants::max48BitAddress); +} + +TEST(GfxPartitionTest, testGfxPartitionLimitedRange) { + testGfxPartition(maxNBitValue<48 - 1>); +} diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index 7654d7b887..599f9020f5 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -38,6 +38,8 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_event.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_execution_environment.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_experimental_command_buffer.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gfx_partition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_gfx_partition.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_client_context_base.h diff --git a/unit_tests/mocks/mock_gfx_partition.cpp b/unit_tests/mocks/mock_gfx_partition.cpp new file mode 100644 index 0000000000..cee8e4a347 --- /dev/null +++ b/unit_tests/mocks/mock_gfx_partition.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "unit_tests/mocks/mock_gfx_partition.h" + +using namespace OCLRT; + +std::array(HeapIndex::TOTAL_HEAPS)> + MockGfxPartition::allHeapNames{HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, + HeapIndex::HEAP_INTERNAL, + HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY, + HeapIndex::HEAP_EXTERNAL, + HeapIndex::HEAP_STANDARD, + HeapIndex::HEAP_STANDARD64KB, + HeapIndex::HEAP_SVM, + HeapIndex::HEAP_LIMITED}; diff --git a/unit_tests/mocks/mock_gfx_partition.h b/unit_tests/mocks/mock_gfx_partition.h new file mode 100644 index 0000000000..e4a424618b --- /dev/null +++ b/unit_tests/mocks/mock_gfx_partition.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/memory_manager/gfx_partition.h" + +using namespace OCLRT; + +class MockGfxPartition : public GfxPartition { + public: + uint64_t getHeapSize(HeapIndex heapIndex) { + return getHeap(heapIndex).getSize(); + } + + bool heapInitialized(HeapIndex heapIndex) { + return getHeapBase(heapIndex) && getHeapSize(heapIndex); + } + + static std::array(HeapIndex::TOTAL_HEAPS)> allHeapNames; +}; diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 7eb4322146..62fdfba543 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -20,6 +20,7 @@ #include "runtime/os_interface/windows/wddm_engine_mapper.h" #include "runtime/os_interface/windows/wddm_memory_manager.h" #include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/mocks/mock_gfx_partition.h" #include "unit_tests/mocks/mock_gmm_resource_info.h" #include "unit_tests/os_interface/windows/mock_wddm_allocation.h" #include "unit_tests/os_interface/windows/wddm_fixture.h" @@ -996,3 +997,23 @@ TEST(WddmInternalHeapTest, whenConfigurationIs32BitThenInternalHeapIndexIsHeapIn EXPECT_EQ(HeapIndex::HEAP_INTERNAL, internalHeapIndex); } } + +using WddmGfxPartitionTest = Wddm20Tests; + +TEST_F(WddmGfxPartitionTest, initGfxPartition) { + MockGfxPartition gfxPartition; + + for (auto heap : MockGfxPartition::allHeapNames) { + ASSERT_FALSE(gfxPartition.heapInitialized(heap)); + } + + wddm->initGfxPartition(gfxPartition); + + for (auto heap : MockGfxPartition::allHeapNames) { + if (!gfxPartition.heapInitialized(heap)) { + EXPECT_TRUE(heap == HeapIndex::HEAP_SVM || heap == HeapIndex::HEAP_LIMITED); + } else { + EXPECT_TRUE(gfxPartition.heapInitialized(heap)); + } + } +}