Like Session::Run(), but uses the Make/Run/ReleaseCallable() API to avoid leaving behind non-GC'ed state. Detailed motivation behind this approach, from ashankar@: Each call to Session::Run() that identifies a new subgraph (based on feeds and fetches) creates some datastructures that live as long as the session (the partitioned graph, associated executors etc.). A pathological case of this woul
| 191 | // |
| 192 | // However, the resource manager state remains. |
| 193 | Status RunOnce(const RunOptions& run_options, |
| 194 | const std::vector<std::pair<string, Tensor>>& inputs, |
| 195 | const std::vector<string>& output_tensor_names, |
| 196 | const std::vector<string>& target_node_names, |
| 197 | std::vector<Tensor>* outputs, RunMetadata* run_metadata, |
| 198 | Session* session) { |
| 199 | CallableOptions callable_options; |
| 200 | std::vector<Tensor> feed_tensors; |
| 201 | *callable_options.mutable_run_options() = run_options; |
| 202 | for (const auto& input : inputs) { |
| 203 | const string& name = input.first; |
| 204 | const Tensor& tensor = input.second; |
| 205 | callable_options.add_feed(name); |
| 206 | feed_tensors.push_back(tensor); |
| 207 | } |
| 208 | for (const string& output_tensor_name : output_tensor_names) { |
| 209 | callable_options.add_fetch(output_tensor_name); |
| 210 | } |
| 211 | for (const string& target_node_name : target_node_names) { |
| 212 | callable_options.add_target(target_node_name); |
| 213 | } |
| 214 | |
| 215 | Session::CallableHandle callable_handle; |
| 216 | TF_RETURN_IF_ERROR(session->MakeCallable(callable_options, &callable_handle)); |
| 217 | const Status run_status = session->RunCallable(callable_handle, feed_tensors, |
| 218 | outputs, run_metadata); |
| 219 | // Be sure to call ReleaseCallable() regardless of the outcome of |
| 220 | // RunCallable(). |
| 221 | session->ReleaseCallable(callable_handle).IgnoreError(); |
| 222 | return run_status; |
| 223 | } |
| 224 | |
| 225 | // RunInitOp will return OK if the initialization op was run successfully. |
| 226 | // An empty init_op_name indicates that there are no init ops to run. |
no test coverage detected