| 194 | } |
| 195 | |
| 196 | Status GrpcSession::RunHelper( |
| 197 | const RunOptions& run_options, |
| 198 | const std::vector<std::pair<string, Tensor>>& inputs, |
| 199 | const std::vector<string>& output_tensor_names, |
| 200 | const std::vector<string>& target_node_names, std::vector<Tensor>* outputs, |
| 201 | RunMetadata* run_metadata, const string& prun_handle) { |
| 202 | // Convert to proto |
| 203 | std::unique_ptr<MutableRunStepRequestWrapper> req( |
| 204 | master_->CreateRunStepRequest()); |
| 205 | std::unique_ptr<MutableRunStepResponseWrapper> resp( |
| 206 | master_->CreateRunStepResponse()); |
| 207 | |
| 208 | *req->mutable_options() = run_options; |
| 209 | |
| 210 | if (run_options.timeout_in_ms() == 0) { |
| 211 | req->mutable_options()->set_timeout_in_ms( |
| 212 | options_.config.operation_timeout_in_ms()); |
| 213 | } |
| 214 | |
| 215 | if (!prun_handle.empty()) { |
| 216 | req->set_partial_run_handle(prun_handle); |
| 217 | } |
| 218 | |
| 219 | for (const auto& it : inputs) { |
| 220 | req->add_feed(it.first, it.second); |
| 221 | } |
| 222 | |
| 223 | // Support long error messages by storing the error code in the response body. |
| 224 | req->set_store_errors_in_response_body(true); |
| 225 | |
| 226 | // Build an index from fetch tensor name to first index in |
| 227 | // output_tensor_names. |
| 228 | std::unordered_map<string, int> output_name_to_offset; |
| 229 | for (int i = 0; i < output_tensor_names.size(); ++i) { |
| 230 | const string& name = output_tensor_names[i]; |
| 231 | if (output_name_to_offset.insert(std::make_pair(name, i)).second) { |
| 232 | req->add_fetch(name); |
| 233 | } |
| 234 | } |
| 235 | for (const string& target : target_node_names) { |
| 236 | req->add_target(target); |
| 237 | } |
| 238 | |
| 239 | CallOptions call_options; |
| 240 | call_options.SetTimeout(req->options().timeout_in_ms()); |
| 241 | TF_RETURN_IF_ERROR(RunProto(&call_options, req.get(), resp.get())); |
| 242 | |
| 243 | // Look for an extended error returned in the response body. |
| 244 | if (resp->status_code() != error::Code::OK) { |
| 245 | return Status(resp->status_code(), resp->status_error_message()); |
| 246 | } |
| 247 | |
| 248 | if (!output_tensor_names.empty()) { |
| 249 | outputs->resize(output_tensor_names.size()); |
| 250 | } |
| 251 | |
| 252 | // Convert response back to Tensors in the correct order. |
| 253 | for (size_t i = 0; i < resp->num_tensors(); ++i) { |
nothing calls this directly
no test coverage detected