mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 00:24:58 +08:00
Revert "feature: integrate UsmMemAllocPoolsManager with OpenCL device pool"
This reverts commit 7833d62e3a.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
88c473bcf0
commit
f9225de6b1
@@ -4046,7 +4046,7 @@ CL_API_ENTRY void *CL_API_CALL clDeviceMemAllocINTEL(
|
||||
|
||||
neoContext->initializeDeviceUsmAllocationPool();
|
||||
|
||||
auto allocationFromPool = neoContext->getDeviceMemAllocPoolsManager().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
|
||||
auto allocationFromPool = neoContext->getDeviceMemAllocPool().createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
|
||||
if (allocationFromPool) {
|
||||
TRACING_EXIT(ClDeviceMemAllocINTEL, &allocationFromPool);
|
||||
return allocationFromPool;
|
||||
@@ -4135,7 +4135,7 @@ CL_API_ENTRY cl_int CL_API_CALL clMemFreeCommon(cl_context context,
|
||||
|
||||
bool successfulFree = false;
|
||||
|
||||
if (ptr && neoContext->getDeviceMemAllocPoolsManager().freeSVMAlloc(const_cast<void *>(ptr), blocking)) {
|
||||
if (ptr && neoContext->getDeviceMemAllocPool().freeSVMAlloc(const_cast<void *>(ptr), blocking)) {
|
||||
successfulFree = true;
|
||||
}
|
||||
|
||||
@@ -4236,7 +4236,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetMemAllocInfoINTEL(
|
||||
TRACING_EXIT(ClGetMemAllocInfoINTEL, &retVal);
|
||||
return retVal;
|
||||
}
|
||||
if (auto basePtrFromDevicePool = pContext->getDeviceMemAllocPoolsManager().getPooledAllocationBasePtr(ptr)) {
|
||||
if (auto basePtrFromDevicePool = pContext->getDeviceMemAllocPool().getPooledAllocationBasePtr(ptr)) {
|
||||
retVal = changeGetInfoStatusToCLResultType(info.set<uint64_t>(castToUint64(basePtrFromDevicePool)));
|
||||
TRACING_EXIT(ClGetMemAllocInfoINTEL, &retVal);
|
||||
return retVal;
|
||||
@@ -4256,7 +4256,7 @@ CL_API_ENTRY cl_int CL_API_CALL clGetMemAllocInfoINTEL(
|
||||
TRACING_EXIT(ClGetMemAllocInfoINTEL, &retVal);
|
||||
return retVal;
|
||||
}
|
||||
if (auto sizeFromDevicePool = pContext->getDeviceMemAllocPoolsManager().getPooledAllocationSize(ptr)) {
|
||||
if (auto sizeFromDevicePool = pContext->getDeviceMemAllocPool().getPooledAllocationSize(ptr)) {
|
||||
retVal = changeGetInfoStatusToCLResultType(info.set<size_t>(sizeFromDevicePool));
|
||||
TRACING_EXIT(ClGetMemAllocInfoINTEL, &retVal);
|
||||
return retVal;
|
||||
|
||||
@@ -64,7 +64,7 @@ Context::~Context() {
|
||||
smallBufferPoolAllocator.releasePools();
|
||||
}
|
||||
|
||||
usmDeviceMemAllocPoolsManager.cleanup();
|
||||
usmDeviceMemAllocPool.cleanup();
|
||||
|
||||
delete[] properties;
|
||||
|
||||
@@ -123,11 +123,10 @@ cl_int Context::tryGetExistingSvmAllocation(const void *ptr,
|
||||
if (svmEntry) {
|
||||
memoryType = svmEntry->memoryType;
|
||||
UsmMemAllocPool *pool = nullptr;
|
||||
if (memoryType == InternalMemoryType::hostUnifiedMemory) {
|
||||
UsmMemAllocPool *hostAllocPool = &this->getDevice(0u)->getPlatform()->getHostMemAllocPool();
|
||||
pool = hostAllocPool->isInPool(ptr) ? hostAllocPool : nullptr;
|
||||
} else if (memoryType == InternalMemoryType::deviceUnifiedMemory) {
|
||||
pool = this->getDeviceMemAllocPoolsManager().getPoolContainingAlloc(ptr);
|
||||
if (this->getDevice(0u)->getPlatform()->getHostMemAllocPool().isInPool(ptr)) {
|
||||
pool = &this->getDevice(0u)->getPlatform()->getHostMemAllocPool();
|
||||
} else if (this->getDeviceMemAllocPool().isInPool(ptr)) {
|
||||
pool = &this->getDeviceMemAllocPool();
|
||||
}
|
||||
if (pool) {
|
||||
size_t pooledSize = pool->getPooledAllocationSize(ptr);
|
||||
@@ -525,18 +524,23 @@ void Context::initializeDeviceUsmAllocationPool() {
|
||||
}
|
||||
|
||||
auto &productHelper = getDevices()[0]->getProductHelper();
|
||||
bool usmDeviceAllocPoolingEnabled = ApiSpecificConfig::isDeviceUsmPoolingEnabled() &&
|
||||
productHelper.isDeviceUsmPoolAllocatorSupported() &&
|
||||
DeviceFactory::isHwModeSelected();
|
||||
bool enabled = ApiSpecificConfig::isDeviceUsmPoolingEnabled() &&
|
||||
productHelper.isDeviceUsmPoolAllocatorSupported() &&
|
||||
DeviceFactory::isHwModeSelected();
|
||||
|
||||
auto usmDevicePoolParams = UsmPoolParams::getUsmPoolParams(getDevices()[0]->getGfxCoreHelper());
|
||||
if (debugManager.flags.EnableDeviceUsmAllocationPool.get() != -1) {
|
||||
usmDeviceAllocPoolingEnabled = debugManager.flags.EnableDeviceUsmAllocationPool.get() > 0;
|
||||
enabled = debugManager.flags.EnableDeviceUsmAllocationPool.get() > 0;
|
||||
usmDevicePoolParams.poolSize = debugManager.flags.EnableDeviceUsmAllocationPool.get() * MemoryConstants::megaByte;
|
||||
}
|
||||
if (usmDeviceAllocPoolingEnabled) {
|
||||
if (enabled) {
|
||||
auto subDeviceBitfields = getDeviceBitfields();
|
||||
auto &neoDevice = devices[0]->getDevice();
|
||||
subDeviceBitfields[neoDevice.getRootDeviceIndex()] = neoDevice.getDeviceBitfield();
|
||||
this->usmDeviceMemAllocPoolsManager.initialize(InternalMemoryType::deviceUnifiedMemory, rootDeviceIndices, deviceBitfields, &this->devices[0]->getDevice(), svmMemoryManager);
|
||||
SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::deviceUnifiedMemory, MemoryConstants::pageSize2M,
|
||||
getRootDeviceIndices(), subDeviceBitfields);
|
||||
memoryProperties.device = &neoDevice;
|
||||
usmDeviceMemAllocPool.initialize(svmMemoryManager, memoryProperties, usmDevicePoolParams.poolSize, usmDevicePoolParams.minServicedSize, usmDevicePoolParams.maxServicedSize);
|
||||
}
|
||||
this->usmPoolInitialized = true;
|
||||
}
|
||||
|
||||
@@ -245,8 +245,8 @@ class Context : public BaseObject<_cl_context> {
|
||||
BufferPoolAllocator &getBufferPoolAllocator() {
|
||||
return smallBufferPoolAllocator;
|
||||
}
|
||||
UsmMemAllocPoolsFacade &getDeviceMemAllocPoolsManager() {
|
||||
return usmDeviceMemAllocPoolsManager;
|
||||
UsmMemAllocPool &getDeviceMemAllocPool() {
|
||||
return usmDeviceMemAllocPool;
|
||||
}
|
||||
|
||||
TagAllocatorBase *getMultiRootDeviceTimestampPacketAllocator();
|
||||
@@ -292,7 +292,7 @@ class Context : public BaseObject<_cl_context> {
|
||||
StackVec<CommandQueue *, 1> specialQueues;
|
||||
DriverDiagnostics *driverDiagnostics = nullptr;
|
||||
BufferPoolAllocator smallBufferPoolAllocator;
|
||||
UsmMemAllocPoolsFacade usmDeviceMemAllocPoolsManager;
|
||||
UsmDeviceMemAllocPool usmDeviceMemAllocPool;
|
||||
|
||||
uint32_t maxRootDeviceIndex = std::numeric_limits<uint32_t>::max();
|
||||
cl_bool preferD3dSharedResources = 0u;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "shared/source/unified_memory/usm_memory_support.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/mocks/mock_svm_manager.h"
|
||||
#include "shared/test/common/mocks/mock_usm_memory_pool.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
||||
@@ -423,12 +422,9 @@ TEST_F(clSetKernelArgSVMPointerTests, givenSvmAndValidArgValueWhenAllocIdCacheHi
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_EQ(++callCounter, pMockKernel->setArgSvmAllocCalls);
|
||||
|
||||
auto devicePoolsManager = static_cast<MockUsmMemAllocPoolsFacade *>(&pContext->getDeviceMemAllocPoolsManager());
|
||||
|
||||
auto expectedAllocationsCounter = 1u;
|
||||
expectedAllocationsCounter += pContext->getDevice(0u)->getPlatform()->getHostMemAllocPool().isInitialized() ? 1u : 0u;
|
||||
expectedAllocationsCounter += devicePoolsManager->poolManager ? 3u : 0u;
|
||||
expectedAllocationsCounter += devicePoolsManager->pool ? 1u : 0u;
|
||||
expectedAllocationsCounter += pContext->getDeviceMemAllocPool().isInitialized() ? 1u : 0u;
|
||||
|
||||
EXPECT_EQ(expectedAllocationsCounter, mockSvmManager->allocationsCounter);
|
||||
EXPECT_EQ(mockSvmManager->allocationsCounter, pMockKernel->getKernelArguments()[0].allocIdMemoryManagerCounter);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_context.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_kernel.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
||||
#include "opencl/test/unit_test/mocks/ult_cl_device_factory_with_platform.h"
|
||||
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
|
||||
|
||||
@@ -703,58 +702,51 @@ TEST_F(ClUnifiedSharedMemoryTests, givenSVMAllocationPoolWhenClGetMemAllocInfoIN
|
||||
size_t paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
const size_t allocationSize = 4u;
|
||||
auto platform = static_cast<MockPlatform *>(device->getPlatform());
|
||||
for (auto enablePoolManager : {false, true}) {
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(enablePoolManager);
|
||||
platform->getHostMemAllocPool().cleanup();
|
||||
platform->usmPoolInitialized = false;
|
||||
mockContext->getDeviceMemAllocPoolsManager().cleanup();
|
||||
mockContext->usmPoolInitialized = false;
|
||||
{
|
||||
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(mockContext.get(), nullptr, allocationSize, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryHostAllocation, CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
{
|
||||
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(mockContext.get(), nullptr, allocationSize, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryHostAllocation, CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryHostAllocation, allocationSize - 1), CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryHostAllocation, allocationSize - 1), CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryHostAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
{
|
||||
auto unifiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(mockContext.get(), device, nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryDeviceAllocation);
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryHostAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryDeviceAllocation, CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
{
|
||||
auto unifiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(mockContext.get(), device, nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryDeviceAllocation);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryDeviceAllocation, CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryDeviceAllocation, allocationSize - 1), CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryDeviceAllocation, allocationSize - 1), CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryDeviceAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(allocationSize, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryDeviceAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -770,59 +762,50 @@ TEST_F(ClUnifiedSharedMemoryTests, givenSVMAllocationPoolWhenClGetMemAllocInfoIN
|
||||
uint64_t paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
|
||||
auto platform = static_cast<MockPlatform *>(device->getPlatform());
|
||||
for (auto enablePoolManager : {false, true}) {
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(enablePoolManager);
|
||||
platform->getHostMemAllocPool().cleanup();
|
||||
platform->usmPoolInitialized = false;
|
||||
mockContext->getDeviceMemAllocPoolsManager().cleanup();
|
||||
mockContext->usmPoolInitialized = false;
|
||||
{
|
||||
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(mockContext.get(), nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
|
||||
|
||||
{
|
||||
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(mockContext.get(), nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryHostAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryHostAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryHostAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryHostAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryHostAllocation, 3), CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryHostAllocation, 3), CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryHostAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryHostAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryHostAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryHostAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
{
|
||||
auto unifiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(mockContext.get(), device, nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryDeviceAllocation);
|
||||
|
||||
{
|
||||
auto unifiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(mockContext.get(), device, nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext->getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryDeviceAllocation);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryDeviceAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), unifiedMemoryDeviceAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryDeviceAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryDeviceAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryDeviceAllocation, 3), CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(mockContext.get(), ptrOffset(unifiedMemoryDeviceAllocation, 3), CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryDeviceAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
|
||||
EXPECT_EQ(unifiedMemoryDeviceAllocation, addrToPtr(paramValue));
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryDeviceAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
retVal = clMemFreeINTEL(mockContext.get(), unifiedMemoryDeviceAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -812,9 +812,6 @@ TEST_F(ContextUsmPoolParamsTest, whenGettingUsmPoolParamsThenReturnCorrectValues
|
||||
}
|
||||
|
||||
TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingUsmPoolsThenPoolsAreInitializedWithCorrectParams) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(0);
|
||||
|
||||
mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
|
||||
mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
|
||||
|
||||
@@ -828,7 +825,7 @@ TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingU
|
||||
platform->initializeHostUsmAllocationPool();
|
||||
|
||||
EXPECT_TRUE(platform->getHostMemAllocPool().isInitialized());
|
||||
EXPECT_TRUE(context->getDeviceMemAllocPoolsManager().isInitialized());
|
||||
EXPECT_TRUE(context->getDeviceMemAllocPool().isInitialized());
|
||||
|
||||
{
|
||||
auto mockHostUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&platform->getHostMemAllocPool());
|
||||
@@ -843,9 +840,6 @@ TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingU
|
||||
}
|
||||
|
||||
TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingUsmPoolsThenPoolsAreInitializedOnlyWithHwCsr) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(0);
|
||||
|
||||
mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
|
||||
mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
|
||||
|
||||
@@ -859,13 +853,13 @@ TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingU
|
||||
auto platform = static_cast<MockPlatform *>(context->getDevice(0)->getPlatform());
|
||||
EXPECT_NE(nullptr, platform);
|
||||
EXPECT_FALSE(platform->getHostMemAllocPool().isInitialized());
|
||||
EXPECT_FALSE(context->getDeviceMemAllocPoolsManager().isInitialized());
|
||||
EXPECT_FALSE(context->getDeviceMemAllocPool().isInitialized());
|
||||
context->initializeDeviceUsmAllocationPool();
|
||||
platform->initializeHostUsmAllocationPool();
|
||||
|
||||
EXPECT_EQ(DeviceFactory::isHwModeSelected(), platform->getHostMemAllocPool().isInitialized());
|
||||
EXPECT_EQ(DeviceFactory::isHwModeSelected(), context->getDeviceMemAllocPoolsManager().isInitialized());
|
||||
context->getDeviceMemAllocPoolsManager().cleanup();
|
||||
EXPECT_EQ(DeviceFactory::isHwModeSelected(), context->getDeviceMemAllocPool().isInitialized());
|
||||
context->getDeviceMemAllocPool().cleanup();
|
||||
platform->getHostMemAllocPool().cleanup();
|
||||
context->usmPoolInitialized = false;
|
||||
platform->usmPoolInitialized = false;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#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"
|
||||
@@ -32,22 +31,23 @@ struct UsmPoolTest : public ::testing::Test {
|
||||
cl_int retVal;
|
||||
mockContext.reset(Context::create<MockContext>(nullptr, ClDeviceVector(&deviceId, 1), nullptr, nullptr, retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
mockDeviceMemPoolsFacade = static_cast<MockUsmMemAllocPoolsFacade *>(&mockContext->getDeviceMemAllocPoolsManager());
|
||||
mockDeviceUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&mockContext->getDeviceMemAllocPool());
|
||||
mockHostUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&mockContext->getDevice(0u)->getPlatform()->getHostMemAllocPool());
|
||||
}
|
||||
|
||||
MockClDevice *device;
|
||||
MockUsmMemAllocPoolsFacade *mockDeviceMemPoolsFacade;
|
||||
std::unique_ptr<UltClDeviceFactoryWithPlatform> deviceFactory;
|
||||
std::unique_ptr<MockContext> mockContext;
|
||||
MockUsmMemAllocPool *mockDeviceUsmMemAllocPool;
|
||||
MockUsmMemAllocPool *mockHostUsmMemAllocPool;
|
||||
constexpr static auto poolAllocationThreshold = MemoryConstants::pageSize;
|
||||
};
|
||||
|
||||
TEST_F(UsmPoolTest, givenCreatedContextWhenCheckingUsmPoolsThenPoolsAreNotInitialized) {
|
||||
EXPECT_FALSE(mockDeviceMemPoolsFacade->isInitialized());
|
||||
EXPECT_EQ(nullptr, mockDeviceMemPoolsFacade->poolManager);
|
||||
EXPECT_EQ(nullptr, mockDeviceMemPoolsFacade->pool);
|
||||
EXPECT_FALSE(mockDeviceUsmMemAllocPool->isInitialized());
|
||||
EXPECT_EQ(0u, mockDeviceUsmMemAllocPool->poolInfo.poolSize);
|
||||
EXPECT_EQ(nullptr, mockDeviceUsmMemAllocPool->pool);
|
||||
|
||||
MockUsmMemAllocPool *mockHostUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&mockContext->getDevice(0u)->getPlatform()->getHostMemAllocPool());
|
||||
EXPECT_FALSE(mockHostUsmMemAllocPool->isInitialized());
|
||||
EXPECT_EQ(0u, mockHostUsmMemAllocPool->poolInfo.poolSize);
|
||||
EXPECT_EQ(nullptr, mockHostUsmMemAllocPool->pool);
|
||||
@@ -63,53 +63,29 @@ TEST_F(UsmPoolTest, givenEnabledDebugFlagsAndUsmPoolsNotSupportedWhenCreatingAll
|
||||
device1Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = false;
|
||||
device2Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = false;
|
||||
|
||||
auto platform = static_cast<MockPlatform *>(device->getPlatform());
|
||||
for (auto enablePoolManager : {false, true}) {
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(enablePoolManager);
|
||||
platform->getHostMemAllocPool().cleanup();
|
||||
platform->usmPoolInitialized = false;
|
||||
mockContext->getDeviceMemAllocPoolsManager().cleanup();
|
||||
mockContext->usmPoolInitialized = false;
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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->poolInfo.poolSize);
|
||||
EXPECT_NE(nullptr, mockDeviceUsmMemAllocPool->pool);
|
||||
EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, mockDeviceUsmMemAllocPool->poolMemoryType);
|
||||
|
||||
if (enablePoolManager) {
|
||||
EXPECT_NE(nullptr, mockDeviceMemPoolsFacade->poolManager);
|
||||
|
||||
EXPECT_TRUE(platform->getHostMemAllocPool().isInitialized());
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->isInitialized());
|
||||
} else {
|
||||
EXPECT_NE(nullptr, mockDeviceMemPoolsFacade->pool);
|
||||
|
||||
EXPECT_TRUE(platform->getHostMemAllocPool().isInitialized());
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->isInitialized());
|
||||
|
||||
MockUsmMemAllocPool *mockDeviceUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(mockDeviceMemPoolsFacade->pool.get());
|
||||
EXPECT_EQ(1 * MemoryConstants::megaByte, mockDeviceUsmMemAllocPool->poolInfo.poolSize);
|
||||
EXPECT_NE(nullptr, mockDeviceUsmMemAllocPool->pool);
|
||||
EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, mockDeviceUsmMemAllocPool->poolMemoryType);
|
||||
|
||||
MockUsmMemAllocPool *mockHostUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&platform->getHostMemAllocPool());
|
||||
EXPECT_EQ(3 * MemoryConstants::megaByte, mockHostUsmMemAllocPool->poolInfo.poolSize);
|
||||
EXPECT_NE(nullptr, mockHostUsmMemAllocPool->pool);
|
||||
EXPECT_EQ(InternalMemoryType::hostUnifiedMemory, mockHostUsmMemAllocPool->poolMemoryType);
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(mockHostUsmMemAllocPool->isInitialized());
|
||||
EXPECT_EQ(3 * MemoryConstants::megaByte, mockHostUsmMemAllocPool->poolInfo.poolSize);
|
||||
EXPECT_NE(nullptr, mockHostUsmMemAllocPool->pool);
|
||||
EXPECT_EQ(InternalMemoryType::hostUnifiedMemory, mockHostUsmMemAllocPool->poolMemoryType);
|
||||
}
|
||||
|
||||
TEST_F(UsmPoolTest, givenUsmPoolsSupportedWhenCreatingAllocationsThenPoolsAreInitialized) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(0);
|
||||
|
||||
RAIIProductHelperFactory<MockProductHelper> device1Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]);
|
||||
RAIIProductHelperFactory<MockProductHelper> device2Raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[1]);
|
||||
device1Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
|
||||
@@ -127,8 +103,6 @@ TEST_F(UsmPoolTest, givenUsmPoolsSupportedWhenCreatingAllocationsThenPoolsAreIni
|
||||
EXPECT_NE(nullptr, pooledHostAlloc);
|
||||
clMemFreeINTEL(mockContext.get(), pooledHostAlloc);
|
||||
|
||||
MockUsmMemAllocPool *mockDeviceUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(mockDeviceMemPoolsFacade->pool.get());
|
||||
MockUsmMemAllocPool *mockHostUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&device->getPlatform()->getHostMemAllocPool());
|
||||
EXPECT_EQ(UsmPoolParams::getUsmPoolSize(deviceFactory->rootDevices[0]->getGfxCoreHelper()), mockDeviceUsmMemAllocPool->poolInfo.poolSize);
|
||||
EXPECT_EQ(UsmPoolParams::getUsmPoolSize(deviceFactory->rootDevices[0]->getGfxCoreHelper()), mockHostUsmMemAllocPool->poolInfo.poolSize);
|
||||
EXPECT_TRUE(mockDeviceUsmMemAllocPool->isInitialized());
|
||||
@@ -154,8 +128,8 @@ TEST_F(UsmPoolTest, givenUsmPoolsSupportedAndDisabledByDebugFlagsWhenCreatingAll
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
clMemFreeINTEL(mockContext.get(), hostAlloc);
|
||||
|
||||
EXPECT_FALSE(mockContext->getDeviceMemAllocPoolsManager().isInitialized());
|
||||
EXPECT_FALSE(mockContext->getDevice(0u)->getPlatform()->getHostMemAllocPool().isInitialized());
|
||||
EXPECT_FALSE(mockDeviceUsmMemAllocPool->isInitialized());
|
||||
EXPECT_FALSE(mockHostUsmMemAllocPool->isInitialized());
|
||||
}
|
||||
|
||||
TEST_F(UsmPoolTest, givenUsmPoolsSupportedAndMultiDeviceContextWhenCreatingAllocationsThenDevicePoolIsNotInitialized) {
|
||||
@@ -166,133 +140,46 @@ TEST_F(UsmPoolTest, givenUsmPoolsSupportedAndMultiDeviceContextWhenCreatingAlloc
|
||||
device2Raii.mockProductHelper->isDeviceUsmPoolAllocatorSupportedResult = true;
|
||||
device2Raii.mockProductHelper->isHostUsmPoolAllocatorSupportedResult = true;
|
||||
|
||||
auto platform = static_cast<MockPlatform *>(device->getPlatform());
|
||||
for (auto enablePoolManager : {false, true}) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(enablePoolManager);
|
||||
platform->getHostMemAllocPool().cleanup();
|
||||
platform->usmPoolInitialized = false;
|
||||
mockContext->getDeviceMemAllocPoolsManager().cleanup();
|
||||
mockContext->usmPoolInitialized = false;
|
||||
mockContext->devices.push_back(deviceFactory->rootDevices[1]);
|
||||
EXPECT_FALSE(mockContext->isSingleDeviceContext());
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
void *hostAlloc = clHostMemAllocINTEL(mockContext.get(), nullptr, poolAllocationThreshold, 0, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
clMemFreeINTEL(mockContext.get(), hostAlloc);
|
||||
|
||||
void *hostAlloc = clHostMemAllocINTEL(mockContext.get(), nullptr, poolAllocationThreshold, 0, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
clMemFreeINTEL(mockContext.get(), hostAlloc);
|
||||
|
||||
EXPECT_TRUE(platform->getHostMemAllocPool().isInitialized());
|
||||
EXPECT_FALSE(mockContext->getDeviceMemAllocPoolsManager().isInitialized());
|
||||
|
||||
mockContext->devices.pop_back();
|
||||
}
|
||||
EXPECT_FALSE(mockDeviceUsmMemAllocPool->isInitialized());
|
||||
EXPECT_TRUE(mockHostUsmMemAllocPool->isInitialized());
|
||||
mockContext->devices.pop_back();
|
||||
}
|
||||
|
||||
TEST_F(UsmPoolTest, givenTwoContextsWhenHostAllocationIsFreedInFirstContextThenItIsReusedInSecondContext) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(0);
|
||||
debugManager.flags.EnableHostUsmAllocationPool.set(3);
|
||||
|
||||
auto platform = static_cast<MockPlatform *>(device->getPlatform());
|
||||
for (auto enablePoolManager : {false, true}) {
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(enablePoolManager);
|
||||
platform->getHostMemAllocPool().cleanup();
|
||||
platform->usmPoolInitialized = false;
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
void *pooledHostAlloc1 = clHostMemAllocINTEL(mockContext.get(), nullptr, poolAllocationThreshold, 0, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_NE(nullptr, pooledHostAlloc1);
|
||||
|
||||
MockUsmMemAllocPool *mockHostUsmMemAllocPool = static_cast<MockUsmMemAllocPool *>(&platform->getHostMemAllocPool());
|
||||
EXPECT_GT(mockHostUsmMemAllocPool->poolInfo.poolSize, 0u);
|
||||
|
||||
clMemFreeINTEL(mockContext.get(), pooledHostAlloc1);
|
||||
|
||||
cl_device_id deviceId = device;
|
||||
auto mockContext2 = std::unique_ptr<MockContext>(Context::create<MockContext>(nullptr, ClDeviceVector(&deviceId, 1), nullptr, nullptr, retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
void *pooledHostAlloc2 = clHostMemAllocINTEL(mockContext2.get(), nullptr, poolAllocationThreshold, 0, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_NE(nullptr, pooledHostAlloc2);
|
||||
|
||||
EXPECT_EQ(pooledHostAlloc1, pooledHostAlloc2);
|
||||
|
||||
clMemFreeINTEL(mockContext2.get(), pooledHostAlloc2);
|
||||
}
|
||||
}
|
||||
|
||||
using UsmPoolManagerTest = UsmPoolTest;
|
||||
|
||||
TEST_F(UsmPoolManagerTest, givenCreatedContextWhenCheckingUsmPoolsManagersThenPoolsManagersAreNotInitialized) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(3);
|
||||
debugManager.flags.EnableDeviceUsmAllocationPool.set(1);
|
||||
|
||||
EXPECT_FALSE(mockContext->getDeviceMemAllocPoolsManager().isInitialized());
|
||||
EXPECT_EQ(nullptr, mockDeviceMemPoolsFacade->poolManager);
|
||||
}
|
||||
|
||||
TEST_F(UsmPoolManagerTest, givenUsmPoolsManagerSupportedWhenCreatingAllocationsThenPoolFromManagerIsUsed) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableHostUsmAllocationPool.set(3);
|
||||
debugManager.flags.EnableDeviceUsmAllocationPool.set(1);
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto deviceAlloc = clDeviceMemAllocINTEL(mockContext.get(), static_cast<cl_device_id>(mockContext->getDevice(0)), nullptr, 1 * MemoryConstants::kiloByte, 0, &retVal);
|
||||
void *pooledHostAlloc1 = clHostMemAllocINTEL(mockContext.get(), nullptr, poolAllocationThreshold, 0, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->isInitialized());
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->poolManager->isInitialized());
|
||||
EXPECT_NE(nullptr, pooledHostAlloc1);
|
||||
|
||||
auto pool = mockDeviceMemPoolsFacade->getPoolContainingAlloc(deviceAlloc);
|
||||
EXPECT_NE(pool, nullptr);
|
||||
EXPECT_TRUE(pool->isInPool(deviceAlloc));
|
||||
EXPECT_TRUE(mockHostUsmMemAllocPool->isInitialized());
|
||||
EXPECT_EQ(3 * MemoryConstants::megaByte, mockHostUsmMemAllocPool->poolInfo.poolSize);
|
||||
|
||||
clMemFreeINTEL(mockContext.get(), deviceAlloc);
|
||||
}
|
||||
clMemFreeINTEL(mockContext.get(), pooledHostAlloc1);
|
||||
|
||||
TEST_F(UsmPoolManagerTest, givenUsmPoolsManagerAllocationsWhenFreeingAllocationsThenFreeIsSuccessful) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableHostUsmAllocationPool.set(3);
|
||||
debugManager.flags.EnableDeviceUsmAllocationPool.set(1);
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto deviceAlloc = clDeviceMemAllocINTEL(mockContext.get(), static_cast<cl_device_id>(mockContext->getDevice(0)), nullptr, 1 * MemoryConstants::kiloByte, 0, &retVal);
|
||||
cl_device_id deviceId = device;
|
||||
auto mockContext2 = std::unique_ptr<MockContext>(Context::create<MockContext>(nullptr, ClDeviceVector(&deviceId, 1), nullptr, nullptr, retVal));
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->isInitialized());
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->poolManager->isInitialized());
|
||||
|
||||
auto pool = mockDeviceMemPoolsFacade->getPoolContainingAlloc(deviceAlloc);
|
||||
EXPECT_NE(pool, nullptr);
|
||||
EXPECT_FALSE(pool->isEmpty());
|
||||
|
||||
clMemFreeINTEL(mockContext.get(), deviceAlloc);
|
||||
EXPECT_TRUE(pool->isEmpty());
|
||||
}
|
||||
|
||||
TEST_F(UsmPoolManagerTest, givenUsmPoolsManagerAllocationsWhenFreeingInvalidAllocationThenErrorIsReturned) {
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableHostUsmAllocationPool.set(3);
|
||||
debugManager.flags.EnableDeviceUsmAllocationPool.set(1);
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
// first make valid allocation to initialize the pool manager
|
||||
auto deviceAlloc = clDeviceMemAllocINTEL(mockContext.get(), static_cast<cl_device_id>(mockContext->getDevice(0)), nullptr, 1 * MemoryConstants::kiloByte, 0, &retVal);
|
||||
void *pooledHostAlloc2 = clHostMemAllocINTEL(mockContext2.get(), nullptr, poolAllocationThreshold, 0, &retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->isInitialized());
|
||||
EXPECT_TRUE(mockDeviceMemPoolsFacade->poolManager->isInitialized());
|
||||
EXPECT_NE(nullptr, mockDeviceMemPoolsFacade->getPoolContainingAlloc(deviceAlloc));
|
||||
retVal = clMemFreeINTEL(mockContext.get(), deviceAlloc);
|
||||
EXPECT_EQ(retVal, CL_SUCCESS);
|
||||
EXPECT_NE(nullptr, pooledHostAlloc2);
|
||||
|
||||
retVal = clMemFreeINTEL(mockContext.get(), reinterpret_cast<void *>(0x123));
|
||||
EXPECT_NE(retVal, CL_SUCCESS);
|
||||
}
|
||||
EXPECT_EQ(pooledHostAlloc1, pooledHostAlloc2);
|
||||
|
||||
clMemFreeINTEL(mockContext2.get(), pooledHostAlloc2);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ MockContext::~MockContext() {
|
||||
stagingBufferManager = nullptr;
|
||||
}
|
||||
if (!platformManagersInitialized && svmAllocsManager) {
|
||||
usmDeviceMemAllocPoolsManager.cleanup();
|
||||
usmDeviceMemAllocPool.cleanup();
|
||||
svmAllocsManager->cleanupUSMAllocCaches();
|
||||
delete svmAllocsManager;
|
||||
svmAllocsManager = nullptr;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
#include "shared/source/memory_manager/memory_operations_handler.h"
|
||||
#include "shared/source/memory_manager/unified_memory_manager.h"
|
||||
#include "shared/source/memory_manager/usm_pool_params.h"
|
||||
#include "shared/source/utilities/heap_allocator.h"
|
||||
|
||||
namespace NEO {
|
||||
@@ -339,97 +338,4 @@ UsmMemAllocPool *UsmMemAllocPoolsManager::getPoolContainingAlloc(const void *ptr
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool UsmMemAllocPoolsFacade::initialize(InternalMemoryType memoryType, const RootDeviceIndicesContainer &rootDeviceIndices, const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields, Device *device, SVMAllocsManager *svmMemoryManager) {
|
||||
bool poolManagerEnabled = true;
|
||||
if (NEO::debugManager.flags.EnableUsmAllocationPoolManager.get() != -1) {
|
||||
poolManagerEnabled = NEO::debugManager.flags.EnableUsmAllocationPoolManager.get() != 0;
|
||||
}
|
||||
|
||||
if (poolManagerEnabled) {
|
||||
this->poolManager.reset(new UsmMemAllocPoolsManager(memoryType, rootDeviceIndices, subdeviceBitfields, device));
|
||||
return this->poolManager->initialize(svmMemoryManager);
|
||||
} else {
|
||||
this->pool.reset(new UsmMemAllocPool());
|
||||
SVMAllocsManager::UnifiedMemoryProperties memoryProperties(memoryType, MemoryConstants::pageSize2M,
|
||||
rootDeviceIndices, subdeviceBitfields);
|
||||
auto usmPoolParams = UsmPoolParams::getUsmPoolParams(device->getGfxCoreHelper());
|
||||
if (memoryType == InternalMemoryType::deviceUnifiedMemory && debugManager.flags.EnableDeviceUsmAllocationPool.get() != -1) {
|
||||
usmPoolParams.poolSize = debugManager.flags.EnableDeviceUsmAllocationPool.get() * MemoryConstants::megaByte;
|
||||
} else if (memoryType == InternalMemoryType::hostUnifiedMemory && debugManager.flags.EnableHostUsmAllocationPool.get() != -1) {
|
||||
usmPoolParams.poolSize = debugManager.flags.EnableHostUsmAllocationPool.get() * MemoryConstants::megaByte;
|
||||
}
|
||||
if (memoryType == InternalMemoryType::deviceUnifiedMemory) {
|
||||
memoryProperties.device = device;
|
||||
}
|
||||
return this->pool->initialize(svmMemoryManager, memoryProperties, usmPoolParams.poolSize, usmPoolParams.minServicedSize, usmPoolParams.maxServicedSize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UsmMemAllocPoolsFacade::isInitialized() const {
|
||||
if (this->poolManager) {
|
||||
return this->poolManager->isInitialized();
|
||||
} else if (this->pool) {
|
||||
return this->pool->isInitialized();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UsmMemAllocPoolsFacade::cleanup() {
|
||||
if (this->poolManager) {
|
||||
this->poolManager->cleanup();
|
||||
this->poolManager.reset();
|
||||
} else if (this->pool) {
|
||||
this->pool->cleanup();
|
||||
this->pool.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void *UsmMemAllocPoolsFacade::createUnifiedMemoryAllocation(size_t size, const SVMAllocsManager::UnifiedMemoryProperties &memoryProperties) {
|
||||
if (this->poolManager) {
|
||||
return this->poolManager->createUnifiedMemoryAllocation(size, memoryProperties);
|
||||
} else if (this->pool) {
|
||||
return this->pool->createUnifiedMemoryAllocation(size, memoryProperties);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool UsmMemAllocPoolsFacade::freeSVMAlloc(const void *ptr, bool blocking) {
|
||||
if (this->poolManager) {
|
||||
return this->poolManager->freeSVMAlloc(ptr, blocking);
|
||||
} else if (this->pool) {
|
||||
return this->pool->freeSVMAlloc(ptr, blocking);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t UsmMemAllocPoolsFacade::getPooledAllocationSize(const void *ptr) {
|
||||
if (this->poolManager) {
|
||||
return this->poolManager->getPooledAllocationSize(ptr);
|
||||
} else if (this->pool) {
|
||||
return this->pool->getPooledAllocationSize(ptr);
|
||||
}
|
||||
return 0u;
|
||||
}
|
||||
|
||||
void *UsmMemAllocPoolsFacade::getPooledAllocationBasePtr(const void *ptr) {
|
||||
if (this->poolManager) {
|
||||
return this->poolManager->getPooledAllocationBasePtr(ptr);
|
||||
} else if (this->pool) {
|
||||
return this->pool->getPooledAllocationBasePtr(ptr);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UsmMemAllocPool *UsmMemAllocPoolsFacade::getPoolContainingAlloc(const void *ptr) {
|
||||
if (this->poolManager) {
|
||||
if (auto poolPtr = this->poolManager->getPoolContainingAlloc(ptr)) {
|
||||
return poolPtr;
|
||||
}
|
||||
} else if (this->pool && this->pool->isInPool(ptr)) {
|
||||
return this->pool.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -141,20 +141,4 @@ class UsmMemAllocPoolsManager : NEO::NonCopyableAndNonMovableClass {
|
||||
bool trackResidency{false};
|
||||
};
|
||||
|
||||
class UsmMemAllocPoolsFacade : NEO::NonCopyableAndNonMovableClass {
|
||||
public:
|
||||
bool initialize(InternalMemoryType memoryType, const RootDeviceIndicesContainer &rootDeviceIndices, const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields, Device *device, SVMAllocsManager *svmMemoryManager);
|
||||
bool isInitialized() const;
|
||||
void cleanup();
|
||||
void *createUnifiedMemoryAllocation(size_t size, const SVMAllocsManager::UnifiedMemoryProperties &memoryProperties);
|
||||
bool freeSVMAlloc(const void *ptr, bool blocking);
|
||||
size_t getPooledAllocationSize(const void *ptr);
|
||||
void *getPooledAllocationBasePtr(const void *ptr);
|
||||
UsmMemAllocPool *getPoolContainingAlloc(const void *ptr);
|
||||
|
||||
protected:
|
||||
std::unique_ptr<UsmMemAllocPool> pool;
|
||||
std::unique_ptr<UsmMemAllocPoolsManager> poolManager;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -77,10 +77,4 @@ class MockUsmMemAllocPoolsManager : public UsmMemAllocPoolsManager {
|
||||
bool canAddPools = true;
|
||||
bool canAddPoolCallBase = false;
|
||||
};
|
||||
|
||||
class MockUsmMemAllocPoolsFacade : public UsmMemAllocPoolsFacade {
|
||||
public:
|
||||
using UsmMemAllocPoolsFacade::pool;
|
||||
using UsmMemAllocPoolsFacade::poolManager;
|
||||
};
|
||||
} // namespace NEO
|
||||
@@ -671,137 +671,3 @@ TEST_P(UnifiedMemoryPoolingManagerTest, givenInitializedPoolsManagerWhenAllocati
|
||||
|
||||
usmMemAllocPoolsManager->cleanup();
|
||||
}
|
||||
|
||||
class UnifiedMemoryPoolingFacadeTest : public SVMMemoryAllocatorFixture<true>, public ::testing::TestWithParam<std::tuple<InternalMemoryType, bool>> {
|
||||
public:
|
||||
void SetUp() override {
|
||||
REQUIRE_64BIT_OR_SKIP();
|
||||
SVMMemoryAllocatorFixture::setUp();
|
||||
|
||||
if (isPoolManagerEnabled) {
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(1);
|
||||
} else {
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(0);
|
||||
}
|
||||
|
||||
deviceFactory = std::unique_ptr<UltDeviceFactory>(new UltDeviceFactory(1, 1));
|
||||
device = deviceFactory->rootDevices[0];
|
||||
|
||||
svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager());
|
||||
mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
|
||||
if (InternalMemoryType::deviceUnifiedMemory == poolMemoryType) {
|
||||
mockMemoryManager->localMemorySupported[mockRootDeviceIndex] = true;
|
||||
}
|
||||
|
||||
poolMemoryProperties = std::make_unique<SVMAllocsManager::UnifiedMemoryProperties>(poolMemoryType, MemoryConstants::preferredAlignment, rootDeviceIndices, deviceBitfields);
|
||||
poolMemoryProperties->device = poolMemoryType == InternalMemoryType::deviceUnifiedMemory ? device : nullptr;
|
||||
|
||||
mockUsmMemAllocPoolsFacade.initialize(poolMemoryType, rootDeviceIndices, deviceBitfields, device, svmManager.get());
|
||||
}
|
||||
void TearDown() override {
|
||||
mockUsmMemAllocPoolsFacade.cleanup();
|
||||
SVMMemoryAllocatorFixture::tearDown();
|
||||
}
|
||||
|
||||
const InternalMemoryType poolMemoryType = std::get<0>(GetParam());
|
||||
const bool isPoolManagerEnabled = std::get<1>(GetParam());
|
||||
const size_t poolSize = 2 * MemoryConstants::megaByte;
|
||||
|
||||
std::unique_ptr<MockUsmMemAllocPoolsManager> usmMemAllocPoolsManager;
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory;
|
||||
std::unique_ptr<MockSVMAllocsManager> svmManager;
|
||||
std::unique_ptr<SVMAllocsManager::UnifiedMemoryProperties> poolMemoryProperties;
|
||||
|
||||
MockMemoryManager *mockMemoryManager;
|
||||
Device *device;
|
||||
MockUsmMemAllocPoolsFacade mockUsmMemAllocPoolsFacade;
|
||||
|
||||
private:
|
||||
DebugManagerStateRestore restorer;
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
UnifiedMemoryPoolingFacadeTestParameterized,
|
||||
UnifiedMemoryPoolingFacadeTest,
|
||||
::testing::Combine(
|
||||
::testing::Values(InternalMemoryType::deviceUnifiedMemory, InternalMemoryType::hostUnifiedMemory), ::testing::Bool()));
|
||||
|
||||
TEST_P(UnifiedMemoryPoolingFacadeTest, givenCombinationOfPoolManagerAndSinglePoolThenPoolsFacadeIsInitializedCorrectly) {
|
||||
if (isPoolManagerEnabled) {
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.isInitialized());
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.poolManager->isInitialized());
|
||||
EXPECT_EQ(nullptr, mockUsmMemAllocPoolsFacade.pool.get());
|
||||
} else {
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.isInitialized());
|
||||
EXPECT_EQ(nullptr, mockUsmMemAllocPoolsFacade.poolManager.get());
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.pool->isInitialized());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(UnifiedMemoryPoolingFacadeTest, givenVariousConfigurationsWhenAllocatingThenCorrectPathIsTaken) {
|
||||
size_t allocationSize = 1 * MemoryConstants::kiloByte;
|
||||
void *allocation = mockUsmMemAllocPoolsFacade.createUnifiedMemoryAllocation(allocationSize, *poolMemoryProperties.get());
|
||||
if (isPoolManagerEnabled) {
|
||||
EXPECT_EQ(mockUsmMemAllocPoolsFacade.poolManager->getPoolContainingAlloc(allocation), mockUsmMemAllocPoolsFacade.getPoolContainingAlloc(allocation));
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.poolManager->getPoolContainingAlloc(allocation)->isInPool(allocation));
|
||||
} else {
|
||||
EXPECT_EQ(mockUsmMemAllocPoolsFacade.pool.get(), mockUsmMemAllocPoolsFacade.getPoolContainingAlloc(allocation));
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.pool->isInPool(allocation));
|
||||
}
|
||||
|
||||
EXPECT_NE(nullptr, allocation);
|
||||
EXPECT_EQ(allocationSize, mockUsmMemAllocPoolsFacade.getPooledAllocationSize(allocation));
|
||||
EXPECT_EQ(allocation, mockUsmMemAllocPoolsFacade.getPooledAllocationBasePtr(ptrOffset(allocation, 20)));
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.freeSVMAlloc(allocation, true));
|
||||
}
|
||||
|
||||
TEST_P(UnifiedMemoryPoolingFacadeTest, givenInvalidAllocationWhenUsingPoolsFacadeThenCorrectValuesAreReturned) {
|
||||
void *allocation = reinterpret_cast<void *>(0x123);
|
||||
EXPECT_EQ(0u, mockUsmMemAllocPoolsFacade.getPooledAllocationSize(allocation));
|
||||
EXPECT_EQ(nullptr, mockUsmMemAllocPoolsFacade.getPooledAllocationBasePtr(allocation));
|
||||
EXPECT_EQ(nullptr, mockUsmMemAllocPoolsFacade.getPoolContainingAlloc(allocation));
|
||||
EXPECT_FALSE(mockUsmMemAllocPoolsFacade.freeSVMAlloc(allocation, true));
|
||||
}
|
||||
|
||||
TEST_P(UnifiedMemoryPoolingFacadeTest, givenNotInitializedPoolsFacadeWhenUsingPoolsFacadeThenCorrectValuesAreReturned) {
|
||||
mockUsmMemAllocPoolsFacade.cleanup();
|
||||
EXPECT_FALSE(mockUsmMemAllocPoolsFacade.isInitialized());
|
||||
|
||||
void *allocation = mockUsmMemAllocPoolsFacade.createUnifiedMemoryAllocation(1 * MemoryConstants::kiloByte, *poolMemoryProperties.get());
|
||||
EXPECT_EQ(nullptr, allocation);
|
||||
EXPECT_EQ(0u, mockUsmMemAllocPoolsFacade.getPooledAllocationSize(allocation));
|
||||
EXPECT_EQ(nullptr, mockUsmMemAllocPoolsFacade.getPooledAllocationBasePtr(allocation));
|
||||
EXPECT_EQ(nullptr, mockUsmMemAllocPoolsFacade.getPoolContainingAlloc(allocation));
|
||||
EXPECT_FALSE(mockUsmMemAllocPoolsFacade.freeSVMAlloc(allocation, true));
|
||||
}
|
||||
|
||||
TEST_P(UnifiedMemoryPoolingFacadeTest, givenNoDebugFlagsWhenInitializingPoolsFacadeThenPoolManagerIsEnabledByDefault) {
|
||||
mockUsmMemAllocPoolsFacade.cleanup();
|
||||
EXPECT_FALSE(mockUsmMemAllocPoolsFacade.isInitialized());
|
||||
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(-1);
|
||||
mockUsmMemAllocPoolsFacade.initialize(poolMemoryType, rootDeviceIndices, deviceBitfields, device, svmManager.get());
|
||||
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.isInitialized());
|
||||
EXPECT_TRUE(mockUsmMemAllocPoolsFacade.poolManager->isInitialized());
|
||||
EXPECT_EQ(nullptr, mockUsmMemAllocPoolsFacade.pool.get());
|
||||
}
|
||||
|
||||
TEST_P(UnifiedMemoryPoolingFacadeTest, givenPoolManagerDisabledAndCustomPoolSizeWhenInitializingPoolsFacadeThenPoolHasCorrectSize) {
|
||||
mockUsmMemAllocPoolsFacade.cleanup();
|
||||
EXPECT_FALSE(mockUsmMemAllocPoolsFacade.isInitialized());
|
||||
|
||||
DebugManagerStateRestore restorer;
|
||||
debugManager.flags.EnableUsmAllocationPoolManager.set(0);
|
||||
debugManager.flags.EnableDeviceUsmAllocationPool.set(1);
|
||||
debugManager.flags.EnableHostUsmAllocationPool.set(2);
|
||||
|
||||
mockUsmMemAllocPoolsFacade.initialize(poolMemoryType, rootDeviceIndices, deviceBitfields, device, svmManager.get());
|
||||
|
||||
if (poolMemoryType == InternalMemoryType::deviceUnifiedMemory) {
|
||||
EXPECT_EQ(1 * MemoryConstants::megaByte, mockUsmMemAllocPoolsFacade.pool->getPoolSize());
|
||||
} else {
|
||||
EXPECT_EQ(2 * MemoryConstants::megaByte, mockUsmMemAllocPoolsFacade.pool->getPoolSize());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user