From 4f54ea5c87fe84b953f1d21b5c24da2dd138383e Mon Sep 17 00:00:00 2001 From: Krzysztof Gibala Date: Fri, 11 Dec 2020 14:02:32 +0000 Subject: [PATCH] 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 --- .../source/command_queue/enqueue_copy_image.h | 5 ++ .../test/unit_test/mem_obj/buffer_tests.cpp | 10 +++- opencl/test/unit_test/mem_obj/image_tests.cpp | 51 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/opencl/source/command_queue/enqueue_copy_image.h b/opencl/source/command_queue/enqueue_copy_image.h index f6c6fef2a4..4ea0137348 100644 --- a/opencl/source/command_queue/enqueue_copy_image.h +++ b/opencl/source/command_queue/enqueue_copy_image.h @@ -32,6 +32,11 @@ cl_int CommandQueueHw::enqueueCopyImage( const cl_event *eventWaitList, cl_event *event) { + auto rootDeviceIndex = getDevice().getRootDeviceIndex(); + + srcImage->getMigrateableMultiGraphicsAllocation().ensureMemoryOnDevice(*getDevice().getMemoryManager(), rootDeviceIndex); + dstImage->getMigrateableMultiGraphicsAllocation().ensureMemoryOnDevice(*getDevice().getMemoryManager(), rootDeviceIndex); + auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImageToImage3d, this->getClDevice()); BuiltInOwnershipWrapper builtInLock(builder); diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 73fbc09ebf..fac141972d 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -1809,14 +1809,20 @@ TEST_F(BufferTransferTests, givenBufferWhenTransferFromHostPtrCalledThenCopyRequ using MultiRootDeviceBufferTest = MultiRootDeviceFixture; -TEST_F(MultiRootDeviceBufferTest, WhenCleanAllGraphicsAllocationsCalledThenGraphicsAllocationsAreProperlyRemoved) { +TEST_F(MultiRootDeviceBufferTest, WhenCleanAllGraphicsAllocationsCalledThenGraphicsAllocationsAreProperlyRemovedAccordingToIsParentObjectFlag) { AllocationInfoType allocationInfo; allocationInfo.resize(3u); allocationInfo[1u] = {}; allocationInfo[1u].memory = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{1u, MemoryConstants::pageSize}); - Buffer::cleanAllGraphicsAllocations(*context, *context->getMemoryManager(), allocationInfo, false); + bool isParentObject = true; + Buffer::cleanAllGraphicsAllocations(*context, *context->getMemoryManager(), allocationInfo, isParentObject); + EXPECT_EQ(mockMemoryManager->freeGraphicsMemoryCalled, 0u); + + isParentObject = false; + Buffer::cleanAllGraphicsAllocations(*context, *context->getMemoryManager(), allocationInfo, isParentObject); + EXPECT_EQ(mockMemoryManager->freeGraphicsMemoryCalled, 1u); } TEST_F(MultiRootDeviceBufferTest, WhenBufferIsCreatedThenBufferGraphicsAllocationHasCorrectRootDeviceIndex) { diff --git a/opencl/test/unit_test/mem_obj/image_tests.cpp b/opencl/test/unit_test/mem_obj/image_tests.cpp index 341da4aa39..d015ea2bbc 100644 --- a/opencl/test/unit_test/mem_obj/image_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_tests.cpp @@ -1764,3 +1764,54 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueReadImageCalledThe alignedFree(hostBuffer); } + +TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageCalledThenImagesMultiGraphicsAllocationLastUsedRootDeviceIndexHasCorrectRootDeviceIndex) { + REQUIRE_IMAGES_OR_SKIP(defaultHwInfo); + + cl_int retVal = 0; + + size_t height = 4; + size_t width = 4; + size_t region[] = {width * height, 1, 1}; + size_t orgin[] = {0, 0, 0}; + + cl_image_format format; + format.image_channel_order = CL_RGBA; + format.image_channel_data_type = CL_UNSIGNED_INT8; + + cl_image_desc desc{}; + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + desc.image_width = width * sizeof(unsigned int); + desc.image_height = height * sizeof(unsigned int); + + cl_mem_flags flags = CL_MEM_READ_WRITE; + + auto surfaceFormat = Image::getSurfaceFormatFromTable( + flags, &format, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + + std::unique_ptr image1(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal)); + std::unique_ptr image2(Image::create(context.get(), MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &desc, nullptr, retVal)); + + auto cmdQ1 = context->getSpecialQueue(1u); + cmdQ1->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + + cmdQ1->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + + auto cmdQ2 = context->getSpecialQueue(2u); + cmdQ2->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); + EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); + + cmdQ1->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + + static_cast(image1->getMigrateableMultiGraphicsAllocation().getGraphicsAllocation(2u))->overrideMemoryPool(MemoryPool::LocalMemory); + cmdQ2->enqueueCopyImage(image1.get(), image2.get(), orgin, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image1->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); + EXPECT_EQ(image2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); +}