1 /** 2 * Copyright 2019 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_GPU_DISTRIBUTION_COLLECTIVE_INIT_H_ 18 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_GPU_DISTRIBUTION_COLLECTIVE_INIT_H_ 19 20 #include <dlfcn.h> 21 #include <vector> 22 #include <string> 23 24 namespace mindspore { 25 namespace device { 26 namespace gpu { 27 using InitMPI = void (*)(); 28 using InitNCCLComm = void (*)(); 29 using GetLocalRankId = int (*)(); 30 using CreateCommGroupFunc = bool (*)(const std::string &, const std::vector<unsigned int> &); 31 using GetRankIDByGroupFunc = int (*)(const std::string &); 32 using GetGroupSizeFunc = int (*)(const std::string &); 33 using DestroyGroupFunc = bool (*)(const std::string &); 34 35 class CollectiveInitializer { 36 public: 37 CollectiveInitializer(CollectiveInitializer const &) = delete; 38 CollectiveInitializer &operator=(const CollectiveInitializer &) = delete; 39 static CollectiveInitializer &instance(); 40 bool collective_inited() const; 41 const void *collective_handle() const; 42 static void InitCollective(); 43 static void FinalizeCollective(); 44 45 private: CollectiveInitializer()46 CollectiveInitializer() : collective_inited_(false) {} 47 ~CollectiveInitializer() = default; 48 49 bool collective_inited_; 50 void *collective_handle_{nullptr}; 51 }; 52 } // namespace gpu 53 } // namespace device 54 } // namespace mindspore 55 56 #endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_GPU_DISTRIBUTION_COLLECTIVE_INIT_H_ 57