Added support for TBB 2021#1027
Conversation
For details see:
AcademySoftwareFoundation#1027
|
@Idclip I've noticed that in In H19, I've added a However, then I realized that this is insufficient because of |
|
hey @e4lam! I don't remember running into this, but it may very well be that I didn't properly try to build all the unit tests. As this isn't instantiated anywhere in the core lib/bins I probably didn't see it. You're saying that |
|
@Idclip Starting with oneTBB 2021, |
|
@e4lam I did not get that far, thanks for confirming. Up till this point it seemed everything had a replacement which overlapped the versions we support. As you say, we'll need a wrapper in the VDB headers for this which could subsequently be used in the houdini plugin. |
|
For reference, I've looked into this and it looks like Annoyingly, the macro is provided by different headers though. |
I'm going to assume that at least something consistent in TBB 2020/2021 propagates this define? i.e. maybe we include |
|
Oh interesting, yeah including |
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
|
I think I'm almost at a point to make this PR official. @e4lam I've added the wrapper logic to a new header |
|
I like this new threading header a lot, that's a good idea. One question is about whether we could potentially introduce a new namespace for all threading-related functionality? |
e4lam
left a comment
There was a problem hiding this comment.
Thank you for all the work on this!
I have no problem with this, but yeah it should probably live in a new appropriately named folder. Slightly odd to have such small logic introduce a new folder but, as you say, the new infrastructure will set a precedent to allow us to extending any more threading logic. |
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
|
I've added a basic test with an additional Mac build which builds the lib, binaries and unit tests. This really warrants something like a new @danrbailey I've moved |
| -DOPENVDB_CXX_STRICT=OFF -DUSE_BLOSC=OFF -DUSE_ZLIB=OFF | ||
| - name: test | ||
| shell: bash | ||
| run: cd build && ctest -V |
There was a problem hiding this comment.
New, very basic CI for TBB2021 in lieu of the intel docker images
| // compile time branching (as we still support 2018), we use it in 2018 too by | ||
| // enabling the below define. | ||
| #define TBB_PREVIEW_GLOBAL_CONTROL 1 | ||
| #include <tbb/global_control.h> |
There was a problem hiding this comment.
Significant change
The VDB Render binary now uses tbb::global_control over tbb::task_scheduler_init
|
|
||
| // get the global task arena | ||
| tbb::task_arena arena(tbb::task_arena::attach{}); | ||
| arena.enqueue([task = std::move(task)] { task.execute(); }); |
There was a problem hiding this comment.
Significant change
Instead of queueing tasks through task::enqueue, add them to the global task arena.
@jmlait I think this is correct? i.e. tbb::task_arena arena(tbb::task_arena::attach{}); gets a hooks to the "default" arena so I don't need to keep the arena in scope? This could be improved by having an arena per Queue, but I'm trying to keep the changes as minimal as possible.
There was a problem hiding this comment.
The change is faithful to what the code previously did. Offhand, I don't see an advantage to using an arena per queue?
There was a problem hiding this comment.
Thanks for confirming @e4lam. I'm trying to figure out what the better API would be, us wrapping the logic or delegating it to the caller. i.e:
Queue q;
q.concurrency(/*max threads*/1); // where each queue has its own configurable arena
q.write(...);
vs
// set arena for current scope
{
tbb::task_arena arena(/*1*/);
Queue q;
q.write(...)
}
It's the same debate as the bool threaded = true argument that appears everywhere. In any case, not relevant for this PR.
|
|
||
| namespace tbb { class split; } // forward declaration | ||
|
|
||
| #include <tbb/blocked_range.h> // for tbb::split |
There was a problem hiding this comment.
Significant change
I couldn't find a nice way to fix the forward declaration between versions.
| { | ||
| const auto grainSize = std::max<size_t>( | ||
| length / tbb::task_scheduler_init::default_num_threads(), 1024); | ||
| length / tbb::this_task_arena::max_concurrency(), 1024); |
There was a problem hiding this comment.
Significant change
This should now be affected by the caller configuring their own arena
|
|
||
| // @note this grain size is used for optimal threading | ||
| const size_t numThreads = size_t(tbb::task_scheduler_init::default_num_threads()); | ||
| const size_t numThreads = size_t(tbb::this_task_arena::max_concurrency()); |
There was a problem hiding this comment.
Significant change
This should now be affected by the caller configuring their own arena
| using IndexPairListMapPtr = std::shared_ptr<IndexPairListMap>; | ||
|
|
||
| size_t numTasks = 1, numThreads = size_t(tbb::task_scheduler_init::default_num_threads()); | ||
| size_t numTasks = 1, numThreads = size_t(tbb::this_task_arena::max_concurrency()); |
There was a problem hiding this comment.
Significant change
This should now be affected by the caller configuring their own arena
| { | ||
| const auto grainSize = std::max<size_t>( | ||
| length / tbb::task_scheduler_init::default_num_threads(), 1024); | ||
| length / tbb::this_task_arena::max_concurrency(), 1024); |
There was a problem hiding this comment.
Significant change
This should now be affected by the caller configuring their own arena
| r[i] = new(allocate_child()) ReadTask(acc); | ||
| w[i] = new(allocate_child()) WriteTask(acc); | ||
| tasks.run([&] { ReadTask r(acc); r.execute(); }); | ||
| tasks.run([&] { WriteTask w(acc); w.execute(); }); |
There was a problem hiding this comment.
Significant change
This test tests multiple read/write accesses running concurrently. I believe I've ported it to represent that, even though the behaviour is not exactly identical.
|
I've commented the significant changes that may warrant more review. The rest should be pretty trivial. |
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
danrbailey
left a comment
There was a problem hiding this comment.
This is great, thanks Nick!
Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
I believe this is the remaining work needed to support TBB 2021 except for the updates to
Queue.h. This also needs testing so marking as a draft and pushing up for visibility.Signed-off-by: Nick Avramoussis 4256455+Idclip@users.noreply.github.com