/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/TensorAccessor.h (10296B)
#pragma once #include #include #include #include #include namespace at { // The PtrTraits argument to the TensorAccessor/GenericPackedTensorAccessor // is used to enable the __restrict__ keyword/modifier for the data // passed to cuda. template struct DefaultPtrTraits { typedef T* PtrType; }; #if defined(__CUDACC__) || defined(__HIPCC__) template struct RestrictPtrTraits { typedef T* __restrict__ PtrType; }; #endif // TensorAccessorBase and TensorAccessor are used for both CPU and CUDA tensors. // For CUDA tensors it is used in device code (only). This means that we restrict ourselves // to functions and types available there (e.g. IntArrayRef isn't). // The PtrTraits argument is only relevant to cuda to support `__restrict__` pointers. template class PtrTraits = DefaultPtrTraits, typename index_t = int64_t> class TensorAccessorBase { public: typedef typename PtrTraits::PtrType PtrType; C10_HOST_DEVICE TensorAccessorBase( PtrType data_, const index_t* sizes_, const index_t* strides_) : data_(data_), sizes_(sizes_), strides_(strides_) {} C10_HOST IntArrayRef sizes() const { return IntArrayRef(sizes_,N); } C10_HOST IntArrayRef strides() const { return IntArrayRef(strides_,N); } C10_HOST_DEVICE index_t stride(index_t i) const { return strides_[i]; } C10_HOST_DEVICE index_t size(index_t i) const { return sizes_[i]; } C10_HOST_DEVICE PtrType data() { return data_; } C10_HOST_DEVICE const PtrType data() const { return data_; } protected: PtrType data_; const index_t* sizes_; const index_t* strides_; }; // The `TensorAccessor` is typically instantiated for CPU `Tensor`s using // `Tensor.accessor()`. // For CUDA `Tensor`s, `GenericPackedTensorAccessor` is used on the host and only // indexing on the device uses `TensorAccessor`s. template class PtrTraits = DefaultPtrTraits, typename index_t = int64_t> class TensorAccessor : public TensorAccessorBase { public: typedef typename PtrTraits::PtrType PtrType; C10_HOST_DEVICE TensorAccessor( PtrType data_, const index_t* sizes_, const index_t* strides_) : TensorAccessorBase(data_,sizes_,strides_) {} C10_HOST_DEVICE TensorAccessor operator[](index_t i) { return TensorAccessor(this->data_ + this->strides_[0]*i,this->sizes_+1,this->strides_+1); } C10_HOST_DEVICE const TensorAccessor operator[](index_t i) const { return TensorAccessor(this->data_ + this->strides_[0]*i,this->sizes_+1,this->strides_+1); } }; template class PtrTraits, typename index_t> class TensorAccessor : public TensorAccessorBase { public: typedef typename PtrTraits::PtrType PtrType; C10_HOST_DEVICE TensorAccessor( PtrType data_, const index_t* sizes_, const index_t* strides_) : TensorAccessorBase(data_,sizes_,strides_) {} C10_HOST_DEVICE T & operator[](index_t i) { // NOLINTNEXTLINE(clang-analyzer-core.NullDereference) return this->data_[this->strides_[0]*i]; } C10_HOST_DEVICE const T & operator[](index_t i) const { return this->data_[this->strides_[0]*i]; } }; // GenericPackedTensorAccessorBase and GenericPackedTensorAccessor are used on for CUDA `Tensor`s on the host // and as // In contrast to `TensorAccessor`s, they copy the strides and sizes on instantiation (on the host) // in order to transfer them on the device when calling kernels. // On the device, indexing of multidimensional tensors gives to `TensorAccessor`s. // Use RestrictPtrTraits as PtrTraits if you want the tensor's data pointer to be marked as __restrict__. // Instantiation from data, sizes, strides is only needed on the host and std::copy isn't available // on the device, so those functions are host only. template class PtrTraits = DefaultPtrTraits, typename index_t = int64_t> class GenericPackedTensorAccessorBase { public: typedef typename PtrTraits::PtrType PtrType; C10_HOST GenericPackedTensorAccessorBase( PtrType data_, const index_t* sizes_, const index_t* strides_) : data_(data_) { std::copy(sizes_, sizes_ + N, std::begin(this->sizes_)); std::copy(strides_, strides_ + N, std::begin(this->strides_)); } // if index_t is not int64_t, we want to have an int64_t constructor template ::value>::type> C10_HOST GenericPackedTensorAccessorBase( PtrType data_, const source_index_t* sizes_, const source_index_t* strides_) : data_(data_) { for (int i = 0; i < N; i++) { this->sizes_[i] = sizes_[i]; this->strides_[i] = strides_[i]; } } C10_HOST_DEVICE index_t stride(index_t i) const { return strides_[i]; } C10_HOST_DEVICE index_t size(index_t i) const { return sizes_[i]; } C10_HOST_DEVICE PtrType data() { return data_; } C10_HOST_DEVICE const PtrType data() const { return data_; } protected: PtrType data_; index_t sizes_[N]; index_t strides_[N]; C10_HOST void bounds_check_(index_t i) const { TORCH_CHECK_INDEX( 0 <= i && i < N, "Index ", i, " is not within bounds of a tensor of dimension ", N); } }; template class PtrTraits = DefaultPtrTraits, typename index_t = int64_t> class GenericPackedTensorAccessor : public GenericPackedTensorAccessorBase { public: typedef typename PtrTraits::PtrType PtrType; C10_HOST GenericPackedTensorAccessor( PtrType data_, const index_t* sizes_, const index_t* strides_) : GenericPackedTensorAccessorBase(data_, sizes_, strides_) {} // if index_t is not int64_t, we want to have an int64_t constructor template ::value>::type> C10_HOST GenericPackedTensorAccessor( PtrType data_, const source_index_t* sizes_, const source_index_t* strides_) : GenericPackedTensorAccessorBase(data_, sizes_, strides_) {} C10_DEVICE TensorAccessor operator[](index_t i) { index_t* new_sizes = this->sizes_ + 1; index_t* new_strides = this->strides_ + 1; return TensorAccessor(this->data_ + this->strides_[0]*i, new_sizes, new_strides); } C10_DEVICE const TensorAccessor operator[](index_t i) const { const index_t* new_sizes = this->sizes_ + 1; const index_t* new_strides = this->strides_ + 1; return TensorAccessor(this->data_ + this->strides_[0]*i, new_sizes, new_strides); } /// Returns a PackedTensorAccessor of the same dimension after transposing the /// two dimensions given. Does not actually move elements; transposition is /// made by permuting the size/stride arrays. If the dimensions are not valid, /// asserts. C10_HOST GenericPackedTensorAccessor transpose( index_t dim1, index_t dim2) const { this->bounds_check_(dim1); this->bounds_check_(dim2); GenericPackedTensorAccessor result( this->data_, this->sizes_, this->strides_); std::swap(result.strides_[dim1], result.strides_[dim2]); std::swap(result.sizes_[dim1], result.sizes_[dim2]); return result; } }; template class PtrTraits, typename index_t> class GenericPackedTensorAccessor : public GenericPackedTensorAccessorBase { public: typedef typename PtrTraits::PtrType PtrType; C10_HOST GenericPackedTensorAccessor( PtrType data_, const index_t* sizes_, const index_t* strides_) : GenericPackedTensorAccessorBase(data_, sizes_, strides_) {} // if index_t is not int64_t, we want to have an int64_t constructor template ::value>::type> C10_HOST GenericPackedTensorAccessor( PtrType data_, const source_index_t* sizes_, const source_index_t* strides_) : GenericPackedTensorAccessorBase(data_, sizes_, strides_) {} C10_DEVICE T & operator[](index_t i) { return this->data_[this->strides_[0] * i]; } C10_DEVICE const T& operator[](index_t i) const { return this->data_[this->strides_[0]*i]; } // Same as in the general N-dimensional case, but note that in the // 1-dimensional case the returned PackedTensorAccessor will always be an // identical copy of the original C10_HOST GenericPackedTensorAccessor transpose( index_t dim1, index_t dim2) const { this->bounds_check_(dim1); this->bounds_check_(dim2); return GenericPackedTensorAccessor( this->data_, this->sizes_, this->strides_); } }; // Can't put this directly into the macro function args because of commas #define AT_X GenericPackedTensorAccessor // Old name for `GenericPackedTensorAccessor` template class PtrTraits = DefaultPtrTraits, typename index_t = int64_t> C10_DEFINE_DEPRECATED_USING(PackedTensorAccessor, AT_X) #undef AT_X template class PtrTraits = DefaultPtrTraits> using PackedTensorAccessor32 = GenericPackedTensorAccessor; template class PtrTraits = DefaultPtrTraits> using PackedTensorAccessor64 = GenericPackedTensorAccessor; } // namespace at