From 2212fd623e8e09bf468d3b72e4468a604511a9c9 Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Fri, 27 Sep 2013 20:04:19 +0200 Subject: [PATCH] filters: Linear: Run one thread on in-place filter If filter is run in-place (src == dst) the filter cannot run in more than one thread (as threads would override values read by other threads). This patch changes the Linear Convolution filters to default to one thread if in-place usage is detected instead of the ASSERTS() Also update linear convolution docs. Signed-off-by: Cyril Hrubis --- doc/filters.txt | 5 +++++ libs/filters/GP_LinearThreads.c | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/filters.txt b/doc/filters.txt index c69ccdd2..ef6b1232 100644 --- a/doc/filters.txt +++ b/doc/filters.txt @@ -714,6 +714,11 @@ and array of kernel values. The last function prints convolution kernel in human-readable format into the stdout. +WARNING: If filter is executed in-place the work cannot be distributed between + threads (as some of the threads will overwrite values read by other + threads). In this case convolution filters runs in one thread + regardless of if threads are eanbled or not. + [source,c] ------------------------------------------------------------------------------- #include diff --git a/libs/filters/GP_LinearThreads.c b/libs/filters/GP_LinearThreads.c index 218110bf..da55ce9b 100644 --- a/libs/filters/GP_LinearThreads.c +++ b/libs/filters/GP_LinearThreads.c @@ -65,8 +65,10 @@ int GP_FilterHConvolutionMP_Raw(const GP_ConvolutionParams *params) if (t == 1) return GP_FilterHConvolution_Raw(params); - GP_ASSERT(params->src != params->dst, - "Multithreaded convolution can't work in-place"); + if (params->src == params->dst) { + GP_DEBUG(1, "In-place filter detected, running in one thread."); + return GP_FilterHConvolution_Raw(params); + } GP_PROGRESS_CALLBACK_MP(callback_mp, params->callback); @@ -113,8 +115,10 @@ int GP_FilterVConvolutionMP_Raw(const GP_ConvolutionParams *params) if (t == 1) return GP_FilterVConvolution_Raw(params); - GP_ASSERT(params->src != params->dst, - "Multithreaded convolution can't work in-place"); + if (params->src == params->dst) { + GP_DEBUG(1, "In-place filter detected, running in one thread."); + return GP_FilterVConvolution_Raw(params); + } GP_PROGRESS_CALLBACK_MP(callback_mp, params->callback); @@ -160,8 +164,10 @@ int GP_FilterConvolutionMP_Raw(const GP_ConvolutionParams *params) if (t == 1) return GP_FilterConvolution_Raw(params); - GP_ASSERT(params->src != params->dst, - "Multithreaded convolution can't work in-place"); + if (params->src == params->dst) { + GP_DEBUG(1, "In-place filter detected, running in one thread."); + return GP_FilterConvolution_Raw(params); + } GP_PROGRESS_CALLBACK_MP(callback_mp, params->callback); -- 2.11.4.GIT