tensorflow/compiler/mlir/hlo/lib/Dialect/mhlo/transforms/group_reduction_dimensions.cc
// Groups consecutive dimensions of a reduction argument by their kind, i.e. if
// they are reduction or parallel dimensions. Dimensions of size 1 can be
// considered as any kind.
Groups consecutive dimensions of a reduction argument by their kind, i.e. if
they are reduction or parallel dimensions. Dimensions of size 1 can be
considered as any kind.
Groups consecutive dimensions of a reduction argument by their kind i . e . if they are reduction or parallel dimensions . Dimensions of size 1 can be considered as any kind .
void GroupDimensions(RankedTensorType arg_ty,
                     SmallVector<int64_t> ordered_reduction_dims,
                     SmallVector<DimensionGroup>& groups) {
  int64_t arg_rank = arg_ty.getRank();
  int64_t num_reduction_dims = ordered_reduction_dims.size();
  int64_t j = 0;
  for (int64_t i = 0; i < arg_rank; ++i) {
    bool is_declared_as_reduction_dim = false;
    if (j < num_reduction_dims && i == ordered_reduction_dims[j]) {
      is_declared_as_reduction_dim = true;
      j++;
    }
    DimensionKind kind = is_declared_as_reduction_dim
                             ? DimensionKind::kReduction
                             : DimensionKind::kParallel;
    if (arg_ty.getDimSize(i) == 1) kind = DimensionKind::kDegenerate;
    if (groups.empty() || (groups.back().kind != kind &&
                           groups.back().kind != DimensionKind::kDegenerate &&
                           kind != DimensionKind::kDegenerate)) {
      groups.push_back({kind, i, i});
    }
    if (groups.back().kind == DimensionKind::kDegenerate)
      groups.back().kind = kind;
    groups.back().end++;
  }
}
void GroupDimensions ( RankedTensorType arg_ty , SmallVector < int64_t > ordered_reduction_dims , SmallVector < DimensionGroup > & groups ) { int64_t arg_rank = arg_ty . getRank ( ) ; int64_t num_reduction_dims = ordered_reduction_dims . size ( ) ; int64_t j = 0 ; for ( int64_t i = 0 ; i < arg_rank ; ++ i ) { bool is_declared_as_reduction_dim = false ; if ( j < num_reduction_dims && i == ordered_reduction_dims [ j ] ) { is_declared_as_reduction_dim = true ; j ++ ; } DimensionKind kind = is_declared_as_reduction_dim ? DimensionKind :: kReduction : DimensionKind :: kParallel ; if ( arg_ty . getDimSize ( i ) == 1 ) kind = DimensionKind :: kDegenerate ; if ( groups . empty ( ) || ( groups . back ( ) . kind != kind && groups . back ( ) . kind != DimensionKind :: kDegenerate && kind != DimensionKind :: kDegenerate ) ) { groups . push_back ( { kind , i , i } ) ; } if ( groups . back ( ) . kind == DimensionKind :: kDegenerate ) groups . back ( ) . kind = kind ; groups . back ( ) . end ++ ; } }
Groups consecutive dimensions of a reduction argument by their kind, i.e.
Groups consecutive dimensions of a reduction argument by their kind i . e .
// Check if the i-th dimension is one of the declared reduction dimensions. // Use the declared dimension kind unless the dimension is of extent 1, in // which case we can consider it either kind. We exploit this to form // maximal dimension groups. // Start a new dimension group if the dimenion kind conflicts with the // trailing kind. // Include dimension in trailing group and concretize dimension kind if // necessary.