3 #include <ATen/core/ATenGeneral.h> 4 #include <c10/core/Allocator.h> 5 #include <c10/util/Deprecated.h> 6 #include <ATen/core/Generator.h> 7 #include <c10/core/Layout.h> 8 #include <c10/core/Scalar.h> 9 #include <c10/core/ScalarType.h> 10 #include <ATen/core/SparseTensorRef.h> 11 #include <c10/util/ArrayRef.h> 12 #include <c10/util/Half.h> 13 #include <c10/core/TensorTypeIdRegistration.h> 14 #include <ATen/core/Reduction.h> 15 #include <c10/core/TensorOptions.h> 17 #include <c10/util/Optional.h> 39 using TensorList = ArrayRef<Tensor>;
44 static inline void noop_deleter(
void*) {}
56 struct CAFFE2_API Type {
57 explicit Type(TensorTypeId type_id,
bool is_variable,
bool is_undefined)
58 : type_id_(type_id), is_variable_(is_variable), is_undefined_(is_undefined) {}
61 virtual ScalarType scalarType()
const = 0;
63 virtual Backend backend()
const = 0;
64 Layout
layout() const noexcept {
return layout_from_backend(backend()); }
65 virtual bool is_cuda()
const = 0;
66 virtual bool is_hip()
const = 0;
67 virtual bool is_sparse()
const = 0;
68 virtual bool is_distributed()
const = 0;
69 bool is_variable() const noexcept {
return is_variable_; }
70 bool is_undefined() const noexcept {
return is_undefined_; }
71 virtual Allocator * allocator()
const = 0;
72 virtual Device getDeviceFromPtr(
void * data)
const = 0;
73 virtual Storage storageFromBlob(
void * data, int64_t size,
const std::function<
void(
void*)> & deleter=noop_deleter)
const = 0;
74 virtual Storage storageWithAllocator(int64_t size, Allocator* allocator)
const = 0;
75 virtual std::unique_ptr<Generator> generator()
const = 0;
76 virtual Tensor unsafeTensorFromTH(
void * th_pointer,
bool retain)
const = 0;
77 virtual Storage unsafeStorageFromTH(
void * th_pointer,
bool retain)
const = 0;
78 virtual const char * toString()
const = 0;
79 virtual Type & toBackend(
Backend b)
const = 0;
80 virtual Type & toScalarType(ScalarType s)
const = 0;
81 Type & toSparse()
const {
82 return this->toBackend(at::toSparse(this->backend()));
84 Type & toDense()
const {
85 return this->toBackend(at::toDense(this->backend()));
88 return this->toBackend(at::backendToCPU(this->backend()));
91 return this->toBackend(at::backendToCUDA(this->backend()));
94 return this->toBackend(at::backendToHIP(this->backend()));
98 virtual TypeID ID()
const = 0;
101 TensorTypeId type_id()
const {
return type_id_; }
104 DeviceType device_type()
const {
105 return backendToDeviceType(backend());
110 bool non_blocking =
false,
112 virtual Tensor & copy_(
Tensor &
self,
const Tensor & src,
bool non_blocking=
false)
const = 0;
114 virtual void backward(
118 bool create_graph)
const = 0;
119 virtual void set_data(
Tensor &
self,
Tensor new_data)
const = 0;
121 virtual Tensor tensorFromBlob(
void * data, IntArrayRef sizes,
const std::function<
void(
void*)> & deleter=noop_deleter)
const = 0;
122 virtual Tensor tensorFromBlob(
void * data, IntArrayRef sizes, IntArrayRef strides,
const std::function<
void(
void*)> & deleter=noop_deleter)
const = 0;
123 virtual Tensor tensorWithAllocator(IntArrayRef sizes, Allocator* allocator)
const = 0;
124 virtual Tensor tensorWithAllocator(IntArrayRef sizes, IntArrayRef strides, Allocator* allocator)
const = 0;
126 bool operator==(
const Type& other)
const {
127 return this == &other;
129 bool operator!=(
const Type& other)
const {
130 return this != &other;
138 .is_variable(is_variable());
144 if (!device_opt.has_value()) {
148 AT_ASSERT(device.
type() == device_type());
149 return options(device.
index());
159 ${pure_virtual_type_method_declarations}
168 #include <ATen/core/Tensor.h> TensorOptions device_index(int16_t device_index)
Convenience function that returns a TensorOptions object with the device set to CUDA and the device_i...
TensorOptions device(Device device)
Convenience function that returns a TensorOptions object with the device set to the given one...
TensorOptions options(int16_t device_index=-1) const
Constructs the TensorOptions from a type and a device_index.
Represents a a compute device on which a tensor is located.
Backend
This legacy enum class defines the set of backends supported by old school, code generated Type-based...
Dynamic type ID of a Tensor argument.
TensorOptions(T &&device)
A class to encapsulate construction axes of an Tensor.
TensorOptions layout(Layout layout)
Convenience function that returns a TensorOptions object with the layout set to the given one...
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
Flush-To-Zero and Denormals-Are-Zero mode.
DeviceIndex index() const noexcept
Returns the optional index.
TensorOptions options(c10::optional< Device > device_opt) const
Constructs the TensorOptions from a type and a Device.
DeviceType type() const noexcept
Returns the type of device this is.