Skip to content

Commit cd4f181

Browse files
shengconintel-mediadev
authored andcommitted
[CM] Aligns object reuse policy in creating CmQueue in Cmrtlib and UMD.
CreateQueue() and CreateQueueEx() will create one and only one render queue, but multiple compute queue as required. Change-Id: Iac58a858bf78747890e03c34e9eb4f0f5ffe5ccc
1 parent c3c05ee commit cd4f181

File tree

4 files changed

+48
-95
lines changed

4 files changed

+48
-95
lines changed

cmrtlib/agnostic/hardware/cm_device.cpp

+23-39
Original file line numberDiff line numberDiff line change
@@ -321,40 +321,12 @@ CM_RT_API int32_t CmDevice_RT::DestroyTask( CmTask*& task)
321321
//! CM_OUT_OF_HOST_MEMORY if out of system memory;
322322
//! CM_FAILURE otherwise;
323323
//!
324-
CM_RT_API int32_t CmDevice_RT::CreateQueue( CmQueue* & queue )
324+
CM_RT_API int32_t CmDevice_RT::CreateQueue(CmQueue* &queue)
325325
{
326326
INSERT_PROFILER_RECORD();
327327

328-
// For legacy CreateQueue API, we will only return the same queue
329-
m_criticalSectionQueue.Acquire();
330-
for (auto iter = m_queue.begin(); iter != m_queue.end(); iter++)
331-
{
332-
CM_QUEUE_TYPE queueType = (*iter)->GetQueueOption().QueueType;
333-
if (queueType == CM_QUEUE_TYPE_RENDER)
334-
{
335-
queue = (*iter);
336-
m_criticalSectionQueue.Release();
337-
return CM_SUCCESS;
338-
}
339-
}
340-
341-
CmQueue_RT *queueRT = nullptr;
342-
int32_t result = CmQueue_RT::Create(this, queueRT);
343-
if (result != CM_SUCCESS)
344-
{
345-
CmAssert(0);
346-
CmDebugMessage(("Failed to create queue!"));
347-
m_criticalSectionQueue.Release();
348-
return result;
349-
}
350-
351-
m_queue.push_back(queueRT);
352-
m_criticalSectionQueue.Release();
353-
354-
if (queueRT != nullptr)
355-
{
356-
queue = static_cast< CmQueue* >(queueRT);
357-
}
328+
CM_QUEUE_CREATE_OPTION option = CM_DEFAULT_QUEUE_CREATE_OPTION;
329+
int32_t result = CreateQueueEx(queue, option);
358330

359331
#if USE_EXTENSION_CODE
360332
GTPIN_MAKER_FUNCTION(CmrtCodeMarkerForGTPin_CreateQueue(this, queue));
@@ -363,28 +335,40 @@ CM_RT_API int32_t CmDevice_RT::CreateQueue( CmQueue* & queue )
363335
return result;
364336
}
365337

366-
CM_RT_API int32_t CmDevice_RT::CreateQueueEx(CmQueue *&queue, CM_QUEUE_CREATE_OPTION queueCreateOption)
338+
CM_RT_API int32_t
339+
CmDevice_RT::CreateQueueEx(CmQueue* &queue,
340+
CM_QUEUE_CREATE_OPTION queueCreateOption)
367341
{
368342
INSERT_PROFILER_RECORD();
369-
370343
m_criticalSectionQueue.Acquire();
344+
371345
CmQueue_RT *queueRT = nullptr;
346+
if (CM_QUEUE_TYPE_RENDER == queueCreateOption.QueueType)
347+
{
348+
for (auto iter = m_queue.begin(); iter != m_queue.end(); ++iter)
349+
{
350+
CM_QUEUE_TYPE queueType = (*iter)->GetQueueOption().QueueType;
351+
if (queueType == CM_QUEUE_TYPE_RENDER)
352+
{
353+
queue = (*iter);
354+
m_criticalSectionQueue.Release();
355+
return CM_SUCCESS;
356+
}
357+
}
358+
}
359+
372360
int32_t result = CmQueue_RT::Create(this, queueRT, queueCreateOption);
373-
if (result != CM_SUCCESS)
361+
if (CM_SUCCESS != result || nullptr == queueRT)
374362
{
375363
CmAssert(0);
376364
CmDebugMessage(("Failed to create queue!"));
377365
m_criticalSectionQueue.Release();
378366
return result;
379367
}
380-
381368
m_queue.push_back(queueRT);
369+
queue = queueRT;
382370
m_criticalSectionQueue.Release();
383371

384-
if (queueRT != nullptr)
385-
{
386-
queue = static_cast< CmQueue* >(queueRT);
387-
}
388372
return result;
389373
}
390374

cmrtlib/agnostic/hardware/cm_queue.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,6 @@ struct CM_ENQUEUE_VEBOX_PARAM
112112
int32_t returnValue; // [out] return value
113113
};
114114

115-
int32_t CmQueue_RT::Create(CmDevice_RT *device, CmQueue_RT *&queue)
116-
{
117-
int32_t result = CM_SUCCESS;
118-
queue = new(std::nothrow) CmQueue_RT(device, CM_DEFAULT_QUEUE_CREATE_OPTION);
119-
if (queue)
120-
{
121-
result = queue->Initialize();
122-
if (result != CM_SUCCESS)
123-
{
124-
CmQueue_RT::Destroy(queue);
125-
}
126-
}
127-
else
128-
{
129-
CmAssert(0);
130-
result = CM_OUT_OF_HOST_MEMORY;
131-
}
132-
return result;
133-
}
134-
135115
int32_t CmQueue_RT::Create(CmDevice_RT *device, CmQueue_RT *&queue, CM_QUEUE_CREATE_OPTION queueCreateOption)
136116
{
137117
int32_t result = CM_SUCCESS;

cmrtlib/agnostic/hardware/cm_queue.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ typedef struct _CM_ENQUEUE_GPUCOPY_PARAM
7171
class CmQueue_RT : public CmQueue
7272
{
7373
public:
74-
static int32_t Create(CmDevice_RT *device, CmQueue_RT *&queue);
75-
static int32_t Create(CmDevice_RT *device, CmQueue_RT *&queue, CM_QUEUE_CREATE_OPTION queueCreateOption);
74+
static int32_t Create(CmDevice_RT *device,
75+
CmQueue_RT* &queue,
76+
CM_QUEUE_CREATE_OPTION queueCreateOption);
7677
static int32_t Destroy(CmQueue_RT *&queue);
7778

7879
CM_RT_API int32_t Enqueue(CmTask *task,

media_driver/agnostic/common/cm/cm_device_rt.cpp

+22-34
Original file line numberDiff line numberDiff line change
@@ -1731,15 +1731,13 @@ CM_RT_API int32_t CmDeviceRT::DestroyKernel(CmKernel*& kernel)
17311731
return CM_SUCCESS;
17321732
}
17331733

1734-
CM_RT_API int32_t CmDeviceRT::CreateQueue(CmQueue* & queue)
1734+
CM_RT_API int32_t CmDeviceRT::CreateQueue(CmQueue* &queue)
17351735
{
17361736
INSERT_API_CALL_LOG();
17371737

1738-
CmQueue *tmpQueue = nullptr;
1739-
1740-
// For legacy CreateQueue API, we will only return the same queue
1738+
CM_QUEUE_CREATE_OPTION queueCreateOption = CM_DEFAULT_QUEUE_CREATE_OPTION;
17411739
m_criticalSectionQueue.Acquire();
1742-
for (auto iter = m_queue.begin(); iter != m_queue.end(); iter++)
1740+
for (auto iter = m_queue.begin(); iter != m_queue.end(); ++iter)
17431741
{
17441742
CM_QUEUE_TYPE queueType = (*iter)->GetQueueOption().QueueType;
17451743
if (queueType == CM_QUEUE_TYPE_RENDER)
@@ -1751,8 +1749,6 @@ CM_RT_API int32_t CmDeviceRT::CreateQueue(CmQueue* & queue)
17511749
}
17521750
m_criticalSectionQueue.Release();
17531751

1754-
CM_QUEUE_CREATE_OPTION queueCreateOption = {};
1755-
17561752
// Check queue type redirect is needed.
17571753
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
17581754
CM_CHK_NULL_RETURN_CMERROR(cmData);
@@ -1770,51 +1766,44 @@ CM_RT_API int32_t CmDeviceRT::CreateQueue(CmQueue* & queue)
17701766
#if (_DEBUG || _RELEASE_INTERNAL)
17711767
// Check queue type override for debugging is needed.
17721768
MOS_USER_FEATURE_VALUE_DATA UserFeatureData = {0};
1773-
if( MOS_UserFeature_ReadValue_ID( nullptr,
1769+
if (MOS_UserFeature_ReadValue_ID(
1770+
nullptr,
17741771
__MEDIA_USER_FEATURE_VALUE_MDF_DEFAULT_CM_QUEUE_TYPE_ID,
17751772
&UserFeatureData) == MOS_STATUS_SUCCESS )
17761773
{
17771774
if (UserFeatureData.u32Data == CM_QUEUE_TYPE_RENDER
1778-
|| UserFeatureData.u32Data == CM_QUEUE_TYPE_COMPUTE)
1775+
|| UserFeatureData.u32Data == CM_QUEUE_TYPE_COMPUTE)
17791776
{
1780-
queueCreateOption.QueueType = (CM_QUEUE_TYPE)UserFeatureData.u32Data;
1777+
queueCreateOption.QueueType
1778+
= (CM_QUEUE_TYPE)UserFeatureData.u32Data;
17811779
}
17821780
}
17831781
#endif
17841782

1785-
int32_t result = CreateQueueEx(tmpQueue, queueCreateOption);
1786-
1787-
if (result != CM_SUCCESS)
1788-
{
1789-
CM_ASSERTMESSAGE("Failed to create the queue.");
1790-
return result;
1791-
}
1792-
1793-
queue = tmpQueue;
1794-
return CM_SUCCESS;
1783+
return CreateQueueEx(queue, queueCreateOption);
17951784
}
17961785

17971786
CM_RT_API int32_t
1798-
CmDeviceRT::CreateQueueEx(CmQueue* & queue,
1787+
CmDeviceRT::CreateQueueEx(CmQueue* &queue,
17991788
CM_QUEUE_CREATE_OPTION queueCreateOption)
18001789
{
18011790
INSERT_API_CALL_LOG();
1802-
18031791
m_criticalSectionQueue.Acquire();
1804-
CmQueueRT *queueRT = nullptr;
18051792

1806-
for (auto iter = m_queue.begin(); iter != m_queue.end(); iter++)
1793+
CmQueueRT *queueRT = nullptr;
1794+
if (CM_QUEUE_TYPE_RENDER == queueCreateOption.QueueType)
18071795
{
1808-
CM_QUEUE_TYPE queueType = (*iter)->GetQueueOption().QueueType;
1809-
unsigned int gpuContext = (*iter)->GetQueueOption().GPUContext;
1810-
1811-
if (queueType == CM_QUEUE_TYPE_RENDER
1812-
&& queueType == queueCreateOption.QueueType
1813-
&& gpuContext == queueCreateOption.GPUContext)
1796+
for (auto iter = m_queue.begin(); iter != m_queue.end(); ++iter)
18141797
{
1815-
queue = (*iter);
1816-
m_criticalSectionQueue.Release();
1817-
return CM_SUCCESS;
1798+
CM_QUEUE_TYPE queueType = (*iter)->GetQueueOption().QueueType;
1799+
unsigned int gpuContext = (*iter)->GetQueueOption().GPUContext;
1800+
if (queueType == CM_QUEUE_TYPE_RENDER
1801+
&& gpuContext == queueCreateOption.GPUContext)
1802+
{
1803+
queue = (*iter);
1804+
m_criticalSectionQueue.Release();
1805+
return CM_SUCCESS;
1806+
}
18181807
}
18191808
}
18201809

@@ -1825,7 +1814,6 @@ CmDeviceRT::CreateQueueEx(CmQueue* & queue,
18251814
m_criticalSectionQueue.Release();
18261815
return result;
18271816
}
1828-
18291817
m_queue.push_back(queueRT);
18301818
queue = queueRT;
18311819
m_criticalSectionQueue.Release();

0 commit comments

Comments
 (0)