2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-25 17:20:32 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "runtime/command_queue/command_queue_hw.h"
|
2019-04-08 20:49:35 +08:00
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
2019-01-25 17:20:32 +08:00
|
|
|
#include "unit_tests/libult/ult_command_stream_receiver.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MockCommandQueue - Core implementation
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
class MockCommandQueue : public CommandQueue {
|
|
|
|
public:
|
|
|
|
using CommandQueue::device;
|
2019-07-15 20:28:09 +08:00
|
|
|
using CommandQueue::gpgpuEngine;
|
2019-02-12 17:35:22 +08:00
|
|
|
using CommandQueue::multiEngineQueue;
|
2018-10-03 05:37:30 +08:00
|
|
|
using CommandQueue::obtainNewTimestampPacketNodes;
|
2019-02-11 00:50:54 +08:00
|
|
|
using CommandQueue::requiresCacheFlushAfterWalker;
|
2018-11-16 19:46:49 +08:00
|
|
|
using CommandQueue::throttle;
|
2018-10-03 05:37:30 +08:00
|
|
|
using CommandQueue::timestampPacketContainer;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setProfilingEnabled() {
|
|
|
|
commandQueueProperties |= CL_QUEUE_PROFILING_ENABLE;
|
|
|
|
}
|
2018-09-26 06:44:43 +08:00
|
|
|
void setOoqEnabled() {
|
|
|
|
commandQueueProperties |= CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
MockCommandQueue() : CommandQueue(nullptr, nullptr, 0) {}
|
|
|
|
MockCommandQueue(Context *context, Device *device, const cl_queue_properties *props)
|
|
|
|
: CommandQueue(context, device, props) {
|
|
|
|
}
|
|
|
|
|
2018-08-24 14:48:59 +08:00
|
|
|
LinearStream &getCS(size_t minRequiredSize) override {
|
|
|
|
requestedCmdStreamSize = minRequiredSize;
|
|
|
|
return CommandQueue::getCS(minRequiredSize);
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void releaseIndirectHeap(IndirectHeap::Type heap) override {
|
|
|
|
releaseIndirectHeapCalled = true;
|
|
|
|
CommandQueue::releaseIndirectHeap(heap);
|
|
|
|
}
|
2018-07-24 15:06:33 +08:00
|
|
|
|
|
|
|
cl_int enqueueWriteBuffer(Buffer *buffer, cl_bool blockingWrite, size_t offset, size_t size, const void *ptr,
|
2019-04-08 20:49:35 +08:00
|
|
|
GraphicsAllocation *mapAllocation, cl_uint numEventsInWaitList, const cl_event *eventWaitList,
|
|
|
|
cl_event *event) override {
|
2018-07-24 15:06:33 +08:00
|
|
|
writeBufferCounter++;
|
|
|
|
writeBufferBlocking = (CL_TRUE == blockingWrite);
|
|
|
|
writeBufferOffset = offset;
|
|
|
|
writeBufferSize = size;
|
|
|
|
writeBufferPtr = const_cast<void *>(ptr);
|
|
|
|
return writeBufferRetValue;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool releaseIndirectHeapCalled = false;
|
2018-07-24 15:06:33 +08:00
|
|
|
|
|
|
|
cl_int writeBufferRetValue = CL_SUCCESS;
|
|
|
|
uint32_t writeBufferCounter = 0;
|
|
|
|
bool writeBufferBlocking = false;
|
|
|
|
size_t writeBufferOffset = 0;
|
|
|
|
size_t writeBufferSize = 0;
|
|
|
|
void *writeBufferPtr = nullptr;
|
2018-08-24 14:48:59 +08:00
|
|
|
size_t requestedCmdStreamSize = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
|
|
|
|
typedef CommandQueueHw<GfxFamily> BaseClass;
|
|
|
|
|
|
|
|
public:
|
2019-07-16 15:23:02 +08:00
|
|
|
using BaseClass::bcsEngine;
|
2018-09-11 15:43:06 +08:00
|
|
|
using BaseClass::commandStream;
|
2019-07-15 20:28:09 +08:00
|
|
|
using BaseClass::gpgpuEngine;
|
2019-02-21 23:59:10 +08:00
|
|
|
using BaseClass::multiEngineQueue;
|
2019-07-19 03:15:50 +08:00
|
|
|
using BaseClass::obtainCommandStream;
|
2018-10-03 05:37:30 +08:00
|
|
|
using BaseClass::obtainNewTimestampPacketNodes;
|
2019-02-21 23:59:10 +08:00
|
|
|
using BaseClass::requiresCacheFlushAfterWalker;
|
2018-10-03 05:37:30 +08:00
|
|
|
using BaseClass::timestampPacketContainer;
|
2018-02-28 19:09:48 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
MockCommandQueueHw(Context *context,
|
|
|
|
Device *device,
|
|
|
|
cl_queue_properties *properties) : BaseClass(context, device, properties) {
|
|
|
|
}
|
|
|
|
|
2019-01-25 17:20:32 +08:00
|
|
|
UltCommandStreamReceiver<GfxFamily> &getUltCommandStreamReceiver() {
|
2019-07-15 20:28:09 +08:00
|
|
|
return reinterpret_cast<UltCommandStreamReceiver<GfxFamily> &>(*BaseClass::gpgpuEngine->commandStreamReceiver);
|
2019-01-25 17:20:32 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_int enqueueWriteImage(Image *dstImage,
|
|
|
|
cl_bool blockingWrite,
|
|
|
|
const size_t *origin,
|
|
|
|
const size_t *region,
|
|
|
|
size_t inputRowPitch,
|
|
|
|
size_t inputSlicePitch,
|
|
|
|
const void *ptr,
|
2019-04-16 00:17:28 +08:00
|
|
|
GraphicsAllocation *mapAllocation,
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_uint numEventsInWaitList,
|
|
|
|
const cl_event *eventWaitList,
|
|
|
|
cl_event *event) override {
|
|
|
|
EnqueueWriteImageCounter++;
|
|
|
|
return BaseClass::enqueueWriteImage(dstImage,
|
|
|
|
blockingWrite,
|
|
|
|
origin,
|
|
|
|
region,
|
|
|
|
inputRowPitch,
|
|
|
|
inputSlicePitch,
|
|
|
|
ptr,
|
2019-04-16 00:17:28 +08:00
|
|
|
mapAllocation,
|
2017-12-21 07:45:38 +08:00
|
|
|
numEventsInWaitList,
|
|
|
|
eventWaitList,
|
|
|
|
event);
|
|
|
|
}
|
2019-04-03 19:15:07 +08:00
|
|
|
void *cpuDataTransferHandler(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &retVal) override {
|
|
|
|
cpuDataTransferHandlerCalled = true;
|
|
|
|
return BaseClass::cpuDataTransferHandler(transferProperties, eventsRequest, retVal);
|
|
|
|
}
|
2018-02-01 20:40:30 +08:00
|
|
|
cl_int enqueueWriteBuffer(Buffer *buffer, cl_bool blockingWrite, size_t offset, size_t size,
|
2019-04-08 20:49:35 +08:00
|
|
|
const void *ptr, GraphicsAllocation *mapAllocation, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override {
|
2018-02-01 20:40:30 +08:00
|
|
|
EnqueueWriteBufferCounter++;
|
|
|
|
blockingWriteBuffer = blockingWrite == CL_TRUE;
|
2019-04-08 20:49:35 +08:00
|
|
|
return BaseClass::enqueueWriteBuffer(buffer, blockingWrite, offset, size, ptr, mapAllocation, numEventsInWaitList, eventWaitList, event);
|
2018-02-01 20:40:30 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void enqueueHandlerHook(const unsigned int commandType, const MultiDispatchInfo &dispatchInfo) override {
|
|
|
|
lastCommandType = commandType;
|
|
|
|
for (auto &di : dispatchInfo) {
|
|
|
|
lastEnqueuedKernels.push_back(di.getKernel());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 00:41:52 +08:00
|
|
|
void notifyEnqueueReadBuffer(Buffer *buffer, bool blockingRead) override {
|
|
|
|
notifyEnqueueReadBufferCalled = true;
|
|
|
|
}
|
|
|
|
void notifyEnqueueReadImage(Image *image, bool blockingRead) override {
|
|
|
|
notifyEnqueueReadImageCalled = true;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
unsigned int lastCommandType;
|
|
|
|
std::vector<Kernel *> lastEnqueuedKernels;
|
|
|
|
size_t EnqueueWriteImageCounter = 0;
|
2018-02-01 20:40:30 +08:00
|
|
|
size_t EnqueueWriteBufferCounter = 0;
|
|
|
|
bool blockingWriteBuffer = false;
|
2018-08-23 00:41:52 +08:00
|
|
|
bool notifyEnqueueReadBufferCalled = false;
|
|
|
|
bool notifyEnqueueReadImageCalled = false;
|
2019-04-03 19:15:07 +08:00
|
|
|
bool cpuDataTransferHandlerCalled = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
LinearStream *peekCommandStream() {
|
|
|
|
return this->commandStream;
|
|
|
|
}
|
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|