| 1 |
/* |
| 2 |
* Copyright (c) 2018, 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 mos_gpucontextmgr.h |
| 24 |
//! \brief Container class for the gpu context manager |
| 25 |
//! |
| 26 |
|
| 27 |
#ifndef __MOS_GPU_CONTEXT_MGR_H__ |
| 28 |
#define __MOS_GPU_CONTEXT_MGR_H__ |
| 29 |
|
| 30 |
#include "mos_os.h" |
| 31 |
#include "mos_gpucontext.h" |
| 32 |
|
| 33 |
//! |
| 34 |
//! \class GpuContextMgr |
| 35 |
//! |
| 36 |
class GpuContextMgr |
| 37 |
{ |
| 38 |
public: |
| 39 |
//! |
| 40 |
//! \brief Constructor |
| 41 |
//! |
| 42 |
GpuContextMgr(GT_SYSTEM_INFO *gtSystemInfo, OsContext *osContext); |
| 43 |
|
| 44 |
//! |
| 45 |
//! \brief Copy constructor |
| 46 |
//! |
| 47 |
GpuContextMgr(const GpuContextMgr&) = delete; |
| 48 |
|
| 49 |
//! |
| 50 |
//! \brief Copy assignment operator |
| 51 |
//! |
| 52 |
GpuContextMgr& operator=(const GpuContextMgr&) = delete; |
| 53 |
|
| 54 |
//! |
| 55 |
//! \brief Destructor |
| 56 |
//! |
| 57 |
virtual ~GpuContextMgr(); |
| 58 |
|
| 59 |
//! |
| 60 |
//! \brief Static entrypoint, get gpu context manager object |
| 61 |
//! \return GpuContextMgr* |
| 62 |
//! gpu context manager specific object if success, else nullptr |
| 63 |
//! |
| 64 |
static GpuContextMgr* GetObject( |
| 65 |
GT_SYSTEM_INFO *gtSystemInfo, |
| 66 |
OsContext *osContext); |
| 67 |
|
| 68 |
//! |
| 69 |
//! \brief Clean up the gpu context manager |
| 70 |
//! \details This function mainly celar all allocated gpu context in |
| 71 |
//! apu context array |
| 72 |
//! |
| 73 |
void CleanUp(); |
| 74 |
|
| 75 |
//! |
| 76 |
//! \brief Create GPU context |
| 77 |
//! \param [in] gpuNode |
| 78 |
//! Reqired gpu node |
| 79 |
//! \param [in] cmdBufMgr |
| 80 |
//! Command buffer manager |
| 81 |
//! \param [in] mosGpuCtx |
| 82 |
//! Required gpu context type |
| 83 |
//! \return GpuContext* |
| 84 |
//! Gpu context pointer if success, otherwise nullptr |
| 85 |
//! |
| 86 |
GpuContext* CreateGpuContext( |
| 87 |
const MOS_GPU_NODE gpuNode, |
| 88 |
CmdBufMgr *cmdBufMgr, |
| 89 |
MOS_GPU_CONTEXT mosGpuCtx); |
| 90 |
|
| 91 |
//! |
| 92 |
//! \brief Get GPU context base on gpu context handle |
| 93 |
//! \detail Gpu context manager maintain an array, gpu context handle |
| 94 |
//! as its index. |
| 95 |
//! \param [in] gpuContextHandle |
| 96 |
//! Reqired gpu context's handle |
| 97 |
//! \return GpuContext* |
| 98 |
//! Gpu context pointer if success, otherwise nullptr |
| 99 |
//! |
| 100 |
GpuContext* GetGpuContext(GPU_CONTEXT_HANDLE gpuContextHandle); |
| 101 |
|
| 102 |
//! |
| 103 |
//! \brief Destroy specified gpu context |
| 104 |
//! \param [in] gpuContext |
| 105 |
//! Gpu context need to be destroyed |
| 106 |
//! |
| 107 |
void DestroyGpuContext(GpuContext *gpuContext); |
| 108 |
|
| 109 |
//! |
| 110 |
//! \brief Destroy all gpu context instance |
| 111 |
//! \detail Destroy all gpu context maintained in m_gpuContextArray |
| 112 |
//! |
| 113 |
void DestroyAllGpuContexts(); |
| 114 |
|
| 115 |
//! |
| 116 |
//! \brief Determine whether gpu context reuse is needed |
| 117 |
//! \detail Implementation to be added after reuse scheme is nailed down |
| 118 |
//! \return bool |
| 119 |
//! True if needed, otherwise false |
| 120 |
//! |
| 121 |
bool ContextReuseNeeded(); |
| 122 |
|
| 123 |
//! |
| 124 |
//! \brief Select one gpu context to be reused |
| 125 |
//! \detail Implementation to be added after reuse scheme is nailed down |
| 126 |
//! \return GpuContext* |
| 127 |
//! Gpu context pointer if success, otherwise nullptr |
| 128 |
//! |
| 129 |
GpuContext* SelectContextToReuse(); |
| 130 |
|
| 131 |
//! |
| 132 |
//! \brief Get os context used in manager |
| 133 |
//! \return OsContext* |
| 134 |
//! Os context pointer if success, otherwise nullptr |
| 135 |
//! |
| 136 |
OsContext* GetOsContext() { return m_osContext; } |
| 137 |
|
| 138 |
//! |
| 139 |
//! \brief Get Gpu context number |
| 140 |
//! \return uint32_t |
| 141 |
//! Number of all Gpu contexts, include the node which was already destroyed |
| 142 |
//! |
| 143 |
uint32_t GetGpuContextNumber() |
| 144 |
{ |
| 145 |
return m_gpuContextArray.size(); |
| 146 |
} |
| 147 |
|
| 148 |
//! |
| 149 |
//! \brief Get the validity flag |
| 150 |
//! \return bool |
| 151 |
//! Get the validity flag of GpuContextMgr |
| 152 |
//! |
| 153 |
bool IsInitialized() |
| 154 |
{ |
| 155 |
return m_initialized; |
| 156 |
} |
| 157 |
|
| 158 |
//! \brief Indicate whether new gpu context is inserted into the first slot w/ null ctx handle |
| 159 |
//! or always at the end of the gpucontext array |
| 160 |
bool m_noCycledGpuCxtMgmt = false; |
| 161 |
|
| 162 |
protected: |
| 163 |
//! \brief Gt system info |
| 164 |
//! \detail reserve to reuse gpu context |
| 165 |
GT_SYSTEM_INFO m_gtSystemInfo = {}; |
| 166 |
|
| 167 |
//! \brief Os Context |
| 168 |
OsContext *m_osContext = nullptr; |
| 169 |
|
| 170 |
//! \brief Gpu context array mutex |
| 171 |
PMOS_MUTEX m_gpuContextArrayMutex = nullptr; |
| 172 |
|
| 173 |
//! \brief Gpu context count |
| 174 |
uint32_t m_gpuContextCount = 0; |
| 175 |
|
| 176 |
//! \brief Maintained gpu context array |
| 177 |
std::vector<GpuContext *> m_gpuContextArray; |
| 178 |
|
| 179 |
//! \brief Flag to indicate gpu context mgr initialized or not |
| 180 |
bool m_initialized = false; |
| 181 |
}; |
| 182 |
|
| 183 |
#endif // #ifndef __MOS_GPU_CONTEXT_MGR_H__ |