dnn(ocl4dnn): calculate activation expression once
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 2 Oct 2018 21:10:52 +0000 (21:10 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 2 Oct 2018 21:23:41 +0000 (21:23 +0000)
- to avoid multiple conditional calls via sub_group() functions

modules/dnn/src/opencl/conv_layer_spatial.cl

index 37aceee..5d4d6f3 100644 (file)
 #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