From e789375cd58ce25ee85e34ec8bd8fa0d0294dc58 Mon Sep 17 00:00:00 2001 From: Krzysztof Gibala Date: Mon, 14 Dec 2020 11:47:58 +0000 Subject: [PATCH] Enable memory transfer in enqueueCopyBufferToImage Related-To: NEO-4589 Signed-off-by: Krzysztof Gibala --- .../enqueue_copy_buffer_to_image.h | 5 ++ opencl/test/unit_test/mem_obj/image_tests.cpp | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/opencl/source/command_queue/enqueue_copy_buffer_to_image.h b/opencl/source/command_queue/enqueue_copy_buffer_to_image.h index d86aa5f283..8f9d85c514 100644 --- a/opencl/source/command_queue/enqueue_copy_buffer_to_image.h +++ b/opencl/source/command_queue/enqueue_copy_buffer_to_image.h @@ -31,6 +31,11 @@ cl_int CommandQueueHw::enqueueCopyBufferToImage( const cl_event *eventWaitList, cl_event *event) { + auto rootDeviceIndex = getDevice().getRootDeviceIndex(); + + srcBuffer->getMigrateableMultiGraphicsAllocation().ensureMemoryOnDevice(*getDevice().getMemoryManager(), rootDeviceIndex); + dstImage->getMigrateableMultiGraphicsAllocation().ensureMemoryOnDevice(*getDevice().getMemoryManager(), rootDeviceIndex); + auto eBuiltInOpsType = EBuiltInOps::CopyBufferToImage3d; if (forceStateless(srcBuffer->getSize())) { eBuiltInOpsType = EBuiltInOps::CopyBufferToImage3dStateless; diff --git a/opencl/test/unit_test/mem_obj/image_tests.cpp b/opencl/test/unit_test/mem_obj/image_tests.cpp index b72916a110..9abbad1614 100644 --- a/opencl/test/unit_test/mem_obj/image_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_tests.cpp @@ -1866,3 +1866,54 @@ TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyImageToBufferC EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); } + +TEST_F(ImageMultiRootDeviceTests, WhenImageIsCreatedAndEnqueueCopyBufferToImageCalledThenImageAndBufferMultiGraphicsAllocationsLastUsedRootDeviceIndexHasCorrectRootDeviceIndex) { + 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 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::create(context.get(), flags, MemoryConstants::pageSize, nullptr, retVal)); + + auto cmdQ1 = context->getSpecialQueue(1u); + cmdQ1->enqueueCopyBufferToImage(buffer.get(), image.get(), 0, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + + cmdQ1->enqueueCopyBufferToImage(buffer.get(), image.get(), 0, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + + auto cmdQ2 = context->getSpecialQueue(2u); + cmdQ2->enqueueCopyBufferToImage(buffer.get(), image.get(), 0, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); + EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); + + cmdQ1->enqueueCopyBufferToImage(buffer.get(), image.get(), 0, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); + + static_cast(image->getMigrateableMultiGraphicsAllocation().getGraphicsAllocation(2u))->overrideMemoryPool(MemoryPool::LocalMemory); + cmdQ2->enqueueCopyBufferToImage(buffer.get(), image.get(), 0, orgin, region, 0, nullptr, nullptr); + EXPECT_EQ(image->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); + EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); +}