Can I run sequentially (only 1 thread) functions implemented with TBB like cv::warpPerspective() ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can I run sequentially (only 1 thread) functions implemented with TBB like cv::warpPerspective() ?

opencv-users mailing list
   Hello.
     Can I make the following functions run sequentially :
      - cv::warpPerspective() - see
http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#warpperspective
      - cv::VideoCapture::set() - see
http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set 
.

     I ask because they will STILL run multicore, even if we give before:
         cv::setNumThreads(1)
      since they are implemented with TBB.

     The documentation I found so far is
http://docs.opencv.org/modules/core/doc/utility_and_system_functions_and_macros.html#setnumthreads
     <<Concurrency – If threads == 1, OpenCV will disable threading optimizations and run
it’s functions sequentially.>>
     However, at the same place it is also written:
       <<TBB – User-defined parallel constructions will run with the same
threads number, if another does not specified. If late on user creates own scheduler,
OpenCV will be use it.
       OpenMP – No special defined behaviour.>>

     I found also http://code.opencv.org/issues/2064 where it is written: <<unfortunately,
right now OpenCV uses TBB and (until recently?) this library does not allow to explicitly
specify the number of threads to use. Therefore, setNumThreads() right now has no any
effect. Let's try to do something with it by the next update>> .

     So I guess the solution is to make TBB use only 1 thread - something like in the
examples at
https://www.threadingbuildingblocks.org/docs/help/reference/appendices/community_preview_features/tbb_global_control.htm 
(or https://software.intel.com/en-us/forums/intel-threading-building-blocks/topic/289355 ) .

   Best regards,
     Alex
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can I run sequentially (only 1 thread) functions implemented with TBB like cv::warpPerspective() ?

opencv-users mailing list
   Hi.
     I managed to run on only 1 core all OpenCV functions.
     Since I didn't get an answer, I'm writing down the main steps I followed - I use
Linux cpuset (and the cset tool).

     Below I give some examples on how I ran on a specific cpuset I created on Linux
kernel 3.13:

# From http://stackoverflow.com/questions/9072060/one-core-exclusively-for-my-process
# See also http://man7.org/linux/man-pages/man7/cpuset.7.html

mkdir cpuset
mount -t cpuset none cpuset/
cd cpuset

mkdir sys # create sub-cpuset for system processes
/bin/echo 0-2 > sys/cpus # assign cpus (cores) 0-2 to this set
# adjust if you have more/less cores
/bin/echo 1 > sys/cpu_exclusive
/bin/echo 0 > sys/mems

mkdir rt # create sub-cpuset for my process
/bin/echo 3 > rt/cpus # assign cpu (core) 3 to this cpuset
# adjust this to number of cores-1
/bin/echo 1 > rt/cpu_exclusive
/bin/echo 0 > rt/mems
/bin/echo 0 > rt/sched_load_balance
/bin/echo 1 > rt/mem_hardwall

# move all processes from the default cpuset to the sys-cpuset
#for T in `cat tasks`; do echo "Moving " $T; /bin/echo $T > sys/tasks; done


"""
If you want to revert these changes, just restart your system or do:

# move tasks back from sys-cpuset to root cpuset
for T in `cat /cpuset/sys/tasks`; do echo "Moving " $T; /bin/echo $T > /cpuset/tasks; done
# remove sys-cpuset
rmdir /cpuset/sys
# move tasks back from rt-cpuset to root cpuset
for T in `cat /cpuset/rt/tasks`; do echo "Moving " $T; /bin/echo $T > /cpuset/tasks; done
# remove rt-cpuset
rmdir /cpuset/rt
# unmount and remove /cpuset
umount /cpuset
rmdir /cpuset
"""

# unmount and remove /cpuset
#umount cpuset
#rmdir cpuset





# Now, in order to run a certain Linux taks on a specific cpuset, we should use the tool cset:

# From https://rt.wiki.kernel.org/index.php/Cpuset_Management_Utilty/proc_writeup
#sudo apt-get install cpuset
#cset proc --list --set rt
cset proc --set=rt --exec ./myExecutable # It works if I do NOT pass args to the prg

# IMPORTANT: in order to execute on a specific cpuset my program with a set of arguments I
start first bash and then run my program as in any other terminal.
# Inspired from
https://rt.wiki.kernel.org/index.php/Cpuset_Management_Utility/tutorial#Execing_Tasks_with_Proc
sudo cset proc --set=rt --exec bash
[sudo] password for user:
cset: --> last message, executed args into cpuset "/rt", new pid is: 32562

perf stat ./myExecutable arg1 arg2 ...


# Other examples:
cset proc --list --set rt
     cset: "rt" cpuset of CPUSPEC(3) with 1 task running
     USER PID PPID SPPr TASK NAME
     -------- ----- ----- ---- ---------
     user 18209 16593 Soth kile bla.tex

sudo cset proc --move 18209 sys
     cset: moving following pidspec: 18209
     cset: moving 1 userspace tasks to /sys
     cset: done
cset proc --list --set rt
     cset: "rt" cpuset of CPUSPEC(3) with 0 tasks running





   Best regards,
     Alex



On 3/4/2016 11:28 PM, RCU wrote:

>    Hello.
>      Can I make the following functions run sequentially :
>       - cv::warpPerspective() - see
> http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#warpperspective
>       - cv::VideoCapture::set() - see
> http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set
> .
>
>      I ask because they will STILL run multicore, even if we give before:
>          cv::setNumThreads(1)
>       since they are implemented with TBB.
>
>      The documentation I found so far is
> http://docs.opencv.org/modules/core/doc/utility_and_system_functions_and_macros.html#setnumthreads
>
>      <<Concurrency – If threads == 1, OpenCV will disable threading optimizations and run
> it’s functions sequentially.>>
>      However, at the same place it is also written:
>        <<TBB – User-defined parallel constructions will run with the same
> threads number, if another does not specified. If late on user creates own scheduler,
> OpenCV will be use it.
>        OpenMP – No special defined behaviour.>>
>
>      I found also http://code.opencv.org/issues/2064 where it is written: <<unfortunately,
> right now OpenCV uses TBB and (until recently?) this library does not allow to explicitly
> specify the number of threads to use. Therefore, setNumThreads() right now has no any
> effect. Let's try to do something with it by the next update>> .
>
>      So I guess the solution is to make TBB use only 1 thread - something like in the
> examples at
> https://www.threadingbuildingblocks.org/docs/help/reference/appendices/community_preview_features/tbb_global_control.htm
> (or https://software.intel.com/en-us/forums/intel-threading-building-blocks/topic/289355 ) .
>
>    Best regards,
>      Alex
Loading...