refactor: Add GTPinHelper getter in clDevice

Related-To: NEO-6853
Signed-off-by: Kamil Kopryk <kamil.kopryk@intel.com>
This commit is contained in:
Kamil Kopryk
2023-02-01 15:00:54 +00:00
committed by Compute-Runtime-Automation
parent 1a0bc60434
commit b08a385f6b
14 changed files with 49 additions and 37 deletions

View File

@@ -19,6 +19,7 @@
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/source_level_debugger/source_level_debugger.h"
#include "opencl/source/gtpin/gtpin_gfx_core_helper.h"
#include "opencl/source/helpers/cl_gfx_core_helper.h"
#include "opencl/source/platform/platform.h"
@@ -276,4 +277,11 @@ const ProductHelper &ClDevice::getProductHelper() const {
return device.getProductHelper();
}
const GTPinGfxCoreHelper &ClDevice::getGTPinGfxCoreHelper() const {
GFXCORE_FAMILY genFamily = this->getHardwareInfo().platform.eRenderCoreFamily;
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(genFamily);
return gtpinHelper;
}
} // namespace NEO

View File

@@ -42,6 +42,7 @@ struct RootDeviceEnvironment;
struct SelectorCopyEngine;
class GfxCoreHelper;
class ProductHelper;
class GTPinGfxCoreHelper;
template <>
struct OpenCLObjectMapper<_cl_device_id> {
@@ -132,6 +133,7 @@ class ClDevice : public BaseObject<_cl_device_id> {
Platform *getPlatform() const;
const GfxCoreHelper &getGfxCoreHelper() const;
const ProductHelper &getProductHelper() const;
const GTPinGfxCoreHelper &getGTPinGfxCoreHelper() const;
protected:
void initializeCaps();

View File

@@ -24,7 +24,7 @@ typedef Gen11Family Family;
static const auto gfxFamily = IGFX_GEN11_CORE;
template <>
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() {
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() const {
return gtpin::GTPIN_GEN_11;
}

View File

@@ -24,7 +24,7 @@ typedef Gen12LpFamily Family;
static const auto gfxFamily = IGFX_GEN12LP_CORE;
template <>
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() {
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() const {
return gtpin::GTPIN_GEN_12_1;
}

View File

@@ -24,7 +24,7 @@ typedef Gen8Family Family;
static const auto gfxFamily = IGFX_GEN8_CORE;
template <>
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() {
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() const {
return gtpin::GTPIN_GEN_8;
}

View File

@@ -24,7 +24,7 @@ typedef Gen9Family Family;
static const auto gfxFamily = IGFX_GEN9_CORE;
template <>
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() {
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() const {
return gtpin::GTPIN_GEN_9;
}

View File

@@ -47,8 +47,7 @@ void gtpinNotifyContextCreate(cl_context context) {
auto pContext = castToObjectOrAbort<Context>(context);
auto pDevice = pContext->getDevice(0);
UNRECOVERABLE_IF(pDevice == nullptr);
GFXCORE_FAMILY genFamily = pDevice->getHardwareInfo().platform.eRenderCoreFamily;
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(genFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
gtpinPlatformInfo.gen_version = (gtpin::GTPIN_GEN_VERSION)gtpinHelper.getGenVersion();
gtpinPlatformInfo.device_id = static_cast<uint32_t>(pDevice->getHardwareInfo().platform.usDeviceID);
(*GTPinCallbacks.onContextCreate)((context_handle_t)context, &gtpinPlatformInfo, &pIgcInit);
@@ -68,11 +67,11 @@ void gtpinNotifyKernelCreate(cl_kernel kernel) {
if (isGTPinInitialized) {
auto pMultiDeviceKernel = castToObjectOrAbort<MultiDeviceKernel>(kernel);
auto pKernel = pMultiDeviceKernel->getDefaultKernel();
auto &device = pMultiDeviceKernel->getDevices()[0]->getDevice();
auto &device = pMultiDeviceKernel->getDevices()[0];
size_t gtpinBTI = pKernel->getNumberOfBindingTableStates();
// Enlarge local copy of SSH by 1 SS
GFXCORE_FAMILY genFamily = device.getHardwareInfo().platform.eRenderCoreFamily;
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(genFamily);
auto &gtpinHelper = device->getGTPinGfxCoreHelper();
if (!gtpinHelper.addSurfaceState(pKernel)) {
// Kernel with no SSH or Kernel EM, not supported
return;
@@ -146,7 +145,9 @@ void gtpinNotifyKernelSubmit(cl_kernel kernel, void *pCmdQueue) {
if (!resource) {
return;
}
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(device.getHardwareInfo().platform.eRenderCoreFamily);
auto clDevice = pContext->getDevice(0);
auto &gtpinHelper = clDevice->getGTPinGfxCoreHelper();
size_t gtpinBTI = pKernel->getNumberOfBindingTableStates() - 1;
void *pSurfaceState = gtpinHelper.getSurfaceState(pKernel, gtpinBTI);
if (gtpinHelper.canUseSharedAllocation(device.getHardwareInfo())) {
@@ -213,7 +214,10 @@ void gtpinNotifyMakeResident(void *pKernel, void *pCSR) {
CommandStreamReceiver *pCommandStreamReceiver = reinterpret_cast<CommandStreamReceiver *>(pCSR);
GraphicsAllocation *pGfxAlloc = nullptr;
Context &context = static_cast<Kernel *>(pKernel)->getContext();
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(context.getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily);
auto clDevice = context.getDevice(0);
auto &gtpinHelper = clDevice->getGTPinGfxCoreHelper();
if (gtpinHelper.canUseSharedAllocation(context.getDevice(0)->getHardwareInfo())) {
auto allocData = reinterpret_cast<SvmAllocationData *>(kernelExecQueue[n].gtpinResource);
pGfxAlloc = allocData->gpuAllocations.getGraphicsAllocation(pCommandStreamReceiver->getRootDeviceIndex());

View File

@@ -19,9 +19,9 @@ struct HardwareInfo;
class GTPinGfxCoreHelper {
public:
static GTPinGfxCoreHelper &get(GFXCORE_FAMILY gfxCore);
virtual uint32_t getGenVersion() = 0;
virtual bool addSurfaceState(Kernel *pKernel) = 0;
virtual void *getSurfaceState(Kernel *pKernel, size_t bti) = 0;
virtual uint32_t getGenVersion() const = 0;
virtual bool addSurfaceState(Kernel *pKernel) const = 0;
virtual void *getSurfaceState(Kernel *pKernel, size_t bti) const = 0;
virtual bool canUseSharedAllocation(const HardwareInfo &hwInfo) const = 0;
protected:
@@ -35,9 +35,9 @@ class GTPinGfxCoreHelperHw : public GTPinGfxCoreHelper {
static GTPinGfxCoreHelperHw<GfxFamily> gtpinGfxCoreHelper;
return gtpinGfxCoreHelper;
}
uint32_t getGenVersion() override;
bool addSurfaceState(Kernel *pKernel) override;
void *getSurfaceState(Kernel *pKernel, size_t bti) override;
uint32_t getGenVersion() const override;
bool addSurfaceState(Kernel *pKernel) const override;
void *getSurfaceState(Kernel *pKernel, size_t bti) const override;
bool canUseSharedAllocation(const HardwareInfo &hwInfo) const override;
protected:

View File

@@ -14,7 +14,7 @@
namespace NEO {
template <typename GfxFamily>
bool GTPinGfxCoreHelperHw<GfxFamily>::addSurfaceState(Kernel *pKernel) {
bool GTPinGfxCoreHelperHw<GfxFamily>::addSurfaceState(Kernel *pKernel) const {
using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE;
using BINDING_TABLE_STATE = typename GfxFamily::BINDING_TABLE_STATE;
@@ -44,7 +44,7 @@ bool GTPinGfxCoreHelperHw<GfxFamily>::addSurfaceState(Kernel *pKernel) {
}
template <typename GfxFamily>
void *GTPinGfxCoreHelperHw<GfxFamily>::getSurfaceState(Kernel *pKernel, size_t bti) {
void *GTPinGfxCoreHelperHw<GfxFamily>::getSurfaceState(Kernel *pKernel, size_t bti) const {
using BINDING_TABLE_STATE = typename GfxFamily::BINDING_TABLE_STATE;
if ((nullptr == pKernel->getSurfaceStateHeap()) || (bti >= pKernel->getNumberOfBindingTableStates())) {

View File

@@ -33,7 +33,7 @@ GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinCreateBuffer(context_handle_t context
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
}
size_t size = alignUp(reqSize, MemoryConstants::cacheLineSize);
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pContext->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pContext->getDevice(0)->getGTPinGfxCoreHelper();
if (gtpinHelper.canUseSharedAllocation(pContext->getDevice(0)->getHardwareInfo())) {
void *unifiedMemorySharedAllocation = clSharedMemAllocINTEL(pContext, pContext->getDevice(0), 0, size, 0, &diag);
auto allocationsManager = pContext->getSVMAllocsManager();
@@ -55,7 +55,7 @@ GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinFreeBuffer(context_handle_t context,
if ((pContext == nullptr) || (resource == nullptr)) {
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
}
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pContext->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pContext->getDevice(0)->getGTPinGfxCoreHelper();
if (gtpinHelper.canUseSharedAllocation(pContext->getDevice(0)->getHardwareInfo())) {
auto allocData = reinterpret_cast<SvmAllocationData *>(resource);
clMemFreeINTEL(pContext, allocData->cpuAllocation->getUnderlyingBuffer());
@@ -76,7 +76,7 @@ GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinMapBuffer(context_handle_t context, r
if ((pContext == nullptr) || (buffer == nullptr) || (pAddress == nullptr)) {
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
}
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pContext->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pContext->getDevice(0)->getGTPinGfxCoreHelper();
if (gtpinHelper.canUseSharedAllocation(pContext->getDevice(0)->getHardwareInfo())) {
auto allocData = reinterpret_cast<SvmAllocationData *>(resource);
*pAddress = reinterpret_cast<uint8_t *>(allocData->cpuAllocation->getUnderlyingBuffer());
@@ -95,7 +95,7 @@ GTPIN_DI_STATUS GTPIN_DRIVER_CALLCONV gtpinUnmapBuffer(context_handle_t context,
if ((pContext == nullptr) || (resource == nullptr)) {
return GTPIN_DI_ERROR_INVALID_ARGUMENT;
}
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pContext->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pContext->getDevice(0)->getGTPinGfxCoreHelper();
if (!gtpinHelper.canUseSharedAllocation(pContext->getDevice(0)->getHardwareInfo())) {
auto pMemObj = castToObject<MemObj>(resource);
if (pMemObj == nullptr) {

View File

@@ -21,7 +21,7 @@ typedef XeHpFamily Family;
static const auto gfxFamily = IGFX_XE_HP_CORE;
template <>
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() {
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() const {
return gtpin::GTPIN_XEHP_CORE;
}

View File

@@ -32,7 +32,7 @@ struct GTPinEnableXeHpcCore {
};
template <>
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() {
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() const {
return gtpin::GTPIN_XE_HPC_CORE;
}

View File

@@ -32,7 +32,7 @@ struct GTPinEnableXeHpgCore {
};
template <>
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() {
uint32_t GTPinGfxCoreHelperHw<Family>::getGenVersion() const {
return gtpin::GTPIN_XE_HPG_CORE;
}

View File

@@ -716,8 +716,7 @@ TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenContextIsCreatedThenCorrect
context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, context);
GFXCORE_FAMILY genFamily = pDevice->getHardwareInfo().platform.eRenderCoreFamily;
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(genFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
EXPECT_EQ(ULT::platformInfo.gen_version, static_cast<gtpin::GTPIN_GEN_VERSION>(gtpinHelper.getGenVersion()));
retVal = clReleaseContext(context);
@@ -2141,8 +2140,7 @@ TEST_F(GTPinTests, givenKernelWithSSHThenVerifyThatSSHResizeWorksWell) {
size_t offsetBTS1 = pKernel->getBindingTableOffset();
EXPECT_NE(0u, offsetBTS1);
GFXCORE_FAMILY genFamily = pDevice->getHardwareInfo().platform.eRenderCoreFamily;
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(genFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
void *pSS1 = gtpinHelper.getSurfaceState(pKernel, 0);
EXPECT_NE(nullptr, pSS1);
@@ -2461,7 +2459,7 @@ using GTPinTestsWithLocalMemory = Test<GTPinFixtureWithLocalMemory>;
TEST_F(GTPinTestsWithLocalMemory, whenPlatformHasNoSvmSupportThenGtPinBufferCantBeAllocatedInSharedMemory) {
DebugManager.flags.GTPinAllocateBufferInSharedMemory.set(-1);
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
auto canUseSharedAllocation = gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo());
if (!pDevice->getHardwareInfo().capabilityTable.ftrSvm) {
EXPECT_FALSE(canUseSharedAllocation);
@@ -2469,7 +2467,7 @@ TEST_F(GTPinTestsWithLocalMemory, whenPlatformHasNoSvmSupportThenGtPinBufferCant
}
HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinWithSupportForSharedAllocationWhenGtPinHelperFunctionsAreCalledThenCheckIfSharedAllocationCabBeUsed) {
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo())) {
GTEST_SKIP();
}
@@ -2509,7 +2507,7 @@ HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinWithSupportForSharedAllocationWhen
}
HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtPinBufferIsCreatedThenAllocateBufferInSharedMemory) {
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo())) {
GTEST_SKIP();
}
@@ -2545,7 +2543,7 @@ HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtPinBuf
}
HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtPinBufferIsAllocatedInSharedMemoryThenSetSurfaceStateForTheBufferAndMakeItResident) {
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
const auto &compilerProductHelper = pDevice->getRootDeviceEnvironment().getHelper<CompilerProductHelper>();
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo()) ||
compilerProductHelper.isForceToStatelessRequired() || !compilerProductHelper.isStatelessToStatefulBufferOffsetSupported()) {
@@ -2660,14 +2658,14 @@ HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtPinBuf
EXPECT_EQ(CL_SUCCESS, retVal);
}
HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtpinNotifyKernelSubmitThenMoveToAllocationDomainCalled) {
GTPinGfxCoreHelper &gtpinHelper = GTPinGfxCoreHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily);
auto &gtpinHelper = pDevice->getGTPinGfxCoreHelper();
if (!gtpinHelper.canUseSharedAllocation(pDevice->getHardwareInfo())) {
GTEST_SKIP();
}
class MockGTPinGfxCoreHelperHw : public GTPinGfxCoreHelperHw<FamilyType> {
public:
void *getSurfaceState(Kernel *pKernel, size_t bti) override {
return data;
void *getSurfaceState(Kernel *pKernel, size_t bti) const override {
return const_cast<void *>(static_cast<const void *>(data));
}
uint8_t data[128];
};