From 0f1918221420d9300463e9b8e9dfb20234668cb6 Mon Sep 17 00:00:00 2001 From: Jitendra Sharma Date: Tue, 20 May 2025 12:12:47 +0000 Subject: [PATCH] feature: Extract SIP binary and SSAH from external SIP Lib Related-To: NEO-13737 Signed-off-by: Jitendra Sharma --- shared/source/built_ins/sip.cpp | 39 ++++++++++++++++++- .../sip_external_lib/sip_external_lib.h | 7 ++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/shared/source/built_ins/sip.cpp b/shared/source/built_ins/sip.cpp index 39bb9300aa..17192601ef 100644 --- a/shared/source/built_ins/sip.cpp +++ b/shared/source/built_ins/sip.cpp @@ -17,6 +17,7 @@ #include "shared/source/helpers/aligned_memory.h" #include "shared/source/helpers/compiler_product_helper.h" #include "shared/source/helpers/debug_helpers.h" +#include "shared/source/helpers/file_io.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/string.h" @@ -251,7 +252,43 @@ bool SipKernel::initHexadecimalArraySipKernel(SipKernelType type, Device &device } bool SipKernel::initSipKernelFromExternalLib(SipKernelType type, Device &device) { - return false; + uint32_t sipIndex = static_cast(type); + uint32_t rootDeviceIndex = device.getRootDeviceIndex(); + auto sipKenel = device.getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->sipKernels[sipIndex].get(); + if (sipKenel != nullptr) { + return true; + } + + std::vector sipBinary; + std::vector stateSaveAreaHeader; + auto &rootDeviceEnvironment = device.getRootDeviceEnvironment(); + + auto ret = device.getSipExternalLibInterface()->getSipKernelBinary(device, type, sipBinary, stateSaveAreaHeader); + if (ret != 0) { + return false; + } + UNRECOVERABLE_IF(sipBinary.size() == 0); + + const auto allocType = AllocationType::kernelIsaInternal; + AllocationProperties properties = {device.getRootDeviceIndex(), sipBinary.size(), allocType, device.getDeviceBitfield()}; + properties.flags.use32BitFrontWindow = false; + + auto sipAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties(properties); + if (sipAllocation == nullptr) { + return false; + } + auto &productHelper = device.getProductHelper(); + MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *sipAllocation), + device, sipAllocation, 0, sipBinary.data(), + sipBinary.size()); + + device.getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->sipKernels[sipIndex] = + std::make_unique(type, sipAllocation, std::move(stateSaveAreaHeader), std::move(sipBinary)); + + if (type == SipKernelType::csr) { + rootDeviceEnvironment.getMutableHardwareInfo()->capabilityTable.requiredPreemptionSurfaceSize = device.getBuiltIns()->getSipKernel(type, device).getStateSaveAreaSize(&device); + } + return true; } void SipKernel::selectSipClassType(std::string &fileName, Device &device) { diff --git a/shared/source/sip_external_lib/sip_external_lib.h b/shared/source/sip_external_lib/sip_external_lib.h index ae375f5891..aebbccb5fa 100644 --- a/shared/source/sip_external_lib/sip_external_lib.h +++ b/shared/source/sip_external_lib/sip_external_lib.h @@ -7,21 +7,22 @@ #pragma once +#include "shared/source/built_ins/sip_kernel_type.h" #include "shared/source/helpers/non_copyable_or_moveable.h" #include "shared/source/os_interface/os_library.h" #include #include +#include namespace NEO { +class Device; class SipExternalLib : NonCopyableAndNonMovableClass { public: virtual ~SipExternalLib() {} static SipExternalLib *getSipExternalLibInstance(); - static std::string_view getLibName(); - - std::unique_ptr libraryHandle = nullptr; + virtual int getSipKernelBinary(NEO::Device &device, SipKernelType type, std::vector &retBinary, std::vector &stateSaveAreaHeader) = 0; }; } // namespace NEO