Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multithreading processing chain #66

Closed
5 of 9 tasks
pozitronik opened this issue Aug 26, 2023 · 2 comments
Closed
5 of 9 tasks

Multithreading processing chain #66

pozitronik opened this issue Aug 26, 2023 · 2 comments
Assignees
Labels
dev 🧑‍💻Developer issues (todos, experiments, styling, etc)
Milestone

Comments

@pozitronik
Copy link
Owner

pozitronik commented Aug 26, 2023

In the current processing logic all frame processors runs in turns, one after one. The advantages of this logic are obvious: it is simple, there is a possibility to stop and resume processing at any time, e.t.c.
But there are disadvantages too, and they seems to be critical at this moment. There is no possibility to implement any realtime preview with this logic, and there is no place for speed enhancements, because we can't parallelize processing task.
So, there is a big (really big) task to implement multithreading there.

There will be named buffers, each buffer named to a linked processor. Each processor processing will start in the separate thread, it will read a frame from the input buffer, process it, and write to the output buffer (which is input buffer for the next processor).

There are subtasks for this task:

  • Implement the buffered processing chain.
  • Make *FrameBuffer classes for the different buffers types (memory, file, e.t.c).
  • Implement threads manager. Some processors may work faster than others, so their buffers will fill quickly. So it make a sense to pause those processors threads to redistribute computing powers to the other threads.
  • Implement states in this approach. Saving and loading buffers as a files can be useful: this logic partially coincides with the current state logic.
  • Different modules settings via config file #68
  • Implement a memory control code. It is important, because several loaded models may require a lot of memory, and frame buffers are too.
  • Allow to control each processor sub-threads count (ThreadPoolExecutor workers). #70
  • Show the general progress bar and the every processor progress bar and statistics (memory usage, buffers occupancy, e.t.c).
  • Properly handle in-threads exceptions.
@pozitronik pozitronik added the dev 🧑‍💻Developer issues (todos, experiments, styling, etc) label Aug 26, 2023
@pozitronik pozitronik self-assigned this Aug 26, 2023
@pozitronik pozitronik added this to the R02 milestone Aug 26, 2023
@pozitronik pozitronik mentioned this issue Aug 26, 2023
20 tasks
@pozitronik pozitronik pinned this issue Aug 26, 2023
pozitronik added a commit that referenced this issue Aug 26, 2023
The basic working prototype of multithreading processing
pozitronik added a commit that referenced this issue Aug 26, 2023
Remove prototype
pozitronik added a commit that referenced this issue Aug 27, 2023
Compact code
pozitronik added a commit that referenced this issue Aug 27, 2023
Use treads count from parameters
pozitronik added a commit that referenced this issue Aug 27, 2023
Experimental progress bars
pozitronik added a commit that referenced this issue Sep 1, 2023
unused imports
pozitronik added a commit that referenced this issue Sep 1, 2023
FrameBuffer stub
pozitronik added a commit that referenced this issue Sep 1, 2023
Basic memory frame buffer
pozitronik added a commit that referenced this issue Sep 1, 2023
Basic FrameBufferManager
pozitronik added a commit that referenced this issue Sep 1, 2023
implementing buffers handlers
pozitronik added a commit that referenced this issue Sep 1, 2023
fixed decorators order
pozitronik added a commit that referenced this issue Sep 1, 2023
fixed typos
pozitronik added a commit that referenced this issue Sep 1, 2023
fixes on implementation
pozitronik added a commit that referenced this issue Sep 1, 2023
Fixed: a type passed instead of variable
Removed simple done callback
threading lock added
pozitronik added a commit that referenced this issue Sep 1, 2023
Implement _name for FrameBuffers (for debugging purposes)
pozitronik added a commit that referenced this issue Sep 1, 2023
New methods for proper buffers handling
pozitronik added a commit that referenced this issue Sep 1, 2023
More compact init logic
pozitronik added a commit that referenced this issue Sep 1, 2023
Add init call to avoid class variable sharing
pozitronik added a commit that referenced this issue Sep 1, 2023
Changed call logic to make it similar everywhere
Handle buffers via manager, not by buffers themselves
pozitronik added a commit that referenced this issue Sep 1, 2023
Linear debug code
@pozitronik
Copy link
Owner Author

Intermediate tests on 497 frames 1920x1080 video with the same processing chain (in-memory extracting -> FaceSwapper->FaceEnhancer):
Parallel execution (cpu+cuda execution providers, 2 threads):14% in 12 min -> approximately an hour.
Parallel execution (FaceSwapper uses 16 CPU threads, FaceEnhancer uses 2 CUDA threads): ~724s
Parallel execution (FaceSwapper uses 16 CPU threads, FaceEnhancer uses 2 CUDA threads, frame extractor buffer lock on 10 frames): ~700s (with 1 second thread waiting), ~717s (0.5).
All other parallel tries are even worse.

Current master (cpu+cuda execution providers): ~580s (18% faster of best parallel result).

It is worth to try to play some thread-control logic. it seems, that in some cases parallel execution can speed up the whole processing, and slow it down in other.
Other conclusion: swapper and enhancer can't properly work simultaneously, if they share some hardware (it was predictable, but still worth to try). They can work in parallel with different hardware providers (e.g cpu/gpu), but even in that case the whole process will be slower.
Note: currently i can try my tests only on my laptop, which may redistribute power to cpu/gpu to preserve consumption/heat limits, which can also affect the tests.

pozitronik added a commit that referenced this issue Sep 3, 2023
Execution time measure code
pozitronik added a commit that referenced this issue Sep 3, 2023
Remove locks, more progress indication, logic fixes
@pozitronik
Copy link
Owner Author

Due to unsatisfactory experiments result and changes in the common processing logic the task is closed.

@pozitronik pozitronik unpinned this issue Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev 🧑‍💻Developer issues (todos, experiments, styling, etc)
Projects
None yet
Development

No branches or pull requests

1 participant