You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mpi_initializer.cc 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include "device/gpu/mpi/mpi_initializer.h"
  17. #include <mpi.h>
  18. #include <pybind11/operators.h>
  19. #include <iostream>
  20. namespace mindspore {
  21. namespace device {
  22. namespace gpu {
  23. MPIInitializer::MPIInitializer() {
  24. MPI_Comm_rank(MPI_COMM_WORLD, &rank_id_);
  25. MPI_Comm_size(MPI_COMM_WORLD, &rank_size_);
  26. }
  27. MPIInitializer &MPIInitializer::GetInstance() {
  28. static MPIInitializer instance;
  29. return instance;
  30. }
  31. int MPIInitializer::get_rank_id() { return MPIInitializer::GetInstance().rank_id_; }
  32. int MPIInitializer::get_rank_size() { return MPIInitializer::GetInstance().rank_size_; }
  33. PYBIND11_MODULE(_ms_mpi, mpi_initializer) {
  34. mpi_initializer.doc() = "mindspore mpi python wrapper";
  35. mpi_initializer.def("get_rank_id", &MPIInitializer::get_rank_id, "get rank id");
  36. mpi_initializer.def("get_rank_size", &MPIInitializer::get_rank_size, "get rank size");
  37. }
  38. } // namespace gpu
  39. } // namespace device
  40. } // namespace mindspore