fragment_stream.h
Go to the documentation of this file.
/***************************************************************************************************
* Copyright (c) 2017-2018, 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/convert.h>
#include <cutlass/fragment.h>
#include <cutlass/iterator_access.h>
#include <cutlass/tensor_ref.h>
#include <cutlass/tile_iterator.h>
#include <cutlass/gemm/gemm_operand.h>
#include <cutlass/gemm/gemm_traits.h>
#include <cutlass/matrix_traits.h>
namespace cutlass {
template <typename Traits_, typename LoadIterator_, typename StoreIterator_,
typename Convert_ =
FragmentCopy<typename StoreIterator_::Fragment, typename LoadIterator_::Fragment>,
typename Index_ = int>
struct FragmentStream {
//
// Constant and type definitions
//
typedef Traits_ Traits;
typedef LoadIterator_ LoadIterator;
typedef StoreIterator_ StoreIterator;
typedef Convert_ Convert;
typedef Index_ Index;
//
// Dependent types
//
typedef typename LoadIterator::Fragment Fragment;
typedef typename StoreIterator::Fragment StoreFragment;
typedef typename StoreIterator::Storage Storage;
typedef typename StoreIterator::Storage SharedStoreStorage;
//
// Nested classes
//
struct Params {
typedef typename LoadIterator::Params LoadParams;
typedef typename StoreIterator::Params StoreParams;
//
// Data members
//
LoadParams load_params;
StoreParams store_params;
//
// Methods
//
CUTLASS_HOST_DEVICE int initialize(LoadParams const &_load_params,
StoreParams const &_store_params) {
load_params = _load_params;
store_params = _store_params;
return 0;
}
};
//
// Data members
//
LoadIterator load_iterator;
typename LoadIterator::PredicateVector predicates;
StoreIterator store_iterator;
Fragment fetch;
Convert convert;
//
// Static members
//
static CUTLASS_DEVICE void shared_store_fence() { __syncthreads(); }
//
// Methods
//
CUTLASS_DEVICE
FragmentStream() {}
CUTLASS_DEVICE
FragmentStream(Params const &params, Coord<3> const &bounds,
Coord<3> const &block_offset = make_Coord(0, 0, 0))
: load_iterator(params.load_params, block_offset), store_iterator(params.store_params) {
// set predicates
initialize_predicates(bounds, block_offset);
fetch.clear();
}
CUTLASS_DEVICE
void load() {
ConstPredicateTileAdapter<typename LoadIterator::PredicateVector,
typename LoadIterator::Iterations>
predicates_it(predicates);
iterator_load_post_increment(load_iterator, fetch, predicates_it);
}
CUTLASS_DEVICE
void commit() {
StoreFragment store_fragment(convert(fetch));
iterator_store(store_iterator, store_fragment);
}
CUTLASS_DEVICE
void initialize_predicates(Coord<3> const &bounds, Coord<3> const &block_offset) {
PredicateTileAdapter<typename LoadIterator::PredicateVector, typename LoadIterator::Iterations>
predicates_it(predicates);
load_iterator.initialize_predicates(predicates_it, bounds, block_offset);
}
};
} // namespace cutlass
cutlass::FragmentStream::store_iterator
StoreIterator store_iterator
Stores fragment to shared memory.
Definition: fragment_stream.h:132
cutlass::TileStoreIterator< Traits_::TileTraits, Traits_::Scalar, Traits_::MultiplicandTraits::kKstrided ? IteratorAdvance::kH :IteratorAdvance::kW, MemorySpace::kShared, Traits_::Index, Traits_::Scalar, IteratorFragment::kScalar, Traits_::DestinationSkew >::Fragment
Base::Fragment Fragment
Fragment definition.
Definition: tile_iterator.h:606
cutlass
Definition: convert.h:34
tensor_ref.h
Defines a structure containing strides, bounds, and a pointer to tensor data.
cutlass::FragmentStream::Params::store_params
StoreParams store_params
Parameters to the store iterator.
Definition: fragment_stream.h:106
cutlass::FragmentStream::predicates
LoadIterator::PredicateVector predicates
Predicate vector.
Definition: fragment_stream.h:129
tile_iterator.h
Defines the Tile Traits concept and iterators for loading and storing to tiles efficiently.
gemm_traits.h
Defines structural properties of complete GEMM computation.
cutlass::make_Coord
CUTLASS_HOST_DEVICE Coord< 1 > make_Coord(int _0)
Helper to make a 2-element coordinate.
Definition: coord.h:241
cutlass::FragmentStream::Storage
StoreIterator::Storage Storage
Destination storage.
Definition: fragment_stream.h:81
cutlass::FragmentStream::FragmentStream
CUTLASS_DEVICE FragmentStream(Params const &params, Coord< 3 > const &bounds, Coord< 3 > const &block_offset=make_Coord(0, 0, 0))
Constructor.
Definition: fragment_stream.h:156
cutlass::FragmentStream::fetch
Fragment fetch
Fragment fetched by load iterator.
Definition: fragment_stream.h:135
cutlass::FragmentStream::commit
CUTLASS_DEVICE void commit()
Commits the fragment.
Definition: fragment_stream.h:176
cutlass::FragmentStream::StoreIterator
StoreIterator_ StoreIterator
Defines the store iterator.
Definition: fragment_stream.h:62
cutlass::PredicateTileAdapter
Adapter to enable random access to predicates via logical coordinate within a tile.
Definition: predicate_vector.h:435
cutlass::FragmentStream::Index
Index_ Index
Index type.
Definition: fragment_stream.h:68
cutlass::TileIteratorBase< Traits_, Traits_::Scalar, Advance_, MemorySpace, Traits_::Index, Traits_::Scalar, IteratorFragment_, Traits_::DestinationSkew >::Storage
Fragment< Scalar, ShapeCount< Tile >::kCount, kFragmentSize > Storage
The storage.
Definition: tile_iterator.h:181
cutlass::TileLoadIterator< Traits_::TileTraits, Traits_::Scalar, Traits_::MultiplicandTraits::kKstrided ? IteratorAdvance::kH :IteratorAdvance::kW, MemorySpace::kGlobal, Traits_::Index >::Iterations
Base::Iterations Iterations
Iterations.
Definition: tile_iterator.h:346
cutlass::FragmentStream::shared_store_fence
static CUTLASS_DEVICE void shared_store_fence()
The memory fence for shared stores.
Definition: fragment_stream.h:145
iterator_access.h
Free functions for loading and storing to implementations of tile iteartor concepts.
cutlass::TileLoadIterator< Traits_::TileTraits, Traits_::Scalar, Traits_::MultiplicandTraits::kKstrided ? IteratorAdvance::kH :IteratorAdvance::kW, MemorySpace::kGlobal, Traits_::Index >
cutlass::iterator_load_post_increment
CUTLASS_HOST_DEVICE void iterator_load_post_increment(InputIterator &iterator, Fragment &fragment, typename InputIterator::Index offset, ConstPredicateAdapter predicate_adapter)
Loads a fragment from an input iterator, masked by a predicate iterator.
Definition: iterator_access.h:113
cutlass::FragmentStream::SharedStoreStorage
StoreIterator::Storage SharedStoreStorage
The storage in shared memory.
Definition: fragment_stream.h:84
cutlass::FragmentStream::initialize_predicates
CUTLASS_DEVICE void initialize_predicates(Coord< 3 > const &bounds, Coord< 3 > const &block_offset)
Recomputes predicates.
Definition: fragment_stream.h:184
gemm_operand.h
Defines constant expressions for mapping GEMM problem size and strides onto pitch-linear memory...
cutlass::FragmentStream
Manages a pair of iterators to stream data from global memory to shared.
Definition: fragment_stream.h:50
cutlass::FragmentStream::FragmentStream
CUTLASS_DEVICE FragmentStream()
Definition: fragment_stream.h:152
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:37
cutlass::Coord
Statically-sized array specifying Coords within a tensor.
Definition: coord.h:48
cutlass::iterator_store
CUTLASS_HOST_DEVICE void iterator_store(OutputIterator &iterator, Fragment &fragment)
Stores a fragment to an output iterator.
Definition: iterator_access.h:174
cutlass::FragmentStream::Params::LoadParams
LoadIterator::Params LoadParams
Load parameters.
Definition: fragment_stream.h:93
cutlass::FragmentStream::Convert
Convert_ Convert
Converts between tiles.
Definition: fragment_stream.h:65
cutlass::FragmentStream::StoreFragment
StoreIterator::Fragment StoreFragment
Stored fragment type.
Definition: fragment_stream.h:78
cutlass::FragmentStream::Traits
Traits_ Traits
Defines traits of WMMA GEMM tile stream.
Definition: fragment_stream.h:56
cutlass::FragmentStream::load
CUTLASS_DEVICE void load()
Loads the fragment.
Definition: fragment_stream.h:167
cutlass::FragmentStream::Params::StoreParams
StoreIterator::Params StoreParams
Store parameters.
Definition: fragment_stream.h:96
cutlass::ConstPredicateTileAdapter
Adapter to enable random access to predicates via logical coordinate within a tile.
Definition: predicate_vector.h:466
cutlass::FragmentStream::Fragment
LoadIterator::Fragment Fragment
Loaded fragment type.
Definition: fragment_stream.h:75
cutlass::FragmentStream::LoadIterator
LoadIterator_ LoadIterator
Defines the load iterator.
Definition: fragment_stream.h:59
cutlass::FragmentStream::Params::initialize
CUTLASS_HOST_DEVICE int initialize(LoadParams const &_load_params, StoreParams const &_store_params)
Initializes parameters.
Definition: fragment_stream.h:113
matrix_traits.h
Defines properties of matrices used to denote layout and operands to GEMM kernels.
cutlass::FragmentStream::Params::load_params
LoadParams load_params
Parameters to load iterator.
Definition: fragment_stream.h:103
cutlass::FragmentStream::convert
Convert convert
Converts between load fragments and store fragments.
Definition: fragment_stream.h:138
fragment.h
Defines Fragment, a statically-sized array for storing parts of matrices within a thread&#39;s registers...
cutlass::FragmentStream::load_iterator
LoadIterator load_iterator
Loads fragment from global memory.
Definition: fragment_stream.h:126
convert.h
Defines conversion operations among Fragments of different base type.
cutlass::TileStoreIterator< Traits_::TileTraits, Traits_::Scalar, Traits_::MultiplicandTraits::kKstrided ? IteratorAdvance::kH :IteratorAdvance::kW, MemorySpace::kShared, Traits_::Index, Traits_::Scalar, IteratorFragment::kScalar, Traits_::DestinationSkew >
cutlass::FragmentStream::Params
Parameters passed to initialize the ierator.
Definition: fragment_stream.h:91