Do not take ownership on device.

- Command Stream Receiver should be used instead for locking.
- Remove not needed synchronization in clSetUserEventStatus

Change-Id: I17050dc70cb0be03b2003043a9666ba8df1a83c9
This commit is contained in:
Mrozek, Michal
2018-08-06 14:55:04 +02:00
committed by sys_ocldev
parent 44fbbaee24
commit d80dbb1ae0
11 changed files with 24 additions and 19 deletions

View File

@@ -1801,8 +1801,7 @@ cl_int CL_API_CALL clSetUserEventStatus(cl_event event,
return retVal;
}
TakeOwnershipWrapper<Device> deviceOwnership(*userEvent->getContext()->getDevice(0));
auto commandStreamReceiverOwnership = userEvent->getContext()->getDevice(0)->getCommandStreamReceiver().obtainUniqueOwnership();
userEvent->setStatus(executionStatus);
return retVal;
}

View File

@@ -21,6 +21,7 @@
*/
#include "runtime/command_queue/command_queue.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/event/event_builder.h"
@@ -64,7 +65,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
*eventsRequest.outEvent = outEventObj;
}
TakeOwnershipWrapper<Device> deviceOwnership(*device);
auto commandStreamReceieverOwnership = device->getCommandStreamReceiver().obtainUniqueOwnership();
TakeOwnershipWrapper<CommandQueue> queueOwnership(*this);
auto blockQueue = false;
@@ -81,7 +82,6 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
(transferProperties.cmdType == CL_COMMAND_MAP_BUFFER ||
transferProperties.cmdType == CL_COMMAND_MAP_IMAGE ||
transferProperties.cmdType == CL_COMMAND_UNMAP_MEM_OBJECT)) {
// Pass size and offset only. Unblocked command will call transferData(size, offset) method
enqueueBlockedMapUnmapOperation(eventsRequest.eventWaitList,
static_cast<size_t>(eventsRequest.numEventsInWaitList),
@@ -94,7 +94,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie
}
queueOwnership.unlock();
deviceOwnership.unlock();
commandStreamReceieverOwnership.unlock();
// read/write buffers are always blocking
if (!blockQueue || transferProperties.blocking) {

View File

@@ -159,8 +159,8 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
DeviceQueueHw<GfxFamily> *devQueueHw = castToObject<DeviceQueueHw<GfxFamily>>(devQueue);
HwTimeStamps *hwTimeStamps = nullptr;
TakeOwnershipWrapper<Device> deviceOwnership(*device);
auto &commandStreamReceiver = device->getCommandStreamReceiver();
auto commandStreamRecieverOwnership = commandStreamReceiver.obtainUniqueOwnership();
TimeStampData queueTimeStamp;
if (isProfilingEnabled() && event) {
@@ -197,7 +197,6 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
auto &commandStream = getCommandStream<GfxFamily, commandType>(*this, profilingRequired, perfCountersRequired, multiDispatchInfo);
auto commandStreamStart = commandStream.getUsed();
auto &commandStreamReceiver = device->getCommandStreamReceiver();
DBG_LOG(EventsDebugEnable, "blockQueue", blockQueue, "virtualEvent", virtualEvent, "taskLevel", taskLevel);
@@ -413,7 +412,7 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
}
queueOwnership.unlock();
deviceOwnership.unlock();
commandStreamRecieverOwnership.unlock();
if (blocking) {
if (blockQueue) {

View File

@@ -239,9 +239,9 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
auto memoryManager = getDevice().getMemoryManager();
DEBUG_BREAK_IF(nullptr == memoryManager);
TakeOwnershipWrapper<Device> deviceOwnership(getDevice());
auto commandStreamReceieverOwnership = device->getCommandStreamReceiver().obtainUniqueOwnership();
auto patternAllocation = memoryManager->obtainReusableAllocation(patternSize, false).release();
deviceOwnership.unlock();
commandStreamReceieverOwnership.unlock();
if (!patternAllocation) {
patternAllocation = memoryManager->allocateGraphicsMemory(patternSize);

View File

@@ -363,4 +363,8 @@ bool CommandStreamReceiver::initializeTagAllocation() {
return true;
}
std::unique_lock<CommandStreamReceiver::MutexType> CommandStreamReceiver::obtainUniqueOwnership() {
return std::unique_lock<CommandStreamReceiver::MutexType>(this->ownershipMutex);
}
} // namespace OCLRT

View File

@@ -59,6 +59,7 @@ class CommandStreamReceiver {
samplerCacheFlushBefore, //add sampler cache flush before Walker with redescribed image
samplerCacheFlushAfter //add sampler cache flush after Walker with redescribed image
};
using MutexType = std::recursive_mutex;
CommandStreamReceiver();
virtual ~CommandStreamReceiver();
@@ -143,6 +144,7 @@ class CommandStreamReceiver {
void setExperimentalCmdBuffer(std::unique_ptr<ExperimentalCommandBuffer> &&cmdBuffer);
bool initializeTagAllocation();
std::unique_lock<MutexType> obtainUniqueOwnership();
KmdNotifyHelper *peekKmdNotifyHelper() {
return kmdNotifyHelper.get();
@@ -199,6 +201,7 @@ class CommandStreamReceiver {
IndirectHeap *indirectHeap[IndirectHeap::NUM_TYPES];
std::unique_ptr<FlatBatchBufferHelper> flatBatchBufferHelper;
std::unique_ptr<ExperimentalCommandBuffer> experimentalCmdBuffer;
MutexType ownershipMutex;
std::unique_ptr<KmdNotifyHelper> kmdNotifyHelper;
};

View File

@@ -481,7 +481,7 @@ inline void CommandStreamReceiverHw<GfxFamily>::flushBatchedSubmissions() {
typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START;
typedef typename GfxFamily::PIPE_CONTROL PIPE_CONTROL;
Device *device = this->getMemoryManager()->device;
TakeOwnershipWrapper<Device> deviceOwnership(*device);
std::unique_lock<MutexType> lockGuard(ownershipMutex);
EngineType engineType = device->getEngineType();
auto &commandBufferList = this->submissionAggregator->peekCmdBufferList();

View File

@@ -64,8 +64,7 @@ CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) {
}
bool blocking = true;
TakeOwnershipWrapper<Device> deviceOwnership(cmdQ.getDevice());
auto commandStreamReceiverOwnership = csr.obtainUniqueOwnership();
auto &queueCommandStream = cmdQ.getCS(0);
size_t offset = queueCommandStream.getUsed();
@@ -146,7 +145,7 @@ CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminate
bool executionModelKernel = kernel->isParentKernel;
auto devQueue = commandQueue.getContext().getDefaultDeviceQueue();
TakeOwnershipWrapper<Device> deviceOwnership(commandQueue.getDevice());
auto commandStreamReceiverOwnership = commandStreamReceiver.obtainUniqueOwnership();
if (executionModelKernel) {
while (!devQueue->isEMCriticalSectionFree())

View File

@@ -66,9 +66,8 @@ HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenFinishIsCalledThenBatchesS
//call a flush while other threads enqueue, we can't drop anything
while (currentTaskCount < enqueueCount * threadCount) {
clFlush(pCmdQ);
pCmdQ->getDevice().takeOwnership(true);
auto locker = mockCsr->obtainUniqueOwnership();
currentTaskCount = mockCsr->peekTaskCount();
pCmdQ->getDevice().releaseOwnership();
}
for (auto &thread : threads) {

View File

@@ -55,7 +55,8 @@ class CommandStreamReceiverMock : public UltCommandStreamReceiver<FamilyType> {
batchBuffer.stream->replaceBuffer(nullptr, 0);
batchBuffer.stream->replaceGraphicsAllocation(nullptr);
EXPECT_TRUE(pDevice->hasOwnership());
EXPECT_TRUE(this->ownershipMutex.try_lock());
this->ownershipMutex.unlock();
return 0;
}

View File

@@ -1074,7 +1074,8 @@ TEST_F(EventTests, givenUserEventWhenSetStatusIsDoneThenDeviceMutextisAcquired)
struct mockedEvent : public UserEvent {
using UserEvent::UserEvent;
bool setStatus(cl_int status) override {
mutexProperlyAcquired = this->getContext()->getDevice(0)->hasOwnership();
auto commandStreamReceiverOwnership = this->getContext()->getDevice(0)->getCommandStreamReceiver().obtainUniqueOwnership();
mutexProperlyAcquired = commandStreamReceiverOwnership.owns_lock();
return true;
}
bool mutexProperlyAcquired = false;