File: helper.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 (60 lines) | stat: -rw-r--r-- 1,502 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
#include "caffe2/onnx/helper.h"

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

namespace caffe2 {
namespace onnx {

std::string DummyName::NewDummyName() {
  while (true) {
    const std::string name = c10::str("OC2_DUMMY_", counter_++);
    auto ret = used_names_.insert(name);
    if (ret.second) {
      // NOLINTNEXTLINE(performance-no-automatic-move)
      return name;
    }
  }
}

void DummyName::Reset(const std::unordered_set<std::string>& used_names) {
  used_names_ = used_names;
  counter_ = 0;
}

::ONNX_NAMESPACE::TypeProto ExtraTypeProto(
    const ::ONNX_NAMESPACE::TensorProto& tensor) {
  ::ONNX_NAMESPACE::TypeProto t;
  auto* tensor_type = t.mutable_tensor_type();
  tensor_type->set_elem_type(tensor.data_type());
  auto* shape = tensor_type->mutable_shape();
  for (const auto d : tensor.dims()) {
    shape->add_dim()->set_dim_value(d);
  }
  return t;
}

NodeProto MakeNode(
    const std::string& type,
    const std::vector<std::string>& inputs,
    const std::vector<std::string>& outputs,
    const std::vector<AttributeProto>& attributes,
    const std::string& name) {
  NodeProto node;
  if (!name.empty()) {
    node.set_name(name);
  }
  node.set_op_type(type);
  for (const auto& input : inputs) {
    node.add_input(input);
  }
  for (const auto& output : outputs) {
    node.add_output(output);
  }
  for (const auto& attr : attributes) {
    node.add_attribute()->CopyFrom(attr);
  }
  return node;
}
} // namespace onnx
} // namespace caffe2