| 2193 | } |
| 2194 | |
| 2195 | Status DirectSession::CreateGraphs( |
| 2196 | const BuildGraphOptions& subgraph_options, |
| 2197 | std::unordered_map<string, std::unique_ptr<Graph>>* outputs, |
| 2198 | std::unique_ptr<FunctionLibraryDefinition>* flib_def, |
| 2199 | RunStateArgs* run_state_args, DataTypeVector* input_types, |
| 2200 | DataTypeVector* output_types, int64* collective_graph_key) { |
| 2201 | mutex_lock l(graph_state_lock_); |
| 2202 | std::unique_ptr<ClientGraph> client_graph; |
| 2203 | |
| 2204 | std::unique_ptr<GraphExecutionState> temp_exec_state_holder; |
| 2205 | GraphExecutionState* execution_state = nullptr; |
| 2206 | if (options_.config.graph_options().place_pruned_graph()) { |
| 2207 | // Because we are placing pruned graphs, we need to create a |
| 2208 | // new GraphExecutionState for every new unseen graph, |
| 2209 | // and then place it. |
| 2210 | GraphExecutionStateOptions prune_options; |
| 2211 | prune_options.device_set = &device_set_; |
| 2212 | prune_options.session_options = &options_; |
| 2213 | prune_options.stateful_placements = stateful_placements_; |
| 2214 | prune_options.session_handle = session_handle_; |
| 2215 | TF_RETURN_IF_ERROR(GraphExecutionState::MakeForPrunedGraph( |
| 2216 | *execution_state_, prune_options, subgraph_options, |
| 2217 | &temp_exec_state_holder, &client_graph)); |
| 2218 | execution_state = temp_exec_state_holder.get(); |
| 2219 | } else { |
| 2220 | execution_state = execution_state_.get(); |
| 2221 | TF_RETURN_IF_ERROR( |
| 2222 | execution_state->BuildGraph(subgraph_options, &client_graph)); |
| 2223 | } |
| 2224 | *collective_graph_key = client_graph->collective_graph_key; |
| 2225 | |
| 2226 | if (subgraph_options.callable_options.feed_size() != |
| 2227 | client_graph->feed_types.size()) { |
| 2228 | return errors::Internal( |
| 2229 | "Graph pruning failed: requested number of feed endpoints = ", |
| 2230 | subgraph_options.callable_options.feed_size(), |
| 2231 | " versus number of pruned feed endpoints = ", |
| 2232 | client_graph->feed_types.size()); |
| 2233 | } |
| 2234 | if (subgraph_options.callable_options.fetch_size() != |
| 2235 | client_graph->fetch_types.size()) { |
| 2236 | return errors::Internal( |
| 2237 | "Graph pruning failed: requested number of fetch endpoints = ", |
| 2238 | subgraph_options.callable_options.fetch_size(), |
| 2239 | " versus number of pruned fetch endpoints = ", |
| 2240 | client_graph->fetch_types.size()); |
| 2241 | } |
| 2242 | |
| 2243 | auto current_stateful_placements = execution_state->GetStatefulPlacements(); |
| 2244 | // Update our current state based on the execution_state's |
| 2245 | // placements. If there are any mismatches for a node, |
| 2246 | // we should fail, as this should never happen. |
| 2247 | for (auto placement_pair : current_stateful_placements) { |
| 2248 | const string& node_name = placement_pair.first; |
| 2249 | const string& placement = placement_pair.second; |
| 2250 | auto iter = stateful_placements_.find(node_name); |
| 2251 | if (iter == stateful_placements_.end()) { |
| 2252 | stateful_placements_.insert(std::make_pair(node_name, placement)); |
nothing calls this directly
no test coverage detected