Skip to content

Commit

Permalink
[Decode] local memory mode switch
Browse files Browse the repository at this point in the history
[Decode] local memory mode switch

Change-Id: I7f3868852fe6c7bca375e400b8bd48b0c7b37070
  • Loading branch information
yangning1368 authored and Zhong, Xiaoxia committed Jan 8, 2021
1 parent d2d715b commit e4d6894
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 64 deletions.
9 changes: 9 additions & 0 deletions media_driver/agnostic/common/os/mos_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3838,6 +3838,15 @@ static MOS_USER_FEATURE_VALUE MOSUserFeatureDescFields[__MOS_USER_FEATURE_KEY_MA
MOS_USER_FEATURE_VALUE_TYPE_UINT32,
"0",
"Inter frame ninja counter"),
MOS_DECLARE_UF_KEY(__MEDIA_USER_FEATURE_VALUE_LOCAL_MEMORY_LEVEL_SWITCH_ID,
"EnableLocalMemoryLevelSwitch",
__MEDIA_USER_FEATURE_SUBKEY_INTERNAL,
__MEDIA_USER_FEATURE_SUBKEY_REPORT,
"MOS",
MOS_USER_FEATURE_TYPE_USER,
MOS_USER_FEATURE_VALUE_TYPE_UINT32,
"2",
"Enable local memory level switch.")
};

PMOS_USER_FEATURE_VALUE const MosUtilities::m_mosUserFeatureDescFields = MOSUserFeatureDescFields;
Expand Down
1 change: 1 addition & 0 deletions media_driver/agnostic/common/os/mos_utilities_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ typedef enum _MOS_USER_FEATURE_VALUE_ID
__MEDIA_USER_FEATURE_VALUE_APOGEIOS_HEVCD_ENABLE_ID,
__MEDIA_USER_FEATURE_VALUE_RESOURCE_ADDR_DUMP_ENABLE_ID,
__MEDIA_USER_FEATURE_VALUE_RA_MODE_ENABLE_ID,
__MEDIA_USER_FEATURE_VALUE_LOCAL_MEMORY_LEVEL_SWITCH_ID,
__MOS_USER_FEATURE_KEY_MAX_ID,
} MOS_USER_FEATURE_VALUE_ID;

Expand Down
33 changes: 16 additions & 17 deletions media_driver/agnostic/common/shared/memory_policy_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,31 @@
#include "memory_policy_manager.h"

int MemoryPolicyManager::UpdateMemoryPolicy(
MEDIA_FEATURE_TABLE* skuTable,
GMM_RESOURCE_INFO* resInfo,
const char* resName,
int preferredMemType)
MemoryPolicyParameter* memPolicyPar)
{
int mem_type = MOS_MEMPOOL_VIDEOMEMORY;

if(!skuTable || !resInfo)
if(!memPolicyPar || !memPolicyPar->skuTable || !memPolicyPar->resInfo)
{
MOS_OS_ASSERTMESSAGE("Null pointer");
return mem_type;
}

if(!MEDIA_IS_SKU(skuTable, FtrLocalMemory))
if(!MEDIA_IS_SKU(memPolicyPar->skuTable, FtrLocalMemory))
{
MOS_OS_VERBOSEMESSAGE("No FtrLocalMemory");
return mem_type;
}

GMM_TILE_TYPE tile_type = resInfo->GetTileType();
GMM_RESOURCE_FLAG& resFlag = resInfo->GetResFlags();
GMM_RESOURCE_TYPE res_type = resInfo->GetResourceType();
GMM_TILE_TYPE tile_type = memPolicyPar->resInfo->GetTileType();
GMM_RESOURCE_FLAG& resFlag = memPolicyPar->resInfo->GetResFlags();
GMM_RESOURCE_TYPE res_type = memPolicyPar->resInfo->GetResourceType();

if (preferredMemType != MOS_MEMPOOL_VIDEOMEMORY &&
preferredMemType != MOS_MEMPOOL_DEVICEMEMORY &&
preferredMemType != MOS_MEMPOOL_SYSTEMMEMORY)
if (memPolicyPar->preferredMemType != MOS_MEMPOOL_VIDEOMEMORY &&
memPolicyPar->preferredMemType != MOS_MEMPOOL_DEVICEMEMORY &&
memPolicyPar->preferredMemType != MOS_MEMPOOL_SYSTEMMEMORY)
{
MOS_OS_ASSERTMESSAGE("Wrong preferredMemType %d", preferredMemType);
MOS_OS_ASSERTMESSAGE("Wrong preferredMemType %d", memPolicyPar->preferredMemType);
return mem_type;
}

Expand All @@ -72,23 +69,25 @@ int MemoryPolicyManager::UpdateMemoryPolicy(
}

// Override setting, depending on preferredMemType
if ((preferredMemType & MOS_MEMPOOL_DEVICEMEMORY) && !(mem_type & MOS_MEMPOOL_DEVICEMEMORY))
if ((memPolicyPar->preferredMemType & MOS_MEMPOOL_DEVICEMEMORY) && !(mem_type & MOS_MEMPOOL_DEVICEMEMORY))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;
resFlag.Info.LocalOnly = 1;
resFlag.Info.NonLocalOnly = 0;
}

if ((preferredMemType & MOS_MEMPOOL_SYSTEMMEMORY) && !(mem_type & MOS_MEMPOOL_SYSTEMMEMORY))
if ((memPolicyPar->preferredMemType & MOS_MEMPOOL_SYSTEMMEMORY) && !(mem_type & MOS_MEMPOOL_SYSTEMMEMORY))
{
mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
resFlag.Info.LocalOnly = 0;
resFlag.Info.NonLocalOnly = 1;
}

uint32_t surfSize = (uint32_t)resInfo->GetSizeSurface();
UpdateMemoryPolicyWithWA(memPolicyPar, mem_type);

MOS_OS_NORMALMESSAGE("\"%s\" preferredMemType %d, mem_type %d, res_type %d, size %d", (resName ? resName : "Resource"), preferredMemType, mem_type, res_type, surfSize);
uint32_t surfSize = (uint32_t)memPolicyPar->resInfo->GetSizeSurface();

MOS_OS_NORMALMESSAGE("\"%s\" preferredMemType %d, mem_type %d, res_type %d, size %d", (memPolicyPar->resName ? memPolicyPar->resName : "Resource"), memPolicyPar->preferredMemType, mem_type, res_type, surfSize);

return mem_type;
}
48 changes: 39 additions & 9 deletions media_driver/agnostic/common/shared/memory_policy_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,55 @@

#include "mos_os.h"

//! \param [in] skuTable
//! The pointer to MEDIA_FEATURE_TABLE
//! \param [in] waTable
//! The pointer to MEDIA_WA_TABLE
//! \param [in, out] resInfo
//! The pointer to GMM_RESOURCE_INFO, resource description which gets updated
//! \param [in] resName
//! The pointer to resource name
//! \param [in] uiType
//! The pointer to resource type
//! \param [in] preferredMemType
//! Prefer which type of memory is allocated (device memory, system memory or default setting).
struct MemoryPolicyParameter
{
MEDIA_FEATURE_TABLE *skuTable;
MEDIA_WA_TABLE *waTable;
GMM_RESOURCE_INFO *resInfo;
const char* resName;
uint32_t uiType;
int preferredMemType;
};

class MemoryPolicyManager
{

public:

//! \brief Updates resource memory policy
//!
//! \details Update memory policy to decide which type of memory is allocated (device memory, system memory or default setting).
//! \param [in] memPolicyPar
//! The pointer to MemoryPolicyParameter
//!
//! \return new memory policy
static int UpdateMemoryPolicy(MemoryPolicyParameter* memPolicyPar);

private:

//! \brief Updates resource memory policy with WA
//!
//! \param [in] skuTable
//! The pointer to MEDIA_FEATURE_TABLE
//! \param [in, out] resInfo
//! The pointer to GMM_RESOURCE_INFO, resource description which gets updated
//! \param [in] resName
//! The pointer to resource name
//! \param [in] preferredMemType
//! Prefer which type of memory is allocated (device memory, system memory or default setting).
//! \details Update memory policy to decide which type of memory is allocated (device memory, system memory or default setting).
//! \param [in] memPolicyPar
//! The pointer to MemoryPolicyParameter
//!
//! \param [in/out] mem_type
//! The pointer to mem_type

//! \return new memory policy
static int UpdateMemoryPolicy(MEDIA_FEATURE_TABLE *skuTable, GMM_RESOURCE_INFO *resInfo, const char* resName, int preferredMemType = MOS_MEMPOOL_VIDEOMEMORY);
static int UpdateMemoryPolicyWithWA(MemoryPolicyParameter* memPolicyPar, int& mem_type);
};


Expand Down
49 changes: 26 additions & 23 deletions media_driver/linux/common/ddi/media_libva_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,16 @@ VAStatus DdiMediaUtil_AllocateSurface(
goto finish;
}

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&mediaDrvCtx->SkuTable, mediaSurface->pGmmResourceInfo, "Media Surface", mem_type);
MemoryPolicyParameter memPolicyPar;
MOS_ZeroMemory(&memPolicyPar, sizeof(MemoryPolicyParameter));

if(MEDIA_IS_WA(&mediaDrvCtx->WaTable, WaForceAllocateLM))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;
}
memPolicyPar.skuTable = &mediaDrvCtx->SkuTable;
memPolicyPar.waTable = &mediaDrvCtx->WaTable;
memPolicyPar.resInfo = mediaSurface->pGmmResourceInfo;
memPolicyPar.resName = "Media Surface";
memPolicyPar.preferredMemType = mem_type;

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

if (!DdiMediaUtil_IsExternalSurface(mediaSurface) ||
mediaSurface->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
Expand Down Expand Up @@ -675,21 +679,17 @@ VAStatus DdiMediaUtil_AllocateBuffer(
mediaBuffer->pGmmResourceInfo->OverrideBaseWidth(mediaBuffer->iSize);
mediaBuffer->pGmmResourceInfo->OverridePitch(mediaBuffer->iSize);

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(
&mediaBuffer->pMediaCtx->SkuTable,
mediaBuffer->pGmmResourceInfo,
"Media Buffer",
mediaBuffer->bUseSysGfxMem ? MOS_MEMPOOL_SYSTEMMEMORY : 0);
MemoryPolicyParameter memPolicyPar;
MOS_ZeroMemory(&memPolicyPar, sizeof(MemoryPolicyParameter));

if(MEDIA_IS_WA(&mediaBuffer->pMediaCtx->WaTable, WaForceAllocateLM))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;
memPolicyPar.skuTable = &mediaBuffer->pMediaCtx->SkuTable;
memPolicyPar.waTable = &mediaBuffer->pMediaCtx->WaTable;
memPolicyPar.resInfo = mediaBuffer->pGmmResourceInfo;
memPolicyPar.resName = "Media Buffer";
memPolicyPar.uiType = mediaBuffer->uiType;
memPolicyPar.preferredMemType = mediaBuffer->bUseSysGfxMem ? MOS_MEMPOOL_SYSTEMMEMORY : 0;

if(mediaBuffer->uiType == VAEncCodedBufferType)
{
mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
}
}
mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

MOS_LINUX_BO *bo = mos_bo_alloc(bufmgr, "Media Buffer", size, 4096, mem_type);

Expand Down Expand Up @@ -780,12 +780,15 @@ VAStatus DdiMediaUtil_Allocate2DBuffer(
gmmSize = (uint32_t)gmmResourceInfo->GetSizeSurface();
gmmHeight = gmmResourceInfo->GetBaseHeight();

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&mediaBuffer->pMediaCtx->SkuTable, mediaBuffer->pGmmResourceInfo, "Media 2D Buffer");
MemoryPolicyParameter memPolicyPar;
MOS_ZeroMemory(&memPolicyPar, sizeof(MemoryPolicyParameter));

if(MEDIA_IS_WA(&mediaBuffer->pMediaCtx->WaTable, WaForceAllocateLM))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;
}
memPolicyPar.skuTable = &mediaBuffer->pMediaCtx->SkuTable;
memPolicyPar.waTable = &mediaBuffer->pMediaCtx->WaTable;
memPolicyPar.resInfo = mediaBuffer->pGmmResourceInfo;
memPolicyPar.resName = "Media 2D Buffer";

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

MOS_LINUX_BO *bo;
bo = mos_bo_alloc(bufmgr, "Media 2D Buffer", gmmSize, 4096, mem_type);
Expand Down
1 change: 1 addition & 0 deletions media_driver/linux/common/os/media_srcs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(TMP_SOURCES_
${CMAKE_CURRENT_LIST_DIR}/mos_auxtable_mgr.cpp
${CMAKE_CURRENT_LIST_DIR}/mos_interface.cpp
${CMAKE_CURRENT_LIST_DIR}/mos_gpucontext_specific_ext.cpp
${CMAKE_CURRENT_LIST_DIR}/memory_policy_manager_specific.cpp
)

set(TMP_HEADERS_
Expand Down
58 changes: 58 additions & 0 deletions media_driver/linux/common/os/memory_policy_manager_specific.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2020, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file memory_policy_manager_specific.cpp
//! \brief Defines interfaces for media memory policy manager.

#include "memory_policy_manager.h"


int MemoryPolicyManager::UpdateMemoryPolicyWithWA(
MemoryPolicyParameter* memPolicyPar,
int& mem_type)
{
if (!memPolicyPar || !memPolicyPar->skuTable || !memPolicyPar->resInfo)
{
MOS_OS_ASSERTMESSAGE("Null pointer");
return 0;
}

if (MEDIA_IS_WA(memPolicyPar->waTable, WaForceAllocateLML2))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;

if (memPolicyPar->uiType == VAEncCodedBufferType)
{
mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
}
}

if (MEDIA_IS_WA(memPolicyPar->waTable, WaForceAllocateLML3))
{
if(memPolicyPar->preferredMemType == MOS_MEMPOOL_VIDEOMEMORY)
{
mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
}
}

return 0;
}
14 changes: 9 additions & 5 deletions media_driver/linux/common/os/mos_graphicsresource_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,16 @@ MOS_STATUS GraphicsResourceSpecific::Allocate(OsContext* osContextPtr, CreatePar

if(!params.m_pSystemMemory)
{
mem_type = MemoryPolicyManager::UpdateMemoryPolicy(pOsContextSpecific->GetSkuTable(), gmmResourceInfoPtr, params.m_name.c_str(), params.m_memType);
MemoryPolicyParameter memPolicyPar;
MOS_ZeroMemory(&memPolicyPar, sizeof(MemoryPolicyParameter));

if(MEDIA_IS_WA(pOsContextSpecific->GetWaTable(), WaForceAllocateLM))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;
}
memPolicyPar.skuTable = pOsContextSpecific->GetSkuTable();
memPolicyPar.waTable = pOsContextSpecific->GetWaTable();
memPolicyPar.resInfo = gmmResourceInfoPtr;
memPolicyPar.resName = params.m_name.c_str();
memPolicyPar.preferredMemType = params.m_memType;

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);
}

MOS_TraceEventExt(EVENT_RESOURCE_ALLOCATE, EVENT_TYPE_START, nullptr, 0, nullptr, 0);
Expand Down
14 changes: 9 additions & 5 deletions media_driver/linux/common/os/mos_os_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -2492,12 +2492,16 @@ MOS_STATUS Mos_Specific_AllocateResource(
iSize = GFX_ULONG_CAST(pGmmResourceInfo->GetSizeSurface());
iHeight = pGmmResourceInfo->GetBaseHeight();

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&pOsInterface->pOsContext->SkuTable, pGmmResourceInfo, pParams->pBufName, pParams->dwMemType);
MemoryPolicyParameter memPolicyPar;
MOS_ZeroMemory(&memPolicyPar, sizeof(MemoryPolicyParameter));

if (MEDIA_IS_WA(&pOsInterface->pOsContext->WaTable, WaForceAllocateLM))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;
}
memPolicyPar.skuTable = &pOsInterface->pOsContext->SkuTable;
memPolicyPar.waTable = &pOsInterface->pOsContext->WaTable;
memPolicyPar.resInfo = pGmmResourceInfo;
memPolicyPar.resName = pParams->pBufName;
memPolicyPar.preferredMemType = pParams->dwMemType;

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

// Only Linear and Y TILE supported
if( tileformat_linux == I915_TILING_NONE )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,16 @@ MOS_STATUS GraphicsResourceSpecificNext::Allocate(OsContextNext* osContextPtr, C

if(!params.m_pSystemMemory)
{
mem_type = MemoryPolicyManager::UpdateMemoryPolicy(pOsContextSpecific->GetSkuTable(), gmmResourceInfoPtr, params.m_name.c_str(), params.m_memType);
MemoryPolicyParameter memPolicyPar;
MOS_ZeroMemory(&memPolicyPar, sizeof(MemoryPolicyParameter));

if(MEDIA_IS_WA(pOsContextSpecific->GetWaTable(), WaForceAllocateLM))
{
mem_type = MOS_MEMPOOL_DEVICEMEMORY;
}
memPolicyPar.skuTable = pOsContextSpecific->GetSkuTable();
memPolicyPar.waTable = pOsContextSpecific->GetWaTable();
memPolicyPar.resInfo = gmmResourceInfoPtr;
memPolicyPar.resName = params.m_name.c_str();
memPolicyPar.preferredMemType = params.m_memType;

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);
}

uint32_t bufPitch = GFX_ULONG_CAST(gmmResourceInfoPtr->GetRenderPitch());
Expand Down

0 comments on commit e4d6894

Please sign in to comment.