File: offline_tensor.h

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 (53 lines) | stat: -rw-r--r-- 1,645 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 TORCH_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