Add additional create buffer arguments

Allow to: disable performance hints, make allocation lockable

Used in BufferPoolAllocator

Related-To: NEO-7332

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2022-11-21 11:03:05 +00:00
committed by Compute-Runtime-Automation
parent 50df7f430e
commit 67bfebb25e
12 changed files with 125 additions and 26 deletions

View File

@ -91,19 +91,23 @@ TEST_P(PerformanceHintBufferTest, GivenHostPtrAndSizeAlignmentsWhenBufferIsCreat
flags |= CL_MEM_FORCE_HOST_MEMORY_INTEL;
}
Buffer::AdditionalBufferCreateArgs bufferCreateArgs{};
bufferCreateArgs.doNotProvidePerformanceHints = !providePerformanceHint;
buffer = Buffer::create(
context,
flags,
sizeForBuffer,
(void *)addressForBuffer,
bufferCreateArgs,
retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, buffer);
snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_BUFFER_DOESNT_MEET_ALIGNMENT_RESTRICTIONS], addressForBuffer, sizeForBuffer, MemoryConstants::pageSize, MemoryConstants::pageSize);
EXPECT_EQ(!(alignedSize && alignedAddress), containsHint(expectedHint, userData));
EXPECT_EQ(providePerformanceHint && !(alignedSize && alignedAddress), containsHint(expectedHint, userData));
snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[CL_BUFFER_NEEDS_ALLOCATE_MEMORY], 0);
EXPECT_EQ(!(alignedSize && alignedAddress), containsHint(expectedHint, userData));
EXPECT_EQ(providePerformanceHint && !(alignedSize && alignedAddress), containsHint(expectedHint, userData));
}
TEST_P(PerformanceHintCommandQueueTest, GivenProfilingFlagAndPreemptionFlagWhenCommandQueueIsCreatingThenContextProvidesProperHints) {
@ -916,6 +920,7 @@ INSTANTIATE_TEST_CASE_P(
DriverDiagnosticsTests,
PerformanceHintBufferTest,
testing::Combine(
::testing::Bool(),
::testing::Bool(),
::testing::Bool()));

View File

@ -84,11 +84,11 @@ struct PerformanceHintTest : public DriverDiagnosticsTest,
};
struct PerformanceHintBufferTest : public PerformanceHintTest,
public ::testing::WithParamInterface<std::tuple<bool /*address aligned*/, bool /*size aligned*/>> {
public ::testing::WithParamInterface<std::tuple<bool /*address aligned*/, bool /*size aligned*/, bool /*provide performance hint*/>> {
void SetUp() override {
PerformanceHintTest::SetUp();
std::tie(alignedAddress, alignedSize) = GetParam();
std::tie(alignedAddress, alignedSize, providePerformanceHint) = GetParam();
address = alignedMalloc(2 * MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
}
@ -99,6 +99,7 @@ struct PerformanceHintBufferTest : public PerformanceHintTest,
}
bool alignedSize = false;
bool alignedAddress = false;
bool providePerformanceHint = false;
void *address = nullptr;
Buffer *buffer = nullptr;
};

View File

@ -19,24 +19,12 @@ namespace Ult {
using PoolAllocator = Context::BufferPoolAllocator;
using MockBufferPoolAllocator = MockContext::MockBufferPoolAllocator;
template <int32_t poolBufferFlag = -1, bool failMainStorageAllocation = false>
template <int32_t poolBufferFlag = -1, bool failMainStorageAllocation = false, bool runSetup = true>
class AggregatedSmallBuffersTestTemplate : public ::testing::Test {
void SetUp() override {
this->setUpImpl();
}
void setUpImpl() {
DebugManager.flags.ExperimentalSmallBufferPoolAllocator.set(poolBufferFlag);
this->deviceFactory = std::make_unique<UltClDeviceFactory>(1, 0);
this->device = deviceFactory->rootDevices[0];
this->mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
this->mockMemoryManager->localMemorySupported[mockRootDeviceIndex] = true;
this->setAllocationToFail(failMainStorageAllocation);
cl_device_id devices[] = {device};
this->context.reset(Context::create<MockContext>(nullptr, ClDeviceVector(devices, 1), nullptr, nullptr, retVal));
ASSERT_EQ(retVal, CL_SUCCESS);
this->setAllocationToFail(false);
this->poolAllocator = static_cast<MockBufferPoolAllocator *>(&context->smallBufferPoolAllocator);
if constexpr (runSetup) {
this->setUpImpl();
}
}
void TearDown() override {
@ -62,6 +50,20 @@ class AggregatedSmallBuffersTestTemplate : public ::testing::Test {
cl_int retVal = CL_SUCCESS;
DebugManagerStateRestore restore;
void setUpImpl() {
DebugManager.flags.ExperimentalSmallBufferPoolAllocator.set(poolBufferFlag);
this->deviceFactory = std::make_unique<UltClDeviceFactory>(1, 0);
this->device = deviceFactory->rootDevices[0];
this->mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
this->mockMemoryManager->localMemorySupported[mockRootDeviceIndex] = true;
this->setAllocationToFail(failMainStorageAllocation);
cl_device_id devices[] = {device};
this->context.reset(Context::create<MockContext>(nullptr, ClDeviceVector(devices, 1), nullptr, nullptr, retVal));
ASSERT_EQ(retVal, CL_SUCCESS);
this->setAllocationToFail(false);
this->poolAllocator = static_cast<MockBufferPoolAllocator *>(&context->smallBufferPoolAllocator);
}
};
using aggregatedSmallBuffersDefaultTest = AggregatedSmallBuffersTestTemplate<-1>;
@ -84,6 +86,13 @@ TEST_F(aggregatedSmallBuffersDisabledTest, givenAggregatedSmallBuffersDisabledWh
using aggregatedSmallBuffersEnabledTest = AggregatedSmallBuffersTestTemplate<1>;
TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenAllocatingMainStorageThenMakeDeviceBufferLockable) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_NE(poolAllocator->mainStorage, nullptr);
ASSERT_NE(mockMemoryManager->lastAllocationProperties, nullptr);
EXPECT_TRUE(mockMemoryManager->lastAllocationProperties->makeDeviceBufferLockable);
}
TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeLargerThanThresholdWhenBufferCreateCalledThenDoNotUsePool) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_NE(poolAllocator->mainStorage, nullptr);
@ -235,9 +244,9 @@ TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndS
}
}
using aggregatedSmallBuffersEnabledTestDoNotRunSetup = AggregatedSmallBuffersTestTemplate<1, true>;
using aggregatedSmallBuffersEnabledTestFailPoolInit = AggregatedSmallBuffersTestTemplate<1, true>;
TEST_F(aggregatedSmallBuffersEnabledTestDoNotRunSetup, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledButPoolCreateFailedThenDoNotUsePool) {
TEST_F(aggregatedSmallBuffersEnabledTestFailPoolInit, givenAggregatedSmallBuffersEnabledAndSizeEqualToThresholdWhenBufferCreateCalledButPoolCreateFailedThenDoNotUsePool) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_EQ(poolAllocator->mainStorage, nullptr);
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal));
@ -247,6 +256,19 @@ TEST_F(aggregatedSmallBuffersEnabledTestDoNotRunSetup, givenAggregatedSmallBuffe
EXPECT_EQ(poolAllocator->mainStorage, nullptr);
}
using aggregatedSmallBuffersEnabledTestDoNotRunSetup = AggregatedSmallBuffersTestTemplate<1, false, false>;
TEST_F(aggregatedSmallBuffersEnabledTestDoNotRunSetup, givenAggregatedSmallBuffersEnabledWhenPoolInitializedThenPerformanceHintsNotProvided) {
testing::internal::CaptureStdout();
DebugManager.flags.PrintDriverDiagnostics.set(1);
setUpImpl();
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_NE(poolAllocator->mainStorage, nullptr);
ASSERT_NE(context->driverDiagnostics, nullptr);
std::string output = testing::internal::GetCapturedStdout();
EXPECT_EQ(0u, output.size());
}
template <int32_t poolBufferFlag = -1>
class AggregatedSmallBuffersApiTestTemplate : public ::testing::Test {
void SetUp() override {