Skip to content

Commit f6f9c0f

Browse files
committed
Add notify functions to enqueue read buffer and image calls
This commit adds notifications to enqueue read buffer and image calls and setters/getters to mark/check if an allocation is dumpable. Change-Id: I123f24752d2a86abcf934e0d404f4e0ecf1729cc
1 parent b91c14f commit f6f9c0f

File tree

9 files changed

+66
-0
lines changed

9 files changed

+66
-0
lines changed

runtime/command_queue/command_queue_hw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class CommandQueueHw : public CommandQueue {
7676
return new CommandQueueHw<GfxFamily>(context, device, properties);
7777
}
7878

79+
MOCKABLE_VIRTUAL void notifyEnqueueReadBuffer(Buffer *buffer, bool blockingRead);
80+
MOCKABLE_VIRTUAL void notifyEnqueueReadImage(Image *image, bool blockingRead);
81+
7982
cl_int enqueueBarrierWithWaitList(cl_uint numEventsInWaitList,
8083
const cl_event *eventWaitList,
8184
cl_event *event) override;

runtime/command_queue/command_queue_hw.inl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@
4141
#include "runtime/command_queue/enqueue_write_image.h"
4242
#include "runtime/command_queue/finish.h"
4343
#include "runtime/command_queue/flush.h"
44+
45+
namespace OCLRT {
46+
template <typename Family>
47+
void CommandQueueHw<Family>::notifyEnqueueReadBuffer(Buffer *buffer, bool blockingRead) {
48+
}
49+
template <typename Family>
50+
void CommandQueueHw<Family>::notifyEnqueueReadImage(Image *image, bool blockingRead) {
51+
}
52+
} // namespace OCLRT

runtime/command_queue/enqueue_read_buffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
4545
const cl_event *eventWaitList,
4646
cl_event *event) {
4747

48+
notifyEnqueueReadBuffer(buffer, !!blockingRead);
49+
4850
cl_int retVal = CL_SUCCESS;
4951
bool isMemTransferNeeded = buffer->isMemObjZeroCopy() ? buffer->checkIfMemoryTransferIsRequired(offset, 0, ptr, CL_COMMAND_READ_BUFFER) : true;
5052
if ((DebugManager.flags.DoCpuCopyOnReadBuffer.get() ||

runtime/command_queue/enqueue_read_image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadImage(
5050
const cl_event *eventWaitList,
5151
cl_event *event) {
5252

53+
notifyEnqueueReadImage(srcImage, !!blockingRead);
54+
5355
MultiDispatchInfo di;
5456
auto isMemTransferNeeded = true;
5557
if (srcImage->isMemObjZeroCopy()) {

runtime/memory_manager/graphics_allocation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
136136

137137
void setAubWritable(bool writable) { aubWritable = writable; }
138138
bool isAubWritable() const { return aubWritable; }
139+
void setAllocDumpable(bool dumpable) { allocDumpable = dumpable; }
140+
bool isAllocDumpable() const { return allocDumpable; }
139141
bool isMemObjectsAllocationWithWritableFlags() const { return memObjectsAllocationWithWritableFlags; }
140142
void setMemObjectsAllocationWithWritableFlags(bool newValue) { memObjectsAllocationWithWritableFlags = newValue; }
141143

@@ -160,6 +162,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
160162
uint32_t inspectionId = 0;
161163
AllocationType allocationType = AllocationType::UNKNOWN;
162164
bool aubWritable = true;
165+
bool allocDumpable = false;
163166
bool memObjectsAllocationWithWritableFlags = false;
164167
};
165168
} // namespace OCLRT

unit_tests/command_queue/enqueue_read_buffer_tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "unit_tests/command_queue/enqueue_read_buffer_fixture.h"
3131
#include "unit_tests/helpers/debug_manager_state_restore.h"
3232
#include "unit_tests/helpers/unit_test_helper.h"
33+
#include "unit_tests/mocks/mock_command_queue.h"
3334
#include "test.h"
3435

3536
using namespace OCLRT;
@@ -451,6 +452,22 @@ HWTEST_F(EnqueueReadBufferTypeTest, givenInOrderQueueAndEnabledSupportCpuCopiesA
451452
EXPECT_EQ(pCmdQ->taskLevel, 1u);
452453
}
453454

455+
HWTEST_F(EnqueueReadBufferTypeTest, givenCommandQueueWhenEnqueueReadBufferIsCalledThenItCallsNotifyFunction) {
456+
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
457+
void *ptr = nonZeroCopyBuffer->getCpuAddressForMemoryTransfer();
458+
auto retVal = mockCmdQ->enqueueReadBuffer(srcBuffer.get(),
459+
CL_TRUE,
460+
0,
461+
MemoryConstants::cacheLineSize,
462+
ptr,
463+
0,
464+
nullptr,
465+
nullptr);
466+
467+
EXPECT_EQ(CL_SUCCESS, retVal);
468+
EXPECT_TRUE(mockCmdQ->notifyEnqueueReadBufferCalled);
469+
}
470+
454471
using NegativeFailAllocationTest = Test<NegativeFailAllocationCommandEnqueueBaseFixture>;
455472

456473
HWTEST_F(NegativeFailAllocationTest, givenEnqueueReadBufferWhenHostPtrAllocationCreationFailsThenReturnOutOfResource) {

unit_tests/command_queue/enqueue_read_image_tests.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include "unit_tests/command_queue/enqueue_read_image_fixture.h"
2626
#include "unit_tests/gen_common/gen_commands_common_validation.h"
2727
#include "unit_tests/helpers/unit_test_helper.h"
28+
#include "unit_tests/helpers/debug_manager_state_restore.h"
2829
#include "unit_tests/mocks/mock_builtin_dispatch_info_builder.h"
30+
#include "unit_tests/mocks/mock_command_queue.h"
2931
#include "test.h"
3032

3133
using namespace OCLRT;
@@ -533,6 +535,18 @@ HWTEST_F(EnqueueReadImageTest, GivenNonZeroCopyImage2DAndImageShareTheSameStorag
533535
EXPECT_EQ(pCmdQ->taskLevel, 2u);
534536
}
535537

538+
HWTEST_F(EnqueueReadImageTest, givenCommandQueueWhenEnqueueReadImageIsCalledThenItCallsNotifyFunction) {
539+
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
540+
std::unique_ptr<Image> srcImage(Image2dArrayHelper<>::create(context));
541+
auto imageDesc = srcImage->getImageDesc();
542+
size_t origin[] = {0, 0, 0};
543+
size_t region[] = {imageDesc.image_width, imageDesc.image_height, imageDesc.image_array_size};
544+
545+
EnqueueReadImageHelper<>::enqueueReadImage(mockCmdQ.get(), srcImage.get(), CL_TRUE, origin, region);
546+
547+
EXPECT_TRUE(mockCmdQ->notifyEnqueueReadImageCalled);
548+
}
549+
536550
typedef EnqueueReadImageMipMapTest MipMapReadImageTest;
537551

538552
HWTEST_P(MipMapReadImageTest, GivenImageWithMipLevelNonZeroWhenReadImageIsCalledThenProperMipLevelIsSet) {

unit_tests/mem_obj/mem_obj_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,10 @@ TEST(MemObj, givenNotSharedMemObjectWhenChangingGfxAllocationThenOldAllocationIs
481481

482482
EXPECT_EQ(newGfxAllocation, memObj.getGraphicsAllocation());
483483
}
484+
485+
TEST(MemObj, givenGraphicsAllocationWhenCallingIsAllocDumpableThenItReturnsTheCorrectValue) {
486+
GraphicsAllocation gfxAllocation(nullptr, 0);
487+
EXPECT_FALSE(gfxAllocation.isAllocDumpable());
488+
gfxAllocation.setAllocDumpable(true);
489+
EXPECT_TRUE(gfxAllocation.isAllocDumpable());
490+
}

unit_tests/mocks/mock_command_queue.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,20 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
114114
}
115115
}
116116

117+
void notifyEnqueueReadBuffer(Buffer *buffer, bool blockingRead) override {
118+
notifyEnqueueReadBufferCalled = true;
119+
}
120+
void notifyEnqueueReadImage(Image *image, bool blockingRead) override {
121+
notifyEnqueueReadImageCalled = true;
122+
}
123+
117124
unsigned int lastCommandType;
118125
std::vector<Kernel *> lastEnqueuedKernels;
119126
size_t EnqueueWriteImageCounter = 0;
120127
size_t EnqueueWriteBufferCounter = 0;
121128
bool blockingWriteBuffer = false;
129+
bool notifyEnqueueReadBufferCalled = false;
130+
bool notifyEnqueueReadImageCalled = false;
122131

123132
LinearStream *peekCommandStream() {
124133
return this->commandStream;

0 commit comments

Comments
 (0)