Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / Support / AMDHSAKernelDescriptor.h
blobdca1a3137ac39cd8fbf56e740cd1099f62600b52
1 //===--- AMDHSAKernelDescriptor.h -----------------------------*- 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 /// \file
10 /// AMDHSA kernel descriptor definitions. For more information, visit
11 /// https://llvm.org/docs/AMDGPUUsage.html#kernel-descriptor
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_AMDHSAKERNELDESCRIPTOR_H
16 #define LLVM_SUPPORT_AMDHSAKERNELDESCRIPTOR_H
18 #include <cstddef>
19 #include <cstdint>
21 // Gets offset of specified member in specified type.
22 #ifndef offsetof
23 #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE*)0)->MEMBER)
24 #endif // offsetof
26 // Creates enumeration entries used for packing bits into integers. Enumeration
27 // entries include bit shift amount, bit width, and bit mask.
28 #ifndef AMDHSA_BITS_ENUM_ENTRY
29 #define AMDHSA_BITS_ENUM_ENTRY(NAME, SHIFT, WIDTH) \
30 NAME ## _SHIFT = (SHIFT), \
31 NAME ## _WIDTH = (WIDTH), \
32 NAME = (((1 << (WIDTH)) - 1) << (SHIFT))
33 #endif // AMDHSA_BITS_ENUM_ENTRY
35 // Gets bits for specified bit mask from specified source.
36 #ifndef AMDHSA_BITS_GET
37 #define AMDHSA_BITS_GET(SRC, MSK) ((SRC & MSK) >> MSK ## _SHIFT)
38 #endif // AMDHSA_BITS_GET
40 // Sets bits for specified bit mask in specified destination.
41 #ifndef AMDHSA_BITS_SET
42 #define AMDHSA_BITS_SET(DST, MSK, VAL) \
43 DST &= ~MSK; \
44 DST |= ((VAL << MSK ## _SHIFT) & MSK)
45 #endif // AMDHSA_BITS_SET
47 namespace llvm {
48 namespace amdhsa {
50 // Floating point rounding modes. Must match hardware definition.
51 enum : uint8_t {
52 FLOAT_ROUND_MODE_NEAR_EVEN = 0,
53 FLOAT_ROUND_MODE_PLUS_INFINITY = 1,
54 FLOAT_ROUND_MODE_MINUS_INFINITY = 2,
55 FLOAT_ROUND_MODE_ZERO = 3,
58 // Floating point denorm modes. Must match hardware definition.
59 enum : uint8_t {
60 FLOAT_DENORM_MODE_FLUSH_SRC_DST = 0,
61 FLOAT_DENORM_MODE_FLUSH_DST = 1,
62 FLOAT_DENORM_MODE_FLUSH_SRC = 2,
63 FLOAT_DENORM_MODE_FLUSH_NONE = 3,
66 // System VGPR workitem IDs. Must match hardware definition.
67 enum : uint8_t {
68 SYSTEM_VGPR_WORKITEM_ID_X = 0,
69 SYSTEM_VGPR_WORKITEM_ID_X_Y = 1,
70 SYSTEM_VGPR_WORKITEM_ID_X_Y_Z = 2,
71 SYSTEM_VGPR_WORKITEM_ID_UNDEFINED = 3,
74 // Compute program resource register 1. Must match hardware definition.
75 #define COMPUTE_PGM_RSRC1(NAME, SHIFT, WIDTH) \
76 AMDHSA_BITS_ENUM_ENTRY(COMPUTE_PGM_RSRC1_ ## NAME, SHIFT, WIDTH)
77 enum : int32_t {
78 COMPUTE_PGM_RSRC1(GRANULATED_WORKITEM_VGPR_COUNT, 0, 6),
79 COMPUTE_PGM_RSRC1(GRANULATED_WAVEFRONT_SGPR_COUNT, 6, 4),
80 COMPUTE_PGM_RSRC1(PRIORITY, 10, 2),
81 COMPUTE_PGM_RSRC1(FLOAT_ROUND_MODE_32, 12, 2),
82 COMPUTE_PGM_RSRC1(FLOAT_ROUND_MODE_16_64, 14, 2),
83 COMPUTE_PGM_RSRC1(FLOAT_DENORM_MODE_32, 16, 2),
84 COMPUTE_PGM_RSRC1(FLOAT_DENORM_MODE_16_64, 18, 2),
85 COMPUTE_PGM_RSRC1(PRIV, 20, 1),
86 COMPUTE_PGM_RSRC1(ENABLE_DX10_CLAMP, 21, 1),
87 COMPUTE_PGM_RSRC1(DEBUG_MODE, 22, 1),
88 COMPUTE_PGM_RSRC1(ENABLE_IEEE_MODE, 23, 1),
89 COMPUTE_PGM_RSRC1(BULKY, 24, 1),
90 COMPUTE_PGM_RSRC1(CDBG_USER, 25, 1),
91 COMPUTE_PGM_RSRC1(FP16_OVFL, 26, 1), // GFX9+
92 COMPUTE_PGM_RSRC1(RESERVED0, 27, 5),
94 #undef COMPUTE_PGM_RSRC1
96 // Compute program resource register 2. Must match hardware definition.
97 #define COMPUTE_PGM_RSRC2(NAME, SHIFT, WIDTH) \
98 AMDHSA_BITS_ENUM_ENTRY(COMPUTE_PGM_RSRC2_ ## NAME, SHIFT, WIDTH)
99 enum : int32_t {
100 COMPUTE_PGM_RSRC2(ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET, 0, 1),
101 COMPUTE_PGM_RSRC2(USER_SGPR_COUNT, 1, 5),
102 COMPUTE_PGM_RSRC2(ENABLE_TRAP_HANDLER, 6, 1),
103 COMPUTE_PGM_RSRC2(ENABLE_SGPR_WORKGROUP_ID_X, 7, 1),
104 COMPUTE_PGM_RSRC2(ENABLE_SGPR_WORKGROUP_ID_Y, 8, 1),
105 COMPUTE_PGM_RSRC2(ENABLE_SGPR_WORKGROUP_ID_Z, 9, 1),
106 COMPUTE_PGM_RSRC2(ENABLE_SGPR_WORKGROUP_INFO, 10, 1),
107 COMPUTE_PGM_RSRC2(ENABLE_VGPR_WORKITEM_ID, 11, 2),
108 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_ADDRESS_WATCH, 13, 1),
109 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_MEMORY, 14, 1),
110 COMPUTE_PGM_RSRC2(GRANULATED_LDS_SIZE, 15, 9),
111 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION, 24, 1),
112 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_FP_DENORMAL_SOURCE, 25, 1),
113 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO, 26, 1),
114 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW, 27, 1),
115 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW, 28, 1),
116 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_IEEE_754_FP_INEXACT, 29, 1),
117 COMPUTE_PGM_RSRC2(ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO, 30, 1),
118 COMPUTE_PGM_RSRC2(RESERVED0, 31, 1),
120 #undef COMPUTE_PGM_RSRC2
122 // Kernel code properties. Must be kept backwards compatible.
123 #define KERNEL_CODE_PROPERTY(NAME, SHIFT, WIDTH) \
124 AMDHSA_BITS_ENUM_ENTRY(KERNEL_CODE_PROPERTY_ ## NAME, SHIFT, WIDTH)
125 enum : int32_t {
126 KERNEL_CODE_PROPERTY(ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER, 0, 1),
127 KERNEL_CODE_PROPERTY(ENABLE_SGPR_DISPATCH_PTR, 1, 1),
128 KERNEL_CODE_PROPERTY(ENABLE_SGPR_QUEUE_PTR, 2, 1),
129 KERNEL_CODE_PROPERTY(ENABLE_SGPR_KERNARG_SEGMENT_PTR, 3, 1),
130 KERNEL_CODE_PROPERTY(ENABLE_SGPR_DISPATCH_ID, 4, 1),
131 KERNEL_CODE_PROPERTY(ENABLE_SGPR_FLAT_SCRATCH_INIT, 5, 1),
132 KERNEL_CODE_PROPERTY(ENABLE_SGPR_PRIVATE_SEGMENT_SIZE, 6, 1),
133 KERNEL_CODE_PROPERTY(RESERVED0, 7, 9),
135 #undef KERNEL_CODE_PROPERTY
137 // Kernel descriptor. Must be kept backwards compatible.
138 struct kernel_descriptor_t {
139 uint32_t group_segment_fixed_size;
140 uint32_t private_segment_fixed_size;
141 uint8_t reserved0[8];
142 int64_t kernel_code_entry_byte_offset;
143 uint8_t reserved1[24];
144 uint32_t compute_pgm_rsrc1;
145 uint32_t compute_pgm_rsrc2;
146 uint16_t kernel_code_properties;
147 uint8_t reserved2[6];
150 static_assert(
151 sizeof(kernel_descriptor_t) == 64,
152 "invalid size for kernel_descriptor_t");
153 static_assert(
154 offsetof(kernel_descriptor_t, group_segment_fixed_size) == 0,
155 "invalid offset for group_segment_fixed_size");
156 static_assert(
157 offsetof(kernel_descriptor_t, private_segment_fixed_size) == 4,
158 "invalid offset for private_segment_fixed_size");
159 static_assert(
160 offsetof(kernel_descriptor_t, reserved0) == 8,
161 "invalid offset for reserved0");
162 static_assert(
163 offsetof(kernel_descriptor_t, kernel_code_entry_byte_offset) == 16,
164 "invalid offset for kernel_code_entry_byte_offset");
165 static_assert(
166 offsetof(kernel_descriptor_t, reserved1) == 24,
167 "invalid offset for reserved1");
168 static_assert(
169 offsetof(kernel_descriptor_t, compute_pgm_rsrc1) == 48,
170 "invalid offset for compute_pgm_rsrc1");
171 static_assert(
172 offsetof(kernel_descriptor_t, compute_pgm_rsrc2) == 52,
173 "invalid offset for compute_pgm_rsrc2");
174 static_assert(
175 offsetof(kernel_descriptor_t, kernel_code_properties) == 56,
176 "invalid offset for kernel_code_properties");
177 static_assert(
178 offsetof(kernel_descriptor_t, reserved2) == 58,
179 "invalid offset for reserved2");
181 } // end namespace amdhsa
182 } // end namespace llvm
184 #endif // LLVM_SUPPORT_AMDHSAKERNELDESCRIPTOR_H