1 | //===- Chipset.h - AMDGPU Chipset version struct ----------*- 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 | #ifndef MLIR_DIALECT_AMDGPU_UTILS_CHIPSET_H_ |
9 | #define MLIR_DIALECT_AMDGPU_UTILS_CHIPSET_H_ |
10 | |
11 | #include "mlir/Support/LLVM.h" |
12 | #include <tuple> |
13 | |
14 | namespace mlir::amdgpu { |
15 | |
16 | /// Represents the amdgpu gfx chipset version, e.g., gfx90a, gfx942, gfx1103. |
17 | /// Note that the leading digits form a decimal number, while the last two |
18 | /// digits for a hexadecimal number. For example: |
19 | /// gfx942 --> major = 9, minor = 0x4, stepping = 0x2 |
20 | /// gfx90a --> major = 9, minor = 0x0, stepping = 0xa |
21 | /// gfx1103 --> major = 10, minor = 0x0, stepping = 0x3 |
22 | struct Chipset { |
23 | unsigned majorVersion = 0; // The major version (decimal). |
24 | unsigned minorVersion = 0; // The minor version (hexadecimal). |
25 | unsigned steppingVersion = 0; // The stepping version (hexadecimal). |
26 | |
27 | constexpr Chipset() = default; |
28 | constexpr Chipset(unsigned major, unsigned minor, unsigned stepping) |
29 | : majorVersion(major), minorVersion(minor), steppingVersion(stepping) {}; |
30 | |
31 | /// Parses the chipset version string and returns the chipset on success, and |
32 | /// failure otherwise. |
33 | static FailureOr<Chipset> parse(StringRef name); |
34 | |
35 | std::tuple<unsigned, unsigned, unsigned> asTuple() const { |
36 | return {majorVersion, minorVersion, steppingVersion}; |
37 | } |
38 | |
39 | #define DEFINE_COMP_OPERATOR(OPERATOR) \ |
40 | friend bool operator OPERATOR(const Chipset &lhs, const Chipset &rhs) { \ |
41 | return lhs.asTuple() OPERATOR rhs.asTuple(); \ |
42 | } |
43 | DEFINE_COMP_OPERATOR(==) |
44 | DEFINE_COMP_OPERATOR(!=) |
45 | DEFINE_COMP_OPERATOR(<) |
46 | DEFINE_COMP_OPERATOR(<=) |
47 | DEFINE_COMP_OPERATOR(>) |
48 | DEFINE_COMP_OPERATOR(>=) |
49 | #undef DEFINE_COMP_OPERATOR |
50 | }; |
51 | |
52 | inline bool hasOcpFp8(const Chipset &chipset) { |
53 | return (chipset.majorVersion == 9 && chipset.minorVersion >= 5) || |
54 | chipset.majorVersion >= 12; |
55 | } |
56 | |
57 | } // namespace mlir::amdgpu |
58 | |
59 | #endif |
60 | |