MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / RunOperator

Method RunOperator

paddle/fluid/framework/new_executor/program_interpreter.cc:937–1196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

935}
936
937void ProgramInterpreter::RunOperator(const Instruction& instr_node) {
938 auto* op = instr_node.OpBase();
939 auto place = instr_node.DeviceContext().GetPlace();
940 Scope* local_scope = HasLocalScope() ? var_scope_.GetMutableLocalScope()
941 : var_scope_.GetMutableScope();
942 VLOG(4) << "Start run " << place << " " << op->DebugStringEx(local_scope);
943
944 if (execution_config_.used_for_inference) {
945 for (auto& hook : input_hookfuncs_) {
946 hook(op, local_scope);
947 }
948
949 if (op->Type() == "while" || op->Type() == "conditional_block") {
950 op->SetInputHooks(input_hookfuncs_);
951 op->SetOutputHooks(output_hookfuncs_);
952 auto runtime_attrs = op->RuntimeAttrs();
953 runtime_attrs.insert(std::make_pair("used_for_inference", true));
954 op->SetRuntimeAttributeMap(runtime_attrs);
955 }
956 }
957
958 auto op_with_kernel = dynamic_cast<const framework::OperatorWithKernel*>(op);
959 {
960 // If it is OperatorBase, InferShape do nothing.
961 if (op_with_kernel != nullptr) {
962 phi::RecordEvent infershape_event("infer_shape",
963 phi::TracerEventType::OperatorInner,
964 1,
965 phi::EventRole::kInnerOp);
966
967 // see OperatorWithKernel::RunImpl in operator.cc for why
968 if (!(op_with_kernel->HasAttr(kAllKernelsMustComputeRuntimeShape) &&
969 op_with_kernel->Attr<bool>(kAllKernelsMustComputeRuntimeShape))) {
970 if (instr_node.can_use_infermeta_ctx_) {
971 op_with_kernel->Info().infer_meta_(const_cast<phi::InferMetaContext*>(
972 instr_node.InnerCompatInferMetaContext()));
973 } else {
974 op_with_kernel->Info().infer_shape_(
975 instr_node.InnerInferShapeContext().get());
976 }
977 }
978 if (FLAGS_enable_host_event_recorder_hook) {
979 platform::RecordOpInfoSupplement(op->Type(),
980 op->Attrs(),
981 *(instr_node.InnerInferShapeContext()),
982 *(instr_node.InnerRuntimeContext()),
983 op->Id());
984 }
985 }
986 }
987 if (op_with_kernel != nullptr && FLAGS_new_executor_use_inplace) {
988 // TODO(xiongkun03) Does operator base support inplace ?
989 for (auto& pair : instr_node.InplaceInfo()) {
990 const auto& in = GetTensorFromVar(pair.first);
991 auto* out = GetMutableTensorFromVar(pair.second);
992 if (in.dims() == out->dims()) {
993 out->ShareBufferWith(in);
994 }

Callers

nothing calls this directly

Calls 15

hookFunction · 0.85
GetTensorFromVarFunction · 0.85
GetMutableTensorFromVarFunction · 0.85
IsCommunicationOpFunction · 0.85
GetInstanceFunction · 0.85
SaveTensorFunction · 0.85
CheckOpHasNanOrInfFunction · 0.85
PADDLE_GET_CONSTFunction · 0.85
GetMutableLocalScopeMethod · 0.80
GetMutableScopeMethod · 0.80

Tested by

no test coverage detected