docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
gpu_mma_fragment.h
Go to the documentation of this file.
1#pragma once
2
3#include <nlohmann/json_fwd.hpp>
4#include <ostream>
5#include <string>
8#include "sdfg/types/type.h"
9
10namespace sdfg::gpu {
11
12class GpuArch;
13
14enum class MmaFragmentType { A = 1, B = 2, C = 3 };
15
17 int m;
18 int n;
19 int k;
20
21 std::string toStr() const;
22
23 std::string dim_str(MmaFragmentType for_type) const;
24
26
27 static MmaBlockSize parse_block_size(const std::string& block_size_str);
28};
29
30std::ostream& operator<<(std::ostream& os, const MmaBlockSize& block_size);
31
38
39 int total_blocks() const {
40 return blocks_m * blocks_n;
41 }
42};
43
77
83
84constexpr const char* mma_fragment_layout_to_string(MmaFragmentLayout layout) {
85 switch (layout) {
87 return "*";
89 return "row_major";
91 return "col_major";
92 default:
93 throw std::invalid_argument("invalid MMA fragment layout");
94 }
95}
96
98 virtual ~GpuMmaSupport() = default;
99
101 types::PrimitiveType input_type, types::PrimitiveType output_type, types::PrimitiveType desired_acc_type
102 ) const = 0;
106
107 GpuMmaSupport() = default;
108
110 const MmaBlockSize& block_size, types::PrimitiveType input_type, types::PrimitiveType acc_type
111 ) const = 0;
112
114
115 static int get_integer_block_count(const symbolic::Expression& size, uint16_t block_size);
116
118 static int get_ceil_block_count(const symbolic::Expression& size, uint16_t block_size);
119
120 virtual bool supported_types(types::PrimitiveType input_type, types::PrimitiveType output_type) const = 0;
121
122 virtual std::optional<GpuMmaTiling> get_mma_tiling(
123 const symbolic::MultiExpression& res_shape,
124 types::PrimitiveType input_type,
125 types::PrimitiveType acc_type,
126 const MmaBlockSize* block_size_hint,
127 const BlockCounts* wave_tile_hint
128 ) const = 0;
129
135 virtual std::optional<GpuMmaTiling> get_ragged_mma_tiling(
136 const symbolic::MultiExpression& padded_shape,
137 types::PrimitiveType input_type,
138 types::PrimitiveType output_type,
139 types::PrimitiveType acc_type,
140 const MmaBlockSize* block_size_hint,
141 const BlockCounts* wave_tile_hint
142 ) const {
143 return std::nullopt;
144 }
145
147 types::StorageType& storage_type, const GpuMmaTiling& tiling, MmaFragmentType type, MmaFragmentLayout layout
148 ) const = 0;
149
150 virtual std::vector<MmaBlockSize>
152
153protected:
154 static int get_storage_type_arg_as_int(const types::StorageType& storage, int idx);
155};
156
170 symbolic::Expression rows = SymEngine::null;
171 symbolic::Expression cols = SymEngine::null;
172
173 bool clipped() const {
174 return !rows.is_null() || !cols.is_null();
175 }
176
177 std::string toStr() const;
179 void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression);
180 void replace(const symbolic::ExpressionMapping& replacements);
181
183 [[nodiscard]] std::optional<math::tensor::TensorLayout>
184 to_tensor_layout(const MmaBlockSize& block_size, MmaFragmentType frag) const;
185
188 const symbolic::MultiExpression& shape, const MmaBlockSize& block_size, MmaFragmentType frag
189 ) const;
190
191 static std::optional<GpuMmaFromMemoryLayout> from_tensor_layout(const math::tensor::TensorLayout& layout);
192};
193
194std::ostream& operator<<(std::ostream& os, const GpuMmaFromMemoryLayout& layout);
195
196// JSON (de)serialization helpers shared by the MMA library-node serializers.
197void serialize_mma_block_size(nlohmann::json& j, const MmaBlockSize& block_size);
199
200void serialize_mma_from_memory_layout(nlohmann::json& j, const GpuMmaFromMemoryLayout& layout);
202
203} // namespace sdfg::gpu
Definition gpu_arch.h:14
The metadata associated with a addressing a tensor in elements Meant to be used with TensorNodes to d...
Definition tensor_layout.h:20
Represents the storage location and management characteristics of data.
Definition type.h:64
std::vector< Expression > MultiExpression
Vector of symbolic expressions for multi-dimensional operations.
Definition symbolic.h:89
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
std::set< Symbol, SymEngine::RCPBasicKeyLess > SymbolSet
Ordered set of symbols.
Definition symbolic.h:95
SymEngine::map_basic_basic ExpressionMapping
Definition symbolic.h:109
Library node definitions for calling functions beyond simple instructions.
StringEnum ImplementationType
Implementation type identifier for library nodes.
Definition library_node.h:75
Definition cuda_arch.h:11
MmaFragmentLayout
Definition gpu_mma_fragment.h:78
@ MMA_LAYOUT_COL_MAJOR
Definition gpu_mma_fragment.h:81
@ MMA_LAYOUT_ROW_MAJOR
Definition gpu_mma_fragment.h:80
@ MMA_LAYOUT_UNSPECIFIED
Definition gpu_mma_fragment.h:79
GpuMmaFromMemoryLayout deserialize_mma_from_memory_layout(const nlohmann::json &j)
void serialize_mma_block_size(nlohmann::json &j, const MmaBlockSize &block_size)
void serialize_mma_from_memory_layout(nlohmann::json &j, const GpuMmaFromMemoryLayout &layout)
constexpr const char * mma_fragment_layout_to_string(MmaFragmentLayout layout)
Definition gpu_mma_fragment.h:84
std::ostream & operator<<(std::ostream &os, const MmaBlockSize &block_size)
MmaFragmentType
Definition gpu_mma_fragment.h:14
@ C
Definition gpu_mma_fragment.h:14
@ A
Definition gpu_mma_fragment.h:14
@ B
Definition gpu_mma_fragment.h:14
MmaBlockSize deserialize_mma_block_size(const nlohmann::json &j)
PrimitiveType
Enumeration of all primitive data types supported by sdfglib.
Definition type.h:35
@ Void
Void type (0 bits).
Definition type.h:36
Grouping of MMA blocks.
Definition gpu_mma_fragment.h:35
int total_blocks() const
Definition gpu_mma_fragment.h:39
int blocks_n
Definition gpu_mma_fragment.h:37
int blocks_m
Definition gpu_mma_fragment.h:36
Describes how a single MMA fragment maps to memory relative to a base pointer.
Definition gpu_mma_fragment.h:163
std::optional< math::tensor::TensorLayout > to_tensor_layout(const MmaBlockSize &block_size, MmaFragmentType frag) const
The accessed tile; a clipped fragment reports its clipped (in-bounds) extents min(block,...
MmaFragmentLayout layout
memory layout of the tile
Definition gpu_mma_fragment.h:166
symbolic::Expression rows
Clip of a ragged fragment: only logical rows r < rows and columns c < cols (from the fragment origin)...
Definition gpu_mma_fragment.h:170
bool matches_access_shape(const symbolic::MultiExpression &shape, const MmaBlockSize &block_size, MmaFragmentType frag) const
Whether shape is this fragment's block shape or its clipped shape (see to_tensor_layout).
symbolic::Expression ldstride
leading-dimension stride
Definition gpu_mma_fragment.h:165
symbolic::Expression cols
Definition gpu_mma_fragment.h:171
void replace(const symbolic::ExpressionMapping &replacements)
bool clipped() const
Definition gpu_mma_fragment.h:173
static std::optional< GpuMmaFromMemoryLayout > from_tensor_layout(const math::tensor::TensorLayout &layout)
symbolic::Expression offset
element offset added to the base pointer
Definition gpu_mma_fragment.h:164
void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression)
void collect_symbols(symbolic::SymbolSet &syms) const
virtual std::optional< GpuMmaTiling > get_ragged_mma_tiling(const symbolic::MultiExpression &padded_shape, types::PrimitiveType input_type, types::PrimitiveType output_type, types::PrimitiveType acc_type, const MmaBlockSize *block_size_hint, const BlockCounts *wave_tile_hint) const
Tiling for a ragged problem: padded_shape is a constant upper bound of each extent that need not be a...
Definition gpu_mma_fragment.h:135
static int get_integer_block_count(const symbolic::Expression &size, uint16_t block_size)
virtual std::vector< MmaBlockSize > get_supported_block_sizes(types::PrimitiveType input_type, types::PrimitiveType acc_type) const =0
types::PrimitiveType get_accumulator_type(types::PrimitiveType input_type, types::PrimitiveType output_type) const
Definition gpu_mma_fragment.h:103
virtual std::optional< GpuMmaTiling > get_mma_tiling(const symbolic::MultiExpression &res_shape, types::PrimitiveType input_type, types::PrimitiveType acc_type, const MmaBlockSize *block_size_hint, const BlockCounts *wave_tile_hint) const =0
static int get_ceil_block_count(const symbolic::Expression &size, uint16_t block_size)
ceil(size / block_size) for a positive integer size, otherwise 0.
static int get_storage_type_arg_as_int(const types::StorageType &storage, int idx)
virtual bool is_valid_block_size(const MmaBlockSize &block_size, types::PrimitiveType input_type, types::PrimitiveType acc_type) const =0
virtual types::PrimitiveType get_accumulator_type(types::PrimitiveType input_type, types::PrimitiveType output_type, types::PrimitiveType desired_acc_type) const =0
virtual data_flow::ImplementationType get_mma_impl_type(const GpuMmaTiling &tiling) const =0
virtual void set_mma_fragment_storage_type(types::StorageType &storage_type, const GpuMmaTiling &tiling, MmaFragmentType type, MmaFragmentLayout layout) const =0
virtual bool supported_types(types::PrimitiveType input_type, types::PrimitiveType output_type) const =0
virtual ~GpuMmaSupport()=default
Definition gpu_mma_fragment.h:44
int get_mma_blocks_n_per_wavefront() const
static bool wave_tile_divides(const BlockCounts &wave_tiling, const BlockCounts &macro_block)
Check that we can use the given wave tiling for the given macro block tiling, i.e.
types::PrimitiveType acc_type
The type used by the MMA hardware to accumulate the results of the MMA operation.
Definition gpu_mma_fragment.h:60
BlockCounts macro_tiling
How many MMA blocks will be grouped together in a macro block / on a SM or CU This controls how much ...
Definition gpu_mma_fragment.h:56
BlockCounts wave_tiling
How many MMA blocks will be grouped together in a single wavefront / warp.
Definition gpu_mma_fragment.h:52
int impl_details
implementation-specific details, e.g. for ROCm MFMA variant selection
Definition gpu_mma_fragment.h:63
MmaBlockSize mma_block_size
The MMA block size (m, n, k) in elements.
Definition gpu_mma_fragment.h:47
int get_mma_blocks_m_per_wavefront() const
int threads_per_mma_wavefront
How many threads will work together on 1 MMA block.
Definition gpu_mma_fragment.h:49
Definition gpu_mma_fragment.h:16
std::string dim_str(MmaFragmentType for_type) const
int k
Definition gpu_mma_fragment.h:19
int m
Definition gpu_mma_fragment.h:17
symbolic::MultiExpression get_shape(MmaFragmentType frag) const
static MmaBlockSize parse_block_size(const std::string &block_size_str)
std::string toStr() const
int n
Definition gpu_mma_fragment.h:18
Symbolic system for integer-based symbol analysis.
Core type system definitions for sdfglib.