chufanchen / read-paper-and-code

0 stars 0 forks source link

Convolution #176

Closed chufanchen closed 2 months ago

chufanchen commented 5 months ago

PyTorch

Memory format

at::MemoryFormat suggest_memory_format(
    bool channels_last_strides_exact_match = false) const {
  // Setting channels_last_strides_exact_match to true forces function to
  // check 0,1 - sized dimension strides.
  if (layout() == at::kStrided) {
    if (impl_->is_strides_like_channels_last()) {
      if (!channels_last_strides_exact_match ||
          get_channels_last_strides_2d(sizes()) == strides()) {
        return at::MemoryFormat::ChannelsLast;
      }
    }
    else if (impl_->is_strides_like_channels_last_3d()) {
      if (!channels_last_strides_exact_match ||
          get_channels_last_strides_3d(sizes()) == strides()) {
        return at::MemoryFormat::ChannelsLast3d;
      }
    }
  }
  return at::MemoryFormat::Contiguous;
}

Placeholder

Code shared by Conv_v7 and Conv_v8