From 97154f7f98c6ecbe4920b23c22fad974524b05cf Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 13 Oct 2020 11:41:48 +0200 Subject: [PATCH] Use ProgramInfo instead of Program in sip kernel Related-To: NEO-5001 Change-Id: I58eda3ecc52fe1215ea8bbc35f97eea3a9d848e0 Signed-off-by: Mateusz Jablonski --- opencl/source/helpers/built_ins_helper.cpp | 36 ++++---- opencl/source/helpers/built_ins_helper.h | 9 +- .../source/program/process_device_binary.cpp | 27 +++--- opencl/test/unit_test/built_ins/sip_tests.cpp | 8 +- .../unit_test/helpers/built_ins_helper.cpp | 11 +-- opencl/test/unit_test/main.cpp | 4 +- opencl/test/unit_test/mocks/mock_program.cpp | 91 ++++++++----------- opencl/test/unit_test/mocks/mock_program.h | 31 +++---- opencl/test/unit_test/mocks/mock_sip.cpp | 5 +- opencl/test/unit_test/mocks/mock_sip.h | 4 +- .../linux/drm_command_stream_tests.cpp | 8 +- .../windows/device_command_stream_tests.cpp | 8 +- opencl/test/unit_test/ult_config_listener.cpp | 7 ++ shared/source/built_ins/built_ins.cpp | 16 +--- shared/source/built_ins/sip.cpp | 17 ++-- shared/source/built_ins/sip.h | 10 +- shared/test/unit_test/main.cpp | 4 +- .../unit_test/preemption/preemption_tests.cpp | 2 +- 18 files changed, 127 insertions(+), 171 deletions(-) diff --git a/opencl/source/helpers/built_ins_helper.cpp b/opencl/source/helpers/built_ins_helper.cpp index 88c416f95f..3867417a63 100644 --- a/opencl/source/helpers/built_ins_helper.cpp +++ b/opencl/source/helpers/built_ins_helper.cpp @@ -8,29 +8,31 @@ #include "opencl/source/helpers/built_ins_helper.h" #include "shared/source/device/device.h" +#include "shared/source/device_binary_format/device_binary_formats.h" -#include "opencl/source/program/program.h" +#include "opencl/source/program/kernel_info.h" namespace NEO { const SipKernel &initSipKernel(SipKernelType type, Device &device) { return device.getBuiltIns()->getSipKernel(type, device); } -Program *createProgramForSip(ExecutionEnvironment &executionEnvironment, - Context *context, - std::vector &binary, - size_t size, - cl_int *errcodeRet, - Device *device) { +ProgramInfo createProgramInfoForSip(std::vector &binary, size_t size, const Device &device) { - cl_int retVal = 0; - auto program = Program::createFromGenBinary(executionEnvironment, - context, - binary.data(), - size, - true, - &retVal, - device); - DEBUG_BREAK_IF(retVal != 0); - return program; + ProgramInfo programInfo; + auto blob = ArrayRef(reinterpret_cast(binary.data()), binary.size()); + SingleDeviceBinary deviceBinary = {}; + deviceBinary.deviceBinary = blob; + std::string decodeErrors; + std::string decodeWarnings; + + DecodeError decodeError; + DeviceBinaryFormat singleDeviceBinaryFormat; + std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, deviceBinary, decodeErrors, decodeWarnings); + UNRECOVERABLE_IF(DecodeError::Success != decodeError); + + auto success = programInfo.kernelInfos[0]->createKernelAllocation(device); + UNRECOVERABLE_IF(!success); + + return programInfo; } } // namespace NEO diff --git a/opencl/source/helpers/built_ins_helper.h b/opencl/source/helpers/built_ins_helper.h index b94394b9d5..173484a543 100644 --- a/opencl/source/helpers/built_ins_helper.h +++ b/opencl/source/helpers/built_ins_helper.h @@ -7,16 +7,11 @@ #pragma once #include "shared/source/built_ins/built_ins.h" -#include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/program/program_info.h" namespace NEO { class Device; const SipKernel &initSipKernel(SipKernelType type, Device &device); -Program *createProgramForSip(ExecutionEnvironment &executionEnvironment, - Context *context, - std::vector &binary, - size_t size, - int *errcodeRet, - Device *device); +ProgramInfo createProgramInfoForSip(std::vector &binary, size_t size, const Device &device); } // namespace NEO diff --git a/opencl/source/program/process_device_binary.cpp b/opencl/source/program/process_device_binary.cpp index 58c5973a22..1ce7d740f0 100644 --- a/opencl/source/program/process_device_binary.cpp +++ b/opencl/source/program/process_device_binary.cpp @@ -52,7 +52,7 @@ const KernelInfo *Program::getKernelInfo(size_t ordinal) const { } cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const void *variablesInitData) { - auto linkerInput = pDevice ? getLinkerInput(pDevice->getRootDeviceIndex()) : nullptr; + auto linkerInput = getLinkerInput(pDevice->getRootDeviceIndex()); if (linkerInput == nullptr) { return CL_SUCCESS; } @@ -162,24 +162,23 @@ cl_int Program::processProgramInfo(ProgramInfo &src) { size_t slmAvailable = 0U; NEO::DeviceInfoKernelPayloadConstants deviceInfoConstants; LinkerInput *linkerInput = nullptr; - if (this->pDevice) { - slmAvailable = static_cast(this->pDevice->getDeviceInfo().localMemSize); - deviceInfoConstants.maxWorkGroupSize = (uint32_t)this->pDevice->getDeviceInfo().maxWorkGroupSize; - deviceInfoConstants.computeUnitsUsedForScratch = this->pDevice->getDeviceInfo().computeUnitsUsedForScratch; - deviceInfoConstants.slmWindowSize = (uint32_t)this->pDevice->getDeviceInfo().localMemSize; - if (requiresLocalMemoryWindowVA(src)) { - deviceInfoConstants.slmWindow = this->executionEnvironment.memoryManager->getReservedMemory(MemoryConstants::slmWindowSize, MemoryConstants::slmWindowAlignment); - } - linkerInput = src.linkerInput.get(); - setLinkerInput(pDevice->getRootDeviceIndex(), std::move(src.linkerInput)); + slmAvailable = static_cast(this->pDevice->getDeviceInfo().localMemSize); + deviceInfoConstants.maxWorkGroupSize = (uint32_t)this->pDevice->getDeviceInfo().maxWorkGroupSize; + deviceInfoConstants.computeUnitsUsedForScratch = this->pDevice->getDeviceInfo().computeUnitsUsedForScratch; + deviceInfoConstants.slmWindowSize = (uint32_t)this->pDevice->getDeviceInfo().localMemSize; + if (requiresLocalMemoryWindowVA(src)) { + deviceInfoConstants.slmWindow = this->executionEnvironment.memoryManager->getReservedMemory(MemoryConstants::slmWindowSize, MemoryConstants::slmWindowAlignment); } + linkerInput = src.linkerInput.get(); + setLinkerInput(pDevice->getRootDeviceIndex(), std::move(src.linkerInput)); + if (slmNeeded > slmAvailable) { return CL_OUT_OF_RESOURCES; } this->kernelInfoArray = std::move(src.kernelInfos); auto svmAllocsManager = context ? context->getSVMAllocsManager() : nullptr; - auto rootDeviceIndex = pDevice ? pDevice->getRootDeviceIndex() : 0u; + auto rootDeviceIndex = pDevice->getRootDeviceIndex(); if (src.globalConstants.size != 0) { UNRECOVERABLE_IF(nullptr == pDevice); buildInfos[rootDeviceIndex].constantSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalConstants.size, true, linkerInput, src.globalConstants.initData); @@ -188,7 +187,6 @@ cl_int Program::processProgramInfo(ProgramInfo &src) { buildInfos[rootDeviceIndex].globalVarTotalSize = src.globalVariables.size; if (src.globalVariables.size != 0) { - UNRECOVERABLE_IF(nullptr == pDevice); buildInfos[rootDeviceIndex].globalSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalVariables.size, false, linkerInput, src.globalVariables.initData); if (pDevice->getSpecializedDevice()->areOcl21FeaturesEnabled() == false) { buildInfos[rootDeviceIndex].globalVarTotalSize = 0u; @@ -197,11 +195,10 @@ cl_int Program::processProgramInfo(ProgramInfo &src) { for (auto &kernelInfo : this->kernelInfoArray) { cl_int retVal = CL_SUCCESS; - if (kernelInfo->heapInfo.KernelHeapSize && this->pDevice) { + if (kernelInfo->heapInfo.KernelHeapSize) { retVal = kernelInfo->createKernelAllocation(*this->pDevice) ? CL_SUCCESS : CL_OUT_OF_HOST_MEMORY; } - DEBUG_BREAK_IF(kernelInfo->heapInfo.KernelHeapSize && !this->pDevice); if (retVal != CL_SUCCESS) { return retVal; } diff --git a/opencl/test/unit_test/built_ins/sip_tests.cpp b/opencl/test/unit_test/built_ins/sip_tests.cpp index df3ed56521..7871fc36eb 100644 --- a/opencl/test/unit_test/built_ins/sip_tests.cpp +++ b/opencl/test/unit_test/built_ins/sip_tests.cpp @@ -82,16 +82,16 @@ TEST(Sip, GivenSipLlWhenGettingMetadataThenMetadataRequiredByCompilerIsReturned) } TEST(Sip, WhenGettingTypeThenCorrectTypeIsReturned) { - SipKernel csr{SipKernelType::Csr, GlobalMockSipProgram::getSipProgramWithCustomBinary()}; + SipKernel csr{SipKernelType::Csr, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()}; EXPECT_EQ(SipKernelType::Csr, csr.getType()); - SipKernel dbgCsr{SipKernelType::DbgCsr, GlobalMockSipProgram::getSipProgramWithCustomBinary()}; + SipKernel dbgCsr{SipKernelType::DbgCsr, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()}; EXPECT_EQ(SipKernelType::DbgCsr, dbgCsr.getType()); - SipKernel dbgCsrLocal{SipKernelType::DbgCsrLocal, GlobalMockSipProgram::getSipProgramWithCustomBinary()}; + SipKernel dbgCsrLocal{SipKernelType::DbgCsrLocal, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()}; EXPECT_EQ(SipKernelType::DbgCsrLocal, dbgCsrLocal.getType()); - SipKernel undefined{SipKernelType::COUNT, GlobalMockSipProgram::getSipProgramWithCustomBinary()}; + SipKernel undefined{SipKernelType::COUNT, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()}; EXPECT_EQ(SipKernelType::COUNT, undefined.getType()); } diff --git a/opencl/test/unit_test/helpers/built_ins_helper.cpp b/opencl/test/unit_test/helpers/built_ins_helper.cpp index 83af9c0509..6d53efdf5f 100644 --- a/opencl/test/unit_test/helpers/built_ins_helper.cpp +++ b/opencl/test/unit_test/helpers/built_ins_helper.cpp @@ -29,14 +29,7 @@ const SipKernel &initSipKernel(SipKernelType type, Device &device) { MockSipData::called = true; return *MockSipData::mockSipKernel; } -Program *createProgramForSip(ExecutionEnvironment &executionEnvironment, - Context *context, - std::vector &binary, - size_t size, - cl_int *errcodeRet, - Device *device) { - GlobalMockSipProgram::sipProgram->incRefApi(); - GlobalMockSipProgram::sipProgram->resetAllocationState(); - return GlobalMockSipProgram::sipProgram; +ProgramInfo createProgramInfoForSip(std::vector &binary, size_t size, const Device &device) { + return GlobalMockSipProgram::getSipProgramInfo(); } } // namespace NEO diff --git a/opencl/test/unit_test/main.cpp b/opencl/test/unit_test/main.cpp index 703f0f1164..2432dfe862 100644 --- a/opencl/test/unit_test/main.cpp +++ b/opencl/test/unit_test/main.cpp @@ -147,12 +147,12 @@ LONG WINAPI UltExceptionFilter( #endif void initializeTestHelpers() { - GlobalMockSipProgram::initSipProgram(); + GlobalMockSipProgram::initSipProgramInfo(); MockSipData::mockSipKernel.reset(new MockSipKernel()); } void cleanTestHelpers() { - GlobalMockSipProgram::shutDownSipProgram(); + GlobalMockSipProgram::shutDownSipProgramInfo(); delete platformsImpl; } diff --git a/opencl/test/unit_test/mocks/mock_program.cpp b/opencl/test/unit_test/mocks/mock_program.cpp index 3e8fcfec8b..77e858cef5 100644 --- a/opencl/test/unit_test/mocks/mock_program.cpp +++ b/opencl/test/unit_test/mocks/mock_program.cpp @@ -23,9 +23,7 @@ #include "opencl/test/unit_test/mocks/mock_graphics_allocation.h" namespace NEO { -GlobalMockSipProgram *GlobalMockSipProgram::sipProgram; -ExecutionEnvironment GlobalMockSipProgram::executionEnvironment; - +ProgramInfo *GlobalMockSipProgram::globalSipProgramInfo; Device *MockProgram::getDevicePtr() { return this->pDevice; } std::string MockProgram::getCachedFileName() const { @@ -35,63 +33,55 @@ std::string MockProgram::getCachedFileName() const { auto internalOpts = ArrayRef(this->internalOptions.c_str(), this->internalOptions.size()); return CompilerCache::getCachedFileName(hwInfo, input, opts, internalOpts); } -cl_int GlobalMockSipProgram::processGenBinary(uint32_t rootDeviceIndex) { - return CL_SUCCESS; -} -cl_int GlobalMockSipProgram::processGenBinaryOnce(uint32_t rootDeviceIndex) { - cl_int ret = Program::processGenBinary(rootDeviceIndex); - sipAllocationStorage = alignedMalloc(this->kernelInfoArray[0]->heapInfo.KernelHeapSize, MemoryConstants::pageSize); - this->kernelInfoArray[0]->kernelAllocation = new MockGraphicsAllocation(sipAllocationStorage, this->kernelInfoArray[0]->heapInfo.KernelHeapSize); - return ret; -} -void GlobalMockSipProgram::resetAllocationState() { - auto allocation = static_cast(this->kernelInfoArray[0]->kernelAllocation); - for (uint32_t index = 0u; index < allocation->usageInfos.size(); index++) { - this->kernelInfoArray[0]->kernelAllocation->releaseResidencyInOsContext(index); - } - allocation->resetInspectionIds(); -} -void GlobalMockSipProgram::initSipProgram() { - cl_int retVal = 0; +void GlobalMockSipProgram::initSipProgramInfo() { + globalSipProgramInfo = new ProgramInfo(); std::vector binary = MockCompilerInterface::getDummyGenBinary(); - executionEnvironment.prepareRootDeviceEnvironments(maxRootDeviceCount); - for (auto i = 0u; i < executionEnvironment.rootDeviceEnvironments.size(); i++) { - executionEnvironment.rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get()); - } - executionEnvironment.calculateMaxOsContextCount(); - executionEnvironment.incRefInternal(); - MockDevice device(&executionEnvironment, mockRootDeviceIndex); - sipProgram = Program::createFromGenBinary(executionEnvironment, - nullptr, - binary.data(), - binary.size(), - true, - &retVal, - &device); - DEBUG_BREAK_IF(retVal != 0); - sipProgram->processGenBinaryOnce(mockRootDeviceIndex); + auto blob = ArrayRef(reinterpret_cast(binary.data()), binary.size()); + SingleDeviceBinary deviceBinary = {}; + deviceBinary.deviceBinary = blob; + std::string decodeErrors; + std::string decodeWarnings; + + NEO::decodeSingleDeviceBinary(*globalSipProgramInfo, deviceBinary, decodeErrors, decodeWarnings); + auto sipAllocationStorage = alignedMalloc(globalSipProgramInfo->kernelInfos[0]->heapInfo.KernelHeapSize, MemoryConstants::pageSize); + memcpy(sipAllocationStorage, globalSipProgramInfo->kernelInfos[0]->heapInfo.pKernelHeap, globalSipProgramInfo->kernelInfos[0]->heapInfo.KernelHeapSize); + globalSipProgramInfo->kernelInfos[0]->heapInfo.pKernelHeap = sipAllocationStorage; + globalSipProgramInfo->kernelInfos[0]->kernelAllocation = new MockGraphicsAllocation(sipAllocationStorage, globalSipProgramInfo->kernelInfos[0]->heapInfo.KernelHeapSize); +} +void GlobalMockSipProgram::shutDownSipProgramInfo() { + deleteAllocation(); + delete globalSipProgramInfo; } void GlobalMockSipProgram::resetAllocation(GraphicsAllocation *allocation) { - this->kernelInfoArray[0]->kernelAllocation = allocation; + globalSipProgramInfo->kernelInfos[0]->kernelAllocation = allocation; } GraphicsAllocation *GlobalMockSipProgram::getAllocation() { - return this->kernelInfoArray[0]->kernelAllocation; + return globalSipProgramInfo->kernelInfos[0]->kernelAllocation; } void GlobalMockSipProgram::deleteAllocation() { - delete this->kernelInfoArray[0]->kernelAllocation; - alignedFree(sipAllocationStorage); - this->kernelInfoArray[0]->kernelAllocation = nullptr; + auto allocation = globalSipProgramInfo->kernelInfos[0]->kernelAllocation; + alignedFree(allocation->getUnderlyingBuffer()); + delete allocation; + globalSipProgramInfo->kernelInfos[0]->kernelAllocation = nullptr; } -void GlobalMockSipProgram::shutDownSipProgram() { - sipProgram->deleteAllocation(); - - delete sipProgram; +void GlobalMockSipProgram::resetAllocationState() { + auto allocation = static_cast(globalSipProgramInfo->kernelInfos[0]->kernelAllocation); + for (uint32_t index = 0u; index < allocation->usageInfos.size(); index++) { + globalSipProgramInfo->kernelInfos[0]->kernelAllocation->releaseResidencyInOsContext(index); + } + allocation->resetInspectionIds(); } - -Program *GlobalMockSipProgram::getSipProgramWithCustomBinary() { +ProgramInfo GlobalMockSipProgram::getSipProgramInfo() { + ProgramInfo programInfo; + programInfo.kernelInfos.push_back(new KernelInfo{}); + programInfo.kernelInfos[0]->heapInfo = GlobalMockSipProgram::globalSipProgramInfo->kernelInfos[0]->heapInfo; + programInfo.kernelInfos[0]->kernelAllocation = GlobalMockSipProgram::getAllocation(); + return programInfo; +} +ProgramInfo GlobalMockSipProgram::getSipProgramInfoWithCustomBinary() { NEO::PatchTokenBinary::ProgramFromPatchtokens programTokens; programTokens.kernels.resize(1); @@ -113,9 +103,6 @@ Program *GlobalMockSipProgram::getSipProgramWithCustomBinary() { NEO::ProgramInfo programInfo; NEO::populateProgramInfo(programInfo, programTokens); - - Program *ret = new Program(executionEnvironment, nullptr, false, nullptr); - ret->processProgramInfo(programInfo); - return ret; + return programInfo; } } // namespace NEO diff --git a/opencl/test/unit_test/mocks/mock_program.h b/opencl/test/unit_test/mocks/mock_program.h index f4a6c246ac..7504ee8a47 100644 --- a/opencl/test/unit_test/mocks/mock_program.h +++ b/opencl/test/unit_test/mocks/mock_program.h @@ -156,26 +156,17 @@ class MockProgram : public Program { int isOptionValueValidOverride = -1; }; -class GlobalMockSipProgram : public Program { - public: - using Program::Program; - GlobalMockSipProgram(ExecutionEnvironment &executionEnvironment) : Program(executionEnvironment, nullptr, false, nullptr) { - } - cl_int processGenBinary(uint32_t rootDeviceIndex) override; - cl_int processGenBinaryOnce(uint32_t rootDeviceIndex); - void resetAllocationState(); - void resetAllocation(GraphicsAllocation *allocation); - void deleteAllocation(); - GraphicsAllocation *getAllocation(); - static void initSipProgram(); - static void shutDownSipProgram(); - static GlobalMockSipProgram *sipProgram; - static Program *getSipProgramWithCustomBinary(); - - protected: - void *sipAllocationStorage; - static ExecutionEnvironment executionEnvironment; -}; +namespace GlobalMockSipProgram { +void resetAllocationState(); +void resetAllocation(GraphicsAllocation *allocation); +void deleteAllocation(); +GraphicsAllocation *getAllocation(); +void initSipProgramInfo(); +void shutDownSipProgramInfo(); +ProgramInfo getSipProgramInfoWithCustomBinary(); +extern ProgramInfo *globalSipProgramInfo; +ProgramInfo getSipProgramInfo(); +}; // namespace GlobalMockSipProgram class GMockProgram : public Program { public: diff --git a/opencl/test/unit_test/mocks/mock_sip.cpp b/opencl/test/unit_test/mocks/mock_sip.cpp index b0487660b2..5ff6f3a03d 100644 --- a/opencl/test/unit_test/mocks/mock_sip.cpp +++ b/opencl/test/unit_test/mocks/mock_sip.cpp @@ -23,7 +23,7 @@ #include namespace NEO { -MockSipKernel::MockSipKernel(SipKernelType type, Program *sipProgram) : SipKernel(type, sipProgram) { +MockSipKernel::MockSipKernel(SipKernelType type, ProgramInfo &&sipProgramInfo) : SipKernel(type, std::move(sipProgramInfo)) { this->mockSipMemoryAllocation = std::make_unique(0u, GraphicsAllocation::AllocationType::KERNEL_ISA, @@ -34,7 +34,7 @@ MockSipKernel::MockSipKernel(SipKernelType type, Program *sipProgram) : SipKerne MemoryPool::System4KBPages, 3u); } -MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) { +MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, {}) { this->mockSipMemoryAllocation = std::make_unique(0u, GraphicsAllocation::AllocationType::KERNEL_ISA, @@ -43,7 +43,6 @@ MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) { 0u, MemoryConstants::pageSize, MemoryPool::System4KBPages, 3u); - this->program = new MockProgram(this->executionEnvironment, nullptr, false, nullptr); } MockSipKernel::~MockSipKernel() = default; diff --git a/opencl/test/unit_test/mocks/mock_sip.h b/opencl/test/unit_test/mocks/mock_sip.h index 422d8ebd03..4ea84c165d 100644 --- a/opencl/test/unit_test/mocks/mock_sip.h +++ b/opencl/test/unit_test/mocks/mock_sip.h @@ -19,10 +19,10 @@ class MemoryAllocation; class MockSipKernel : public SipKernel { public: - using SipKernel::program; + using SipKernel::programInfo; using SipKernel::type; - MockSipKernel(SipKernelType type, Program *sipProgram); + MockSipKernel(SipKernelType type, ProgramInfo &&sipProgramInfo); MockSipKernel(); ~MockSipKernel() override; diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp index 04b011c139..ddd11394c6 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp @@ -663,8 +663,8 @@ class DrmCommandStreamBatchingTests : public DrmCommandStreamEnhancedTest { void SetUpT() { DrmCommandStreamEnhancedTest::SetUpT(); if (PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo) == PreemptionMode::MidThread) { - tmpAllocation = GlobalMockSipProgram::sipProgram->getAllocation(); - GlobalMockSipProgram::sipProgram->resetAllocation(device->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); + tmpAllocation = GlobalMockSipProgram::getAllocation(); + GlobalMockSipProgram::resetAllocation(device->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); } tagAllocation = static_cast(device->getDefaultEngine().commandStreamReceiver->getTagAllocation()); preemptionAllocation = static_cast(device->getDefaultEngine().commandStreamReceiver->getPreemptionAllocation()); @@ -673,8 +673,8 @@ class DrmCommandStreamBatchingTests : public DrmCommandStreamEnhancedTest { template void TearDownT() { if (PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo) == PreemptionMode::MidThread) { - device->getMemoryManager()->freeGraphicsMemory((GlobalMockSipProgram::sipProgram)->getAllocation()); - GlobalMockSipProgram::sipProgram->resetAllocation(tmpAllocation); + device->getMemoryManager()->freeGraphicsMemory(GlobalMockSipProgram::getAllocation()); + GlobalMockSipProgram::resetAllocation(tmpAllocation); } DrmCommandStreamEnhancedTest::TearDownT(); } diff --git a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp index 4e145b450d..f10ba19277 100644 --- a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp @@ -806,8 +806,8 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt GraphicsAllocation *tmpAllocation = nullptr; if (device->getPreemptionMode() == PreemptionMode::MidThread) { csrSurfaceCount = 2; - tmpAllocation = GlobalMockSipProgram::sipProgram->getAllocation(); - GlobalMockSipProgram::sipProgram->resetAllocation(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); + tmpAllocation = GlobalMockSipProgram::getAllocation(); + GlobalMockSipProgram::resetAllocation(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); } csrSurfaceCount += csr->globalFenceAllocation ? 1 : 0; @@ -884,8 +884,8 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt memoryManager->freeGraphicsMemory(sshAlloc); memoryManager->freeGraphicsMemory(commandBuffer); if (device->getPreemptionMode() == PreemptionMode::MidThread) { - memoryManager->freeGraphicsMemory(GlobalMockSipProgram::sipProgram->getAllocation()); - GlobalMockSipProgram::sipProgram->resetAllocation(tmpAllocation); + memoryManager->freeGraphicsMemory(GlobalMockSipProgram::getAllocation()); + GlobalMockSipProgram::resetAllocation(tmpAllocation); } } diff --git a/opencl/test/unit_test/ult_config_listener.cpp b/opencl/test/unit_test/ult_config_listener.cpp index 2109f94e44..b2fd2b2d61 100644 --- a/opencl/test/unit_test/ult_config_listener.cpp +++ b/opencl/test/unit_test/ult_config_listener.cpp @@ -15,7 +15,14 @@ #include "opencl/source/platform/platform.h" #include "opencl/test/unit_test/mocks/mock_platform.h" +namespace NEO { +namespace GlobalMockSipProgram { +void resetAllocationState(); +} +} // namespace NEO + void NEO::UltConfigListener::OnTestStart(const ::testing::TestInfo &testInfo) { + GlobalMockSipProgram::resetAllocationState(); referencedHwInfo = *defaultHwInfo; auto executionEnvironment = constructPlatform()->peekExecutionEnvironment(); executionEnvironment->prepareRootDeviceEnvironments(1); diff --git a/shared/source/built_ins/built_ins.cpp b/shared/source/built_ins/built_ins.cpp index 1309629afc..3f960826e4 100644 --- a/shared/source/built_ins/built_ins.cpp +++ b/shared/source/built_ins/built_ins.cpp @@ -9,6 +9,7 @@ #include "shared/source/built_ins/sip.h" #include "shared/source/compiler_interface/compiler_interface.h" +#include "shared/source/device_binary_format/device_binary_formats.h" #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/debug_helpers.h" @@ -35,8 +36,6 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) { auto &sipBuiltIn = this->sipKernels[kernelId]; auto initializer = [&] { - int retVal = 0; - std::vector sipBinary; auto compilerInteface = device.getCompilerInterface(); UNRECOVERABLE_IF(compilerInteface == nullptr); @@ -45,19 +44,10 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) { UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success); UNRECOVERABLE_IF(sipBinary.size() == 0); - auto program = createProgramForSip(*device.getExecutionEnvironment(), - nullptr, - sipBinary, - sipBinary.size(), - &retVal, - &device); - DEBUG_BREAK_IF(retVal != 0); - UNRECOVERABLE_IF(program == nullptr); - retVal = program->processGenBinary(device.getRootDeviceIndex()); - DEBUG_BREAK_IF(retVal != 0); + ProgramInfo programInfo = createProgramInfoForSip(sipBinary, sipBinary.size(), device); - sipBuiltIn.first.reset(new SipKernel(type, program)); + sipBuiltIn.first.reset(new SipKernel(type, std::move(programInfo))); }; std::call_once(sipBuiltIn.second, initializer); UNRECOVERABLE_IF(sipBuiltIn.first == nullptr); diff --git a/shared/source/built_ins/sip.cpp b/shared/source/built_ins/sip.cpp index 01178b6201..de6b5f5a91 100644 --- a/shared/source/built_ins/sip.cpp +++ b/shared/source/built_ins/sip.cpp @@ -17,7 +17,6 @@ #include "shared/source/memory_manager/graphics_allocation.h" #include "opencl/source/program/kernel_info.h" -#include "opencl/source/program/program.h" namespace NEO { @@ -68,24 +67,20 @@ const char *getSipLlSrc(const Device &device) { return (ptrSize == 8) ? llDummySrc64 : llDummySrc32; } -SipKernel::SipKernel(SipKernelType type, Program *sipProgram) - : type(type) { - program = sipProgram; -} -SipKernel::~SipKernel() { - program->release(); -} +SipKernel::SipKernel(SipKernelType type, ProgramInfo &&sipProgram) + : type(type), programInfo(std::move(sipProgram)) {} +SipKernel::~SipKernel() = default; GraphicsAllocation *SipKernel::getSipAllocation() const { - return program->getKernelInfo(size_t{0})->getGraphicsAllocation(); + return programInfo.kernelInfos[0]->getGraphicsAllocation(); } const char *SipKernel::getBinary() const { - auto kernelInfo = program->getKernelInfo(size_t{0}); + auto kernelInfo = programInfo.kernelInfos[0]; return reinterpret_cast(ptrOffset(kernelInfo->heapInfo.pKernelHeap, kernelInfo->systemKernelOffset)); } size_t SipKernel::getBinarySize() const { - auto kernelInfo = program->getKernelInfo(size_t{0}); + auto kernelInfo = programInfo.kernelInfos[0]; return kernelInfo->heapInfo.KernelHeapSize - kernelInfo->systemKernelOffset; } diff --git a/shared/source/built_ins/sip.h b/shared/source/built_ins/sip.h index e4555b53f1..1256995cdf 100644 --- a/shared/source/built_ins/sip.h +++ b/shared/source/built_ins/sip.h @@ -8,13 +8,13 @@ #pragma once #include "shared/source/built_ins/sip_kernel_type.h" #include "shared/source/helpers/hw_info.h" +#include "shared/source/program/program_info.h" #include namespace NEO { class Device; -class Program; class GraphicsAllocation; const char *getSipKernelCompilerInternalOptions(SipKernelType kernel); @@ -23,11 +23,11 @@ const char *getSipLlSrc(const Device &device); class SipKernel { public: - SipKernel(SipKernelType type, Program *sipProgram); + SipKernel(SipKernelType type, ProgramInfo &&sipProgramInfo); SipKernel(const SipKernel &) = delete; SipKernel &operator=(const SipKernel &) = delete; - SipKernel(SipKernel &&) = default; - SipKernel &operator=(SipKernel &&) = default; + SipKernel(SipKernel &&) = delete; + SipKernel &operator=(SipKernel &&) = delete; virtual ~SipKernel(); const char *getBinary() const; @@ -46,6 +46,6 @@ class SipKernel { protected: SipKernelType type = SipKernelType::COUNT; - Program *program = nullptr; + const ProgramInfo programInfo; }; } // namespace NEO diff --git a/shared/test/unit_test/main.cpp b/shared/test/unit_test/main.cpp index df74c09241..001deb63f2 100644 --- a/shared/test/unit_test/main.cpp +++ b/shared/test/unit_test/main.cpp @@ -433,12 +433,12 @@ int main(int argc, char **argv) { GmmInterface::initialize(nullptr, nullptr); } - GlobalMockSipProgram::initSipProgram(); + GlobalMockSipProgram::initSipProgramInfo(); NEO::MockSipData::mockSipKernel.reset(new NEO::MockSipKernel()); retVal = RUN_ALL_TESTS(); - GlobalMockSipProgram::shutDownSipProgram(); + GlobalMockSipProgram::shutDownSipProgramInfo(); delete platformsImpl; return retVal; diff --git a/shared/test/unit_test/preemption/preemption_tests.cpp b/shared/test/unit_test/preemption/preemption_tests.cpp index d6f322340b..3544bfc677 100644 --- a/shared/test/unit_test/preemption/preemption_tests.cpp +++ b/shared/test/unit_test/preemption/preemption_tests.cpp @@ -113,7 +113,7 @@ HWTEST_P(PreemptionHwTest, GivenPreemptionModeIsNotChangingWhenGettingRequiredCm { auto builtIns = new MockBuiltins(); - builtIns->overrideSipKernel(std::unique_ptr(new NEO::SipKernel{SipKernelType::Csr, GlobalMockSipProgram::getSipProgramWithCustomBinary()})); + builtIns->overrideSipKernel(std::unique_ptr(new NEO::SipKernel{SipKernelType::Csr, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()})); mockDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->builtins.reset(builtIns); PreemptionHelper::programCmdStream(cmdStream, mode, mode, nullptr); }