mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Set Context in program when using builtins
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
402082182c
commit
722f693e0f
@ -780,19 +780,27 @@ BuiltinDispatchInfoBuilder &BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuil
|
||||
return *operationBuilder.first;
|
||||
}
|
||||
|
||||
BuiltInOwnershipWrapper::BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder) {
|
||||
takeOwnership(inputBuilder);
|
||||
BuiltInOwnershipWrapper::BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
|
||||
takeOwnership(inputBuilder, context);
|
||||
}
|
||||
BuiltInOwnershipWrapper::~BuiltInOwnershipWrapper() {
|
||||
if (builder) {
|
||||
for (auto &kernel : builder->peekUsedKernels()) {
|
||||
kernel->releaseOwnership();
|
||||
}
|
||||
if (!builder->peekUsedKernels().empty()) {
|
||||
builder->peekUsedKernels()[0]->getProgram()->setContext(nullptr);
|
||||
builder->peekUsedKernels()[0]->getProgram()->releaseOwnership();
|
||||
}
|
||||
}
|
||||
}
|
||||
void BuiltInOwnershipWrapper::takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder) {
|
||||
void BuiltInOwnershipWrapper::takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
|
||||
UNRECOVERABLE_IF(builder);
|
||||
builder = &inputBuilder;
|
||||
if (!builder->peekUsedKernels().empty()) {
|
||||
builder->peekUsedKernels()[0]->getProgram()->takeOwnership();
|
||||
builder->peekUsedKernels()[0]->getProgram()->setContext(context);
|
||||
}
|
||||
for (auto &kernel : builder->peekUsedKernels()) {
|
||||
kernel->takeOwnership();
|
||||
}
|
||||
|
@ -118,10 +118,10 @@ class BuiltInDispatchBuilderOp {
|
||||
class BuiltInOwnershipWrapper : public NonCopyableOrMovableClass {
|
||||
public:
|
||||
BuiltInOwnershipWrapper() = default;
|
||||
BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder);
|
||||
BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context);
|
||||
~BuiltInOwnershipWrapper();
|
||||
|
||||
void takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder);
|
||||
void takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context);
|
||||
|
||||
protected:
|
||||
BuiltinDispatchInfoBuilder *builder = nullptr;
|
||||
|
@ -80,7 +80,7 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface *(&surfaces)[surfaceCount
|
||||
|
||||
if (AuxTranslationMode::Builtin == auxTranslationMode) {
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::AuxTranslation, getClDevice());
|
||||
builtInLock.takeOwnership(builder);
|
||||
builtInLock.takeOwnership(builder, this->context);
|
||||
|
||||
dispatchAuxTranslationBuiltin(multiDispatchInfo, AuxTranslationDirection::AuxToNonAux);
|
||||
}
|
||||
@ -1175,7 +1175,7 @@ void CommandQueueHw<GfxFamily>::dispatchBcsOrGpgpuEnqueue(MultiDispatchInfo &dis
|
||||
} else {
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(builtInOperation,
|
||||
this->getClDevice());
|
||||
BuiltInOwnershipWrapper builtInLock(builder);
|
||||
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
||||
|
||||
builder.buildDispatchInfos(dispatchInfo);
|
||||
|
||||
|
@ -38,7 +38,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBufferToImage(
|
||||
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOpsType,
|
||||
this->getClDevice());
|
||||
BuiltInOwnershipWrapper builtInLock(builder);
|
||||
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
||||
|
||||
MemObjSurface srcBufferSurf(srcBuffer);
|
||||
MemObjSurface dstImgSurf(dstImage);
|
||||
|
@ -33,7 +33,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImage(
|
||||
cl_event *event) {
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImageToImage3d,
|
||||
this->getClDevice());
|
||||
BuiltInOwnershipWrapper builtInLock(builder);
|
||||
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
||||
|
||||
MemObjSurface srcImgSurf(srcImage);
|
||||
MemObjSurface dstImgSurf(dstImage);
|
||||
|
@ -37,7 +37,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImageToBuffer(
|
||||
}
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOpsType,
|
||||
this->getClDevice());
|
||||
BuiltInOwnershipWrapper builtInLock(builder);
|
||||
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
||||
|
||||
MemObjSurface srcImgSurf(srcImage);
|
||||
MemObjSurface dstBufferSurf(dstBuffer);
|
||||
|
@ -61,7 +61,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillBuffer(
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOps,
|
||||
this->getClDevice());
|
||||
|
||||
BuiltInOwnershipWrapper builtInLock(builder);
|
||||
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
||||
|
||||
BuiltinOpParams dc;
|
||||
auto multiGraphicsAllocation = MultiGraphicsAllocation(getDevice().getRootDeviceIndex());
|
||||
|
@ -31,7 +31,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillImage(
|
||||
cl_event *event) {
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::FillImage3d,
|
||||
this->getClDevice());
|
||||
BuiltInOwnershipWrapper builtInLock(builder);
|
||||
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
||||
|
||||
MemObjSurface dstImgSurf(image);
|
||||
Surface *surfaces[] = {&dstImgSurf};
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2020 Intel Corporation
|
||||
* Copyright (C) 2017-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@ -461,7 +461,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
|
||||
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(builtInType,
|
||||
this->getClDevice());
|
||||
|
||||
BuiltInOwnershipWrapper builtInLock(builder);
|
||||
BuiltInOwnershipWrapper builtInLock(builder, this->context);
|
||||
|
||||
BuiltinOpParams operationParams;
|
||||
auto multiGraphicsAllocation = MultiGraphicsAllocation(getDevice().getRootDeviceIndex());
|
||||
|
@ -277,6 +277,10 @@ class Program : public BaseObject<_cl_program> {
|
||||
|
||||
const ExecutionEnvironment &getExecutionEnvironment() const { return executionEnvironment; }
|
||||
|
||||
void setContext(Context *pContext) {
|
||||
this->context = pContext;
|
||||
}
|
||||
|
||||
protected:
|
||||
MOCKABLE_VIRTUAL cl_int createProgramFromBinary(const void *pBinary, size_t binarySize, ClDevice &clDevice);
|
||||
|
||||
|
@ -2172,30 +2172,43 @@ using BuiltInOwnershipWrapperTests = BuiltInTests;
|
||||
|
||||
TEST_F(BuiltInOwnershipWrapperTests, givenBuiltinWhenConstructedThenLockAndUnlockOnDestruction) {
|
||||
MockAuxBuilInOp mockAuxBuiltInOp(*pBuiltIns, *pClDevice);
|
||||
MockContext context(pClDevice);
|
||||
{
|
||||
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp);
|
||||
EXPECT_EQ(nullptr, mockAuxBuiltInOp.baseKernel->getProgram()->getContextPtr());
|
||||
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp, &context);
|
||||
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->getMultiDeviceKernel()->hasOwnership());
|
||||
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->getProgram()->hasOwnership());
|
||||
EXPECT_EQ(&context, mockAuxBuiltInOp.baseKernel->getProgram()->getContextPtr());
|
||||
}
|
||||
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->getMultiDeviceKernel()->hasOwnership());
|
||||
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->getProgram()->hasOwnership());
|
||||
EXPECT_EQ(nullptr, mockAuxBuiltInOp.baseKernel->getProgram()->getContextPtr());
|
||||
}
|
||||
|
||||
TEST_F(BuiltInOwnershipWrapperTests, givenLockWithoutParametersWhenConstructingThenLockOnlyWhenRequested) {
|
||||
MockAuxBuilInOp mockAuxBuiltInOp(*pBuiltIns, *pClDevice);
|
||||
MockContext context(pClDevice);
|
||||
{
|
||||
BuiltInOwnershipWrapper lock;
|
||||
lock.takeOwnership(mockAuxBuiltInOp);
|
||||
EXPECT_EQ(nullptr, mockAuxBuiltInOp.baseKernel->getProgram()->getContextPtr());
|
||||
lock.takeOwnership(mockAuxBuiltInOp, &context);
|
||||
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->getMultiDeviceKernel()->hasOwnership());
|
||||
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->getProgram()->hasOwnership());
|
||||
EXPECT_EQ(&context, mockAuxBuiltInOp.baseKernel->getProgram()->getContextPtr());
|
||||
}
|
||||
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->getMultiDeviceKernel()->hasOwnership());
|
||||
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->getProgram()->hasOwnership());
|
||||
EXPECT_EQ(nullptr, mockAuxBuiltInOp.baseKernel->getProgram()->getContextPtr());
|
||||
}
|
||||
|
||||
TEST_F(BuiltInOwnershipWrapperTests, givenLockWithAcquiredOwnershipWhenTakeOwnershipCalledThenAbort) {
|
||||
MockAuxBuilInOp mockAuxBuiltInOp1(*pBuiltIns, *pClDevice);
|
||||
MockAuxBuilInOp mockAuxBuiltInOp2(*pBuiltIns, *pClDevice);
|
||||
MockContext context(pClDevice);
|
||||
|
||||
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp1);
|
||||
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp1), std::exception);
|
||||
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp2), std::exception);
|
||||
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp1, &context);
|
||||
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp1, &context), std::exception);
|
||||
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp2, &context), std::exception);
|
||||
}
|
||||
|
||||
HWTEST_F(BuiltInOwnershipWrapperTests, givenBuiltInOwnershipWrapperWhenAskedForTypeTraitsThenDisableCopyConstructorAndOperator) {
|
||||
|
Reference in New Issue
Block a user