Skip to content

ocl: fix kernels compilation#24740

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
opencv-pushbot:gitee/alalek/ocl_fix_kernel_compilation
Dec 22, 2023
Merged

ocl: fix kernels compilation#24740
asmorkalov merged 1 commit intoopencv:4.xfrom
opencv-pushbot:gitee/alalek/ocl_fix_kernel_compilation

Conversation

@opencv-alalek
Copy link
Copy Markdown
Contributor

@opencv-alalek opencv-alalek commented Dec 21, 2023

Avoid verbose OpenCL compilation messages like:

relates #24734

[ RUN      ] DNNTestNetwork.AlexNet/0, where GetParam() = OCV/OCL
...
OpenCL program build log: dnn/conv_layer_spatial
Status 0: CL_SUCCESS
 -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=11 -D KERNEL_HEIGHT=11 -D STRIDE_X=4 -D STRIDE_Y=4 -D DILATION_X=1 -D DILATION_Y=1 -D INPUT_PAD_W=0 -D INPUT_PAD_H=0 -D INPUT_PAD_RIGHT=0 -D INPUT_PAD_BOTTOM=0 -cl-fast-relaxed-math  -D GEMM_LIKE_CONV_32_1 -D Conv_Interleaved=U_GEMM_LIKE_CONV_k11x11_cn3_g1_s4x4_d1x1_b1_in240x240_p0x0_num1_M96_activ1_eltwise0_FP32_5_1_8_32_SIMD8 -cl-mad-enable -cl-no-subgroup-ifp  -D KERNEL_GEMM_LIKE -D INPUT_DEPTH=3 -D WIDTH1=96 -D OUT_PADDING_LEFT=0 -D OUT_PADDING_HEIGHT=0 -D OUT_DEPTH=96 -D NUM_BATCHES=1 -D DY=1 -D DX=32 -D KERNEL_WIDTH_DIV2=5 -D KERNEL_SLICE_DIV2=60 -D TILE_N_LAST=0 -D TILE_N_LAST_DIV8=0 -D APPLY_BIAS=1 -D FUSED_CONV_RELU=1 -D INTEL_DEVICE
3:406:1: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts
LOOP(KERNEL_WIDTH, pos,
^~~~~~~~~~~~~~~~~~~~~~~
3:67:48: note: expanded from macro 'LOOP'
#define LOOP(N, VAR, STMT) CAT(LOOP, N)((VAR), (STMT))
                                               ^
3:61:39: note: expanded from macro 'LOOP11'
#define LOOP11(VAR, STMT) LOOP10(VAR, STMT); (STMT); (VAR)++;
                                      ^~~~
3:60:38: note: expanded from macro 'LOOP10'
#define LOOP10(VAR, STMT) LOOP9(VAR, STMT); (STMT); (VAR)++;
                                     ^~~~
note: (skipping 6 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
3:53:37: note: expanded from macro 'LOOP3'
#define LOOP3(VAR, STMT) LOOP2(VAR, STMT); (STMT); (VAR)++;
                                    ^~~~
3:52:37: note: expanded from macro 'LOOP2'
#define LOOP2(VAR, STMT) LOOP1(VAR, STMT); (STMT); (VAR)++;
                                    ^~~~
3:51:27: note: expanded from macro 'LOOP1'
#define LOOP1(VAR, STMT) (STMT); (VAR)++;
                          ^~~~
3:407:1: note: '{' token is here
{
^
3:67:49: note: expanded from macro 'LOOP'
#define LOOP(N, VAR, STMT) CAT(LOOP, N)((VAR), (STMT))
                                                ^~~~
3:61:39: note: expanded from macro 'LOOP11'
#define LOOP11(VAR, STMT) LOOP10(VAR, STMT); (STMT); (VAR)++;
                                      ^~~~
3:60:38: note: expanded from macro 'LOOP10'
#define LOOP10(VAR, STMT) LOOP9(VAR, STMT); (STMT); (VAR)++;
                                     ^~~~
note: (skipping 6 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
3:53:37: note: expanded from macro 'LOOP3'
#define LOOP3(VAR, STMT) LOOP2(VAR, STMT); (STMT); (VAR)++;
                                    ^~~~
3:52:37: note: expanded from macro 'LOOP2'
#define LOOP2(VAR, STMT) LOOP1(VAR, STMT); (STMT); (VAR)++;
                                    ^~~~
3:51:27: note: expanded from macro 'LOOP1'
#define LOOP1(VAR, STMT) (STMT); (VAR)++;
                          ^~~~

Validate with:

  • Intel OpenCL device (kernels are guarded by dev.isIntel())
  • disabled OpenCL cache in OpenCV: OPENCV_OPENCL_CACHE_ENABLE=0
  • disable cache in runtime, e.g. rm -f ~/.cache/neo_compiler_cache
  • enable CV_OPENCL_ALWAYS_SHOW_BUILD_LOG in ocl.cpp

relates https://reviews.llvm.org/D86751

force_builders=Linux OpenCL,Linux AVX2,Win64 OpenCL

@asmorkalov
Copy link
Copy Markdown
Contributor

OpenCV-Linux:

ypedef CAT( Dtype, KERNEL_WIDTH ) Dtype_t;
        ^
4730:49:19: note: expanded from macro 'CAT'
#define CAT(x, y) __CAT(x, y)
                  ^
4730:48:21: note: expanded from macro '__CAT'
#define __CAT(x, y) x##y
                    ^
<scratch space>:9:1: note: expanded from here
half32
^
4730:406:1: error: implicit declaration of function 'LOOP32' is invalid in OpenCL
LOOP(KERNEL_WIDTH, pos,
^
4730:67:28: note: expanded from macro 'LOOP'
#define LOOP(N, VAR, STMT) CAT(LOOP, N)(VAR, STMT)
                           ^
4730:49:19: note: expanded from macro 'CAT'
#define CAT(x, y) __CAT(x, y)
                  ^
4730:48:21: note: expanded from macro '__CAT'
#define __CAT(x, y) x##y
                    ^
<scratch space>:10:1: note: expanded from here
LOOP32
^
4730:407:1: error: expected expression
{
^

[ WARN:0@1545.320] global ocl4dnn_conv_spatial.cpp:1290 compileKernel DNN/OpenCL: Failed to compile kernel: U_GEMM_LIKE_CONV_k32x32_cn3_g1_s32x32_d1x1_b1_in224x224_p0x0_num1_M768_activ0_eltwise0_FP16_5_1_8_32_SIMD8, buildflags: ' -D TYPE=2 -D Dtype=half -D Dtype2=half2 -D Dtype4=half4 -D Dtype8=half8 -D Dtype16=half16 -D as_Dtype=as_half -D as_Dtype2=as_half2 -D as_Dtype4=as_half4 -D as_Dtype8=as_half8 -D KERNEL_WIDTH=32 -D KERNEL_HEIGHT=32 -D STRIDE_X=32 -D STRIDE_Y=32 -D DILATION_X=1 -D DILATION_Y=1 -D INPUT_PAD_W=0 -D INPUT_PAD_H=0 -D INPUT_PAD_RIGHT=0 -D INPUT_PAD_BOTTOM=0 -cl-fast-relaxed-math  -D GEMM_LIKE_CONV_32_1 -D Conv_Interleaved=U_GEMM_LIKE_CONV_k32x32_cn3_g1_s32x32_d1x1_b1_in224x224_p0x0_num1_M768_activ0_eltwise0_FP16_5_1_8_32_SIMD8 -cl-mad-enable -cl-no-subgroup-ifp  -D KERNEL_GEMM_LIKE -D INPUT_DEPTH=3 -D WIDTH1=768 -D OUT_PADDING_LEFT=0 -D OUT_PADDING_HEIGHT=0 -D OUT_DEPTH=768 -D NUM_BATCHES=1 -D DY=1 -D DX=32 -D KERNEL_WIDTH_DIV2=16 -D KERNEL_SLICE_DIV2=512 -D TILE_N_LAST=0 -D TILE_N_LAST_DIV8=0 -D APPLY_BIAS=1', errmsg: '4730:356:9: error: unknown type name 'half32'
typedef CAT( Dtype, KERNEL_WIDTH ) Dtype_t;
        ^
4730:49:19: note: expanded from macro 'CAT'
#define CAT(x, y) __CAT(x, y)
                  ^
4730:48:21: note: expanded from macro '__CAT'
#define __CAT(x, y) x##y
                    ^
<scratch space>:9:1: note: expanded from here
half32
^
4730:406:1: error: implicit declaration of function 'LOOP32' is invalid in OpenCL
LOOP(KERNEL_WIDTH, pos,
^
4730:67:28: note: expanded from macro 'LOOP'
#define LOOP(N, VAR, STMT) CAT(LOOP, N)(VAR, STMT)
                           ^
4730:49:19: note: expanded from macro 'CAT'
#define CAT(x, y) __CAT(x, y)
                  ^
4730:48:21: note: expanded from macro '__CAT'
#define __CAT(x, y) x##y
                    ^
<scratch space>:10:1: note: expanded from here
LOOP32
^
4730:407:1: error: expected expression
{
^
'

@opencv-alalek
Copy link
Copy Markdown
Contributor Author

half32

Problem with VIT test is fixed in another PR: #24736

@asmorkalov asmorkalov self-requested a review December 22, 2023 05:15
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@asmorkalov asmorkalov merged commit 35e2ef8 into opencv:4.x Dec 22, 2023
@asmorkalov asmorkalov mentioned this pull request Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants