mehmetalici opened a new issue, #15879:
URL: https://github.com/apache/tvm/issues/15879

   I am facing a critical compilation warning when I try to compile a model 
generated for CMSIS target in uTVM.
   
   Below is the generated code snippet that results in warning by the compiler:
   ```c
   TVM_DLL int32_t tvmgen_default_cmsis_nn_main_5(int8_t* input_, int8_t* 
filter_, int32_t* bias_, int8_t* output_, uint8_t* 
global_const_workspace_14_var, uint8_t* global_workspace_15_var) {
     // ...
     arm_cmsis_nn_status status = arm_fully_connected_s8(&context, &fc_params, 
&quant_params, &input_dims, input_, &filter_dims, filter_, &bias_dims, bias_, 
&output_dims, output_);
     switch (!status) {
     case ARM_CMSIS_NN_SUCCESS: break;
     case ARM_CMSIS_NN_ARG_ERROR: return -1;
     case ARM_CMSIS_NN_NO_IMPL_ERROR: return -1;
     }
     return 0;
   }
       }
   ```
   The warning is:
   ```
   default_lib2.c: In function 'tvmgen_default_cmsis_nn_main_0':
   default_lib2.c:41:3: warning: switch condition has boolean value 
[-Wswitch-bool]
      41 |   switch (!status) {
         |   ^~~~~~
   ```
   As hinted by the compiler, the switch statement returns a boolean value, 
i.e. 0 or 1, regardless of value of `Enum` of type `arm_cmsis_nn_status`. This 
is obviously erroneous because the function will return 0 in the case of 
`ARM_CMSIS_NN_ARG_ERROR` or `ARM_CMSIS_NN_NO_IMPL_ERROR`, hence, no error.
   
   I would like to give `arm_cmsis_nn_status` definition below as well for your 
reference:
   ```c
   typedef enum
   {
       ARM_CMSIS_NN_SUCCESS = 0,        /**< No error */
       ARM_CMSIS_NN_ARG_ERROR = -1,     /**< One or more arguments are 
incorrect */
       ARM_CMSIS_NN_NO_IMPL_ERROR = -2, /**<  No implementation available */
   } arm_cmsis_nn_status;
   ```
   ### Expected behavior
   `switch` statement at CMSIS model layer functions without the negation !.
   
   ### Actual behavior
   `switch` statement with `!` in CMSIS model layer functions leading to a 
critical compiler warning as described. 
   
   ### Environment
   - OS: Ubuntu 22.04
   - TVM Version: 0.14.dev163
   
   ### Steps to reproduce
   ```bash
   # Check tvmc version:
   tvmc --version  # Outputs 0.14.dev163
   
   # Download an example model:
   wget 
https://github.com/tensorflow/tflite-micro/raw/a56087ffa2703b4d5632f024a8a4c899815c31bb/tensorflow/lite/micro/examples/micro_speech/micro_speech.tflite
   
   # Run tvmc to compile the model for CMSIS:
    tvmc compile --target=cmsis-nn,c \
                --target-c-mcpu=cortex-m4 \
                --target-cmsis-nn-mcpu=cortex-m4 \
                --runtime=crt \
                --executor=aot \
                --executor-aot-interface-api=c \
                --executor-aot-unpacked-api=1 \
                --pass-config tir.usmp.enable=1 \
                --pass-config tir.usmp.algorithm=hill_climb \
                --pass-config tir.disable_storage_rewrite=1 \
                --pass-config tir.disable_vectorize=1 \
                micro_speech.tflite \
                --output-format=mlf \
                --output module.tar \
                -vvvv
   
   # Extract the archive:
   mkdir module
   tar xvf module.tar --directory=module
   
   # Open the model's `default_lib2.c` with a text editor:
   vim module/codegen/host/src/default_lib2.c
   
   # You will notice `!switch` statements on the functions. 
   ```
   ### Triage
   
   * needs-triage
   * byoc-cmsis_nn
   * flow:aot
   * frontend:tflite
   * runtime:c
   * vert:micro
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to