Use ProgramInfo instead of Program in sip kernel

Related-To: NEO-5001
Change-Id: I58eda3ecc52fe1215ea8bbc35f97eea3a9d848e0
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-10-13 11:41:48 +02:00
committed by sys_ocldev
parent dd5c5ed723
commit 97154f7f98
18 changed files with 127 additions and 171 deletions

View File

@ -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());
}

View File

@ -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<char> &binary,
size_t size,
cl_int *errcodeRet,
Device *device) {
GlobalMockSipProgram::sipProgram->incRefApi();
GlobalMockSipProgram::sipProgram->resetAllocationState();
return GlobalMockSipProgram::sipProgram;
ProgramInfo createProgramInfoForSip(std::vector<char> &binary, size_t size, const Device &device) {
return GlobalMockSipProgram::getSipProgramInfo();
}
} // namespace NEO

View File

@ -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;
}

View File

@ -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<const char>(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<MockGraphicsAllocation *>(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<char> 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<GlobalMockSipProgram>(executionEnvironment,
nullptr,
binary.data(),
binary.size(),
true,
&retVal,
&device);
DEBUG_BREAK_IF(retVal != 0);
sipProgram->processGenBinaryOnce(mockRootDeviceIndex);
auto blob = ArrayRef<const uint8_t>(reinterpret_cast<const uint8_t *>(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<MockGraphicsAllocation *>(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

View File

@ -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:

View File

@ -23,7 +23,7 @@
#include <map>
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<MemoryAllocation>(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<MemoryAllocation>(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;

View File

@ -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;

View File

@ -663,8 +663,8 @@ class DrmCommandStreamBatchingTests : public DrmCommandStreamEnhancedTest {
void SetUpT() {
DrmCommandStreamEnhancedTest::SetUpT<GfxFamily>();
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<DrmAllocation *>(device->getDefaultEngine().commandStreamReceiver->getTagAllocation());
preemptionAllocation = static_cast<DrmAllocation *>(device->getDefaultEngine().commandStreamReceiver->getPreemptionAllocation());
@ -673,8 +673,8 @@ class DrmCommandStreamBatchingTests : public DrmCommandStreamEnhancedTest {
template <typename GfxFamily>
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<GfxFamily>();
}

View File

@ -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);
}
}

View File

@ -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);