|
|
|
|
@ -20,7 +20,7 @@ AIModel_Impl::AIModel_Impl()
|
|
|
|
|
m_pNode_output_1 = NULL;
|
|
|
|
|
m_pNode_output_2 = NULL;
|
|
|
|
|
m_DetGPUStream.clear();
|
|
|
|
|
m_nLast_GPUStreamIdx = 0;
|
|
|
|
|
m_nLast_GPUStreamIdx.store(0);
|
|
|
|
|
m_nALLStreamNum = 0;
|
|
|
|
|
}
|
|
|
|
|
AIModel_Impl::~AIModel_Impl()
|
|
|
|
|
@ -492,7 +492,11 @@ int AIModel_Impl::AI_Det_In_1_Out_1(Node_Config *pConfig_in, Node_Config *pConfi
|
|
|
|
|
{
|
|
|
|
|
// printf("=== s1 ");
|
|
|
|
|
std::shared_ptr<Det_GPU_Stram> pdetStream;
|
|
|
|
|
GetStream(pdetStream);
|
|
|
|
|
if (GetStream(pdetStream) != 0 || !pdetStream)
|
|
|
|
|
{
|
|
|
|
|
printf("AI_Det_In_1_Out_1: GetStream error \n");
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
// printf("=== s2 ");
|
|
|
|
|
std::lock_guard<std::mutex> lock(pdetStream->AI_mutex);
|
|
|
|
|
// printf(" ss g %d s %d -- ", pdetStream->nGPUIdx, pdetStream->cuda_stream->nstreamIdx);
|
|
|
|
|
@ -521,22 +525,40 @@ int AIModel_Impl::AI_Det_In_1_Out_1(Node_Config *pConfig_in, Node_Config *pConfi
|
|
|
|
|
|
|
|
|
|
int AIModel_Impl::GetStream(std::shared_ptr<Det_GPU_Stram> &pdetStream)
|
|
|
|
|
{
|
|
|
|
|
int sidx = m_nLast_GPUStreamIdx;
|
|
|
|
|
if (m_nALLStreamNum <= 0 || m_DetGPUStream.empty())
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sidx++;
|
|
|
|
|
if (sidx >= m_nALLStreamNum)
|
|
|
|
|
// 多线程并发时原子轮询分配 stream:
|
|
|
|
|
int sidx = m_nLast_GPUStreamIdx.load();
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
sidx = 0;
|
|
|
|
|
int next = sidx + 1;
|
|
|
|
|
if (next >= m_nALLStreamNum)
|
|
|
|
|
{
|
|
|
|
|
next = 0;
|
|
|
|
|
}
|
|
|
|
|
if (m_nLast_GPUStreamIdx.compare_exchange_weak(sidx, next))
|
|
|
|
|
{
|
|
|
|
|
sidx = next;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// CAS 失败时 sidx 已被更新为当前实际值,重新计算 next
|
|
|
|
|
}
|
|
|
|
|
pdetStream = m_DetGPUStream.at(sidx);
|
|
|
|
|
m_nLast_GPUStreamIdx = sidx;
|
|
|
|
|
|
|
|
|
|
pdetStream = m_DetGPUStream.at(sidx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int AIModel_Impl::AI_Det_In_1_Out_1_class(unsigned char *p_indata_0, float *fmaxScore)
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<Det_GPU_Stram> pdetStream;
|
|
|
|
|
GetStream(pdetStream);
|
|
|
|
|
if (GetStream(pdetStream) != 0 || !pdetStream)
|
|
|
|
|
{
|
|
|
|
|
printf("AI_Det_In_1_Out_1_class: GetStream error \n");
|
|
|
|
|
*fmaxScore = 0.0f;
|
|
|
|
|
return -3;
|
|
|
|
|
}
|
|
|
|
|
// printf("=== s2 ");
|
|
|
|
|
std::lock_guard<std::mutex> lock(pdetStream->AI_mutex);
|
|
|
|
|
// printf(" ss g %d s %d -- ", pdetStream->nGPUIdx, pdetStream->cuda_stream->nstreamIdx);
|
|
|
|
|
|