Revert "performance: move host/device memUsmAllocPool init to platform/contex...

This reverts commit f0f869ed42.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2025-09-20 07:04:41 +02:00
committed by Compute-Runtime-Automation
parent 2ce915aa5b
commit a0d1a88f96
18 changed files with 133 additions and 157 deletions

View File

@@ -3977,7 +3977,10 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
return nullptr;
}
auto allocationFromPool = neoContext->getDevice(0u)->getPlatform()->getHostMemAllocPool().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
auto platform = neoContext->getDevice(0u)->getPlatform();
platform->initializeHostUsmAllocationPool();
auto allocationFromPool = platform->getHostMemAllocPool().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
if (allocationFromPool) {
TRACING_EXIT(ClHostMemAllocINTEL, &allocationFromPool);
return allocationFromPool;
@@ -4039,6 +4042,8 @@ CL_API_ENTRY void *CL_API_CALL clDeviceMemAllocINTEL(
unifiedMemoryProperties.device = &neoDevice->getDevice();
neoContext->initializeDeviceUsmAllocationPool();
auto allocationFromPool = neoContext->getDeviceMemAllocPool().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
if (allocationFromPool) {
TRACING_EXIT(ClDeviceMemAllocINTEL, &allocationFromPool);

View File

@@ -299,7 +299,6 @@ bool Context::createImpl(const cl_context_properties *properties,
setupContextType();
initializeManagers();
initializeDeviceUsmAllocationPool();
smallBufferPoolAllocator.setParams(SmallBuffersParams::getPreferredBufferPoolParams(device->getProductHelper()));
}
@@ -506,11 +505,19 @@ bool Context::isSingleDeviceContext() {
}
void Context::initializeDeviceUsmAllocationPool() {
if (this->usmPoolInitialized) {
return;
}
auto svmMemoryManager = getSVMAllocsManager();
if (!(svmMemoryManager && this->isSingleDeviceContext())) {
return;
}
TakeOwnershipWrapper<Context> lock(*this);
if (this->usmPoolInitialized) {
return;
}
auto &productHelper = getDevices()[0]->getProductHelper();
bool enabled = ApiSpecificConfig::isDeviceUsmPoolingEnabled() &&
productHelper.isDeviceUsmPoolAllocatorSupported() &&
@@ -530,6 +537,7 @@ void Context::initializeDeviceUsmAllocationPool() {
memoryProperties.device = &neoDevice;
usmDeviceMemAllocPool.initialize(svmMemoryManager, memoryProperties, usmDevicePoolParams.poolSize, usmDevicePoolParams.minServicedSize, usmDevicePoolParams.maxServicedSize);
}
this->usmPoolInitialized = true;
}
bool Context::BufferPoolAllocator::isAggregatedSmallBuffersEnabled(Context *context) const {

View File

@@ -304,6 +304,7 @@ class Context : public BaseObject<_cl_context> {
bool interopUserSync = false;
bool resolvesRequiredInKernels = false;
bool usmPoolInitialized = false;
bool platformManagersInitialized = false;
};

View File

@@ -169,7 +169,6 @@ bool Platform::initialize(std::vector<std::unique_ptr<Device>> devices) {
bool requiresWritableStaging = this->clDevices[0]->getDefaultEngine().commandStreamReceiver->getType() != CommandStreamReceiverType::hardware;
this->stagingBufferManager = new StagingBufferManager(this->svmAllocsManager, rootDeviceIndices, deviceBitfields, requiresWritableStaging);
this->initializeHostUsmAllocationPool(rootDeviceIndices, deviceBitfields);
DEBUG_BREAK_IF(this->platformInfo);
this->platformInfo.reset(new PlatformInfo);
@@ -310,9 +309,17 @@ void Platform::decActiveContextCount() {
}
}
void Platform::initializeHostUsmAllocationPool(const RootDeviceIndicesContainer &rootDeviceIndices, const std::map<uint32_t, DeviceBitfield> &deviceBitfields) {
void Platform::initializeHostUsmAllocationPool() {
if (this->usmPoolInitialized) {
return;
}
auto svmMemoryManager = this->getSVMAllocsManager();
TakeOwnershipWrapper<Platform> platformOwnership(*this);
if (this->usmPoolInitialized) {
return;
}
auto usmHostAllocPoolingEnabled = ApiSpecificConfig::isHostUsmPoolingEnabled();
for (auto &device : this->clDevices) {
usmHostAllocPoolingEnabled &= device->getProductHelper().isHostUsmPoolAllocatorSupported() && DeviceFactory::isHwModeSelected();
@@ -324,9 +331,27 @@ void Platform::initializeHostUsmAllocationPool(const RootDeviceIndicesContainer
usmHostPoolParams.poolSize = debugManager.flags.EnableHostUsmAllocationPool.get() * MemoryConstants::megaByte;
}
if (usmHostAllocPoolingEnabled) {
RootDeviceIndicesContainer rootDeviceIndices;
std::map<uint32_t, DeviceBitfield> deviceBitfields;
for (auto &device : this->clDevices) {
rootDeviceIndices.pushUnique(device->getRootDeviceIndex());
}
for (auto &rootDeviceIndex : rootDeviceIndices) {
DeviceBitfield deviceBitfield{};
for (const auto &pDevice : this->clDevices) {
if (pDevice->getRootDeviceIndex() == rootDeviceIndex) {
deviceBitfield |= pDevice->getDeviceBitfield();
}
}
deviceBitfields.insert({rootDeviceIndex, deviceBitfield});
}
SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::hostUnifiedMemory, MemoryConstants::pageSize2M,
rootDeviceIndices, deviceBitfields);
this->usmHostMemAllocPool.initialize(svmMemoryManager, memoryProperties, usmHostPoolParams.poolSize, usmHostPoolParams.minServicedSize, usmHostPoolParams.maxServicedSize);
}
this->usmPoolInitialized = true;
}
} // namespace NEO

View File

@@ -64,6 +64,7 @@ class Platform : public BaseObject<_cl_platform_id> {
SVMAllocsManager *getSVMAllocsManager() const;
StagingBufferManager *getStagingBufferManager() const;
UsmMemAllocPool &getHostMemAllocPool();
void initializeHostUsmAllocationPool();
void incActiveContextCount();
void decActiveContextCount();
@@ -78,7 +79,6 @@ class Platform : public BaseObject<_cl_platform_id> {
};
cl_uint state = StateNone;
void fillGlobalDispatchTable();
void initializeHostUsmAllocationPool(const RootDeviceIndicesContainer &rootDeviceIndices, const std::map<uint32_t, DeviceBitfield> &deviceBitfields);
std::unique_ptr<PlatformInfo> platformInfo;
ClDeviceVector clDevices;
ExecutionEnvironment &executionEnvironment;
@@ -88,6 +88,7 @@ class Platform : public BaseObject<_cl_platform_id> {
StagingBufferManager *stagingBufferManager = nullptr;
int32_t activeContextCount = 0;
UsmMemAllocPool usmHostMemAllocPool;
bool usmPoolInitialized = false;
};
static_assert(NEO::NonCopyableAndNonMovable<BaseObject<_cl_platform_id>>);

View File

@@ -266,9 +266,6 @@ TEST_F(ClSVMAllocTests, GivenForcedFineGrainedSvmWhenCreatingSvmAllocThenAllocat
}
TEST(clSvmAllocTest, givenSubDeviceWhenCreatingSvmAllocThenProperDeviceBitfieldIsPassed) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableDeviceUsmAllocationPool.set(0);
UltClDeviceFactory deviceFactory{1, 2};
auto device = deviceFactory.subDevices[1];

View File

@@ -23,7 +23,6 @@ using namespace NEO;
struct ClUnifiedSharedMemoryTests : ::testing::Test {
void SetUp() override {
DebugManagerStateRestore restorer;
debugManager.flags.ExperimentalEnableHostAllocationCache.set(0);
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(0);
debugManager.flags.EnableHostUsmAllocationPool.set(0);
@@ -34,6 +33,7 @@ struct ClUnifiedSharedMemoryTests : ::testing::Test {
std::unique_ptr<UltClDeviceFactoryWithPlatform> deviceFactory;
std::unique_ptr<MockContext> mockContext;
DebugManagerStateRestore restorer;
};
TEST_F(ClUnifiedSharedMemoryTests, whenClHostMemAllocINTELisCalledWithoutContextThenInvalidContextIsReturned) {
@@ -669,6 +669,7 @@ TEST_F(ClUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithAllocat
}
TEST_F(ClUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithAllocationSizeParamNameThenProperFieldsAreSet) {
cl_int retVal = CL_SUCCESS;
size_t paramValueSize = sizeof(size_t);
size_t paramValue = 0;
@@ -694,10 +695,6 @@ TEST_F(ClUnifiedSharedMemoryTests, givenSVMAllocationPoolWhenClGetMemAllocInfoIN
debugManager.flags.EnableHostUsmAllocationPool.set(2);
debugManager.flags.EnableDeviceUsmAllocationPool.set(2);
mockContext.reset();
deviceFactory = std::make_unique<UltClDeviceFactoryWithPlatform>(1, 0);
mockContext = std::make_unique<MockContext>(deviceFactory->rootDevices[0]);
auto device = mockContext->getDevice(0u);
cl_int retVal = CL_SUCCESS;
@@ -758,10 +755,6 @@ TEST_F(ClUnifiedSharedMemoryTests, givenSVMAllocationPoolWhenClGetMemAllocInfoIN
debugManager.flags.EnableHostUsmAllocationPool.set(2);
debugManager.flags.EnableDeviceUsmAllocationPool.set(2);
mockContext.reset();
deviceFactory = std::make_unique<UltClDeviceFactoryWithPlatform>(1, 0);
mockContext = std::make_unique<MockContext>(deviceFactory->rootDevices[0]);
auto device = mockContext->getDevice(0u);
cl_int retVal = CL_SUCCESS;
@@ -1386,15 +1379,12 @@ TEST_F(ClUnifiedSharedMemoryTests, givenUnifiedMemoryAllocationSizeGreaterThanMa
}
}
struct MultiRootDeviceClUnifiedSharedMemoryTests : public MultiRootDeviceFixture {
void SetUp() override {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostUsmAllocationPool.set(0);
MultiRootDeviceFixture::SetUp();
}
};
using MultiRootDeviceClUnifiedSharedMemoryTests = MultiRootDeviceFixture;
TEST_F(MultiRootDeviceClUnifiedSharedMemoryTests, WhenClHostMemAllocIntelIsCalledInMultiRootDeviceEnvironmentThenItAllocatesHostUnifiedMemoryAllocations) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostUsmAllocationPool.set(0);
cl_int retVal = CL_SUCCESS;
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(context.get(), nullptr, 4, 0, &retVal);
@@ -1429,6 +1419,7 @@ TEST_F(MultiRootDeviceClUnifiedSharedMemoryTests, WhenClHostMemAllocIntelIsCalle
}
TEST_F(MultiRootDeviceClUnifiedSharedMemoryTests, WhenClSharedMemAllocIntelIsCalledWithoutDeviceInMultiRootDeviceEnvironmentThenItAllocatesHostUnifiedMemoryAllocations) {
cl_int retVal = CL_SUCCESS;
auto unifiedMemorySharedAllocation = clSharedMemAllocINTEL(context.get(), nullptr, nullptr, 4, 0, &retVal);
@@ -1462,6 +1453,7 @@ TEST_F(MultiRootDeviceClUnifiedSharedMemoryTests, WhenClSharedMemAllocIntelIsCal
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(MultiRootDeviceClUnifiedSharedMemoryTests, WhenClSharedMemAllocIntelIsCalledWithoutDeviceInMultiRootDeviceEnvironmentThenItWaitsForAllGpuAllocations) {
mockMemoryManager->waitAllocations.reset(new MultiGraphicsAllocation(2u));
cl_int retVal = CL_SUCCESS;

View File

@@ -46,12 +46,6 @@ struct EnqueueSvmTest : public ClDeviceFixture,
EnqueueSvmTest() {
}
void cleanupUsmAllocations() {
context->getDevice(0)->getPlatform()->getHostMemAllocPool().cleanup();
context->getDeviceMemAllocPool().cleanup();
context->getSVMAllocsManager()->cleanupUSMAllocCaches();
}
void SetUp() override {
ClDeviceFixture::setUp();
CommandQueueFixture::setUp(pClDevice, 0);
@@ -214,8 +208,6 @@ TEST_F(EnqueueSvmTest, GivenValidParamsWhenUnmappingSvmWithEventsThenSuccessIsRe
}
TEST_F(EnqueueSvmTest, GivenValidParamsWhenFreeingSvmThenSuccessIsReturned) {
this->cleanupUsmAllocations();
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableAsyncEventsHandler.set(false);
ASSERT_EQ(1U, this->context->getSVMAllocsManager()->getNumAllocs());
@@ -987,8 +979,6 @@ TEST_F(EnqueueSvmTest, givenEnqueueTaskBlockedOnUserEventWhenItIsEnqueuedThenSur
}
TEST_F(EnqueueSvmTest, GivenMultipleThreasWhenAllocatingSvmThenOnlyOneAllocationIsCreated) {
this->cleanupUsmAllocations();
std::atomic<int> flag(0);
std::atomic<int> ready(0);
void *svmPtrs[15] = {};
@@ -1684,8 +1674,6 @@ struct FailCsr : public CommandStreamReceiverHw<GfxFamily> {
};
HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreMadeResidentThenOnlyNonSvmAllocationsAreAdded) {
this->cleanupUsmAllocations();
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, context->getRootDeviceIndices(), context->getDeviceBitfields());
unifiedMemoryProperties.device = pDevice;
auto allocationSize = 4096u;
@@ -1710,8 +1698,6 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreMadeResidentThenOnlyNonSvmAll
}
HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreAddedToResidencyContainerThenOnlyExpectedAllocationsAreAdded) {
this->cleanupUsmAllocations();
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, context->getRootDeviceIndices(), context->getDeviceBitfields());
unifiedMemoryProperties.device = pDevice;
auto allocationSize = 4096u;
@@ -1736,8 +1722,6 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreAddedToResidencyContainerThen
}
HWTEST_F(EnqueueSvmTest, whenInternalAllocationIsTriedToBeAddedTwiceToResidencyContainerThenItIsAdded) {
this->cleanupUsmAllocations();
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, context->getRootDeviceIndices(), context->getDeviceBitfields());
unifiedMemoryProperties.device = pDevice;
auto allocationSize = 4096u;

View File

@@ -778,32 +778,21 @@ TEST_F(AllocationReuseContextTest, givenHostPtrStoredInMapOperationsStorageAndRe
struct ContextUsmPoolParamsTest : public ::testing::Test {
void SetUp() override {
mockNeoDevice = deviceFactory.rootDevices[0];
device = deviceFactory.rootDevices[0];
mockNeoDevice = static_cast<MockDevice *>(&device->getDevice());
mockProductHelper = new MockProductHelper;
mockNeoDevice->getRootDeviceEnvironmentRef().productHelper.reset(mockProductHelper);
}
void TearDown() override {
context.reset();
NEO::cleanupPlatform(deviceFactory.rootDevices[0]->getExecutionEnvironment());
}
void createPlatformWithContext() {
platform = NEO::constructPlatform(deviceFactory.rootDevices[0]->getExecutionEnvironment());
NEO::initPlatform(deviceFactory.rootDevices);
device = static_cast<MockClDevice *>(platform->getClDevice(0));
}
bool compareUsmPoolParams(const UsmPoolParams &first, const UsmPoolParams &second) {
return first.poolSize == second.poolSize &&
first.minServicedSize == second.minServicedSize &&
first.maxServicedSize == second.maxServicedSize;
}
UltDeviceFactory deviceFactory{1, 0};
UltClDeviceFactoryWithPlatform deviceFactory{1, 0};
MockClDevice *device;
MockDevice *mockNeoDevice;
Platform *platform;
MockProductHelper *mockProductHelper;
std::unique_ptr<MockContext> context;
cl_int retVal = CL_SUCCESS;
@@ -811,7 +800,6 @@ struct ContextUsmPoolParamsTest : public ::testing::Test {
};
TEST_F(ContextUsmPoolParamsTest, whenGettingUsmPoolParamsThenReturnCorrectValues) {
ContextUsmPoolParamsTest::createPlatformWithContext();
cl_device_id devices[] = {device};
context.reset(Context::create<MockContext>(nullptr, ClDeviceVector(devices, 1), nullptr, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -827,14 +815,15 @@ TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingU
mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
ContextUsmPoolParamsTest::createPlatformWithContext();
cl_device_id devices[] = {device};
context.reset(Context::create<MockContext>(nullptr, ClDeviceVector(devices, 1), nullptr, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
auto platform = context->getDevice(0)->getPlatform();
EXPECT_NE(nullptr, platform);
context->initializeDeviceUsmAllocationPool();
platform->initializeHostUsmAllocationPool();
EXPECT_TRUE(platform->getHostMemAllocPool().isInitialized());
EXPECT_TRUE(context->getDeviceMemAllocPool().isInitialized());
@@ -849,3 +838,30 @@ TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingU
EXPECT_TRUE(compareUsmPoolParams(expectedUsmHostPoolParams, givenUsmHostPoolParams));
}
}
TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingUsmPoolsThenPoolsAreInitializedOnlyWithHwCsr) {
mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
cl_device_id devices[] = {device};
context.reset(Context::create<MockContext>(nullptr, ClDeviceVector(devices, 1), nullptr, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
for (int32_t csrType = 0; csrType < static_cast<int32_t>(CommandStreamReceiverType::typesNum); ++csrType) {
DebugManagerStateRestore restorer;
debugManager.flags.SetCommandStreamReceiver.set(static_cast<int32_t>(csrType));
auto platform = static_cast<MockPlatform *>(context->getDevice(0)->getPlatform());
EXPECT_NE(nullptr, platform);
EXPECT_FALSE(platform->getHostMemAllocPool().isInitialized());
EXPECT_FALSE(context->getDeviceMemAllocPool().isInitialized());
context->initializeDeviceUsmAllocationPool();
platform->initializeHostUsmAllocationPool();
EXPECT_EQ(DeviceFactory::isHwModeSelected(), platform->getHostMemAllocPool().isInitialized());
EXPECT_EQ(DeviceFactory::isHwModeSelected(), context->getDeviceMemAllocPool().isInitialized());
context->getDeviceMemAllocPool().cleanup();
platform->getHostMemAllocPool().cleanup();
context->usmPoolInitialized = false;
platform->usmPoolInitialized = false;
}
}

View File

@@ -1403,14 +1403,7 @@ TEST_F(KernelConstantSurfaceTest, givenStatelessKernelWhenKernelIsCreatedThenCon
delete kernel;
}
struct KernelResidencyTest : public ClDeviceFixture, ::testing::Test {
void SetUp() override {
debugManager.flags.EnableHostUsmAllocationPool.set(0);
debugManager.flags.EnableDeviceUsmAllocationPool.set(0);
ClDeviceFixture::setUp();
}
DebugManagerStateRestore restorer;
};
typedef Test<ClDeviceFixture> KernelResidencyTest;
HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenKernelIsaIsMadeResident) {
ASSERT_NE(nullptr, pDevice);

View File

@@ -798,7 +798,6 @@ TEST_F(CompressedBuffersSvmTests, givenSvmAllocationWhenCreatingBufferThenForceD
struct CompressedBuffersCopyHostMemoryTests : public CompressedBuffersTests {
void SetUp() override {
CompressedBuffersTests::SetUp();
context->getDeviceMemAllocPool().cleanup();
device->injectMemoryManager(new MockMemoryManager(true, false, *device->getExecutionEnvironment()));
context->memoryManager = device->getMemoryManager();
mockCmdQ = new MockCommandQueue();

View File

@@ -836,8 +836,6 @@ TEST_P(CreateImageHostPtr, givenLinearImageWhenFailedAtCreationThenReturnError)
}
TEST_P(CreateImageHostPtr, WhenWritingOutsideAllocatedMemoryWhileCreatingImageThenWriteIsHandledCorrectly) {
pClDevice->getPlatform()->getHostMemAllocPool().cleanup();
context->getDeviceMemAllocPool().cleanup();
pClDevice->getPlatform()->getSVMAllocsManager()->cleanupUSMAllocCaches();
auto mockMemoryManager = new MockMemoryManager(*pDevice->executionEnvironment);
pDevice->injectMemoryManager(mockMemoryManager);

View File

@@ -5,17 +5,14 @@
*
*/
#include "shared/source/os_interface/device_factory.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/raii_product_helper.h"
#include "shared/test/common/mocks/mock_product_helper.h"
#include "shared/test/common/mocks/mock_usm_memory_pool.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/test.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/mocks/mock_platform.h"
#include "opencl/test/unit_test/mocks/ult_cl_device_factory_with_platform.h"
#include "gtest/gtest.h"
@@ -24,21 +21,8 @@ using namespace NEO;
struct UsmPoolTest : public ::testing::Test {
void SetUp() override {
deviceFactory = std::make_unique<UltDeviceFactory>(2, 0);
}
void TearDown() override {
mockContext.reset();
NEO::cleanupPlatform(deviceFactory->rootDevices[0]->getExecutionEnvironment());
deviceFactory.reset();
}
void createPlatformWithContext() {
platform = NEO::constructPlatform(deviceFactory->rootDevices[0]->getExecutionEnvironment());
NEO::initPlatform(deviceFactory->rootDevices);
device = static_cast<MockClDevice *>(platform->getClDevice(0));
deviceFactory = std::make_unique<UltClDeviceFactoryWithPlatform>(2, 0);
device = deviceFactory->rootDevices[0];
if (device->deviceInfo.svmCapabilities == 0) {
GTEST_SKIP();
}
@@ -52,40 +36,43 @@ struct UsmPoolTest : public ::testing::Test {
}
MockClDevice *device;
std::unique_ptr<UltDeviceFactory> deviceFactory;
std::unique_ptr<UltClDeviceFactoryWithPlatform> deviceFactory;
std::unique_ptr<MockContext> mockContext;
MockUsmMemAllocPool *mockDeviceUsmMemAllocPool;
MockUsmMemAllocPool *mockHostUsmMemAllocPool;
Platform *platform;
constexpr static auto poolAllocationThreshold = 1 * MemoryConstants::megaByte;
};
TEST_F(UsmPoolTest, givenCreatedContextWhenCheckingUsmPoolsThenPoolsAreInitialized) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableDeviceUsmAllocationPool.set(1);
debugManager.flags.EnableHostUsmAllocationPool.set(3);
TEST_F(UsmPoolTest, givenCreatedContextWhenCheckingUsmPoolsThenPoolsAreNotInitialized) {
EXPECT_FALSE(mockDeviceUsmMemAllocPool->isInitialized());
EXPECT_EQ(0u, mockDeviceUsmMemAllocPool->poolSize);
EXPECT_EQ(nullptr, mockDeviceUsmMemAllocPool->pool);
UsmPoolTest::createPlatformWithContext();
EXPECT_TRUE(mockDeviceUsmMemAllocPool->isInitialized());
EXPECT_EQ(1 * MemoryConstants::megaByte, mockDeviceUsmMemAllocPool->poolSize);
EXPECT_NE(nullptr, mockDeviceUsmMemAllocPool->pool);
EXPECT_TRUE(mockHostUsmMemAllocPool->isInitialized());
EXPECT_EQ(3 * MemoryConstants::megaByte, mockHostUsmMemAllocPool->poolSize);
EXPECT_NE(nullptr, mockHostUsmMemAllocPool->pool);
EXPECT_FALSE(mockHostUsmMemAllocPool->isInitialized());
EXPECT_EQ(0u, mockHostUsmMemAllocPool->poolSize);
EXPECT_EQ(nullptr, mockHostUsmMemAllocPool->pool);
}
TEST_F(UsmPoolTest, givenEnabledDebugFlagsAndUsmPoolsNotSupportedWhenCheckingUsmPoolsThenPoolsAreInitialized) {
TEST_F(UsmPoolTest, givenEnabledDebugFlagsAndUsmPoolsNotSupportedWhenCreatingAllocationsThenPoolsAreInitialized) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableDeviceUsmAllocationPool.set(1);
debugManager.flags.EnableHostUsmAllocationPool.set(3);
RAIIProductHelperFactory<MockProductHelper> device1Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[1]);
RAIIProductHelperFactory<MockProductHelper> device1Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[1]);
device1Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = false;
device1Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = false;
device2Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = false;
UsmPoolTest::createPlatformWithContext();
cl_int retVal = CL_SUCCESS;
void *pooledDeviceAlloc = clDeviceMemAllocINTEL(mockContext.get(), static_cast<cl_device_id>(mockContext->getDevice(0)), nullptr, poolAllocationThreshold, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, pooledDeviceAlloc);
clMemFreeINTEL(mockContext.get(), pooledDeviceAlloc);
void *pooledHostAlloc = clHostMemAllocINTEL(mockContext.get(), nullptr, poolAllocationThreshold, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, pooledHostAlloc);
clMemFreeINTEL(mockContext.get(), pooledHostAlloc);
EXPECT_TRUE(mockDeviceUsmMemAllocPool->isInitialized());
EXPECT_EQ(1 * MemoryConstants::megaByte, mockDeviceUsmMemAllocPool->poolSize);
@@ -99,13 +86,22 @@ TEST_F(UsmPoolTest, givenEnabledDebugFlagsAndUsmPoolsNotSupportedWhenCheckingUsm
}
TEST_F(UsmPoolTest, givenUsmPoolsSupportedWhenCreatingAllocationsThenPoolsAreInitialized) {
RAIIProductHelperFactory<MockProductHelper> device1Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[1]);
RAIIProductHelperFactory<MockProductHelper> device1Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[1]);
device1Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
device1Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
device2Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
UsmPoolTest::createPlatformWithContext();
cl_int retVal = CL_SUCCESS;
void *pooledDeviceAlloc = clDeviceMemAllocINTEL(mockContext.get(), static_cast<cl_device_id>(mockContext->getDevice(0)), nullptr, poolAllocationThreshold, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, pooledDeviceAlloc);
clMemFreeINTEL(mockContext.get(), pooledDeviceAlloc);
void *pooledHostAlloc = clHostMemAllocINTEL(mockContext.get(), nullptr, poolAllocationThreshold, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, pooledHostAlloc);
clMemFreeINTEL(mockContext.get(), pooledHostAlloc);
EXPECT_EQ(UsmPoolParams::getUsmPoolSize(), mockDeviceUsmMemAllocPool->poolSize);
EXPECT_EQ(UsmPoolParams::getUsmPoolSize(), mockHostUsmMemAllocPool->poolSize);
@@ -117,14 +113,12 @@ TEST_F(UsmPoolTest, givenUsmPoolsSupportedAndDisabledByDebugFlagsWhenCreatingAll
DebugManagerStateRestore restorer;
debugManager.flags.EnableDeviceUsmAllocationPool.set(0);
debugManager.flags.EnableHostUsmAllocationPool.set(0);
RAIIProductHelperFactory<MockProductHelper> device1Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[1]);
RAIIProductHelperFactory<MockProductHelper> device1Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[1]);
device1Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
device1Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
device2Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
UsmPoolTest::createPlatformWithContext();
cl_int retVal = CL_SUCCESS;
void *deviceAlloc = clDeviceMemAllocINTEL(mockContext.get(), static_cast<cl_device_id>(mockContext->getDevice(0)), nullptr, poolAllocationThreshold, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -139,22 +133,17 @@ TEST_F(UsmPoolTest, givenUsmPoolsSupportedAndDisabledByDebugFlagsWhenCreatingAll
}
TEST_F(UsmPoolTest, givenUsmPoolsSupportedAndMultiDeviceContextWhenCreatingAllocationsThenDevicePoolIsNotInitialized) {
RAIIProductHelperFactory<MockProductHelper> device1Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[1]);
RAIIProductHelperFactory<MockProductHelper> device1Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[1]);
device1Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
device1Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
device2Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
device2Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
UsmPoolTest::createPlatformWithContext();
std::vector<cl_device_id> devices = {device, platform->getClDevice(1)};
cl_int retVal = CL_SUCCESS;
mockContext.reset(Context::create<MockContext>(nullptr, ClDeviceVector(devices.data(), 2), nullptr, nullptr, retVal));
mockDeviceUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&mockContext->getDeviceMemAllocPool());
EXPECT_EQ(CL_SUCCESS, retVal);
mockContext->devices.push_back(deviceFactory->rootDevices[1]);
EXPECT_FALSE(mockContext->isSingleDeviceContext());
cl_int retVal = CL_SUCCESS;
void *deviceAlloc = clDeviceMemAllocINTEL(mockContext.get(), static_cast<cl_device_id>(mockContext->getDevice(0)), nullptr, poolAllocationThreshold, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
clMemFreeINTEL(mockContext.get(), deviceAlloc);
@@ -165,14 +154,13 @@ TEST_F(UsmPoolTest, givenUsmPoolsSupportedAndMultiDeviceContextWhenCreatingAlloc
EXPECT_FALSE(mockDeviceUsmMemAllocPool->isInitialized());
EXPECT_TRUE(mockHostUsmMemAllocPool->isInitialized());
mockContext->devices.pop_back();
}
TEST_F(UsmPoolTest, givenTwoContextsWhenHostAllocationIsFreedInFirstContextThenItIsReusedInSecondContext) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostUsmAllocationPool.set(3);
UsmPoolTest::createPlatformWithContext();
cl_int retVal = CL_SUCCESS;
void *pooledHostAlloc1 = clHostMemAllocINTEL(mockContext.get(), nullptr, poolAllocationThreshold, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -194,35 +182,4 @@ TEST_F(UsmPoolTest, givenTwoContextsWhenHostAllocationIsFreedInFirstContextThenI
EXPECT_EQ(pooledHostAlloc1, pooledHostAlloc2);
clMemFreeINTEL(mockContext2.get(), pooledHostAlloc2);
}
TEST_F(UsmPoolTest, GivenUsmPoolAllocatorSupportedWhenInitializingUsmPoolsThenPoolsAreInitializedOnlyWithHwCsr) {
RAIIProductHelperFactory<MockProductHelper> device1Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[0]);
RAIIProductHelperFactory<MockProductHelper> device2Raii(*deviceFactory->rootDevices[0]->getExecutionEnvironment()->rootDeviceEnvironments[1]);
device1Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
device1Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
device2Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
UltClDeviceFactoryWithPlatform deviceFactoryWithPoolsEnabled{1, 0};
device = deviceFactoryWithPoolsEnabled.rootDevices[0];
UsmPoolTest::createPlatformWithContext();
EXPECT_TRUE(platform->getHostMemAllocPool().isInitialized());
EXPECT_TRUE(mockContext->getDeviceMemAllocPool().isInitialized());
mockContext.reset();
NEO::cleanupPlatform(deviceFactory->rootDevices[0]->getExecutionEnvironment());
for (int32_t csrType = 0; csrType < static_cast<int32_t>(CommandStreamReceiverType::typesNum); ++csrType) {
DebugManagerStateRestore restorer;
debugManager.flags.SetCommandStreamReceiver.set(static_cast<int32_t>(csrType));
UsmPoolTest::createPlatformWithContext();
EXPECT_NE(nullptr, platform);
EXPECT_EQ(DeviceFactory::isHwModeSelected(), platform->getHostMemAllocPool().isInitialized());
EXPECT_EQ(DeviceFactory::isHwModeSelected(), mockContext->getDeviceMemAllocPool().isInitialized());
mockContext.reset();
NEO::cleanupPlatform(deviceFactory->rootDevices[0]->getExecutionEnvironment());
}
}

View File

@@ -1301,13 +1301,14 @@ TEST(UnifiedMemoryManagerTest, givenEnableStatelessCompressionWhenDeviceAllocati
cl_int retVal = CL_SUCCESS;
for (auto enable : {-1, 0, 1}) {
debugManager.flags.EnableStatelessCompression.set(enable);
UltClDeviceFactoryWithPlatform deviceFactory{1, 0};
MockContext mockContext(deviceFactory.rootDevices[0]);
auto device = mockContext.getDevice(0u);
auto allocationsManager = mockContext.getSVMAllocsManager();
debugManager.flags.EnableStatelessCompression.set(enable);
auto deviceMemAllocPtr = clDeviceMemAllocINTEL(&mockContext, device, nullptr, 2048, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, deviceMemAllocPtr);

View File

@@ -126,7 +126,6 @@ void MockContext::initializeWithDevices(const ClDeviceVector &devices, bool noSp
}
initializeManagers();
initializeDeviceUsmAllocationPool();
cl_int retVal;
if (!noSpecialQueue) {

View File

@@ -43,6 +43,7 @@ class MockContext : public Context {
using Context::smallBufferPoolAllocator;
using Context::specialQueues;
using Context::svmAllocsManager;
using Context::usmPoolInitialized;
MockContext(ClDevice *pDevice, bool noSpecialQueue = false);
MockContext(const ClDeviceVector &clDeviceVector, bool noSpecialQueue = true);

View File

@@ -16,6 +16,7 @@ class MockDevice;
class MockPlatform : public Platform {
public:
using Platform::fillGlobalDispatchTable;
using Platform::usmPoolInitialized;
MockPlatform() : MockPlatform(*(new ExecutionEnvironment())) {}
MockPlatform(ExecutionEnvironment &executionEnvironment) : Platform(executionEnvironment) {}
bool initializeWithNewDevices();

View File

@@ -34,7 +34,6 @@ using DrmMemoryManagerTest = Test<DrmMemoryManagerFixture>;
struct ClDrmMemoryManagerTest : public DrmMemoryManagerTest {
template <typename GfxFamily>
void setUpT() {
debugManager.flags.EnableDeviceUsmAllocationPool.set(0);
MemoryManagementFixture::setUp();
executionEnvironment = MockClDevice::prepareExecutionEnvironment(defaultHwInfo.get(), numRootDevices - 1);
@@ -50,7 +49,6 @@ struct ClDrmMemoryManagerTest : public DrmMemoryManagerTest {
}
MockClDevice *pClDevice = nullptr;
DebugManagerStateRestore restorer;
};
HWTEST_TEMPLATED_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen32BitBufferIsReturned) {