tile_iterator_simt.h
Go to the documentation of this file.
/***************************************************************************************************
* Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
* * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************************************/
#pragma once
#include "cutlass/array.h"
#include "cutlass/layout/matrix.h"
#include "cutlass/layout/pitch_linear.h"
#include "cutlass/epilogue/warp/simt_policy.h"
#define CUTLASS_SIMT_EPILOGUE_USE_SCALAR_STORES 1
namespace cutlass {
namespace epilogue {
namespace warp {
template <
typename WarpShape,
typename Operator,
typename Element,
typename Layout,
typename MmaSimtPolicy
>
class TileIteratorSimt;
template <
typename WarpShape_,
typename Operator_,
typename Element_,
typename MmaSimtPolicy_
>
class TileIteratorSimt<WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_> {
public:
using WarpShape = WarpShape_;
using Operator = Operator_;
using Element = Element_;
using Layout = layout::RowMajor;
using TensorRef = TensorRef<Element, Layout>;
using TensorCoord = MatrixCoord;
using Index = typename TensorRef::Index;
using LongIndex = typename TensorRef::LongIndex;
using Policy = SimtPolicy<WarpShape, Operator, Layout, MmaSimtPolicy_>;
using Shape = MatrixShape<
Policy::kRowsPerIteration,
WarpShape::kN
>;
using Fragment = Array<
typename Operator::ElementC,
Policy::kElementsPerIteration>;
using AccumulatorTile = Array<
typename Operator::ElementC,
Policy::kAccumulatorElementCount>;
static int const kIterations = Policy::kIterations;
using Padding = MatrixShape<
0,
4 * Policy::kElementsPerAccess>;
private:
using AccessType = AlignedArray<Element, Policy::kElementsPerAccess>;
//
// Data members
//
AccessType *pointer_;
Layout layout_;
public:
CUTLASS_HOST_DEVICE
TileIteratorSimt(): pointer_(nullptr) { }
CUTLASS_HOST_DEVICE
TileIteratorSimt(
TensorRef const &ref,
unsigned lane_id
):
pointer_(reinterpret_cast<AccessType *>(ref.data())),
layout_(ref.stride()[0] / Policy::kElementsPerAccess) {
auto lane_layout = Policy::MmaSimtPolicy::get_lane_layout();
MatrixCoord lane_offset = lane_layout.inverse(lane_id);
pointer_ += layout_(lane_offset);
}
CUTLASS_HOST_DEVICE
TileIteratorSimt & add_pointer_offset(Index pointer_offset) {
pointer_ += pointer_offset / Policy::kElementsPerAccess;
return *this;
}
CUTLASS_HOST_DEVICE
TileIteratorSimt & add_tile_offset(TensorCoord const &tile_offset) {
pointer_ += layout_({
tile_offset.row() * Shape::kRow,
(tile_offset.column() * Shape::kColumn / Policy::kElementsPerAccess)
});
return *this;
}
CUTLASS_HOST_DEVICE
TileIteratorSimt & operator+=(TensorCoord const &tile_offset) {
add_tile_offset(tile_offset);
return *this;
}
CUTLASS_HOST_DEVICE
void store_with_pointer_offset(Fragment const &frag, Index pointer_offset) {
#if CUTLASS_SIMT_EPILOGUE_USE_SCALAR_STORES
// de-vectorized stores
using ScalarAccessType = AlignedArray<Element, 1>;
ScalarAccessType const *scalarFragPtr = reinterpret_cast<ScalarAccessType const *>(&frag);
ScalarAccessType *scalarPointer = reinterpret_cast<ScalarAccessType *>(pointer_);
CUTLASS_PRAGMA_UNROLL
for (int n = 0; n < Policy::kAccessesPerIteration; ++n) {
CUTLASS_PRAGMA_UNROLL
for (int s = 0; s < Policy::kElementsPerAccess; s++) {
scalarPointer[n * Policy::MmaSimtPolicy::WarpShape::kColumn * Policy::kElementsPerAccess + s] = scalarFragPtr[n * Policy::kElementsPerAccess + s];
}
}
#else
// original vector stores
AccessType const *frag_ptr = reinterpret_cast< AccessType const *>(&frag);
CUTLASS_PRAGMA_UNROLL
for (int n = 0; n < Policy::kAccessesPerIteration; ++n) {
pointer_[n * Policy::MmaSimtPolicy::WarpShape::kColumn] = frag_ptr[n];
}
#endif
}
CUTLASS_HOST_DEVICE
void store(Fragment const &frag) {
store_with_pointer_offset(frag, 0);
}
CUTLASS_HOST_DEVICE
void load_with_pointer_offset(Fragment &frag, Index pointer_offset) const {
AccessType *frag_ptr = reinterpret_cast< AccessType *>(&frag);
CUTLASS_PRAGMA_UNROLL
for (int n = 0; n < Policy::kAccessesPerIteration; ++n) {
frag_ptr[n] = pointer_[n * Policy::MmaSimtPolicy::WarpShape::kColumn];
}
}
CUTLASS_HOST_DEVICE
void load(Fragment &frag) const {
load_with_pointer_offset(frag, 0);
}
};
} // namespace warp
} // namespace epilogue
} // namespace cutlass
cutlass::MatrixShape
Describes the size of a matrix tile.
Definition: matrix_shape.h:42
cutlass::MatrixCoord::column
CUTLASS_HOST_DEVICE Index const & column() const
Returns the column of the coordinate.
Definition: matrix_coord.h:85
cutlass
Definition: aligned_buffer.h:35
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::AccumulatorTile
Array< typename Operator::ElementC, Policy::kAccumulatorElementCount > AccumulatorTile
This is the complete warp-level accumulator tile.
Definition: tile_iterator_simt.h:95
cutlass::AlignedArray
Aligned array type.
Definition: array.h:511
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::Fragment
Array< typename Operator::ElementC, Policy::kElementsPerIteration > Fragment
This is the fragment size produced by one access of the iterator.
Definition: tile_iterator_simt.h:90
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::Index
typename TensorRef::Index Index
Definition: tile_iterator_simt.h:76
cutlass::MatrixCoord::row
CUTLASS_HOST_DEVICE Index const & row() const
Returns the row of the coordinate.
Definition: matrix_coord.h:77
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::LongIndex
typename TensorRef::LongIndex LongIndex
Definition: tile_iterator_simt.h:77
cutlass::epilogue::warp::SimtPolicy
Definition: simt_policy.h:50
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::load
CUTLASS_HOST_DEVICE void load(Fragment &frag) const
Load.
Definition: tile_iterator_simt.h:215
array.h
Statically sized array of elements that accommodates all CUTLASS-supported numeric types and is safe ...
CUTLASS_PRAGMA_UNROLL
#define CUTLASS_PRAGMA_UNROLL
Definition: cutlass.h:110
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::store
CUTLASS_HOST_DEVICE void store(Fragment const &frag)
Store.
Definition: tile_iterator_simt.h:197
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::add_tile_offset
CUTLASS_HOST_DEVICE TileIteratorSimt & add_tile_offset(TensorCoord const &tile_offset)
advances in units of whole tiles along the logical coordinate space of the tensor ...
Definition: tile_iterator_simt.h:150
nullptr
#define nullptr
nullptr
Definition: platform.h:144
cutlass::TensorRef< Element, Layout >
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::store_with_pointer_offset
CUTLASS_HOST_DEVICE void store_with_pointer_offset(Fragment const &frag, Index pointer_offset)
Store.
Definition: tile_iterator_simt.h:171
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::add_pointer_offset
CUTLASS_HOST_DEVICE TileIteratorSimt & add_pointer_offset(Index pointer_offset)
Adds a pointer offset.
Definition: tile_iterator_simt.h:143
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::TileIteratorSimt
CUTLASS_HOST_DEVICE TileIteratorSimt(TensorRef const &ref, unsigned lane_id)
Constructor from TensorRef.
Definition: tile_iterator_simt.h:128
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:89
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::TileIteratorSimt
CUTLASS_HOST_DEVICE TileIteratorSimt()
Default constructor.
Definition: tile_iterator_simt.h:124
cutlass::TensorRef::Index
typename Layout::Index Index
Index type.
Definition: tensor_ref.h:165
cutlass::layout::RowMajor
Mapping function for row-major matrices.
Definition: layout/matrix.h:50
matrix.h
Defines layout functions used by TensorRef and derived classes.
pitch_linear.h
Defines layout functions used by TensorRef and derived classes for pitch-linear memory.
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::operator+=
CUTLASS_HOST_DEVICE TileIteratorSimt & operator+=(TensorCoord const &tile_offset)
Definition: tile_iterator_simt.h:162
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::load_with_pointer_offset
CUTLASS_HOST_DEVICE void load_with_pointer_offset(Fragment &frag, Index pointer_offset) const
Load.
Definition: tile_iterator_simt.h:203
simt_policy.h
Defines basic structures needed for implementing the warp-scoped phase of the epilogue. These quantities assume a &#39;column-major&#39; arrangement of SimtOp instructions, of which a row-oriented slice is visible per iteration.
cutlass::epilogue::warp::TileIteratorSimt< WarpShape_, Operator_, Element_, layout::RowMajor, MmaSimtPolicy_ >::WarpShape
WarpShape_ WarpShape
Definition: tile_iterator_simt.h:69
cutlass::MatrixCoord
Definition: matrix_coord.h:39
cutlass::epilogue::warp::TileIteratorSimt
Template for reading and writing tiles of accumulators to shared memory.
Definition: tile_iterator_simt.h:55
cutlass::TensorRef::LongIndex
typename Layout::LongIndex LongIndex
Long index used for pointer offsets.
Definition: tensor_ref.h:168