mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
Create image allocations in system memory pool
Create image allocations in multi device setup in system memory pool Related-To: NEO-5508 Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
5a50ad098c
commit
0b7d2da162
@ -239,6 +239,8 @@ Image *Image::create(Context *context,
|
||||
AllocationInfoType allocationInfo;
|
||||
allocationInfo.resize(maxRootDeviceIndex + 1u);
|
||||
bool isParentObject = parentBuffer || parentImage;
|
||||
void *cpuPtr = nullptr;
|
||||
void *hostPtrForced = nullptr;
|
||||
|
||||
for (auto &rootDeviceIndex : context->getRootDeviceIndices()) {
|
||||
allocationInfo[rootDeviceIndex] = {};
|
||||
@ -321,11 +323,39 @@ Image *Image::create(Context *context,
|
||||
allocationInfo[rootDeviceIndex].mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr);
|
||||
}
|
||||
} else {
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo,
|
||||
true, // allocateMemory
|
||||
memoryProperties, hwInfo,
|
||||
context->getDeviceBitfieldForAllocation(rootDeviceIndex));
|
||||
allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
|
||||
if (context->getRootDeviceIndices().size() > 1) {
|
||||
MemoryProperties memoryPropertiesToSet = memoryProperties;
|
||||
memoryPropertiesToSet.flags.useHostPtr = true;
|
||||
memoryPropertiesToSet.flags.copyHostPtr = false;
|
||||
|
||||
if (cpuPtr) {
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo,
|
||||
false, // allocateMemory
|
||||
const_cast<MemoryProperties &>(memoryPropertiesToSet), hwInfo,
|
||||
context->getDeviceBitfieldForAllocation(rootDeviceIndex));
|
||||
allocProperties.flags.crossRootDeviceAccess = true;
|
||||
|
||||
allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, cpuPtr);
|
||||
} else {
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo,
|
||||
false, // allocateMemory
|
||||
const_cast<MemoryProperties &>(memoryPropertiesToSet), hwInfo,
|
||||
context->getDeviceBitfieldForAllocation(rootDeviceIndex));
|
||||
allocProperties.flags.crossRootDeviceAccess = true;
|
||||
|
||||
hostPtrForced = alignedMalloc(hostPtrMinSize, MemoryConstants::pageSize64k);
|
||||
allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtrForced);
|
||||
if (allocationInfo[rootDeviceIndex].memory) {
|
||||
cpuPtr = reinterpret_cast<void *>(allocationInfo[rootDeviceIndex].memory->getUnderlyingBuffer());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo,
|
||||
true, // allocateMemory
|
||||
memoryProperties, hwInfo,
|
||||
context->getDeviceBitfieldForAllocation(rootDeviceIndex));
|
||||
allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
|
||||
}
|
||||
|
||||
if (allocationInfo[rootDeviceIndex].memory && MemoryPool::isSystemMemoryPool(allocationInfo[rootDeviceIndex].memory->getMemoryPool())) {
|
||||
allocationInfo[rootDeviceIndex].zeroCopyAllowed = true;
|
||||
@ -336,6 +366,9 @@ Image *Image::create(Context *context,
|
||||
|
||||
if (!allocationInfo[rootDeviceIndex].memory) {
|
||||
cleanAllGraphicsAllocations(*context, *memoryManager, allocationInfo, isParentObject);
|
||||
if (hostPtrForced) {
|
||||
alignedFree(hostPtrForced);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -371,6 +404,8 @@ Image *Image::create(Context *context,
|
||||
image = createImageHw(context, memoryProperties, flags, flagsIntel, imgInfo.size, hostPtrToSet, surfaceFormat->OCLImageFormat,
|
||||
imageDescriptor, allocationInfo[defaultRootDeviceIndex].zeroCopyAllowed, std::move(multiGraphicsAllocation), false, 0, 0, surfaceFormat);
|
||||
|
||||
image->setAllocatedMapPtr(hostPtrForced);
|
||||
|
||||
for (auto &rootDeviceIndex : context->getRootDeviceIndices()) {
|
||||
|
||||
auto &hwInfo = *memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "opencl/source/mem_obj/image.h"
|
||||
#include "opencl/test/unit_test/helpers/unit_test_helper.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "opencl/test/unit_test/test_macros/test_checks_ocl.h"
|
||||
|
||||
#include "cl_api_tests.h"
|
||||
@ -1400,4 +1401,51 @@ TEST_F(clCreateImageWithMultiDeviceContextTests, GivenImageCreatedWithContextdWi
|
||||
clReleaseContext(context);
|
||||
}
|
||||
|
||||
TEST_F(clCreateImageWithMultiDeviceContextTests, GivenContextdWithMultiDeviceFailingAllocationThenImageAllocateFails) {
|
||||
REQUIRE_IMAGES_OR_SKIP(defaultHwInfo);
|
||||
|
||||
UltClDeviceFactory deviceFactory{2, 0};
|
||||
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
|
||||
|
||||
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[1]};
|
||||
|
||||
MockContext pContext(ClDeviceVector(devices, 2));
|
||||
|
||||
EXPECT_EQ(1u, pContext.getMaxRootDeviceIndex());
|
||||
|
||||
auto bufferSize = imageDesc.image_width * imageDesc.image_height * 4;
|
||||
|
||||
cl_mem_flags flags = CL_MEM_COPY_HOST_PTR;
|
||||
|
||||
{
|
||||
auto hostBuffer = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
auto ptrHostBuffer = static_cast<uint8_t *>(hostBuffer);
|
||||
|
||||
static_cast<MockMemoryManager *>(pContext.memoryManager)->successAllocatedGraphicsMemoryIndex = 0u;
|
||||
static_cast<MockMemoryManager *>(pContext.memoryManager)->maxSuccessAllocatedGraphicsMemoryIndex = 0u;
|
||||
|
||||
auto image = clCreateImage(&pContext, flags, &imageFormat, &imageDesc, ptrHostBuffer, &retVal);
|
||||
|
||||
ASSERT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
|
||||
alignedFree(hostBuffer);
|
||||
}
|
||||
|
||||
{
|
||||
auto hostBuffer = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
auto ptrHostBuffer = static_cast<uint8_t *>(hostBuffer);
|
||||
|
||||
static_cast<MockMemoryManager *>(pContext.memoryManager)->successAllocatedGraphicsMemoryIndex = 0u;
|
||||
static_cast<MockMemoryManager *>(pContext.memoryManager)->maxSuccessAllocatedGraphicsMemoryIndex = 1u;
|
||||
|
||||
auto image = clCreateImage(&pContext, flags, &imageFormat, &imageDesc, ptrHostBuffer, &retVal);
|
||||
|
||||
ASSERT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
|
||||
alignedFree(hostBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ClCreateImageTests
|
||||
|
@ -1604,6 +1604,20 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedThenImageAllocationHasCorrec
|
||||
EXPECT_EQ(expectedRootDeviceIndex, graphicsAllocation->getRootDeviceIndex());
|
||||
}
|
||||
|
||||
TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedWithoutHostPtrThenImageMultiGraphicsAllocationIsCreatedInSystemMemoryPool) {
|
||||
REQUIRE_IMAGES_OR_SKIP(defaultHwInfo);
|
||||
|
||||
std::unique_ptr<Image> image(ImageHelper<Image1dDefaults>::create(context.get()));
|
||||
|
||||
EXPECT_TRUE(MemoryPool::isSystemMemoryPool(image->getMultiGraphicsAllocation().getGraphicsAllocation(1u)->getMemoryPool()));
|
||||
EXPECT_TRUE(MemoryPool::isSystemMemoryPool(image->getMultiGraphicsAllocation().getGraphicsAllocation(2u)->getMemoryPool()));
|
||||
|
||||
auto graphicsAllocation1 = image->getMultiGraphicsAllocation().getGraphicsAllocation(1u);
|
||||
auto graphicsAllocation2 = image->getMultiGraphicsAllocation().getGraphicsAllocation(2u);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation2->getUnderlyingBuffer(), graphicsAllocation1->getUnderlyingBuffer());
|
||||
}
|
||||
|
||||
TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueWriteImageCalledThenImageMultiGraphicsAllocationLastUsedRootDeviceIndexHasCorrectRootDeviceIndex) {
|
||||
REQUIRE_IMAGES_OR_SKIP(defaultHwInfo);
|
||||
|
||||
@ -1624,7 +1638,7 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueWriteImageCalledTh
|
||||
desc.image_height = height * sizeof(unsigned int);
|
||||
|
||||
auto bufferSize = sizeof(unsigned int) * width * height;
|
||||
auto hostBuffer = alignedMalloc(bufferSize, 64 * 1024);
|
||||
auto hostBuffer = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
|
||||
|
||||
@ -1674,7 +1688,7 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueReadImageCalledThe
|
||||
desc.image_height = height * sizeof(unsigned int);
|
||||
|
||||
auto bufferSize = sizeof(unsigned int) * width * height;
|
||||
auto hostBuffer = alignedMalloc(bufferSize, 64 * 1024);
|
||||
auto hostBuffer = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
|
||||
|
||||
@ -1724,7 +1738,7 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueFillImageCalledThe
|
||||
desc.image_height = height * sizeof(unsigned int);
|
||||
|
||||
auto bufferSize = sizeof(unsigned int) * width * height;
|
||||
auto hostBuffer = alignedMalloc(bufferSize, 64 * 1024);
|
||||
auto hostBuffer = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
|
||||
|
||||
@ -1774,13 +1788,17 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageCalledThe
|
||||
desc.image_width = width * sizeof(unsigned int);
|
||||
desc.image_height = height * sizeof(unsigned int);
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
|
||||
|
||||
auto bufferSize = sizeof(unsigned int) * width * height;
|
||||
auto hostBuffer1 = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
auto hostBuffer2 = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(
|
||||
flags, &format, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
|
||||
std::unique_ptr<Image> image1(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal));
|
||||
std::unique_ptr<Image> image2(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal));
|
||||
std::unique_ptr<Image> image1(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, hostBuffer1, retVal));
|
||||
std::unique_ptr<Image> image2(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, hostBuffer2, retVal));
|
||||
|
||||
auto cmdQ1 = context->getSpecialQueue(1u);
|
||||
cmdQ1->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr);
|
||||
@ -1804,6 +1822,9 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageCalledThe
|
||||
cmdQ2->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
|
||||
EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
|
||||
|
||||
alignedFree(hostBuffer2);
|
||||
alignedFree(hostBuffer1);
|
||||
}
|
||||
|
||||
TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageToBufferCalledThenImageAndBufferMultiGraphicsAllocationsLastUsedRootDeviceIndexHasCorrectRootDeviceIndex) {
|
||||
@ -1825,13 +1846,17 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageToBufferC
|
||||
desc.image_width = width * sizeof(unsigned int);
|
||||
desc.image_height = height * sizeof(unsigned int);
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
|
||||
|
||||
auto bufferSize = sizeof(unsigned int) * width * height;
|
||||
auto hostBuffer1 = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
auto hostBuffer2 = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(
|
||||
flags, &format, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
|
||||
std::unique_ptr<Image> image(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal));
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, MemoryConstants::pageSize, nullptr, retVal));
|
||||
std::unique_ptr<Image> image(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, hostBuffer1, retVal));
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, MemoryConstants::pageSize, hostBuffer2, retVal));
|
||||
|
||||
auto cmdQ1 = context->getSpecialQueue(1u);
|
||||
cmdQ1->enqueueCopyImageToBuffer(image.get(), buffer.get(), orgin, region, 0, 0, nullptr, nullptr);
|
||||
@ -1855,6 +1880,9 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageToBufferC
|
||||
cmdQ2->enqueueCopyImageToBuffer(image.get(), buffer.get(), orgin, region, 0, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
|
||||
EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
|
||||
|
||||
alignedFree(hostBuffer2);
|
||||
alignedFree(hostBuffer1);
|
||||
}
|
||||
|
||||
TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyBufferToImageCalledThenImageAndBufferMultiGraphicsAllocationsLastUsedRootDeviceIndexHasCorrectRootDeviceIndex) {
|
||||
@ -1876,13 +1904,17 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyBufferToImageC
|
||||
desc.image_width = width * sizeof(unsigned int);
|
||||
desc.image_height = height * sizeof(unsigned int);
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
|
||||
|
||||
auto bufferSize = sizeof(unsigned int) * width * height;
|
||||
auto hostBuffer1 = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
auto hostBuffer2 = alignedMalloc(bufferSize, MemoryConstants::pageSize64k);
|
||||
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(
|
||||
flags, &format, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
|
||||
std::unique_ptr<Image> image(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal));
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, MemoryConstants::pageSize, nullptr, retVal));
|
||||
std::unique_ptr<Image> image(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, hostBuffer1, retVal));
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), flags, MemoryConstants::pageSize, hostBuffer2, retVal));
|
||||
|
||||
auto cmdQ1 = context->getSpecialQueue(1u);
|
||||
cmdQ1->enqueueCopyBufferToImage(buffer.get(), image.get(), 0, orgin, region, 0, nullptr, nullptr);
|
||||
@ -1906,4 +1938,7 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyBufferToImageC
|
||||
cmdQ2->enqueueCopyBufferToImage(buffer.get(), image.get(), 0, orgin, region, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
|
||||
EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
|
||||
|
||||
alignedFree(hostBuffer2);
|
||||
alignedFree(hostBuffer1);
|
||||
}
|
||||
|
@ -51,25 +51,55 @@ TEST_F(MemoryManagerGetAlloctionDataTests, givenNonHostMemoryAllocatoinTypeWhenA
|
||||
}
|
||||
|
||||
TEST_F(MemoryManagerGetAlloctionDataTests, givenMultiRootDeviceIndexAllocationPropertiesWhenAllocationDataIsQueriedThenUseSystemMemoryFlagsIsSet) {
|
||||
AllocationData allocData;
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield);
|
||||
properties.flags.crossRootDeviceAccess = true;
|
||||
{
|
||||
AllocationData allocData;
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield);
|
||||
properties.flags.crossRootDeviceAccess = true;
|
||||
|
||||
MockMemoryManager mockMemoryManager;
|
||||
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
|
||||
MockMemoryManager mockMemoryManager;
|
||||
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
|
||||
|
||||
EXPECT_TRUE(allocData.flags.useSystemMemory);
|
||||
EXPECT_TRUE(allocData.flags.useSystemMemory);
|
||||
EXPECT_TRUE(allocData.flags.crossRootDeviceAccess);
|
||||
}
|
||||
|
||||
{
|
||||
AllocationData allocData;
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::IMAGE, false, mockDeviceBitfield);
|
||||
properties.flags.crossRootDeviceAccess = true;
|
||||
|
||||
MockMemoryManager mockMemoryManager;
|
||||
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
|
||||
|
||||
EXPECT_TRUE(allocData.flags.useSystemMemory);
|
||||
EXPECT_TRUE(allocData.flags.crossRootDeviceAccess);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MemoryManagerGetAlloctionDataTests, givenDisabledCrossRootDeviceAccsessFlagInAllocationPropertiesWhenAllocationDataIsQueriedThenUseSystemMemoryFlagsIsNotSet) {
|
||||
AllocationData allocData;
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield);
|
||||
properties.flags.crossRootDeviceAccess = false;
|
||||
{
|
||||
AllocationData allocData;
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield);
|
||||
properties.flags.crossRootDeviceAccess = false;
|
||||
|
||||
MockMemoryManager mockMemoryManager;
|
||||
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
|
||||
MockMemoryManager mockMemoryManager;
|
||||
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
|
||||
|
||||
EXPECT_FALSE(allocData.flags.useSystemMemory);
|
||||
EXPECT_FALSE(allocData.flags.useSystemMemory);
|
||||
EXPECT_FALSE(allocData.flags.crossRootDeviceAccess);
|
||||
}
|
||||
|
||||
{
|
||||
AllocationData allocData;
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::IMAGE, false, mockDeviceBitfield);
|
||||
properties.flags.crossRootDeviceAccess = false;
|
||||
|
||||
MockMemoryManager mockMemoryManager;
|
||||
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
|
||||
|
||||
EXPECT_FALSE(allocData.flags.useSystemMemory);
|
||||
EXPECT_FALSE(allocData.flags.crossRootDeviceAccess);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(MemoryManagerGetAlloctionDataTests, givenCommandBufferAllocationTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) {
|
||||
|
@ -856,6 +856,44 @@ TEST(OsAgnosticMemoryManager, givenHostPointerRequiringCopyWhenAllocateGraphicsM
|
||||
alignedFree(hostPtr);
|
||||
}
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenEnabledCrossRootDeviceAccessFlagWhenAllocateGraphicsMemoryForImageFromHostPtrIsCalledThenGraphicsAllocationIsReturned) {
|
||||
ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment();
|
||||
MockMemoryManager memoryManager(false, false, *executionEnvironment);
|
||||
|
||||
cl_image_desc imgDesc = {};
|
||||
imgDesc.image_width = 4;
|
||||
imgDesc.image_height = 1;
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
|
||||
|
||||
cl_image_format imageFormat = {};
|
||||
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8;
|
||||
imageFormat.image_channel_order = CL_RGBA;
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR;
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, defaultHwInfo->capabilityTable.supportsOcl21Features);
|
||||
|
||||
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, surfaceFormat);
|
||||
imgInfo.rowPitch = imgDesc.image_width * 4;
|
||||
imgInfo.slicePitch = imgInfo.rowPitch * imgDesc.image_height;
|
||||
imgInfo.size = imgInfo.slicePitch;
|
||||
imgInfo.linearStorage = true;
|
||||
|
||||
auto hostPtr = alignedMalloc(imgDesc.image_width * imgDesc.image_height * 4, MemoryConstants::pageSize);
|
||||
|
||||
AllocationData allocationData;
|
||||
allocationData.imgInfo = &imgInfo;
|
||||
allocationData.hostPtr = hostPtr;
|
||||
allocationData.size = imgInfo.size;
|
||||
allocationData.flags.crossRootDeviceAccess = true;
|
||||
|
||||
auto imageAllocation = memoryManager.allocateGraphicsMemoryForImageFromHostPtr(allocationData);
|
||||
ASSERT_NE(nullptr, imageAllocation);
|
||||
EXPECT_EQ(hostPtr, imageAllocation->getUnderlyingBuffer());
|
||||
|
||||
memoryManager.freeGraphicsMemory(imageAllocation);
|
||||
alignedFree(hostPtr);
|
||||
}
|
||||
|
||||
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAllocationWhenMappingThenReturnFalse) {
|
||||
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
|
||||
executionEnvironment.initGmm();
|
||||
|
@ -101,7 +101,8 @@ struct AllocationData {
|
||||
uint32_t resource48Bit : 1;
|
||||
uint32_t isUSMHostAllocation : 1;
|
||||
uint32_t use32BitFrontWindow : 1;
|
||||
uint32_t reserved : 18;
|
||||
uint32_t crossRootDeviceAccess : 1;
|
||||
uint32_t reserved : 17;
|
||||
} flags;
|
||||
uint32_t allFlags = 0;
|
||||
};
|
||||
|
@ -120,7 +120,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryWithHostPtr(const Alloc
|
||||
GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForImageFromHostPtr(const AllocationData &allocationData) {
|
||||
bool copyRequired = isCopyRequired(*allocationData.imgInfo, allocationData.hostPtr);
|
||||
|
||||
if (allocationData.hostPtr && !copyRequired) {
|
||||
if (allocationData.hostPtr && (!copyRequired || allocationData.flags.crossRootDeviceAccess)) {
|
||||
return allocateGraphicsMemoryWithHostPtr(allocationData);
|
||||
}
|
||||
return nullptr;
|
||||
@ -424,6 +424,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
|
||||
allocationData.rootDeviceIndex = properties.rootDeviceIndex;
|
||||
allocationData.useMmapObject = properties.useMmapObject;
|
||||
|
||||
allocationData.flags.crossRootDeviceAccess = properties.flags.crossRootDeviceAccess;
|
||||
allocationData.flags.useSystemMemory |= properties.flags.crossRootDeviceAccess;
|
||||
|
||||
hwHelper.setExtraAllocationData(allocationData, properties, *hwInfo);
|
||||
|
Reference in New Issue
Block a user