tensorflow/lite/kernels/conv.cc
bool IsIm2ColRequired(const TfLiteTensor* input, TfLiteConvParams* params,
                      const TfLiteTensor* filter, OpData* data, bool is_hybrid,
                      KernelType kernel_type) {
  // If HWCN weights are required, Im2Col not required
  if (data->need_hwcn_weights) return false;

  // segregate based on dilated conv & non-dialated conv
  const bool need_dilated_im2col =
      params->dilation_width_factor != 1 || params->dilation_height_factor != 1;
  const bool need_non_dilated_im2col =
      params->stride_width != 1 || params->stride_height != 1 ||
      filter->dims->data[2] != 1 || filter->dims->data[1] != 1;

  const bool need_im2col = need_dilated_im2col || need_non_dilated_im2col;

  // Return early as basic requirement is not met
  if (!need_im2col) return false;

  // Special case for Hybrid, as it supports only non-dilated im2col currently
  const bool is_hybrid_non_dilated = is_hybrid && need_non_dilated_im2col;
  const bool is_quantized =
      input->type == kTfLiteUInt8 || input->type == kTfLiteInt8;

  switch (kernel_type) {
    case kReference:
      if (is_hybrid) {
        return true;
      } else {
        return false;
      }
    case kGenericOptimized:
    case kCblasOptimized:
      if (is_hybrid && !need_non_dilated_im2col) {
        return false;
      } else {
        return true;
      }
    case kMultithreadOptimized:
      if (is_hybrid_non_dilated || is_quantized ||
          !data->supports_multithreaded_kernel) {
        return true;
      } else {
        return false;
      }
    default:
      return false;
  }
}
// Check if im2col needs to be allocated, as some version of optimized Conv dont
// use it. If any change is supporting im2col in any of the Conv versions, then
// it should be updated here as well
Check if im2col needs to be allocated, as some version of optimized Conv dont
use it. If any change is supporting im2col in any of the Conv versions, then
it should be updated here as well
Check if im2col needs to be allocated as some version of optimized Conv dont use it . If any change is supporting im2col in any of the Conv versions then it should be updated here as well
bool IsIm2ColRequired(const TfLiteTensor* input, TfLiteConvParams* params,
                      const TfLiteTensor* filter, OpData* data, bool is_hybrid,
                      KernelType kernel_type) {
  if (data->need_hwcn_weights) return false;
  const bool need_dilated_im2col =
      params->dilation_width_factor != 1 || params->dilation_height_factor != 1;
  const bool need_non_dilated_im2col =
      params->stride_width != 1 || params->stride_height != 1 ||
      filter->dims->data[2] != 1 || filter->dims->data[1] != 1;
  const bool need_im2col = need_dilated_im2col || need_non_dilated_im2col;
  if (!need_im2col) return false;
  const bool is_hybrid_non_dilated = is_hybrid && need_non_dilated_im2col;
  const bool is_quantized =
      input->type == kTfLiteUInt8 || input->type == kTfLiteInt8;
  switch (kernel_type) {
    case kReference:
      if (is_hybrid) {
        return true;
      } else {
        return false;
      }
    case kGenericOptimized:
    case kCblasOptimized:
      if (is_hybrid && !need_non_dilated_im2col) {
        return false;
      } else {
        return true;
      }
    case kMultithreadOptimized:
      if (is_hybrid_non_dilated || is_quantized ||
          !data->supports_multithreaded_kernel) {
        return true;
      } else {
        return false;
      }
    default:
      return false;
  }
}
bool IsIm2ColRequired ( const TfLiteTensor * input , TfLiteConvParams * params , const TfLiteTensor * filter , OpData * data , bool is_hybrid , KernelType kernel_type ) { if ( data -> need_hwcn_weights ) return false ; const bool need_dilated_im2col = params -> dilation_width_factor != 1 || params -> dilation_height_factor != 1 ; const bool need_non_dilated_im2col = params -> stride_width != 1 || params -> stride_height != 1 || filter -> dims -> data [ 2 ] != 1 || filter -> dims -> data [ 1 ] != 1 ; const bool need_im2col = need_dilated_im2col || need_non_dilated_im2col ; if ( ! need_im2col ) return false ; const bool is_hybrid_non_dilated = is_hybrid && need_non_dilated_im2col ; const bool is_quantized = input -> type == kTfLiteUInt8 || input -> type == kTfLiteInt8 ; switch ( kernel_type ) { case kReference : if ( is_hybrid ) { return true ; } else { return false ; } case kGenericOptimized : case kCblasOptimized : if ( is_hybrid && ! need_non_dilated_im2col ) { return false ; } else { return true ; } case kMultithreadOptimized : if ( is_hybrid_non_dilated || is_quantized || ! data -> supports_multithreaded_kernel ) { return true ; } else { return false ; } default : return false ; } }
Check if im2col needs to be allocated, as some version of optimized Conv dont
use it.
Check if im2col needs to be allocated as some version of optimized Conv dont use it .
// If HWCN weights are required, Im2Col not required // segregate based on dilated conv & non-dialated conv // Return early as basic requirement is not met // Special case for Hybrid, as it supports only non-dilated im2col currently