Skip to content

Commit 4f54ea5

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
Enable memory transfer between images
Unlock flow for multi device setup in: - enqueueCopyImage Update cleanAllGraphicsAllocations test Related-To: NEO-4589 Signed-off-by: Krzysztof Gibala <[email protected]>
1 parent 0747cb8 commit 4f54ea5

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

opencl/source/command_queue/enqueue_copy_image.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImage(
3232
const cl_event *eventWaitList,
3333
cl_event *event) {
3434

35+
auto rootDeviceIndex = getDevice().getRootDeviceIndex();
36+
37+
srcImage->getMigrateableMultiGraphicsAllocation().ensureMemoryOnDevice(*getDevice().getMemoryManager(), rootDeviceIndex);
38+
dstImage->getMigrateableMultiGraphicsAllocation().ensureMemoryOnDevice(*getDevice().getMemoryManager(), rootDeviceIndex);
39+
3540
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImageToImage3d,
3641
this->getClDevice());
3742
BuiltInOwnershipWrapper builtInLock(builder);

opencl/test/unit_test/mem_obj/buffer_tests.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,14 +1809,20 @@ TEST_F(BufferTransferTests, givenBufferWhenTransferFromHostPtrCalledThenCopyRequ
18091809

18101810
using MultiRootDeviceBufferTest = MultiRootDeviceFixture;
18111811

1812-
TEST_F(MultiRootDeviceBufferTest, WhenCleanAllGraphicsAllocationsCalledThenGraphicsAllocationsAreProperlyRemoved) {
1812+
TEST_F(MultiRootDeviceBufferTest, WhenCleanAllGraphicsAllocationsCalledThenGraphicsAllocationsAreProperlyRemovedAccordingToIsParentObjectFlag) {
18131813
AllocationInfoType allocationInfo;
18141814
allocationInfo.resize(3u);
18151815

18161816
allocationInfo[1u] = {};
18171817
allocationInfo[1u].memory = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1u, MemoryConstants::pageSize});
18181818

1819-
Buffer::cleanAllGraphicsAllocations(*context, *context->getMemoryManager(), allocationInfo, false);
1819+
bool isParentObject = true;
1820+
Buffer::cleanAllGraphicsAllocations(*context, *context->getMemoryManager(), allocationInfo, isParentObject);
1821+
EXPECT_EQ(mockMemoryManager->freeGraphicsMemoryCalled, 0u);
1822+
1823+
isParentObject = false;
1824+
Buffer::cleanAllGraphicsAllocations(*context, *context->getMemoryManager(), allocationInfo, isParentObject);
1825+
EXPECT_EQ(mockMemoryManager->freeGraphicsMemoryCalled, 1u);
18201826
}
18211827

18221828
TEST_F(MultiRootDeviceBufferTest, WhenBufferIsCreatedThenBufferGraphicsAllocationHasCorrectRootDeviceIndex) {

opencl/test/unit_test/mem_obj/image_tests.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,3 +1764,54 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueReadImageCalledThe
17641764

17651765
alignedFree(hostBuffer);
17661766
}
1767+
1768+
TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageCalledThenImagesMultiGraphicsAllocationLastUsedRootDeviceIndexHasCorrectRootDeviceIndex) {
1769+
REQUIRE_IMAGES_OR_SKIP(defaultHwInfo);
1770+
1771+
cl_int retVal = 0;
1772+
1773+
size_t height = 4;
1774+
size_t width = 4;
1775+
size_t region[] = {width * height, 1, 1};
1776+
size_t orgin[] = {0, 0, 0};
1777+
1778+
cl_image_format format;
1779+
format.image_channel_order = CL_RGBA;
1780+
format.image_channel_data_type = CL_UNSIGNED_INT8;
1781+
1782+
cl_image_desc desc{};
1783+
desc.image_type = CL_MEM_OBJECT_IMAGE2D;
1784+
desc.image_width = width * sizeof(unsigned int);
1785+
desc.image_height = height * sizeof(unsigned int);
1786+
1787+
cl_mem_flags flags = CL_MEM_READ_WRITE;
1788+
1789+
auto surfaceFormat = Image::getSurfaceFormatFromTable(
1790+
flags, &format, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
1791+
1792+
std::unique_ptr<Image> image1(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal));
1793+
std::unique_ptr<Image> image2(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal));
1794+
1795+
auto cmdQ1 = context->getSpecialQueue(1u);
1796+
cmdQ1->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr);
1797+
EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u);
1798+
EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u);
1799+
1800+
cmdQ1->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr);
1801+
EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u);
1802+
EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u);
1803+
1804+
auto cmdQ2 = context->getSpecialQueue(2u);
1805+
cmdQ2->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr);
1806+
EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
1807+
EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
1808+
1809+
cmdQ1->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr);
1810+
EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u);
1811+
EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u);
1812+
1813+
static_cast<MemoryAllocation *>(image1->getMigrateableMultiGraphicsAllocation().getGraphicsAllocation(2u))->overrideMemoryPool(MemoryPool::LocalMemory);
1814+
cmdQ2->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr);
1815+
EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
1816+
EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u);
1817+
}

0 commit comments

Comments
 (0)