Page MenuHome

Bump maximum threads number to 1024
ClosedPublic

Authored by Sergey Sharybin (sergey) on Jun 8 2015, 9:15 AM.

Details

Summary

This commit contains all the changes required for most optimal maximum threads
number bump. This is needed to avoid possibly unneeded initialization or data
allocation on systems with lower threads count.

TODO: Still need to review arrays in render data structures from render_types.h,

P.S. We might remove actual bump of max threads from this patch, so when we'll
be applying the patch we can do all the preparation work and then do actual
bump of max threads.

Diff Detail

Repository
rB Blender
Branch
max_threads_bump

Event Timeline

Sergey Sharybin (sergey) retitled this revision from to Bump maximum threads number to 1024.
Sergey Sharybin (sergey) updated this object.
Sergey Sharybin (sergey) planned changes to this revision.Jun 8 2015, 1:54 PM

I screwed up and cases when scene->r.threads is set to higher than the system threads are not handled correct.

Just update against latest master.

Can't remember what was the issue i was having, nor can reproduce any.

Thing is, BLI_system_thread_count is always clamped to an actual limit
of threads and it's not possible to set user threads higher than that
value as well.

Sergey Sharybin (sergey) planned changes to this revision.Jul 13 2016, 4:35 PM

Ahhh, oki. It's all fine when you use -t 1024 but fails when one sets 1024 threads in the interface. Oki-doki, hacking time!

Fixed the bug i've been experiencing.

Was playing more but couldn't find anything bad, so recon
the patch fully testable/reviewable.

Besides point noted in comment, lgtm.

source/blender/blenlib/intern/rand.c
297–301

Not sure about that change… Unless I’m mistaken:

  • rngarr is allocated based on BLENDER_MAX_THREADS anyway, so we are only skipping some initialization here.
  • There is no guarantee we won't have more threads running at some point than number reported by BLI_system_thread_count(), which would make some random generators use uninitialized memory.
source/blender/blenlib/intern/rand.c
297–301

The idea is not only save memory, but save calculations.

Can you elaborate a bit more why we'll have more threads running than BLI_system_thread_count() in Blender side?

source/blender/blenlib/intern/rand.c
297–301

It’s actually pretty simple - Add a Noise texture to your default cube, and render with custom number of threads higher than BLI_system_thread_count() returned value, and BLI_rng_thread_rand() will be called with higher values of threadid than reported system count…

Anyway, I really doubt initializing 1k random numbers is anything like a serious load of calculation. ;)

Sergey Sharybin (sergey) planned changes to this revision.Jul 13 2016, 9:35 PM
Sergey Sharybin (sergey) added inline comments.
source/blender/blenlib/intern/rand.c
297–301

Argh, was yet again confused by num_threads_override.

Note for myself: num_threads_override is ONLY set when using command line argument.

Also now i see this function is only called once from creator.c, where we cant' know anything about amount of threads renderer will use later.

Will change this function to always use BLENDER_MAX_THREADS tomorrow.

This revision is now accepted and ready to land.Jul 14 2016, 4:05 PM
Campbell Barton (campbellbarton) edited edge metadata.

LGTM, after applying there are a few cases where we use BLENDER_MAX_THREADS for stack memory that could be replaced with allocated memory, but not urgent.

This revision was automatically updated to reflect the committed changes.