/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include #include #include "glog/logging.h" #include "paddle/fluid/framework/op_proto_maker.h" #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/operator.h" #include "paddle/fluid/framework/scope.h" #include "paddle/fluid/framework/var_type_traits.h" #include "paddle/fluid/operators/collective/gen_hccl_id_op_helper.h" #include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/place.h" #include "paddle/fluid/string/split.h" namespace paddle { namespace operators { class GenHCCLIdOp : public framework::OperatorBase { public: GenHCCLIdOp(const std::string& type, const framework::VariableNameMap& inputs, const framework::VariableNameMap& outputs, const framework::AttributeMap& attrs) : OperatorBase(type, inputs, outputs, attrs) {} void RunImpl(const framework::Scope& scope, const platform::Place& dev_place) const override {} }; class GenHCCLIdOpMaker : public framework::OpProtoAndCheckerMaker { public: void Make() override { AddOutput("HCCLID", "Raw variable contains a HCCL UniqueId instaces."); AddComment(R"DOC( GenHCCLId operator For trainer 0: generate a new UniqueId and send it to all the other trainers. For trainer 1~n: start a gRPC server to get the UniqueId, once got, stop the server. )DOC"); AddAttr>( "trainers", "['trainer0_ip:port', 'trainer1_ip:port', ...] " "list of all trainer endpoints") .SetDefault({}); AddAttr("trainer_id", "(int) " "The index of the trainer in distributed training."); AddAttr("hccl_comm_num", "(int default 1) " "The number of nccl communicator num.") .SetDefault(1); AddAttr("use_hierarchical_allreduce", "(bool default false) " "Wheter to use hierarchical allreduce.") .SetDefault(false); AddAttr("hierarchical_allreduce_inter_nranks", "(int default 1) " "Wheter to use hierarchical allreduce.") .SetDefault(-1); } }; } // namespace operators } // namespace paddle namespace ops = paddle::operators; REGISTER_OPERATOR(gen_hccl_id, ops::GenHCCLIdOp, ops::GenHCCLIdOpMaker);