tile_traits_standard.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/tile_iterator.h>
namespace cutlass {
template <typename ThreadShape>
struct TiledThreadOffset {
CUTLASS_HOST_DEVICE
Coord<4> operator()() const {
Coord<4> thread_offset;
int index = threadIdx.x;
thread_offset[3] = (index % ThreadShape::kC);
index = (index / ThreadShape::kC);
thread_offset[2] = (index % ThreadShape::kW);
index = (index / ThreadShape::kW);
thread_offset[1] = (index % ThreadShape::kH);
index = (index / ThreadShape::kH);
thread_offset[0] = index;
return thread_offset;
}
};
template <typename Tile_, int Threads>
struct TileTraitsStrideMajor {
typedef Tile_ Tile;
static int const kThreads = Threads;
// Static assertions
static_assert(!(ShapeCount<Tile>::kDhw % kThreads),
"Tiling undefined if elements not divisible by threads.");
static_assert(Tile::kW <= kThreads,
"This specialization assumes there are more threads than the contiguous dimension "
"of the tile.");
typedef Shape<1, kThreads / Tile::kW, Tile::kW, 1> ThreadShape;
typedef Shape<1, ThreadShape::kH, 1, 1> Delta;
typedef Shape<1, Tile::kH / ThreadShape::kH, 1, 1> Iterations;
typedef TiledThreadOffset<ThreadShape> ThreadOffset;
};
template <typename Tile_, int Threads>
struct TileTraitsContiguousMajor {
typedef Tile_ Tile;
static int const kThreads = Threads;
// Static assertions
static_assert(Tile::kW >= kThreads,
"This specialization assumes there are more threads than the contiguous dimension "
"of the tile.");
static_assert(!(ShapeCount<Tile>::kDhw % kThreads),
"Tiling undefined if elements not divisible by threads.");
static_assert(!(Tile::kW % kThreads),
"The contiguous size of the tile must be divisible by the number of threads.");
typedef Shape<1, 1, kThreads> ThreadShape;
typedef Shape<1, 1, kThreads> Delta;
typedef Shape<1, Tile::kH, Tile::kW / kThreads> Iterations;
typedef TiledThreadOffset<ThreadShape> ThreadOffset;
};
template <typename Tile_, int Threads>
struct TileTraitsWarpRake {
typedef Tile_ Tile;
static int const kThreads = Threads;
static int const kWarpSize = 32;
static int const kWarpCount = kThreads / kWarpSize;
// Static assertions
static_assert(!(ShapeCount<Tile>::kDhw % kThreads),
"Tiling undefined if elements not divisible by threads.");
static_assert(!(kThreads % kWarpSize), "Number of threads must be divisible by the warp size.");
static_assert(!(Tile::kW % kWarpSize), "Contiguous dimension must be divisible by the warp size");
static int const kWarpsStrided = __NV_STD_MIN(kWarpCount, Tile::kH);
static int const kWarpsContiguous = kWarpCount / kWarpsStrided;
typedef Shape<1, kWarpsStrided, kWarpsContiguous * kWarpSize> ThreadShape;
typedef Shape<1, kWarpsStrided, kWarpSize> Delta;
typedef Shape<1, Tile::kH / Delta::kH, Tile::kW / ThreadShape::kW> Iterations;
struct ThreadOffset {
CUTLASS_HOST_DEVICE
Coord<4> operator()() const {
int tid = threadIdx.x;
int warp = (tid / kWarpSize);
int lane = (tid % kWarpSize);
static int const kWarpSpanContiguous = kWarpSize * Iterations::kW;
int warp_w = (warp % kWarpsContiguous);
int warp_h = (warp / kWarpsContiguous);
return make_Coord(0, warp_h, lane + kWarpSpanContiguous * warp_w, 0);
}
};
};
template <typename Tile_, int Threads>
struct TileTraitsStandard {
typedef Tile_ Tile;
static int const kThreads = Threads;
static int const kWarpSize = 32;
static int const kWarpCount = kThreads / kWarpSize;
// Static assertions
static_assert(!(ShapeCount<Tile>::kDhw % kThreads),
"Tiling undefined if elements not divisible by threads.");
typedef typename platform::conditional <
Tile::kW<kWarpSize,
TileTraitsStrideMajor<Tile, Threads>,
typename platform::conditional<!(Tile::kW % kWarpSize),
TileTraitsWarpRake<Tile, Threads>,
TileTraitsContiguousMajor<Tile, Threads> >::type>::
type Traits;
typedef typename Traits::Delta Delta;
typedef Delta ImmediateOffsetStrides;
typedef typename Traits::Iterations Iterations;
typedef typename Traits::ThreadOffset ThreadOffset;
};
} // namespace cutlass
cutlass::TileTraitsWarpRake::Iterations
Shape< 1, Tile::kH/Delta::kH, Tile::kW/ThreadShape::kW > Iterations
Number of iterations.
Definition: tile_traits_standard.h:169
cutlass
Definition: convert.h:33
cutlass::TileTraitsStrideMajor::Iterations
Shape< 1, Tile::kH/ThreadShape::kH, 1, 1 > Iterations
Number of iterations.
Definition: tile_traits_standard.h:89
cutlass::TileTraitsStandard::kWarpCount
static int const kWarpCount
Number of participating warps.
Definition: tile_traits_standard.h:205
cutlass::TileTraitsContiguousMajor
Definition: tile_traits_standard.h:100
tile_iterator.h
Defines the Tile Traits concept and iterators for loading and storing to tiles efficiently.
cutlass::TileTraitsWarpRake::kWarpsStrided
static int const kWarpsStrided
Warps strip-mined across strided dimension.
Definition: tile_traits_standard.h:157
cutlass::TileTraitsContiguousMajor::kThreads
static int const kThreads
Number of participating threads.
Definition: tile_traits_standard.h:105
cutlass::make_Coord
CUTLASS_HOST_DEVICE Coord< 1 > make_Coord(int _0)
Helper to make a 2-element coordinate.
Definition: coord.h:241
cutlass::TileTraitsWarpRake::ThreadOffset
Computes the thread offset in (H, W) based on thread ID.
Definition: tile_traits_standard.h:172
cutlass::TileTraitsStrideMajor::kThreads
static int const kThreads
Number of participating threads.
Definition: tile_traits_standard.h:72
cutlass::TileTraitsStandard
Chooses &#39;best&#39; shape to enable warp raking along contiguous dimension if possible.
Definition: tile_traits_standard.h:194
cutlass::TileTraitsWarpRake::Tile
Tile_ Tile
Shape of tile.
Definition: tile_traits_standard.h:137
cutlass::TileTraitsWarpRake::kWarpsContiguous
static int const kWarpsContiguous
Warps stripmined contiguous dimension.
Definition: tile_traits_standard.h:160
cutlass::TiledThreadOffset::operator()
CUTLASS_HOST_DEVICE Coord< 4 > operator()() const
Computes the logical coordinate from thread shape.
Definition: tile_traits_standard.h:42
cutlass::TileTraitsWarpRake::Delta
Shape< 1, kWarpsStrided, kWarpSize > Delta
The same warp rakes along the contiguous dimension.
Definition: tile_traits_standard.h:166
cutlass::TileTraitsWarpRake::ThreadOffset::operator()
CUTLASS_HOST_DEVICE Coord< 4 > operator()() const
Basic thread offset function computed from a thread shape.
Definition: tile_traits_standard.h:175
cutlass::TiledThreadOffset
Basic thread offset function computed from a thread shape.
Definition: tile_traits_standard.h:39
cutlass::Shape::kH
static int const kH
The height of the cube.
Definition: shape.h:68
cutlass::TileTraitsWarpRake::kThreads
static int const kThreads
Number of participating threads.
Definition: tile_traits_standard.h:140
cutlass::TileTraitsStrideMajor::Delta
Shape< 1, ThreadShape::kH, 1, 1 > Delta
Delta along each dimension.
Definition: tile_traits_standard.h:86
cutlass::TileTraitsStrideMajor::ThreadShape
Shape< 1, kThreads/Tile::kW, Tile::kW, 1 > ThreadShape
Shape of threads.
Definition: tile_traits_standard.h:76
cutlass::TileTraitsWarpRake::kWarpSize
static int const kWarpSize
Hard-coded warp size.
Definition: tile_traits_standard.h:143
__NV_STD_MIN
#define __NV_STD_MIN(a, b)
Select minimum(a, b)
Definition: platform.h:160
cutlass::TileTraitsStandard::Tile
Tile_ Tile
Shape of tile.
Definition: tile_traits_standard.h:196
cutlass::TileTraitsStrideMajor::Tile
Tile_ Tile
Shape of tile.
Definition: tile_traits_standard.h:69
cutlass::TileTraitsWarpRake::kWarpCount
static int const kWarpCount
Number of participating warps.
Definition: tile_traits_standard.h:146
cutlass::TileTraitsWarpRake::ThreadShape
Shape< 1, kWarpsStrided, kWarpsContiguous *kWarpSize > ThreadShape
Arrangement of threads.
Definition: tile_traits_standard.h:163
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
cutlass::TileTraitsStrideMajor
Definition: tile_traits_standard.h:67
cutlass::platform::conditional
std::conditional (true specialization)
Definition: platform.h:343
static_assert
#define static_assert(__e, __m)
Definition: platform.h:145
cutlass::Shape
A Shape implementing Layout Concept describing the dimensions of a cube.
Definition: shape.h:64
cutlass::Coord< 4 >
cutlass::TileTraitsStrideMajor::ThreadOffset
TiledThreadOffset< ThreadShape > ThreadOffset
Computes the initial offset.
Definition: tile_traits_standard.h:92
cutlass::TileTraitsContiguousMajor::Tile
Tile_ Tile
Shape of tile.
Definition: tile_traits_standard.h:102
cutlass::Shape::kW
static int const kW
The width of the cube.
Definition: shape.h:70
cutlass::TileTraitsWarpRake
Tiling in which warps rake across the contiguous dimension.
Definition: tile_traits_standard.h:135
cutlass::TileTraitsStandard::kWarpSize
static int const kWarpSize
Hard-coded warp size.
Definition: tile_traits_standard.h:202
cutlass::TileTraitsContiguousMajor::Delta
Shape< 1, 1, kThreads > Delta
Delta between each thread&#39;s access.
Definition: tile_traits_standard.h:122
cutlass::TileTraitsContiguousMajor::ThreadShape
Shape< 1, 1, kThreads > ThreadShape
Thread shape.
Definition: tile_traits_standard.h:110
cutlass::ShapeCount
Compute derived counted of a Layout Concept based class.
Definition: shape.h:79
cutlass::TileTraitsContiguousMajor::ThreadOffset
TiledThreadOffset< ThreadShape > ThreadOffset
Computes the initial offset.
Definition: tile_traits_standard.h:128
cutlass::TileTraitsStandard::kThreads
static int const kThreads
Number of participating threads.
Definition: tile_traits_standard.h:199
cutlass::TileTraitsContiguousMajor::Iterations
Shape< 1, Tile::kH, Tile::kW/kThreads > Iterations
Number of iterations.
Definition: tile_traits_standard.h:125