Skip to content

Commit 33e1b3a

Browse files
Command stream receiver: handle flush method failure when flushing BCS task
Related-To: NEO-7412 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 27d0421 commit 33e1b3a

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

shared/source/command_stream/command_stream_receiver.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -928,4 +928,15 @@ LogicalStateHelper *CommandStreamReceiver::getLogicalStateHelper() const {
928928
return logicalStateHelper.get();
929929
}
930930

931+
uint32_t CompletionStamp::getTaskCountFromSubmissionStatusError(SubmissionStatus status) {
932+
switch (status) {
933+
case SubmissionStatus::OUT_OF_HOST_MEMORY:
934+
return CompletionStamp::outOfHostMemory;
935+
case SubmissionStatus::OUT_OF_MEMORY:
936+
return CompletionStamp::outOfDeviceMemory;
937+
default:
938+
return 0;
939+
}
940+
}
941+
931942
} // namespace NEO

shared/source/command_stream/command_stream_receiver_hw_base.inl

+4-1
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,10 @@ uint32_t CommandStreamReceiverHw<GfxFamily>::flushBcsTask(const BlitPropertiesCo
11641164
commandStream.getGraphicsAllocation()->updateTaskCount(newTaskCount, this->osContext->getContextId());
11651165
commandStream.getGraphicsAllocation()->updateResidencyTaskCount(newTaskCount, this->osContext->getContextId());
11661166

1167-
flush(batchBuffer, getResidencyAllocations());
1167+
auto flushSubmissionStatus = flush(batchBuffer, getResidencyAllocations());
1168+
if (flushSubmissionStatus != SubmissionStatus::SUCCESS) {
1169+
return CompletionStamp::getTaskCountFromSubmissionStatusError(flushSubmissionStatus);
1170+
}
11681171
makeSurfacePackNonResident(getResidencyAllocations(), true);
11691172

11701173
if (updateTag) {

shared/source/helpers/completion_stamp.h

+3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
namespace NEO {
1313
using FlushStamp = uint64_t;
14+
enum class SubmissionStatus : uint32_t;
1415
struct CompletionStamp {
16+
static uint32_t getTaskCountFromSubmissionStatusError(SubmissionStatus submissionStatus);
17+
1518
uint32_t taskCount;
1619
uint32_t taskLevel;
1720
FlushStamp flushStamp;

shared/test/common/libult/ult_command_stream_receiver.h

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
163163
}
164164

165165
NEO::SubmissionStatus flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
166+
if (flushReturnValue) {
167+
return *flushReturnValue;
168+
}
166169
if (recordFlusheBatchBuffer) {
167170
latestFlushedBatchBuffer = batchBuffer;
168171
}
@@ -393,6 +396,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
393396
std::optional<WaitStatus> waitForTaskCountWithKmdNotifyFallbackReturnValue{};
394397
bool callBaseFlushBcsTask{true};
395398
uint32_t flushBcsTaskReturnValue{};
399+
std::optional<SubmissionStatus> flushReturnValue{};
396400
};
397401

398402
} // namespace NEO

shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -2320,4 +2320,28 @@ HWTEST_F(CommandStreamReceiverHwTest, givenSshHeapNotProvidedWhenFlushTaskPerfor
23202320
*pDevice);
23212321

23222322
EXPECT_FALSE(scratchController->setRequiredScratchSpaceCalled);
2323+
}
2324+
2325+
TEST(CommandStreamReceiverSimpleTest, whenTranslatingSubmissionStatusToTaskCountValueThenProperValueIsReturned) {
2326+
EXPECT_EQ(0u, CompletionStamp::getTaskCountFromSubmissionStatusError(SubmissionStatus::SUCCESS));
2327+
EXPECT_EQ(CompletionStamp::outOfHostMemory, CompletionStamp::getTaskCountFromSubmissionStatusError(SubmissionStatus::OUT_OF_HOST_MEMORY));
2328+
EXPECT_EQ(CompletionStamp::outOfDeviceMemory, CompletionStamp::getTaskCountFromSubmissionStatusError(SubmissionStatus::OUT_OF_MEMORY));
2329+
}
2330+
2331+
HWTEST_F(CommandStreamReceiverHwTest, givenFailureOnFlushWhenFlushingBcsTaskThenErrorIsPropagated) {
2332+
auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver<FamilyType>();
2333+
2334+
auto blitProperties = BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::BufferToHostPtr,
2335+
commandStreamReceiver, commandStreamReceiver.getTagAllocation(), nullptr,
2336+
commandStreamReceiver.getTagAllocation()->getUnderlyingBuffer(),
2337+
commandStreamReceiver.getTagAllocation()->getGpuAddress(), 0,
2338+
0, 0, 0, 0, 0, 0, 0);
2339+
2340+
BlitPropertiesContainer container;
2341+
container.push_back(blitProperties);
2342+
2343+
commandStreamReceiver.flushReturnValue = SubmissionStatus::OUT_OF_HOST_MEMORY;
2344+
EXPECT_EQ(CompletionStamp::outOfHostMemory, commandStreamReceiver.flushBcsTask(container, true, false, *pDevice));
2345+
commandStreamReceiver.flushReturnValue = SubmissionStatus::OUT_OF_MEMORY;
2346+
EXPECT_EQ(CompletionStamp::outOfDeviceMemory, commandStreamReceiver.flushBcsTask(container, true, false, *pDevice));
23232347
}

0 commit comments

Comments
 (0)