/usr/local/lib64/python3.6/site-packages/torch/include/ATen/core
NameSizeModeActions
boxing/-0755rm
dispatch/-0755rm
op_registration/-0755rm
alias_info.h29860644editdlrm
Array.h7680644editdlrm
ATenGeneral.h450644editdlrm
ATenOpList.h2460644editdlrm
aten_interned_strings.h253890644editdlrm
Backtrace.h590644editdlrm
blob.h54220644editdlrm
builtin_function.h36490644editdlrm
DeprecatedTypeProperties.h37730644editdlrm
DeprecatedTypePropertiesRegistry.h7950644editdlrm
Dict.h131950644editdlrm
Dict_inl.h79960644editdlrm
Dimname.h11880644editdlrm
DimVector.h2470644editdlrm
DistributionsHelper.h125940644editdlrm
Formatting.h9590644editdlrm
function.h21450644editdlrm
functional.h14600644editdlrm
function_schema.h135770644editdlrm
function_schema_inl.h93190644editdlrm
Generator.h49350644editdlrm
grad_mode.h2100644editdlrm
interned_strings.h253320644editdlrm
interned_strings_class.h7700644editdlrm
ivalue.h388230644editdlrm
ivalue_inl.h599630644editdlrm
ivalue_to.h7560644editdlrm
jit_type.h759710644editdlrm
jit_type_base.h65080644editdlrm
LegacyTypeDispatch.h46260644editdlrm
List.h156670644editdlrm
List_inl.h110120644editdlrm
Macros.h440644editdlrm
MT19937RNGEngine.h64100644editdlrm
NamedTensor.h50500644editdlrm
operator_name.h30180644editdlrm
PhiloxRNGEngine.h64960644editdlrm
PythonModeTLS.h4030644editdlrm
qualified_name.h43580644editdlrm
QuantizerBase.h24430644editdlrm
Range.h4180644editdlrm
Reduction.h4610644editdlrm
rref_interface.h11440644editdlrm
Scalar.h290644editdlrm
ScalarType.h330644editdlrm
stack.h60340644editdlrm
Tensor.h17560644editdlrm
TensorAccessor.h102960644editdlrm
TensorBase.h327670644editdlrm
TensorBody.h2475550644editdlrm
TransformationHelper.h69110644editdlrm
typeid.h290644editdlrm
UndefinedTensorImpl.h420644editdlrm
UnsafeFromTH.h7080644editdlrm
VariableHooksInterface.h33120644editdlrm
Variadic.h22570644editdlrm
Vitals.h23050644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/ATen/core/blob.h (5422B)
#pragma once #include #include #include #include #include #include #include #include namespace caffe2 { class Tensor; /** * @brief Blob is a general container that hosts a typed pointer. * * A Blob hosts a pointer as well as its type, and takes charge of deleting it * properly when the blob is deallocated or re-allocated with a new type. A blob * could contain anything, although the most common case is to contain a Tensor. */ class TORCH_API Blob final : public c10::intrusive_ptr_target { public: /** * Initializes an empty Blob. */ Blob() noexcept : meta_(), pointer_(nullptr), has_ownership_(false) {} ~Blob() { Reset(); } Blob(Blob&& other) noexcept : Blob() { swap(other); } Blob& operator=(Blob&& other) noexcept { Blob(std::move(other)).swap(*this); return *this; } /** * Checks if the content stored in the blob is of type T. */ template bool IsType() const noexcept { return meta_.Match(); } /** * Returns the meta info of the blob. */ const TypeMeta meta() const noexcept { return meta_; } /** * Returns a printable typename of the blob. */ c10::string_view TypeName() const noexcept { return meta_.name(); } /** * @brief Gets the const reference of the stored object. The code checks if * the stored object is of the desired type. */ // TODO(jerryzh): add a Get(DeviceType) function? template const T& Get() const { TORCH_INTERNAL_ASSERT( IsType(), "wrong type for the Blob instance. Blob contains ", meta_.name(), " while caller expects ", TypeMeta::TypeName()); // TODO: after we add Get(DeviceType) // and changed all the callsites, we can add // a static assert here to enforce T != Tensor // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) return *static_cast(pointer_); } const void* GetRaw() const noexcept { return pointer_; } void* GetRaw() noexcept { return pointer_; } /** * @brief Gets a mutable pointer to the stored object. * * If the current object is not of the right type, a new object is created * and the old object is freed. Note that type T should have a default * constructor. Otherwise, create the object yourself first, and use * Reset(). */ template T* GetMutable() { static_assert( std::is_default_constructible::value, "GetMutable can't be called with non-default-constructible types. " "Try using specialized methods"); if (IsType()) { return static_cast(pointer_); } else { // TODO Re-enable logging // VLOG(1) << "Create new mutable object " << TypeMeta::TypeName(); return Reset(new T()); } } template T* GetMutableOrNull() { if (IsType()) { return static_cast(pointer_); } else { return nullptr; } } /** * Sets the underlying object to the allocated one. The Blob then takes over * the ownership of the passed in pointer. If there is already an object in * the Blob, the old object is freed. * * This is used when the underlying class T does not have a default ctor, or * complex initializations needs to be done outside the blob. */ template T* Reset(T* allocated) { free_(); meta_ = TypeMeta::Make(); pointer_ = static_cast(allocated); has_ownership_ = true; return allocated; } /** * Sets the underlying object to the allocated one, but does not take over * the ownership of the passed in pointer. If there is already an object in * the Blob, the old object is freed. * * Unlike Reset, this does not take over the ownership of the pointer and the * caller is responsible for making sure that the lifetime of the allocated * blob outlasts the lifetime of any access to this blob, until another Reset * call is made or the blob is destructed. */ template typename std::remove_const::type* ShareExternal( typename std::remove_const::type* allocated) { return static_cast(ShareExternal( static_cast(allocated), TypeMeta::Make::type>())); } void* ShareExternal(void* allocated, const TypeMeta meta) { free_(); meta_ = meta; pointer_ = allocated; has_ownership_ = false; return allocated; } /** * Resets the Blob to an empty one. */ void Reset() { free_(); pointer_ = nullptr; meta_ = TypeMeta(); has_ownership_ = false; } /** * @brief Swaps the underlying storage of two blobs. */ void swap(Blob& rhs) { using std::swap; swap(meta_, rhs.meta_); swap(pointer_, rhs.pointer_); swap(has_ownership_, rhs.has_ownership_); } private: void free_() { if (has_ownership_ && pointer_ != nullptr) { (*meta_.deleteFn())(pointer_); } } TypeMeta meta_; void* pointer_; bool has_ownership_; C10_DISABLE_COPY_AND_ASSIGN(Blob); }; inline void swap(Blob& lhs, Blob& rhs) { lhs.swap(rhs); } inline std::ostream& operator<<(std::ostream& out, const Blob& v) { return out << "Blob[" << v.TypeName() << "]"; } } // namespace caffe2