| 594 | } |
| 595 | |
| 596 | TFE_Op* TFE_NewOp(TFE_Context* ctx, const char* op_or_function_name, |
| 597 | TF_Status* status) { |
| 598 | const char* name = op_or_function_name; // Shorthand |
| 599 | const tensorflow::AttrTypeMap* types; |
| 600 | bool is_function = false; |
| 601 | status->status = tensorflow::AttrTypeMapForOp(name, &types, &is_function); |
| 602 | if (!status->status.ok()) { |
| 603 | return nullptr; |
| 604 | } |
| 605 | if (!is_function) { |
| 606 | const tensorflow::OpDef* op_def; |
| 607 | status->status = tensorflow::OpDefForOp(op_or_function_name, &op_def); |
| 608 | if (!status->status.ok()) { |
| 609 | return nullptr; |
| 610 | } |
| 611 | return new TFE_Op(ctx, name, false, types, |
| 612 | new TFE_OpInferenceContext(op_def)); |
| 613 | } |
| 614 | if (!ctx->context->FindFunctionByName(name)) { |
| 615 | status->status = tensorflow::errors::NotFound( |
| 616 | "'", name, |
| 617 | "' is neither a type of a primitive operation nor a name " |
| 618 | "of a function registered in binary running on ", |
| 619 | tensorflow::port::Hostname(), |
| 620 | ". Make sure the operation or function is " |
| 621 | "registered in the binary running in this process."); |
| 622 | return nullptr; |
| 623 | } |
| 624 | return new TFE_Op(ctx, name, true, types, nullptr); |
| 625 | } |
| 626 | |
| 627 | void TFE_DeleteOp(TFE_Op* op) { delete op; } |
| 628 | |