Refactor Sip Kernel usage

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-12-02 10:22:27 +00:00
committed by Compute-Runtime-Automation
parent da779d067f
commit 8198a739c8
30 changed files with 190 additions and 251 deletions

View File

@@ -7,13 +7,17 @@
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "opencl/source/helpers/built_ins_helper.h"
#include "shared/source/built_ins/sip.h"
namespace L0 {
namespace ult {
const NEO::SipKernel &MockBuiltins::getSipKernel(NEO::SipKernelType type, NEO::Device &device) {
return NEO::initSipKernel(type, device);
if (!(sipKernel && sipKernel->getType() == type)) {
sipKernel.reset(new NEO::SipKernel(type, allocation.get()));
}
return *sipKernel;
}
} // namespace ult

View File

@@ -7,13 +7,19 @@
#pragma once
#include "shared/source/built_ins/built_ins.h"
#include "shared/test/unit_test/mocks/mock_graphics_allocation.h"
namespace L0 {
namespace ult {
class MockBuiltins : public NEO::BuiltIns {
public:
MockBuiltins() : BuiltIns() {
allocation.reset(new NEO::MockGraphicsAllocation());
}
const NEO::SipKernel &getSipKernel(NEO::SipKernelType type, NEO::Device &device) override;
std::unique_ptr<NEO::SipKernel> sipKernel;
std::unique_ptr<NEO::MockGraphicsAllocation> allocation;
};
} // namespace ult
} // namespace L0

View File

@@ -8,6 +8,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_barrier.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_event_reset.cpp

View File

@@ -1114,72 +1114,5 @@ HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNull
commandList->hostPtrMap.clear();
}
struct MemoryManagerCommandListCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandListCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
if (forceFailureInPrimaryAllocation) {
return nullptr;
}
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
}
bool forceFailureInPrimaryAllocation = false;
};
struct CommandListCreateNegativeTest : public ::testing::Test {
void SetUp() override {
executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t i = 0; i < numRootDevices; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
}
memoryManager = new MemoryManagerCommandListCreateNegativeTest(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
std::vector<std::unique_ptr<NEO::Device>> devices;
for (uint32_t i = 0; i < numRootDevices; i++) {
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, i);
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
}
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
}
void TearDown() override {
}
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
MemoryManagerCommandListCreateNegativeTest *memoryManager = nullptr;
const uint32_t numRootDevices = 1u;
};
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListImmediateCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
const ze_command_queue_desc_t desc = {};
bool internalEngine = true;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily,
device,
&desc,
internalEngine,
NEO::EngineGroupType::RenderCompute,
returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
} // namespace ult
} // namespace L0

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h"
namespace L0 {
namespace ult {
struct MemoryManagerCommandListCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandListCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
if (forceFailureInPrimaryAllocation) {
return nullptr;
}
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
}
bool forceFailureInPrimaryAllocation = false;
};
struct CommandListCreateNegativeTest : public ::testing::Test {
void SetUp() override {
executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t i = 0; i < numRootDevices; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
}
memoryManager = new MemoryManagerCommandListCreateNegativeTest(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
std::vector<std::unique_ptr<NEO::Device>> devices;
for (uint32_t i = 0; i < numRootDevices; i++) {
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, i);
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
}
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
}
void TearDown() override {
}
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
MemoryManagerCommandListCreateNegativeTest *memoryManager = nullptr;
const uint32_t numRootDevices = 1u;
};
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListImmediateCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
const ze_command_queue_desc_t desc = {};
bool internalEngine = true;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily,
device,
&desc,
internalEngine,
NEO::EngineGroupType::RenderCompute,
returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
} // namespace ult
} // namespace L0

View File

@@ -10,29 +10,8 @@
#include "shared/source/device/device.h"
#include "shared/source/device_binary_format/device_binary_formats.h"
#include "opencl/source/program/kernel_info.h"
namespace NEO {
const SipKernel &initSipKernel(SipKernelType type, Device &device) {
return device.getBuiltIns()->getSipKernel(type, device);
}
ProgramInfo createProgramInfoForSip(std::vector<char> &binary, size_t size, const Device &device) {
ProgramInfo programInfo;
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;
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, true);
UNRECOVERABLE_IF(!success);
return programInfo;
void initSipKernel(SipKernelType type, Device &device) {
device.getBuiltIns()->getSipKernel(type, device);
}
} // namespace NEO

View File

@@ -12,6 +12,6 @@
namespace NEO {
class Device;
const SipKernel &initSipKernel(SipKernelType type, Device &device);
ProgramInfo createProgramInfoForSip(std::vector<char> &binary, size_t size, const Device &device);
void initSipKernel(SipKernelType type, Device &device);
} // namespace NEO

View File

@@ -2005,28 +2005,31 @@ TEST_F(BuiltInTests, GivenInvalidBuiltinKernelNameWhenCreatingBuiltInProgramThen
}
TEST_F(BuiltInTests, WhenGettingSipKernelThenReturnProgramCreatedFromIsaAcquiredThroughCompilerInterface) {
MockBuiltins mockBuiltins;
auto mockCompilerInterface = new MockCompilerInterface();
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->compilerInterface.reset(mockCompilerInterface);
auto builtins = new BuiltIns;
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->builtins.reset(builtins);
mockCompilerInterface->sipKernelBinaryOverride = mockCompilerInterface->getDummyGenBinary();
cl_int errCode = CL_BUILD_PROGRAM_FAILURE;
auto p = Program::createBuiltInFromGenBinary(pContext, pContext->getDevices(), mockCompilerInterface->sipKernelBinaryOverride.data(), mockCompilerInterface->sipKernelBinaryOverride.size(), &errCode);
ASSERT_EQ(CL_SUCCESS, errCode);
errCode = p->processGenBinary(*pClDevice);
ASSERT_EQ(CL_SUCCESS, errCode);
const SipKernel &sipKern = mockBuiltins.getSipKernel(SipKernelType::Csr, pContext->getDevice(0)->getDevice());
const auto &sipKernelInfo = p->getKernelInfo(static_cast<size_t>(0), rootDeviceIndex);
auto compbinedKernelHeapSize = sipKernelInfo->heapInfo.KernelHeapSize;
auto sipOffset = sipKernelInfo->systemKernelOffset;
ASSERT_GT(compbinedKernelHeapSize, sipOffset);
const SipKernel &sipKernel = builtins->getSipKernel(SipKernelType::Csr, *pDevice);
auto expectedMem = reinterpret_cast<const char *>(sipKernelInfo->heapInfo.pKernelHeap) + sipOffset;
ASSERT_EQ(compbinedKernelHeapSize - sipOffset, sipKern.getBinarySize());
EXPECT_EQ(0, memcmp(expectedMem, sipKern.getBinary(), sipKern.getBinarySize()));
EXPECT_EQ(0, memcmp(expectedMem, sipKernel.getSipAllocation()->getUnderlyingBuffer(), compbinedKernelHeapSize - sipOffset));
EXPECT_EQ(SipKernelType::Csr, mockCompilerInterface->requestedSipKernel);
p->release();
mockCompilerInterface->releaseDummyGenBinary();
}
TEST_F(BuiltInTests, givenSipKernelWhenItIsCreatedThenItHasGraphicsAllocationForKernel) {

View File

@@ -82,16 +82,16 @@ TEST(Sip, GivenSipLlWhenGettingMetadataThenMetadataRequiredByCompilerIsReturned)
}
TEST(Sip, WhenGettingTypeThenCorrectTypeIsReturned) {
SipKernel csr{SipKernelType::Csr, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()};
SipKernel csr{SipKernelType::Csr, nullptr};
EXPECT_EQ(SipKernelType::Csr, csr.getType());
SipKernel dbgCsr{SipKernelType::DbgCsr, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()};
SipKernel dbgCsr{SipKernelType::DbgCsr, nullptr};
EXPECT_EQ(SipKernelType::DbgCsr, dbgCsr.getType());
SipKernel dbgCsrLocal{SipKernelType::DbgCsrLocal, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()};
SipKernel dbgCsrLocal{SipKernelType::DbgCsrLocal, nullptr};
EXPECT_EQ(SipKernelType::DbgCsrLocal, dbgCsrLocal.getType());
SipKernel undefined{SipKernelType::COUNT, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()};
SipKernel undefined{SipKernelType::COUNT, nullptr};
EXPECT_EQ(SipKernelType::COUNT, undefined.getType());
}

View File

@@ -23,13 +23,9 @@ SipKernelType calledType = SipKernelType::COUNT;
bool called = false;
} // namespace MockSipData
const SipKernel &initSipKernel(SipKernelType type, Device &device) {
void initSipKernel(SipKernelType type, Device &device) {
MockSipData::calledType = type;
MockSipData::mockSipKernel->type = type;
MockSipData::called = true;
return *MockSipData::mockSipKernel;
}
ProgramInfo createProgramInfoForSip(std::vector<char> &binary, size_t size, const Device &device) {
return GlobalMockSipProgram::getSipProgramInfo();
}
} // namespace NEO

View File

@@ -113,6 +113,11 @@ void applyWorkarounds() {
});
tempThreadID = t.get_id();
t.join();
//Create FileLogger to prevent false memory leaks
{
NEO::FileLoggerInstance();
}
}
#ifdef __linux__
void handle_SIGALRM(int signal) {
@@ -148,12 +153,10 @@ LONG WINAPI UltExceptionFilter(
#endif
void initializeTestHelpers() {
GlobalMockSipProgram::initSipProgramInfo();
MockSipData::mockSipKernel.reset(new MockSipKernel());
}
void cleanTestHelpers() {
GlobalMockSipProgram::shutDownSipProgramInfo();
delete platformsImpl;
}

View File

@@ -11,7 +11,7 @@
#include "shared/source/built_ins/sip.h"
#include "opencl/source/built_ins/builtins_dispatch_builder.h"
#include "opencl/source/program/program.h"
#include "opencl/test/unit_test/mocks/mock_sip.h"
#include <memory>
@@ -24,14 +24,14 @@ class MockBuiltins : public BuiltIns {
}
getSipKernelCalled = true;
getSipKernelType = type;
return BuiltIns::getSipKernel(type, device);
MockSipData::mockSipKernel->type = type;
return *MockSipData::mockSipKernel;
}
void overrideSipKernel(std::unique_ptr<SipKernel> kernel) {
sipKernelsOverride[kernel->getType()] = std::move(kernel);
}
std::unique_ptr<BuiltinDispatchInfoBuilder> setBuiltinDispatchInfoBuilder(EBuiltInOps::Type operation, Context &context, Device &device, std::unique_ptr<BuiltinDispatchInfoBuilder> builder);
BuiltIns *originalGlobalBuiltins = nullptr;
std::map<SipKernelType, std::unique_ptr<SipKernel>> sipKernelsOverride;
bool getSipKernelCalled = false;
SipKernelType getSipKernelType = SipKernelType::COUNT;

View File

@@ -628,4 +628,8 @@ IGC::FclOclTranslationCtxBase *MockFclOclDeviceCtx::CreateTranslationCtxImpl(CIF
std::vector<char> MockCompilerInterface::getDummyGenBinary() {
return MockSipKernel::getDummyGenBinary();
}
void MockCompilerInterface::releaseDummyGenBinary() {
MockSipKernel::shutDown();
}
} // namespace NEO

View File

@@ -33,6 +33,7 @@ struct MockCompilerDebugVars {
bool failCreatePlatformInterface = false;
bool failCreateGtSystemInfoInterface = false;
bool failCreateIgcFeWaInterface = false;
IGC::SystemRoutineType::SystemRoutineType_t typeOfSystemRoutine = IGC::SystemRoutineType::undefined;
std::string *receivedInternalOptionsOutput = nullptr;
std::string *receivedInput = nullptr;

View File

@@ -28,7 +28,7 @@ ClDeviceVector toClDeviceVector(ClDevice &clDevice) {
deviceVector.push_back(&clDevice);
return deviceVector;
}
ProgramInfo *GlobalMockSipProgram::globalSipProgramInfo;
int MockProgram::initInternalOptionsCalled = 0;
std::string MockProgram::getCachedFileName() const {
@@ -40,75 +40,4 @@ std::string MockProgram::getCachedFileName() const {
return CompilerCache::getCachedFileName(hwInfo, input, opts, internalOpts);
}
void GlobalMockSipProgram::initSipProgramInfo() {
globalSipProgramInfo = new ProgramInfo();
std::vector<char> binary = MockCompilerInterface::getDummyGenBinary();
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) {
globalSipProgramInfo->kernelInfos[0]->kernelAllocation = allocation;
}
GraphicsAllocation *GlobalMockSipProgram::getAllocation() {
return globalSipProgramInfo->kernelInfos[0]->kernelAllocation;
}
void GlobalMockSipProgram::deleteAllocation() {
auto allocation = globalSipProgramInfo->kernelInfos[0]->kernelAllocation;
alignedFree(allocation->getUnderlyingBuffer());
delete allocation;
globalSipProgramInfo->kernelInfos[0]->kernelAllocation = nullptr;
}
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();
}
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);
const uint8_t isa[] = "kernel morphEUs()";
const char name[] = "sip";
SProgramBinaryHeader progHeader = {};
progHeader.NumberOfKernels = 1;
SKernelBinaryHeaderCommon kernHeader = {};
kernHeader.KernelNameSize = sizeof(name);
kernHeader.KernelHeapSize = sizeof(isa);
kernHeader.KernelUnpaddedSize = sizeof(isa);
programTokens.header = &progHeader;
programTokens.kernels[0].header = &kernHeader;
programTokens.kernels[0].isa = isa;
programTokens.kernels[0].name = name;
NEO::ProgramInfo programInfo;
NEO::populateProgramInfo(programInfo, programTokens);
return programInfo;
}
} // namespace NEO

View File

@@ -178,18 +178,6 @@ class MockProgram : public Program {
int isOptionValueValidOverride = -1;
};
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:
using Program::Program;

View File

@@ -23,7 +23,7 @@
#include <map>
namespace NEO {
MockSipKernel::MockSipKernel(SipKernelType type, ProgramInfo &&sipProgramInfo) : SipKernel(type, std::move(sipProgramInfo)) {
MockSipKernel::MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : SipKernel(type, sipAlloc) {
this->mockSipMemoryAllocation =
std::make_unique<MemoryAllocation>(0u,
GraphicsAllocation::AllocationType::KERNEL_ISA,
@@ -34,7 +34,7 @@ MockSipKernel::MockSipKernel(SipKernelType type, ProgramInfo &&sipProgramInfo) :
MemoryPool::System4KBPages, 3u);
}
MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, {}) {
MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr) {
this->mockSipMemoryAllocation =
std::make_unique<MemoryAllocation>(0u,
GraphicsAllocation::AllocationType::KERNEL_ISA,
@@ -71,6 +71,7 @@ void MockSipKernel::initDummyBinary() {
}
void MockSipKernel::shutDown() {
MockSipKernel::dummyBinaryForSip.clear();
std::vector<char>().swap(MockSipKernel::dummyBinaryForSip);
}
GraphicsAllocation *MockSipKernel::getSipAllocation() const {

View File

@@ -19,10 +19,9 @@ class MemoryAllocation;
class MockSipKernel : public SipKernel {
public:
using SipKernel::programInfo;
using SipKernel::type;
MockSipKernel(SipKernelType type, ProgramInfo &&sipProgramInfo);
MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc);
MockSipKernel();
~MockSipKernel() override;
@@ -37,4 +36,10 @@ class MockSipKernel : public SipKernel {
std::unique_ptr<MemoryAllocation> mockSipMemoryAllocation;
MockExecutionEnvironment executionEnvironment;
};
namespace MockSipData {
extern std::unique_ptr<MockSipKernel> mockSipKernel;
extern SipKernelType calledType;
extern bool called;
} // namespace MockSipData
} // namespace NEO

View File

@@ -659,25 +659,16 @@ class DrmCommandStreamBatchingTests : public DrmCommandStreamEnhancedTest {
public:
DrmAllocation *tagAllocation;
DrmAllocation *preemptionAllocation;
GraphicsAllocation *tmpAllocation;
template <typename GfxFamily>
void SetUpT() {
DrmCommandStreamEnhancedTest::SetUpT<GfxFamily>();
if (PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo) == PreemptionMode::MidThread) {
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());
}
template <typename GfxFamily>
void TearDownT() {
if (PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo) == PreemptionMode::MidThread) {
device->getMemoryManager()->freeGraphicsMemory(GlobalMockSipProgram::getAllocation());
GlobalMockSipProgram::resetAllocation(tmpAllocation);
}
DrmCommandStreamEnhancedTest::TearDownT<GfxFamily>();
}
};
@@ -789,7 +780,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSe
EXPECT_EQ(testedCsr->commandStream.getGraphicsAllocation(), recordedCmdBuffer->batchBuffer.commandBufferAllocation);
int ioctlUserPtrCnt = 3;
int ioctlUserPtrCnt = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 4 : 3;
EXPECT_EQ(ioctlUserPtrCnt, this->mock->ioctl_cnt.total);
EXPECT_EQ(ioctlUserPtrCnt, this->mock->ioctl_cnt.gemUserptr);
@@ -864,7 +855,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhen
}
int ioctlExecCnt = 1;
int ioctlUserPtrCnt = 2;
int ioctlUserPtrCnt = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 3 : 2;
EXPECT_EQ(ioctlExecCnt, this->mock->ioctl_cnt.execbuffer2);
EXPECT_EQ(ioctlUserPtrCnt, this->mock->ioctl_cnt.gemUserptr);
EXPECT_EQ(ioctlExecCnt + ioctlUserPtrCnt, this->mock->ioctl_cnt.total);

View File

@@ -13,6 +13,7 @@
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
#include "opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h"
#include "opencl/test/unit_test/mocks/mock_builtins.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h"
@@ -61,6 +62,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
rootDeviceEnvironment->osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironment->osInterface->get()->setDrm(new DrmMockCustom());
rootDeviceEnvironment->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*rootDeviceEnvironment->osInterface->get()->getDrm(), i);
rootDeviceEnvironment->builtins.reset(new MockBuiltins);
}
rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get();

View File

@@ -810,11 +810,11 @@ TEST_F(WddmCommandStreamMockGdiTest, WhenMakingResidentThenResidencyAllocationsL
HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmittedThenFlushTaskIsProperlyCalled) {
//preemption allocation + sip allocation
size_t csrSurfaceCount = 0;
GraphicsAllocation *tmpAllocation = nullptr;
//GraphicsAllocation *tmpAllocation = nullptr;
if (device->getPreemptionMode() == PreemptionMode::MidThread) {
csrSurfaceCount = 2;
tmpAllocation = GlobalMockSipProgram::getAllocation();
GlobalMockSipProgram::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;
@@ -891,8 +891,8 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
memoryManager->freeGraphicsMemory(sshAlloc);
memoryManager->freeGraphicsMemory(commandBuffer);
if (device->getPreemptionMode() == PreemptionMode::MidThread) {
memoryManager->freeGraphicsMemory(GlobalMockSipProgram::getAllocation());
GlobalMockSipProgram::resetAllocation(tmpAllocation);
// memoryManager->freeGraphicsMemory(GlobalMockSipProgram::getAllocation());
// GlobalMockSipProgram::resetAllocation(tmpAllocation);
}
}

View File

@@ -17,14 +17,7 @@
#include "third_party/aub_stream/headers/aubstream.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);

View File

@@ -12,6 +12,7 @@
#include "shared/source/device_binary_format/device_binary_formats.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "opencl/source/helpers/built_ins_helper.h"
#include "opencl/source/helpers/convert_color.h"
@@ -45,13 +46,35 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) {
UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success);
UNRECOVERABLE_IF(sipBinary.size() == 0);
ProgramInfo programInfo = createProgramInfoForSip(sipBinary, sipBinary.size(), device);
ProgramInfo programInfo;
auto blob = ArrayRef<const uint8_t>(reinterpret_cast<const uint8_t *>(sipBinary.data()), sipBinary.size());
SingleDeviceBinary deviceBinary = {};
deviceBinary.deviceBinary = blob;
std::string decodeErrors;
std::string decodeWarnings;
sipBuiltIn.first.reset(new SipKernel(type, std::move(programInfo)));
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, true);
UNRECOVERABLE_IF(!success);
sipBuiltIn.first.reset(new SipKernel(type, programInfo.kernelInfos[0]->kernelAllocation));
programInfo.kernelInfos[0]->kernelAllocation = nullptr;
};
std::call_once(sipBuiltIn.second, initializer);
UNRECOVERABLE_IF(sipBuiltIn.first == nullptr);
return *sipBuiltIn.first;
}
void BuiltIns::freeSipKernels(MemoryManager *memoryManager) {
for (auto &sipKernel : sipKernels) {
if (sipKernel.first.get()) {
memoryManager->freeGraphicsMemory(sipKernel.first->getSipAllocation());
}
}
}
} // namespace NEO

View File

@@ -33,6 +33,7 @@ struct KernelInfo;
struct MultiDispatchInfo;
class Program;
class SipKernel;
class MemoryManager;
static constexpr ConstStringRef mediaKernelsBuildOptionsList[] = {
"-D cl_intel_device_side_advanced_vme_enable",
@@ -156,6 +157,7 @@ class BuiltIns {
virtual ~BuiltIns();
MOCKABLE_VIRTUAL const SipKernel &getSipKernel(SipKernelType type, Device &device);
MOCKABLE_VIRTUAL void freeSipKernels(MemoryManager *memoryManager);
BuiltinsLib &getBuiltinsLib() {
DEBUG_BREAK_IF(!builtinsLib.get());

View File

@@ -14,9 +14,9 @@
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/string.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "opencl/source/program/kernel_info.h"
#include "shared/source/memory_manager/memory_manager.h"
namespace NEO {
@@ -67,21 +67,13 @@ const char *getSipLlSrc(const Device &device) {
return (ptrSize == 8) ? llDummySrc64 : llDummySrc32;
}
SipKernel::SipKernel(SipKernelType type, ProgramInfo &&sipProgram)
: type(type), programInfo(std::move(sipProgram)) {}
SipKernel::~SipKernel() = default;
GraphicsAllocation *SipKernel::getSipAllocation() const {
return programInfo.kernelInfos[0]->getGraphicsAllocation();
SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : type(type), sipAllocation(sipAlloc) {
}
const char *SipKernel::getBinary() const {
auto kernelInfo = programInfo.kernelInfos[0];
return reinterpret_cast<const char *>(ptrOffset(kernelInfo->heapInfo.pKernelHeap, kernelInfo->systemKernelOffset));
}
size_t SipKernel::getBinarySize() const {
auto kernelInfo = programInfo.kernelInfos[0];
return kernelInfo->heapInfo.KernelHeapSize - kernelInfo->systemKernelOffset;
GraphicsAllocation *SipKernel::getSipAllocation() const {
return sipAllocation;
}
SipKernelType SipKernel::getSipKernelType(GFXCORE_FAMILY family, bool debuggingActive) {
@@ -94,5 +86,4 @@ GraphicsAllocation *SipKernel::getSipKernelAllocation(Device &device) {
auto sipType = SipKernel::getSipKernelType(device.getHardwareInfo().platform.eRenderCoreFamily, debuggingEnabled);
return device.getBuiltIns()->getSipKernel(sipType, device).getSipAllocation();
}
} // namespace NEO

View File

@@ -11,7 +11,7 @@
#include "shared/source/program/program_info.h"
#include <memory>
#include <vector>
namespace NEO {
class Device;
@@ -23,17 +23,13 @@ const char *getSipLlSrc(const Device &device);
class SipKernel {
public:
SipKernel(SipKernelType type, ProgramInfo &&sipProgramInfo);
SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc);
SipKernel(const SipKernel &) = delete;
SipKernel &operator=(const SipKernel &) = delete;
SipKernel(SipKernel &&) = delete;
SipKernel &operator=(SipKernel &&) = delete;
virtual ~SipKernel();
const char *getBinary() const;
size_t getBinarySize() const;
SipKernelType getType() const {
return type;
}
@@ -46,6 +42,6 @@ class SipKernel {
protected:
SipKernelType type = SipKernelType::COUNT;
const ProgramInfo programInfo;
GraphicsAllocation *sipAllocation = nullptr;
};
} // namespace NEO

View File

@@ -7,6 +7,7 @@
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/built_ins/built_ins.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/memory_manager/memory_manager.h"
@@ -19,6 +20,11 @@ ExecutionEnvironment::ExecutionEnvironment() = default;
ExecutionEnvironment::~ExecutionEnvironment() {
if (memoryManager) {
memoryManager->commonCleanup();
for (const auto &rootDeviceEnvironment : this->rootDeviceEnvironments) {
if (rootDeviceEnvironment->builtins.get()) {
rootDeviceEnvironment->builtins.get()->freeSipKernels(memoryManager.get());
}
}
}
rootDeviceEnvironments.clear();
}

View File

@@ -440,12 +440,10 @@ int main(int argc, char **argv) {
GmmInterface::initialize(nullptr, nullptr);
}
GlobalMockSipProgram::initSipProgramInfo();
NEO::MockSipData::mockSipKernel.reset(new NEO::MockSipKernel());
retVal = RUN_ALL_TESTS();
GlobalMockSipProgram::shutDownSipProgramInfo();
delete platformsImpl;
return retVal;

View File

@@ -124,6 +124,7 @@ class MockCompilerInterface : public CompilerInterface {
}
static std::vector<char> getDummyGenBinary();
static void releaseDummyGenBinary();
void (*lockListener)(MockCompilerInterface &compInt) = nullptr;
void *lockListenerData = nullptr;

View File

@@ -113,7 +113,6 @@ HWTEST_P(PreemptionHwTest, GivenPreemptionModeIsNotChangingWhenGettingRequiredCm
{
auto builtIns = new MockBuiltins();
builtIns->overrideSipKernel(std::unique_ptr<NEO::SipKernel>(new NEO::SipKernel{SipKernelType::Csr, GlobalMockSipProgram::getSipProgramInfoWithCustomBinary()}));
mockDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->builtins.reset(builtIns);
PreemptionHelper::programCmdStream<FamilyType>(cmdStream, mode, mode, nullptr);
}