1 /* 2 * Copyright (c) 2017, 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 cm_task_internal.h 24 //! \brief Contains Class CmTaskInternal definitions 25 //! 26 27 #ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMTASKINTERNAL_H_ 28 #define MEDIADRIVER_AGNOSTIC_COMMON_CM_CMTASKINTERNAL_H_ 29 30 #include "cm_def.h" 31 #include "cm_array.h" 32 #include "cm_event.h" 33 #include "cm_hal.h" 34 #include "cm_hal_vebox.h" 35 #include "cm_log.h" 36 37 enum CM_INTERNAL_TASK_TYPE 38 { 39 CM_INTERNAL_TASK_WITH_THREADSPACE, 40 CM_INTERNAL_TASK_WITH_THREADGROUPSPACE, 41 CM_INTERNAL_TASK_VEBOX, 42 CM_INTERNAL_TASK_ENQUEUEWITHHINTS 43 }; 44 45 #define CM_TASK_TYPE_DEFAULT CM_INTERNAL_TASK_WITH_THREADSPACE 46 47 //*----------------------------------------------------------------------------- 48 //| CM Task Profiling Information 49 //*----------------------------------------------------------------------------- 50 struct CM_PROFILING_INFO 51 { 52 uint32_t taskID; 53 uint32_t threadID; 54 uint32_t kernelCount; 55 uint32_t kernelNameLen; 56 char *kernelNames; 57 uint32_t *localWorkWidth; 58 uint32_t *localWorkHeight; 59 uint32_t *globalWorkWidth; 60 uint32_t *globalWorkHeight; 61 62 LARGE_INTEGER enqueueTime; 63 LARGE_INTEGER flushTime; 64 LARGE_INTEGER hwStartTime; 65 LARGE_INTEGER hwEndTime; 66 LARGE_INTEGER completeTime; 67 }; 68 69 namespace CMRT_UMD 70 { 71 class CmKernelRT; 72 class CmEventRT; 73 class CmKernelData; 74 class CmThreadSpaceRT; 75 class CmThreadGroupSpace; 76 class CmDeviceRT; 77 class CmVeboxRT; 78 class CmVeboxData; 79 class CmBufferUP; 80 81 class CmTaskInternal: public CmDynamicArray 82 { 83 public: 84 85 static int32_t Create( const uint32_t kernelCount, const uint32_t totalThreadCount, 86 CmKernelRT* kernelArray[], const CmThreadSpaceRT* threadSpace, 87 CmDeviceRT* device, const uint64_t syncBitmap, CmTaskInternal*& task, 88 const uint64_t conditionalEndBitmap, 89 PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo ); 90 static int32_t Destroy( CmTaskInternal* &task ); 91 static int32_t Create( const uint32_t kernelCount, const uint32_t totalThreadCount, 92 CmKernelRT* kernelArray[], const CmThreadGroupSpace* threadGroupSpace, 93 CmDeviceRT* device, const uint64_t syncBitmap, CmTaskInternal*& task, 94 const uint64_t conditionalEndBitmap, 95 PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo, 96 const CM_EXECUTION_CONFIG* krnExecCfg); 97 static int32_t Create( CmDeviceRT* device, CmVeboxRT* vebox, CmTaskInternal*& task ); 98 static int32_t Create( const uint32_t kernelCount, const uint32_t totalThreadCount, 99 CmKernelRT* kernelArray[], CmTaskInternal*& task, 100 uint32_t numGeneratedTasks, bool isLastTask, uint32_t hints, 101 CmDeviceRT* device); 102 103 int32_t GetKernelCount( uint32_t& count ); 104 int32_t GetKernel( const uint32_t index, CmKernelRT* & kernel ); 105 int32_t GetKernelData( const uint32_t index, CmKernelData* & kernelData ); 106 int32_t GetKernelDataSize( const uint32_t index, uint32_t & size ); 107 uint32_t GetKernelCurbeOffset( const uint32_t index ); 108 int32_t GetTotalThreadCount( uint32_t& totalThreadCount ); 109 110 int32_t SetTaskEvent( CmEventRT* event ); 111 int32_t GetTaskEvent( CmEventRT* & event ); 112 113 int32_t CreateThreadSpaceData(const CmThreadSpaceRT* threadSpace); 114 int32_t GetKernelCoordinates(const uint32_t index, void *&kernelCoordinates); 115 int32_t GetKernelDependencyMasks(const uint32_t index, void *&kernelDependencyMasks); 116 int32_t GetDependencyPattern(CM_DEPENDENCY_PATTERN &dependencyPattern); 117 int32_t GetWalkingPattern(CM_WALKING_PATTERN &walkingPattern); 118 int32_t GetWalkingParameters(CM_WALKING_PARAMETERS &walkingParameters); 119 int32_t GetDependencyVectors(CM_HAL_DEPENDENCY &dependencyVector); 120 bool CheckWalkingParametersSet(); 121 bool CheckDependencyVectorsSet(); 122 #if _DEBUG 123 int32_t DisplayThreadSpaceData(uint32_t width, uint32_t height); 124 #endif 125 int32_t GetThreadSpaceSize(uint32_t& width, uint32_t& height ); 126 int32_t GetThreadGroupSpaceSize(uint32_t& threadSpaceWidth, uint32_t& threadSpaceHeight, 127 uint32_t& threadSpaceDepth, uint32_t& groupSpaceWidth, 128 uint32_t& groupSpaceHeight, uint32_t& groupSpaceDepth); 129 int32_t GetSLMSize(uint32_t& slmSize); 130 int32_t GetSpillMemUsed(uint32_t& spillMemUsed); 131 int32_t GetColorCountMinusOne(uint32_t& colorCount); 132 int32_t GetMediaWalkerGroupSelect(CM_MW_GROUP_SELECT& groupSelect); 133 int32_t GetHints(uint32_t& hints); 134 int32_t GetNumTasksGenerated(uint32_t& numTasksGenerated); 135 int32_t GetLastTask(bool& isLastTask); 136 137 bool IsThreadGroupSpaceCreated(void); 138 bool IsThreadSpaceCreated(void ); 139 bool IsThreadCoordinatesExisted(void); 140 141 int32_t AllocateKernelSurfInfo(); 142 int32_t GetKernelSurfInfo(CM_HAL_SURFACE_ENTRY_INFO_ARRAYS & surfEntryInfoArray); 143 int32_t ClearKernelSurfInfo(); 144 int32_t ResetKernelDataStatus(); 145 146 int32_t GetTaskType(uint32_t& taskType); 147 148 int32_t GetVeboxState(CM_VEBOX_STATE & veboxState); 149 int32_t GetVeboxParam(CmBufferUP * &veboxParam); 150 int32_t GetVeboxSurfaceData(CM_VEBOX_SURFACE_DATA &veboxSurfaceData); 151 152 int32_t GetTaskSurfaces( bool *&surfArray ); 153 154 uint64_t GetSyncBitmap(); 155 uint64_t GetConditionalEndBitmap(); 156 CM_HAL_CONDITIONAL_BB_END_INFO* GetConditionalEndInfo(); 157 158 int32_t SetPowerOption( PCM_POWER_OPTION powerOption ); 159 PCM_POWER_OPTION GetPowerOption(); 160 int32_t GetTaskStatus(CM_STATUS & taskStatus); 161 int32_t SetProperty(CM_TASK_CONFIG * taskConfig); 162 int32_t GetProperty(CM_TASK_CONFIG &taskConfig); GetKernelExecuteConfig()163 const CM_EXECUTION_CONFIG* GetKernelExecuteConfig() { return m_krnExecCfg; }; 164 void *GetMediaStatePtr(); 165 #if CM_LOG_ON 166 std::string Log(); 167 #endif 168 169 void SurfaceDump(int32_t taskId); 170 171 int32_t VtuneInitProfilingInfo(const CmThreadGroupSpace *perTaskThreadGroupSpace); 172 int32_t VtuneInitProfilingInfo(const CmThreadSpaceRT *perTaskThreadSpace); 173 int32_t VtuneSetFlushTime(); 174 175 protected: 176 177 CmTaskInternal(const uint32_t kernelCount, const uint32_t totalThreadCount, 178 CmKernelRT* kernelArray[], CmDeviceRT* device, const uint64_t syncBitmap, 179 const uint64_t conditionalEndBitmap, 180 PCM_HAL_CONDITIONAL_BB_END_INFO conditionalEndInfo, 181 const CM_EXECUTION_CONFIG* krnExecCfg); 182 ~CmTaskInternal( void ); 183 184 int32_t Initialize(const CmThreadSpaceRT* threadSpace, bool isWithHints); 185 int32_t Initialize(const CmThreadGroupSpace* threadGroupSpace); 186 187 int32_t Initialize(CmVeboxRT* vebox); 188 int32_t Initialize(uint32_t hints, uint32_t numTasksGenerated, bool isLastTask); 189 190 int32_t VtuneWriteEventInfo(); 191 int32_t VtuneReleaseProfilingInfo(); 192 193 int32_t UpdateSurfaceStateOnTaskCreation(); 194 195 CmDynamicArray m_kernels; 196 CmDynamicArray m_kernelData; // one CmKernelData* per kernel 197 uint32_t *m_kernelCurbeOffsetArray; // Array to record each kernel's curbe offset. Even the same kernel could have different curbe offset. 198 uint32_t m_kernelCount; 199 200 uint32_t m_totalThreadCount; //total thread count per task 201 202 CmEventRT* m_taskEvent; 203 204 //ThreadSpaceInformation from CreateThreadSpace() or CreateThreadGroupSpace() 205 bool m_isThreadSpaceCreated; 206 bool m_isThreadCoordinatesExisted; 207 uint32_t m_threadSpaceWidth; 208 uint32_t m_threadSpaceHeight; 209 uint32_t m_threadSpaceDepth; 210 211 PCM_HAL_SCOREBOARD *m_threadCoordinates; 212 CM_DEPENDENCY_PATTERN m_dependencyPattern; 213 CM_WALKING_PATTERN m_walkingPattern; 214 uint32_t m_walkingParameters[CM_NUM_DWORD_FOR_MW_PARAM]; 215 bool m_mediaWalkerParamsSet; 216 CM_HAL_DEPENDENCY m_dependencyVectors; 217 bool m_dependencyVectorsSet; 218 PCM_HAL_MASK_AND_RESET *m_dependencyMasks; 219 CM_MW_GROUP_SELECT m_mediaWalkerGroupSelect; 220 221 bool m_isThreadGroupSpaceCreated; 222 uint32_t m_groupSpaceWidth; 223 uint32_t m_groupSpaceHeight; 224 uint32_t m_groupSpaceDepth; 225 uint32_t m_slmSize; //SLM size per thread group in 1KB unit 226 uint32_t m_spillMemUsed; 227 228 uint32_t m_colorCountMinusOne; 229 uint32_t m_hints; 230 uint32_t m_numTasksGenerated; 231 bool m_isLastTask; 232 233 uint64_t m_ui64SyncBitmap; 234 uint64_t m_ui64ConditionalEndBitmap; 235 CM_HAL_CONDITIONAL_BB_END_INFO m_conditionalEndInfo[CM_MAX_CONDITIONAL_END_CMDS]; 236 237 CM_HAL_SURFACE_ENTRY_INFO_ARRAYS m_kernelSurfInfo; 238 CmDeviceRT* m_cmDevice; 239 bool *m_surfaceArray; // vector-flag of surfaces R/W by this CM Task (containing multi-kernel) 240 bool m_isSurfaceUpdateDone; 241 242 uint32_t m_taskType; //0 - Task with thread space, 1 - Task with thread group space, 2 - Task for VEBOX 243 244 CmBufferUP * m_veboxParam; 245 CM_VEBOX_STATE m_veboxState; 246 CM_VEBOX_SURFACE_DATA m_veboxSurfaceData; 247 248 CM_POWER_OPTION m_powerOption; 249 CM_PROFILING_INFO m_taskProfilingInfo; 250 CM_TASK_CONFIG m_taskConfig; 251 CM_EXECUTION_CONFIG m_krnExecCfg[CM_MAX_KERNELS_PER_TASK]; 252 void *m_mediaStatePtr; 253 private: 254 CmTaskInternal (const CmTaskInternal& other); 255 CmTaskInternal& operator= (const CmTaskInternal& other); 256 }; 257 }; //namespace 258 259 #endif // #ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMTASKINTERNAL_H_ 260