Here is my test code:
void Process()
{
GpuMat GpuRGBSrc;
Mat CpuRGBSrc;
Src.copyTo(CpuRGBSrc);
GpuRGBSrc.upload(CpuRGBSrc);
int MatchMethod = TM_SQDIFF;
PtrTemplateMatcher = createTemplateMatching(GpuRGBSrc.type(), MatchMethod);
GpuMat MatchResult;
double MinVal, MaxVal, MatchVal;
Point MinLocal, MaxLocal, MatchLocal;
GpuMat TG;
TG.upload(T1);
TickMeter t;
TemplateMatcher->match(GpuRGBSrc, TG, MatchResult);
}
void* Thread1(void* arg)
{
while (1)
{
TickMeter t;
t.start();
Process();
t.stop();
cout << “Thread1 Time:”<<t.getAvgTimeMilli() << endl;
}
return 0;
}
void* Thread2(void* arg)
{
while (1)
{
TickMeter t;
t.start();
Process();
t.stop();
cout << “Thread2 Time:”<< t.getAvgTimeMilli() << endl;
}
return 0;
}
void* Thread3(void* arg)
{
while (1)
{
TickMeter t;
t.start();
Process();
t.stop();
cout << “Thread3 Time:” <<t.getAvgTimeMilli() << endl;
}
return 0;
}
void* Thread4(void* arg)
{
while (1)
{
TickMeter t;
t.start();
Process();
t.stop();
cout << “Thread4 Time:”<<t.getAvgTimeMilli() << endl;
}
return 0;
}
int main()
{
pthread_t ListenHandle1,ListenHandle2,ListenHandle3,ListenHandle4,ListenHandle5,ListenHandle6;
T1 = imread(“/media/hjy/SSD/CigPrint/MB1.bmp”);
T2 = imread(“/media/hjy/SSD/CigPrint/MB2.bmp”);
Src = imread(“/media/hjy/SSD/CigPrint/src.bmp”);
pthread_create(&ListenHandle1,NULL,Thread1,NULL);
// pthread_create(&ListenHandle2,NULL,Thread2,NULL);
// pthread_create(&ListenHandle3,NULL,Thread3,NULL);
// pthread_create(&ListenHandle4,NULL,Thread4,NULL);
while(1);
}
if only create one thread ,Thread1 time:23ms, GPU usage is 20%-40%.
if create two threads,Thread1 and Thread2 time both are 47ms,GPU usage is 20%-40%,which isn’t increased.
the more thread is created,the process time is increase,but GPU usage isn’t increased.I have tested that the thread is parallel in CPU,but the more thread is created,the process time of one thread is increase,it seems that it is not concurrency in GPU.
The same code i have tested in my Windoes computer,but result is different.The more thread is created,the process time is same,and GPU usage is increased.So why Opencv with cuda in Multi-threads doesn’t work on jetson?Is there any tips to solve the problem.