| 244 | class NcclReplacePass : public GraphOptimizationPass { |
| 245 | public: |
| 246 | Status Run(const GraphOptimizationPassOptions& options) override { |
| 247 | if (options.graph == nullptr) { |
| 248 | return Status::OK(); |
| 249 | } |
| 250 | Graph* graph = options.graph->get(); |
| 251 | if (graph == nullptr) { |
| 252 | return errors::Internal( |
| 253 | "NCCL replacement should happen before partitioning and a " |
| 254 | "graph should be available."); |
| 255 | } |
| 256 | // Find reduction and broadcast ops and replace them with Send/Recv ops. |
| 257 | for (Node* node : graph->op_nodes()) { |
| 258 | StringPiece type = node->type_string(); |
| 259 | if (!absl::StartsWith(type, "Nccl")) { |
| 260 | continue; |
| 261 | } |
| 262 | if (type == "NcclReduce") { |
| 263 | TF_RETURN_IF_ERROR(ReplaceReduce(graph, node)); |
| 264 | } |
| 265 | if (type == "NcclBroadcast") { |
| 266 | TF_RETURN_IF_ERROR(ReplaceBroadcast(graph, node)); |
| 267 | } |
| 268 | } |
| 269 | return Status::OK(); |
| 270 | } |
| 271 | }; |
| 272 | REGISTER_OPTIMIZATION(OptimizationPassRegistry::POST_PLACEMENT, 0, |
| 273 | NcclReplacePass); |
nothing calls this directly
no test coverage detected