3 #include <c10/core/StorageImpl.h> 18 : storage_impl_(c10::make_intrusive<StorageImpl>(
33 : storage_impl_(c10::make_intrusive<StorageImpl>(
44 return Storage(c10::make_intrusive<StorageImpl>(
48 GetAllocator(device.
type()),
53 inline bool IsType()
const {
54 return storage_impl_->IsType<
T>();
58 T* data()
const {
return storage_impl_->data<
T>(); }
61 T* unsafe_data()
const {
return storage_impl_->unsafe_data<
T>(); }
63 size_t elementSize()
const {
64 return storage_impl_->itemsize();
67 inline size_t itemsize()
const {
68 return storage_impl_->itemsize();
71 ptrdiff_t size()
const {
72 return storage_impl_->numel();
75 int64_t numel()
const {
76 return storage_impl_->numel();
80 void set_numel(int64_t numel)
const {
81 storage_impl_.get()->set_numel(numel);
84 bool resizable()
const {
85 return storage_impl_->resizable();
88 size_t capacity()
const {
89 return storage_impl_->capacity();
94 return storage_impl_.get()->data();
98 return storage_impl_->
dtype();
102 return storage_impl_->data_ptr();
106 return storage_impl_->data_ptr();
111 return storage_impl_.get()->set_data_ptr(std::move(data_ptr));
115 storage_impl_.get()->set_dtype(data_type);
118 DeviceType device_type()
const {
119 return storage_impl_->device_type();
123 return storage_impl_.get()->allocator();
127 return storage_impl_->
device();
131 return storage_impl_.release();
134 StorageImpl* unsafeGetStorageImpl()
const noexcept {
135 return storage_impl_.get();
138 operator bool()
const {
139 return storage_impl_;
142 size_t use_count()
const {
143 return storage_impl_.use_count();
146 inline bool unique()
const {
147 return storage_impl_.unique();
150 bool is_alias_of(
const Storage& other)
const {
151 return storage_impl_ == other.storage_impl_;
154 void UniqueStorageShareExternalPointer(
158 DeleterFnPtr d =
nullptr) {
159 if (!storage_impl_.unique()) {
161 "UniqueStorageShareExternalPointer can only be called when use_count == 1");
163 storage_impl_->UniqueStorageShareExternalPointer(
164 src, data_type, capacity, d);
167 void UniqueStorageShareExternalPointer(
171 if (!storage_impl_.unique()) {
173 "UniqueStorageShareExternalPointer can only be called when use_count == 1");
175 storage_impl_->UniqueStorageShareExternalPointer(
176 std::move(data_ptr), data_type, capacity);
C10_NODISCARD TensorOptions device(c10::optional< Device > device) const noexcept
Return a copy of TensorOptions with device set to the given one, or cleared if device is nullopt...
TensorOptions device(Device device)
Convenience function that returns a TensorOptions object with the device set to the given one...
Represents a a compute device on which a tensor is located.
C10_NODISCARD TensorOptions dtype(c10::optional< caffe2::TypeMeta > dtype) const noexcept
Return a copy of TensorOptions with dtype set to the given one.
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
DeviceType type() const noexcept
Returns the type of device this is.
TensorOptions dtype(caffe2::TypeMeta dtype)
Convenience function that returns a TensorOptions object with the dtype set to the given one...