Don't store Context in Kernel

reuse Context from Program

Related-To: NEO-5001
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-11-18 17:06:55 +01:00
committed by Compute-Runtime-Automation
parent 4c55491dc1
commit 2003fe46a6
14 changed files with 26 additions and 48 deletions

View File

@ -770,23 +770,21 @@ BuiltinDispatchInfoBuilder &BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuil
return *operationBuilder.first;
}
BuiltInOwnershipWrapper::BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
takeOwnership(inputBuilder, context);
BuiltInOwnershipWrapper::BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder) {
takeOwnership(inputBuilder);
}
BuiltInOwnershipWrapper::~BuiltInOwnershipWrapper() {
if (builder) {
for (auto &kernel : builder->peekUsedKernels()) {
kernel->setContext(nullptr);
kernel->releaseOwnership();
}
}
}
void BuiltInOwnershipWrapper::takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context) {
void BuiltInOwnershipWrapper::takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder) {
UNRECOVERABLE_IF(builder);
builder = &inputBuilder;
for (auto &kernel : builder->peekUsedKernels()) {
kernel->takeOwnership();
kernel->setContext(context);
}
}

View File

@ -114,10 +114,10 @@ class BuiltInDispatchBuilderOp {
class BuiltInOwnershipWrapper : public NonCopyableOrMovableClass {
public:
BuiltInOwnershipWrapper() = default;
BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder, Context *context);
BuiltInOwnershipWrapper(BuiltinDispatchInfoBuilder &inputBuilder);
~BuiltInOwnershipWrapper();
void takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder, Context *context);
void takeOwnership(BuiltinDispatchInfoBuilder &inputBuilder);
protected:
BuiltinDispatchInfoBuilder *builder = nullptr;

View File

@ -66,7 +66,7 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface *(&surfaces)[surfaceCount
} else {
if (kernel->isAuxTranslationRequired()) {
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::AuxTranslation, getClDevice());
builtInLock.takeOwnership(builder, this->context);
builtInLock.takeOwnership(builder);
kernel->fillWithBuffersForAuxTranslation(memObjsForAuxTranslation);
multiDispatchInfo.setMemObjsForAuxTranslation(memObjsForAuxTranslation);
if (!memObjsForAuxTranslation.empty()) {
@ -1114,7 +1114,7 @@ void CommandQueueHw<GfxFamily>::dispatchBcsOrGpgpuEnqueue(MultiDispatchInfo &dis
} else {
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(builtInOperation,
this->getClDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltInOwnershipWrapper builtInLock(builder);
builder.buildDispatchInfos(dispatchInfo);

View File

@ -38,7 +38,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyBufferToImage(
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOpsType,
this->getClDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltInOwnershipWrapper builtInLock(builder);
MemObjSurface srcBufferSurf(srcBuffer);
MemObjSurface dstImgSurf(dstImage);

View File

@ -34,7 +34,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImage(
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImageToImage3d,
this->getClDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltInOwnershipWrapper builtInLock(builder);
MemObjSurface srcImgSurf(srcImage);
MemObjSurface dstImgSurf(dstImage);

View File

@ -37,7 +37,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueCopyImageToBuffer(
}
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOpsType,
this->getClDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltInOwnershipWrapper builtInLock(builder);
MemObjSurface srcImgSurf(srcImage);
MemObjSurface dstBufferSurf(dstBuffer);

View File

@ -53,7 +53,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillBuffer(
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(eBuiltInOps,
this->getClDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltInOwnershipWrapper builtInLock(builder);
BuiltinOpParams dc;
auto multiGraphicsAllocation = MultiGraphicsAllocation(getDevice().getRootDeviceIndex());

View File

@ -32,7 +32,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueFillImage(
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::FillImage3d,
this->getClDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltInOwnershipWrapper builtInLock(builder);
MemObjSurface dstImgSurf(image);
Surface *surfaces[] = {&dstImgSurf};

View File

@ -461,7 +461,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(builtInType,
this->getClDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
BuiltInOwnershipWrapper builtInLock(builder);
BuiltinOpParams operationParams;
auto multiGraphicsAllocation = MultiGraphicsAllocation(getDevice().getRootDeviceIndex());

View File

@ -189,11 +189,7 @@ class Kernel : public BaseObject<_cl_kernel> {
}
Context &getContext() const {
return context ? *context : program->getContext();
}
void setContext(Context *context) {
this->context = context;
return program->getContext();
}
Program *getProgram() const { return program; }
@ -515,7 +511,6 @@ class Kernel : public BaseObject<_cl_kernel> {
}
Program *program;
Context *context = nullptr;
const ClDeviceVector &deviceVector;
const KernelInfo &kernelInfo;

View File

@ -2066,25 +2066,19 @@ using BuiltInOwnershipWrapperTests = BuiltInTests;
TEST_F(BuiltInOwnershipWrapperTests, givenBuiltinWhenConstructedThenLockAndUnlockOnDestruction) {
MockAuxBuilInOp mockAuxBuiltInOp(*pBuiltIns, *pClDevice);
MockContext mockContext;
{
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp, &mockContext);
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp);
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->hasOwnership());
EXPECT_EQ(&mockContext, &mockAuxBuiltInOp.baseKernel->getContext());
}
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->hasOwnership());
}
TEST_F(BuiltInOwnershipWrapperTests, givenLockWithoutParametersWhenConstructingThenLockOnlyWhenRequested) {
MockAuxBuilInOp mockAuxBuiltInOp(*pBuiltIns, *pClDevice);
MockContext mockContext;
{
BuiltInOwnershipWrapper lock;
lock.takeOwnership(mockAuxBuiltInOp, &mockContext);
lock.takeOwnership(mockAuxBuiltInOp);
EXPECT_TRUE(mockAuxBuiltInOp.baseKernel->hasOwnership());
EXPECT_EQ(&mockContext, &mockAuxBuiltInOp.baseKernel->getContext());
}
EXPECT_FALSE(mockAuxBuiltInOp.baseKernel->hasOwnership());
}
@ -2093,9 +2087,9 @@ TEST_F(BuiltInOwnershipWrapperTests, givenLockWithAcquiredOwnershipWhenTakeOwner
MockAuxBuilInOp mockAuxBuiltInOp1(*pBuiltIns, *pClDevice);
MockAuxBuilInOp mockAuxBuiltInOp2(*pBuiltIns, *pClDevice);
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp1, pContext);
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp1, pContext), std::exception);
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp2, pContext), std::exception);
BuiltInOwnershipWrapper lock(mockAuxBuiltInOp1);
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp1), std::exception);
EXPECT_THROW(lock.takeOwnership(mockAuxBuiltInOp2), std::exception);
}
HWTEST_F(BuiltInOwnershipWrapperTests, givenBuiltInOwnershipWrapperWhenAskedForTypeTraitsThenDisableCopyConstructorAndOperator) {

View File

@ -152,10 +152,9 @@ class GMockCommandQueueHw : public CommandQueueHw<GfxFamily> {
};
HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelFromProgramWithDebugEnabledWhenEnqueuedThenDebugSurfaceIsSetup) {
MockProgram program(toClDeviceVector(*pClDevice));
MockProgram program(context, false, toClDeviceVector(*pClDevice));
program.enableKernelDebug();
std::unique_ptr<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*pDevice, &program));
kernel->setContext(context);
kernel->initialize();
std::unique_ptr<GMockCommandQueueHw<FamilyType>> mockCmdQ(new GMockCommandQueueHw<FamilyType>(context, pClDevice, 0));
mockCmdQ->getGpgpuCommandStreamReceiver().allocateDebugSurface(SipKernel::maxDbgSurfaceSize);
@ -171,10 +170,9 @@ HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelFromProgramWithDebugEnabledWhe
}
HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelWithoutSystemThreadSurfaceWhenEnqueuedThenDebugSurfaceIsNotSetup) {
MockProgram program(toClDeviceVector(*pClDevice));
MockProgram program(context, false, toClDeviceVector(*pClDevice));
program.enableKernelDebug();
std::unique_ptr<MockKernel> kernel(MockKernel::create<MockKernel>(*pDevice, &program));
kernel->setContext(context);
kernel->initialize();
EXPECT_EQ(nullptr, kernel->getKernelInfo().patchInfo.pAllocateSystemThreadSurface);
@ -190,9 +188,8 @@ HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelWithoutSystemThreadSurfaceWhen
}
HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelFromProgramWithoutDebugEnabledWhenEnqueuedThenDebugSurfaceIsNotSetup) {
MockProgram program(toClDeviceVector(*pClDevice));
MockProgram program(context, false, toClDeviceVector(*pClDevice));
std::unique_ptr<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*pDevice, &program));
kernel->setContext(context);
std::unique_ptr<NiceMock<GMockCommandQueueHw<FamilyType>>> mockCmdQ(new NiceMock<GMockCommandQueueHw<FamilyType>>(context, pClDevice, nullptr));
EXPECT_CALL(*mockCmdQ.get(), setupDebugSurface(kernel.get())).Times(0);
@ -207,9 +204,8 @@ HWTEST_F(EnqueueDebugKernelSimpleTest, givenKernelFromProgramWithoutDebugEnabled
using ActiveDebuggerTest = EnqueueDebugKernelTest;
HWTEST_F(ActiveDebuggerTest, givenKernelFromProgramWithoutDebugEnabledAndActiveDebuggerWhenEnqueuedThenDebugSurfaceIsSetup) {
MockProgram program(toClDeviceVector(*pClDevice));
MockProgram program(&context, false, toClDeviceVector(*pClDevice));
std::unique_ptr<MockDebugKernel> kernel(MockKernel::create<MockDebugKernel>(*pDevice, &program));
kernel->setContext(&context);
std::unique_ptr<CommandQueueHw<FamilyType>> cmdQ(new CommandQueueHw<FamilyType>(&context, pClDevice, nullptr, false));
size_t gws[] = {1, 1, 1};

View File

@ -59,7 +59,8 @@ void KernelImageArgTest::SetUp() {
pKernelInfo->kernelDescriptor.kernelAttributes.bufferAddressingMode = ApiSpecificConfig::getBindlessConfiguration() ? KernelDescriptor::AddressingMode::BindlessAndStateless : KernelDescriptor::AddressingMode::BindfulAndStateless;
ClDeviceFixture::SetUp();
program = std::make_unique<MockProgram>(toClDeviceVector(*pClDevice));
context.reset(new MockContext(pClDevice));
program = std::make_unique<MockProgram>(context.get(), false, toClDeviceVector(*pClDevice));
pKernel.reset(new MockKernel(program.get(), *pKernelInfo));
ASSERT_EQ(CL_SUCCESS, pKernel->initialize());
@ -73,9 +74,7 @@ void KernelImageArgTest::SetUp() {
crossThreadData[0x20 / sizeof(uint32_t)] = 0x12344321;
pKernel->setCrossThreadData(crossThreadData, sizeof(crossThreadData));
context.reset(new MockContext(pClDevice));
image.reset(Image2dHelper<>::create(context.get()));
pKernel->setContext(context.get());
ASSERT_NE(nullptr, image);
}

View File

@ -163,18 +163,14 @@ TEST_F(KernelArgPipeTest, GivenBufferWhenSettingKernelArgThenInvalidArgValueErro
}
TEST_F(KernelArgPipeTest, GivenPipeFromDifferentContextWhenSettingKernelArgThenInvalidMemObjectErrorIsReturned) {
Pipe *pipe = new MockPipe(pContext);
Context *oldContext = &pKernel->getContext();
MockContext newContext;
this->pKernel->setContext(&newContext);
Pipe *pipe = new MockPipe(&newContext);
auto val = (cl_mem)pipe;
auto pVal = &val;
auto retVal = this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
pKernel->setContext(oldContext);
delete pipe;
}