Prepare for pool buffer enabling 3/n

Add per platform config
Reorder checks in allocateBufferFromPool

Related-To: NEO-7332

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek 2022-12-12 15:06:59 +00:00 committed by Compute-Runtime-Automation
parent 5edbca1aa2
commit 2d34f00b3e
11 changed files with 111 additions and 35 deletions

View File

@ -46,7 +46,7 @@ Context::Context(
Context::~Context() {
gtpinNotifyContextDestroy((cl_context)this);
if (smallBufferPoolAllocator.isAggregatedSmallBuffersEnabled()) {
if (smallBufferPoolAllocator.isAggregatedSmallBuffersEnabled(this)) {
smallBufferPoolAllocator.releaseSmallBufferPool();
}
@ -471,7 +471,20 @@ Platform *Context::getPlatformFromProperties(const cl_context_properties *proper
}
bool Context::isSingleDeviceContext() {
return devices[0]->getNumGenericSubDevices() == 0 && getNumDevices() == 1;
return getNumDevices() == 1 && devices[0]->getNumGenericSubDevices() == 0;
}
bool Context::BufferPoolAllocator::isAggregatedSmallBuffersEnabled(Context *context) const {
if (DebugManager.flags.ExperimentalSmallBufferPoolAllocator.get() != -1) {
return !!DebugManager.flags.ExperimentalSmallBufferPoolAllocator.get();
}
bool enabled = false;
if (context->isSingleDeviceContext()) {
auto &hwInfo = context->getDevices()[0]->getHardwareInfo();
auto &productHelper = *ProductHelper::get(hwInfo.platform.eProductFamily);
enabled = productHelper.isBufferPoolAllocatorSupported();
}
return enabled;
}
void Context::BufferPoolAllocator::initAggregatedSmallBuffers(Context *context) {
@ -501,10 +514,9 @@ Buffer *Context::BufferPoolAllocator::allocateBufferFromPool(const MemoryPropert
void *hostPtr,
cl_int &errcodeRet) {
errcodeRet = CL_MEM_OBJECT_ALLOCATION_FAILURE;
if (this->isAggregatedSmallBuffersEnabled() &&
if (this->mainStorage &&
this->isSizeWithinThreshold(size) &&
this->flagsAllowBufferFromPool(flags, flagsIntel) &&
this->mainStorage) {
this->flagsAllowBufferFromPool(flags, flagsIntel)) {
auto lock = std::unique_lock<std::mutex>(this->mutex);
cl_buffer_region bufferRegion{};
bufferRegion.origin = static_cast<size_t>(this->chunkAllocator->allocate(size));

View File

@ -60,13 +60,8 @@ class Context : public BaseObject<_cl_context> {
void tryFreeFromPoolBuffer(MemObj *possiblePoolBuffer, size_t offset, size_t size);
void releaseSmallBufferPool();
inline bool isAggregatedSmallBuffersEnabled() const {
constexpr bool enable = false;
if (DebugManager.flags.ExperimentalSmallBufferPoolAllocator.get() != -1) {
return !!DebugManager.flags.ExperimentalSmallBufferPoolAllocator.get();
}
return enable;
}
bool isAggregatedSmallBuffersEnabled(Context *context) const;
void initAggregatedSmallBuffers(Context *context);
bool isPoolBuffer(const MemObj *buffer) const;
@ -101,7 +96,7 @@ class Context : public BaseObject<_cl_context> {
pContext = nullptr;
} else {
auto &bufferPoolAllocator = pContext->getBufferPoolAllocator();
if (bufferPoolAllocator.isAggregatedSmallBuffersEnabled()) {
if (bufferPoolAllocator.isAggregatedSmallBuffersEnabled(pContext)) {
bufferPoolAllocator.initAggregatedSmallBuffers(pContext);
}
}

View File

@ -8,6 +8,7 @@
#include "shared/source/helpers/hw_helper.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "shared/test/common/test_macros/test.h"
#include "opencl/test/unit_test/mocks/mock_buffer.h"
@ -29,7 +30,7 @@ class AggregatedSmallBuffersTestTemplate : public ::testing::Test {
}
void TearDown() override {
if (this->context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled()) {
if (this->context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())) {
this->context->getBufferPoolAllocator().releaseSmallBufferPool();
}
}
@ -98,14 +99,14 @@ class AggregatedSmallBuffersKernelTest : public AggregatedSmallBuffersTestTempla
using AggregatedSmallBuffersDefaultTest = AggregatedSmallBuffersTestTemplate<-1>;
TEST_F(AggregatedSmallBuffersDefaultTest, givenAggregatedSmallBuffersDefaultWhenCheckIfEnabledThenReturnFalse) {
EXPECT_FALSE(poolAllocator->isAggregatedSmallBuffersEnabled());
HWTEST_F(AggregatedSmallBuffersDefaultTest, givenAggregatedSmallBuffersDefaultWhenCheckIfEnabledThenReturnFalse) {
EXPECT_FALSE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
}
using AggregatedSmallBuffersDisabledTest = AggregatedSmallBuffersTestTemplate<0>;
TEST_F(AggregatedSmallBuffersDisabledTest, givenAggregatedSmallBuffersDisabledWhenBufferCreateCalledThenDoNotUsePool) {
ASSERT_FALSE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_FALSE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_EQ(poolAllocator->mainStorage, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal));
EXPECT_NE(buffer, nullptr);
@ -117,14 +118,14 @@ TEST_F(AggregatedSmallBuffersDisabledTest, givenAggregatedSmallBuffersDisabledWh
using AggregatedSmallBuffersEnabledTest = AggregatedSmallBuffersTestTemplate<1>;
TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenAllocatingMainStorageThenMakeDeviceBufferLockable) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_NE(poolAllocator->mainStorage, nullptr);
ASSERT_NE(mockMemoryManager->lastAllocationProperties, nullptr);
EXPECT_TRUE(mockMemoryManager->lastAllocationProperties->makeDeviceBufferLockable);
}
TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeLargerThanThresholdWhenBufferCreateCalledThenDoNotUsePool) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_NE(poolAllocator->mainStorage, nullptr);
size = PoolAllocator::smallBufferThreshold + 1;
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal));
@ -135,7 +136,7 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndS
}
TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledThenUsePool) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_NE(poolAllocator->mainStorage, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal));
@ -155,7 +156,7 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndS
}
TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenClReleaseMemObjectCalledThenWaitForEnginesCompletionCalled) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_NE(poolAllocator->mainStorage, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal));
@ -196,7 +197,7 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenCopyHostPointerWhenCreatingBuffer
unsigned char dataToCopy[PoolAllocator::smallBufferThreshold];
hostPtr = dataToCopy;
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_NE(poolAllocator->mainStorage, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal));
if (commandQueue->writeBufferCounter == 0) {
@ -212,7 +213,7 @@ TEST_F(AggregatedSmallBuffersEnabledTest, givenCopyHostPointerWhenCreatingBuffer
}
TEST_F(AggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledMultipleTimesThenUsePool) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_NE(poolAllocator->mainStorage, nullptr);
constexpr auto buffersToCreate = PoolAllocator::aggregatedSmallBuffersPoolSize / PoolAllocator::smallBufferThreshold;
@ -300,7 +301,7 @@ TEST_F(AggregatedSmallBuffersKernelTest, givenBufferFromPoolWhenOffsetSubbufferI
using AggregatedSmallBuffersEnabledTestFailPoolInit = AggregatedSmallBuffersTestTemplate<1, true>;
TEST_F(AggregatedSmallBuffersEnabledTestFailPoolInit, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledButPoolCreateFailedThenDoNotUsePool) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_EQ(poolAllocator->mainStorage, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal));
@ -315,7 +316,7 @@ TEST_F(AggregatedSmallBuffersEnabledTestDoNotRunSetup, givenAggregatedSmallBuffe
testing::internal::CaptureStdout();
DebugManager.flags.PrintDriverDiagnostics.set(1);
setUpImpl();
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled(context.get()));
ASSERT_NE(poolAllocator->mainStorage, nullptr);
ASSERT_NE(context->driverDiagnostics, nullptr);
std::string output = testing::internal::GetCapturedStdout();
@ -349,8 +350,8 @@ class AggregatedSmallBuffersApiTestTemplate : public ::testing::Test {
DebugManagerStateRestore restore;
};
using AggregatedSmallBuffersDefaultApiTest = AggregatedSmallBuffersApiTestTemplate<-1>;
TEST_F(AggregatedSmallBuffersDefaultApiTest, givenNoBufferCreatedWhenReleasingContextThenDoNotLeakMemory) {
using AggregatedSmallBuffersDisabledApiTest = AggregatedSmallBuffersApiTestTemplate<0>;
TEST_F(AggregatedSmallBuffersDisabledApiTest, givenNoBufferCreatedWhenReleasingContextThenDoNotLeakMemory) {
EXPECT_EQ(clReleaseContext(context), CL_SUCCESS);
}

View File

@ -13,6 +13,7 @@ if(TESTS_DG2)
set(IGDRCL_SRCS_tests_xe_hpg_core_dg2
${IGDRCL_SRCS_tests_xe_hpg_core_dg2_excludes}
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/buffer_pool_alloc_tests_dg2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/get_device_info_dg2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sampler_tests_dg2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmds_programming_dg2.cpp

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/xe_hpg_core/hw_cmds_dg2.h"
#include "shared/test/common/test_macros/header/per_product_test_definitions.h"
#include "shared/test/common/test_macros/test.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/fixtures/context_fixture.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
using namespace NEO;
namespace Ult {
class AggregatedSmallBuffersDg2DefaultTest : public ContextFixture,
public ClDeviceFixture,
public testing::Test {
protected:
void SetUp() override {
ClDeviceFixture::setUp();
cl_device_id device = pClDevice;
ContextFixture::setUp(1, &device);
}
void TearDown() override {
ContextFixture::tearDown();
ClDeviceFixture::tearDown();
}
};
DG2TEST_F(AggregatedSmallBuffersDg2DefaultTest, givenAggregatedSmallBuffersDefaultWhenCheckIfEnabledThenReturnFalse) {
EXPECT_FALSE(pContext->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(pContext));
}
DG2TEST_F(AggregatedSmallBuffersDg2DefaultTest, givenAggregatedSmallBuffersDefaultAndMultiDeviceContextWhenCheckIfEnabledThenReturnFalse) {
pContext->devices.push_back(nullptr);
EXPECT_FALSE(pContext->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(pContext));
pContext->devices.pop_back();
}
} // namespace Ult

View File

@ -15,3 +15,4 @@ HWTEST_EXCLUDE_PRODUCT(ProgramTests, givenAtLeastXeHpgCoreWhenGetInternalOptions
HWTEST_EXCLUDE_PRODUCT(CmdsProgrammingTestsXeHpgCore, givenL3ToL1DebugFlagWhenStatelessMocsIsProgrammedThenItHasL1CachingOn, IGFX_DG2);
HWTEST_EXCLUDE_PRODUCT(CmdsProgrammingTestsXeHpgCore, givenAlignedCacheableReadOnlyBufferThenChoseOclBufferConstPolicy, IGFX_DG2);
HWTEST_EXCLUDE_PRODUCT(CmdsProgrammingTestsXeHpgCore, whenAppendingRssThenProgramWBPL1CachePolicy, IGFX_DG2);
HWTEST_EXCLUDE_PRODUCT(AggregatedSmallBuffersDefaultTest, givenAggregatedSmallBuffersDefaultWhenCheckIfEnabledThenReturnFalse, IGFX_DG2);

View File

@ -149,6 +149,7 @@ class ProductHelper {
virtual bool isNonBlockingGpuSubmissionSupported() const = 0;
virtual bool isResolveDependenciesByPipeControlsSupported(const HardwareInfo &hwInfo, bool isOOQ) const = 0;
virtual bool isMidThreadPreemptionDisallowedForRayTracingKernels() const = 0;
virtual bool isBufferPoolAllocatorSupported() const = 0;
virtual bool getFrontEndPropertyScratchSizeSupport() const = 0;
virtual bool getFrontEndPropertyPrivateScratchSizeSupport() const = 0;
@ -293,6 +294,7 @@ class ProductHelperHw : public ProductHelper {
bool isNonBlockingGpuSubmissionSupported() const override;
bool isResolveDependenciesByPipeControlsSupported(const HardwareInfo &hwInfo, bool isOOQ) const override;
bool isMidThreadPreemptionDisallowedForRayTracingKernels() const override;
bool isBufferPoolAllocatorSupported() const override;
bool getFrontEndPropertyScratchSizeSupport() const override;
bool getFrontEndPropertyPrivateScratchSizeSupport() const override;

View File

@ -537,6 +537,11 @@ bool ProductHelperHw<gfxProduct>::isMidThreadPreemptionDisallowedForRayTracingKe
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::isBufferPoolAllocatorSupported() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
void ProductHelperHw<gfxProduct>::fillScmPropertiesSupportStructureBase(StateComputeModePropertiesSupport &propertiesSupport) const {
propertiesSupport.coherencyRequired = getScmPropertyCoherencyRequiredSupport();

View File

@ -217,6 +217,11 @@ bool ProductHelperHw<gfxProduct>::isResolveDependenciesByPipeControlsSupported(c
return enabled;
}
template <>
bool ProductHelperHw<gfxProduct>::isBufferPoolAllocatorSupported() const {
return false;
}
template <>
std::optional<aub_stream::ProductFamily> ProductHelperHw<gfxProduct>::getAubStreamProductFamily() const {
return aub_stream::ProductFamily::Dg2;

View File

@ -677,3 +677,8 @@ HWTEST_F(ProductHelperTest, givenDebugFlagWhenCheckingIsResolveDependenciesByPip
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(pInHwInfo, false));
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(pInHwInfo, true));
}
HWTEST_F(ProductHelperTest, givenProductHelperWhenCheckingIsBufferPoolAllocatorSupportedThenCorrectValueIsReturned) {
DebugManagerStateRestore restorer;
EXPECT_FALSE(productHelper->isBufferPoolAllocatorSupported());
}

View File

@ -555,18 +555,24 @@ DG2TEST_F(ProductHelperTestDg2, givenProductHelperWhenGettingEvictIfNecessaryFla
DG2TEST_F(ProductHelperTestDg2, givenDebugFlagWhenCheckingIsResolveDependenciesByPipeControlsSupportedThenCorrectValueIsReturned) {
DebugManagerStateRestore restorer;
HardwareInfo hwInfo = *defaultHwInfo;
auto productHelper = ProductHelper::get(hwInfo.platform.eProductFamily);
auto productHelper = ProductHelper::get(defaultHwInfo->platform.eProductFamily);
// ResolveDependenciesViaPipeControls = -1 (default)
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(hwInfo, false));
EXPECT_FALSE(productHelper->isResolveDependenciesByPipeControlsSupported(hwInfo, true));
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(*defaultHwInfo, false));
EXPECT_FALSE(productHelper->isResolveDependenciesByPipeControlsSupported(*defaultHwInfo, true));
DebugManager.flags.ResolveDependenciesViaPipeControls.set(0);
EXPECT_FALSE(productHelper->isResolveDependenciesByPipeControlsSupported(hwInfo, false));
EXPECT_FALSE(productHelper->isResolveDependenciesByPipeControlsSupported(hwInfo, true));
EXPECT_FALSE(productHelper->isResolveDependenciesByPipeControlsSupported(*defaultHwInfo, false));
EXPECT_FALSE(productHelper->isResolveDependenciesByPipeControlsSupported(*defaultHwInfo, true));
DebugManager.flags.ResolveDependenciesViaPipeControls.set(1);
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(hwInfo, false));
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(hwInfo, true));
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(*defaultHwInfo, false));
EXPECT_TRUE(productHelper->isResolveDependenciesByPipeControlsSupported(*defaultHwInfo, true));
}
DG2TEST_F(ProductHelperTestDg2, givenProductHelperWhenCheckingIsBufferPoolAllocatorSupportedThenCorrectValueIsReturned) {
DebugManagerStateRestore restorer;
auto productHelper = ProductHelper::get(defaultHwInfo->platform.eProductFamily);
EXPECT_FALSE(productHelper->isBufferPoolAllocatorSupported());
}