CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
default_gemv_core.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  **************************************************************************************************/
32 #pragma once
33 
34 #include "cutlass/cutlass.h"
35 #include "cutlass/array.h"
36 #include "cutlass/numeric_types.h"
37 #include "cutlass/matrix_shape.h"
38 
39 #include "cutlass/layout/matrix.h"
40 
42 
43 #include "cutlass/gemm/gemm.h"
45 
48 
50 
52 namespace cutlass {
53 namespace gemm {
54 namespace threadblock {
55 
58 template <
59  typename Shape_,
60  typename ThreadShape_,
61  typename ElementA_,
62  typename LayoutA_,
63  typename ElementB_,
64  typename LayoutB_,
65  typename ElementC_,
66  typename LayoutC_
67 >
69 
70  using Shape = Shape_;
71  using ThreadShape = ThreadShape_;
72 
73  using LayoutA = LayoutA_;
74  using LayoutB = LayoutB_;
75  using LayoutC = LayoutC_;
76 
77  using ElementA = ElementA_;
78  using ElementB = ElementB_;
79  using ElementC = ElementC_;
80 
81  static int const kThreadsPerN = Shape::kN / ThreadShape::kN;
82 
83  using IteratorPolicyA = typename platform::conditional<
89 
92 
93  using IteratorPolicyB = typename platform::conditional<
99 
102 
103  using IteratorPolicyC = typename platform::conditional<
109 
112 
113  using MmaSimtOp = typename cutlass::gemm::thread::Mma<
115  ElementA,
116  LayoutA,
117  ElementB,
118  LayoutB,
119  ElementC,
120  LayoutC>;
121 
123 
124  // Assertions for correctness
125  static_assert((Shape::kM == 1), "M=1 is required for GEMV");
126 
127  static_assert((ThreadShape::kM == 1), "M=1 is required for GEMV");
128 
129  static_assert(Shape::kK % ThreadShape::kK == 0, "Shape::K must be a multiple of ThreadShape::K");
130 
131  static_assert(((ThreadShape::kK == 1) ||
132  (ThreadShape::kK == 2) ||
133  (ThreadShape::kK == 4) ||
134  (ThreadShape::kK == 8) ||
135  (ThreadShape::kK == 16) ||
136  (ThreadShape::kK == 32)
137  ),
138  "ThreadShape::K must be a 1, 2, 4, 8, 16 or 32");
139 };
140 
142 
143 } // namespace threadblock
144 } // namespace gemm
145 } // namespace cutlass
Describes the size of a matrix tile.
Definition: matrix_shape.h:42
Definition: aligned_buffer.h:35
Shape_ Shape
Definition: default_gemv_core.h:70
std::is_same (false specialization)
Definition: platform.h:394
Templates implementing how threads are mapped to a given tile.
ThreadShape_ ThreadShape
Definition: default_gemv_core.h:71
Defines common types used for all GEMM-like operators.
ElementA_ ElementA
Definition: default_gemv_core.h:77
C++ features that may be otherwise unimplemented for CUDA device functions.
typename platform::conditional< platform::is_same< LayoutC, layout::RowMajor >::value, cutlass::transform::PitchLinearTilePolicyStripminedThreadContiguous< layout::PitchLinearShape< Shape::kN, Shape::kM >, kThreadsPerN, ThreadShape::kN >, cutlass::transform::PitchLinearTilePolicyStripminedThreadStrided< layout::PitchLinearShape< Shape::kM, Shape::kN >, kThreadsPerN, ThreadShape::kM >>::type IteratorPolicyC
Definition: default_gemv_core.h:108
Template defining a shape used by pitch-linear operators.
Definition: pitch_linear.h:43
Statically sized array of elements that accommodates all CUTLASS-supported numeric types and is safe ...
Defines a Shape template for matrix tiles.
typename platform::conditional< platform::is_same< LayoutA, layout::RowMajor >::value, cutlass::transform::PitchLinearTilePolicyStripminedThreadContiguous< layout::PitchLinearShape< Shape::kK, Shape::kM >, 1, ThreadShape::kK >, cutlass::transform::PitchLinearTilePolicyStripminedThreadStrided< layout::PitchLinearShape< Shape::kM, Shape::kK >, 1, ThreadShape::kM >>::type IteratorPolicyA
Definition: default_gemv_core.h:88
typename platform::conditional< platform::is_same< LayoutB, layout::RowMajor >::value, cutlass::transform::PitchLinearTilePolicyStripminedThreadContiguous< layout::PitchLinearShape< Shape::kN, Shape::kK >, kThreadsPerN, ThreadShape::kN >, cutlass::transform::PitchLinearTilePolicyStripminedThreadStrided< layout::PitchLinearShape< Shape::kK, Shape::kN >, kThreadsPerN, ThreadShape::kK >>::type IteratorPolicyB
Definition: default_gemv_core.h:98
ElementC_ ElementC
Definition: default_gemv_core.h:79
MmaSimtOp Operator
Definition: default_gemv_core.h:122
typename cutlass::gemm::thread::Mma< cutlass::gemm::GemmShape< ThreadShape::kM, ThreadShape::kN, Shape::kK >, ElementA, LayoutA, ElementB, LayoutB, ElementC, LayoutC > MmaSimtOp
Definition: default_gemv_core.h:120
Templates exposing architecture support for warp-level multiply-add operations.
Top-level include for all CUTLASS numeric types.
Shape of a matrix multiply-add operation.
Definition: include/cutlass/gemm/gemm.h:57
Definition: default_gemv_core.h:68
std::conditional (true specialization)
Definition: platform.h:325
#define static_assert(__e, __m)
Definition: platform.h:153
LayoutB_ LayoutB
Definition: default_gemv_core.h:74
Definition: transform/threadblock/predicated_tile_iterator.h:133
static int const kThreadsPerN
Definition: default_gemv_core.h:81
Structure to compute the matrix product.
Definition: gemm/thread/mma.h:66
Defines layout functions used by TensorRef and derived classes.
Template for a threadblock-scoped GEMV kernel.
Templates implementing loading of tiles from pitch-linear rank=2 tensors.
ElementB_ ElementB
Definition: default_gemv_core.h:78
LayoutC_ LayoutC
Definition: default_gemv_core.h:75
Basic include for CUTLASS.
LayoutA_ LayoutA
Definition: default_gemv_core.h:73