I would like to encode to H.264 from multiple streams, each with its own instance of UMC encoder. I could do this in Version 5.3 without any issue.
However in Version 6.1, when I encode one stream the CPU approximately takes 10% of the CPU. When I encode two streams (each with its own instance of UMC encoder), the CPU is 99%.
How do I encode multiple streams each with its own instance of UMC encoder? Thank you.
"However in Version 6.1, when I encode one stream the CPU approximately takes 10% of the CPU. When I encode two streams (each with its own instance of UMC encoder), the CPU is 99%."
since 10% CPU is enough for the one stream, I suppose you do not need to use internal OpenMP threading in UMC encoder. Is it true?
This is possibly a problem related to the application level. How are the two encoders are the application? Is there waiting()/sleep() API or other threading synchronization API used.
Yes, we do not need to use internal OpenMP and I set KMP_BLOCKTIME=0.
Thereare frames streaming from the camera all the time, and each camera stream is threaded. Since it is live there is no need to wait/sleep. Hence we do not use these blocking calls.
Out of curiousity, Why do you think more than one streamwill be causing 99% CPU? The same source code is used for Version 5.3 and there was not any issue.
Do I have to set KMP_BLOCKTIME=0 for every instance of the encoder?
Do you have a sample application which instantiates more than one encoder? If so, probably we can eliminate the application level issue.
Please advise. Thank you.
To disable the OMP threaded in the Codec, you can check at the \audio-video-codecs\Makefile file, and remove the following:
CFLAGS += -openmp
CFLAGS += -fopenmp
Setting KMP_BLOCKTIME is not to disable the OpenMP threading, that is because some known problem discussed here:
Also you need to link with non threaded static libraries.
If you disable the OpenMP threading, it does not need to set the KMP_BLOCKTIME environment.
It is not clear that how each thread is calling the H.264 encoder, For each threading, are they just calling Getframe() function, no blocking or waiting at somewhere? If this is true, it looks each is trying to do encoding all the time, surely it will consume all of the CPU.
Thanks for your suggestion.
In fact, we use OpenMP support in our application and thus OpenMP is enabled on UMC as well, since UMC source files are part of our project. I believe since both of them use OpenMP, it may be creating "nested threads".
Therefore, I have created a seperate library for UMC source files without OpenMP support and linked those libraries with our application. That did resolve high CPU usage.
> Also you need to link with non threaded static libraries.
Currently, I am using dynamic (stublib) IPPlibraries. When I tried with static, I could not instantiate more than 4 streams, probably because I have quad core systems(???). But with dynamic libraries I am fine so far. Any particular reason you had wanted to link static libraries?
For the question, "But with dynamic libraries I am fine so far. Any particular reason you had wanted to link static libraries?"
Many functions in the dynamic libraries are internally threaded with OpenMP functions; you can check the threaded function list at: \docThreadedFunctionsList.txt. To use the static non-threaded library will help to avoid the enable the internal threaded with your application. ( It looks that you have implemented the high level thread at your application).
Thanks. As I indicated earlier, most likely the problem was with the nested threads. Currently, I am building the UMC libraries without OpenMP support and linking those libraries with my application which has OpenMP support.
I ran our application with 48 instances of UMC encoder in an i7 system (encoding 340 2CIF frames per second in total) and utilizing less than 50% usage. The performance is, in fact very good and better than expected.
BTW, I am still using dynamic IPPlibraries and that is the only way I could do it.
Thanks for your assistance.
Note: Ifanyone needs help regarding this issue, please do not hesitate to contact me. Thank you.
Thanks for sharing the experience here.
For those who also want to using dynamic IPP libraries in case, it can call ippSetNumThreads() in the application to disable the internal threading in the IPP function.