Caffe2 - C++ API
A deep learning, cross platform ML framework
annotations.cc
1 #include "caffe2/opt/annotations.h"
2 
3 namespace caffe2 {
4 
5 using namespace nom::repr;
6 
7 void Caffe2Annotation::setOperatorDef(const caffe2::OperatorDef& opDef) {
8  OpDef = opDef;
9  OpDefExists = true;
10 }
11 
12 bool Caffe2Annotation::hasOperatorDef() const {
13  return OpDefExists;
14 }
15 
16 const caffe2::OperatorDef& Caffe2Annotation::getOperatorDef() const {
17  CAFFE_ENFORCE(
18  OpDefExists,
19  "OperatorDef was never set. Use Caffe2Annotation::setOperatorDef.");
20  return OpDef;
21 }
22 caffe2::OperatorDef* Caffe2Annotation::getMutableOperatorDef() {
23  CAFFE_ENFORCE(
24  OpDefExists,
25  "OperatorDef was never set. Use Caffe2Annotation::setOperatorDef.");
26  return &OpDef;
27 }
28 
29 // Distributed annotations
30 void Caffe2Annotation::setDeviceOption(const caffe2::DeviceOption& devOpt) {
31  *OpDef.mutable_device_option() = devOpt;
32 }
33 
34 bool Caffe2Annotation::hasDeviceOption() const {
35  return OpDef.has_device_option();
36 }
37 
38 const caffe2::DeviceOption& Caffe2Annotation::getDeviceOption() const {
39  CAFFE_ENFORCE(
40  hasDeviceOption(),
41  "DeviceOption was never set. Use Caffe2Annotation::setDeviceOption.");
42  return OpDef.device_option();
43 }
44 caffe2::DeviceOption* Caffe2Annotation::getMutableDeviceOption() {
45  CAFFE_ENFORCE(
46  hasDeviceOption(),
47  "DeviceOption was never set. Use Caffe2Annotation::setDeviceOption.");
48  return OpDef.mutable_device_option();
49 }
50 
51 void Caffe2Annotation::setDevice(std::string device) {
52  Device = device;
53 }
54 const std::string Caffe2Annotation::getDevice() const {
55  return Device;
56 }
57 
58 void Caffe2Annotation::setDeviceType(int device) {
59  DeviceType = device;
60 }
61 int Caffe2Annotation::getDeviceType() const {
62  return DeviceType;
63 }
64 
65 void Caffe2Annotation::setParallelization(
66  Caffe2Annotation::ParallelizationScheme s,
67  int num) {
68  parallelization_scheme_ = s;
69  parallelization_ = num;
70 }
71 
72 Caffe2Annotation::ParallelizationScheme
73 Caffe2Annotation::getParallelizationScheme() const {
74  return parallelization_scheme_;
75 }
76 
77 int Caffe2Annotation::getParallelization() const {
78  return parallelization_;
79 }
80 
81 void Caffe2Annotation::setKeyNode(NNGraph::NodeRef n) {
82  key_node_ = n;
83 }
84 const NNGraph::NodeRef& Caffe2Annotation::getKeyNode() const {
85  CAFFE_ENFORCE(key_node_, "No key node has been annotated");
86  return key_node_;
87 }
88 void Caffe2Annotation::setLengthNode(NNGraph::NodeRef n) {
89  length_node_ = n;
90 }
91 const NNGraph::NodeRef& Caffe2Annotation::getLengthNode() const {
92  CAFFE_ENFORCE(length_node_, "No length node has been annotated");
93  return length_node_;
94 }
95 
96 void Caffe2Annotation::setComponentLevels(std::vector<std::string> components) {
97  component_levels_ = components;
98 }
99 std::vector<std::string> Caffe2Annotation::getComponentLevels() const {
100  return component_levels_;
101 }
102 
103 bool Caffe2Annotation::classof(const Annotation* A) {
104  return A->getKind() == AnnotationKind::Caffe2;
105 }
106 
107 } // namespace caffe2
Annotations allow for generic manipulation of neural network operations.
Definition: NeuralNet.h:44
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
does bound shape inference given a C2 net.