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

Method ComputeConstantGraph

tensorflow/compiler/xla/service/service.cc:1094–1138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1092}
1093
1094Status Service::ComputeConstantGraph(const ComputeConstantGraphRequest* arg,
1095 ComputeConstantResponse* result) {
1096 if (!arg->has_computation()) {
1097 return InvalidArgument("computations may not be empty");
1098 }
1099 if (!arg->computation().has_host_program_shape()) {
1100 return InvalidArgument("program shape may not be empty");
1101 }
1102 if (arg->computation().host_program_shape().parameters_size() != 0) {
1103 return InvalidArgument(
1104 "constant computation may not depend on any parameters.");
1105 }
1106
1107 ProgramShape program_shape(arg->computation().host_program_shape());
1108 TF_DCHECK_OK(ShapeUtil::ValidateShape(program_shape.result()));
1109 absl::optional<Layout> output_layout;
1110 if (arg->has_output_layout()) {
1111 output_layout = Layout::CreateFromProto(arg->output_layout());
1112 TF_RETURN_IF_ERROR(LayoutUtil::ValidateLayoutForShape(
1113 *output_layout, program_shape.result()));
1114 }
1115
1116 HloModuleConfig config(program_shape);
1117
1118 TF_ASSIGN_OR_RETURN(std::unique_ptr<HloModule> module,
1119 CreateModuleFromProto(arg->computation(), config));
1120
1121 TF_ASSIGN_OR_RETURN(DynamicDimensionInference dynamic_dimension_inference,
1122 DynamicDimensionInference::Run(module.get()));
1123
1124 HloEvaluator evaluator;
1125 evaluator.set_dynamic_dimension_inference(&dynamic_dimension_inference);
1126 TF_ASSIGN_OR_RETURN(auto result_literal, evaluator.Evaluate(*module, {}));
1127
1128 // Since the result layout is non-effective to the Evaluator results, explicit
1129 // relayout here.
1130 //
1131 // TODO(b/77824332): Make HloEvaluator take care of the re-layout.
1132 if (output_layout.has_value()) {
1133 result_literal = result_literal.Relayout(*output_layout);
1134 }
1135 *result->mutable_literal() = result_literal.ToProto();
1136
1137 return Status::OK();
1138}
1139
1140Status Service::GetShape(const GetShapeRequest* arg, GetShapeResponse* result) {
1141 TF_ASSIGN_OR_RETURN(const ShapedBuffer* buffer,

Callers

nothing calls this directly

Calls 11

InvalidArgumentFunction · 0.85
ValidateShapeFunction · 0.85
CreateModuleFromProtoFunction · 0.85
parameters_sizeMethod · 0.80
RelayoutMethod · 0.80
TF_ASSIGN_OR_RETURNFunction · 0.70
computationMethod · 0.45
resultMethod · 0.45
has_valueMethod · 0.45
ToProtoMethod · 0.45

Tested by

no test coverage detected