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
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2020-06-05 15:36:31 +0300
committerBrecht Van Lommel <brecht@blender.org>2020-06-06 22:01:48 +0300
commitbe3a8ccbfd50e6c5cbd0b53f19e14cec84f47799 (patch)
tree0be494619d7609c6d7479eb0341d15bfbd1c4961
parentc2e09a773d001ae7151a47b4871f1ca4869bea99 (diff)
Cleanup: remove task pool stop() and finished()
-rw-r--r--intern/cycles/device/cuda/device_cuda_impl.cpp2
-rw-r--r--intern/cycles/device/device_cpu.cpp2
-rw-r--r--intern/cycles/device/device_optix.cpp2
-rw-r--r--intern/cycles/device/opencl/device_opencl.h2
-rw-r--r--intern/cycles/device/opencl/device_opencl_impl.cpp17
-rw-r--r--intern/cycles/util/util_task.cpp33
-rw-r--r--intern/cycles/util/util_task.h3
7 files changed, 22 insertions, 39 deletions
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 */