tensorflow/compiler/mlir/tensorflow/transforms/tpu_space_to_depth_pass.cc
// Adds padding for convolution filter for space to depth transform.
Adds padding for convolution filter for space to depth transform.
Adds padding for convolution filter for space to depth transform .
TF::PadOp GetPadOpForConv2DFilter(ArrayRef<int64_t> filter_shape, Value filter,
                                  OpBuilder* builder, int32_t pad_h,
                                  int32_t pad_w) {
  SmallVector<int32_t, 8> values = {pad_h, 0, pad_w, 0, 0, 0, 0, 0};
  auto padding_type =
      RankedTensorType::get({4, 2}, builder->getIntegerType(32));
  auto paddings = DenseIntElementsAttr::get(padding_type, values);
  auto paddings_value = builder->create<TF::ConstOp>(filter.getLoc(), paddings);
  std::vector<int64_t> pad_shape = {filter_shape[0] + pad_h,
                                    filter_shape[1] + pad_w, filter_shape[2],
                                    filter_shape[3]};
  SmallVector<int64_t, 4> expand_shape(pad_shape.begin(), pad_shape.end());
  auto expand_result_type =
      RankedTensorType::get(expand_shape, getElementTypeOrSelf(filter));
  return builder->create<TF::PadOp>(filter.getLoc(), expand_result_type, filter,
                                    paddings_value);
}
TF :: PadOp GetPadOpForConv2DFilter ( ArrayRef < int64_t > filter_shape , Value filter , OpBuilder * builder , int32_t pad_h , int32_t pad_w ) { SmallVector < int32_t , 8 > values = { pad_h , 0 , pad_w , 0 , 0 , 0 , 0 , 0 } ; auto padding_type = RankedTensorType :: get ( { 4 , 2 } , builder -> getIntegerType ( 32 ) ) ; auto paddings = DenseIntElementsAttr :: get ( padding_type , values ) ; auto paddings_value = builder -> create < TF :: ConstOp > ( filter . getLoc ( ) , paddings ) ; std :: vector < int64_t > pad_shape = { filter_shape [ 0 ] + pad_h , filter_shape [ 1 ] + pad_w , filter_shape [ 2 ] , filter_shape [ 3 ] } ; SmallVector < int64_t , 4 > expand_shape ( pad_shape . begin ( ) , pad_shape . end ( ) ) ; auto expand_result_type = RankedTensorType :: get ( expand_shape , getElementTypeOrSelf ( filter ) ) ; return builder -> create < TF :: PadOp > ( filter . getLoc ( ) , expand_result_type , filter , paddings_value ) ; }
Adds padding for convolution filter for space to depth transform.
Adds padding for convolution filter for space to depth transform .