|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "caffe2/core/common.h" |
| 4 | +#include "caffe2/core/logging.h" |
| 5 | +#include "caffe2/proto/caffe2_pb.h" |
| 6 | +#include "nomnigraph/Representations/NeuralNet.h" |
| 7 | + |
| 8 | +namespace caffe2 { |
| 9 | + |
| 10 | +class Caffe2Annotation : public nom::repr::Annotation { |
| 11 | + public: |
| 12 | + Caffe2Annotation() : Annotation(AnnotationKind::Caffe2) {} |
| 13 | + Caffe2Annotation(std::string device) |
| 14 | + : Annotation(AnnotationKind::Caffe2), Device(device) {} |
| 15 | + virtual ~Caffe2Annotation() {} |
| 16 | + |
| 17 | + void setOperatorDef(const caffe2::OperatorDef& opDef); |
| 18 | + bool hasOperatorDef() const; |
| 19 | + const caffe2::OperatorDef& getOperatorDef() const; |
| 20 | + caffe2::OperatorDef* getMutableOperatorDef(); |
| 21 | + |
| 22 | + // Distributed annotations |
| 23 | + void setDevice(std::string device); |
| 24 | + const std::string getDevice() const; |
| 25 | + void setDeviceType(int device); |
| 26 | + int getDeviceType() const; |
| 27 | + |
| 28 | + enum class ParallelizationScheme { |
| 29 | + none, |
| 30 | + split_by_batch, |
| 31 | + split_by_length, |
| 32 | + shard, |
| 33 | + shard_by_number |
| 34 | + }; |
| 35 | + void setParallelization(ParallelizationScheme, int num = -1); |
| 36 | + ParallelizationScheme getParallelizationScheme() const; |
| 37 | + int getParallelization() const; |
| 38 | + |
| 39 | + void setKeyNode(nom::repr::NNGraph::NodeRef); |
| 40 | + const nom::repr::NNGraph::NodeRef& getKeyNode() const; |
| 41 | + void setLengthNode(nom::repr::NNGraph::NodeRef); |
| 42 | + const nom::repr::NNGraph::NodeRef& getLengthNode() const; |
| 43 | + |
| 44 | + void setComponentLevels(std::vector<std::string> components); |
| 45 | + std::vector<std::string> getComponentLevels() const; |
| 46 | + |
| 47 | + static bool classof(const Annotation* A); |
| 48 | + |
| 49 | + private: |
| 50 | + std::string Device = ""; |
| 51 | + caffe2::OperatorDef OpDef; |
| 52 | + bool OpDefExists = false; |
| 53 | + |
| 54 | + // Distributed annotations |
| 55 | + int DeviceType = caffe2::DeviceTypeProto::PROTO_CPU; |
| 56 | + ParallelizationScheme parallelization_scheme_ = ParallelizationScheme::none; |
| 57 | + int parallelization_ = -1; |
| 58 | + nom::repr::NNGraph::NodeRef key_node_ = nullptr; |
| 59 | + nom::repr::NNGraph::NodeRef length_node_ = nullptr; |
| 60 | + std::vector<std::string> component_levels_; |
| 61 | +}; |
| 62 | + |
| 63 | +} // namespace caffe2 |
0 commit comments