xref: /aosp_15_r20/external/pytorch/c10/core/UndefinedTensorImpl.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 #include <c10/core/MemoryFormat.h>
4 #include <c10/core/SymIntArrayRef.h>
5 #include <c10/core/TensorImpl.h>
6 #include <c10/macros/Export.h>
7 #include <c10/util/ArrayRef.h>
8 #include <cstdint>
9 
10 namespace c10 {
11 
12 struct C10_API UndefinedTensorImpl final : public TensorImpl {
13  public:
14   // Without this, we get:
15   //  error: identifier "at::UndefinedTensorImpl::_singleton" is undefined in
16   //  device code
17   // (ostensibly because the constexpr tricks MSVC into trying to compile this
18   // function for device as well).
19 #ifdef _WIN32
singletonfinal20   static inline TensorImpl* singleton() {
21     return &getInstance();
22   }
23 #else
24   static constexpr inline TensorImpl* singleton() {
25     return &_singleton;
26   }
27 #endif
28 
29 #ifdef DEBUG
30   bool has_storage() const override;
31 #endif
32   void set_storage_offset(int64_t offset) override;
33 
34  protected:
35   bool is_contiguous_custom(MemoryFormat format) const override;
36   IntArrayRef strides_custom() const override;
37   SymIntArrayRef sym_strides_custom() const override;
38 
39  private:
40   UndefinedTensorImpl();
41 #ifdef _WIN32
42   static UndefinedTensorImpl& getInstance();
43 #else
44   static UndefinedTensorImpl _singleton;
45 #endif
46   const char* tensorimpl_type_name() const override;
47 };
48 
49 } // namespace c10
50