eloquentarduino / EloquentTinyML

Eloquent interface to Tensorflow Lite for Microcontrollers
301 stars 57 forks source link

When warning level raised, compilation breaks. #31

Closed maarten-pennings closed 3 years ago

maarten-pennings commented 3 years ago

If you set (in the Arduino IDE)

  File > Preferences > Compiler warnings > More

then close and reopen Arduino IDE (otherwise the build is from the cache) you get more warnings (on All even more).

    C:\Users\mpen\Documents\Arduino\libraries\EloquentTinyML\src\tensorflow\lite\micro\debug_log_numbers.cpp: In function 'char* {anonymous}::FastFloatToBufferLeft(float, char*)':
    C:\Users\mpen\Documents\Arduino\libraries\EloquentTinyML\src\tensorflow\lite\micro\debug_log_numbers.cpp:117:53: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       const uint32_t u = *reinterpret_cast<uint32_t*>(&f);
                                                         ^
    In file included from C:\Users\mpen\Documents\Arduino\libraries\EloquentTinyML\src\tensorflow\lite\micro\kernels\svdf.cpp:25:0:
    C:\Users\mpen\Documents\Arduino\libraries\EloquentTinyML\src/tensorflow/lite/micro/kernels/activation_utils.h: In function 'float tflite::ops::micro::ActivationValFloat(TfLiteFusedActivation, float)':
    C:\Users\mpen\Documents\Arduino\libraries\EloquentTinyML\src/tensorflow/lite/micro/kernels/activation_utils.h:53:1: error: control reaches end of non-void function [-Werror=return-type]
     }
     ^
    cc1plus.exe: some warnings being treated as errors
    exit status 1
    Error compiling for board AI Thinker ESP32-CAM.

The problem is that (I believe the last) warning results in a failed compilation because a return is missing in the below function. Probably because a default case is missing in the switch.

// Returns the floating point value for a fused activation:
inline float ActivationValFloat(TfLiteFusedActivation act, float a) {
  switch (act) {
    case kTfLiteActNone:
      return a;
    case kTfLiteActRelu:
      return _max(0.0f, a);
    case kTfLiteActRelu1:
      return _max(-1.0f, _min(a, 1.0f));
    case kTfLiteActRelu6:
      return _max(0.0f, _min(a, 6.0f));
    case kTfLiteActTanh:
      return tanh(a);
    case kTfLiteActSignBit:
      //return signbit(a);
      return a > 0 ? 1 : 0;
    case kTfLiteActSigmoid:
      return 1.0f / (1.0f + exp(-a));
  }
}
eloquentarduino commented 3 years ago

Thank you for pointing it out. I will patch that function from the Tensorflow library in the next release.