Aux translation [4/n]: Lock BuiltIn Kernel + refactor BuiltIns locking

Change-Id: Ic7dc9b86a4aa5f93f1c4bcdf80b9598ecdff9713
Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz 2018-08-13 12:24:17 +02:00 committed by sys_ocldev
parent d3d8b6f905
commit a5950500a3
21 changed files with 152 additions and 77 deletions

View File

@ -224,20 +224,6 @@ Program *BuiltIns::createBuiltInProgram(
return pBuiltInProgram; return pBuiltInProgram;
} }
void BuiltinDispatchInfoBuilder::takeOwnership(Context *context) {
for (auto &k : usedKernels) {
k->takeOwnership(true);
k->setContext(context);
}
}
void BuiltinDispatchInfoBuilder::releaseOwnership() {
for (auto &k : usedKernels) {
k->setContext(nullptr);
k->releaseOwnership();
}
}
template <typename HWFamily> template <typename HWFamily>
class BuiltInOp<HWFamily, EBuiltInOps::CopyBufferToBuffer> : public BuiltinDispatchInfoBuilder { class BuiltInOp<HWFamily, EBuiltInOps::CopyBufferToBuffer> : public BuiltinDispatchInfoBuilder {
public: public:
@ -827,4 +813,24 @@ std::unique_ptr<BuiltinDispatchInfoBuilder> BuiltIns::setBuiltinDispatchInfoBuil
return builder; return builder;
} }
BuiltInOwnershipWrapper::BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
takeOwnership(inputBuilder, context);
}
BuiltInOwnershipWrapper::~BuiltInOwnershipWrapper() {
if (builder) {
for (auto &kernel : builder->peekUsedKernels()) {
kernel->setContext(nullptr);
kernel->releaseOwnership();
}
}
}
void BuiltInOwnershipWrapper::takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
UNRECOVERABLE_IF(builder);
builder = &inputBuilder;
for (auto &kernel : builder->peekUsedKernels()) {
kernel->takeOwnership(true);
kernel->setContext(context);
}
}
} // namespace OCLRT } // namespace OCLRT

View File

@ -22,6 +22,7 @@
#pragma once #pragma once
#include "CL/cl.h" #include "CL/cl.h"
#include "runtime/helpers/properties_helper.h"
#include "runtime/built_ins/sip.h" #include "runtime/built_ins/sip.h"
#include "runtime/utilities/vec.h" #include "runtime/utilities/vec.h"
@ -238,6 +239,18 @@ class BuiltIns {
bool enableCacheing = true; bool enableCacheing = true;
}; };
class BuiltInOwnershipWrapper : public NonCopyableOrMovableClass {
public:
BuiltInOwnershipWrapper() = default;
BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context);
~BuiltInOwnershipWrapper();
void takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context);
protected:
BuiltinDispatchInfoBuilder *builder = nullptr;
};
template <typename HWFamily, EBuiltInOps OpCode> template <typename HWFamily, EBuiltInOps OpCode>
class BuiltInOp; class BuiltInOp;

View File

@ -90,8 +90,7 @@ class BuiltinDispatchInfoBuilder {
return true; return true;
} }
void takeOwnership(Context *context); std::vector<std::unique_ptr<Kernel>> &peekUsedKernels() { return usedKernels; }
void releaseOwnership();
protected: protected:
template <typename KernelNameT, typename... KernelsDescArgsT> template <typename KernelNameT, typename... KernelsDescArgsT>

View File

@ -78,6 +78,7 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface *(&surfaces)[surfaceCount
if (kernel == nullptr) { if (kernel == nullptr) {
enqueueHandler<commandType>(surfaces, blocking, MultiDispatchInfo(), numEventsInWaitList, eventWaitList, event); enqueueHandler<commandType>(surfaces, blocking, MultiDispatchInfo(), numEventsInWaitList, eventWaitList, event);
} else { } else {
BuiltInOwnershipWrapper builtInLock;
MultiDispatchInfo multiDispatchInfo; MultiDispatchInfo multiDispatchInfo;
if (DebugManager.flags.ForceDispatchScheduler.get()) { if (DebugManager.flags.ForceDispatchScheduler.get()) {
@ -85,6 +86,8 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface *(&surfaces)[surfaceCount
} else { } else {
BuffersForAuxTranslation buffersForAuxTranslation; BuffersForAuxTranslation buffersForAuxTranslation;
if (kernel->isAuxTranslationRequired()) { if (kernel->isAuxTranslationRequired()) {
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::AuxTranslation, getContext(), getDevice());
builtInLock.takeOwnership(builder, this->context);
kernel->fillWithBuffersForAuxTranslation(buffersForAuxTranslation); kernel->fillWithBuffersForAuxTranslation(buffersForAuxTranslation);
dispatchAuxTranslation(multiDispatchInfo, buffersForAuxTranslation, AuxTranslationDirection::AuxToNonAux); dispatchAuxTranslation(multiDispatchInfo, buffersForAuxTranslation, AuxTranslationDirection::AuxToNonAux);
} }

View File

@ -48,7 +48,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBuffer(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltinDispatchInfoBuilder::BuiltinOpParams dc; BuiltinDispatchInfoBuilder::BuiltinOpParams dc;
dc.srcMemObj = srcBuffer; dc.srcMemObj = srcBuffer;
@ -70,8 +70,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBuffer(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -50,7 +50,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBufferRect(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferRect, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferRect,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
MemObjSurface srcBufferSurf(srcBuffer); MemObjSurface srcBufferSurf(srcBuffer);
MemObjSurface dstBufferSurf(dstBuffer); MemObjSurface dstBufferSurf(dstBuffer);
@ -76,8 +76,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBufferRect(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -50,7 +50,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBufferToImage(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToImage3d, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToImage3d,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
MemObjSurface srcBufferSurf(srcBuffer); MemObjSurface srcBufferSurf(srcBuffer);
MemObjSurface dstImgSurf(dstImage); MemObjSurface dstImgSurf(dstImage);
@ -75,8 +75,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBufferToImage(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -50,7 +50,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImage(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImageToImage3d, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImageToImage3d,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
MemObjSurface srcImgSurf(srcImage); MemObjSurface srcImgSurf(srcImage);
MemObjSurface dstImgSurf(dstImage); MemObjSurface dstImgSurf(dstImage);
@ -78,8 +78,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImage(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -50,7 +50,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImageToBuffer(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImage3dToBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImage3dToBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
MemObjSurface srcImgSurf(srcImage); MemObjSurface srcImgSurf(srcImage);
MemObjSurface dstBufferSurf(dstBuffer); MemObjSurface dstBufferSurf(dstBuffer);
@ -75,8 +75,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImageToBuffer(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -64,7 +64,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillBuffer(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::FillBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::FillBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltinDispatchInfoBuilder::BuiltinOpParams dc; BuiltinDispatchInfoBuilder::BuiltinOpParams dc;
MemObj patternMemObj(this->context, 0, 0, alignUp(patternSize, 4), patternAllocation->getUnderlyingBuffer(), MemObj patternMemObj(this->context, 0, 0, alignUp(patternSize, 4), patternAllocation->getUnderlyingBuffer(),
@ -89,8 +89,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillBuffer(
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(patternAllocation), TEMPORARY_ALLOCATION, taskCount); memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(patternAllocation), TEMPORARY_ALLOCATION, taskCount);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -49,7 +49,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillImage(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::FillImage3d, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::FillImage3d,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
MemObjSurface dstImgSurf(image); MemObjSurface dstImgSurf(image);
Surface *surfaces[] = {&dstImgSurf}; Surface *surfaces[] = {&dstImgSurf};
@ -70,8 +70,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillImage(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -94,7 +94,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
} }
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
void *dstPtr = ptr; void *dstPtr = ptr;
@ -105,7 +105,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
if (size != 0) { if (size != 0) {
bool status = createAllocationForHostSurface(hostPtrSurf); bool status = createAllocationForHostSurface(hostPtrSurf);
if (!status) { if (!status) {
builder.releaseOwnership();
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
} }
dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch()); dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
@ -131,7 +130,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
numEventsInWaitList, numEventsInWaitList,
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }

View File

@ -79,7 +79,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBufferRect(
} }
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferRect, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferRect,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
size_t hostPtrSize = Buffer::calculateHostPtrSize(hostOrigin, region, hostRowPitch, hostSlicePitch); size_t hostPtrSize = Buffer::calculateHostPtrSize(hostOrigin, region, hostRowPitch, hostSlicePitch);
void *dstPtr = ptr; void *dstPtr = ptr;
@ -93,7 +93,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBufferRect(
region[2] != 0) { region[2] != 0) {
bool status = createAllocationForHostSurface(hostPtrSurf); bool status = createAllocationForHostSurface(hostPtrSurf);
if (!status) { if (!status) {
builder.releaseOwnership();
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
} }
dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch()); dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
@ -119,8 +118,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBufferRect(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
if (context->isProvidingPerformanceHints()) { if (context->isProvidingPerformanceHints()) {
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_READ_BUFFER_RECT_REQUIRES_COPY_DATA, static_cast<cl_mem>(buffer), ptr); context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_READ_BUFFER_RECT_REQUIRES_COPY_DATA, static_cast<cl_mem>(buffer), ptr);
if (!isL3Capable(ptr, hostPtrSize)) { if (!isL3Capable(ptr, hostPtrSize)) {

View File

@ -82,7 +82,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadImage(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImage3dToBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImage3dToBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
size_t hostPtrSize = calculateHostPtrSizeForImage(const_cast<size_t *>(region), inputRowPitch, inputSlicePitch, srcImage); size_t hostPtrSize = calculateHostPtrSizeForImage(const_cast<size_t *>(region), inputRowPitch, inputSlicePitch, srcImage);
void *dstPtr = ptr; void *dstPtr = ptr;
@ -96,7 +96,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadImage(
region[2] != 0) { region[2] != 0) {
bool status = createAllocationForHostSurface(hostPtrSurf); bool status = createAllocationForHostSurface(hostPtrSurf);
if (!status) { if (!status) {
builder.releaseOwnership();
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
} }
dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch()); dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
@ -122,8 +121,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadImage(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
if (context->isProvidingPerformanceHints()) { if (context->isProvidingPerformanceHints()) {
if (!isL3Capable(ptr, hostPtrSize)) { if (!isL3Capable(ptr, hostPtrSize)) {
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_READ_IMAGE_DOESNT_MEET_ALIGNMENT_RESTRICTIONS, ptr, hostPtrSize, MemoryConstants::pageSize, MemoryConstants::pageSize); context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL, CL_ENQUEUE_READ_IMAGE_DOESNT_MEET_ALIGNMENT_RESTRICTIONS, ptr, hostPtrSize, MemoryConstants::pageSize, MemoryConstants::pageSize);

View File

@ -194,7 +194,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltinDispatchInfoBuilder::BuiltinOpParams operationParams; BuiltinDispatchInfoBuilder::BuiltinOpParams operationParams;
operationParams.srcPtr = const_cast<void *>(srcPtr); operationParams.srcPtr = const_cast<void *>(srcPtr);
@ -217,8 +217,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
@ -264,7 +262,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::FillBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::FillBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltinDispatchInfoBuilder::BuiltinOpParams operationParams; BuiltinDispatchInfoBuilder::BuiltinOpParams operationParams;
MemObj patternMemObj(this->context, 0, 0, alignUp(patternSize, 4), patternAllocation->getUnderlyingBuffer(), MemObj patternMemObj(this->context, 0, 0, alignUp(patternSize, 4), patternAllocation->getUnderlyingBuffer(),
@ -290,8 +288,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(patternAllocation), REUSABLE_ALLOCATION, taskCount); memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(patternAllocation), REUSABLE_ALLOCATION, taskCount);
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }

View File

@ -95,7 +95,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
void *srcPtr = const_cast<void *>(ptr); void *srcPtr = const_cast<void *>(ptr);
@ -106,7 +106,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
if (size != 0) { if (size != 0) {
bool status = createAllocationForHostSurface(hostPtrSurf); bool status = createAllocationForHostSurface(hostPtrSurf);
if (!status) { if (!status) {
builder.releaseOwnership();
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
} }
srcPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch()); srcPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
@ -131,8 +130,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(buffer)); context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, CL_ENQUEUE_WRITE_BUFFER_REQUIRES_COPY_DATA, static_cast<cl_mem>(buffer));
} }
builder.releaseOwnership();
return CL_SUCCESS; return CL_SUCCESS;
} }
} // namespace OCLRT } // namespace OCLRT

View File

@ -78,7 +78,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBufferRect(
} }
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferRect, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferRect,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper builtInLock(builder, this->context);
size_t hostPtrSize = Buffer::calculateHostPtrSize(hostOrigin, region, hostRowPitch, hostSlicePitch); size_t hostPtrSize = Buffer::calculateHostPtrSize(hostOrigin, region, hostRowPitch, hostSlicePitch);
void *srcPtr = const_cast<void *>(ptr); void *srcPtr = const_cast<void *>(ptr);
@ -92,7 +92,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBufferRect(
region[2] != 0) { region[2] != 0) {
bool status = createAllocationForHostSurface(hostPtrSurf); bool status = createAllocationForHostSurface(hostPtrSurf);
if (!status) { if (!status) {
builder.releaseOwnership();
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
} }
srcPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch()); srcPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
@ -118,8 +117,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBufferRect(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
if (context->isProvidingPerformanceHints()) { if (context->isProvidingPerformanceHints()) {
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, CL_ENQUEUE_WRITE_BUFFER_RECT_REQUIRES_COPY_DATA, static_cast<cl_mem>(buffer)); context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, CL_ENQUEUE_WRITE_BUFFER_RECT_REQUIRES_COPY_DATA, static_cast<cl_mem>(buffer));
} }

View File

@ -79,7 +79,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteImage(
auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToImage3d, auto &builder = BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToImage3d,
this->getContext(), this->getDevice()); this->getContext(), this->getDevice());
builder.takeOwnership(this->context); BuiltInOwnershipWrapper lock(builder, this->context);
size_t hostPtrSize = calculateHostPtrSizeForImage(const_cast<size_t *>(region), inputRowPitch, inputSlicePitch, dstImage); size_t hostPtrSize = calculateHostPtrSizeForImage(const_cast<size_t *>(region), inputRowPitch, inputSlicePitch, dstImage);
void *srcPtr = const_cast<void *>(ptr); void *srcPtr = const_cast<void *>(ptr);
@ -93,7 +93,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteImage(
region[2] != 0) { region[2] != 0) {
bool status = createAllocationForHostSurface(hostPtrSurf); bool status = createAllocationForHostSurface(hostPtrSurf);
if (!status) { if (!status) {
builder.releaseOwnership();
return CL_OUT_OF_RESOURCES; return CL_OUT_OF_RESOURCES;
} }
srcPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch()); srcPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
@ -120,8 +119,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteImage(
eventWaitList, eventWaitList,
event); event);
builder.releaseOwnership();
if (context->isProvidingPerformanceHints()) { if (context->isProvidingPerformanceHints()) {
context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, CL_ENQUEUE_WRITE_IMAGE_REQUIRES_COPY_DATA, static_cast<cl_mem>(dstImage)); context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, CL_ENQUEUE_WRITE_IMAGE_REQUIRES_COPY_DATA, static_cast<cl_mem>(dstImage));
} }

View File

@ -87,4 +87,14 @@ struct MapInfo {
bool readOnly = false; bool readOnly = false;
uint32_t mipLevel = 0; uint32_t mipLevel = 0;
}; };
class NonCopyableOrMovableClass {
public:
NonCopyableOrMovableClass() = default;
NonCopyableOrMovableClass(const NonCopyableOrMovableClass &) = delete;
NonCopyableOrMovableClass &operator=(const NonCopyableOrMovableClass &) = delete;
NonCopyableOrMovableClass(NonCopyableOrMovableClass &&) = delete;
NonCopyableOrMovableClass &operator=(NonCopyableOrMovableClass &&) = delete;
};
} // namespace OCLRT } // namespace OCLRT

View File

@ -41,6 +41,7 @@
#include "unit_tests/global_environment.h" #include "unit_tests/global_environment.h"
#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_buffer.h" #include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_builtins.h" #include "unit_tests/mocks/mock_builtins.h"
#include "unit_tests/mocks/mock_compilers.h" #include "unit_tests/mocks/mock_compilers.h"
#include "unit_tests/mocks/mock_kernel.h" #include "unit_tests/mocks/mock_kernel.h"
@ -204,11 +205,6 @@ TEST_F(BuiltInTests, BuiltinDispatchInfoBuilderCopyBufferToBuffer) {
builtinOpsParams.size = {dst.getSize(), 0, 0}; builtinOpsParams.size = {dst.getSize(), 0, 0};
ASSERT_TRUE(builder.buildDispatchInfos(multiDispatchInfo, builtinOpsParams)); ASSERT_TRUE(builder.buildDispatchInfos(multiDispatchInfo, builtinOpsParams));
builder.takeOwnership(pContext);
for (auto &dispatchInfo : multiDispatchInfo) {
EXPECT_TRUE(dispatchInfo.getKernel()->hasOwnership());
}
size_t leftSize = reinterpret_cast<uintptr_t>(dst.getCpuAddress()) % MemoryConstants::cacheLineSize; size_t leftSize = reinterpret_cast<uintptr_t>(dst.getCpuAddress()) % MemoryConstants::cacheLineSize;
if (leftSize > 0) { if (leftSize > 0) {
@ -249,11 +245,6 @@ TEST_F(BuiltInTests, BuiltinDispatchInfoBuilderCopyBufferToBuffer) {
i++; i++;
} }
builder.releaseOwnership();
for (auto &dispatchInfo : multiDispatchInfo) {
EXPECT_FALSE(dispatchInfo.getKernel()->hasOwnership());
}
delete srcPtr; delete srcPtr;
delete dstPtr; delete dstPtr;
} }
@ -413,6 +404,7 @@ class MockAuxBuilInOp : public BuiltInOp<Family, EBuiltInOps::AuxTranslation> {
using BaseClass::convertToAuxKernel; using BaseClass::convertToAuxKernel;
using BaseClass::convertToNonAuxKernel; using BaseClass::convertToNonAuxKernel;
using BaseClass::resizeKernelInstances; using BaseClass::resizeKernelInstances;
using BaseClass::usedKernels;
MockAuxBuilInOp(BuiltIns &kernelsLib, Context &context, Device &device) : BaseClass(kernelsLib, context, device) {} MockAuxBuilInOp(BuiltIns &kernelsLib, Context &context, Device &device) : BaseClass(kernelsLib, context, device) {}
}; };
@ -447,7 +439,6 @@ HWTEST_F(BuiltInTests, givenMoreBuffersForAuxTranslationThanKernelInstancesWhenD
HWTEST_F(BuiltInTests, givenkAuxBuiltInWhenResizeIsCalledThenCloneAllNewInstancesFromBaseKernel) { HWTEST_F(BuiltInTests, givenkAuxBuiltInWhenResizeIsCalledThenCloneAllNewInstancesFromBaseKernel) {
MockAuxBuilInOp<FamilyType> mockAuxBuiltInOp(*pBuiltIns, *pContext, *pDevice); MockAuxBuilInOp<FamilyType> mockAuxBuiltInOp(*pBuiltIns, *pContext, *pDevice);
size_t newSize = mockAuxBuiltInOp.convertToAuxKernel.size() + 3; size_t newSize = mockAuxBuiltInOp.convertToAuxKernel.size() + 3;
mockAuxBuiltInOp.resizeKernelInstances(newSize); mockAuxBuiltInOp.resizeKernelInstances(newSize);
@ -462,6 +453,39 @@ HWTEST_F(BuiltInTests, givenkAuxBuiltInWhenResizeIsCalledThenCloneAllNewInstance
} }
} }
HWTEST_F(BuiltInTests, givenKernelWithAuxTranslationRequiredWhenEnqueueCalledThenLockOnBuiltin) {
BuiltIns::getInstance().getBuiltinDispatchInfoBuilder(EBuiltInOps::AuxTranslation, *pContext, *pDevice);
auto mockAuxBuiltInOp = new MockAuxBuilInOp<FamilyType>(*pBuiltIns, *pContext, *pDevice);
pBuiltIns->BuiltinOpsBuilders[static_cast<uint32_t>(EBuiltInOps::AuxTranslation)].first.reset(mockAuxBuiltInOp);
MockProgram mockProgram;
auto mockBuiltinKernel = MockKernel::create(*pDevice, &mockProgram);
mockAuxBuiltInOp->usedKernels.at(0).reset(mockBuiltinKernel);
MockKernelWithInternals mockKernel(*pDevice, pContext);
MockCommandQueueHw<FamilyType> cmdQ(pContext, pDevice, nullptr);
size_t gws[3] = {1, 0, 0};
MockBuffer buffer;
cl_mem clMem = &buffer;
buffer.getGraphicsAllocation()->setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
mockKernel.kernelInfo.kernelArgInfo.resize(1);
mockKernel.kernelInfo.kernelArgInfo.at(0).kernelArgPatchInfoVector.resize(1);
mockKernel.kernelInfo.kernelArgInfo.at(0).pureStatefulBufferAccess = false;
mockKernel.mockKernel->initialize();
mockKernel.mockKernel->setArgBuffer(0, sizeof(cl_mem *), &clMem);
mockKernel.mockKernel->auxTranslationRequired = false;
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_EQ(0u, mockBuiltinKernel->takeOwnershipCalls);
EXPECT_EQ(0u, mockBuiltinKernel->releaseOwnershipCalls);
mockKernel.mockKernel->auxTranslationRequired = true;
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_EQ(1u, mockBuiltinKernel->takeOwnershipCalls);
EXPECT_EQ(1u, mockBuiltinKernel->releaseOwnershipCalls);
}
TEST_F(BuiltInTests, BuiltinDispatchInfoBuilderCopyBufferToBufferAligned) { TEST_F(BuiltInTests, BuiltinDispatchInfoBuilderCopyBufferToBufferAligned) {
BuiltinDispatchInfoBuilder &builder = pBuiltIns->getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer, *pContext, *pDevice); BuiltinDispatchInfoBuilder &builder = pBuiltIns->getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer, *pContext, *pDevice);
@ -1740,3 +1764,46 @@ TEST_F(BuiltInTests, givenDebugFlagForceUseSourceWhenArgIsAnyThenReturnBuiltinCo
EXPECT_NE(0u, code.resource.size()); EXPECT_NE(0u, code.resource.size());
EXPECT_EQ(pDevice, code.targetDevice); EXPECT_EQ(pDevice, code.targetDevice);
} }
using BuiltInOwnershipWrapperTests = BuiltInTests;
HWTEST_F(BuiltInOwnershipWrapperTests, givenBuiltinWhenConstructedThenLockAndUnlockOnDestruction) {
MockAuxBuilInOp<FamilyType> mockAuxBuiltInOp(*pBuiltIns, *pContext, *pDevice);
MockContext mockContext;
{
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp, &mockContext);
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->hasOwnership());
EXPECT_EQ(&mockContext, &mockAuxBuiltInOp.baseKernel->getContext());
}
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->hasOwnership());
EXPECT_EQ(pContext, &mockAuxBuiltInOp.baseKernel->getContext());
}
HWTEST_F(BuiltInOwnershipWrapperTests, givenLockWithoutParametersWhenConstructingThenLockOnlyWhenRequested) {
MockAuxBuilInOp<FamilyType> mockAuxBuiltInOp(*pBuiltIns, *pContext, *pDevice);
MockContext mockContext;
{
BuiltInOwnershipWrapper lock;
lock.takeOwnership(mockAuxBuiltInOp, &mockContext);
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->hasOwnership());
EXPECT_EQ(&mockContext, &mockAuxBuiltInOp.baseKernel->getContext());
}
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->hasOwnership());
EXPECT_EQ(pContext, &mockAuxBuiltInOp.baseKernel->getContext());
}
HWTEST_F(BuiltInOwnershipWrapperTests, givenLockWithAcquiredOwnershipWhenTakeOwnershipCalledThenAbort) {
MockAuxBuilInOp<FamilyType> mockAuxBuiltInOp1(*pBuiltIns, *pContext, *pDevice);
MockAuxBuilInOp<FamilyType> mockAuxBuiltInOp2(*pBuiltIns, *pContext, *pDevice);
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp1, pContext);
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp1, pContext), std::exception);
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp2, pContext), std::exception);
}
HWTEST_F(BuiltInOwnershipWrapperTests, givenBuiltInOwnershipWrapperWhenAskedForTypeTraitsThenDisableCopyConstructorAndOperator) {
EXPECT_FALSE(std::is_copy_constructible<BuiltInOwnershipWrapper>::value);
EXPECT_FALSE(std::is_copy_assignable<BuiltInOwnershipWrapper>::value);
}

View File

@ -227,9 +227,21 @@ class MockKernel : public Kernel {
void makeResident(CommandStreamReceiver &commandStreamReceiver) override; void makeResident(CommandStreamReceiver &commandStreamReceiver) override;
void getResidency(std::vector<Surface *> &dst) override; void getResidency(std::vector<Surface *> &dst) override;
bool takeOwnership(bool lock) const override {
auto retVal = Kernel::takeOwnership(lock);
takeOwnershipCalls++;
return retVal;
}
void releaseOwnership() const override {
releaseOwnershipCalls++;
Kernel::releaseOwnership();
}
uint32_t makeResidentCalls = 0; uint32_t makeResidentCalls = 0;
uint32_t getResidencyCalls = 0; uint32_t getResidencyCalls = 0;
mutable uint32_t takeOwnershipCalls = 0;
mutable uint32_t releaseOwnershipCalls = 0;
bool canKernelTransformImages = true; bool canKernelTransformImages = true;