69 static int const kRank = Layout::kRank;
72 using Index =
typename Layout::Index;
81 using Stride =
typename Layout::Stride;
117 std::vector<Element> host_;
154 layout_ = Layout::packed(extent_);
163 bool device_backed_ =
true) {
173 Element* device_memory =
nullptr;
174 if (device_backed_) {
175 device_memory = device_memory::allocate<Element>(count);
177 device_.
reset(device_memory, device_backed_ ? count : 0);
185 bool device_backed_ =
true) {
190 reserve(
size_t(layout_.capacity(extent_)), device_backed_);
197 bool device_backed_ =
true) {
199 reset(extent, Layout::packed(extent), device_backed_);
207 bool device_backed_ =
true) {
212 LongIndex new_size = size_t(layout_.capacity(extent_));
214 if (
static_cast<decltype(host_.
size())
>(new_size) > host_.size()) {
223 bool device_backed_ =
true) {
225 resize(extent, Layout::packed(extent), device_backed_);
304 return (device_.
get() ==
nullptr) ?
false :
true;
320 return layout_.stride();
325 return layout_.stride();
330 return layout_.stride().at(dim);
335 return layout_.stride().at(dim);
340 return layout_(coord);
Stride & stride()
Returns the layout object's stride vector.
Definition: host_tensor.h:324
Definition: aligned_buffer.h:35
HostTensor(TensorCoord const &extent, Layout const &layout, bool device_backed=true)
Constructs a tensor given an extent and layout.
Definition: host_tensor.h:140
Defines a structure containing strides, bounds, and a pointer to tensor data.
typename Layout::Stride Stride
Layout's stride vector.
Definition: host_tensor.h:81
void copy_in_host_to_device(Element const *ptr_host, LongIndex count=-1)
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:410
Index & stride(int dim)
Returns the layout object's stride in a given physical dimension.
Definition: host_tensor.h:334
void copy_to_device(T *dst, T const *src, size_t count=1)
Definition: device_memory.h:81
ConstTensorView device_view(LongIndex ptr_element_offset=0) const
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:298
typename Layout::LongIndex LongIndex
Long index used for pointer offsets.
Definition: host_tensor.h:75
Layout_ Layout
Mapping function from logical coordinate to linear memory.
Definition: host_tensor.h:66
ConstTensorView host_view(LongIndex ptr_element_offset=0) const
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:288
LongIndex capacity() const
Returns the logical capacity based on extent and layout. May differ from size().
Definition: host_tensor.h:234
void copy_out_host_to_host(Element *ptr_host, LongIndex count=-1) const
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:485
void sync_host()
Copies data from device to host.
Definition: host_tensor.h:364
Layout layout() const
Returns the layout object.
Definition: host_tensor.h:314
void copy_in_host_to_host(Element const *ptr_host, LongIndex count=-1)
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:425
Element * device_data()
Gets pointer to device data.
Definition: host_tensor.h:258
T * get() const
Returns a pointer to the managed object.
Definition: device_memory.h:162
void reset()
Deletes the managed object and resets capacity to zero.
Definition: device_memory.h:171
Element const * device_data() const
Gets pointer to device data.
Definition: host_tensor.h:264
static int const kElementsPerStoredItem
Used to handle packing of subbyte elements.
Definition: host_tensor.h:102
Defines a structure containing strides and a pointer to tensor data.
C++ interface to CUDA device memory management functions.
~HostTensor()
Definition: host_tensor.h:149
TensorRef< typename platform::remove_const< Element >::type const, Layout > ConstTensorRef
TensorRef to constant data.
Definition: tensor_ref.h:179
void copy_in_device_to_device(Element const *ptr_device, LongIndex count=-1)
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:395
typename ConstTensorRef::Reference ConstReference
Constant reference to element in tensor.
Definition: host_tensor.h:99
Index stride(int dim) const
Returns the layout object's stride in a given physical dimension.
Definition: host_tensor.h:329
void sync_device()
Copies data from host to device.
Definition: host_tensor.h:372
TensorView< typename platform::remove_const< Element >::type const, Layout > ConstTensorView
TensorView pointing to constant memory.
Definition: tensor_view.h:95
TensorView< Element, Layout > TensorView
Tensor reference to device memory.
Definition: host_tensor.h:90
Element * host_data_ptr_offset(LongIndex ptr_element_offset)
Gets pointer to host data with a pointer offset.
Definition: host_tensor.h:242
Host tensor.
Definition: host_tensor.h:59
TensorView device_view(LongIndex ptr_element_offset=0)
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:293
void copy_out_device_to_host(Element *ptr_host, LongIndex count=-1) const
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:440
void copy_out_host_to_device(Element *ptr_device, LongIndex count=-1) const
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:470
ConstReference at(TensorCoord const &coord) const
Returns a const reference to the element at the logical Coord in host memory.
Definition: host_tensor.h:349
Defines the size of an element in bits.
Definition: numeric_types.h:42
void copy_host_to_host(T *dst, T const *src, size_t count=1)
Definition: device_memory.h:96
ConstTensorRef host_ref(LongIndex ptr_element_offset=0) const
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:270
TensorCoord extent() const
Returns the extent of the tensor.
Definition: host_tensor.h:354
Element * host_data()
Gets pointer to host data.
Definition: host_tensor.h:239
void reserve(size_t count, bool device_backed_=true)
Resizes internal memory allocations without affecting layout or extent.
Definition: host_tensor.h:161
Definition: subbyte_reference.h:557
bool device_backed() const
Returns true if device memory is allocated.
Definition: host_tensor.h:303
typename Layout::TensorCoord TensorCoord
Coordinate in logical tensor space.
Definition: host_tensor.h:78
typename platform::conditional< sizeof_bits< Element >::value >=8, Element &, SubbyteReference< Element > >::type Reference
Reference type to an element.
Definition: tensor_ref.h:159
Reference host_data(LongIndex idx)
Gets a reference to an element in host memory.
Definition: host_tensor.h:245
TensorCoord & extent()
Returns the extent of the tensor.
Definition: host_tensor.h:359
HostTensor()
Default constructor.
Definition: host_tensor.h:128
typename TensorView::ConstTensorView ConstTensorView
Tensor reference to constant device memory.
Definition: host_tensor.h:93
void resize(TensorCoord const &extent, bool device_backed_=true)
Definition: host_tensor.h:221
void copy_to_host(T *dst, T const *src, size_t count=1)
Definition: device_memory.h:86
void copy_in_device_to_host(Element const *ptr_device, LongIndex count=-1)
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:380
LongIndex offset(TensorCoord const &coord) const
Computes the offset of an index from the origin of the tensor.
Definition: host_tensor.h:339
TensorView host_view(LongIndex ptr_element_offset=0)
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:283
HostTensor(TensorCoord const &extent, bool device_backed=true)
Constructs a tensor given an extent. Assumes a packed layout.
Definition: host_tensor.h:131
TensorRef device_ref(LongIndex ptr_element_offset=0)
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:273
Element_ Element
Data type of individual access.
Definition: host_tensor.h:63
Reference at(TensorCoord const &coord)
Returns a reference to the element at the logical Coord in host memory.
Definition: host_tensor.h:344
void reset(TensorCoord const &extent, bool device_backed_=true)
Definition: host_tensor.h:195
typename TensorRef::ConstTensorRef ConstTensorRef
Tensor reference to constant device memory.
Definition: host_tensor.h:87
ConstReference host_data(LongIndex idx) const
Gets a constant reference to an element in host memory.
Definition: host_tensor.h:253
void reset()
Clears the HostTensor allocation to size/capacity = 0.
Definition: host_tensor.h:152
static int const kRank
Logical rank of tensor index space.
Definition: host_tensor.h:69
Element * device_data_ptr_offset(LongIndex ptr_element_offset)
Gets pointer to device data with a pointer offset.
Definition: host_tensor.h:261
size_t size() const
Returns the number of elements stored in the host tensor.
Definition: host_tensor.h:229
ConstTensorRef device_ref(LongIndex ptr_element_offset=0) const
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:278
Layout & layout()
Returns the layout object.
Definition: host_tensor.h:309
typename TensorRef::Reference Reference
Reference to element in tensor.
Definition: host_tensor.h:96
void resize(TensorCoord const &extent, Layout const &layout, bool device_backed_=true)
Definition: host_tensor.h:204
Defines properties of matrices used to denote layout and operands to GEMM kernels.
TensorRef< Element, Layout > TensorRef
Tensor reference to device memory.
Definition: host_tensor.h:84
void reset(TensorCoord const &extent, Layout const &layout, bool device_backed_=true)
Definition: host_tensor.h:182
Stride stride() const
Returns the layout object's stride vector.
Definition: host_tensor.h:319
typename Layout::Index Index
Index type.
Definition: host_tensor.h:72
Basic include for CUTLASS.
TensorRef host_ref(LongIndex ptr_element_offset=0)
Accesses the tensor reference pointing to data.
Definition: host_tensor.h:267
void copy_out_device_to_device(Element *ptr_device, LongIndex count=-1) const
Copy data from a caller-supplied device pointer into host memory.
Definition: host_tensor.h:455
void copy_device_to_device(T *dst, T const *src, size_t count=1)
Definition: device_memory.h:91
Element const * host_data() const
Gets pointer to host data.
Definition: host_tensor.h:250