1 /*
2 * Copyright (c) 2020, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file memory_policy_manager.cpp
24 //! \brief Defines interfaces for media memory policy manager.
25
26 #include "memory_policy_manager.h"
27
UpdateMemoryPolicy(MemoryPolicyParameter * memPolicyPar)28 int MemoryPolicyManager::UpdateMemoryPolicy(
29 MemoryPolicyParameter* memPolicyPar)
30 {
31 int mem_type = MOS_MEMPOOL_VIDEOMEMORY;
32
33 if(!memPolicyPar || !memPolicyPar->skuTable || !memPolicyPar->resInfo)
34 {
35 MOS_OS_ASSERTMESSAGE("Null pointer");
36 return mem_type;
37 }
38
39 if(!MEDIA_IS_SKU(memPolicyPar->skuTable, FtrLocalMemory))
40 {
41 MOS_OS_VERBOSEMESSAGE("No FtrLocalMemory");
42 return mem_type;
43 }
44
45 GMM_TILE_TYPE tile_type = memPolicyPar->resInfo->GetTileType();
46 GMM_RESOURCE_FLAG& resFlag = memPolicyPar->resInfo->GetResFlags();
47 GMM_RESOURCE_TYPE res_type = memPolicyPar->resInfo->GetResourceType();
48
49 if (memPolicyPar->preferredMemType != MOS_MEMPOOL_VIDEOMEMORY &&
50 memPolicyPar->preferredMemType != MOS_MEMPOOL_DEVICEMEMORY &&
51 memPolicyPar->preferredMemType != MOS_MEMPOOL_SYSTEMMEMORY)
52 {
53 MOS_OS_ASSERTMESSAGE("Wrong preferredMemType %d", memPolicyPar->preferredMemType);
54 return mem_type;
55 }
56
57 // Follow default setting, tiled resource in Video Memory, 1D linear resource in System Memory
58 if (tile_type == GMM_NOT_TILED && res_type == RESOURCE_1D)
59 {
60 mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
61 resFlag.Info.LocalOnly = 0;
62 resFlag.Info.NonLocalOnly = 1;
63 }
64 else
65 {
66 mem_type = MOS_MEMPOOL_VIDEOMEMORY;
67 resFlag.Info.LocalOnly = 0;
68 resFlag.Info.NonLocalOnly = 0;
69 }
70
71 // Override setting, depending on preferredMemType
72 if ((memPolicyPar->preferredMemType & MOS_MEMPOOL_DEVICEMEMORY) && !(mem_type & MOS_MEMPOOL_DEVICEMEMORY))
73 {
74 mem_type = MOS_MEMPOOL_DEVICEMEMORY;
75 resFlag.Info.LocalOnly = 1;
76 resFlag.Info.NonLocalOnly = 0;
77 }
78
79 if ((memPolicyPar->preferredMemType & MOS_MEMPOOL_SYSTEMMEMORY) && !(mem_type & MOS_MEMPOOL_SYSTEMMEMORY))
80 {
81 mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
82 resFlag.Info.LocalOnly = 0;
83 resFlag.Info.NonLocalOnly = 1;
84 }
85
86 UpdateMemoryPolicyWithWA(memPolicyPar, mem_type);
87
88 uint32_t surfSize = (uint32_t)memPolicyPar->resInfo->GetSizeSurface();
89
90 if (1 == resFlag.Info.LocalOnly && 0 == resFlag.Info.NotLockable)
91 {
92 MOS_OS_ASSERTMESSAGE("Invalid setting! Local only memory with cpu visible.");
93 MOS_OS_ASSERTMESSAGE("\"%s\" preferredMemType %d, mem_type %d, res_type %d, size %d", (memPolicyPar->resName ? memPolicyPar->resName : "Resource"), memPolicyPar->preferredMemType, mem_type, res_type, surfSize);
94 }
95 else
96 {
97 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);
98 }
99
100 return mem_type;
101 }
102