Special address pool at External heap begining

Change-Id: I7da6e67010ff7a819aec25abea9213b6e43e348e
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2020-09-14 15:14:11 +02:00
committed by sys_ocldev
parent 79498dee93
commit e34c319ed7
47 changed files with 388 additions and 53 deletions

View File

@@ -38,7 +38,7 @@ HWTEST2_F(AlocationHelperTests, givenLinearStreamTypeWhenUseIternalAllocatorThen
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
HeapAssigner heapAssigner = {};
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::LINEAR_STREAM, true, *defaultHwInfo.get());
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::LINEAR_STREAM, true, *defaultHwInfo.get(), false);
EXPECT_EQ(heapIndex, NEO::HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY);
}
struct MockMemoryManagerAllocationHelper : public MemoryManagerMock {
@@ -75,7 +75,19 @@ TEST_F(AlocationHelperTests, givenLinearStreamAllocationWhenSelectingHeapWithUse
std::unique_ptr<MockMemoryManagerAllocationHelper> mockMemoryManager(new MockMemoryManagerAllocationHelper(*device->getNEODevice()->getExecutionEnvironment()));
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::LINEAR_STREAM, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
allocation.set32BitAllocation(false);
EXPECT_EQ(MemoryManager::selectExternalHeap(allocation.isAllocatedInLocalMemoryPool()), mockMemoryManager->selectHeap(&allocation, false, false));
EXPECT_EQ(MemoryManager::selectExternalHeap(allocation.isAllocatedInLocalMemoryPool()), mockMemoryManager->selectHeap(&allocation, false, false, false));
}
TEST_F(AlocationHelperTests, givenExternalHeapIndexWhenMapingToExternalFrontWindowThenEternalFrontWindowReturned) {
EXPECT_EQ(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW, HeapAssigner::mapExternalWindowIndex(HeapIndex::HEAP_EXTERNAL));
}
TEST_F(AlocationHelperTests, givenExternalDeviceHeapIndexWhenMapingToExternalFrontWindowThenEternalDeviceFrontWindowReturned) {
EXPECT_EQ(HeapIndex::HEAP_EXTERNAL_DEVICE_FRONT_WINDOW, HeapAssigner::mapExternalWindowIndex(HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY));
}
TEST_F(AlocationHelperTests, givenOtherThanExternalHeapIndexWhenMapingToExternalFrontWindowThenAbortHasBeenThrown) {
EXPECT_THROW(HeapAssigner::mapExternalWindowIndex(HeapIndex::HEAP_STANDARD), std::exception);
}
} // namespace ult

View File

@@ -19,7 +19,7 @@ components:
internal:
branch: master
dest_dir: internal
revision: 603332ad122fdb2eb0a8151dda4e12b50f1620d7
revision: df8d48f5e352a7340a3dcb58b861a580907d7734
type: git
kmdaf:
branch: kmdaf

View File

@@ -30,6 +30,7 @@ set(RUNTIME_SRCS_DLL_BASE
${NEO_SOURCE_DIR}/opencl/source/api/api.cpp
${NEO_SOURCE_DIR}/opencl/source/compiler_interface/default_cache_config.cpp
${NEO_SOURCE_DIR}/opencl/source/helpers/built_ins_helper.cpp
${NEO_SOURCE_DIR}/opencl/source/helpers/heap_assigner_config_ocl.cpp
${GTPIN_INIT_FILE}
${HW_SRC_LINK}

View File

@@ -29,7 +29,6 @@ set(RUNTIME_SRCS_HELPERS_BASE
${CMAKE_CURRENT_SOURCE_DIR}/hardware_commands_helper_bdw_plus.inl
${CMAKE_CURRENT_SOURCE_DIR}/hardware_context_controller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hardware_context_controller.h
${CMAKE_CURRENT_SOURCE_DIR}/heap_assigner_config_ocl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/helper_options.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/memory_properties_helpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/memory_properties_helpers.h

View File

@@ -36,7 +36,7 @@ OsAgnosticMemoryManager::OsAgnosticMemoryManager(bool aubUsage, ExecutionEnviron
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) {
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size());
getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh);
}
}
@@ -116,7 +116,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(const Al
GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) {
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
auto heap = heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo);
auto heap = heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo, allocationData.flags.use32BitExtraPool);
auto gfxPartition = getGfxPartition(allocationData.rootDeviceIndex);
if (allocationData.hostPtr) {
auto allocationSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size);

View File

@@ -57,6 +57,7 @@ class MemoryAllocation : public GraphicsAllocation {
class OsAgnosticMemoryManager : public MemoryManager {
public:
using MemoryManager::allocateGraphicsMemory;
using MemoryManager::heapAssigner;
OsAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, executionEnvironment) {}
OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment);

View File

@@ -48,6 +48,7 @@ set(IGDRCL_SRCS_tests_local
${CMAKE_CURRENT_SOURCE_DIR}/libult/os_interface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ult_configuration.cpp
${NEO_SHARED_TEST_DIRECTORY}/unit_test/tests_configuration.h
${NEO_SOURCE_DIR}/opencl/source/helpers/heap_assigner_config_ocl.cpp
)
if(WIN32)

View File

@@ -52,6 +52,7 @@ target_include_directories(igdrcl_aub_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(igdrcl_aub_tests PRIVATE
${NEO_SHARED_TEST_DIRECTORY}/unit_test/page_fault_manager/default_asan_options.cpp
${NEO_SHARED_DIRECTORY}/gmm_helper/resource_info.cpp
${NEO_SOURCE_DIR}/opencl/source/helpers/heap_assigner_config_ocl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_mode.h
)

View File

@@ -5,8 +5,9 @@
*
*/
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
using namespace NEO;

View File

@@ -26,6 +26,7 @@ add_executable(igdrcl_${target_name}
${NEO_SOURCE_DIR}/opencl/source/dll/linux/options_linux.cpp
${NEO_SOURCE_DIR}/opencl/source/dll/linux/os_interface.cpp
${NEO_SOURCE_DIR}/opencl/source/os_interface/linux/platform_teardown_linux.cpp
${NEO_SOURCE_DIR}/opencl/source/helpers/heap_assigner_config_ocl.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/aub_stream_mocks/aub_stream_interface_mock.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/linux${BRANCH_DIR_SUFFIX}/drm_other_requests.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/create_drm_memory_manager.cpp

View File

@@ -2099,29 +2099,29 @@ class HeapSelectorTest : public Test<ClDeviceFixture> {
TEST_F(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
allocation.set32BitAllocation(true);
EXPECT_EQ(MemoryManager::selectInternalHeap(allocation.isAllocatedInLocalMemoryPool()), memoryManager->selectHeap(&allocation, false, false));
EXPECT_EQ(MemoryManager::selectInternalHeap(allocation.isAllocatedInLocalMemoryPool()), memoryManager->selectHeap(&allocation, false, false, false));
}
TEST_F(HeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
allocation.set32BitAllocation(false);
EXPECT_EQ(MemoryManager::selectInternalHeap(allocation.isAllocatedInLocalMemoryPool()), memoryManager->selectHeap(&allocation, false, false));
EXPECT_EQ(MemoryManager::selectInternalHeap(allocation.isAllocatedInLocalMemoryPool()), memoryManager->selectHeap(&allocation, false, false, false));
}
TEST_F(HeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
allocation.set32BitAllocation(true);
EXPECT_EQ(MemoryManager::selectExternalHeap(allocation.isAllocatedInLocalMemoryPool()), memoryManager->selectHeap(&allocation, false, false));
EXPECT_EQ(MemoryManager::selectExternalHeap(allocation.isAllocatedInLocalMemoryPool()), memoryManager->selectHeap(&allocation, false, false, false));
}
TEST_F(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllocationThenStandardHeapIsUsed) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(&allocation, true, false));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(&allocation, true, false, false));
}
TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithPtrThenSvmHeapIsUsed) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
EXPECT_EQ(HeapIndex::HEAP_SVM, memoryManager->selectHeap(&allocation, true, true));
EXPECT_EQ(HeapIndex::HEAP_SVM, memoryManager->selectHeap(&allocation, true, true, false));
}
TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIs64KSuitableThenStandard64kHeapIsUsed) {
@@ -2131,7 +2131,7 @@ TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAlloca
auto resourceInfo = static_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
resourceInfo->is64KBPageSuitableValue = true;
allocation.setDefaultGmm(gmm.get());
EXPECT_EQ(HeapIndex::HEAP_STANDARD64KB, memoryManager->selectHeap(&allocation, false, true));
EXPECT_EQ(HeapIndex::HEAP_STANDARD64KB, memoryManager->selectHeap(&allocation, false, true, false));
}
TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIsNot64KSuitableThenStandardHeapIsUsed) {
@@ -2141,15 +2141,15 @@ TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAlloca
auto resourceInfo = static_cast<MockGmmResourceInfo *>(gmm->gmmResourceInfo.get());
resourceInfo->is64KBPageSuitableValue = false;
allocation.setDefaultGmm(gmm.get());
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(&allocation, false, true));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(&allocation, false, true, false));
}
TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(nullptr, false, true));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(nullptr, false, true, false));
}
TEST_F(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(nullptr, false, false));
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(nullptr, false, false, false));
}
TEST(MemoryAllocationTest, givenAllocationTypeWhenPassedToMemoryAllocationConstructorThenAllocationTypeIsStored) {

View File

@@ -109,8 +109,6 @@ if(WIN32)
else()
list(APPEND IGDRCL_SRCS_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_allocation.h
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.h
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_command_stream_receiver.h
${NEO_SHARED_DIRECTORY}/os_interface/linux/page_table_manager_functions.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/drm_mock.cpp

View File

@@ -18,6 +18,7 @@ add_custom_target(run_mt_unit_tests)
add_executable(igdrcl_mt_tests EXCLUDE_FROM_ALL
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${NEO_SOURCE_DIR}/shared/test/unit_test/test_macros/test_checks_shared.cpp
${NEO_SOURCE_DIR}/opencl/source/helpers/heap_assigner_config_ocl.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/libult/os_interface.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/test_macros/test_checks_ocl.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/ult_configuration.cpp

View File

@@ -9,8 +9,8 @@
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h"

View File

@@ -10,10 +10,10 @@
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/source/os_interface/linux/drm_command_stream.h"
#include "opencl/source/platform/platform.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h"
#include "test.h"

View File

@@ -10,8 +10,8 @@
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/helpers/ult_hw_config.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_allocation_properties.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"

View File

@@ -13,8 +13,8 @@
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/mocks/mock_gmm.h"
#include "opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests_dg1.h"

View File

@@ -8,11 +8,11 @@
#pragma once
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "shared/test/unit_test/mocks/mock_device.h"
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h"

View File

@@ -7,11 +7,11 @@
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/source/command_queue/command_queue_hw.h"
#include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
#include "test.h"

View File

@@ -1099,7 +1099,7 @@ TEST_F(WddmGfxPartitionTest, WhenInitializingGfxPartitionThenAllHeapsAreInitiali
ASSERT_FALSE(gfxPartition.heapInitialized(heap));
}
wddm->initGfxPartition(gfxPartition, 0, 1);
wddm->initGfxPartition(gfxPartition, 0, 1, false);
for (auto heap : MockGfxPartition::allHeapNames) {
if (!gfxPartition.heapInitialized(heap)) {
@@ -1125,7 +1125,7 @@ TEST(WddmGfxPartitionTests, WhenInitializingGfxPartitionThen64KBHeapsAreUsed) {
MockGfxPartition gfxPartition;
wddm->init();
wddm->initGfxPartition(gfxPartition, rootDeviceIndex, numRootDevices);
wddm->initGfxPartition(gfxPartition, rootDeviceIndex, numRootDevices, false);
auto heapStandard64KBSize = alignDown((wddm->gfxPartition.Standard64KB.Limit - wddm->gfxPartition.Standard64KB.Base + 1) / numRootDevices, GfxPartition::heapGranularity);
EXPECT_EQ(heapStandard64KBSize, gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD64KB));

View File

@@ -19,6 +19,7 @@ if(WIN32)
${NEO_SOURCE_DIR}/opencl/source/dll/create_command_stream.cpp
${NEO_SOURCE_DIR}/opencl/source/dll${BRANCH_DIR_SUFFIX}/get_devices.cpp
${NEO_SOURCE_DIR}/opencl/source/dll/windows/os_interface.cpp
${NEO_SOURCE_DIR}/opencl/source/helpers/heap_assigner_config_ocl.cpp
${NEO_SHARED_DIRECTORY}/os_interface/windows/wddm/wddm_create.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/ult_configuration.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/get_devices_tests.cpp

View File

@@ -77,6 +77,7 @@ bool RootDevice::createDeviceImpl() {
if (!status) {
return status;
}
return true;
}
DeviceBitfield RootDevice::getDeviceBitfield() const {

View File

@@ -21,7 +21,6 @@ class RootDevice : public Device {
uint32_t getRootDeviceIndex() const override;
Device *getDeviceById(uint32_t deviceId) const override;
Device *getParentDevice() const override;
uint32_t getNumSubDevices() const;
protected:

View File

@@ -23,11 +23,11 @@ bool HeapAssigner::useInternal32BitHeap(GraphicsAllocation::AllocationType alloc
bool HeapAssigner::use32BitHeap(GraphicsAllocation::AllocationType allocType) {
return useExternal32BitHeap(allocType) || useInternal32BitHeap(allocType);
}
HeapIndex HeapAssigner::get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo) {
HeapIndex HeapAssigner::get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo, bool useExternalWindow) {
if (useInternal32BitHeap(allocType)) {
return MemoryManager::selectInternalHeap(useLocalMem);
}
return MemoryManager::selectExternalHeap(useLocalMem);
return useExternalWindow ? mapExternalWindowIndex(MemoryManager::selectExternalHeap(useLocalMem)) : MemoryManager::selectExternalHeap(useLocalMem);
}
bool HeapAssigner::useExternal32BitHeap(GraphicsAllocation::AllocationType allocType) {
if (apiAllowExternalHeapForSshAndDsh) {
@@ -35,4 +35,25 @@ bool HeapAssigner::useExternal32BitHeap(GraphicsAllocation::AllocationType alloc
}
return false;
}
bool HeapAssigner::heapTypeWithFrontWindowPool(HeapIndex heap) {
return heap == HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY || heap == HeapIndex::HEAP_EXTERNAL;
}
HeapIndex HeapAssigner::mapExternalWindowIndex(HeapIndex index) {
auto retIndex = HeapIndex::TOTAL_HEAPS;
switch (index) {
case HeapIndex::HEAP_EXTERNAL:
retIndex = HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW;
break;
case HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY:
retIndex = HeapIndex::HEAP_EXTERNAL_DEVICE_FRONT_WINDOW;
break;
default:
UNRECOVERABLE_IF(true);
break;
};
return retIndex;
}
} // namespace NEO

View File

@@ -16,8 +16,10 @@ struct HeapAssigner {
bool useExternal32BitHeap(GraphicsAllocation::AllocationType allocType);
bool useInternal32BitHeap(GraphicsAllocation::AllocationType allocType);
bool use32BitHeap(GraphicsAllocation::AllocationType allocType);
HeapIndex get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo);
HeapIndex get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo, bool useExternalWindow);
static bool heapTypeWithFrontWindowPool(HeapIndex heap);
static HeapIndex mapExternalWindowIndex(HeapIndex index);
bool apiAllowExternalHeapForSshAndDsh = false;
};
} // namespace NEO

View File

@@ -25,7 +25,8 @@ struct AllocationProperties {
uint32_t resource48Bit : 1;
uint32_t isUSMHostAllocation : 1;
uint32_t isUSMDeviceAllocation : 1;
uint32_t reserved : 21;
uint32_t use32BitExtraPool : 1;
uint32_t reserved : 20;
} flags;
uint32_t allFlags = 0;
};
@@ -96,7 +97,8 @@ struct AllocationData {
uint32_t shareable : 1;
uint32_t resource48Bit : 1;
uint32_t isUSMHostAllocation : 1;
uint32_t reserved : 19;
uint32_t use32BitExtraPool : 1;
uint32_t reserved : 18;
} flags;
uint32_t allFlags = 0;
};

View File

@@ -8,6 +8,8 @@
#include "shared/source/memory_manager/gfx_partition.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/memory_manager/memory_manager.h"
namespace NEO {
@@ -43,6 +45,15 @@ void GfxPartition::Heap::init(uint64_t base, uint64_t size) {
alloc = std::make_unique<HeapAllocator>(base + GfxPartition::heapGranularity, size);
}
void GfxPartition::Heap::initExternalWithFrontWindow(uint64_t base, uint64_t size) {
this->base = base;
this->size = size;
size -= GfxPartition::heapGranularity;
alloc = std::make_unique<HeapAllocator>(base, size, 0u);
}
void GfxPartition::freeGpuAddressRange(uint64_t ptr, size_t size) {
for (auto heapName : GfxPartition::heapNonSvmNames) {
auto &heap = getHeap(heapName);
@@ -53,7 +64,7 @@ void GfxPartition::freeGpuAddressRange(uint64_t ptr, size_t size) {
}
}
void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices) {
void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool) {
/*
* I. 64-bit builds:
@@ -131,7 +142,14 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
}
for (auto heap : GfxPartition::heap32Names) {
if (useFrontWindowPool && HeapAssigner::heapTypeWithFrontWindowPool(heap)) {
heapInitExternalWithFrontWindow(heap, gfxBase, gfxHeap32Size);
size_t externalFrontWindowSize = GfxPartition::frontWindowPoolSize;
heapInitExternalWithFrontWindow(HeapAssigner::mapExternalWindowIndex(heap), heapAllocate(heap, externalFrontWindowSize),
externalFrontWindowSize);
} else {
heapInit(heap, gfxBase, gfxHeap32Size);
}
gfxBase += gfxHeap32Size;
}

View File

@@ -7,10 +7,12 @@
#pragma once
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/os_interface/os_memory.h"
#include "shared/source/utilities/heap_allocator.h"
#include <array>
#include <map>
namespace NEO {
@@ -23,6 +25,8 @@ enum class HeapIndex : uint32_t {
HEAP_STANDARD64KB,
HEAP_SVM,
HEAP_EXTENDED,
HEAP_EXTERNAL_FRONT_WINDOW,
HEAP_EXTERNAL_DEVICE_FRONT_WINDOW,
// Please put new heap indexes above this line
TOTAL_HEAPS
@@ -33,12 +37,19 @@ class GfxPartition {
GfxPartition(OSMemory::ReservedCpuAddressRange &sharedReservedCpuAddressRange);
MOCKABLE_VIRTUAL ~GfxPartition();
void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices);
void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices) {
init(gpuAddressSpace, cpuAddressRangeSizeToReserve, rootDeviceIndex, numRootDevices, false);
}
void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool);
void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) {
getHeap(heapIndex).init(base, size);
}
void heapInitExternalWithFrontWindow(HeapIndex heapIndex, uint64_t base, uint64_t size) {
getHeap(heapIndex).initExternalWithFrontWindow(base, size);
}
uint64_t heapAllocate(HeapIndex heapIndex, size_t &size) {
return getHeap(heapIndex).allocate(size);
}
@@ -58,12 +69,23 @@ class GfxPartition {
}
uint64_t getHeapMinimalAddress(HeapIndex heapIndex) {
if (heapIndex == HeapIndex::HEAP_EXTERNAL_DEVICE_FRONT_WINDOW ||
heapIndex == HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW) {
return getHeapBase(heapIndex);
} else {
if ((heapIndex == HeapIndex::HEAP_EXTERNAL ||
heapIndex == HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY) &&
(getHeapLimit(HeapAssigner::mapExternalWindowIndex(heapIndex)) != 0)) {
return getHeapBase(heapIndex) + GfxPartition::frontWindowPoolSize;
}
return getHeapBase(heapIndex) + heapGranularity;
}
}
bool isLimitedRange() { return getHeap(HeapIndex::HEAP_SVM).getSize() == 0ull; }
static const uint64_t heapGranularity = MemoryConstants::pageSize64k;
static constexpr size_t frontWindowPoolSize = 16 * MemoryConstants::megaByte;
static const std::array<HeapIndex, 4> heap32Names;
static const std::array<HeapIndex, 7> heapNonSvmNames;
@@ -75,6 +97,7 @@ class GfxPartition {
public:
Heap() = default;
void init(uint64_t base, uint64_t size);
void initExternalWithFrontWindow(uint64_t base, uint64_t size);
uint64_t getBase() const { return base; }
uint64_t getSize() const { return size; }
uint64_t getLimit() const { return size ? base + size - 1 : 0; }

View File

@@ -379,6 +379,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
(mayRequireL3Flush ? properties.flags.flushL3RequiredForRead | properties.flags.flushL3RequiredForWrite : 0u);
allocationData.flags.preferRenderCompressed = CompressionSelector::preferRenderCompressedBuffer(properties);
allocationData.flags.multiOsContextCapable = properties.flags.multiOsContextCapable;
allocationData.flags.use32BitExtraPool = properties.flags.use32BitExtraPool;
allocationData.hostPtr = hostPtr;
allocationData.size = properties.size;
@@ -531,13 +532,14 @@ void MemoryManager::unlockResource(GraphicsAllocation *graphicsAllocation) {
graphicsAllocation->unlock();
}
HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM) {
HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM, bool useExternalWindow) {
if (allocation) {
if (heapAssigner.useInternal32BitHeap(allocation->getAllocationType())) {
return selectInternalHeap(allocation->isAllocatedInLocalMemoryPool());
}
if (allocation->is32BitAllocation() || heapAssigner.useExternal32BitHeap(allocation->getAllocationType())) {
return selectExternalHeap(allocation->isAllocatedInLocalMemoryPool());
return useExternalWindow ? HeapAssigner::mapExternalWindowIndex(selectExternalHeap(allocation->isAllocatedInLocalMemoryPool()))
: selectExternalHeap(allocation->isAllocatedInLocalMemoryPool());
}
}
if (isFullRangeSVM) {

View File

@@ -167,7 +167,7 @@ class MemoryManager {
HostPtrManager *getHostPtrManager() const { return hostPtrManager.get(); }
void setDefaultEngineIndex(uint32_t index) { defaultEngineIndex = index; }
virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy);
HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM);
HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM, bool useExternalWindow);
static std::unique_ptr<MemoryManager> createMemoryManager(ExecutionEnvironment &executionEnvironment);
virtual void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) { return nullptr; };
virtual void releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex){};

View File

@@ -45,7 +45,7 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode,
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) {
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size());
getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh);
localMemAllocs.emplace_back();
}
MemoryManager::virtualPaddingAvailable = true;
@@ -444,7 +444,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) {
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
auto allocatorToUse = heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo);
auto allocatorToUse = heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo, allocationData.flags.use32BitExtraPool);
if (allocationData.hostPtr) {
uintptr_t inputPtr = reinterpret_cast<uintptr_t>(allocationData.hostPtr);

View File

@@ -14,6 +14,7 @@
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/page_table_mngr.h"
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/interlocked_max.h"
#include "shared/source/helpers/windows/gmm_callbacks.h"
#include "shared/source/os_interface/hw_info_config.h"
@@ -877,7 +878,7 @@ bool Wddm::waitFromCpu(uint64_t lastFenceValue, const MonitoredFence &monitoredF
return status == STATUS_SUCCESS;
}
void Wddm::initGfxPartition(GfxPartition &outGfxPartition, uint32_t rootDeviceIndex, size_t numRootDevices) const {
void Wddm::initGfxPartition(GfxPartition &outGfxPartition, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool) const {
if (gfxPartition.SVM.Limit != 0) {
outGfxPartition.heapInit(HeapIndex::HEAP_SVM, gfxPartition.SVM.Base, gfxPartition.SVM.Limit - gfxPartition.SVM.Base + 1);
} else if (is32bit) {
@@ -891,10 +892,18 @@ void Wddm::initGfxPartition(GfxPartition &outGfxPartition, uint32_t rootDeviceIn
outGfxPartition.heapInit(HeapIndex::HEAP_STANDARD64KB, gfxPartition.Standard64KB.Base + rootDeviceIndex * gfxStandard64KBSize, gfxStandard64KBSize);
for (auto heap : GfxPartition::heap32Names) {
if (useFrontWindowPool && HeapAssigner::heapTypeWithFrontWindowPool(heap)) {
outGfxPartition.heapInitExternalWithFrontWindow(heap, gfxPartition.Heap32[static_cast<uint32_t>(heap)].Base,
gfxPartition.Heap32[static_cast<uint32_t>(heap)].Limit - gfxPartition.Heap32[static_cast<uint32_t>(heap)].Base + 1);
size_t externalFrontWindowSize = GfxPartition::frontWindowPoolSize;
outGfxPartition.heapInitExternalWithFrontWindow(HeapAssigner::mapExternalWindowIndex(heap), outGfxPartition.heapAllocate(heap, externalFrontWindowSize),
externalFrontWindowSize);
} else {
outGfxPartition.heapInit(heap, gfxPartition.Heap32[static_cast<uint32_t>(heap)].Base,
gfxPartition.Heap32[static_cast<uint32_t>(heap)].Limit - gfxPartition.Heap32[static_cast<uint32_t>(heap)].Base + 1);
}
}
}
uint64_t Wddm::getSystemSharedMemory() const {
return systemSharedMemory;

View File

@@ -101,7 +101,7 @@ class Wddm {
return gfxPartition;
}
void initGfxPartition(GfxPartition &outGfxPartition, uint32_t rootDeviceIndex, size_t numRootDevices) const;
void initGfxPartition(GfxPartition &outGfxPartition, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool) const;
const std::string &getDeviceRegistryPath() const {
return deviceRegistryPath;

View File

@@ -100,6 +100,7 @@ class WddmAllocation : public GraphicsAllocation {
D3DGPU_VIRTUAL_ADDRESS reservedGpuVirtualAddress = 0u;
uint64_t reservedSizeForGpuVirtualAddress = 0u;
uint32_t shareable = 0u;
bool allocInFrontWindowPool = false;
protected:
std::string getHandleInfoString() const {

View File

@@ -45,7 +45,7 @@ WddmMemoryManager::WddmMemoryManager(ExecutionEnvironment &executionEnvironment)
mallocRestrictions.minAddress = 0u;
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) {
getWddm(rootDeviceIndex).initGfxPartition(*getGfxPartition(rootDeviceIndex), rootDeviceIndex, gfxPartitions.size());
getWddm(rootDeviceIndex).initGfxPartition(*getGfxPartition(rootDeviceIndex), rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh);
mallocRestrictions.minAddress = std::max(mallocRestrictions.minAddress, getWddm(rootDeviceIndex).getWddmMinAddress());
}
}
@@ -316,6 +316,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
wddmAllocation->setDriverAllocatedCpuPtr(pSysMem);
wddmAllocation->set32BitAllocation(true);
wddmAllocation->setAllocationOffset(offset);
wddmAllocation->allocInFrontWindowPool = allocationData.flags.use32BitExtraPool;
gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), ptrAligned, sizeAligned, false);
wddmAllocation->setDefaultGmm(gmm);
@@ -326,7 +327,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
return nullptr;
}
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
auto baseAddress = getGfxPartition(allocationData.rootDeviceIndex)->getHeapBase(heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo));
auto baseAddress = getGfxPartition(allocationData.rootDeviceIndex)->getHeapBase(heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo, allocationData.flags.use32BitExtraPool));
wddmAllocation->setGpuBaseAddress(GmmHelper::canonize(baseAddress));
return wddmAllocation.release();
@@ -622,7 +623,7 @@ bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation, void *r
bool WddmMemoryManager::mapGpuVaForOneHandleAllocation(WddmAllocation *allocation, const void *preferredGpuVirtualAddress) {
D3DGPU_VIRTUAL_ADDRESS addressToMap = castToUint64(preferredGpuVirtualAddress);
auto heapIndex = selectHeap(allocation, preferredGpuVirtualAddress != nullptr, is32bit || executionEnvironment.rootDeviceEnvironments[allocation->getRootDeviceIndex()]->isFullRangeSvm());
auto heapIndex = selectHeap(allocation, preferredGpuVirtualAddress != nullptr, is32bit || executionEnvironment.rootDeviceEnvironments[allocation->getRootDeviceIndex()]->isFullRangeSvm(), allocation->allocInFrontWindowPool);
if (!executionEnvironment.rootDeviceEnvironments[allocation->getRootDeviceIndex()]->isFullRangeSvm() && !is32bit) {
addressToMap = 0u;
}
@@ -630,11 +631,18 @@ bool WddmMemoryManager::mapGpuVaForOneHandleAllocation(WddmAllocation *allocatio
addressToMap = allocation->reservedGpuVirtualAddress;
}
auto gfxPartition = getGfxPartition(allocation->getRootDeviceIndex());
auto status = getWddm(allocation->getRootDeviceIndex()).mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), gfxPartition->getHeapMinimalAddress(heapIndex), gfxPartition->getHeapLimit(heapIndex), addressToMap, allocation->getGpuAddressToModify());
if (allocation->allocInFrontWindowPool) {
auto alignedSize = allocation->getAlignedSize();
addressToMap = gfxPartition->heapAllocate(heapIndex, alignedSize);
}
D3DGPU_VIRTUAL_ADDRESS minimumAddress = gfxPartition->getHeapMinimalAddress(heapIndex);
D3DGPU_VIRTUAL_ADDRESS maximumAddress = gfxPartition->getHeapLimit(heapIndex);
auto status = getWddm(allocation->getRootDeviceIndex()).mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), minimumAddress, maximumAddress, addressToMap, allocation->getGpuAddressToModify());
if (!status && deferredDeleter) {
deferredDeleter->drain(true);
status = getWddm(allocation->getRootDeviceIndex()).mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), gfxPartition->getHeapMinimalAddress(heapIndex), gfxPartition->getHeapLimit(heapIndex), addressToMap, allocation->getGpuAddressToModify());
status = getWddm(allocation->getRootDeviceIndex()).mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), minimumAddress, maximumAddress, addressToMap, allocation->getGpuAddressToModify());
}
if (!status) {
if (allocation->reservedGpuVirtualAddress) {

View File

@@ -59,6 +59,7 @@ if(NOT SKIP_NEO_UNIT_TESTS AND NOT SKIP_UNIT_TESTS)
${NEO_SOURCE_DIR}/shared/source/helpers/allow_deferred_deleter.cpp
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.cpp
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.cpp
${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/heap_assigner_config_shared_tests.cpp
$<TARGET_OBJECTS:mock_gmm>
)
@@ -69,6 +70,8 @@ if(NOT SKIP_NEO_UNIT_TESTS AND NOT SKIP_UNIT_TESTS)
${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/drm_neo_create.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/options.cpp
${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/linux/sys_calls_linux_ult.cpp
${NEO_SOURCE_DIR}/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.cpp
${NEO_SOURCE_DIR}/shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h
)
else()
target_sources(${TARGET_NAME} PRIVATE

View File

@@ -23,12 +23,12 @@ HWTEST_F(AlocationHelperTests, givenKernelIsaTypeWhenUse32BitHeapCalledThenTrueR
}
HWTEST_F(AlocationHelperTests, givenKernelIsaTypeWhenUseIternalAllocatorThenUseHeapInternal) {
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::KERNEL_ISA, true, *defaultHwInfo);
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::KERNEL_ISA, true, *defaultHwInfo, false);
EXPECT_EQ(heapIndex, NEO::HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY);
}
HWTEST_F(AlocationHelperTests, givenNotInternalTypeWhenUseIternalAllocatorThenUseHeapExternal) {
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::LINEAR_STREAM, true, *defaultHwInfo);
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::LINEAR_STREAM, true, *defaultHwInfo, false);
EXPECT_EQ(heapIndex, NEO::HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY);
}

View File

@@ -0,0 +1,15 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/heap_assigner_config.h"
namespace NEO {
bool HeapAssignerConfig::getConfiguration() {
return DebugManager.flags.UseExternalAllocatorForSshAndDsh.get();
}
} // namespace NEO

View File

@@ -7,4 +7,5 @@
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/multi_graphics_allocation_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/special_heap_pool_tests.cpp
)

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/test/unit_test/fixtures/device_fixture.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "test.h"
namespace NEO {
class MemManagerFixture : public DeviceFixture {
public:
struct FrontWindowMemManagerMock : public MockMemoryManager {
FrontWindowMemManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {}
void forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size(), true); }
};
void SetUp() {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
DeviceFixture::SetUp();
memManager = std::unique_ptr<FrontWindowMemManagerMock>(new FrontWindowMemManagerMock(*pDevice->getExecutionEnvironment()));
}
void TearDown() {
DeviceFixture::TearDown();
}
std::unique_ptr<FrontWindowMemManagerMock> memManager;
};
using FrontWindowAllocatorTests = Test<MemManagerFixture>;
TEST_F(FrontWindowAllocatorTests, givenAllocateInFrontWindowPoolFlagWhenAllocate32BitGraphicsMemoryThenAllocateAtHeapBegining) {
AllocationData allocData = {};
allocData.flags.use32BitExtraPool = true;
allocData.size = MemoryConstants::kiloByte;
auto allocation(memManager->allocate32BitGraphicsMemoryImpl(allocData, false));
EXPECT_EQ(allocation->getGpuBaseAddress(), allocation->getGpuAddress());
memManager->freeGraphicsMemory(allocation);
}
TEST_F(FrontWindowAllocatorTests, givenAllocateInFrontWindowPoolFlagWhenAllocate32BitGraphicsMemoryThenAlocationInFrontWindowPoolRange) {
AllocationData allocData = {};
allocData.flags.use32BitExtraPool = true;
allocData.size = MemoryConstants::kiloByte;
auto allocation(memManager->allocate32BitGraphicsMemoryImpl(allocData, false));
auto heap = memManager->heapAssigner.get32BitHeapIndex(allocData.type, false, *defaultHwInfo, true);
EXPECT_EQ(GmmHelper::canonize(memManager->getGfxPartition(0)->getHeapMinimalAddress(heap)), allocation->getGpuAddress());
EXPECT_LT(ptrOffset(allocation->getGpuAddress(), allocation->getUnderlyingBufferSize()), GmmHelper::canonize(memManager->getGfxPartition(0)->getHeapLimit(heap)));
memManager->freeGraphicsMemory(allocation);
}
TEST_F(FrontWindowAllocatorTests, givenInitializedHeapsWhenUseExternalAllocatorForSshAndDshEnabledThenExternalHeapHaveFrontWindowPool) {
EXPECT_NE(memManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW), 0u);
}
TEST_F(FrontWindowAllocatorTests, givenInitializedHeapsWhenUseExternalAllocatorForSshAndDshEnabledThenFrontWindowPoolIsAtBeginingOfExternalHeap) {
EXPECT_EQ(memManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW), memManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW));
EXPECT_EQ(memManager->getGfxPartition(0)->getHeapMinimalAddress(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW), memManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW));
}
TEST_F(FrontWindowAllocatorTests, givenInitializedHeapsWhenUseExternalAllocatorForSshAndDshEnabledThenMinimalAdressIsNotAtBeginingOfExternalHeap) {
EXPECT_GT(memManager->getGfxPartition(0)->getHeapMinimalAddress(HeapIndex::HEAP_EXTERNAL), memManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL));
}
TEST_F(FrontWindowAllocatorTests, givenInitializedHeapsWhenUseExternalAllocatorForSshAndDshEnabledThenMinimalAdressIsAtBeginingOfExternalFrontWindowHeap) {
EXPECT_EQ(memManager->getGfxPartition(0)->getHeapMinimalAddress(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW), memManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW));
}
TEST_F(FrontWindowAllocatorTests, givenInitializedHeapsWhenUseExternalAllocatorForSshAndDshEnabledThenMinimalAdressIsAtBeginingOfExternalDeviceFrontWindowHeap) {
EXPECT_EQ(memManager->getGfxPartition(0)->getHeapMinimalAddress(HeapIndex::HEAP_EXTERNAL_DEVICE_FRONT_WINDOW), memManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL_DEVICE_FRONT_WINDOW));
}
TEST_F(FrontWindowAllocatorTests, givenInitializedHeapsWhenUseExternalAllocatorForSshAndDshDisabledThenMinimalAdressEqualBeginingOfExternalHeap) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(false);
memManager.reset(new FrontWindowMemManagerMock(*pDevice->getExecutionEnvironment()));
EXPECT_EQ(memManager->getGfxPartition(0)->getHeapMinimalAddress(HeapIndex::HEAP_EXTERNAL), memManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_EXTERNAL) + GfxPartition::heapGranularity);
}
TEST_F(FrontWindowAllocatorTests, givenInitializedHeapsWhenUseExternalAllocatorForSshAndDshDisabledThenExternalHeapDoesntHaveFrontWindowPool) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(false);
memManager.reset(new FrontWindowMemManagerMock(*pDevice->getExecutionEnvironment()));
EXPECT_EQ(memManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW), 0u);
}
TEST_F(FrontWindowAllocatorTests, givenLinearStreamAllocWhenSelectingHeapWithFrontWindowThenCorrectIndexReturned) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::LINEAR_STREAM, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
EXPECT_EQ(HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW, memManager->selectHeap(&allocation, true, true, true));
}
} // namespace NEO

View File

@@ -25,6 +25,11 @@ if(WIN32)
list(APPEND NEO_CORE_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/windows/mock_wddm_direct_submission.h
)
else()
list(APPEND NEO_CORE_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linux/mock_drm_memory_manager.h
)
endif()
set_property(GLOBAL PROPERTY NEO_CORE_tests_mocks ${NEO_CORE_tests_mocks})

View File

@@ -5,7 +5,7 @@
*
*/
#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "shared/source/os_interface/linux/allocator_helper.h"
#include "shared/source/os_interface/linux/drm_memory_manager.h"

View File

@@ -7,6 +7,7 @@
set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_query_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_special_heap_test.cpp
)
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_TESTS_LINUX ${NEO_CORE_OS_INTERFACE_TESTS_LINUX})

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "shared/test/unit_test/mocks/linux/mock_drm_memory_manager.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
#include "test.h"
namespace NEO {
class DrmMemManagerFixture {
public:
struct FrontWindowMemManagerMock : public TestedDrmMemoryManager {
using MemoryManager::allocate32BitGraphicsMemoryImpl;
FrontWindowMemManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : TestedDrmMemoryManager(executionEnvironment) {}
void forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size(), true); }
};
void SetUp() {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DeviceFactory::prepareDeviceEnvironments(*executionEnvironment);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]));
memManager = std::unique_ptr<FrontWindowMemManagerMock>(new FrontWindowMemManagerMock(*executionEnvironment));
}
void TearDown() {
}
std::unique_ptr<FrontWindowMemManagerMock> memManager;
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
};
using DrmFrontWindowPoolAllocatorTests = Test<DrmMemManagerFixture>;
TEST_F(DrmFrontWindowPoolAllocatorTests, givenAllocateInSpecialPoolFlagWhenDrmAllocate32BitGraphicsMemoryThenAllocateAtHeapBegining) {
AllocationData allocData = {};
allocData.flags.use32BitExtraPool = true;
allocData.size = MemoryConstants::kiloByte;
auto allocation = memManager->allocate32BitGraphicsMemoryImpl(allocData, false);
EXPECT_EQ(allocation->getGpuBaseAddress(), allocation->getGpuAddress());
memManager->freeGraphicsMemory(allocation);
}
} // namespace NEO

View File

@@ -11,6 +11,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_WINDOWS
${CMAKE_CURRENT_SOURCE_DIR}/mock_gdi_interface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_gdi_interface.h
${CMAKE_CURRENT_SOURCE_DIR}/wddm_preemption_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm_special_heap_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/wddm_tests.cpp
)

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/windows/os_interface.h"
#include "shared/test/unit_test/fixtures/device_fixture.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "opencl/test/unit_test/mocks/mock_wddm.h"
#include "opencl/test/unit_test/os_interface/windows/mock_wddm_memory_manager.h"
#include "test.h"
namespace NEO {
class WddmMemManagerFixture {
public:
struct FrontWindowMemManagerMock : public MockWddmMemoryManager {
using MemoryManager::allocate32BitGraphicsMemoryImpl;
FrontWindowMemManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : MockWddmMemoryManager(executionEnvironment) {}
};
void SetUp() {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DeviceFactory::prepareDeviceEnvironments(*executionEnvironment);
auto wddm = static_cast<WddmMock *>(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm());
wddm->callBaseMapGpuVa = false;
memManager = std::unique_ptr<FrontWindowMemManagerMock>(new FrontWindowMemManagerMock(*executionEnvironment));
}
void TearDown() {
}
std::unique_ptr<FrontWindowMemManagerMock> memManager;
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
};
using WddmFrontWindowPoolAllocatorTests = Test<WddmMemManagerFixture>;
TEST_F(WddmFrontWindowPoolAllocatorTests, givenAllocateInFrontWindowPoolFlagWhenWddmAllocate32BitGraphicsMemoryThenAllocateAtHeapBegining) {
AllocationData allocData = {};
allocData.flags.use32BitExtraPool = true;
allocData.size = MemoryConstants::kiloByte;
auto allocation = memManager->allocate32BitGraphicsMemoryImpl(allocData, false);
EXPECT_EQ(allocation->getGpuBaseAddress(), GmmHelper::canonize(allocation->getGpuAddress()));
memManager->freeGraphicsMemory(allocation);
}
} // namespace NEO