MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BuildConstOp

Function BuildConstOp

tensorflow/compiler/mlir/lite/flatbuffer_import.cc:462–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462StatusOr<Operation*> BuildConstOp(const tflite::TensorT& tensor,
463 const std::vector<uint8_t>& buffer,
464 OpBuilder builder, Location loc) {
465 TF_ASSIGN_OR_RETURN(auto type, GetTensorType(tensor, builder,
466 /*shapeless_are_scalars=*/true,
467 /*is_constant=*/true));
468 auto shaped_type = type.dyn_cast<mlir::RankedTensorType>();
469 if (!shaped_type) {
470 return errors::Internal("Constant doesn't have a shape");
471 }
472
473 auto elem_type = shaped_type.getElementType();
474
475 mlir::ElementsAttr value;
476 if (auto float_type = elem_type.dyn_cast<mlir::FloatType>()) {
477 TF_ASSIGN_OR_RETURN(value,
478 ConvertFloatBuffer(shaped_type, float_type, buffer));
479 } else if (elem_type.isa<mlir::IntegerType>() ||
480 elem_type.isa<QuantizedType>()) {
481 TF_ASSIGN_OR_RETURN(value,
482 ConvertIntBuffer(shaped_type, elem_type, buffer));
483 } else if (elem_type.isa<mlir::ComplexType>() ||
484 elem_type.isa<mlir::TF::TensorFlowType>()) {
485 auto dialect = elem_type.getContext()->getRegisteredDialect("tf");
486 tensorflow::TensorProto repr = ConvertTfliteConstTensor(tensor, buffer);
487 std::string mangled = tensorflow::mangling_util::MangleTensor(repr);
488
489 value = mlir::OpaqueElementsAttr::get(dialect, shaped_type, mangled);
490 } else {
491 return errors::Unimplemented("Constant of unsupported type");
492 }
493
494 if (IsQuantized(tensor)) {
495 auto op = builder.create<tfl::QConstOp>(
496 loc, mlir::TypeAttr::get(shaped_type), value);
497 return op.getOperation();
498 }
499 auto op = builder.create<tfl::ConstOp>(loc, value);
500 return op.getOperation();
501}
502
503llvm::SmallVector<mlir::NamedAttribute, 4> ConvertSubgraphIdxsToFunctionAttrs(
504 tflite::BuiltinOptionsUnion options,

Callers 1

ConvertSubgraphFunction · 0.85

Calls 10

InternalFunction · 0.85
ConvertFloatBufferFunction · 0.85
ConvertIntBufferFunction · 0.85
ConvertTfliteConstTensorFunction · 0.85
UnimplementedFunction · 0.85
getContextMethod · 0.80
IsQuantizedFunction · 0.70
TF_ASSIGN_OR_RETURNFunction · 0.50
MangleTensorFunction · 0.50
getFunction · 0.50

Tested by

no test coverage detected