From 1f240862cec4f7f814250f1524af08f969cd1bee Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 15 Sep 2020 17:34:49 +0200 Subject: [PATCH] Move surface allocations from Program to BuildInfo Related-To: NEO-5001 Change-Id: Icf011698fc166285d049b052d59c709c7419e105 Signed-off-by: Mateusz Jablonski --- opencl/source/kernel/kernel.cpp | 48 ++++---- opencl/source/program/get_info.cpp | 3 +- .../source/program/process_device_binary.cpp | 32 ++--- opencl/source/program/program.cpp | 27 +++-- opencl/source/program/program.h | 22 ++-- .../kernel_reflection_surface_tests.cpp | 12 +- opencl/test/unit_test/kernel/kernel_tests.cpp | 10 +- opencl/test/unit_test/mocks/mock_kernel.h | 2 +- opencl/test/unit_test/mocks/mock_program.h | 19 ++- .../unit_test/program/program_data_tests.cpp | 109 +++++++++--------- .../test/unit_test/program/program_tests.cpp | 24 ++-- 11 files changed, 163 insertions(+), 145 deletions(-) diff --git a/opencl/source/kernel/kernel.cpp b/opencl/source/kernel/kernel.cpp index 1afc6ef920..b6cdfd4a89 100644 --- a/opencl/source/kernel/kernel.cpp +++ b/opencl/source/kernel/kernel.cpp @@ -288,21 +288,21 @@ cl_int Kernel::initialize() { const auto &patch = patchInfo.pAllocateStatelessPrivateSurface; patchWithImplicitSurface(reinterpret_cast(privateSurface->getGpuAddressToPatch()), *privateSurface, *patch); } - + auto rootDeviceIndex = device.getRootDeviceIndex(); if (patchInfo.pAllocateStatelessConstantMemorySurfaceWithInitialization) { - DEBUG_BREAK_IF(program->getConstantSurface() == nullptr); - uintptr_t constMemory = isBuiltIn ? (uintptr_t)program->getConstantSurface()->getUnderlyingBuffer() : (uintptr_t)program->getConstantSurface()->getGpuAddressToPatch(); + DEBUG_BREAK_IF(program->getConstantSurface(rootDeviceIndex) == nullptr); + uintptr_t constMemory = isBuiltIn ? (uintptr_t)program->getConstantSurface(rootDeviceIndex)->getUnderlyingBuffer() : (uintptr_t)program->getConstantSurface(rootDeviceIndex)->getGpuAddressToPatch(); const auto &patch = patchInfo.pAllocateStatelessConstantMemorySurfaceWithInitialization; - patchWithImplicitSurface(reinterpret_cast(constMemory), *program->getConstantSurface(), *patch); + patchWithImplicitSurface(reinterpret_cast(constMemory), *program->getConstantSurface(rootDeviceIndex), *patch); } if (patchInfo.pAllocateStatelessGlobalMemorySurfaceWithInitialization) { - DEBUG_BREAK_IF(program->getGlobalSurface() == nullptr); - uintptr_t globalMemory = isBuiltIn ? (uintptr_t)program->getGlobalSurface()->getUnderlyingBuffer() : (uintptr_t)program->getGlobalSurface()->getGpuAddressToPatch(); + DEBUG_BREAK_IF(program->getGlobalSurface(rootDeviceIndex) == nullptr); + uintptr_t globalMemory = isBuiltIn ? (uintptr_t)program->getGlobalSurface(rootDeviceIndex)->getUnderlyingBuffer() : (uintptr_t)program->getGlobalSurface(rootDeviceIndex)->getGpuAddressToPatch(); const auto &patch = patchInfo.pAllocateStatelessGlobalMemorySurfaceWithInitialization; - patchWithImplicitSurface(reinterpret_cast(globalMemory), *program->getGlobalSurface(), *patch); + patchWithImplicitSurface(reinterpret_cast(globalMemory), *program->getGlobalSurface(rootDeviceIndex), *patch); } if (patchInfo.pAllocateStatelessEventPoolSurface) { @@ -1111,20 +1111,21 @@ inline void Kernel::makeArgsResident(CommandStreamReceiver &commandStreamReceive } void Kernel::makeResident(CommandStreamReceiver &commandStreamReceiver) { + auto rootDeviceIndex = device.getRootDeviceIndex(); if (privateSurface) { commandStreamReceiver.makeResident(*privateSurface); } - if (program->getConstantSurface()) { - commandStreamReceiver.makeResident(*(program->getConstantSurface())); + if (program->getConstantSurface(rootDeviceIndex)) { + commandStreamReceiver.makeResident(*(program->getConstantSurface(rootDeviceIndex))); } - if (program->getGlobalSurface()) { - commandStreamReceiver.makeResident(*(program->getGlobalSurface())); + if (program->getGlobalSurface(rootDeviceIndex)) { + commandStreamReceiver.makeResident(*(program->getGlobalSurface(rootDeviceIndex))); } - if (program->getExportedFunctionsSurface()) { - commandStreamReceiver.makeResident(*(program->getExportedFunctionsSurface())); + if (program->getExportedFunctionsSurface(rootDeviceIndex)) { + commandStreamReceiver.makeResident(*(program->getExportedFunctionsSurface(rootDeviceIndex))); } for (auto gfxAlloc : kernelSvmGfxAllocations) { @@ -1160,23 +1161,24 @@ void Kernel::makeResident(CommandStreamReceiver &commandStreamReceiver) { } void Kernel::getResidency(std::vector &dst) { + auto rootDeviceIndex = device.getRootDeviceIndex(); if (privateSurface) { GeneralSurface *surface = new GeneralSurface(privateSurface); dst.push_back(surface); } - if (program->getConstantSurface()) { - GeneralSurface *surface = new GeneralSurface(program->getConstantSurface()); + if (program->getConstantSurface(rootDeviceIndex)) { + GeneralSurface *surface = new GeneralSurface(program->getConstantSurface(rootDeviceIndex)); dst.push_back(surface); } - if (program->getGlobalSurface()) { - GeneralSurface *surface = new GeneralSurface(program->getGlobalSurface()); + if (program->getGlobalSurface(rootDeviceIndex)) { + GeneralSurface *surface = new GeneralSurface(program->getGlobalSurface(rootDeviceIndex)); dst.push_back(surface); } - if (program->getExportedFunctionsSurface()) { - GeneralSurface *surface = new GeneralSurface(program->getExportedFunctionsSurface()); + if (program->getExportedFunctionsSurface(rootDeviceIndex)) { + GeneralSurface *surface = new GeneralSurface(program->getExportedFunctionsSurface(rootDeviceIndex)); dst.push_back(surface); } @@ -1825,12 +1827,12 @@ size_t Kernel::getInstructionHeapSizeForExecutionModel() const { } void Kernel::patchBlocksCurbeWithConstantValues() { - + auto rootDeviceIndex = device.getRootDeviceIndex(); BlockKernelManager *blockManager = program->getBlockKernelManager(); uint32_t blockCount = static_cast(blockManager->getCount()); - uint64_t globalMemoryGpuAddress = program->getGlobalSurface() != nullptr ? program->getGlobalSurface()->getGpuAddressToPatch() : 0; - uint64_t constantMemoryGpuAddress = program->getConstantSurface() != nullptr ? program->getConstantSurface()->getGpuAddressToPatch() : 0; + uint64_t globalMemoryGpuAddress = program->getGlobalSurface(rootDeviceIndex) != nullptr ? program->getGlobalSurface(rootDeviceIndex)->getGpuAddressToPatch() : 0; + uint64_t constantMemoryGpuAddress = program->getConstantSurface(rootDeviceIndex) != nullptr ? program->getConstantSurface(rootDeviceIndex)->getGpuAddressToPatch() : 0; for (uint32_t blockID = 0; blockID < blockCount; blockID++) { const KernelInfo *pBlockInfo = blockManager->getBlockKernelInfo(blockID); @@ -2398,7 +2400,7 @@ void Kernel::getAllocationsForCacheFlush(CacheFlushAllocationsVec &out) const { out.push_back(alloc); } - auto global = getProgram()->getGlobalSurface(); + auto global = getProgram()->getGlobalSurface(device.getRootDeviceIndex()); if (global != nullptr) { out.push_back(global); } diff --git a/opencl/source/program/get_info.cpp b/opencl/source/program/get_info.cpp index 0faa193019..1f006da062 100644 --- a/opencl/source/program/get_info.cpp +++ b/opencl/source/program/get_info.cpp @@ -171,6 +171,7 @@ cl_int Program::getBuildInfo(cl_device_id device, cl_program_build_info paramNam } auto pClDev = castToObject(device); + auto rootDeviceIndex = pClDev->getRootDeviceIndex(); switch (paramName) { case CL_PROGRAM_BUILD_STATUS: @@ -196,7 +197,7 @@ cl_int Program::getBuildInfo(cl_device_id device, cl_program_build_info paramNam break; case CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE: - pSrc = &globalVarTotalSize; + pSrc = &buildInfos[rootDeviceIndex].globalVarTotalSize; retSize = srcSize = sizeof(size_t); break; diff --git a/opencl/source/program/process_device_binary.cpp b/opencl/source/program/process_device_binary.cpp index 492878d031..4cf2157d47 100644 --- a/opencl/source/program/process_device_binary.cpp +++ b/opencl/source/program/process_device_binary.cpp @@ -56,12 +56,13 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const if (linkerInput == nullptr) { return CL_SUCCESS; } + auto rootDeviceIndex = pDevice->getRootDeviceIndex(); Linker linker(*linkerInput); Linker::SegmentInfo globals; Linker::SegmentInfo constants; Linker::SegmentInfo exportedFunctions; - GraphicsAllocation *globalsForPatching = this->globalSurface; - GraphicsAllocation *constantsForPatching = this->constantSurface; + GraphicsAllocation *globalsForPatching = getGlobalSurface(rootDeviceIndex); + GraphicsAllocation *constantsForPatching = getConstantSurface(rootDeviceIndex); if (globalsForPatching != nullptr) { globals.gpuAddress = static_cast(globalsForPatching->getGpuAddress()); globals.segmentSize = globalsForPatching->getUnderlyingBufferSize(); @@ -73,9 +74,9 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const if (linkerInput->getExportedFunctionsSegmentId() >= 0) { // Exported functions reside in instruction heap of one of kernels auto exportedFunctionHeapId = linkerInput->getExportedFunctionsSegmentId(); - this->exportedFunctionsSurface = this->kernelInfoArray[exportedFunctionHeapId]->getGraphicsAllocation(); - exportedFunctions.gpuAddress = static_cast(exportedFunctionsSurface->getGpuAddressToPatch()); - exportedFunctions.segmentSize = exportedFunctionsSurface->getUnderlyingBufferSize(); + buildInfos[rootDeviceIndex].exportedFunctionsSurface = this->kernelInfoArray[exportedFunctionHeapId]->getGraphicsAllocation(); + exportedFunctions.gpuAddress = static_cast(buildInfos[rootDeviceIndex].exportedFunctionsSurface->getGpuAddressToPatch()); + exportedFunctions.segmentSize = buildInfos[rootDeviceIndex].exportedFunctionsSurface->getUnderlyingBufferSize(); } Linker::PatchableSegments isaSegmentsForPatching; std::vector> patchedIsaTempStorage; @@ -125,11 +126,13 @@ cl_int Program::processGenBinary() { } cleanCurrentKernelInfo(); - if (this->constantSurface || this->globalSurface) { - pDevice->getMemoryManager()->freeGraphicsMemory(this->constantSurface); - pDevice->getMemoryManager()->freeGraphicsMemory(this->globalSurface); - this->constantSurface = nullptr; - this->globalSurface = nullptr; + for (auto &buildInfo : buildInfos) { + if (buildInfo.constantSurface || buildInfo.globalSurface) { + pDevice->getMemoryManager()->freeGraphicsMemory(buildInfo.constantSurface); + pDevice->getMemoryManager()->freeGraphicsMemory(buildInfo.globalSurface); + buildInfo.constantSurface = nullptr; + buildInfo.globalSurface = nullptr; + } } ProgramInfo programInfo; @@ -176,18 +179,19 @@ cl_int Program::processProgramInfo(ProgramInfo &src) { this->kernelInfoArray = std::move(src.kernelInfos); auto svmAllocsManager = context ? context->getSVMAllocsManager() : nullptr; + auto rootDeviceIndex = pDevice ? pDevice->getRootDeviceIndex() : 0u; if (src.globalConstants.size != 0) { UNRECOVERABLE_IF(nullptr == pDevice); - this->constantSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalConstants.size, true, linkerInput, src.globalConstants.initData); + buildInfos[rootDeviceIndex].constantSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalConstants.size, true, linkerInput, src.globalConstants.initData); } - this->globalVarTotalSize = src.globalVariables.size; + buildInfos[rootDeviceIndex].globalVarTotalSize = src.globalVariables.size; if (src.globalVariables.size != 0) { UNRECOVERABLE_IF(nullptr == pDevice); - this->globalSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalVariables.size, false, linkerInput, src.globalVariables.initData); + buildInfos[rootDeviceIndex].globalSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalVariables.size, false, linkerInput, src.globalVariables.initData); if (pDevice->getSpecializedDevice()->areOcl21FeaturesEnabled() == false) { - this->globalVarTotalSize = 0u; + buildInfos[rootDeviceIndex].globalVarTotalSize = 0u; } } diff --git a/opencl/source/program/program.cpp b/opencl/source/program/program.cpp index fcebeca2ae..61d54d3ede 100644 --- a/opencl/source/program/program.cpp +++ b/opencl/source/program/program.cpp @@ -123,23 +123,22 @@ Program::~Program() { freeBlockResources(); delete blockKernelManager; - - if (constantSurface) { - if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(constantSurface->getGpuAddress())))) { - context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(constantSurface->getGpuAddress())); - } else { - this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(constantSurface); + for (const auto &buildInfo : buildInfos) { + if (buildInfo.constantSurface) { + if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(buildInfo.constantSurface->getGpuAddress())))) { + context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(buildInfo.constantSurface->getGpuAddress())); + } else { + this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(buildInfo.constantSurface); + } } - constantSurface = nullptr; - } - if (globalSurface) { - if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(globalSurface->getGpuAddress())))) { - context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(globalSurface->getGpuAddress())); - } else { - this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(globalSurface); + if (buildInfo.globalSurface) { + if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(buildInfo.globalSurface->getGpuAddress())))) { + context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast(buildInfo.globalSurface->getGpuAddress())); + } else { + this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(buildInfo.globalSurface); + } } - globalSurface = nullptr; } if (context && !isBuiltIn) { diff --git a/opencl/source/program/program.h b/opencl/source/program/program.h index 1641f8b56a..f00ff3e35d 100644 --- a/opencl/source/program/program.h +++ b/opencl/source/program/program.h @@ -205,16 +205,16 @@ class Program : public BaseObject<_cl_program> { return isSpirV; } - GraphicsAllocation *getConstantSurface() const { - return constantSurface; + GraphicsAllocation *getConstantSurface(uint32_t rootDeviceIndex) const { + return buildInfos[rootDeviceIndex].constantSurface; } - GraphicsAllocation *getGlobalSurface() const { - return globalSurface; + GraphicsAllocation *getGlobalSurface(uint32_t rootDeviceIndex) const { + return buildInfos[rootDeviceIndex].globalSurface; } - GraphicsAllocation *getExportedFunctionsSurface() const { - return exportedFunctionsSurface; + GraphicsAllocation *getExportedFunctionsSurface(uint32_t rootDeviceIndex) const { + return buildInfos[rootDeviceIndex].exportedFunctionsSurface; } BlockKernelManager *getBlockKernelManager() const { @@ -315,12 +315,6 @@ class Program : public BaseObject<_cl_program> { std::vector parentKernelInfoArray; std::vector subgroupKernelInfoArray; - GraphicsAllocation *constantSurface = nullptr; - GraphicsAllocation *globalSurface = nullptr; - GraphicsAllocation *exportedFunctionsSurface = nullptr; - - size_t globalVarTotalSize = 0U; - cl_build_status buildStatus = CL_BUILD_NONE; bool isCreatedFromBinary = false; @@ -333,6 +327,10 @@ class Program : public BaseObject<_cl_program> { bool allowNonUniform = false; struct BuildInfo : public NonCopyableClass { + GraphicsAllocation *constantSurface = nullptr; + GraphicsAllocation *globalSurface = nullptr; + GraphicsAllocation *exportedFunctionsSurface = nullptr; + size_t globalVarTotalSize = 0U; std::unique_ptr linkerInput; Linker::RelocatedSymbolsMap symbols{}; std::string buildLog{}; diff --git a/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp b/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp index 87a3b839e2..2d3773bce9 100644 --- a/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp @@ -2007,8 +2007,8 @@ TEST_F(ReflectionSurfaceConstantValuesPatchingTest, GivenBlockWithGlobalMemoryAn MockContext context(pClDevice); MockParentKernel *parentKernel = MockParentKernel::create(context, false, true, false); - if (parentKernel->mockProgram->getGlobalSurface()) { - pDevice->getMemoryManager()->freeGraphicsMemory(parentKernel->mockProgram->getGlobalSurface()); + if (parentKernel->mockProgram->getGlobalSurface(pClDevice->getRootDeviceIndex())) { + pDevice->getMemoryManager()->freeGraphicsMemory(parentKernel->mockProgram->getGlobalSurface(pClDevice->getRootDeviceIndex())); parentKernel->mockProgram->setGlobalSurface(nullptr); } @@ -2083,8 +2083,8 @@ TEST_F(ReflectionSurfaceConstantValuesPatchingTest, GivenBlockWithConstantMemory MockContext context(pClDevice); MockParentKernel *parentKernel = MockParentKernel::create(context, false, false, true); - if (parentKernel->mockProgram->getConstantSurface()) { - pDevice->getMemoryManager()->freeGraphicsMemory(parentKernel->mockProgram->getConstantSurface()); + if (parentKernel->mockProgram->getConstantSurface(pClDevice->getRootDeviceIndex())) { + pDevice->getMemoryManager()->freeGraphicsMemory(parentKernel->mockProgram->getConstantSurface(pClDevice->getRootDeviceIndex())); parentKernel->mockProgram->setConstantSurface(nullptr); } @@ -2127,7 +2127,7 @@ using KernelReflectionMultiDeviceTest = MultiRootDeviceFixture; TEST_F(KernelReflectionMultiDeviceTest, GivenNoKernelArgsWhenObtainingKernelReflectionSurfaceThenParamsAreCorrect) { REQUIRE_DEVICE_ENQUEUE_OR_SKIP(device.get()); - MockProgram program(*device->getExecutionEnvironment()); + MockProgram program(*device->getExecutionEnvironment(), context.get(), false, &device->getDevice()); KernelInfo *blockInfo = new KernelInfo; KernelInfo &info = *blockInfo; cl_queue_properties properties[1] = {0}; @@ -2176,7 +2176,7 @@ TEST_F(KernelReflectionMultiDeviceTest, GivenNoKernelArgsWhenObtainingKernelRefl TEST_F(KernelReflectionMultiDeviceTest, GivenDeviceQueueKernelArgWhenObtainingKernelReflectionSurfaceThenParamsAreCorrect) { REQUIRE_DEVICE_ENQUEUE_OR_SKIP(device.get()); - MockProgram program(*device->getExecutionEnvironment()); + MockProgram program(*device->getExecutionEnvironment(), context.get(), false, &device->getDevice()); KernelInfo *blockInfo = new KernelInfo; KernelInfo &info = *blockInfo; diff --git a/opencl/test/unit_test/kernel/kernel_tests.cpp b/opencl/test/unit_test/kernel/kernel_tests.cpp index 6cd11f794f..1a4dd07d9a 100644 --- a/opencl/test/unit_test/kernel/kernel_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_tests.cpp @@ -1681,7 +1681,7 @@ HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenExportedFun MockProgram program(*pDevice->getExecutionEnvironment()); auto exportedFunctionsSurface = std::make_unique(); - program.exportedFunctionsSurface = exportedFunctionsSurface.get(); + program.buildInfos[pDevice->getRootDeviceIndex()].exportedFunctionsSurface = exportedFunctionsSurface.get(); MockContext ctx; program.setContext(&ctx); std::unique_ptr pKernel(new MockKernel(&program, *pKernelInfo, *pClDevice)); @@ -1689,7 +1689,7 @@ HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenExportedFun EXPECT_EQ(0u, commandStreamReceiver.makeResidentAllocations.size()); pKernel->makeResident(pDevice->getGpgpuCommandStreamReceiver()); - EXPECT_TRUE(commandStreamReceiver.isMadeResident(program.exportedFunctionsSurface)); + EXPECT_TRUE(commandStreamReceiver.isMadeResident(program.buildInfos[pDevice->getRootDeviceIndex()].exportedFunctionsSurface)); // check getResidency as well std::vector residencySurfaces; @@ -1720,13 +1720,13 @@ HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenGlobalBuffe MockProgram program(*pDevice->getExecutionEnvironment()); MockContext ctx; program.setContext(&ctx); - program.globalSurface = new MockGraphicsAllocation(); + program.buildInfos[pDevice->getRootDeviceIndex()].globalSurface = new MockGraphicsAllocation(); std::unique_ptr pKernel(new MockKernel(&program, *pKernelInfo, *pClDevice)); ASSERT_EQ(CL_SUCCESS, pKernel->initialize()); EXPECT_EQ(0u, commandStreamReceiver.makeResidentAllocations.size()); pKernel->makeResident(pDevice->getGpgpuCommandStreamReceiver()); - EXPECT_TRUE(commandStreamReceiver.isMadeResident(program.globalSurface)); + EXPECT_TRUE(commandStreamReceiver.isMadeResident(program.buildInfos[pDevice->getRootDeviceIndex()].globalSurface)); std::vector residencySurfaces; pKernel->getResidency(residencySurfaces); @@ -1738,7 +1738,7 @@ HWTEST_F(KernelResidencyTest, givenKernelWhenMakeResidentIsCalledThenGlobalBuffe s->makeResident(csrMock); delete s; } - EXPECT_EQ(1U, csrMock.residency.count(program.globalSurface->getUnderlyingBuffer())); + EXPECT_EQ(1U, csrMock.residency.count(program.buildInfos[pDevice->getRootDeviceIndex()].globalSurface->getUnderlyingBuffer())); mockCsrExecEnv = std::move(csrMock.mockExecutionEnvironment); } diff --git a/opencl/test/unit_test/mocks/mock_kernel.h b/opencl/test/unit_test/mocks/mock_kernel.h index acbd7a7159..c765a17253 100644 --- a/opencl/test/unit_test/mocks/mock_kernel.h +++ b/opencl/test/unit_test/mocks/mock_kernel.h @@ -286,7 +286,7 @@ class MockKernelWithInternals { mockContext = context; } - mockProgram = new MockProgram(*deviceArg.getExecutionEnvironment(), context, false, nullptr); + mockProgram = new MockProgram(*deviceArg.getExecutionEnvironment(), context, false, &deviceArg.getDevice()); mockKernel = new MockKernel(mockProgram, kernelInfo, deviceArg); mockKernel->setCrossThreadData(&crossThreadData, sizeof(crossThreadData)); mockKernel->setSshLocal(&sshLocal, sizeof(sshLocal)); diff --git a/opencl/test/unit_test/mocks/mock_program.h b/opencl/test/unit_test/mocks/mock_program.h index bcae519783..c326fbe468 100644 --- a/opencl/test/unit_test/mocks/mock_program.h +++ b/opencl/test/unit_test/mocks/mock_program.h @@ -38,15 +38,12 @@ class MockProgram : public Program { using Program::areSpecializationConstantsInitialized; using Program::blockKernelManager; using Program::buildInfos; - using Program::constantSurface; using Program::context; using Program::createdFrom; using Program::debugData; using Program::debugDataSize; - using Program::exportedFunctionsSurface; using Program::extractInternalOptions; using Program::getKernelInfo; - using Program::globalSurface; using Program::irBinary; using Program::irBinarySize; using Program::isSpirV; @@ -77,10 +74,22 @@ class MockProgram : public Program { } std::string &getInternalOptions() { return internalOptions; }; void setConstantSurface(GraphicsAllocation *gfxAllocation) { - constantSurface = gfxAllocation; + if (gfxAllocation) { + buildInfos[gfxAllocation->getRootDeviceIndex()].constantSurface = gfxAllocation; + } else { + for (auto &buildInfo : buildInfos) { + buildInfo.constantSurface = nullptr; + } + } } void setGlobalSurface(GraphicsAllocation *gfxAllocation) { - globalSurface = gfxAllocation; + if (gfxAllocation) { + buildInfos[gfxAllocation->getRootDeviceIndex()].globalSurface = gfxAllocation; + } else { + for (auto &buildInfo : buildInfos) { + buildInfo.globalSurface = nullptr; + } + } } void setDevice(Device *device) { this->pDevice = device; diff --git a/opencl/test/unit_test/program/program_data_tests.cpp b/opencl/test/unit_test/program/program_data_tests.cpp index db9fc32e3d..36371ccb9c 100644 --- a/opencl/test/unit_test/program/program_data_tests.cpp +++ b/opencl/test/unit_test/program/program_data_tests.cpp @@ -70,7 +70,7 @@ class ProgramDataTestBase : public testing::Test, size_t setupConstantAllocation() { size_t constSize = strlen(constValue) + 1; - EXPECT_EQ(nullptr, pProgram->getConstantSurface()); + EXPECT_EQ(nullptr, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); SPatchAllocateConstantMemorySurfaceProgramBinaryInfo allocateConstMemorySurface; allocateConstMemorySurface.Token = PATCH_TOKEN_ALLOCATE_CONSTANT_MEMORY_SURFACE_PROGRAM_BINARY_INFO; @@ -96,7 +96,7 @@ class ProgramDataTestBase : public testing::Test, size_t setupGlobalAllocation() { size_t globalSize = strlen(globalValue) + 1; - EXPECT_EQ(nullptr, pProgram->getGlobalSurface()); + EXPECT_EQ(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo allocateGlobalMemorySurface; allocateGlobalMemorySurface.Token = PATCH_TOKEN_ALLOCATE_GLOBAL_MEMORY_SURFACE_PROGRAM_BINARY_INFO; @@ -178,8 +178,8 @@ TEST_F(ProgramDataTest, WhenAllocatingConstantMemorySurfaceThenUnderlyingBufferI buildAndDecodeProgramPatchList(); - EXPECT_NE(nullptr, pProgram->getConstantSurface()); - EXPECT_EQ(0, memcmp(constValue, pProgram->getConstantSurface()->getUnderlyingBuffer(), constSize)); + EXPECT_NE(nullptr, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(0, memcmp(constValue, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->getUnderlyingBuffer(), constSize)); } TEST_F(ProgramDataTest, givenProgramWhenAllocatingConstantMemorySurfaceThenProperDeviceBitfieldIsPassed) { @@ -191,7 +191,7 @@ TEST_F(ProgramDataTest, givenProgramWhenAllocatingConstantMemorySurfaceThenPrope EXPECT_NE(pProgram->getDevice().getDeviceBitfield(), memoryManager->recentlyPassedDeviceBitfield); setupConstantAllocation(); buildAndDecodeProgramPatchList(); - EXPECT_NE(nullptr, pProgram->getConstantSurface()); + EXPECT_NE(nullptr, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); EXPECT_EQ(pProgram->getDevice().getDeviceBitfield(), memoryManager->recentlyPassedDeviceBitfield); std::swap(memoryManagerBackup, executionEnvironment->memoryManager); } @@ -210,8 +210,8 @@ TEST_F(ProgramDataTest, whenGlobalConstantsAreExportedThenAllocateSurfacesAsSvm) programInfo.linkerInput = std::move(mockLinkerInput); this->pProgram->processProgramInfo(programInfo); - ASSERT_NE(nullptr, pProgram->getConstantSurface()); - EXPECT_NE(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getConstantSurface()->getGpuAddress()))); + ASSERT_NE(nullptr, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_NE(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddress()))); } TEST_F(ProgramDataTest, whenGlobalConstantsAreNotExportedThenAllocateSurfacesAsNonSvm) { @@ -228,8 +228,9 @@ TEST_F(ProgramDataTest, whenGlobalConstantsAreNotExportedThenAllocateSurfacesAsN programInfo.linkerInput = std::move(mockLinkerInput); this->pProgram->processProgramInfo(programInfo); - ASSERT_NE(nullptr, pProgram->getConstantSurface()); - EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getConstantSurface()->getGpuAddress()))); + ASSERT_NE(nullptr, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast( + pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddress()))); } TEST_F(ProgramDataTest, whenGlobalConstantsAreExportedButContextUnavailableThenAllocateSurfacesAsNonSvm) { @@ -251,8 +252,9 @@ TEST_F(ProgramDataTest, whenGlobalConstantsAreExportedButContextUnavailableThenA pProgram->context = pContext; - ASSERT_NE(nullptr, pProgram->getConstantSurface()); - EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getConstantSurface()->getGpuAddress()))); + ASSERT_NE(nullptr, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast( + pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddress()))); } TEST_F(ProgramDataTest, whenGlobalVariablesAreExportedThenAllocateSurfacesAsSvm) { @@ -268,8 +270,8 @@ TEST_F(ProgramDataTest, whenGlobalVariablesAreExportedThenAllocateSurfacesAsSvm) programInfo.linkerInput = std::move(mockLinkerInput); this->pProgram->processProgramInfo(programInfo); - ASSERT_NE(nullptr, pProgram->getGlobalSurface()); - EXPECT_NE(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getGlobalSurface()->getGpuAddress()))); + ASSERT_NE(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_NE(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddress()))); } TEST_F(ProgramDataTest, whenGlobalVariablesAreExportedButContextUnavailableThenAllocateSurfacesAsNonSvm) { @@ -291,8 +293,8 @@ TEST_F(ProgramDataTest, whenGlobalVariablesAreExportedButContextUnavailableThenA pProgram->context = pContext; - ASSERT_NE(nullptr, pProgram->getGlobalSurface()); - EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getGlobalSurface()->getGpuAddress()))); + ASSERT_NE(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddress()))); } TEST_F(ProgramDataTest, whenGlobalVariablesAreNotExportedThenAllocateSurfacesAsNonSvm) { @@ -309,8 +311,8 @@ TEST_F(ProgramDataTest, whenGlobalVariablesAreNotExportedThenAllocateSurfacesAsN programInfo.linkerInput = std::move(mockLinkerInput); this->pProgram->processProgramInfo(programInfo); - ASSERT_NE(nullptr, pProgram->getGlobalSurface()); - EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getGlobalSurface()->getGpuAddress()))); + ASSERT_NE(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast(pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddress()))); } TEST_F(ProgramDataTest, givenConstantAllocationThatIsInUseByGpuWhenProgramIsBeingDestroyedThenItIsAddedToTemporaryAllocationList) { @@ -321,7 +323,7 @@ TEST_F(ProgramDataTest, givenConstantAllocationThatIsInUseByGpuWhenProgramIsBein auto &csr = *pPlatform->getClDevice(0)->getDefaultEngine().commandStreamReceiver; auto tagAddress = csr.getTagAddress(); - auto constantSurface = pProgram->getConstantSurface(); + auto constantSurface = pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex()); constantSurface->updateTaskCount(*tagAddress + 1, csr.getOsContext().getContextId()); EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); @@ -338,7 +340,7 @@ TEST_F(ProgramDataTest, givenGlobalAllocationThatIsInUseByGpuWhenProgramIsBeingD auto &csr = *pPlatform->getClDevice(0)->getDefaultEngine().commandStreamReceiver; auto tagAddress = csr.getTagAddress(); - auto globalSurface = pProgram->getGlobalSurface(); + auto globalSurface = pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex()); globalSurface->updateTaskCount(*tagAddress + 1, csr.getOsContext().getContextId()); EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); @@ -354,19 +356,19 @@ TEST_F(ProgramDataTest, GivenDeviceForcing32BitMessagesWhenConstAllocationIsPres buildAndDecodeProgramPatchList(); - EXPECT_NE(nullptr, pProgram->getConstantSurface()); - EXPECT_EQ(0, memcmp(constValue, pProgram->getConstantSurface()->getUnderlyingBuffer(), constSize)); + EXPECT_NE(nullptr, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(0, memcmp(constValue, pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->getUnderlyingBuffer(), constSize)); if (is64bit) { - EXPECT_TRUE(pProgram->getConstantSurface()->is32BitAllocation()); + EXPECT_TRUE(pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->is32BitAllocation()); } } TEST_F(ProgramDataTest, WhenAllocatingGlobalMemorySurfaceThenUnderlyingBufferIsSetCorrectly) { auto globalSize = setupGlobalAllocation(); buildAndDecodeProgramPatchList(); - EXPECT_NE(nullptr, pProgram->getGlobalSurface()); - EXPECT_EQ(0, memcmp(globalValue, pProgram->getGlobalSurface()->getUnderlyingBuffer(), globalSize)); + EXPECT_NE(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(0, memcmp(globalValue, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())->getUnderlyingBuffer(), globalSize)); } TEST_F(ProgramDataTest, givenProgramWhenAllocatingGlobalMemorySurfaceThenProperDeviceBitfieldIsPassed) { auto executionEnvironment = pProgram->getDevice().getExecutionEnvironment(); @@ -378,7 +380,7 @@ TEST_F(ProgramDataTest, givenProgramWhenAllocatingGlobalMemorySurfaceThenProperD setupGlobalAllocation(); buildAndDecodeProgramPatchList(); - EXPECT_NE(nullptr, pProgram->getGlobalSurface()); + EXPECT_NE(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); EXPECT_EQ(pProgram->getDevice().getDeviceBitfield(), memoryManager->recentlyPassedDeviceBitfield); std::swap(memoryManagerBackup, executionEnvironment->memoryManager); } @@ -387,7 +389,7 @@ TEST_F(ProgramDataTest, Given32BitDeviceWhenGlobalMemorySurfaceIsPresentThenItHa char globalValue[] = "55667788"; size_t globalSize = strlen(globalValue) + 1; this->pContext->getDevice(0)->getMemoryManager()->setForce32BitAllocations(true); - EXPECT_EQ(nullptr, pProgram->getGlobalSurface()); + EXPECT_EQ(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo allocateGlobalMemorySurface; allocateGlobalMemorySurface.Token = PATCH_TOKEN_ALLOCATE_GLOBAL_MEMORY_SURFACE_PROGRAM_BINARY_INFO; @@ -410,10 +412,10 @@ TEST_F(ProgramDataTest, Given32BitDeviceWhenGlobalMemorySurfaceIsPresentThenItHa buildAndDecodeProgramPatchList(); - EXPECT_NE(nullptr, pProgram->getGlobalSurface()); - EXPECT_EQ(0, memcmp(globalValue, pProgram->getGlobalSurface()->getUnderlyingBuffer(), globalSize)); + EXPECT_NE(nullptr, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())); + EXPECT_EQ(0, memcmp(globalValue, pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())->getUnderlyingBuffer(), globalSize)); if (is64bit) { - EXPECT_TRUE(pProgram->getGlobalSurface()->is32BitAllocation()); + EXPECT_TRUE(pProgram->getGlobalSurface(pContext->getDevice(0)->getRootDeviceIndex())->is32BitAllocation()); } delete[] pAllocateGlobalMemorySurface; @@ -433,12 +435,13 @@ TEST(ProgramScopeMetadataTest, WhenPatchingGlobalSurfaceThenPickProperSourceBuff program.pDevice = &device.getDevice(); NEO::populateProgramInfo(programInfo, decodedProgram); program.processProgramInfo(programInfo); - ASSERT_NE(nullptr, program.globalSurface); - ASSERT_NE(nullptr, program.constantSurface); - ASSERT_NE(nullptr, program.globalSurface->getUnderlyingBuffer()); - ASSERT_NE(nullptr, program.constantSurface->getUnderlyingBuffer()); - EXPECT_EQ(static_cast(program.globalSurface->getGpuAddressToPatch()), *reinterpret_cast(program.constantSurface->getUnderlyingBuffer())); - EXPECT_EQ(static_cast(program.constantSurface->getGpuAddressToPatch()), *reinterpret_cast(program.globalSurface->getUnderlyingBuffer())); + auto &buildInfo = program.buildInfos[device.getRootDeviceIndex()]; + ASSERT_NE(nullptr, buildInfo.globalSurface); + ASSERT_NE(nullptr, buildInfo.constantSurface); + ASSERT_NE(nullptr, buildInfo.globalSurface->getUnderlyingBuffer()); + ASSERT_NE(nullptr, buildInfo.constantSurface->getUnderlyingBuffer()); + EXPECT_EQ(static_cast(buildInfo.globalSurface->getGpuAddressToPatch()), *reinterpret_cast(buildInfo.constantSurface->getUnderlyingBuffer())); + EXPECT_EQ(static_cast(buildInfo.constantSurface->getGpuAddressToPatch()), *reinterpret_cast(buildInfo.globalSurface->getUnderlyingBuffer())); } TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeConstantBufferPatchTokensAreReadThenConstantPointerOffsetIsPatchedWith32bitPointer) { @@ -449,7 +452,7 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeConstantB MockProgram *prog = pProgram; // simulate case when constant surface was not allocated - EXPECT_EQ(nullptr, prog->getConstantSurface()); + EXPECT_EQ(nullptr, prog->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); ProgramInfo programInfo; programInfo.prepareLinkerInputStorage(); NEO::LinkerInput::RelocationInfo relocInfo; @@ -486,7 +489,7 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeGlobalPoi MockProgram *prog = pProgram; // simulate case when constant surface was not allocated - EXPECT_EQ(nullptr, prog->getConstantSurface()); + EXPECT_EQ(nullptr, prog->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())); ProgramInfo programInfo; programInfo.prepareLinkerInputStorage(); @@ -584,6 +587,7 @@ TEST_F(ProgramDataTest, whenLinkerInputValidThenIsaIsProperlyPatched) { linkerInput->exportedFunctionsSegmentId = 0; auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); MockProgram program{*device->getExecutionEnvironment(), nullptr, false, device.get()}; + auto &buildInfo = program.buildInfos[device->getRootDeviceIndex()]; KernelInfo kernelInfo = {}; kernelInfo.name = "onlyKernel"; std::vector kernelHeap; @@ -595,35 +599,35 @@ TEST_F(ProgramDataTest, whenLinkerInputValidThenIsaIsProperlyPatched) { program.getKernelInfoArray().push_back(&kernelInfo); program.setLinkerInput(device->getRootDeviceIndex(), std::move(linkerInput)); - program.exportedFunctionsSurface = kernelInfo.kernelAllocation; + buildInfo.exportedFunctionsSurface = kernelInfo.kernelAllocation; std::vector globalVariablesBuffer; globalVariablesBuffer.resize(32, 7); std::vector globalConstantsBuffer; globalConstantsBuffer.resize(32, 7); std::vector globalVariablesInitData{32, 0}; std::vector globalConstantsInitData{32, 0}; - program.globalSurface = new MockGraphicsAllocation(globalVariablesBuffer.data(), globalVariablesBuffer.size()); - program.constantSurface = new MockGraphicsAllocation(globalConstantsBuffer.data(), globalConstantsBuffer.size()); + buildInfo.globalSurface = new MockGraphicsAllocation(globalVariablesBuffer.data(), globalVariablesBuffer.size()); + buildInfo.constantSurface = new MockGraphicsAllocation(globalConstantsBuffer.data(), globalConstantsBuffer.size()); program.pDevice = &this->pContext->getDevice(0)->getDevice(); auto ret = program.linkBinary(pProgram->pDevice, globalConstantsInitData.data(), globalVariablesInitData.data()); EXPECT_EQ(CL_SUCCESS, ret); - linkerInput.reset(static_cast *>(program.buildInfos[program.pDevice->getRootDeviceIndex()].linkerInput.release())); + linkerInput.reset(static_cast *>(buildInfo.linkerInput.release())); for (size_t i = 0; i < linkerInput->relocations.size(); ++i) { - auto expectedPatch = program.globalSurface->getGpuAddress() + linkerInput->symbols[linkerInput->relocations[0][0].symbolName].offset; + auto expectedPatch = buildInfo.globalSurface->getGpuAddress() + linkerInput->symbols[linkerInput->relocations[0][0].symbolName].offset; auto relocationAddress = kernelHeap.data() + linkerInput->relocations[0][0].offset; EXPECT_EQ(static_cast(expectedPatch), *reinterpret_cast(relocationAddress)) << i; } program.getKernelInfoArray().clear(); - delete program.globalSurface; - program.globalSurface = nullptr; - delete program.constantSurface; - program.constantSurface = nullptr; + delete buildInfo.globalSurface; + buildInfo.globalSurface = nullptr; + delete buildInfo.constantSurface; + buildInfo.constantSurface = nullptr; } TEST_F(ProgramDataTest, whenRelocationsAreNotNeededThenIsaIsPreserved) { @@ -633,6 +637,7 @@ TEST_F(ProgramDataTest, whenRelocationsAreNotNeededThenIsaIsPreserved) { auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); MockProgram program{*device->getExecutionEnvironment(), nullptr, false, device.get()}; + auto &buildInfo = program.buildInfos[device->getRootDeviceIndex()]; KernelInfo kernelInfo = {}; kernelInfo.name = "onlyKernel"; std::vector kernelHeapData; @@ -651,8 +656,8 @@ TEST_F(ProgramDataTest, whenRelocationsAreNotNeededThenIsaIsPreserved) { globalConstantsBuffer.resize(32, 7); std::vector globalVariablesInitData{32, 0}; std::vector globalConstantsInitData{32, 0}; - program.globalSurface = new MockGraphicsAllocation(globalVariablesBuffer.data(), globalVariablesBuffer.size()); - program.constantSurface = new MockGraphicsAllocation(globalConstantsBuffer.data(), globalConstantsBuffer.size()); + buildInfo.globalSurface = new MockGraphicsAllocation(globalVariablesBuffer.data(), globalVariablesBuffer.size()); + buildInfo.constantSurface = new MockGraphicsAllocation(globalConstantsBuffer.data(), globalConstantsBuffer.size()); program.pDevice = &this->pContext->getDevice(0)->getDevice(); @@ -661,8 +666,8 @@ TEST_F(ProgramDataTest, whenRelocationsAreNotNeededThenIsaIsPreserved) { EXPECT_EQ(kernelHeapData, kernelHeap); program.getKernelInfoArray().clear(); - delete program.globalSurface; - program.globalSurface = nullptr; - delete program.constantSurface; - program.constantSurface = nullptr; + delete buildInfo.globalSurface; + buildInfo.globalSurface = nullptr; + delete buildInfo.constantSurface; + buildInfo.constantSurface = nullptr; } diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index 25fb843eaf..3110cd1351 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -659,18 +659,18 @@ TEST_P(ProgramFromBinaryTest, givenProgramWhenItIsBeingBuildThenItContainsGraphi TEST_P(ProgramFromBinaryTest, whenProgramIsBeingRebuildThenOutdatedGlobalBuffersAreFreed) { cl_device_id device = pClDevice; pProgram->build(1, &device, nullptr, nullptr, nullptr, true); - EXPECT_EQ(nullptr, pProgram->constantSurface); - EXPECT_EQ(nullptr, pProgram->globalSurface); + EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface); + EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface); - pProgram->constantSurface = new MockGraphicsAllocation(); + pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface = new MockGraphicsAllocation(); pProgram->processGenBinary(); - EXPECT_EQ(nullptr, pProgram->constantSurface); - EXPECT_EQ(nullptr, pProgram->globalSurface); + EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface); + EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface); - pProgram->globalSurface = new MockGraphicsAllocation(); + pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface = new MockGraphicsAllocation(); pProgram->processGenBinary(); - EXPECT_EQ(nullptr, pProgram->constantSurface); - EXPECT_EQ(nullptr, pProgram->globalSurface); + EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].constantSurface); + EXPECT_EQ(nullptr, pProgram->buildInfos[pClDevice->getRootDeviceIndex()].globalSurface); } TEST_P(ProgramFromBinaryTest, givenProgramWhenCleanKernelInfoIsCalledThenKernelAllocationIsFreed) { @@ -1384,10 +1384,10 @@ HWTEST_F(PatchTokenTests, givenKernelRequiringConstantAllocationWhenMakeResident auto pKernelInfo = pProgram->getKernelInfo("test"); EXPECT_NE(nullptr, pKernelInfo->patchInfo.pAllocateStatelessConstantMemorySurfaceWithInitialization); - ASSERT_NE(nullptr, pProgram->getConstantSurface()); + ASSERT_NE(nullptr, pProgram->getConstantSurface(pClDevice->getRootDeviceIndex())); uint32_t expected_values[] = {0xabcd5432u, 0xaabb5533u}; - uint32_t *constBuff = reinterpret_cast(pProgram->getConstantSurface()->getUnderlyingBuffer()); + uint32_t *constBuff = reinterpret_cast(pProgram->getConstantSurface(pClDevice->getRootDeviceIndex())->getUnderlyingBuffer()); EXPECT_EQ(expected_values[0], constBuff[0]); EXPECT_EQ(expected_values[1], constBuff[1]); @@ -1409,7 +1409,7 @@ HWTEST_F(PatchTokenTests, givenKernelRequiringConstantAllocationWhenMakeResident //we expect kernel ISA here and constant allocation auto kernelIsa = pKernel->getKernelInfo().getGraphicsAllocation(); - auto constantAllocation = pProgram->getConstantSurface(); + auto constantAllocation = pProgram->getConstantSurface(pDevice->getRootDeviceIndex()); auto element = std::find(residencyVector.begin(), residencyVector.end(), kernelIsa); EXPECT_NE(residencyVector.end(), element); @@ -1417,7 +1417,7 @@ HWTEST_F(PatchTokenTests, givenKernelRequiringConstantAllocationWhenMakeResident EXPECT_NE(residencyVector.end(), element); auto crossThreadData = pKernel->getCrossThreadData(); - uint32_t *constBuffGpuAddr = reinterpret_cast(pProgram->getConstantSurface()->getGpuAddressToPatch()); + uint32_t *constBuffGpuAddr = reinterpret_cast(pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddressToPatch()); uintptr_t *pDst = reinterpret_cast(crossThreadData + pKernelInfo->patchInfo.pAllocateStatelessConstantMemorySurfaceWithInitialization->DataParamOffset); EXPECT_EQ(*pDst, reinterpret_cast(constBuffGpuAddr));