1 #ifndef CAFFE2_OPERATORS_DATASET_OPS_H_ 2 #define CAFFE2_OPERATORS_DATASET_OPS_H_ 8 #include "caffe2/core/blob.h" 9 #include "caffe2/core/blob_serialization.h" 10 #include "caffe2/core/tensor.h" 13 namespace dataset_ops {
16 using TLength = int32_t;
18 using TOffset = int64_t;
28 int lengthFieldId = -1;
32 explicit TreeIterator(
const std::vector<std::string>& fields);
35 const std::vector<const TLength*>& lengths,
36 std::vector<TOffset>& offsets,
37 std::vector<TOffset>& sizes,
38 std::vector<TOffset>& limits,
42 int numLengthFields()
const {
43 return lengthFieldIds_.size();
47 int numOffsetFields()
const {
48 return numLengthFields() + 1;
53 return (desc.lengthFieldId == -1)
55 : &fields_.at(lengthFieldIds_.at(desc.lengthFieldId));
60 const FieldDesc& lengthField(
int lengthFieldId) {
61 return fields_.at(lengthFieldIds_.at(lengthFieldId));
65 int offsetFieldIdFor(
const FieldDesc& fieldDesc) {
66 return fieldDesc.lengthFieldId + 1;
70 const std::vector<FieldDesc>& fields() {
74 const std::vector<int>& lengthFieldIds()
const {
75 return lengthFieldIds_;
80 std::vector<FieldDesc> fields_;
82 std::vector<int> lengthFieldIds_;
88 std::vector<TOffset> offsets;
102 inline TOffset size()
const {
103 return limits_.at(0);
109 inline const TensorCPU& input(int32_t idx)
const {
115 return cursor_.it.fields().at(idx);
118 inline int lengthIdx(
int fieldId)
const {
119 return field(fieldId).lengthFieldId + 1;
122 inline TOffset offset(
int fieldId)
const {
123 return prevOffsets_[lengthIdx(fieldId)];
126 std::vector<int64_t> fieldDim(
int fieldId)
const;
128 void* fieldPtr(
int fieldId)
const;
135 : walker_(walker), fieldId_(fieldId) {}
137 inline std::vector<int64_t> dim()
const {
138 return walker_.fieldDim(fieldId_);
141 inline int64_t size()
const {
143 for (
const auto d : dim()) {
149 inline const TypeMeta& meta()
const {
150 return walker_.input(fieldId_).dtype();
153 inline void* ptr()
const {
154 return walker_.fieldPtr(fieldId_);
157 int fieldId()
const {
161 inline TOffset offset()
const {
162 return walker_.offset(fieldId_);
172 inline const std::vector<Field>& fields()
const {
177 void gatherLengthData();
179 void gatherSizeLimits();
181 const vector<const Blob*>& inputs_;
183 std::vector<Field> fields_;
185 std::vector<const TLength*> lengths_;
186 std::vector<TOffset> limits_;
187 std::vector<TOffset> sizes_;
188 std::vector<TOffset> offsets_;
189 std::vector<TOffset> prevOffsets_;
192 using SharedTensorVectorPtr = std::shared_ptr<std::vector<TensorCPU>>;
194 using TensorVectorPtr = std::unique_ptr<std::vector<Tensor>>;
202 BlobSerializerBase::SerializationAcceptor acceptor)
override;
207 void Deserialize(
const BlobProto& proto,
Blob* blob)
override;
213 #endif // CAFFE2_OPERATORS_DATASET_OPS_H_ Blob is a general container that hosts a typed pointer.
BlobDeserializerBase is an abstract class that deserializes a blob from a BlobProto or a TensorProto...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Simple wrapper class allowing an easy traversal of the tensors representing the hirerarchical structu...
BlobSerializerBase is an abstract class that serializes a blob to a string.
Provides functionality to iterate across a list of tensors where some of those tensors represent leng...