[Bf-blender-cvs] [be3a8ccbfd5] temp-cycles-tbb: Cleanup: remove task pool stop() and finished()

Brecht Van Lommel noreply at git.blender.org
Sat Jun 6 21:05:05 CEST 2020


Commit: be3a8ccbfd50e6c5cbd0b53f19e14cec84f47799
Author: Brecht Van Lommel
Date:   Fri Jun 5 14:36:31 2020 +0200
Branches: temp-cycles-tbb
https://developer.blender.org/rBbe3a8ccbfd50e6c5cbd0b53f19e14cec84f47799

Cleanup: remove task pool stop() and finished()

===================================================================

M	intern/cycles/device/cuda/device_cuda_impl.cpp
M	intern/cycles/device/device_cpu.cpp
M	intern/cycles/device/device_optix.cpp
M	intern/cycles/device/opencl/device_opencl.h
M	intern/cycles/device/opencl/device_opencl_impl.cpp
M	intern/cycles/util/util_task.cpp
M	intern/cycles/util/util_task.h

===================================================================

diff --git a/intern/cycles/device/cuda/device_cuda_impl.cpp b/intern/cycles/device/cuda/device_cuda_impl.cpp
index 55592edda1c..7166cc76218 100644
--- a/intern/cycles/device/cuda/device_cuda_impl.cpp
+++ b/intern/cycles/device/cuda/device_cuda_impl.cpp
@@ -259,7 +259,7 @@ CUDADevice::CUDADevice(DeviceInfo &info, Stats &stats, Profiler &profiler, bool
 
 CUDADevice::~CUDADevice()
 {
-  task_pool.stop();
+  task_pool.cancel();
 
   delete split_kernel;
 
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index d2914bd519c..bc85d9386ad 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -333,7 +333,7 @@ class CPUDevice : public Device {
 
   ~CPUDevice()
   {
-    task_pool.stop();
+    task_pool.cancel();
     texture_info.free();
   }
 
diff --git a/intern/cycles/device/device_optix.cpp b/intern/cycles/device/device_optix.cpp
index 05f20331592..4a6784d7479 100644
--- a/intern/cycles/device/device_optix.cpp
+++ b/intern/cycles/device/device_optix.cpp
@@ -246,7 +246,7 @@ class OptiXDevice : public CUDADevice {
   ~OptiXDevice()
   {
     // Stop processing any more tasks
-    task_pool.stop();
+    task_pool.cancel();
 
     // Make CUDA context current
     const CUDAContextScope scope(cuContext);
diff --git a/intern/cycles/device/opencl/device_opencl.h b/intern/cycles/device/opencl/device_opencl.h
index ec091d12114..e0140996cf0 100644
--- a/intern/cycles/device/opencl/device_opencl.h
+++ b/intern/cycles/device/opencl/device_opencl.h
@@ -259,6 +259,8 @@ class OpenCLDevice : public Device {
   TaskPool load_required_kernel_task_pool;
   /* Task pool for optional kernels (feature kernels during foreground rendering) */
   TaskPool load_kernel_task_pool;
+  std::atomic<int> load_kernel_num_compiling;
+
   cl_context cxContext;
   cl_command_queue cqCommandQueue;
   cl_platform_id cpPlatform;
diff --git a/intern/cycles/device/opencl/device_opencl_impl.cpp b/intern/cycles/device/opencl/device_opencl_impl.cpp
index 0cb5362f392..33811e5fd25 100644
--- a/intern/cycles/device/opencl/device_opencl_impl.cpp
+++ b/intern/cycles/device/opencl/device_opencl_impl.cpp
@@ -610,6 +610,7 @@ void OpenCLDevice::opencl_assert_err(cl_int err, const char *where)
 
 OpenCLDevice::OpenCLDevice(DeviceInfo &info, Stats &stats, Profiler &profiler, bool background)
     : Device(info, stats, profiler, background),
+      load_kernel_num_compiling(0),
       kernel_programs(this),
       preview_programs(this),
       memory_manager(this),
@@ -684,9 +685,9 @@ OpenCLDevice::OpenCLDevice(DeviceInfo &info, Stats &stats, Profiler &profiler, b
 
 OpenCLDevice::~OpenCLDevice()
 {
-  task_pool.stop();
-  load_required_kernel_task_pool.stop();
-  load_kernel_task_pool.stop();
+  task_pool.cancel();
+  load_required_kernel_task_pool.cancel();
+  load_kernel_task_pool.cancel();
 
   memory_manager.free();
 
@@ -798,7 +799,11 @@ bool OpenCLDevice::load_kernels(const DeviceRequestedFeatures &requested_feature
    * internally within a single process. */
   foreach (OpenCLProgram *program, programs) {
     if (!program->load()) {
-      load_kernel_task_pool.push(function_bind(&OpenCLProgram::compile, program));
+      load_kernel_num_compiling++;
+      load_kernel_task_pool.push([&] {
+        program->compile();
+        load_kernel_num_compiling--;
+      });
     }
   }
   return true;
@@ -868,7 +873,7 @@ bool OpenCLDevice::wait_for_availability(const DeviceRequestedFeatures &requeste
      * Better to check on device level than per kernel as mixing preview and
      * non-preview kernels does not work due to different data types */
     if (use_preview_kernels) {
-      use_preview_kernels = !load_kernel_task_pool.finished();
+      use_preview_kernels = load_kernel_num_compiling.load() > 0;
     }
   }
   return split_kernel->load_kernels(requested_features);
@@ -895,7 +900,7 @@ DeviceKernelStatus OpenCLDevice::get_active_kernel_switch_state()
     return DEVICE_KERNEL_USING_FEATURE_KERNEL;
   }
 
-  bool other_kernels_finished = load_kernel_task_pool.finished();
+  bool other_kernels_finished = load_kernel_num_compiling.load() == 0;
   if (use_preview_kernels) {
     if (other_kernels_finished) {
       return DEVICE_KERNEL_FEATURE_KERNEL_AVAILABLE;
diff --git a/intern/cycles/util/util_task.cpp b/intern/cycles/util/util_task.cpp
index b7a47c73571..eb07ec0bfa0 100644
--- a/intern/cycles/util/util_task.cpp
+++ b/intern/cycles/util/util_task.cpp
@@ -46,7 +46,7 @@ TaskPool::TaskPool()
 
 TaskPool::~TaskPool()
 {
-  stop();
+  cancel();
 }
 
 void TaskPool::push(TaskRunFunction &&task, bool front)
@@ -135,24 +135,11 @@ void TaskPool::cancel()
   do_cancel = false;
 }
 
-void TaskPool::stop()
-{
-  TaskScheduler::clear(this);
-
-  assert(num == 0);
-}
-
 bool TaskPool::canceled()
 {
   return do_cancel;
 }
 
-bool TaskPool::finished()
-{
-  thread_scoped_lock num_lock(num_mutex);
-  return num == 0;
-}
-
 void TaskPool::num_decrease(int done)
 {
   num_mutex.lock();
@@ -453,7 +440,11 @@ DedicatedTaskPool::DedicatedTaskPool()
 
 DedicatedTaskPool::~DedicatedTaskPool()
 {
-  stop();
+  wait();
+
+  do_exit = true;
+  queue_cond.notify_all();
+
   worker_thread->join();
   delete worker_thread;
 }
@@ -491,18 +482,6 @@ void DedicatedTaskPool::cancel()
   do_cancel = false;
 }
 
-void DedicatedTaskPool::stop()
-{
-  clear();
-
-  do_exit = true;
-  queue_cond.notify_all();
-
-  wait();
-
-  assert(num == 0);
-}
-
 bool DedicatedTaskPool::canceled()
 {
   return do_cancel;
diff --git a/intern/cycles/util/util_task.h b/intern/cycles/util/util_task.h
index 3f811acfea6..d44ffccbc90 100644
--- a/intern/cycles/util/util_task.h
+++ b/intern/cycles/util/util_task.h
@@ -65,8 +65,6 @@ class TaskPool {
 
   void wait_work(Summary *stats = NULL); /* work and wait until all tasks are done */
   void cancel();                         /* cancel all tasks, keep worker threads running */
-  void stop();                           /* stop all worker threads */
-  bool finished();                       /* check if all work has been completed */
 
   bool canceled(); /* for worker threads, test if canceled */
 
@@ -154,7 +152,6 @@ class DedicatedTaskPool {
 
   void wait();   /* wait until all tasks are done */
   void cancel(); /* cancel all tasks, keep worker thread running */
-  void stop();   /* stop worker thread */
 
   bool canceled(); /* for worker thread, test if canceled */



More information about the Bf-blender-cvs mailing list