From fa3d50af95fde76ef08590d2f86444f2f9fdca95 Mon Sep 17 00:00:00 2001 From: Lukas Stockner Date: Fri, 10 Nov 2017 04:34:14 +0100 Subject: Cycles: Improve denoising speed on GPUs with small tile sizes Previously, the NLM kernels would be launched once per offset with one thread per pixel. However, with the smaller tile sizes that are now feasible, there wasn't enough work to fully occupy GPUs which results in a significant slowdown. Therefore, the kernels are now launched in a single call that handles all offsets at once. This has two downsides: Memory accesses to accumulating buffers are now atomic, and more importantly, the temporary memory now has to be allocated for every shift at once, increasing the required memory. On the other hand, of course, the smaller tiles significantly reduce the size of the memory. The main bottleneck right now is the construction of the transformation - there is nothing to be parallelized there, one thread per pixel is the maximum. I tried to parallelize the SVD implementation by storing the matrix in shared memory and launching one block per pixel, but that wasn't really going anywhere. To make the new code somewhat readable, the handling of rectangular regions was cleaned up a bit and commented, it should be easier to understand what's going on now. Also, some variables have been renamed to make the difference between buffer width and stride more apparent, in addition to some general style cleanup. --- intern/cycles/device/device_cpu.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'intern/cycles/device/device_cpu.cpp') diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 999b9230d29..2d28ccd2b49 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -190,9 +190,9 @@ public: KernelFunctions filter_nlm_update_output_kernel; KernelFunctions filter_nlm_normalize_kernel; - KernelFunctions filter_construct_transform_kernel; - KernelFunctions filter_nlm_construct_gramian_kernel; - KernelFunctions filter_finalize_kernel; + KernelFunctions filter_construct_transform_kernel; + KernelFunctions filter_nlm_construct_gramian_kernel; + KernelFunctions filter_finalize_kernel; KernelFunctionsbuffer.w, + task->buffer.stride, task->buffer.pass_stride, 1.0f, task->nlm_k_2); - filter_nlm_blur_kernel()(difference, blurDifference, local_rect, task->buffer.w, 4); - filter_nlm_calc_weight_kernel()(blurDifference, difference, local_rect, task->buffer.w, 4); - filter_nlm_blur_kernel()(difference, blurDifference, local_rect, task->buffer.w, 4); + filter_nlm_blur_kernel()(difference, blurDifference, local_rect, task->buffer.stride, 4); + filter_nlm_calc_weight_kernel()(blurDifference, difference, local_rect, task->buffer.stride, 4); + filter_nlm_blur_kernel()(difference, blurDifference, local_rect, task->buffer.stride, 4); filter_nlm_construct_gramian_kernel()(dx, dy, blurDifference, (float*) task->buffer.mem.device_pointer, @@ -580,9 +580,8 @@ public: (float*) task->storage.XtWX.device_pointer, (float3*) task->storage.XtWY.device_pointer, local_rect, - &task->reconstruction_state.filter_rect.x, - task->buffer.w, - task->buffer.h, + &task->reconstruction_state.filter_window.x, + task->buffer.stride, 4, task->buffer.pass_stride); } @@ -591,8 +590,6 @@ public: filter_finalize_kernel()(x, y, y*task->filter_area.z + x, - task->buffer.w, - task->buffer.h, (float*) output_ptr, (int*) task->storage.rank.device_pointer, (float*) task->storage.XtWX.device_pointer, -- cgit v1.2.3