BLI: speedup memory bandwidth bound tasks by reducing threading #118939
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118939
Loading…
Reference in New Issue
No description provided.
Delete Branch "JacquesLucke/blender:limit-threading-for-bandwidth-bound-tasks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This improves performance by reducing the amounts of threads used for tasks which require a high memory bandwidth.
This works because the underlying hardware has a certain maximum memory bandwidth. If that is used up by a few threads already, any additional threads wanting to use a lot of memory will just cause more contention which actually slows things down. By reducing the number of threads that can perform certain tasks, the remaining threads are also not locked up doing work that they can't do efficiently. It's best if there is enough scheduled work so that these tasks can do more compute intensive tasks instead.
To use this new functionality, one has to put the parallel code in question into a
threading::memory_bandwidth_bound_task(...)
block. Additionally, one also has to provide a (very) rough approximation for how many bytes are accessed. If the number is low, the number of threads shouldn't be reduced because it's likely that all touched memory can be in L3 cache which generally has a much higher bandwidth than main memory.The exact number of threads that are allowed to do bandwidth bound tasks at the same time is generally highly context and hardware dependent. It's also not really possible to measure reliably because it depends on so many static and dynamic factors. The thread count is now hardcoded to 8. It seems that this many threads are easily capable of maxing out the bandwidth capacity.
With this technique I can measure surprisingly good performance improvements:
In all of these cases, only 8 instead of 24 threads are used. The remaining threads are idle in these cases, but they could do other work if available.
Running the following code can give a rough idea for how many threads are necessary maxing out the memory bandwidth and when performance starts to degrade again.
These are my results. Note how it first gets faster the more threads there are, but then gets slower again.
Using a profiler also show that there is an issue. As long as there are only few threads, the CPU cores are utilized well, but as the number of threads increases, one gets gaps in the profile. It looks like the CPU is doing some kind of time sharing of the memory bus.
@blender-bot build
WIP: BLI: support reduced multi-threading for memory bandwidth bound tasksto BLI: speedup memory bandwidth bound tasks by reducing threading@blender-bot build
It does make sense to limit threading for such operations. The overall code looks fine, but there are some non-code related notes/questions type of a things.
The number of active threads sounds quite arbitrary, as you've mentioned. However, it is above of the minimum required 4 cores (don't think we require HT). Not sure if TBB will limit the number workers for the arena in this case. Would be good if we don't introduce extra overhead to a lower end hardware.
And another, possibly related thing, is doing
blender -t 1
work as expected here, or does it force some parts of algorithm to be threaded?It didn't but with the code I just added it's more obvious.
@JacquesLucke I think the change you did covers both cases of
-t 1
and possible CPUs with less than 8 cores?Yes right. There is no extra overhead when Blender uses just 8 a fewer threads now (except for the function call overhead which is negligible here).
Lovely! I think we can go ahead with this change.
It is kind of interesting of what would the best constants be for multi-socket configurations, but is not something that prevents us from landing the current state of the PR.
True, not something I can test unfortunately.