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.

collective_wrapper.cc 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 <mpi.h>
  17. #include <nccl.h>
  18. #include <unistd.h>
  19. #include <memory>
  20. #include <string>
  21. #include <iostream>
  22. #include "device/gpu/distribution/mpi_wrapper.h"
  23. #include "device/gpu/distribution/nccl_wrapper.h"
  24. #ifndef EXPORT_WRAPPER
  25. #define EXPORT_WRAPPER __attribute__((visibility("default")))
  26. #endif
  27. using MPIWrapper = mindspore::device::gpu::MPIWrapper;
  28. using NCCLWrapper = mindspore::device::gpu::NCCLWrapper;
  29. extern "C" EXPORT_WRAPPER void InitMPI() { MPIWrapper::instance(); }
  30. extern "C" EXPORT_WRAPPER int local_rank_id() { return MPIWrapper::instance().local_rank_id(); }
  31. extern "C" EXPORT_WRAPPER void InitNCCLComm() { NCCLWrapper::instance().InitNCCLComm(); }
  32. extern "C" EXPORT_WRAPPER ncclResult_t AllReduce(const void *input_addr, void *output_addr, size_t count,
  33. ncclDataType_t data_type, ncclRedOp_t reduce_type,
  34. cudaStream_t stream) {
  35. return NCCLWrapper::instance().AllReduce(input_addr, output_addr, count, data_type, reduce_type, stream);
  36. }
  37. extern "C" EXPORT_WRAPPER ncclResult_t AllGather(const void *input_addr, void *output_addr, size_t count,
  38. ncclDataType_t data_type, cudaStream_t stream) {
  39. return NCCLWrapper::instance().AllGather(input_addr, output_addr, count, data_type, stream);
  40. }
  41. extern "C" EXPORT_WRAPPER ncclResult_t ReduceScatter(const void *input_addr, void *output_addr, size_t count,
  42. ncclDataType_t data_type, ncclRedOp_t reduce_type,
  43. cudaStream_t stream) {
  44. return NCCLWrapper::instance().ReduceScatter(input_addr, output_addr, count, data_type, reduce_type, stream);
  45. }