From eec468fa13b82721e48c371b131bf04404a8d2a9 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 2 Oct 2018 21:10:52 +0000 Subject: [PATCH] dnn(ocl4dnn): calculate activation expression once - to avoid multiple conditional calls via sub_group() functions --- modules/dnn/src/opencl/conv_layer_spatial.cl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/dnn/src/opencl/conv_layer_spatial.cl b/modules/dnn/src/opencl/conv_layer_spatial.cl index 37aceee983..5d4d6f3add 100644 --- a/modules/dnn/src/opencl/conv_layer_spatial.cl +++ b/modules/dnn/src/opencl/conv_layer_spatial.cl @@ -69,10 +69,16 @@ #endif #ifdef FUSED_CONV_ELTWISE -#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { (_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(eltwise_data[(_offset_)] + (_data_), _channel_);} while(0) +#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { \ + const Dtype _x_ = eltwise_data[(_offset_)] + (_data_); \ + (_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \ +} while(0) #define ELTWISE_DATA_ARG __global Dtype* eltwise_data, #else -#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { (_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_data_, _channel_);} while(0) +#define ACTIVATION_FUNCTION(_dst_, _offset_, _data_, _channel_) do { \ + const Dtype _x_ = (_data_); \ + (_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \ +} while(0) #define ELTWISE_DATA_ARG #endif