Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBastien Montagne <mont29>2019-10-30 14:23:45 +0300
committerBastien Montagne <b.mont29@gmail.com>2019-10-30 14:23:45 +0300
commit29433da4c6e4b2da6f3fa3d1868c5039b4e6be70 (patch)
treed4419c5337f4d47557381d144d2c340f2f85e788 /tests
parent3e7af19bf1debc18ce65e611711fb9d96421521e (diff)
BLI_task: Add new generic `BLI_task_parallel_iterator()`.
This new function is part of the 'parallel for loops' functions. It takes an iterator callback to generate items to be processed, in addition to the usual 'process' func callback. This allows to use common code from BLI_task for a wide range of custom iteratiors, whithout having to re-invent the wheel of the whole tasks & data chuncks handling. This supports all settings features from `BLI_task_parallel_range()`, including dynamic and static (if total number of items is knwon) scheduling, TLS data and its finalize callback, etc. One question here is whether we should provide usercode with a spinlock by default, or enforce it to always handle its own sync mechanism. I kept it, since imho it will be needed very often, and generating one is pretty cheap even if unused... ---------- Additionaly, this commit converts (currently unused) `BLI_task_parallel_listbase()` to use that generic code. This was done mostly as proof of concept, but performance-wise it shows some interesting data, roughly: - Very light processing (that should not be threaded anyway) is several times slower, which is expected due to more overhead in loop management code. - Heavier processing can be up to 10% quicker (probably thanks to the switch from dynamic to static scheduling, which reduces a lot locking to fill-in the per-tasks chunks of data). Similar speed-up in non-threaded case comes as a surprise though, not sure what can explain that. While this conversion is not really needed, imho we should keep it (instead of existing code for that function), it's easier to have complex handling logic in as few places as possible, for maintaining and for improving it. Note: That work was initially done to allow for D5372 to be possible... Unfortunately that one proved to be not better than orig code on performances point of view. Reviewed By: sergey Differential Revision: https://developer.blender.org/D5371
Diffstat (limited to 'tests')
-rw-r--r--tests/gtests/blenlib/BLI_task_performance_test.cc32
-rw-r--r--tests/gtests/blenlib/BLI_task_test.cc10
2 files changed, 34 insertions, 8 deletions
diff --git a/tests/gtests/blenlib/BLI_task_performance_test.cc b/tests/gtests/blenlib/BLI_task_performance_test.cc
index ecc012aa47a..dc8981f8064 100644
--- a/tests/gtests/blenlib/BLI_task_performance_test.cc
+++ b/tests/gtests/blenlib/BLI_task_performance_test.cc
@@ -38,14 +38,22 @@ static uint gen_pseudo_random_number(uint num)
return ((num & 255) << 6) + 1;
}
-static void task_listbase_light_iter_func(void *UNUSED(userdata), Link *item, int index)
+static void task_listbase_light_iter_func(void *UNUSED(userdata),
+ void *item,
+ int index,
+ const TaskParallelTLS *__restrict UNUSED(tls))
+
{
LinkData *data = (LinkData *)item;
data->data = POINTER_FROM_INT(POINTER_AS_INT(data->data) + index);
}
-static void task_listbase_light_membarrier_iter_func(void *userdata, Link *item, int index)
+static void task_listbase_light_membarrier_iter_func(void *userdata,
+ void *item,
+ int index,
+ const TaskParallelTLS *__restrict UNUSED(tls))
+
{
LinkData *data = (LinkData *)item;
int *count = (int *)userdata;
@@ -54,7 +62,11 @@ static void task_listbase_light_membarrier_iter_func(void *userdata, Link *item,
atomic_sub_and_fetch_uint32((uint32_t *)count, 1);
}
-static void task_listbase_heavy_iter_func(void *UNUSED(userdata), Link *item, int index)
+static void task_listbase_heavy_iter_func(void *UNUSED(userdata),
+ void *item,
+ int index,
+ const TaskParallelTLS *__restrict UNUSED(tls))
+
{
LinkData *data = (LinkData *)item;
@@ -66,7 +78,11 @@ static void task_listbase_heavy_iter_func(void *UNUSED(userdata), Link *item, in
}
}
-static void task_listbase_heavy_membarrier_iter_func(void *userdata, Link *item, int index)
+static void task_listbase_heavy_membarrier_iter_func(void *userdata,
+ void *item,
+ int index,
+ const TaskParallelTLS *__restrict UNUSED(tls))
+
{
LinkData *data = (LinkData *)item;
int *count = (int *)userdata;
@@ -84,14 +100,18 @@ static void task_listbase_test_do(ListBase *list,
const int num_items,
int *num_items_tmp,
const char *id,
- TaskParallelListbaseFunc func,
+ TaskParallelIteratorFunc func,
const bool use_threads,
const bool check_num_items_tmp)
{
+ TaskParallelSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = use_threads;
+
double averaged_timing = 0.0;
for (int i = 0; i < NUM_RUN_AVERAGED; i++) {
const double init_time = PIL_check_seconds_timer();
- BLI_task_parallel_listbase(list, num_items_tmp, func, use_threads);
+ BLI_task_parallel_listbase(list, num_items_tmp, func, &settings);
averaged_timing += PIL_check_seconds_timer() - init_time;
/* Those checks should ensure us all items of the listbase were processed once, and only once -
diff --git a/tests/gtests/blenlib/BLI_task_test.cc b/tests/gtests/blenlib/BLI_task_test.cc
index 0c1868380da..62ae0baaec9 100644
--- a/tests/gtests/blenlib/BLI_task_test.cc
+++ b/tests/gtests/blenlib/BLI_task_test.cc
@@ -88,7 +88,10 @@ TEST(task, MempoolIter)
/* *** Parallel iterations over double-linked list items. *** */
-static void task_listbase_iter_func(void *userdata, Link *item, int index)
+static void task_listbase_iter_func(void *userdata,
+ void *item,
+ int index,
+ const TaskParallelTLS *__restrict UNUSED(tls))
{
LinkData *data = (LinkData *)item;
int *count = (int *)userdata;
@@ -112,7 +115,10 @@ TEST(task, ListBaseIter)
num_items++;
}
- BLI_task_parallel_listbase(&list, &num_items, task_listbase_iter_func, true);
+ TaskParallelSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+
+ BLI_task_parallel_listbase(&list, &num_items, task_listbase_iter_func, &settings);
/* Those checks should ensure us all items of the listbase were processed once, and only once -
* as expected. */