nccl_tools.h 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2022 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.

#pragma once

S
ShenLiang 已提交
17
#ifdef PADDLE_WITH_CUDA
18
#include <cuda_runtime.h>
S
ShenLiang 已提交
19 20 21 22 23
#endif
#ifdef PADDLE_WITH_HIP
#include <hip/hip_runtime.h>
#endif

24 25
#include <string>

W
Wen Sun 已提交
26
#include "paddle/fluid/distributed/collective/types.h"
S
ShenLiang 已提交
27 28

#ifdef PADDLE_WITH_RCCL
29
#include "paddle/phi/backends/dynload/rccl.h"
S
ShenLiang 已提交
30
#else
31
#include "paddle/phi/backends/dynload/nccl.h"
S
ShenLiang 已提交
32 33
#endif

34 35 36
namespace paddle {
namespace distributed {

37 38 39 40 41 42 43 44 45 46
#define NCCL_CHECK(cmd)                            \
  do {                                             \
    ncclResult_t r = cmd;                          \
    if (r != ncclSuccess) {                        \
      printf("Failed, NCCL error %s:%d '%s'\n",    \
             __FILE__,                             \
             __LINE__,                             \
             phi::dynload::ncclGetErrorString(r)); \
      exit(EXIT_FAILURE);                          \
    }                                              \
47 48
  } while (0)

L
lilong12 已提交
49
ncclRedOp_t ToNCCLRedType(ReduceOp reduction);
50

L
lilong12 已提交
51 52
std::string SerializeNCCLUniqueId(const ncclUniqueId& ncclID);

53 54
}  // namespace distributed
}  // namespace paddle