Return error code from submit() to application.

Related-To: NEO-3741

Change-Id: I0e0ff6606eb6a8a77673949955c8e799689017b6
Signed-off-by: Pawel Wilma <pawel.wilma@intel.com>
This commit is contained in:
Pawel Wilma
2019-11-24 14:50:41 +01:00
committed by sys_ocldev
parent fe474379b2
commit 472a75912d
39 changed files with 187 additions and 77 deletions

2
Jenkinsfile vendored
View File

@@ -1,5 +1,5 @@
#!groovy
dependenciesRevision='9154d35827a517f6ae2e1e4fef470fc3026b79c7-1350'
strategy='EQUAL'
allowedCD=260
allowedCD=259
allowedF=7

View File

@@ -68,7 +68,7 @@ CommandQueue::CommandQueue(Context *context, Device *deviceId, const cl_queue_pr
if (device) {
gpgpuEngine = &device->getDefaultEngine();
if (getGpgpuCommandStreamReceiver().peekTimestampPacketWriteEnabled()) {
if (gpgpuEngine->commandStreamReceiver->peekTimestampPacketWriteEnabled()) {
timestampPacketContainer = std::make_unique<TimestampPacketContainer>();
}
if (device->getExecutionEnvironment()->getHardwareInfo()->capabilityTable.blitterOperationsSupported) {
@@ -86,7 +86,7 @@ CommandQueue::~CommandQueue() {
}
if (device) {
auto storageForAllocation = getGpgpuCommandStreamReceiver().getInternalAllocationStorage();
auto storageForAllocation = gpgpuEngine->commandStreamReceiver->getInternalAllocationStorage();
if (commandStream) {
storageForAllocation->storeAllocation(std::unique_ptr<GraphicsAllocation>(commandStream->getGraphicsAllocation()), REUSABLE_ALLOCATION);

View File

@@ -334,7 +334,7 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
cl_uint numEventsInWaitList,
const cl_event *eventWaitList);
CommandStreamReceiver &getGpgpuCommandStreamReceiver() const;
MOCKABLE_VIRTUAL CommandStreamReceiver &getGpgpuCommandStreamReceiver() const;
CommandStreamReceiver *getBcsCommandStreamReceiver() const;
Device &getDevice() const { return *device; }
Context &getContext() const { return *context; }

View File

@@ -13,7 +13,10 @@ namespace NEO {
template <typename GfxFamily>
cl_int CommandQueueHw<GfxFamily>::finish() {
getGpgpuCommandStreamReceiver().flushBatchedSubmissions();
auto result = getGpgpuCommandStreamReceiver().flushBatchedSubmissions();
if (!result) {
return CL_OUT_OF_RESOURCES;
}
//as long as queue is blocked we need to stall.
while (isQueueBlocked())

View File

@@ -10,7 +10,6 @@
namespace NEO {
template <typename GfxFamily>
cl_int CommandQueueHw<GfxFamily>::flush() {
getGpgpuCommandStreamReceiver().flushBatchedSubmissions();
return CL_SUCCESS;
return getGpgpuCommandStreamReceiver().flushBatchedSubmissions() ? CL_SUCCESS : CL_OUT_OF_RESOURCES;
}
} // namespace NEO

View File

@@ -37,7 +37,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::engineInfo;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::stream;
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
void makeNonResident(GraphicsAllocation &gfxAllocation) override;
void processResidency(const ResidencyContainer &allocationsForResidency) override;

View File

@@ -286,13 +286,13 @@ CommandStreamReceiver *AUBCommandStreamReceiverHw<GfxFamily>::create(const std::
}
template <typename GfxFamily>
FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
bool AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
if (subCaptureManager->isSubCaptureMode()) {
if (!subCaptureManager->isSubCaptureEnabled()) {
if (this->standalone) {
*this->tagAddress = this->peekLatestSentTaskCount();
}
return 0;
return true;
}
}
@@ -340,7 +340,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
}
getAubStream()->flush();
return 0;
return true;
}
template <typename GfxFamily>

View File

@@ -188,7 +188,9 @@ bool CommandStreamReceiver::waitForCompletionWithTimeout(bool enableTimeout, int
uint32_t latestSentTaskCount = this->latestFlushedTaskCount;
if (latestSentTaskCount < taskCountToWait) {
this->flushBatchedSubmissions();
if (!this->flushBatchedSubmissions()) {
return false;
}
}
time1 = std::chrono::high_resolution_clock::now();

View File

@@ -65,13 +65,13 @@ class CommandStreamReceiver {
CommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
virtual ~CommandStreamReceiver();
virtual FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) = 0;
virtual bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) = 0;
virtual CompletionStamp flushTask(LinearStream &commandStream, size_t commandStreamStart,
const IndirectHeap &dsh, const IndirectHeap &ioh, const IndirectHeap &ssh,
uint32_t taskLevel, DispatchFlags &dispatchFlags, Device &device) = 0;
virtual void flushBatchedSubmissions() = 0;
virtual bool flushBatchedSubmissions() = 0;
virtual void makeResident(GraphicsAllocation &gfxAllocation);
virtual void makeNonResident(GraphicsAllocation &gfxAllocation);

View File

@@ -30,13 +30,13 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
CommandStreamReceiverHw(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
CompletionStamp flushTask(LinearStream &commandStream, size_t commandStreamStart,
const IndirectHeap &dsh, const IndirectHeap &ioh, const IndirectHeap &ssh,
uint32_t taskLevel, DispatchFlags &dispatchFlags, Device &device) override;
void flushBatchedSubmissions() override;
bool flushBatchedSubmissions() override;
static void addBatchBufferEnd(LinearStream &commandStream, void **patchLocation);
void addBatchBufferStart(MI_BATCH_BUFFER_START *commandBufferMemory, uint64_t startAddress, bool secondary);

View File

@@ -56,8 +56,8 @@ CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiverHw(ExecutionEnvironment
}
template <typename GfxFamily>
FlushStamp CommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
return flushStamp->peekStamp();
bool CommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
return true;
}
template <typename GfxFamily>
@@ -455,7 +455,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
if (submitCSR | submitTask) {
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
flushStamp->setStamp(this->flush(batchBuffer, this->getResidencyAllocations()));
this->flush(batchBuffer, this->getResidencyAllocations());
this->latestFlushedTaskCount = this->taskCount + 1;
this->makeSurfacePackNonResident(this->getResidencyAllocations());
} else {
@@ -526,13 +526,14 @@ inline void CommandStreamReceiverHw<GfxFamily>::programStallingPipeControlForBar
}
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
inline bool CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
return;
return true;
}
typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START;
typedef typename GfxFamily::PIPE_CONTROL PIPE_CONTROL;
std::unique_lock<MutexType> lockGuard(ownershipMutex);
bool submitResult = true;
auto &commandBufferList = this->submissionAggregator->peekCmdBufferList();
if (!commandBufferList.peekIsEmpty()) {
@@ -600,20 +601,25 @@ inline void CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
}
((PIPE_CONTROL *)epiloguePipeControlLocation)->setDcFlushEnable(flushDcInEpilogue);
}
auto flushStamp = this->flush(primaryCmdBuffer->batchBuffer, surfacesForSubmit);
if (!this->flush(primaryCmdBuffer->batchBuffer, surfacesForSubmit)) {
submitResult = false;
break;
}
//after flush task level is closed
this->taskLevel++;
flushStampUpdateHelper.updateAll(flushStamp);
flushStampUpdateHelper.updateAll(flushStamp->peekStamp());
this->latestFlushedTaskCount = lastTaskCount;
this->flushStamp->setStamp(flushStamp);
this->makeSurfacePackNonResident(surfacesForSubmit);
resourcePackage.clear();
}
this->totalMemoryUsed = 0;
}
return submitResult;
}
template <typename GfxFamily>
@@ -839,7 +845,7 @@ uint32_t CommandStreamReceiverHw<GfxFamily>::blitBuffer(const BlitPropertiesCont
BatchBuffer batchBuffer{commandStream.getGraphicsAllocation(), commandStreamStart, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount,
commandStream.getUsed(), &commandStream};
flushStamp->setStamp(flush(batchBuffer, getResidencyAllocations()));
flush(batchBuffer, getResidencyAllocations());
makeSurfacePackNonResident(getResidencyAllocations());
latestFlushedTaskCount = newTaskCount;

View File

@@ -23,7 +23,7 @@ class CommandStreamReceiverWithAUBDump : public BaseCSR {
CommandStreamReceiverWithAUBDump(const CommandStreamReceiverWithAUBDump &) = delete;
CommandStreamReceiverWithAUBDump &operator=(const CommandStreamReceiverWithAUBDump &) = delete;
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
void makeNonResident(GraphicsAllocation &gfxAllocation) override;
AubSubCaptureStatus checkAndActivateAubSubCapture(const MultiDispatchInfo &dispatchInfo) override;

View File

@@ -27,13 +27,12 @@ CommandStreamReceiverWithAUBDump<BaseCSR>::CommandStreamReceiverWithAUBDump(cons
}
template <typename BaseCSR>
FlushStamp CommandStreamReceiverWithAUBDump<BaseCSR>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
bool CommandStreamReceiverWithAUBDump<BaseCSR>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
if (aubCSR) {
aubCSR->flush(batchBuffer, allocationsForResidency);
aubCSR->setLatestSentTaskCount(BaseCSR::peekLatestSentTaskCount());
}
FlushStamp flushStamp = BaseCSR::flush(batchBuffer, allocationsForResidency);
return flushStamp;
return BaseCSR::flush(batchBuffer, allocationsForResidency);
}
template <typename BaseCSR>

View File

@@ -49,7 +49,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::engineInfo;
using CommandStreamReceiverSimulatedCommonHw<GfxFamily>::stream;
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, bool forcePowerSavingMode) override;

View File

@@ -193,7 +193,7 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw<GfxFamily>::create(const std::
}
template <typename GfxFamily>
FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
bool TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
if (subCaptureManager) {
if (aubManager) {
aubManager->pause(false);
@@ -241,7 +241,7 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
subCaptureManager->disableSubCapture();
}
return 0;
return true;
}
template <typename GfxFamily>

View File

@@ -53,7 +53,7 @@ void FlushStampUpdateHelper::insert(FlushStampTrackingObj *stampObj) {
}
}
void FlushStampUpdateHelper::updateAll(FlushStamp &flushStamp) {
void FlushStampUpdateHelper::updateAll(const FlushStamp &flushStamp) {
for (const auto &stamp : flushStampsToUpdate) {
stamp->flushStamp = flushStamp;
stamp->initialized = true;

View File

@@ -39,7 +39,7 @@ class FlushStampTracker {
class FlushStampUpdateHelper {
public:
void insert(FlushStampTrackingObj *stampObj);
void updateAll(FlushStamp &flushStamp);
void updateAll(const FlushStamp &flushStamp);
size_t size() const;
private:

View File

@@ -37,7 +37,7 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
DrmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex,
gemCloseWorkerMode mode = gemCloseWorkerMode::gemCloseWorkerActive);
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
void makeResident(GraphicsAllocation &gfxAllocation) override;
void processResidency(const ResidencyContainer &allocationsForResidency) override;
void makeNonResident(GraphicsAllocation &gfxAllocation) override;

View File

@@ -10,6 +10,7 @@
#include "core/helpers/preamble.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/helpers/flush_stamp.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/os_interface/linux/drm_allocation.h"
#include "runtime/os_interface/linux/drm_buffer_object.h"
@@ -40,13 +41,13 @@ DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver(ExecutionEnvironme
}
template <typename GfxFamily>
FlushStamp DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
bool DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
DrmAllocation *alloc = static_cast<DrmAllocation *>(batchBuffer.commandBufferAllocation);
DEBUG_BREAK_IF(!alloc);
BufferObject *bb = alloc->getBO();
if (bb == nullptr) {
return 0;
return false;
}
if (this->lastSentSliceCount != batchBuffer.sliceCount) {
@@ -55,7 +56,7 @@ FlushStamp DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer,
}
}
FlushStamp flushStamp = bb->peekHandle();
this->flushStamp->setStamp(bb->peekHandle());
this->flushInternal(batchBuffer, allocationsForResidency);
if (this->gemCloseWorkerOperationMode == gemCloseWorkerMode::gemCloseWorkerActive) {
@@ -63,7 +64,7 @@ FlushStamp DrmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer,
this->getMemoryManager()->peekGemCloseWorker()->push(bb);
}
return flushStamp;
return true;
}
template <typename GfxFamily>

View File

@@ -765,7 +765,6 @@ bool Wddm::submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsCo
osContext.getResidencyController().getMonitoredFence().currentFenceValue++;
}
getDeviceState();
UNRECOVERABLE_IF(!status);
return status;
}

View File

@@ -24,7 +24,7 @@ class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily>
WddmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
virtual ~WddmCommandStreamReceiver();
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
void makeResident(GraphicsAllocation &gfxAllocation) override;
void processResidency(const ResidencyContainer &allocationsForResidency) override;
void processEviction() override;

View File

@@ -15,6 +15,7 @@
#include "runtime/device/device.h"
#include "runtime/gen_common/hw_cmds.h"
#include "runtime/gmm_helper/page_table_mngr.h"
#include "runtime/helpers/flush_stamp.h"
#include "runtime/helpers/gmm_callbacks.h"
#include "runtime/mem_obj/mem_obj.h"
#include "runtime/os_interface/windows/wddm/wddm.h"
@@ -25,6 +26,7 @@
#include "runtime/os_interface/windows/os_context_win.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/wddm_memory_manager.h"
namespace NEO {
// Initialize COMMAND_BUFFER_HEADER Type PatchList Streamer Perf Tag
@@ -61,7 +63,7 @@ WddmCommandStreamReceiver<GfxFamily>::~WddmCommandStreamReceiver() {
}
template <typename GfxFamily>
FlushStamp WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
bool WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
auto commandStreamAddress = ptrOffset(batchBuffer.commandBufferAllocation->getGpuAddress(), batchBuffer.startOffset);
if (this->dispatchMode == DispatchMode::ImmediateDispatch) {
@@ -95,9 +97,10 @@ FlushStamp WddmCommandStreamReceiver<GfxFamily>::flush(BatchBuffer &batchBuffer,
}
auto osContextWin = static_cast<OsContextWin *>(osContext);
wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, *osContextWin);
auto status = wddm->submit(commandStreamAddress, batchBuffer.usedSize - batchBuffer.startOffset, commandBufferHeader, *osContextWin);
return osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence;
flushStamp->setStamp(osContextWin->getResidencyController().getMonitoredFence().lastSubmittedFence);
return status;
}
template <typename GfxFamily>

View File

@@ -148,7 +148,10 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::Context *ctx, NEO::Device *devic
svmProps.readOnly = constant;
svmProps.hostPtrReadOnly = constant;
auto ptr = ctx->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), size, svmProps);
UNRECOVERABLE_IF(ptr == nullptr);
DEBUG_BREAK_IF(ptr == nullptr);
if (ptr == nullptr) {
return nullptr;
}
auto svmAlloc = ctx->getSVMAllocsManager()->getSVMAlloc(ptr);
UNRECOVERABLE_IF(svmAlloc == nullptr);
auto gpuAlloc = svmAlloc->gpuAllocation;
@@ -158,7 +161,10 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::Context *ctx, NEO::Device *devic
} else {
auto allocationType = constant ? GraphicsAllocation::AllocationType::CONSTANT_SURFACE : GraphicsAllocation::AllocationType::GLOBAL_SURFACE;
auto gpuAlloc = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({device->getRootDeviceIndex(), size, allocationType});
UNRECOVERABLE_IF(gpuAlloc == nullptr);
DEBUG_BREAK_IF(gpuAlloc == nullptr);
if (gpuAlloc == nullptr) {
return nullptr;
}
memcpy_s(gpuAlloc->getUnderlyingBuffer(), gpuAlloc->getUnderlyingBufferSize(), initData, size);
return gpuAlloc;
}

View File

@@ -341,4 +341,7 @@ class Program : public BaseObject<_cl_program> {
bool isBuiltIn;
bool kernelDebugEnabled = false;
};
GraphicsAllocation *allocateGlobalsSurface(NEO::Context *ctx, NEO::Device *device, size_t size, bool constant, bool globalsAreExported, const void *initData);
} // namespace NEO

View File

@@ -1272,3 +1272,35 @@ HWTEST_F(CommandQueueHwTest, givenSizeWhenForceStatelessIsCalledThenCorrectValue
uint64_t smallSize = bigSize - 1;
EXPECT_FALSE(pCmdQHw->forceStateless(static_cast<size_t>(smallSize)));
}
class MockCommandStreamReceiverWithFailingFlushBatchedSubmission : public MockCommandStreamReceiver {
public:
using MockCommandStreamReceiver::MockCommandStreamReceiver;
bool flushBatchedSubmissions() override {
return false;
}
};
template <typename GfxFamily>
struct MockCommandQueueHwWithOverwrittenCsr : public CommandQueueHw<GfxFamily> {
using CommandQueueHw<GfxFamily>::CommandQueueHw;
MockCommandStreamReceiverWithFailingFlushBatchedSubmission *csr;
CommandStreamReceiver &getGpgpuCommandStreamReceiver() const override { return *csr; }
};
HWTEST_F(CommandQueueHwTest, givenFlushWhenFlushBatchedSubmissionsFailsThenErrorIsRetured) {
MockCommandQueueHwWithOverwrittenCsr<FamilyType> cmdQueue(context, device, nullptr);
MockCommandStreamReceiverWithFailingFlushBatchedSubmission csr(*pDevice->executionEnvironment, 0);
cmdQueue.csr = &csr;
cl_int errorCode = cmdQueue.flush();
EXPECT_EQ(CL_OUT_OF_RESOURCES, errorCode);
}
HWTEST_F(CommandQueueHwTest, givenFinishWhenFlushBatchedSubmissionsFailsThenErrorIsRetured) {
MockCommandQueueHwWithOverwrittenCsr<FamilyType> cmdQueue(context, device, nullptr);
MockCommandStreamReceiverWithFailingFlushBatchedSubmission csr(*pDevice->executionEnvironment, 0);
cmdQueue.csr = &csr;
cl_int errorCode = cmdQueue.finish();
EXPECT_EQ(CL_OUT_OF_RESOURCES, errorCode);
}

View File

@@ -34,7 +34,7 @@ class CommandStreamReceiverMock : public UltCommandStreamReceiver<FamilyType> {
this->pDevice = pDevice;
}
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
EXPECT_NE(nullptr, batchBuffer.commandBufferAllocation->getUnderlyingBuffer());
toFree.push_back(batchBuffer.commandBufferAllocation);
@@ -43,7 +43,7 @@ class CommandStreamReceiverMock : public UltCommandStreamReceiver<FamilyType> {
EXPECT_TRUE(this->ownershipMutex.try_lock());
this->ownershipMutex.unlock();
return 0;
return true;
}
~CommandStreamReceiverMock() override {

View File

@@ -769,9 +769,9 @@ struct CommandStreamReceiverHwLog : public UltCommandStreamReceiver<FamilyType>
flushCount(0) {
}
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
++flushCount;
return 0;
return true;
}
int flushCount;

View File

@@ -20,6 +20,7 @@
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_event.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_os_context.h"
#include "unit_tests/mocks/mock_program.h"
#include "unit_tests/mocks/mock_submissions_aggregator.h"
@@ -1616,3 +1617,29 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, whenPerDssBackBufferProgrammingEna
EXPECT_EQ(0u, commandStreamReceiver.createPerDssBackedBufferCalled);
}
template <typename GfxFamily>
class MockCsrWithFailingFlush : public CommandStreamReceiverHw<GfxFamily> {
public:
using CommandStreamReceiverHw<GfxFamily>::latestSentTaskCount;
using CommandStreamReceiverHw<GfxFamily>::submissionAggregator;
MockCsrWithFailingFlush(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) : CommandStreamReceiverHw<GfxFamily>(executionEnvironment, rootDeviceIndex) {
this->dispatchMode = DispatchMode::BatchedDispatch;
this->tagAddress = &tag;
}
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
return false;
}
uint32_t tag = 0;
};
HWTEST_F(CommandStreamReceiverFlushTaskTests, givenWaitForCompletionWithTimeoutIsCalledWhenFlushBatchedSubmissionsReturnsFailureThenItIsPropagated) {
MockCsrWithFailingFlush<FamilyType> mockCsr(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex());
MockOsContext osContext(0, 8, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false);
mockCsr.setupContext(osContext);
mockCsr.latestSentTaskCount = 0;
auto cmdBuffer = std::make_unique<CommandBuffer>(*pDevice);
mockCsr.submissionAggregator->recordCommandBuffer(cmdBuffer.release());
EXPECT_FALSE(mockCsr.waitForCompletionWithTimeout(false, 0, 1));
}

View File

@@ -583,8 +583,9 @@ HWTEST_P(CommandStreamReceiverWithAubSubCaptureTest, givenCommandStreamReceiverW
void initProgrammingFlags() override {
initProgrammingFlagsCalled = true;
}
void flushBatchedSubmissions() override {
bool flushBatchedSubmissions() override {
flushBatchedSubmissionsCalled = true;
return true;
}
bool initProgrammingFlagsCalled = false;
bool flushBatchedSubmissionsCalled = false;

View File

@@ -12,6 +12,7 @@
#include "runtime/command_stream/tbx_command_stream_receiver_hw.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/dispatch_info.h"
#include "runtime/helpers/flush_stamp.h"
#include "runtime/os_interface/os_context.h"
#include "runtime/platform/platform.h"
#include "test.h"
@@ -30,13 +31,14 @@ struct MyMockCsr : UltCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> {
: UltCommandStreamReceiver(executionEnvironment, rootDeviceIndex) {
}
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
flushParametrization.wasCalled = true;
flushParametrization.receivedBatchBuffer = &batchBuffer;
flushParametrization.receivedEngine = osContext->getEngineType();
flushParametrization.receivedAllocationsForResidency = &allocationsForResidency;
processResidency(allocationsForResidency);
return flushParametrization.flushStampToReturn;
flushStamp->setStamp(flushParametrization.flushStampToReturn);
return true;
}
void makeResident(GraphicsAllocation &gfxAllocation) override {
@@ -243,8 +245,8 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub
auto engineType = csrWithAubDump->getOsContext().getEngineType();
ResidencyContainer allocationsForResidency;
FlushStamp flushStamp = csrWithAubDump->flush(batchBuffer, allocationsForResidency);
EXPECT_EQ(flushStamp, csrWithAubDump->flushParametrization.flushStampToReturn);
csrWithAubDump->flush(batchBuffer, allocationsForResidency);
EXPECT_EQ(csrWithAubDump->obtainCurrentFlushStamp(), csrWithAubDump->flushParametrization.flushStampToReturn);
EXPECT_TRUE(csrWithAubDump->flushParametrization.wasCalled);
EXPECT_EQ(&batchBuffer, csrWithAubDump->flushParametrization.receivedBatchBuffer);
@@ -288,8 +290,8 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub
ASSERT_NE(nullptr, gfxAllocation);
ResidencyContainer allocationsForResidency = {gfxAllocation};
FlushStamp flushStamp = csrWithAubDump->flush(batchBuffer, allocationsForResidency);
EXPECT_EQ(flushStamp, csrWithAubDump->flushParametrization.flushStampToReturn);
csrWithAubDump->flush(batchBuffer, allocationsForResidency);
EXPECT_EQ(csrWithAubDump->obtainCurrentFlushStamp(), csrWithAubDump->flushParametrization.flushStampToReturn);
EXPECT_TRUE(csrWithAubDump->processResidencyParameterization.wasCalled);
EXPECT_EQ(&allocationsForResidency, csrWithAubDump->processResidencyParameterization.receivedAllocationsForResidency);

View File

@@ -131,6 +131,7 @@ HWTEST_F(TbxCommandStreamTests, DISABLED_flushUntilTailRingBufferLargerThanSizeR
pCommandStreamReceiver->flush(batchBuffer, pCommandStreamReceiver->getResidencyAllocations());
auto size = tbxCsr->engineInfo.sizeRingBuffer;
tbxCsr->engineInfo.sizeRingBuffer = 64;
pCommandStreamReceiver->flush(batchBuffer, pCommandStreamReceiver->getResidencyAllocations());
pCommandStreamReceiver->flush(batchBuffer, pCommandStreamReceiver->getResidencyAllocations());
pCommandStreamReceiver->flush(batchBuffer, pCommandStreamReceiver->getResidencyAllocations());

View File

@@ -485,8 +485,8 @@ class CommandStreamReceiverMock : public CommandStreamReceiver {
}
}
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
return flushStamp->peekStamp();
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
return true;
}
void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, bool forcePowerSavingMode) override {
@@ -506,7 +506,7 @@ class CommandStreamReceiverMock : public CommandStreamReceiver {
return cs;
}
void flushBatchedSubmissions() override {}
bool flushBatchedSubmissions() override { return true; }
CommandStreamReceiverType getType() override {
return CommandStreamReceiverType::CSR_HW;

View File

@@ -93,7 +93,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
BaseClass::makeSurfacePackNonResident(allocationsForResidency);
}
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
if (recordFlusheBatchBuffer) {
latestFlushedBatchBuffer = batchBuffer;
}
@@ -161,9 +161,9 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
aubCommentMessages.push_back(message);
addAubCommentCalled = true;
}
void flushBatchedSubmissions() override {
CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions();
bool flushBatchedSubmissions() override {
flushBatchedSubmissionsCalled = true;
return CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions();
}
void initProgrammingFlags() override {
CommandStreamReceiverHw<GfxFamily>::initProgrammingFlags();

View File

@@ -1920,3 +1920,28 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenGetReservedMemoryIsCalledManyTimes
memoryManager.getReservedMemory(MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
EXPECT_EQ(reservedMemory, memoryManager.reservedMemory);
}
class MemoryManagerWithFailure : public MockMemoryManager {
public:
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override {
return nullptr;
}
};
TEST(MemoryManagerTest, whenMemoryManagerReturnsNullptrThenAllocateGlobalsSurfaceAlsoReturnsNullptr) {
MockDevice device;
std::unique_ptr<MemoryManager> memoryManager(new MemoryManagerWithFailure());
device.injectMemoryManager(memoryManager.release());
MockContext context(&device, true);
delete context.svmAllocsManager;
context.svmAllocsManager = nullptr;
GraphicsAllocation *allocation = allocateGlobalsSurface(&context, &device, 1024, false, true, nullptr);
EXPECT_EQ(nullptr, allocation);
context.svmAllocsManager = new SVMAllocsManager(device.getMemoryManager());
allocation = allocateGlobalsSurface(&context, &device, 1024, false, true, nullptr);
EXPECT_EQ(nullptr, allocation);
}

View File

@@ -75,8 +75,9 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
this->latestSentTaskCount = latestSentTaskCount;
}
void flushBatchedSubmissions() override {
bool flushBatchedSubmissions() override {
flushBatchedSubmissionsCalled = true;
return true;
}
void initProgrammingFlags() override {
initProgrammingFlagsCalled = true;

View File

@@ -9,9 +9,8 @@
#include "runtime/os_interface/os_interface.h"
FlushStamp MockCommandStreamReceiver::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
FlushStamp stamp = 0;
return stamp;
bool MockCommandStreamReceiver::flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) {
return true;
}
CompletionStamp MockCommandStreamReceiver::flushTask(

View File

@@ -114,8 +114,8 @@ class MockCsr : public MockCsrBase<GfxFamily> {
MockCsr(int32_t &execStamp, ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) : BaseClass(execStamp, executionEnvironment, rootDeviceIndex) {
}
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
return 0;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
return true;
}
CompletionStamp flushTask(
@@ -185,12 +185,12 @@ class MockCsrHw2 : public CommandStreamReceiverHw<GfxFamily> {
bool peekMediaVfeStateDirty() const { return mediaVfeStateDirty; }
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override {
flushCalledCount++;
recordedCommandBuffer->batchBuffer = batchBuffer;
copyOfAllocations = allocationsForResidency;
flushStamp->setStamp(flushStamp->peekStamp() + 1);
return flushStamp->peekStamp();
return true;
}
CompletionStamp flushTask(LinearStream &commandStream, size_t commandStreamStart,
@@ -265,7 +265,7 @@ class MockCommandStreamReceiver : public CommandStreamReceiver {
waitForCompletionWithTimeoutCalled++;
return true;
}
FlushStamp flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool flush(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency) override;
bool isMultiOsContextCapable() const { return multiOsContextCapable; }
@@ -279,10 +279,11 @@ class MockCommandStreamReceiver : public CommandStreamReceiver {
DispatchFlags &dispatchFlags,
Device &device) override;
void flushBatchedSubmissions() override {
bool flushBatchedSubmissions() override {
if (flushBatchedSubmissionsCallCounter) {
(*flushBatchedSubmissionsCallCounter)++;
}
return true;
}
void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, bool forcePowerSavingMode) override {

View File

@@ -171,8 +171,8 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTest, Flush) {
CommandStreamReceiverHw<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs};
auto availableSpacePriorToFlush = cs.getAvailableSpace();
auto flushStamp = csr->flush(batchBuffer, csr->getResidencyAllocations());
EXPECT_EQ(static_cast<uint64_t>(boHandle), flushStamp);
csr->flush(batchBuffer, csr->getResidencyAllocations());
EXPECT_EQ(static_cast<uint64_t>(boHandle), csr->obtainCurrentFlushStamp());
EXPECT_NE(cs.getCpuBase(), nullptr);
EXPECT_EQ(availableSpacePriorToFlush, cs.getAvailableSpace());
}

View File

@@ -183,11 +183,11 @@ TEST_F(WddmCommandStreamTest, Flush) {
ASSERT_NE(nullptr, commandBuffer);
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs};
auto flushStamp = csr->flush(batchBuffer, csr->getResidencyAllocations());
csr->flush(batchBuffer, csr->getResidencyAllocations());
EXPECT_EQ(1u, wddm->submitResult.called);
EXPECT_TRUE(wddm->submitResult.success);
EXPECT_EQ(flushStamp, static_cast<OsContextWin &>(csr->getOsContext()).getResidencyController().getMonitoredFence().lastSubmittedFence);
EXPECT_EQ(csr->obtainCurrentFlushStamp(), static_cast<OsContextWin &>(csr->getOsContext()).getResidencyController().getMonitoredFence().lastSubmittedFence);
memoryManager->freeGraphicsMemory(commandBuffer);
}