tensorflow/compiler/mlir/xla/transforms/prepare_for_export.cc
// Materializes some splat before export because it may be more efficient in
// HLOInstruction.
Materializes some splat before export because it may be more efficient in
HLOInstruction.
Materializes some splat before export because it may be more efficient in HLOInstruction .
void prepareConstantOp(Operation *op, SplatElementsAttr attr) {
  if (attr.getNumElements() < 32) return;
  ShapedType return_type = op->getResultTypes().front().cast<ShapedType>();
  ImplicitLocOpBuilder b(op->getLoc(), op);
  ConstOp cst;
  if (auto complexTy = return_type.getElementType().dyn_cast<ComplexType>()) {
    auto tensorType = RankedTensorType::get({}, return_type.getElementType());
    assert(complexTy.getElementType().isa<FloatType>() &&
           "unexpected int complex in MHLO");
    auto complexVal = attr.getSplatValue<std::complex<APFloat>>();
    cst = b.create<ConstOp>(DenseElementsAttr::get(tensorType, complexVal));
  } else {
    cst = b.create<ConstOp>(attr.getSplatValue<Attribute>());
  }
  auto broadcast =
      b.create<BroadcastInDimOp>(return_type, cst, b.getI64TensorAttr({}));
  op->replaceAllUsesWith(broadcast);
  op->erase();
}
void prepareConstantOp ( Operation * op , SplatElementsAttr attr ) { if ( attr . getNumElements ( ) < 32 ) return ; ShapedType return_type = op -> getResultTypes ( ) . front ( ) . cast < ShapedType > ( ) ; ImplicitLocOpBuilder b ( op -> getLoc ( ) , op ) ; ConstOp cst ; if ( auto complexTy = return_type . getElementType ( ) . dyn_cast < ComplexType > ( ) ) { auto tensorType = RankedTensorType :: get ( { } , return_type . getElementType ( ) ) ; assert ( complexTy . getElementType ( ) . isa < FloatType > ( ) && " " ) ; auto complexVal = attr . getSplatValue < std :: complex < APFloat > > ( ) ; cst = b . create < ConstOp > ( DenseElementsAttr :: get ( tensorType , complexVal ) ) ; } else { cst = b . create < ConstOp > ( attr . getSplatValue < Attribute > ( ) ) ; } auto broadcast = b . create < BroadcastInDimOp > ( return_type , cst , b . getI64TensorAttr ( { } ) ) ; op -> replaceAllUsesWith ( broadcast ) ; op -> erase ( ) ; }
Materializes some splat before export because it may be more efficient in
HLOInstruction.
Materializes some splat before export because it may be more efficient in HLOInstruction .
// Arbitrarialy chosen "small" number. This could be chosen based on the // proto size too.