| 44 | } |
| 45 | |
| 46 | void SetFeedVariable(Scope* scope, |
| 47 | const DenseTensor& input, |
| 48 | const std::string& var_name, |
| 49 | size_t index) { |
| 50 | // If var_name Variable is not found in GlobalScope, a new variable will |
| 51 | // be created. |
| 52 | VLOG(3) << "SetFeedVariable name=" << var_name << " index=" << index; |
| 53 | if (FLAGS_enable_pir_in_executor) { |
| 54 | // shared data with input tensor |
| 55 | auto feed_ele = scope->Var(var_name); |
| 56 | if (!feed_ele->IsType<DenseTensor>()) { |
| 57 | VLOG(3) << "Reset " << var_name << " to DenseTensor"; |
| 58 | feed_ele->Clear(); |
| 59 | } |
| 60 | auto val = feed_ele->GetMutable<DenseTensor>(); |
| 61 | val->ShareDataWith(input); |
| 62 | // set lod |
| 63 | val->set_lod(input.lod()); |
| 64 | } else { |
| 65 | Variable* g_feed_value = scope->Var(var_name); |
| 66 | auto& feed_inputs = *(g_feed_value->GetMutable<FeedList>()); |
| 67 | if (index >= feed_inputs.size()) { |
| 68 | feed_inputs.resize(index + 1); |
| 69 | } |
| 70 | // shared data with input tensor |
| 71 | auto& val = feed_inputs[index]; |
| 72 | val.ShareDataWith(input); |
| 73 | // set lod |
| 74 | val.set_lod(input.lod()); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | FetchType& GetFetchVariable(const Scope& scope, |
| 79 | const std::string& var_name, |