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

Method ParseSingleInstruction

tensorflow/compiler/xla/service/hlo_parser.cc:4289–4344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4287}
4288
4289bool HloParserImpl::ParseSingleInstruction(HloModule* module) {
4290 if (create_missing_instruction_ != nullptr || !scoped_name_tables_.empty()) {
4291 LOG(FATAL) << "Parser state is not clean. Please do not call any other "
4292 "methods before calling ParseSingleInstruction.";
4293 }
4294 HloComputation::Builder builder(module->name());
4295
4296 // The missing instruction hook we register creates the shaped instruction on
4297 // the fly as a parameter and returns it.
4298 int64 parameter_count = 0;
4299 create_missing_instruction_ =
4300 [this, &builder, &parameter_count](
4301 const std::string& name,
4302 const Shape& shape) -> std::pair<HloInstruction*, LocTy>* {
4303 std::string new_name = name.empty() ? StrCat("_", parameter_count) : name;
4304 HloInstruction* parameter = builder.AddInstruction(
4305 HloInstruction::CreateParameter(parameter_count++, shape, new_name));
4306 current_name_table()[new_name] = {parameter, lexer_.GetLoc()};
4307 return tensorflow::gtl::FindOrNull(current_name_table(), new_name);
4308 };
4309
4310 // Parse the instruction with the registered hook.
4311 Scope scope(&scoped_name_tables_);
4312 if (CanBeShape()) {
4313 // This means that the instruction's left-hand side is probably omitted,
4314 // e.g.
4315 //
4316 // f32[10] fusion(...), calls={...}
4317 if (!ParseInstructionRhs(&builder, module->name(), lexer_.GetLoc())) {
4318 return false;
4319 }
4320 } else {
4321 // This means that the instruction's left-hand side might exist, e.g.
4322 //
4323 // foo = f32[10] fusion(...), calls={...}
4324 std::string root_name;
4325 if (!ParseInstruction(&builder, &root_name)) {
4326 return false;
4327 }
4328 }
4329
4330 if (lexer_.GetKind() != TokKind::kEof) {
4331 Error(
4332 lexer_.GetLoc(),
4333 "Syntax error:\nExpected eof after parsing single instruction. Did "
4334 "you mean to write an HLO module and forget the \"HloModule\" header?");
4335 return false;
4336 }
4337
4338 module->AddEntryComputation(builder.Build());
4339 for (auto& comp : computations_) {
4340 module->AddEmbeddedComputation(std::move(comp));
4341 }
4342 TF_CHECK_OK(module->set_schedule(ScheduleFromInstructionOrder(module)));
4343 return true;
4344}
4345
4346} // namespace

Callers

nothing calls this directly

Calls 13

FindOrNullFunction · 0.85
GetLocMethod · 0.80
GetKindMethod · 0.80
AddEntryComputationMethod · 0.80
set_scheduleMethod · 0.80
nameMethod · 0.65
StrCatFunction · 0.50
ErrorFunction · 0.50
emptyMethod · 0.45
AddInstructionMethod · 0.45

Tested by

no test coverage detected