File: common.cc

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (48 lines) | stat: -rw-r--r-- 1,367 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "caffe2/contrib/gloo/common.h"

#include "caffe2/core/logging.h"
#include "caffe2/core/tensor.h"

#include <gloo/transport/tcp/device.h>
#if defined(GLOO_USE_IBVERBS) && GLOO_USE_IBVERBS
#include <gloo/transport/ibverbs/device.h>
#endif

namespace caffe2 {
namespace gloo {

void signalFailure(Blob* status_blob, std::exception& /* unused */) {
  auto* res = BlobGetMutableTensor(status_blob, CPU);
  res->Resize(1);
  res->template mutable_data<int32_t>()[0] = 1;
}

std::shared_ptr<::gloo::transport::Device> createDevice(
    const createDeviceAttr attr) {
  if (attr.transport == "tcp") {
    ::gloo::transport::tcp::attr tcpAttr;
    if (attr.interface.size() > 0) {
      tcpAttr.iface = attr.interface;
    }
    return ::gloo::transport::tcp::CreateDevice(tcpAttr);
  } else if (attr.transport == "ibverbs") {
#if defined(GLOO_USE_IBVERBS) && GLOO_USE_IBVERBS
    ::gloo::transport::ibverbs::attr ibverbsAttr;
    ibverbsAttr.port = 1;
    ibverbsAttr.index = 0;
    if (attr.interface.size() > 0) {
      ibverbsAttr.name = attr.interface;
    }
    return ::gloo::transport::ibverbs::CreateDevice(ibverbsAttr);
#else
    CAFFE_THROW(
      "Gloo was not compiled with ibverbs support. ",
      "Please recompile with -DUSE_IBVERBS=1.");
#endif
  }

  CAFFE_THROW("Invalid transport: ", attr.transport);
}

} // namespace gloo
} // namespace caffe2