Add new functionality to load SIP from file

Related-To: NEO-5718

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2021-04-16 12:52:30 +00:00
committed by Compute-Runtime-Automation
parent f83b51e628
commit 902cce597a
53 changed files with 534 additions and 211 deletions

View File

@@ -8,8 +8,10 @@
#include "shared/source/built_ins/sip.h"
#include "shared/source/built_ins/built_ins.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device/device.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/ptr_math.h"
@@ -17,14 +19,17 @@
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/utilities/io_functions.h"
namespace NEO {
const size_t SipKernel::maxDbgSurfaceSize = 0x1800000; // proper value should be taken from compiler when it's ready
SipClassType SipKernel::classType = SipClassType::Init;
SipKernel::~SipKernel() = default;
SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc, std::vector<char> ssah) : type(type), sipAllocation(sipAlloc), stateSaveAreaHeader(ssah) {
SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc, std::vector<char> ssah) : stateSaveAreaHeader(ssah), sipAllocation(sipAlloc), type(type) {
}
GraphicsAllocation *SipKernel::getSipAllocation() const {
@@ -35,20 +40,102 @@ const std::vector<char> &SipKernel::getStateSaveAreaHeader() const {
return stateSaveAreaHeader;
}
SipKernelType SipKernel::getSipKernelType(GFXCORE_FAMILY family, bool debuggingActive) {
auto &hwHelper = HwHelper::get(family);
return hwHelper.getSipKernelType(debuggingActive);
}
GraphicsAllocation *SipKernel::getSipKernelAllocation(Device &device) {
SipKernelType SipKernel::getSipKernelType(Device &device) {
bool debuggingEnabled = device.getDebugger() != nullptr || device.isDebuggerActive();
auto sipType = SipKernel::getSipKernelType(device.getHardwareInfo().platform.eRenderCoreFamily, debuggingEnabled);
return device.getBuiltIns()->getSipKernel(sipType, device).getSipAllocation();
auto &hwHelper = HwHelper::get(device.getHardwareInfo().platform.eRenderCoreFamily);
return hwHelper.getSipKernelType(debuggingEnabled);
}
const std::vector<char> &SipKernel::getSipStateSaveAreaHeader(Device &device) {
bool debuggingEnabled = device.getDebugger() != nullptr;
auto sipType = SipKernel::getSipKernelType(device.getHardwareInfo().platform.eRenderCoreFamily, debuggingEnabled);
return device.getBuiltIns()->getSipKernel(sipType, device).getStateSaveAreaHeader();
bool SipKernel::initBuiltinsSipKernel(SipKernelType type, Device &device) {
device.getBuiltIns()->getSipKernel(type, device);
return true;
}
bool SipKernel::initRawBinaryFromFileKernel(SipKernelType type, Device &device, std::string &fileName) {
FILE *fileDescriptor = nullptr;
long int size = 0;
size_t bytesRead = 0u;
fileDescriptor = IoFunctions::fopenPtr(fileName.c_str(), "rb");
if (fileDescriptor == NULL) {
return false;
}
IoFunctions::fseekPtr(fileDescriptor, 0, SEEK_END);
size = IoFunctions::ftellPtr(fileDescriptor);
IoFunctions::rewindPtr(fileDescriptor);
void *alignedBuffer = alignedMalloc(size, MemoryConstants::pageSize);
bytesRead = IoFunctions::freadPtr(alignedBuffer, 1, size, fileDescriptor);
IoFunctions::fclosePtr(fileDescriptor);
if (static_cast<long int>(bytesRead) != size || bytesRead == 0u) {
alignedFree(alignedBuffer);
return false;
}
const auto allocType = GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL;
AllocationProperties properties = {device.getRootDeviceIndex(), bytesRead, allocType, device.getDeviceBitfield()};
properties.flags.use32BitFrontWindow = false;
auto sipAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
if (sipAllocation == nullptr) {
alignedFree(alignedBuffer);
return false;
}
auto &hwInfo = device.getHardwareInfo();
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *sipAllocation),
device, sipAllocation, 0, alignedBuffer,
bytesRead);
alignedFree(alignedBuffer);
std::vector<char> emptyStateSaveAreaHeader;
uint32_t sipIndex = static_cast<uint32_t>(type);
device.getExecutionEnvironment()->rootDeviceEnvironments[device.getRootDeviceIndex()]->sipKernels[sipIndex] =
std::make_unique<SipKernel>(type, sipAllocation, std::move(emptyStateSaveAreaHeader));
return true;
}
void SipKernel::freeSipKernels(RootDeviceEnvironment *rootDeviceEnvironment, MemoryManager *memoryManager) {
for (auto &sipKernel : rootDeviceEnvironment->sipKernels) {
if (sipKernel.get()) {
memoryManager->freeGraphicsMemory(sipKernel->getSipAllocation());
}
}
}
void SipKernel::selectSipClassType(std::string &fileName) {
const std::string unknown("unk");
if (fileName.compare(unknown) == 0) {
SipKernel::classType = SipClassType::Builtins;
} else {
SipKernel::classType = SipClassType::RawBinaryFromFile;
}
}
bool SipKernel::initSipKernelImpl(SipKernelType type, Device &device) {
std::string fileName = DebugManager.flags.LoadBinarySipFromFile.get();
SipKernel::selectSipClassType(fileName);
if (SipKernel::classType == SipClassType::RawBinaryFromFile) {
return SipKernel::initRawBinaryFromFileKernel(type, device, fileName);
}
return SipKernel::initBuiltinsSipKernel(type, device);
}
const SipKernel &SipKernel::getSipKernelImpl(Device &device) {
auto sipType = SipKernel::getSipKernelType(device);
if (SipKernel::classType == SipClassType::RawBinaryFromFile) {
return *device.getRootDeviceEnvironment().sipKernels[static_cast<uint32_t>(sipType)].get();
}
return device.getBuiltIns()->getSipKernel(sipType, device);
}
} // namespace NEO