<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; recent 3.4 ( <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/opencv/opencv/commit/220b37144bbc32dad06e08d4a0b45dba852f3135/hovercard" href="https://github.com/opencv/opencv/commit/220b37144bbc32dad06e08d4a0b45dba852f3135"><tt>220b371</tt></a> ) / master ( <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/opencv/opencv/commit/f584c6d7239e1d56de0c3bd0232d5ccfaf830084/hovercard" href="https://github.com/opencv/opencv/commit/f584c6d7239e1d56de0c3bd0232d5ccfaf830084"><tt>f584c6d</tt></a> )</li>
<li>Operating System / Platform =&gt; Firefly RK3399 Ubuntu 16.04 (Aarch64)</li>
<li>Compiler =&gt; GCC 5.4.0</li>
<li>OpenCL =&gt; 1.2</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Some FP16 inference is disabled on purpose on non-intel platform<br>
Setting <code class="notranslate">OPENCV_DNN_OPENCL_ALLOW_ALL_DEVICES</code> to <code class="notranslate">true</code> will avoid this bypass and kicks the kernel for FP16.<br>
Also, enabling <code class="notranslate">dnn_skip_ocl_fp16</code>, <code class="notranslate">dnn_skip_ocl</code>, <code class="notranslate">dnn_skip_ie_ocl</code> and <code class="notranslate">dnn_skip_ie_ocl_fp16</code> shows one issue in the kernel build.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="OpenCL program build log: dnn/conv_layer_spatial
Status -11: CL_BUILD_PROGRAM_FAILURE
 -D TYPE=1 -D Dtype=float -D Dtype2=float2 -D Dtype4=float4 -D Dtype8=float8 -D Dtype16=float16 -D as_Dtype=as_float -D as_Dtype2=as_float2 -D as_Dtype4=as_float4 -D as_Dtype8=as_float8 -D KERNEL_WIDTH=3 -D KERNEL_HEIGHT=3 -D STRIDE_X=1 -D STRIDE_Y=1 -D DILATION_X=1 -D DILATION_Y=1 -D KERNEL_BASIC -cl-fast-relaxed-math -D ConvolveBasic=BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1 -D CHANNELS=16 -D APPLY_BIAS=0 -D OUTPUT_Z=16 -D ZPAR=1 -D FUSED_CONV_PRELU=1
&lt;source&gt;:157:57: error: use of undeclared identifier 'biasIndex'
ACTIVATION_FUNCTION(convolved_image, offset, sum[kern], biasIndex + kern);
                                                        ^
&lt;source&gt;:35:53: note: expanded from here
(_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \
                                                    ^
&lt;source&gt;:11:101: note: expanded from here
#define ACTIVATION_RELU_FUNCTION(x, c) ((Dtype)(x) &gt; 0 ? (Dtype)(x) : ((Dtype)(x) * (negative_slope[c])))
                                                                                                    ^

error: Compiler frontend failed (error code 59)"><pre class="notranslate"><code class="notranslate">OpenCL program build log: dnn/conv_layer_spatial
Status -11: CL_BUILD_PROGRAM_FAILURE
 -D TYPE=1 -D Dtype=float -D Dtype2=float2 -D Dtype4=float4 -D Dtype8=float8 -D Dtype16=float16 -D as_Dtype=as_float -D as_Dtype2=as_float2 -D as_Dtype4=as_float4 -D as_Dtype8=as_float8 -D KERNEL_WIDTH=3 -D KERNEL_HEIGHT=3 -D STRIDE_X=1 -D STRIDE_Y=1 -D DILATION_X=1 -D DILATION_Y=1 -D KERNEL_BASIC -cl-fast-relaxed-math -D ConvolveBasic=BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1 -D CHANNELS=16 -D APPLY_BIAS=0 -D OUTPUT_Z=16 -D ZPAR=1 -D FUSED_CONV_PRELU=1
&lt;source&gt;:157:57: error: use of undeclared identifier 'biasIndex'
ACTIVATION_FUNCTION(convolved_image, offset, sum[kern], biasIndex + kern);
                                                        ^
&lt;source&gt;:35:53: note: expanded from here
(_dst_)[(_offset_)] = ACTIVATION_RELU_FUNCTION(_x_, _channel_); \
                                                    ^
&lt;source&gt;:11:101: note: expanded from here
#define ACTIVATION_RELU_FUNCTION(x, c) ((Dtype)(x) &gt; 0 ? (Dtype)(x) : ((Dtype)(x) * (negative_slope[c])))
                                                                                                    ^

error: Compiler frontend failed (error code 59)
</code></pre></div>
<p dir="auto">I understand that the FP16 is not fully supported on non Intel platform, but this kernel build failure is a purely syntax error.<br>
Regardless the value of <code class="notranslate">APPLY_BIAS</code>, the parameter <code class="notranslate">biasIndex</code> will be used</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/opencv/opencv/blob/eec468fa13b82721e48c371b131bf04404a8d2a9/modules/dnn/src/opencl/conv_layer_spatial.cl#L205-L209">opencv/modules/dnn/src/opencl/conv_layer_spatial.cl</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 205 to 209
      in
      <a data-pjax="true" class="commit-tease-sha" href="/opencv/opencv/commit/eec468fa13b82721e48c371b131bf04404a8d2a9">eec468f</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L205" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="205"></td>
          <td id="LC205" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">#if</span> <span class="pl-c1">APPLY_BIAS</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L206" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="206"></td>
          <td id="LC206" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">                 <span class="pl-en">ACTIVATION_FUNCTION</span>(<span class="pl-s1">convolved_image</span>, <span class="pl-s1">offset</span>, <span class="pl-s1">sum</span>[<span class="pl-s1">kern</span>] <span class="pl-c1">+</span> <span class="pl-s1">bias</span>[<span class="pl-s1">biasIndex</span> <span class="pl-c1">+</span> <span class="pl-s1">kern</span>], <span class="pl-s1">biasIndex</span> <span class="pl-c1">+</span> <span class="pl-s1">kern</span>); </td>
        </tr>

        <tr class="border-0">
          <td id="L207" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="207"></td>
          <td id="LC207" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">#else</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L208" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="208"></td>
          <td id="LC208" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">                 <span class="pl-en">ACTIVATION_FUNCTION</span>(<span class="pl-s1">convolved_image</span>, <span class="pl-s1">offset</span>, <span class="pl-s1">sum</span>[<span class="pl-s1">kern</span>], <span class="pl-s1">biasIndex</span> <span class="pl-c1">+</span> <span class="pl-s1">kern</span>); </td>
        </tr>

        <tr class="border-0">
          <td id="L209" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="209"></td>
          <td id="LC209" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">#endif</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">when <code class="notranslate">biasIndex</code> in only defined with <code class="notranslate">APPLY_BIAS</code></p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/opencv/opencv/blob/eec468fa13b82721e48c371b131bf04404a8d2a9/modules/dnn/src/opencl/conv_layer_spatial.cl#L170-L172">opencv/modules/dnn/src/opencl/conv_layer_spatial.cl</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 170 to 172
      in
      <a data-pjax="true" class="commit-tease-sha" href="/opencv/opencv/commit/eec468fa13b82721e48c371b131bf04404a8d2a9">eec468f</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L170" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="170"></td>
          <td id="LC170" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">#if</span> <span class="pl-c1">APPLY_BIAS</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L171" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="171"></td>
          <td id="LC171" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         <span class="pl-k">const</span> <span class="pl-smi">int</span> <span class="pl-s1">biasIndex</span> <span class="pl-c1">=</span> <span class="pl-s1">bias_offset</span> <span class="pl-c1">+</span> <span class="pl-s1">kernelNum</span>; </td>
        </tr>

        <tr class="border-0">
          <td id="L172" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="172"></td>
          <td id="LC172" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">#endif</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">Looks like this <code class="notranslate">biasIndex</code> was introduced in to <code class="notranslate">ACTIVATION_FUNCTION</code> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="265198673" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/9847" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/9847/hovercard" href="https://github.com/opencv/opencv/pull/9847">#9847</a> when <code class="notranslate">ACTIVATION_FUNCTION</code> was now related with <code class="notranslate">ACTIVATION_RELU_FUNCTION</code> and <code class="notranslate">FUSED_CONV_PRELU</code>, but not considering the <code class="notranslate">APPLY_BIAS</code><br>
I need to undo this <code class="notranslate">APPLY_BIAS</code> but it's bit tricky, so I'll just report the issue here.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">On Firefly RK3399</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ mkdir build
$ cd build
$ cmake -DOPENCV_EXTRA_MODULES_PATH=/xxx/opencv_contrib/modules -DBUILD_EXAMPLES=true -DOPENCV_ENABLE_NONFREE=true ..
$ make -j 4 all
$ export OPENCV_DNN_OPENCL_ALLOW_ALL_DEVICES=true
$ export OPENCV_TEST_DATA_PATH=/opencv_extra/testdata
$ ./bin/opencv_test_dnn --test_tag_enable=dnn_skip_ocl --gtest_filter=TestLayerFusion/ConvolutionActivationFusion.Accuracy/6"><pre class="notranslate"><code class="notranslate">$ mkdir build
$ cd build
$ cmake -DOPENCV_EXTRA_MODULES_PATH=/xxx/opencv_contrib/modules -DBUILD_EXAMPLES=true -DOPENCV_ENABLE_NONFREE=true ..
$ make -j 4 all
$ export OPENCV_DNN_OPENCL_ALLOW_ALL_DEVICES=true
$ export OPENCV_TEST_DATA_PATH=/opencv_extra/testdata
$ ./bin/opencv_test_dnn --test_tag_enable=dnn_skip_ocl --gtest_filter=TestLayerFusion/ConvolutionActivationFusion.Accuracy/6
</code></pre></div>

<h5 dir="auto">Issue submission checklist</h5>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I report the issue, it's not a question

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I checked the problem with documentation, FAQ, open issues,<br>
answers.opencv.org, Stack Overflow, etc and have not found solution

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I updated to latest OpenCV version and the issue is still there

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> There is reproducer code and related data files: videos, images, onnx, etc

</li>
</ul>
<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.4.0 (probably in 3.4 too)</li>
<li>Operating System / Platform =&gt; Ubuntu 18.04</li>
<li>Compiler =&gt; gcc 7.5</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Convolution without bias followed by ChannelsPReLU activation with fusion enabled leads to:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="OpenCL program build log: dnn/conv_layer_spatial
Status -11: CL_BUILD_PROGRAM_FAILURE
 -D TYPE=1 -D Dtype=float -D Dtype2=float2 -D Dtype4=float4 -D Dtype8=float8 -D Dtype16=float16 -D as_Dtype=as_float -D as_Dtype2=as_float2 -D as_Dtype4=as_float4 -D as_Dtype8=as_float8 -D KERNEL_WIDTH=3 -D KERNEL_HEIGHT=3 -D STRIDE_X=1 -D STRIDE_Y=1 -D DILATION_X=1 -D DILATION_Y=1 -D KERNEL_BASIC -cl-fast-relaxed-math -D ConvolveBasic=BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1 -cl-no-subgroup-ifp  -D CHANNELS=16 -D APPLY_BIAS=0 -D OUTPUT_Z=16 -D ZPAR=1 -D FUSED_CONV_PRELU=1 -D INTEL_DEVICE
9:157:57: error: use of undeclared identifier 'biasIndex'
ACTIVATION_FUNCTION(convolved_image, offset, sum[kern], biasIndex + kern);
                                                        ^

Failed to compile kernel: BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1, buildflags:  -D TYPE=1 -D Dtype=float -D Dtype2=float2 -D Dtype4=float4 -D Dtype8=float8 -D Dtype16=float16 -D as_Dtype=as_float -D as_Dtype2=as_float2 -D as_Dtype4=as_float4 -D as_Dtype8=as_float8 -D KERNEL_WIDTH=3 -D KERNEL_HEIGHT=3 -D STRIDE_X=1 -D STRIDE_Y=1 -D DILATION_X=1 -D DILATION_Y=1 -D KERNEL_BASIC -cl-fast-relaxed-math -D ConvolveBasic=BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1 -cl-no-subgroup-ifp  -D CHANNELS=16 -D APPLY_BIAS=0 -D OUTPUT_Z=16 -D ZPAR=1 -D FUSED_CONV_PRELU=1, errmsg: 9:157:57: error: use of undeclared identifier 'biasIndex'
ACTIVATION_FUNCTION(convolved_image, offset, sum[kern], biasIndex + kern);
                                                        ^

Segmentation fault (core dumped)"><pre class="notranslate"><code class="notranslate">OpenCL program build log: dnn/conv_layer_spatial
Status -11: CL_BUILD_PROGRAM_FAILURE
 -D TYPE=1 -D Dtype=float -D Dtype2=float2 -D Dtype4=float4 -D Dtype8=float8 -D Dtype16=float16 -D as_Dtype=as_float -D as_Dtype2=as_float2 -D as_Dtype4=as_float4 -D as_Dtype8=as_float8 -D KERNEL_WIDTH=3 -D KERNEL_HEIGHT=3 -D STRIDE_X=1 -D STRIDE_Y=1 -D DILATION_X=1 -D DILATION_Y=1 -D KERNEL_BASIC -cl-fast-relaxed-math -D ConvolveBasic=BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1 -cl-no-subgroup-ifp  -D CHANNELS=16 -D APPLY_BIAS=0 -D OUTPUT_Z=16 -D ZPAR=1 -D FUSED_CONV_PRELU=1 -D INTEL_DEVICE
9:157:57: error: use of undeclared identifier 'biasIndex'
ACTIVATION_FUNCTION(convolved_image, offset, sum[kern], biasIndex + kern);
                                                        ^

Failed to compile kernel: BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1, buildflags:  -D TYPE=1 -D Dtype=float -D Dtype2=float2 -D Dtype4=float4 -D Dtype8=float8 -D Dtype16=float16 -D as_Dtype=as_float -D as_Dtype2=as_float2 -D as_Dtype4=as_float4 -D as_Dtype8=as_float8 -D KERNEL_WIDTH=3 -D KERNEL_HEIGHT=3 -D STRIDE_X=1 -D STRIDE_Y=1 -D DILATION_X=1 -D DILATION_Y=1 -D KERNEL_BASIC -cl-fast-relaxed-math -D ConvolveBasic=BASIC_k3x3_cn16_g1_s1x1_d1x1_b0_in16x16_p1x1_num2_M16_activ2_eltwise0_FP32_4_1_1_1 -cl-no-subgroup-ifp  -D CHANNELS=16 -D APPLY_BIAS=0 -D OUTPUT_Z=16 -D ZPAR=1 -D FUSED_CONV_PRELU=1, errmsg: 9:157:57: error: use of undeclared identifier 'biasIndex'
ACTIVATION_FUNCTION(convolved_image, offset, sum[kern], biasIndex + kern);
                                                        ^

Segmentation fault (core dumped)
</code></pre></div>
<p dir="auto">Segfault also happens with convolution without bias + eltwise + ChannelsPReLU. It works without problems if convolution layer has bias.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Disabled tests from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="667767932" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/17976" data-hovercard-type="pull_request" data-hovercard-url="/opencv/opencv/pull/17976/hovercard" href="https://github.com/opencv/opencv/pull/17976">#17976</a> can reproduce this bug. Relevant tests have <code class="notranslate">// bug: https://github.com/opencv/opencv/issues/17953</code> comment just before applying the skip test tag.</p>
<h5 dir="auto">Issue submission checklist</h5>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I report the issue, it's not a question

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I checked the problem with documentation, FAQ, open issues,<br>
answers.opencv.org, Stack Overflow, etc and have not found solution

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I updated to latest OpenCV version and the issue is still there

</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> There is reproducer code and related data files: videos, images, onnx, etc

</li>
</ul>