Support for dsh and ssh on external heap in L0

Related-To: NEO-4724

Change-Id: I85c2effea8a99bebaf9e3db33129641f37dcabe5
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka 2020-08-27 08:55:09 +02:00 committed by sys_ocldev
parent f891708e3f
commit a779e44b52
29 changed files with 356 additions and 46 deletions

View File

@ -46,6 +46,7 @@ set(L0_RUNTIME_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/event/event.h
${CMAKE_CURRENT_SOURCE_DIR}/fence/fence.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fence/fence.h
${CMAKE_CURRENT_SOURCE_DIR}/helpers/heap_assigner_config_l0.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_helpers${BRANCH_DIR_SUFFIX}/hw_helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/kernel/kernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/kernel.h

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

@ -0,0 +1,11 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/heap_assigner_l0_tests.cpp
)
add_subdirectories()

View File

@ -0,0 +1,82 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/heap_assigner.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
namespace L0 {
namespace ult {
using AlocationHelperTests = Test<DeviceFixture>;
using Platforms = IsAtMostProduct<IGFX_TIGERLAKE_LP>;
HWTEST2_F(AlocationHelperTests, givenLinearStreamTypeWhenUseExternalAllocatorForSshAndDshDisabledThenUse32BitIsFalse, Platforms) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(false);
HeapAssigner heapAssigner = {};
EXPECT_FALSE(heapAssigner.use32BitHeap(GraphicsAllocation::AllocationType::LINEAR_STREAM));
}
HWTEST2_F(AlocationHelperTests, givenLinearStreamTypeWhenUseExternalAllocatorForSshAndDshEnabledThenUse32BitIsTrue, Platforms) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
HeapAssigner heapAssigner = {};
EXPECT_TRUE(heapAssigner.use32BitHeap(GraphicsAllocation::AllocationType::LINEAR_STREAM));
}
HWTEST2_F(AlocationHelperTests, givenLinearStreamTypeWhenUseIternalAllocatorThenUseHeapExternal, Platforms) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
HeapAssigner heapAssigner = {};
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::LINEAR_STREAM, true, *defaultHwInfo.get());
EXPECT_EQ(heapIndex, NEO::HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY);
}
struct MockMemoryManagerAllocationHelper : public MemoryManagerMock {
MockMemoryManagerAllocationHelper(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override {
passedUseLocalMem = useLocalMemory;
return nullptr;
}
bool passedUseLocalMem = false;
};
TEST_F(AlocationHelperTests, GivenLinearStreamAllocTypeWhenUseExternalAllocatorForSshAndDshEnabledThenUseLocalMemEqualHwHelperValue) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
AllocationData allocationData;
allocationData.type = GraphicsAllocation::AllocationType::LINEAR_STREAM;
std::unique_ptr<MockMemoryManagerAllocationHelper> mockMemoryManager(new MockMemoryManagerAllocationHelper(*device->getNEODevice()->getExecutionEnvironment()));
mockMemoryManager->allocateGraphicsMemory(allocationData);
EXPECT_EQ(mockMemoryManager->passedUseLocalMem, HwHelper::get(device->getHwInfo().platform.eRenderCoreFamily).heapInLocalMem(device->getHwInfo()));
}
TEST_F(AlocationHelperTests, GivenInternalAllocTypeWhenUseExternalAllocatorForSshAndDshDisabledThenUseLocalMemEqualFalse) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(false);
AllocationData allocationData;
allocationData.type = GraphicsAllocation::AllocationType::KERNEL_ISA;
std::unique_ptr<MockMemoryManagerAllocationHelper> mockMemoryManager(new MockMemoryManagerAllocationHelper(*device->getNEODevice()->getExecutionEnvironment()));
mockMemoryManager->allocateGraphicsMemory(allocationData);
EXPECT_FALSE(mockMemoryManager->passedUseLocalMem);
}
TEST_F(AlocationHelperTests, givenLinearStreamAllocationWhenSelectingHeapWithUseExternalAllocatorForSshAndDshEnabledThenExternalHeapIsUsed) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
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));
}
} // namespace ult
} // namespace L0

View File

@ -28,6 +28,7 @@ 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

@ -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 false;
}
} // namespace NEO

View File

@ -14,6 +14,8 @@
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/memory_manager/host_ptr_manager.h"
@ -109,8 +111,8 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(const Al
}
GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) {
auto heap = useInternal32BitAllocator(allocationData.type) ? selectInternalHeap(useLocalMemory)
: selectExternalHeap(useLocalMemory);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
auto heap = heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo);
auto gfxPartition = getGfxPartition(allocationData.rootDeviceIndex);
if (allocationData.hostPtr) {
auto allocationSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size);

View File

@ -26,6 +26,7 @@ set(IGDRCL_SRCS_tests_helpers
${CMAKE_CURRENT_SOURCE_DIR}/gtest_helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/hardware_commands_helper_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hardware_commands_helper_tests.h
${CMAKE_CURRENT_SOURCE_DIR}/heap_assigner_ocl_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_default_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.h

View File

@ -0,0 +1,25 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/heap_assigner.h"
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "test.h"
namespace NEO {
using AlocationHelperTests = Test<ClDeviceFixture>;
HWTEST_F(AlocationHelperTests, givenLinearStreamTypeWhenUseExternalAllocatorForSshAndDshDisabledThenUse32BitIsFalse) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true);
HeapAssigner heapAssigner = {};
EXPECT_FALSE(heapAssigner.use32BitHeap(GraphicsAllocation::AllocationType::LINEAR_STREAM));
}
} // namespace NEO

View File

@ -619,10 +619,6 @@ TEST(MemoryManagerTest, givenConstantSurfaceTypeWhenGetAllocationDataIsCalledThe
EXPECT_FALSE(allocData.flags.useSystemMemory);
}
TEST(MemoryManagerTest, givenInternalHeapTypeThenUseInternal32BitAllocator) {
EXPECT_TRUE(MockMemoryManager::useInternal32BitAllocator(GraphicsAllocation::AllocationType::INTERNAL_HEAP));
}
HWTEST_F(GetAllocationDataTestHw, givenInternalHeapTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested) {
AllocationData allocData;
MockMemoryManager mockMemoryManager;
@ -658,10 +654,6 @@ TEST(MemoryManagerTest, givenPrintfAllocationWhenGetAllocationDataIsCalledThenDo
EXPECT_TRUE(allocData.flags.requiresCpuAccess);
}
TEST(MemoryManagerTest, givenKernelIsaTypeThenUseInternal32BitAllocator) {
EXPECT_TRUE(MockMemoryManager::useInternal32BitAllocator(GraphicsAllocation::AllocationType::KERNEL_ISA));
}
TEST(MemoryManagerTest, givenExternalHostMemoryWhenGetAllocationDataIsCalledThenItHasProperFieldsSet) {
AllocationData allocData;
auto hostPtr = reinterpret_cast<void *>(0x1234);

View File

@ -2075,60 +2075,75 @@ TEST(MemoryManagerTest, givenForcedLinearImages3DImageAndProperDescriptorValuesW
alignedFree(hostPtr);
}
TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
class HeapSelectorTest : public Test<ClDeviceFixture> {
public:
using BaseClass = ClDeviceFixture;
void SetUp() override {
executionEnvironment = std::unique_ptr<MockExecutionEnvironment>(new MockExecutionEnvironment(defaultHwInfo.get()));
memoryManager = std::unique_ptr<MockMemoryManager>(new MockMemoryManager(false, false, *executionEnvironment.get()));
BaseClass::SetUp();
}
void TearDown() override {
BaseClass::TearDown();
}
std::unique_ptr<MockExecutionEnvironment> executionEnvironment;
std::unique_ptr<MockMemoryManager> memoryManager;
};
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));
}
TEST(HeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
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));
}
TEST(HeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) {
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));
}
TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllocationThenStandardHeapIsUsed) {
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));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithPtrThenSvmHeapIsUsed) {
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));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIs64KSuitableThenStandard64kHeapIsUsed) {
TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIs64KSuitableThenStandard64kHeapIsUsed) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
auto rootDeviceEnvironment = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0].get();
auto gmm = std::make_unique<Gmm>(rootDeviceEnvironment->getGmmClientContext(), nullptr, 0, false);
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));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIsNot64KSuitableThenStandardHeapIsUsed) {
TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIsNot64KSuitableThenStandardHeapIsUsed) {
GraphicsAllocation allocation{0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull};
auto rootDeviceEnvironment = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0].get();
auto gmm = std::make_unique<Gmm>(rootDeviceEnvironment->getGmmClientContext(), nullptr, 0, false);
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));
}
TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, false, true));
TEST_F(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(nullptr, false, true));
}
TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, false, false));
TEST_F(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) {
EXPECT_EQ(HeapIndex::HEAP_STANDARD, memoryManager->selectHeap(nullptr, false, false));
}
TEST(MemoryAllocationTest, givenAllocationTypeWhenPassedToMemoryAllocationConstructorThenAllocationTypeIsStored) {

View File

@ -74,8 +74,8 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
using DrmMemoryManager::supportsMultiStorageResources;
using DrmMemoryManager::unlockResourceInLocalMemoryImpl;
using MemoryManager::allocateGraphicsMemoryInDevicePool;
using MemoryManager::heapAssigner;
using MemoryManager::registeredEngines;
using MemoryManager::useInternal32BitAllocator;
TestedDrmMemoryManager(ExecutionEnvironment &executionEnvironment);
TestedDrmMemoryManager(bool enableLocalMemory,

View File

@ -45,7 +45,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
using MemoryManager::pageFaultManager;
using MemoryManager::registeredEngines;
using MemoryManager::supportsMultiStorageResources;
using MemoryManager::useInternal32BitAllocator;
using MemoryManager::useNonSvmHostPtrAlloc;
using OsAgnosticMemoryManager::allocateGraphicsMemoryForImageFromHostPtr;
using MemoryManagerCreate<OsAgnosticMemoryManager>::MemoryManagerCreate;

View File

@ -7,6 +7,7 @@
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/os_interface/linux/allocator_helper.h"
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
@ -569,7 +570,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenSupportedTypeWhenAllocatingInDevice
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_SVM)), gpuAddress);
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_SVM)), gpuAddress);
}
} else if (memoryManager->useInternal32BitAllocator(allocation->getAllocationType())) {
} else if (memoryManager->heapAssigner.useInternal32BitHeap(allocation->getAllocationType())) {
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapBase(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)), gpuAddress);
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY)), gpuAddress);
} else {

View File

@ -184,3 +184,4 @@ ZebinAppendElws = 0
ZebinIgnoreIcbeVersion = 0
LogWaitingForCompletion = 0
ForceUserptrAlignment = -1
UseExternalAllocatorForSshAndDsh = 0

View File

@ -75,6 +75,7 @@ DECLARE_DEBUG_VARIABLE(bool, ForcePipeControlPriorToWalker, false, "Allows to fo
DECLARE_DEBUG_VARIABLE(bool, UseLegacyLevelZeroAffinity, false, "Use Level Zero affinity mask as bit set, as defined in v0.91 specification")
DECLARE_DEBUG_VARIABLE(bool, ZebinAppendElws, false, "Append crossthread data with enqueue local work size")
DECLARE_DEBUG_VARIABLE(bool, ZebinIgnoreIcbeVersion, false, "Ignore IGC\'s ICBE version")
DECLARE_DEBUG_VARIABLE(bool, UseExternalAllocatorForSshAndDsh, false, "Use 32 bit external Allocator for ssh and dsh in Level Zero")
/*LOGGING FLAGS*/
DECLARE_DEBUG_VARIABLE(bool, PrintDeviceAndEngineIdOnSubmission, false, "print submissions device and engine IDs to standard output")

View File

@ -42,6 +42,9 @@ set(NEO_CORE_HELPERS
${CMAKE_CURRENT_SOURCE_DIR}/flush_stamp.h
${CMAKE_CURRENT_SOURCE_DIR}/get_info.h
${CMAKE_CURRENT_SOURCE_DIR}/hash.h
${CMAKE_CURRENT_SOURCE_DIR}/heap_assigner.h
${CMAKE_CURRENT_SOURCE_DIR}/heap_assigner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/heap_assigner_config.h
${CMAKE_CURRENT_SOURCE_DIR}/heap_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/heap_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/hw_helper.cpp

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/heap_assigner_config.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/memory_manager/memory_manager.h"
namespace NEO {
HeapAssigner::HeapAssigner() {
apiAllowExternalHeapForSshAndDsh = HeapAssignerConfig::getConfiguration();
}
bool HeapAssigner::useInternal32BitHeap(GraphicsAllocation::AllocationType allocType) {
return allocType == GraphicsAllocation::AllocationType::KERNEL_ISA ||
allocType == GraphicsAllocation::AllocationType::INTERNAL_HEAP;
}
bool HeapAssigner::use32BitHeap(GraphicsAllocation::AllocationType allocType) {
return useExternal32BitHeap(allocType) || useInternal32BitHeap(allocType);
}
HeapIndex HeapAssigner::get32BitHeapIndex(GraphicsAllocation::AllocationType allocType, bool useLocalMem, const HardwareInfo &hwInfo) {
if (useInternal32BitHeap(allocType)) {
return MemoryManager::selectInternalHeap(useLocalMem);
}
return MemoryManager::selectExternalHeap(useLocalMem);
}
bool HeapAssigner::useExternal32BitHeap(GraphicsAllocation::AllocationType allocType) {
if (apiAllowExternalHeapForSshAndDsh) {
return allocType == GraphicsAllocation::AllocationType::LINEAR_STREAM;
}
return false;
}
} // namespace NEO

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/memory_manager/graphics_allocation.h"
namespace NEO {
struct HardwareInfo;
struct HeapAssigner {
HeapAssigner();
~HeapAssigner() = default;
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);
bool apiAllowExternalHeapForSshAndDsh = false;
};
} // namespace NEO

View File

@ -0,0 +1,13 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
namespace NEO {
struct HeapAssignerConfig {
static bool getConfiguration();
};
} // namespace NEO

View File

@ -123,6 +123,7 @@ class HwHelper {
virtual uint32_t getGlobalTimeStampBits() const = 0;
virtual uint32_t getDefaultThreadArbitrationPolicy() const = 0;
virtual void adjustPlatformCoreFamilyForIgc(HardwareInfo &hwInfo) = 0;
virtual bool heapInLocalMem(const HardwareInfo &hwInfo) const = 0;
static uint32_t getSubDevicesCount(const HardwareInfo *pHwInfo);
static uint32_t getEnginesCount(const HardwareInfo &hwInfo);
@ -212,6 +213,8 @@ class HwHelperHw : public HwHelper {
bool isLocalMemoryEnabled(const HardwareInfo &hwInfo) const override;
bool heapInLocalMem(const HardwareInfo &hwInfo) const override;
bool hvAlign4Required() const override;
bool obtainRenderBufferCompressionPreference(const HardwareInfo &hwInfo, const size_t size) const override;

View File

@ -35,6 +35,11 @@ bool HwHelperHw<GfxFamily>::isLocalMemoryEnabled(const HardwareInfo &hwInfo) con
return false;
}
template <typename GfxFamily>
bool HwHelperHw<GfxFamily>::heapInLocalMem(const HardwareInfo &hwInfo) const {
return false;
}
template <typename GfxFamily>
bool HwHelperHw<GfxFamily>::hvAlign4Required() const {
return true;

View File

@ -16,6 +16,7 @@
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/string.h"
@ -431,9 +432,12 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData &
}
return allocation;
}
if (useInternal32BitAllocator(allocationData.type) ||
bool use32Allocator = heapAssigner.use32BitHeap(allocationData.type);
if (use32Allocator ||
(force32bitAllocations && allocationData.flags.allow32Bit && is64bit)) {
return allocate32BitGraphicsMemoryImpl(allocationData, false);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
bool useLocalMem = heapAssigner.useExternal32BitHeap(allocationData.type) ? HwHelper::get(hwInfo->platform.eRenderCoreFamily).heapInLocalMem(*hwInfo) : false;
return allocate32BitGraphicsMemoryImpl(allocationData, useLocalMem);
}
if (allocationData.hostPtr) {
return allocateGraphicsMemoryWithHostPtr(allocationData);
@ -514,10 +518,10 @@ void MemoryManager::unlockResource(GraphicsAllocation *graphicsAllocation) {
HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM) {
if (allocation) {
if (useInternal32BitAllocator(allocation->getAllocationType())) {
if (heapAssigner.useInternal32BitHeap(allocation->getAllocationType())) {
return selectInternalHeap(allocation->isAllocatedInLocalMemoryPool());
}
if (allocation->is32BitAllocation()) {
if (allocation->is32BitAllocation() || heapAssigner.useExternal32BitHeap(allocation->getAllocationType())) {
return selectExternalHeap(allocation->isAllocatedInLocalMemoryPool());
}
}

View File

@ -11,6 +11,8 @@
#include "shared/source/helpers/bit_helpers.h"
#include "shared/source/helpers/common_types.h"
#include "shared/source/helpers/engine_control.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/gfx_partition.h"
#include "shared/source/memory_manager/graphics_allocation.h"
@ -165,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);
static HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM);
HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM);
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){};
@ -183,10 +185,6 @@ class MemoryManager {
protected:
bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo);
static void overrideAllocationData(AllocationData &allocationData, const AllocationProperties &properties);
static bool useInternal32BitAllocator(GraphicsAllocation::AllocationType allocationType) {
return allocationType == GraphicsAllocation::AllocationType::KERNEL_ISA ||
allocationType == GraphicsAllocation::AllocationType::INTERNAL_HEAP;
}
static bool isCopyRequired(ImageInfo &imgInfo, const void *hostPtr);
@ -230,6 +228,7 @@ class MemoryManager {
void *reservedMemory = nullptr;
std::unique_ptr<PageFaultManager> pageFaultManager;
OSMemory::ReservedCpuAddressRange reservedCpuAddressRange;
HeapAssigner heapAssigner;
};
std::unique_ptr<DeferredDeleter> createDeferredDeleter();

View File

@ -13,6 +13,7 @@
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/surface_format_info.h"
@ -399,8 +400,8 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
}
DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) {
auto internal = useInternal32BitAllocator(allocationData.type);
auto allocatorToUse = internal ? selectInternalHeap(useLocalMemory) : selectExternalHeap(useLocalMemory);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
auto allocatorToUse = heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo);
if (allocationData.hostPtr) {
uintptr_t inputPtr = reinterpret_cast<uintptr_t>(allocationData.hostPtr);

View File

@ -9,6 +9,7 @@
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/string.h"
#include "shared/source/helpers/surface_format_info.h"
#include "shared/source/os_interface/linux/drm_memory_manager.h"
@ -169,7 +170,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
auto cpuAddress = lockResource(allocation.get());
allocation->setCpuPtrAndGpuAddress(cpuAddress, gpuAddress);
}
if (useInternal32BitAllocator(allocationData.type)) {
if (heapAssigner.useInternal32BitHeap(allocationData.type)) {
allocation->setGpuBaseAddress(GmmHelper::canonize(getInternalHeapBaseAddress(allocationData.rootDeviceIndex, true)));
}

View File

@ -15,6 +15,8 @@
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/deferred_deleter_helper.h"
#include "shared/source/helpers/heap_assigner.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/surface_format_info.h"
#include "shared/source/memory_manager/deferrable_deletion.h"
@ -319,9 +321,8 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
freeSystemMemory(pSysMem);
return nullptr;
}
auto baseAddress = useInternal32BitAllocator(allocationData.type) ? getInternalHeapBaseAddress(allocationData.rootDeviceIndex, useLocalMemory)
: getExternalHeapBaseAddress(allocationData.rootDeviceIndex, useLocalMemory);
auto hwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo();
auto baseAddress = getGfxPartition(allocationData.rootDeviceIndex)->getHeapBase(heapAssigner.get32BitHeapIndex(allocationData.type, useLocalMemory, *hwInfo));
wddmAllocation->setGpuBaseAddress(GmmHelper::canonize(baseAddress));
return wddmAllocation.release();

View File

@ -0,0 +1,10 @@
#
# Copyright (C) 2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/heap_assigner_tests.cpp
)

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/heap_assigner.h"
#include "shared/test/unit_test/fixtures/device_fixture.h"
#include "test.h"
namespace NEO {
class AlocationHelperTests : public Test<DeviceFixture> {
public:
HeapAssigner heapAssigner = {};
};
HWTEST_F(AlocationHelperTests, givenKernelIsaTypeWhenUse32BitHeapCalledThenTrueReturned) {
EXPECT_TRUE(heapAssigner.use32BitHeap(GraphicsAllocation::AllocationType::KERNEL_ISA));
}
HWTEST_F(AlocationHelperTests, givenKernelIsaTypeWhenUseIternalAllocatorThenUseHeapInternal) {
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::KERNEL_ISA, true, *defaultHwInfo);
EXPECT_EQ(heapIndex, NEO::HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY);
}
HWTEST_F(AlocationHelperTests, givenNotInternalTypeWhenUseIternalAllocatorThenUseHeapExternal) {
auto heapIndex = heapAssigner.get32BitHeapIndex(GraphicsAllocation::AllocationType::LINEAR_STREAM, true, *defaultHwInfo);
EXPECT_EQ(heapIndex, NEO::HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY);
}
HWTEST_F(AlocationHelperTests, givenKernelIsaTypeWhenUseInternalAllocatorCalledThenTrueReturned) {
EXPECT_TRUE(heapAssigner.useInternal32BitHeap(GraphicsAllocation::AllocationType::KERNEL_ISA));
}
HWTEST_F(AlocationHelperTests, givenInternalHeapTypeWhenUseInternalAllocatorCalledThenTrueReturned) {
EXPECT_TRUE(heapAssigner.useInternal32BitHeap(GraphicsAllocation::AllocationType::INTERNAL_HEAP));
}
HWTEST_F(AlocationHelperTests, givenNotInternalHeapTypeWhenUseInternalAllocatorCalledThenFalseReturned) {
EXPECT_FALSE(heapAssigner.useInternal32BitHeap(GraphicsAllocation::AllocationType::BUFFER));
}
} // namespace NEO