Skip to content

Commit

Permalink
Fix zeroCopy property for images
Browse files Browse the repository at this point in the history
- zeroCopy means no need for data transfer when cpu transfer is
chosen during map/unmap operations
- tests cleanup

Change-Id: Id312267e51d593781c6fe536b6e96f42f32e5c02
  • Loading branch information
HoppeMateusz authored and Compute-Runtime-Automation committed Aug 23, 2018
1 parent 9ac3529 commit aaf2f94
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 387 deletions.
4 changes: 3 additions & 1 deletion runtime/mem_obj/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ Image *Image::create(Context *context,
}
} else {
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, gmm);
zeroCopy = true;
if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {
zeroCopy = true;
}
}
}
transferNeeded |= !!(flags & CL_MEM_COPY_HOST_PTR);
Expand Down
11 changes: 10 additions & 1 deletion runtime/memory_manager/os_agnostic_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,16 @@ void OsAgnosticMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
}
}
GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) {
auto alloc = allocateGraphicsMemory(imgInfo.size);
GraphicsAllocation *alloc = nullptr;
if (!GmmHelper::allowTiling(*imgInfo.imgDesc) && imgInfo.mipCount == 0) {
alloc = allocateGraphicsMemory(imgInfo.size);
} else {
auto ptr = allocateSystemMemory(alignUp(imgInfo.size, MemoryConstants::pageSize), MemoryConstants::pageSize);
if (ptr != nullptr) {
alloc = new MemoryAllocation(true, ptr, reinterpret_cast<uint64_t>(ptr), imgInfo.size, counter, MemoryPool::SystemCpuInaccessible);
counter++;
}
}
if (alloc) {
alloc->gmm = gmm;
}
Expand Down
202 changes: 30 additions & 172 deletions unit_tests/command_queue/enqueue_read_image_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,61 +298,6 @@ HWTEST_F(EnqueueReadImageTest, GivenImage1DAndImageShareTheSameStorageWithHostPt
EXPECT_EQ(pCmdOOQ->taskLevel, 0u);
}

HWTEST_F(EnqueueReadImageTest, GivenImage2DAndImageShareTheSameStorageWithHostPtrWhenReadReadImageIsCalledThenImageIsNotRead) {
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Image> dstImage2(Image2dHelper<>::create(context));
auto imageDesc = dstImage2->getImageDesc();
size_t origin[] = {0, 0, 0};
size_t region[] = {imageDesc.image_width, imageDesc.image_height, 1};
void *ptr = dstImage2->getCpuAddressForMemoryTransfer();

size_t rowPitch = dstImage2->getHostPtrRowPitch();
size_t slicePitch = dstImage2->getHostPtrSlicePitch();
retVal = pCmdQ->enqueueReadImage(dstImage2.get(),
CL_FALSE,
origin,
region,
rowPitch,
slicePitch,
ptr,
0,
nullptr,
nullptr);

EXPECT_EQ(CL_SUCCESS, retVal);

EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(pCmdQ->taskLevel, 0u);
}

HWTEST_F(EnqueueReadImageTest, GivenImage3DAndImageShareTheSameStorageWithHostPtrWhenReadReadImageIsCalledThenImageIsNotRead) {
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Image> dstImage2(Image3dHelper<>::create(context));
auto imageDesc = dstImage2->getImageDesc();
std::unique_ptr<CommandQueue> pCmdOOQ(createCommandQueue(pDevice, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE));
size_t origin[] = {0, 0, 0};
size_t region[] = {imageDesc.image_width, imageDesc.image_height, imageDesc.image_depth};
void *ptr = dstImage2->getCpuAddressForMemoryTransfer();

size_t rowPitch = dstImage2->getHostPtrRowPitch();
size_t slicePitch = dstImage2->getHostPtrSlicePitch();
retVal = pCmdOOQ->enqueueReadImage(dstImage2.get(),
CL_FALSE,
origin,
region,
rowPitch,
slicePitch,
ptr,
0,
nullptr,
nullptr);

EXPECT_EQ(CL_SUCCESS, retVal);

EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(pCmdOOQ->taskLevel, 0u);
}

HWTEST_F(EnqueueReadImageTest, GivenImage1DArrayAndImageShareTheSameStorageWithHostPtrWhenReadReadImageIsCalledThenImageIsNotRead) {
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Image> dstImage2(Image1dArrayHelper<>::create(context));
Expand Down Expand Up @@ -382,157 +327,70 @@ HWTEST_F(EnqueueReadImageTest, GivenImage1DArrayAndImageShareTheSameStorageWithH
EXPECT_EQ(pCmdQ->taskLevel, 0u);
}

HWTEST_F(EnqueueReadImageTest, GivenImage2DArrayAndImageShareTheSameStorageWithHostPtrWhenReadReadImageIsCalledThenImageIsNotRead) {
HWTEST_F(EnqueueReadImageTest, GivenSharedContextZeroCopy2DImageWhenEnqueueReadImageWithMappedPointerIsCalledThenImageIsNotRead) {
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Image> dstImage2(Image2dArrayHelper<>::create(context));
auto imageDesc = dstImage2->getImageDesc();
std::unique_ptr<CommandQueue> pCmdOOQ(createCommandQueue(pDevice, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE));
size_t origin[] = {0, 0, 0};
size_t region[] = {imageDesc.image_width, imageDesc.image_height, imageDesc.image_array_size};
void *ptr = dstImage2->getCpuAddressForMemoryTransfer();
size_t rowPitch = dstImage2->getHostPtrRowPitch();
size_t slicePitch = dstImage2->getHostPtrSlicePitch();
retVal = pCmdOOQ->enqueueReadImage(dstImage2.get(),
CL_FALSE,
origin,
region,
rowPitch,
slicePitch,
ptr,
0,
nullptr,
nullptr);
context->isSharedContext = true;

EXPECT_EQ(CL_SUCCESS, retVal);
std::unique_ptr<Image> dstImage(ImageHelper<ImageUseHostPtr<Image2dDefaults>>::create(context));
EXPECT_TRUE(dstImage->isMemObjZeroCopy());

EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(pCmdOOQ->taskLevel, 0u);
}

HWTEST_F(EnqueueReadImageTest, GivenImage2DAndImageShareTheSameStorageWithHostPtrAndEventsWhenReadReadImageIsCalledThenImageIsNotRead) {
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Image> dstImage2(Image2dHelper<>::create(context));
auto imageDesc = dstImage2->getImageDesc();
auto imageDesc = dstImage->getImageDesc();
size_t origin[] = {0, 0, 0};
size_t region[] = {imageDesc.image_width, imageDesc.image_height, 1};
void *ptr = dstImage2->getCpuAddressForMemoryTransfer();
void *ptr = dstImage->getCpuAddressForMemoryTransfer();

size_t rowPitch = dstImage2->getHostPtrRowPitch();
size_t slicePitch = dstImage2->getHostPtrSlicePitch();
uint32_t taskLevelCmdQ = 17;
pCmdQ->taskLevel = taskLevelCmdQ;

uint32_t taskLevelEvent1 = 8;
uint32_t taskLevelEvent2 = 19;
Event event1(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, taskLevelEvent1, 4);
Event event2(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, taskLevelEvent2, 10);

cl_event eventWaitList[] =
{
&event1,
&event2};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
cl_event event = nullptr;

retVal = pCmdQ->enqueueReadImage(dstImage2.get(),
size_t rowPitch = dstImage->getHostPtrRowPitch();
size_t slicePitch = dstImage->getHostPtrSlicePitch();
retVal = pCmdQ->enqueueReadImage(dstImage.get(),
CL_FALSE,
origin,
region,
rowPitch,
slicePitch,
ptr,
numEventsInWaitList,
eventWaitList,
&event);
0,
nullptr,
nullptr);

EXPECT_EQ(CL_SUCCESS, retVal);

EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, event);

auto pEvent = (Event *)event;
EXPECT_EQ(19u, pEvent->taskLevel);
EXPECT_EQ(19u, pCmdQ->taskLevel);
EXPECT_EQ(CL_COMMAND_READ_IMAGE, (const int)pEvent->getCommandType());

pEvent->release();
EXPECT_EQ(pCmdQ->taskLevel, 0u);
}

HWTEST_F(EnqueueReadImageTest, GivenImage3DAndImageShareTheSameStorageWithHostPtrAndEventsWhenReadReadImageIsCalledThenImageIsNotRead) {
HWTEST_F(EnqueueReadImageTest, GivenImage1DThatIsZeroCopyWhenReadImageWithTheSamePointerAndOutputEventIsPassedThenEventHasCorrectCommandTypeSet) {
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Image> dstImage2(Image3dHelper<>::create(context));
auto imageDesc = dstImage2->getImageDesc();
std::unique_ptr<CommandQueue> pCmdOOQ(createCommandQueue(pDevice, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE));
std::unique_ptr<Image> dstImage(Image1dHelper<>::create(context));
auto imageDesc = dstImage->getImageDesc();
size_t origin[] = {0, 0, 0};
size_t region[] = {imageDesc.image_width, imageDesc.image_height, imageDesc.image_depth};
void *ptr = dstImage2->getCpuAddressForMemoryTransfer();

size_t rowPitch = dstImage2->getHostPtrRowPitch();
size_t slicePitch = dstImage2->getHostPtrSlicePitch();

uint32_t taskLevelCmdQ = 17;
pCmdOOQ->taskLevel = taskLevelCmdQ;

uint32_t taskLevelEvent1 = 8;
uint32_t taskLevelEvent2 = 19;
Event event1(pCmdOOQ.get(), CL_COMMAND_NDRANGE_KERNEL, taskLevelEvent1, 4);
Event event2(pCmdOOQ.get(), CL_COMMAND_NDRANGE_KERNEL, taskLevelEvent2, 10);
size_t region[] = {imageDesc.image_width, imageDesc.image_height, 1};
void *ptr = dstImage->getCpuAddressForMemoryTransfer();
size_t rowPitch = dstImage->getHostPtrRowPitch();
size_t slicePitch = dstImage->getHostPtrSlicePitch();

cl_event eventWaitList[] =
{
&event1,
&event2};
cl_uint numEventsInWaitList = sizeof(eventWaitList) / sizeof(eventWaitList[0]);
cl_uint numEventsInWaitList = 0;
cl_event event = nullptr;

retVal = pCmdOOQ->enqueueReadImage(dstImage2.get(),
CL_FALSE,
origin,
region,
rowPitch,
slicePitch,
ptr,
numEventsInWaitList,
eventWaitList,
&event);

EXPECT_EQ(CL_SUCCESS, retVal);

EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, event);

auto pEvent = (Event *)event;
EXPECT_EQ(19u, pEvent->taskLevel);
EXPECT_EQ(19u, pCmdOOQ->taskLevel);
EXPECT_EQ(CL_COMMAND_READ_IMAGE, (const int)pEvent->getCommandType());

pEvent->release();
}
HWTEST_F(EnqueueReadImageTest, GivenNonZeroCopyImage2DAndImageShareTheSameStorageWithHostPtrWhenReadReadImageIsCalledThenImageIsRead) {
cl_int retVal = CL_SUCCESS;
std::unique_ptr<Image> dstImage2(ImageHelper<ImageUseHostPtr<Image2dDefaults>>::create(context));
auto imageDesc = dstImage2->getImageDesc();
size_t origin[] = {0, 0, 0};
size_t region[] = {imageDesc.image_width, imageDesc.image_height, 1};
void *ptr = dstImage2->getCpuAddressForMemoryTransfer();

size_t rowPitch = dstImage2->getHostPtrRowPitch();
size_t slicePitch = dstImage2->getHostPtrSlicePitch();
retVal = pCmdQ->enqueueReadImage(dstImage2.get(),
retVal = pCmdQ->enqueueReadImage(dstImage.get(),
CL_FALSE,
origin,
region,
rowPitch,
slicePitch,
ptr,
0,
numEventsInWaitList,
nullptr,
nullptr);
&event);

EXPECT_EQ(CL_SUCCESS, retVal);

EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(pCmdQ->taskLevel, 2u);
ASSERT_NE(nullptr, event);

auto pEvent = static_cast<Event *>(event);
EXPECT_EQ(static_cast<cl_command_type>(CL_COMMAND_READ_IMAGE), pEvent->getCommandType());

pEvent->release();
}

HWTEST_F(EnqueueReadImageTest, givenCommandQueueWhenEnqueueReadImageIsCalledThenItCallsNotifyFunction) {
Expand Down
Loading

0 comments on commit aaf2f94

Please sign in to comment.