File: common.h

package info (click to toggle)
pytorch 1.7.1-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 80,340 kB
  • sloc: cpp: 670,830; python: 343,991; ansic: 67,845; asm: 5,503; sh: 2,924; java: 2,888; xml: 266; makefile: 244; ruby: 148; yacc: 144; objc: 51; lex: 44
file content (73 lines) | stat: -rw-r--r-- 1,687 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once

#include <exception>

#include "caffe2/core/blob.h"

#include <gloo/config.h>
#include <gloo/context.h>
#include <gloo/transport/device.h>

namespace caffe2 {
namespace gloo {

CAFFE2_API void signalFailure(Blob* status_blob, std::exception& exception);

struct createDeviceAttr {
    // "tcp" or "ibverbs"
    std::string transport;

    // E.g. "eth0" (tcp), or "mlx5_0" (ibverbs).
    // This may be empty to make Gloo figure it out.
    std::string interface;
};

CAFFE2_API std::shared_ptr<::gloo::transport::Device> createDevice(
    const createDeviceAttr attr);

// Captures the parameters passed to Gloo.
struct GlooParameters {
  std::shared_ptr<::gloo::Context> context;
  std::vector<const void*> inputs;
  std::vector<void*> outputs;
  size_t size;
  TypeMeta meta;

  template <typename T>
  std::vector<const T*> getInputs() {
    std::vector<const T*> result;
    result.reserve(inputs.size());
    for (auto& input : inputs) {
      result.push_back(reinterpret_cast<const T*>(input));
    }
    return result;
  }

  template <typename T>
  std::vector<T*> getOutputs() {
    std::vector<T*> result;
    result.reserve(outputs.size());
    for (auto& output : outputs) {
      result.push_back(reinterpret_cast<T*>(output));
    }
    return result;
  }

  template <typename T>
  T* getOutput() {
    return reinterpret_cast<T*>(outputs[0]);
  }

  template <typename T>
  bool IsType() const {
    return meta.Match<T>();
  }

  bool operator==(GlooParameters const& other) const {
    return context == other.context && inputs == other.inputs &&
        outputs == other.outputs && size == other.size;
  }
};

} // namespace gloo
} // namespace caffe2