File: offline_tensor.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 (53 lines) | stat: -rw-r--r-- 1,646 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
#pragma once

#include <c10/core/Storage.h>
#include "caffe2/core/operator.h"
#include "caffe2/core/tensor.h"

namespace caffe2 {

#ifndef C10_MOBILE
struct CAFFE2_API OfflineTensor {
  // A shell tensor to record shape and dtype
  Tensor shape_tensor{CPU};

  void setShapeAndType(
      const std::vector<int>& sizes,
      at::Device device,
      caffe2::TypeMeta data_type) {
    shape_tensor.unsafeGetTensorImpl()->set_storage_and_dtype(
        at::Storage::create_legacy(device), data_type);
    shape_tensor.Resize(sizes);
    CHECK(!shape_tensor.storage_initialized());
    CHECK(shape_tensor.dtype_initialized());
  }
};

class OfflineTensorShapeFunctions : public ExternalTensorFunctionsBase {
 public:
  explicit OfflineTensorShapeFunctions() : ExternalTensorFunctionsBase() {}
  ~OfflineTensorShapeFunctions() override {}
  bool isQuantized() const override {
    return false;
  }
  bool IsSameMetaType(TypeIdentifier id) override;
  void SetupExternalTensorDescriptor(
      const Blob* blob,
      std::vector<std::vector<uint64_t>>* shapes,
      std::vector<std::vector<float>>* all_scales,
      std::vector<std::vector<int32_t>>* all_offsets,
      ExternalTensorDescriptor* desc) override;
  void LoadInfoOfBlob(
      const Blob* /* unused */,
      std::vector<float>* /* unused */,
      std::vector<float>* /* unused */,
      uint32_t* /* unused */) override {}
  TypeIdentifier GetTypeMetaId() override;
  TypeMeta GetExternalTensorType(const void* c) override;
  vector<int64_t> GetExternalTensorInfo(
      const void* c,
      size_t* capacity,
      DeviceOption* device) override;
};
#endif
} // namespace caffe2