LLVM 22.0.0git
NVPTXSubtarget.h
Go to the documentation of this file.
1//=====-- NVPTXSubtarget.h - Define Subtarget for the NVPTX ---*- C++ -*--====//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the NVPTX specific subclass of TargetSubtarget.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
14#define LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
15
16#include "NVPTX.h"
17#include "NVPTXFrameLowering.h"
18#include "NVPTXISelLowering.h"
19#include "NVPTXInstrInfo.h"
20#include "NVPTXRegisterInfo.h"
22#include "llvm/IR/DataLayout.h"
25#include <string>
26
27#define GET_SUBTARGETINFO_HEADER
28#include "NVPTXGenSubtargetInfo.inc"
29
30namespace llvm {
31
33 virtual void anchor();
34 std::string TargetName;
35
36 // PTX version x.y is represented as 10*x+y, e.g. 3.1 == 31
37 unsigned PTXVersion;
38
39 // Full SM version x.y is represented as 100*x+10*y+feature, e.g. 3.1 == 310
40 // sm_90a == 901
41 unsigned int FullSmVersion;
42
43 // SM version x.y is represented as 10*x+y, e.g. 3.1 == 31. Derived from
44 // FullSmVersion.
45 unsigned int SmVersion;
46
47 NVPTXInstrInfo InstrInfo;
49 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
50
51 // NVPTX does not have any call stack frame, but need a NVPTX specific
52 // FrameLowering class because TargetFrameLowering is abstract.
53 NVPTXFrameLowering FrameLowering;
54
55public:
56 /// This constructor initializes the data members to match that
57 /// of the specified module.
58 ///
59 NVPTXSubtarget(const Triple &TT, const std::string &CPU,
60 const std::string &FS, const NVPTXTargetMachine &TM);
61
62 ~NVPTXSubtarget() override;
63
64 const TargetFrameLowering *getFrameLowering() const override {
65 return &FrameLowering;
66 }
67 const NVPTXInstrInfo *getInstrInfo() const override { return &InstrInfo; }
68 const NVPTXRegisterInfo *getRegisterInfo() const override {
69 return &InstrInfo.getRegisterInfo();
70 }
71 const NVPTXTargetLowering *getTargetLowering() const override {
72 return &TLInfo;
73 }
74
75 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
76
77 // Checks PTX version and family-specific and architecture-specific SM
78 // versions. For example, sm_100{f/a} and any future variants in the same
79 // family will match for any PTX version greater than or equal to
80 // `PTXVersion`.
81 bool hasPTXWithFamilySMs(unsigned PTXVersion,
82 ArrayRef<unsigned> SMVersions) const;
83 // Checks PTX version and architecture-specific SM versions.
84 // For example, sm_100{a} will match for any PTX version greater than or equal
85 // to `PTXVersion`.
86 bool hasPTXWithAccelSMs(unsigned PTXVersion,
87 ArrayRef<unsigned> SMVersions) const;
88
89 bool has256BitVectorLoadStore(unsigned AS) const {
90 return SmVersion >= 100 && PTXVersion >= 88 &&
92 }
94 return SmVersion >= 50 && PTXVersion >= 83;
95 }
96 bool hasAtomAddF64() const { return SmVersion >= 60; }
97 bool hasAtomScope() const { return SmVersion >= 60; }
98 bool hasAtomBitwise64() const { return SmVersion >= 32; }
99 bool hasAtomMinMax64() const { return SmVersion >= 32; }
100 bool hasAtomCas16() const { return SmVersion >= 70 && PTXVersion >= 63; }
101 bool hasAtomSwap128() const { return SmVersion >= 90 && PTXVersion >= 83; }
102 bool hasClusters() const { return SmVersion >= 90 && PTXVersion >= 78; }
103 bool hasLDG() const { return SmVersion >= 32; }
104 bool hasHWROT32() const { return SmVersion >= 32; }
105 bool hasBrx() const { return SmVersion >= 30 && PTXVersion >= 60; }
106 bool hasFP16Math() const { return SmVersion >= 53; }
107 bool hasBF16Math() const { return SmVersion >= 80; }
108 bool allowFP16Math() const;
109 bool hasMaskOperator() const { return PTXVersion >= 71; }
110 bool hasNoReturn() const { return SmVersion >= 30 && PTXVersion >= 64; }
111 // Does SM & PTX support memory orderings (weak and atomic: relaxed, acquire,
112 // release, acq_rel, sc) ?
113 bool hasMemoryOrdering() const { return SmVersion >= 70 && PTXVersion >= 60; }
114 // Does SM & PTX support .acquire and .release qualifiers for fence?
116 return SmVersion >= 90 && PTXVersion >= 86;
117 }
118 // Does SM & PTX support atomic relaxed MMIO operations ?
119 bool hasRelaxedMMIO() const { return SmVersion >= 70 && PTXVersion >= 82; }
120 bool hasDotInstructions() const {
121 return SmVersion >= 61 && PTXVersion >= 50;
122 }
123
124 // Checks following instructions support:
125 // - tcgen05.ld/st
126 // - tcgen05.alloc/dealloc/relinquish
127 // - tcgen05.cp
128 // - tcgen05.fence/wait
129 // - tcgen05.commit
130 // - tcgen05.mma
132 // sm_101 renamed to sm_110 in PTX 9.0
133 return hasPTXWithFamilySMs(90, {100, 110}) ||
134 hasPTXWithFamilySMs(88, {100, 101}) ||
135 hasPTXWithAccelSMs(86, {100, 101});
136 }
137
138 // Checks tcgen05.shift instruction support.
140 // sm_101 renamed to sm_110 in PTX 9.0
141 return hasPTXWithAccelSMs(90, {100, 110, 103}) ||
142 hasPTXWithAccelSMs(88, {100, 101, 103}) ||
143 hasPTXWithAccelSMs(86, {100, 101});
144 }
145
147 return hasPTXWithFamilySMs(88, {100}) || hasPTXWithAccelSMs(86, {100});
148 }
149
150 bool hasTcgen05MMAI8Kind() const {
151 return hasPTXWithAccelSMs(90, {100, 110}) ||
152 hasPTXWithAccelSMs(86, {100, 101});
153 }
154
156 return hasPTXWithAccelSMs(90, {100, 110, 103}) ||
157 hasPTXWithAccelSMs(87, {100, 101, 103});
158 }
159
161 return hasPTXWithAccelSMs(90, {100, 110, 103}) ||
162 hasPTXWithAccelSMs(86, {100, 101, 103});
163 }
164
165 bool hasReduxSyncF32() const {
166 return hasPTXWithFamilySMs(88, {100}) || hasPTXWithAccelSMs(86, {100});
167 }
168
169 bool hasMMABlockScale() const {
170 return hasPTXWithFamilySMs(88, {120}) || hasPTXWithAccelSMs(87, {120});
171 }
172
174 return hasPTXWithAccelSMs(87, {120, 121});
175 }
176
177 // f32x2 instructions in Blackwell family
178 bool hasF32x2Instructions() const;
179
180 // Checks support for following in TMA:
181 // - cta_group::1/2 support
182 // - im2col_w/w_128 mode support
183 // - tile_gather4 mode support
184 // - tile_scatter4 mode support
186 return hasPTXWithFamilySMs(90, {100, 110}) ||
187 hasPTXWithFamilySMs(88, {100, 101}) ||
188 hasPTXWithAccelSMs(86, {100, 101});
189 }
190
191 // Checks support for conversions involving e4m3x2 and e5m2x2.
193 if (PTXVersion >= 81)
194 return SmVersion >= 89;
195
196 if (PTXVersion >= 78)
197 return SmVersion >= 90;
198
199 return false;
200 }
201
202 // Checks support for conversions involving the following types:
203 // - e2m3x2/e3m2x2
204 // - e2m1x2
205 // - ue8m0x2
207 return hasPTXWithFamilySMs(90, {100, 110, 120}) ||
208 hasPTXWithFamilySMs(88, {100, 101, 120}) ||
209 hasPTXWithAccelSMs(86, {100, 101, 120});
210 }
211
213 return hasPTXWithFamilySMs(90, {90, 100, 110, 120}) ||
214 hasPTXWithFamilySMs(88, {90, 100, 101, 120}) ||
215 hasPTXWithAccelSMs(83, {90, 100, 101, 120});
216 }
217
218 bool hasTensormapReplaceElemtypeSupport(unsigned value) const {
219 if (value >= static_cast<unsigned>(nvvm::TensormapElemType::B4x16))
220 return hasPTXWithFamilySMs(90, {100, 110, 120}) ||
221 hasPTXWithFamilySMs(88, {100, 101, 120}) ||
222 hasPTXWithAccelSMs(87, {100, 101, 120});
223
225 }
226
228 return hasPTXWithFamilySMs(90, {100, 110, 120}) ||
229 hasPTXWithFamilySMs(88, {100, 101, 120}) ||
230 hasPTXWithAccelSMs(87, {100, 101, 120});
231 }
232
233 bool hasTensormapReplaceSwizzleModeSupport(unsigned value) const {
234 if (value == static_cast<unsigned>(nvvm::TensormapSwizzleMode::SWIZZLE_96B))
235 return hasPTXWithAccelSMs(88, {103});
236
238 }
239
241 return hasPTXWithFamilySMs(90, {100, 110, 120}) ||
242 hasPTXWithFamilySMs(88, {100, 101, 120}) ||
243 hasPTXWithAccelSMs(86, {100, 101, 120});
244 }
245
246 bool hasSetMaxNRegSupport() const {
247 return hasPTXWithFamilySMs(90, {100, 110, 120}) ||
248 hasPTXWithFamilySMs(88, {100, 101, 120}) ||
249 hasPTXWithAccelSMs(86, {100, 101, 120}) ||
250 hasPTXWithAccelSMs(80, {90});
251 }
252
254 return hasPTXWithFamilySMs(90, {100, 110, 120}) ||
255 hasPTXWithFamilySMs(88, {100, 101, 120}) ||
256 hasPTXWithAccelSMs(86, {100, 101, 120});
257 }
258
259 // Prior to CUDA 12.3 ptxas did not recognize that the trap instruction
260 // terminates a basic block. Instead, it would assume that control flow
261 // continued to the next instruction. The next instruction could be in the
262 // block that's lexically below it. This would lead to a phantom CFG edges
263 // being created within ptxas. This issue was fixed in CUDA 12.3. Thus, when
264 // PTX ISA versions 8.3+ we can confidently say that the bug will not be
265 // present.
266 bool hasPTXASUnreachableBug() const { return PTXVersion < 83; }
267 bool hasCvtaParam() const { return SmVersion >= 70 && PTXVersion >= 77; }
269 return hasPTXWithAccelSMs(87, {100, 103});
270 }
271 unsigned int getFullSmVersion() const { return FullSmVersion; }
272 unsigned int getSmVersion() const { return getFullSmVersion() / 10; }
273 unsigned int getSmFamilyVersion() const { return getFullSmVersion() / 100; }
274 // GPUs with "a" suffix have architecture-accelerated features that are
275 // supported on the specified architecture only, hence such targets do not
276 // follow the onion layer model. hasArchAccelFeatures() allows distinguishing
277 // such GPU variants from the base GPU architecture.
278 // - false represents non-accelerated architecture.
279 // - true represents architecture-accelerated variant.
280 bool hasArchAccelFeatures() const {
281 return (getFullSmVersion() & 1) && PTXVersion >= 80;
282 }
283 // GPUs with 'f' suffix have architecture-accelerated features which are
284 // portable across all future architectures under same SM major. For example,
285 // sm_100f features will work for sm_10X*f*/sm_10X*a* future architectures.
286 // - false represents non-family-specific architecture.
287 // - true represents family-specific variant.
289 return getFullSmVersion() % 10 == 2 ? PTXVersion >= 88
291 }
292 // If the user did not provide a target we default to the `sm_30` target.
293 std::string getTargetName() const {
294 return TargetName.empty() ? "sm_30" : TargetName;
295 }
296 bool hasTargetName() const { return !TargetName.empty(); }
297
298 bool hasNativeBF16Support(int Opcode) const;
299
300 // Get maximum value of required alignments among the supported data types.
301 // From the PTX ISA doc, section 8.2.3:
302 // The memory consistency model relates operations executed on memory
303 // locations with scalar data-types, which have a maximum size and alignment
304 // of 64 bits. Memory operations with a vector data-type are modelled as a
305 // set of equivalent memory operations with a scalar data-type, executed in
306 // an unspecified order on the elements in the vector.
307 unsigned getMaxRequiredAlignment() const { return 8; }
308 // Get the smallest cmpxchg word size that the hardware supports.
309 unsigned getMinCmpXchgSizeInBits() const { return 32; }
310
311 unsigned getPTXVersion() const { return PTXVersion; }
312
315
316 void failIfClustersUnsupported(std::string const &FailureMessage) const;
317};
318
319} // End llvm namespace
320
321#endif
NVPTX address space definition.
This file contains the definitions of the enumerations and flags associated with NVVM Intrinsics,...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool hasMMASparseBlockScaleF4() const
bool hasTcgen05MMASparseMxf4() const
const NVPTXInstrInfo * getInstrInfo() const override
void failIfClustersUnsupported(std::string const &FailureMessage) const
bool hasTcgen05MMAI8Kind() const
bool hasTMABlackwellSupport() const
bool hasPTXWithAccelSMs(unsigned PTXVersion, ArrayRef< unsigned > SMVersions) const
bool hasTensormapReplaceSwizzleModeSupport(unsigned value) const
std::string getTargetName() const
bool hasTcgen05MMASparseMxf4nvf4() const
unsigned getMaxRequiredAlignment() const
bool hasClusterLaunchControlTryCancelMulticastSupport() const
bool hasAtomMinMax64() const
bool hasTcgen05InstSupport() const
bool hasAtomAddF64() const
bool hasSplitAcquireAndReleaseFences() const
bool hasConvertWithStochasticRounding() const
bool hasMaskOperator() const
bool hasFP8ConversionSupport() const
const NVPTXTargetLowering * getTargetLowering() const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
unsigned getMinCmpXchgSizeInBits() const
unsigned getPTXVersion() const
bool hasCvtaParam() const
~NVPTXSubtarget() override
bool hasNativeBF16Support(int Opcode) const
bool hasUsedBytesMaskPragma() const
bool hasTensormapReplaceElemtypeSupport(unsigned value) const
const NVPTXRegisterInfo * getRegisterInfo() const override
unsigned int getFullSmVersion() const
bool hasTensormapReplaceSupport() const
unsigned int getSmVersion() const
bool hasDotInstructions() const
bool hasTcgen05MMAScaleInputDImm() const
bool hasFamilySpecificFeatures() const
bool hasAtomBitwise64() const
bool hasPTXWithFamilySMs(unsigned PTXVersion, ArrayRef< unsigned > SMVersions) const
bool hasTcgen05ShiftSupport() const
bool hasRelaxedMMIO() const
bool hasTargetName() const
bool hasSetMaxNRegSupport() const
bool hasAtomSwap128() const
bool hasF32x2Instructions() const
bool hasReduxSyncF32() const
unsigned int getSmFamilyVersion() const
const TargetFrameLowering * getFrameLowering() const override
bool hasAtomScope() const
bool hasMMABlockScale() const
bool hasLdStmatrixBlackwellSupport() const
bool hasAtomCas16() const
NVPTXSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const NVPTXTargetMachine &TM)
This constructor initializes the data members to match that of the specified module.
bool hasNarrowFPConversionSupport() const
bool hasMemoryOrdering() const
bool hasArchAccelFeatures() const
NVPTXSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool has256BitVectorLoadStore(unsigned AS) const
bool hasTensormapReplaceSwizzleAtomicitySupport() const
bool hasPTXASUnreachableBug() const
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Information about stack frame layout on the target.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26