1*9880d681SAndroid Build Coastguard Worker //===-- AMDGPUKernelCodeT.h - Print AMDGPU assembly code ---------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker /// \file AMDKernelCodeT.h 10*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 11*9880d681SAndroid Build Coastguard Worker 12*9880d681SAndroid Build Coastguard Worker #ifndef AMDKERNELCODET_H 13*9880d681SAndroid Build Coastguard Worker #define AMDKERNELCODET_H 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/SubtargetFeature.h" 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #include <cstddef> 18*9880d681SAndroid Build Coastguard Worker #include <cstdint> 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h" 21*9880d681SAndroid Build Coastguard Worker //---------------------------------------------------------------------------// 22*9880d681SAndroid Build Coastguard Worker // AMD Kernel Code, and its dependencies // 23*9880d681SAndroid Build Coastguard Worker //---------------------------------------------------------------------------// 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker typedef uint8_t hsa_powertwo8_t; 26*9880d681SAndroid Build Coastguard Worker typedef uint32_t hsa_ext_code_kind_t; 27*9880d681SAndroid Build Coastguard Worker typedef uint8_t hsa_ext_brig_profile8_t; 28*9880d681SAndroid Build Coastguard Worker typedef uint8_t hsa_ext_brig_machine_model8_t; 29*9880d681SAndroid Build Coastguard Worker typedef uint64_t hsa_ext_control_directive_present64_t; 30*9880d681SAndroid Build Coastguard Worker typedef uint16_t hsa_ext_exception_kind16_t; 31*9880d681SAndroid Build Coastguard Worker typedef uint32_t hsa_ext_code_kind32_t; 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Worker typedef struct hsa_dim3_s { 34*9880d681SAndroid Build Coastguard Worker uint32_t x; 35*9880d681SAndroid Build Coastguard Worker uint32_t y; 36*9880d681SAndroid Build Coastguard Worker uint32_t z; 37*9880d681SAndroid Build Coastguard Worker } hsa_dim3_t; 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker /// The version of the amd_*_code_t struct. Minor versions must be 40*9880d681SAndroid Build Coastguard Worker /// backward compatible. 41*9880d681SAndroid Build Coastguard Worker typedef uint32_t amd_code_version32_t; 42*9880d681SAndroid Build Coastguard Worker enum amd_code_version_t { 43*9880d681SAndroid Build Coastguard Worker AMD_CODE_VERSION_MAJOR = 0, 44*9880d681SAndroid Build Coastguard Worker AMD_CODE_VERSION_MINOR = 1 45*9880d681SAndroid Build Coastguard Worker }; 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Worker // Sets val bits for specified mask in specified dst packed instance. 48*9880d681SAndroid Build Coastguard Worker #define AMD_HSA_BITS_SET(dst, mask, val) \ 49*9880d681SAndroid Build Coastguard Worker dst &= (~(1 << mask ## _SHIFT) & ~mask); \ 50*9880d681SAndroid Build Coastguard Worker dst |= (((val) << mask ## _SHIFT) & mask) 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker // Gets bits for specified mask from specified src packed instance. 53*9880d681SAndroid Build Coastguard Worker #define AMD_HSA_BITS_GET(src, mask) \ 54*9880d681SAndroid Build Coastguard Worker ((src & mask) >> mask ## _SHIFT) \ 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker /// The values used to define the number of bytes to use for the 57*9880d681SAndroid Build Coastguard Worker /// swizzle element size. 58*9880d681SAndroid Build Coastguard Worker enum amd_element_byte_size_t { 59*9880d681SAndroid Build Coastguard Worker AMD_ELEMENT_2_BYTES = 0, 60*9880d681SAndroid Build Coastguard Worker AMD_ELEMENT_4_BYTES = 1, 61*9880d681SAndroid Build Coastguard Worker AMD_ELEMENT_8_BYTES = 2, 62*9880d681SAndroid Build Coastguard Worker AMD_ELEMENT_16_BYTES = 3 63*9880d681SAndroid Build Coastguard Worker }; 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Worker /// Shader program settings for CS. Contains COMPUTE_PGM_RSRC1 and 66*9880d681SAndroid Build Coastguard Worker /// COMPUTE_PGM_RSRC2 registers. 67*9880d681SAndroid Build Coastguard Worker typedef uint64_t amd_compute_pgm_resource_register64_t; 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Worker /// Every amd_*_code_t has the following properties, which are composed of 70*9880d681SAndroid Build Coastguard Worker /// a number of bit fields. Every bit field has a mask (AMD_CODE_PROPERTY_*), 71*9880d681SAndroid Build Coastguard Worker /// bit width (AMD_CODE_PROPERTY_*_WIDTH, and bit shift amount 72*9880d681SAndroid Build Coastguard Worker /// (AMD_CODE_PROPERTY_*_SHIFT) for convenient access. Unused bits must be 0. 73*9880d681SAndroid Build Coastguard Worker /// 74*9880d681SAndroid Build Coastguard Worker /// (Note that bit fields cannot be used as their layout is 75*9880d681SAndroid Build Coastguard Worker /// implementation defined in the C standard and so cannot be used to 76*9880d681SAndroid Build Coastguard Worker /// specify an ABI) 77*9880d681SAndroid Build Coastguard Worker typedef uint32_t amd_code_property32_t; 78*9880d681SAndroid Build Coastguard Worker enum amd_code_property_mask_t { 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Worker /// Enable the setup of the SGPR user data registers 81*9880d681SAndroid Build Coastguard Worker /// (AMD_CODE_PROPERTY_ENABLE_SGPR_*), see documentation of amd_kernel_code_t 82*9880d681SAndroid Build Coastguard Worker /// for initial register state. 83*9880d681SAndroid Build Coastguard Worker /// 84*9880d681SAndroid Build Coastguard Worker /// The total number of SGPRuser data registers requested must not 85*9880d681SAndroid Build Coastguard Worker /// exceed 16. Any requests beyond 16 will be ignored. 86*9880d681SAndroid Build Coastguard Worker /// 87*9880d681SAndroid Build Coastguard Worker /// Used to set COMPUTE_PGM_RSRC2.USER_SGPR (set to total count of 88*9880d681SAndroid Build Coastguard Worker /// SGPR user data registers enabled up to 16). 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER_SHIFT = 0, 91*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER_WIDTH = 1, 92*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER_SHIFT, 93*9880d681SAndroid Build Coastguard Worker 94*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR_SHIFT = 1, 95*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR_WIDTH = 1, 96*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR_SHIFT, 97*9880d681SAndroid Build Coastguard Worker 98*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR_SHIFT = 2, 99*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR_WIDTH = 1, 100*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR_SHIFT, 101*9880d681SAndroid Build Coastguard Worker 102*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR_SHIFT = 3, 103*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR_WIDTH = 1, 104*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR_SHIFT, 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID_SHIFT = 4, 107*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID_WIDTH = 1, 108*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID_SHIFT, 109*9880d681SAndroid Build Coastguard Worker 110*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT_SHIFT = 5, 111*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT_WIDTH = 1, 112*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT_SHIFT, 113*9880d681SAndroid Build Coastguard Worker 114*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE_SHIFT = 6, 115*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE_WIDTH = 1, 116*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE_SHIFT, 117*9880d681SAndroid Build Coastguard Worker 118*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X_SHIFT = 7, 119*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X_WIDTH = 1, 120*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X_SHIFT, 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y_SHIFT = 8, 123*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y_WIDTH = 1, 124*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y_SHIFT, 125*9880d681SAndroid Build Coastguard Worker 126*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z_SHIFT = 9, 127*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z_WIDTH = 1, 128*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z = ((1 << AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z_SHIFT, 129*9880d681SAndroid Build Coastguard Worker 130*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_RESERVED1_SHIFT = 10, 131*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_RESERVED1_WIDTH = 6, 132*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_RESERVED1 = ((1 << AMD_CODE_PROPERTY_RESERVED1_WIDTH) - 1) << AMD_CODE_PROPERTY_RESERVED1_SHIFT, 133*9880d681SAndroid Build Coastguard Worker 134*9880d681SAndroid Build Coastguard Worker /// Control wave ID base counter for GDS ordered-append. Used to set 135*9880d681SAndroid Build Coastguard Worker /// COMPUTE_DISPATCH_INITIATOR.ORDERED_APPEND_ENBL. (Not sure if 136*9880d681SAndroid Build Coastguard Worker /// ORDERED_APPEND_MODE also needs to be settable) 137*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_ORDERED_APPEND_GDS_SHIFT = 16, 138*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_ORDERED_APPEND_GDS_WIDTH = 1, 139*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_ENABLE_ORDERED_APPEND_GDS = ((1 << AMD_CODE_PROPERTY_ENABLE_ORDERED_APPEND_GDS_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_ORDERED_APPEND_GDS_SHIFT, 140*9880d681SAndroid Build Coastguard Worker 141*9880d681SAndroid Build Coastguard Worker /// The interleave (swizzle) element size in bytes required by the 142*9880d681SAndroid Build Coastguard Worker /// code for private memory. This must be 2, 4, 8 or 16. This value 143*9880d681SAndroid Build Coastguard Worker /// is provided to the finalizer when it is invoked and is recorded 144*9880d681SAndroid Build Coastguard Worker /// here. The hardware will interleave the memory requests of each 145*9880d681SAndroid Build Coastguard Worker /// lane of a wavefront by this element size to ensure each 146*9880d681SAndroid Build Coastguard Worker /// work-item gets a distinct memory memory location. Therefore, the 147*9880d681SAndroid Build Coastguard Worker /// finalizer ensures that all load and store operations done to 148*9880d681SAndroid Build Coastguard Worker /// private memory do not exceed this size. For example, if the 149*9880d681SAndroid Build Coastguard Worker /// element size is 4 (32-bits or dword) and a 64-bit value must be 150*9880d681SAndroid Build Coastguard Worker /// loaded, the finalizer will generate two 32-bit loads. This 151*9880d681SAndroid Build Coastguard Worker /// ensures that the interleaving will get the work-item 152*9880d681SAndroid Build Coastguard Worker /// specific dword for both halves of the 64-bit value. If it just 153*9880d681SAndroid Build Coastguard Worker /// did a 64-bit load then it would get one dword which belonged to 154*9880d681SAndroid Build Coastguard Worker /// its own work-item, but the second dword would belong to the 155*9880d681SAndroid Build Coastguard Worker /// adjacent lane work-item since the interleaving is in dwords. 156*9880d681SAndroid Build Coastguard Worker /// 157*9880d681SAndroid Build Coastguard Worker /// The value used must match the value that the runtime configures 158*9880d681SAndroid Build Coastguard Worker /// the GPU flat scratch (SH_STATIC_MEM_CONFIG.ELEMENT_SIZE). This 159*9880d681SAndroid Build Coastguard Worker /// is generally DWORD. 160*9880d681SAndroid Build Coastguard Worker /// 161*9880d681SAndroid Build Coastguard Worker /// uSE VALUES FROM THE AMD_ELEMENT_BYTE_SIZE_T ENUM. 162*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_SHIFT = 17, 163*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_WIDTH = 2, 164*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE = ((1 << AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_WIDTH) - 1) << AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_SHIFT, 165*9880d681SAndroid Build Coastguard Worker 166*9880d681SAndroid Build Coastguard Worker /// Are global memory addresses 64 bits. Must match 167*9880d681SAndroid Build Coastguard Worker /// amd_kernel_code_t.hsail_machine_model == 168*9880d681SAndroid Build Coastguard Worker /// HSA_MACHINE_LARGE. Must also match 169*9880d681SAndroid Build Coastguard Worker /// SH_MEM_CONFIG.PTR32 (GFX6 (SI)/GFX7 (CI)), 170*9880d681SAndroid Build Coastguard Worker /// SH_MEM_CONFIG.ADDRESS_MODE (GFX8 (VI)+). 171*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_PTR64_SHIFT = 19, 172*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_PTR64_WIDTH = 1, 173*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_PTR64 = ((1 << AMD_CODE_PROPERTY_IS_PTR64_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_PTR64_SHIFT, 174*9880d681SAndroid Build Coastguard Worker 175*9880d681SAndroid Build Coastguard Worker /// Indicate if the generated ISA is using a dynamically sized call 176*9880d681SAndroid Build Coastguard Worker /// stack. This can happen if calls are implemented using a call 177*9880d681SAndroid Build Coastguard Worker /// stack and recursion, alloca or calls to indirect functions are 178*9880d681SAndroid Build Coastguard Worker /// present. In these cases the Finalizer cannot compute the total 179*9880d681SAndroid Build Coastguard Worker /// private segment size at compile time. In this case the 180*9880d681SAndroid Build Coastguard Worker /// workitem_private_segment_byte_size only specifies the statically 181*9880d681SAndroid Build Coastguard Worker /// know private segment size, and additional space must be added 182*9880d681SAndroid Build Coastguard Worker /// for the call stack. 183*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_SHIFT = 20, 184*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_WIDTH = 1, 185*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK = ((1 << AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_SHIFT, 186*9880d681SAndroid Build Coastguard Worker 187*9880d681SAndroid Build Coastguard Worker /// Indicate if code generated has support for debugging. 188*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_SHIFT = 21, 189*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_WIDTH = 1, 190*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED = ((1 << AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_SHIFT, 191*9880d681SAndroid Build Coastguard Worker 192*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_SHIFT = 22, 193*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_WIDTH = 1, 194*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED = ((1 << AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_SHIFT, 195*9880d681SAndroid Build Coastguard Worker 196*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_RESERVED2_SHIFT = 23, 197*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_RESERVED2_WIDTH = 9, 198*9880d681SAndroid Build Coastguard Worker AMD_CODE_PROPERTY_RESERVED2 = ((1 << AMD_CODE_PROPERTY_RESERVED2_WIDTH) - 1) << AMD_CODE_PROPERTY_RESERVED2_SHIFT 199*9880d681SAndroid Build Coastguard Worker }; 200*9880d681SAndroid Build Coastguard Worker 201*9880d681SAndroid Build Coastguard Worker /// @brief The hsa_ext_control_directives_t specifies the values for the HSAIL 202*9880d681SAndroid Build Coastguard Worker /// control directives. These control how the finalizer generates code. This 203*9880d681SAndroid Build Coastguard Worker /// struct is used both as an argument to hsaFinalizeKernel to specify values for 204*9880d681SAndroid Build Coastguard Worker /// the control directives, and is used in HsaKernelCode to record the values of 205*9880d681SAndroid Build Coastguard Worker /// the control directives that the finalize used when generating the code which 206*9880d681SAndroid Build Coastguard Worker /// either came from the finalizer argument or explicit HSAIL control 207*9880d681SAndroid Build Coastguard Worker /// directives. See the definition of the control directives in HSA Programmer's 208*9880d681SAndroid Build Coastguard Worker /// Reference Manual which also defines how the values specified as finalizer 209*9880d681SAndroid Build Coastguard Worker /// arguments have to agree with the control directives in the HSAIL code. 210*9880d681SAndroid Build Coastguard Worker typedef struct hsa_ext_control_directives_s { 211*9880d681SAndroid Build Coastguard Worker /// This is a bit set indicating which control directives have been 212*9880d681SAndroid Build Coastguard Worker /// specified. If the value is 0 then there are no control directives specified 213*9880d681SAndroid Build Coastguard Worker /// and the rest of the fields can be ignored. The bits are accessed using the 214*9880d681SAndroid Build Coastguard Worker /// hsa_ext_control_directives_present_mask_t. Any control directive that is not 215*9880d681SAndroid Build Coastguard Worker /// enabled in this bit set must have the value of all 0s. 216*9880d681SAndroid Build Coastguard Worker hsa_ext_control_directive_present64_t enabled_control_directives; 217*9880d681SAndroid Build Coastguard Worker 218*9880d681SAndroid Build Coastguard Worker /// If enableBreakExceptions is not enabled then must be 0, otherwise must be 219*9880d681SAndroid Build Coastguard Worker /// non-0 and specifies the set of HSAIL exceptions that must have the BREAK 220*9880d681SAndroid Build Coastguard Worker /// policy enabled. If this set is not empty then the generated code may have 221*9880d681SAndroid Build Coastguard Worker /// lower performance than if the set is empty. If the kernel being finalized 222*9880d681SAndroid Build Coastguard Worker /// has any enablebreakexceptions control directives, then the values specified 223*9880d681SAndroid Build Coastguard Worker /// by this argument are unioned with the values in these control 224*9880d681SAndroid Build Coastguard Worker /// directives. If any of the functions the kernel calls have an 225*9880d681SAndroid Build Coastguard Worker /// enablebreakexceptions control directive, then they must be equal or a 226*9880d681SAndroid Build Coastguard Worker /// subset of, this union. 227*9880d681SAndroid Build Coastguard Worker hsa_ext_exception_kind16_t enable_break_exceptions; 228*9880d681SAndroid Build Coastguard Worker 229*9880d681SAndroid Build Coastguard Worker /// If enableDetectExceptions is not enabled then must be 0, otherwise must be 230*9880d681SAndroid Build Coastguard Worker /// non-0 and specifies the set of HSAIL exceptions that must have the DETECT 231*9880d681SAndroid Build Coastguard Worker /// policy enabled. If this set is not empty then the generated code may have 232*9880d681SAndroid Build Coastguard Worker /// lower performance than if the set is empty. However, an implementation 233*9880d681SAndroid Build Coastguard Worker /// should endeavour to make the performance impact small. If the kernel being 234*9880d681SAndroid Build Coastguard Worker /// finalized has any enabledetectexceptions control directives, then the 235*9880d681SAndroid Build Coastguard Worker /// values specified by this argument are unioned with the values in these 236*9880d681SAndroid Build Coastguard Worker /// control directives. If any of the functions the kernel calls have an 237*9880d681SAndroid Build Coastguard Worker /// enabledetectexceptions control directive, then they must be equal or a 238*9880d681SAndroid Build Coastguard Worker /// subset of, this union. 239*9880d681SAndroid Build Coastguard Worker hsa_ext_exception_kind16_t enable_detect_exceptions; 240*9880d681SAndroid Build Coastguard Worker 241*9880d681SAndroid Build Coastguard Worker /// If maxDynamicGroupSize is not enabled then must be 0, and any amount of 242*9880d681SAndroid Build Coastguard Worker /// dynamic group segment can be allocated for a dispatch, otherwise the value 243*9880d681SAndroid Build Coastguard Worker /// specifies the maximum number of bytes of dynamic group segment that can be 244*9880d681SAndroid Build Coastguard Worker /// allocated for a dispatch. If the kernel being finalized has any 245*9880d681SAndroid Build Coastguard Worker /// maxdynamicsize control directives, then the values must be the same, and 246*9880d681SAndroid Build Coastguard Worker /// must be the same as this argument if it is enabled. This value can be used 247*9880d681SAndroid Build Coastguard Worker /// by the finalizer to determine the maximum number of bytes of group memory 248*9880d681SAndroid Build Coastguard Worker /// used by each work-group by adding this value to the group memory required 249*9880d681SAndroid Build Coastguard Worker /// for all group segment variables used by the kernel and all functions it 250*9880d681SAndroid Build Coastguard Worker /// calls, and group memory used to implement other HSAIL features such as 251*9880d681SAndroid Build Coastguard Worker /// fbarriers and the detect exception operations. This can allow the finalizer 252*9880d681SAndroid Build Coastguard Worker /// to determine the expected number of work-groups that can be executed by a 253*9880d681SAndroid Build Coastguard Worker /// compute unit and allow more resources to be allocated to the work-items if 254*9880d681SAndroid Build Coastguard Worker /// it is known that fewer work-groups can be executed due to group memory 255*9880d681SAndroid Build Coastguard Worker /// limitations. 256*9880d681SAndroid Build Coastguard Worker uint32_t max_dynamic_group_size; 257*9880d681SAndroid Build Coastguard Worker 258*9880d681SAndroid Build Coastguard Worker /// If maxFlatGridSize is not enabled then must be 0, otherwise must be greater 259*9880d681SAndroid Build Coastguard Worker /// than 0. See HSA Programmer's Reference Manual description of 260*9880d681SAndroid Build Coastguard Worker /// maxflatgridsize control directive. 261*9880d681SAndroid Build Coastguard Worker uint32_t max_flat_grid_size; 262*9880d681SAndroid Build Coastguard Worker 263*9880d681SAndroid Build Coastguard Worker /// If maxFlatWorkgroupSize is not enabled then must be 0, otherwise must be 264*9880d681SAndroid Build Coastguard Worker /// greater than 0. See HSA Programmer's Reference Manual description of 265*9880d681SAndroid Build Coastguard Worker /// maxflatworkgroupsize control directive. 266*9880d681SAndroid Build Coastguard Worker uint32_t max_flat_workgroup_size; 267*9880d681SAndroid Build Coastguard Worker 268*9880d681SAndroid Build Coastguard Worker /// If requestedWorkgroupsPerCu is not enabled then must be 0, and the 269*9880d681SAndroid Build Coastguard Worker /// finalizer is free to generate ISA that may result in any number of 270*9880d681SAndroid Build Coastguard Worker /// work-groups executing on a single compute unit. Otherwise, the finalizer 271*9880d681SAndroid Build Coastguard Worker /// should attempt to generate ISA that will allow the specified number of 272*9880d681SAndroid Build Coastguard Worker /// work-groups to execute on a single compute unit. This is only a hint and 273*9880d681SAndroid Build Coastguard Worker /// can be ignored by the finalizer. If the kernel being finalized, or any of 274*9880d681SAndroid Build Coastguard Worker /// the functions it calls, has a requested control directive, then the values 275*9880d681SAndroid Build Coastguard Worker /// must be the same. This can be used to determine the number of resources 276*9880d681SAndroid Build Coastguard Worker /// that should be allocated to a single work-group and work-item. For example, 277*9880d681SAndroid Build Coastguard Worker /// a low value may allow more resources to be allocated, resulting in higher 278*9880d681SAndroid Build Coastguard Worker /// per work-item performance, as it is known there will never be more than the 279*9880d681SAndroid Build Coastguard Worker /// specified number of work-groups actually executing on the compute 280*9880d681SAndroid Build Coastguard Worker /// unit. Conversely, a high value may allocate fewer resources, resulting in 281*9880d681SAndroid Build Coastguard Worker /// lower per work-item performance, which is offset by the fact it allows more 282*9880d681SAndroid Build Coastguard Worker /// work-groups to actually execute on the compute unit. 283*9880d681SAndroid Build Coastguard Worker uint32_t requested_workgroups_per_cu; 284*9880d681SAndroid Build Coastguard Worker 285*9880d681SAndroid Build Coastguard Worker /// If not enabled then all elements for Dim3 must be 0, otherwise every 286*9880d681SAndroid Build Coastguard Worker /// element must be greater than 0. See HSA Programmer's Reference Manual 287*9880d681SAndroid Build Coastguard Worker /// description of requiredgridsize control directive. 288*9880d681SAndroid Build Coastguard Worker hsa_dim3_t required_grid_size; 289*9880d681SAndroid Build Coastguard Worker 290*9880d681SAndroid Build Coastguard Worker /// If requiredWorkgroupSize is not enabled then all elements for Dim3 must be 291*9880d681SAndroid Build Coastguard Worker /// 0, and the produced code can be dispatched with any legal work-group range 292*9880d681SAndroid Build Coastguard Worker /// consistent with the dispatch dimensions. Otherwise, the code produced must 293*9880d681SAndroid Build Coastguard Worker /// always be dispatched with the specified work-group range. No element of the 294*9880d681SAndroid Build Coastguard Worker /// specified range must be 0. It must be consistent with required_dimensions 295*9880d681SAndroid Build Coastguard Worker /// and max_flat_workgroup_size. If the kernel being finalized, or any of the 296*9880d681SAndroid Build Coastguard Worker /// functions it calls, has a requiredworkgroupsize control directive, then the 297*9880d681SAndroid Build Coastguard Worker /// values must be the same. Specifying a value can allow the finalizer to 298*9880d681SAndroid Build Coastguard Worker /// optimize work-group id operations, and if the number of work-items in the 299*9880d681SAndroid Build Coastguard Worker /// work-group is less than the WAVESIZE then barrier operations can be 300*9880d681SAndroid Build Coastguard Worker /// optimized to just a memory fence. 301*9880d681SAndroid Build Coastguard Worker hsa_dim3_t required_workgroup_size; 302*9880d681SAndroid Build Coastguard Worker 303*9880d681SAndroid Build Coastguard Worker /// If requiredDim is not enabled then must be 0 and the produced kernel code 304*9880d681SAndroid Build Coastguard Worker /// can be dispatched with 1, 2 or 3 dimensions. If enabled then the value is 305*9880d681SAndroid Build Coastguard Worker /// 1..3 and the code produced must only be dispatched with a dimension that 306*9880d681SAndroid Build Coastguard Worker /// matches. Other values are illegal. If the kernel being finalized, or any of 307*9880d681SAndroid Build Coastguard Worker /// the functions it calls, has a requireddimsize control directive, then the 308*9880d681SAndroid Build Coastguard Worker /// values must be the same. This can be used to optimize the code generated to 309*9880d681SAndroid Build Coastguard Worker /// compute the absolute and flat work-group and work-item id, and the dim 310*9880d681SAndroid Build Coastguard Worker /// HSAIL operations. 311*9880d681SAndroid Build Coastguard Worker uint8_t required_dim; 312*9880d681SAndroid Build Coastguard Worker 313*9880d681SAndroid Build Coastguard Worker /// Reserved. Must be 0. 314*9880d681SAndroid Build Coastguard Worker uint8_t reserved[75]; 315*9880d681SAndroid Build Coastguard Worker } hsa_ext_control_directives_t; 316*9880d681SAndroid Build Coastguard Worker 317*9880d681SAndroid Build Coastguard Worker /// AMD Kernel Code Object (amd_kernel_code_t). GPU CP uses the AMD Kernel 318*9880d681SAndroid Build Coastguard Worker /// Code Object to set up the hardware to execute the kernel dispatch. 319*9880d681SAndroid Build Coastguard Worker /// 320*9880d681SAndroid Build Coastguard Worker /// Initial Kernel Register State. 321*9880d681SAndroid Build Coastguard Worker /// 322*9880d681SAndroid Build Coastguard Worker /// Initial kernel register state will be set up by CP/SPI prior to the start 323*9880d681SAndroid Build Coastguard Worker /// of execution of every wavefront. This is limited by the constraints of the 324*9880d681SAndroid Build Coastguard Worker /// current hardware. 325*9880d681SAndroid Build Coastguard Worker /// 326*9880d681SAndroid Build Coastguard Worker /// The order of the SGPR registers is defined, but the Finalizer can specify 327*9880d681SAndroid Build Coastguard Worker /// which ones are actually setup in the amd_kernel_code_t object using the 328*9880d681SAndroid Build Coastguard Worker /// enable_sgpr_* bit fields. The register numbers used for enabled registers 329*9880d681SAndroid Build Coastguard Worker /// are dense starting at SGPR0: the first enabled register is SGPR0, the next 330*9880d681SAndroid Build Coastguard Worker /// enabled register is SGPR1 etc.; disabled registers do not have an SGPR 331*9880d681SAndroid Build Coastguard Worker /// number. 332*9880d681SAndroid Build Coastguard Worker /// 333*9880d681SAndroid Build Coastguard Worker /// The initial SGPRs comprise up to 16 User SRGPs that are set up by CP and 334*9880d681SAndroid Build Coastguard Worker /// apply to all waves of the grid. It is possible to specify more than 16 User 335*9880d681SAndroid Build Coastguard Worker /// SGPRs using the enable_sgpr_* bit fields, in which case only the first 16 336*9880d681SAndroid Build Coastguard Worker /// are actually initialized. These are then immediately followed by the System 337*9880d681SAndroid Build Coastguard Worker /// SGPRs that are set up by ADC/SPI and can have different values for each wave 338*9880d681SAndroid Build Coastguard Worker /// of the grid dispatch. 339*9880d681SAndroid Build Coastguard Worker /// 340*9880d681SAndroid Build Coastguard Worker /// SGPR register initial state is defined as follows: 341*9880d681SAndroid Build Coastguard Worker /// 342*9880d681SAndroid Build Coastguard Worker /// Private Segment Buffer (enable_sgpr_private_segment_buffer): 343*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 4. V# that can be used, together with 344*9880d681SAndroid Build Coastguard Worker /// Scratch Wave Offset as an offset, to access the Private/Spill/Arg 345*9880d681SAndroid Build Coastguard Worker /// segments using a segment address. It must be set as follows: 346*9880d681SAndroid Build Coastguard Worker /// - Base address: of the scratch memory area used by the dispatch. It 347*9880d681SAndroid Build Coastguard Worker /// does not include the scratch wave offset. It will be the per process 348*9880d681SAndroid Build Coastguard Worker /// SH_HIDDEN_PRIVATE_BASE_VMID plus any offset from this dispatch (for 349*9880d681SAndroid Build Coastguard Worker /// example there may be a per pipe offset, or per AQL Queue offset). 350*9880d681SAndroid Build Coastguard Worker /// - Stride + data_format: Element Size * Index Stride (???) 351*9880d681SAndroid Build Coastguard Worker /// - Cache swizzle: ??? 352*9880d681SAndroid Build Coastguard Worker /// - Swizzle enable: SH_STATIC_MEM_CONFIG.SWIZZLE_ENABLE (must be 1 for 353*9880d681SAndroid Build Coastguard Worker /// scratch) 354*9880d681SAndroid Build Coastguard Worker /// - Num records: Flat Scratch Work Item Size / Element Size (???) 355*9880d681SAndroid Build Coastguard Worker /// - Dst_sel_*: ??? 356*9880d681SAndroid Build Coastguard Worker /// - Num_format: ??? 357*9880d681SAndroid Build Coastguard Worker /// - Element_size: SH_STATIC_MEM_CONFIG.ELEMENT_SIZE (will be DWORD, must 358*9880d681SAndroid Build Coastguard Worker /// agree with amd_kernel_code_t.privateElementSize) 359*9880d681SAndroid Build Coastguard Worker /// - Index_stride: SH_STATIC_MEM_CONFIG.INDEX_STRIDE (will be 64 as must 360*9880d681SAndroid Build Coastguard Worker /// be number of wavefront lanes for scratch, must agree with 361*9880d681SAndroid Build Coastguard Worker /// amd_kernel_code_t.wavefrontSize) 362*9880d681SAndroid Build Coastguard Worker /// - Add tid enable: 1 363*9880d681SAndroid Build Coastguard Worker /// - ATC: from SH_MEM_CONFIG.PRIVATE_ATC, 364*9880d681SAndroid Build Coastguard Worker /// - Hash_enable: ??? 365*9880d681SAndroid Build Coastguard Worker /// - Heap: ??? 366*9880d681SAndroid Build Coastguard Worker /// - Mtype: from SH_STATIC_MEM_CONFIG.PRIVATE_MTYPE 367*9880d681SAndroid Build Coastguard Worker /// - Type: 0 (a buffer) (???) 368*9880d681SAndroid Build Coastguard Worker /// 369*9880d681SAndroid Build Coastguard Worker /// Dispatch Ptr (enable_sgpr_dispatch_ptr): 370*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 2. 64 bit address of AQL dispatch packet 371*9880d681SAndroid Build Coastguard Worker /// for kernel actually executing. 372*9880d681SAndroid Build Coastguard Worker /// 373*9880d681SAndroid Build Coastguard Worker /// Queue Ptr (enable_sgpr_queue_ptr): 374*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 2. 64 bit address of AmdQueue object for 375*9880d681SAndroid Build Coastguard Worker /// AQL queue on which the dispatch packet was queued. 376*9880d681SAndroid Build Coastguard Worker /// 377*9880d681SAndroid Build Coastguard Worker /// Kernarg Segment Ptr (enable_sgpr_kernarg_segment_ptr): 378*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 2. 64 bit address of Kernarg segment. This 379*9880d681SAndroid Build Coastguard Worker /// is directly copied from the kernargPtr in the dispatch packet. Having CP 380*9880d681SAndroid Build Coastguard Worker /// load it once avoids loading it at the beginning of every wavefront. 381*9880d681SAndroid Build Coastguard Worker /// 382*9880d681SAndroid Build Coastguard Worker /// Dispatch Id (enable_sgpr_dispatch_id): 383*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 2. 64 bit Dispatch ID of the dispatch 384*9880d681SAndroid Build Coastguard Worker /// packet being executed. 385*9880d681SAndroid Build Coastguard Worker /// 386*9880d681SAndroid Build Coastguard Worker /// Flat Scratch Init (enable_sgpr_flat_scratch_init): 387*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 2. This is 2 SGPRs. 388*9880d681SAndroid Build Coastguard Worker /// 389*9880d681SAndroid Build Coastguard Worker /// For CI/VI: 390*9880d681SAndroid Build Coastguard Worker /// The first SGPR is a 32 bit byte offset from SH_MEM_HIDDEN_PRIVATE_BASE 391*9880d681SAndroid Build Coastguard Worker /// to base of memory for scratch for this dispatch. This is the same offset 392*9880d681SAndroid Build Coastguard Worker /// used in computing the Scratch Segment Buffer base address. The value of 393*9880d681SAndroid Build Coastguard Worker /// Scratch Wave Offset must be added by the kernel code and moved to 394*9880d681SAndroid Build Coastguard Worker /// SGPRn-4 for use as the FLAT SCRATCH BASE in flat memory instructions. 395*9880d681SAndroid Build Coastguard Worker /// 396*9880d681SAndroid Build Coastguard Worker /// The second SGPR is 32 bit byte size of a single work-item's scratch 397*9880d681SAndroid Build Coastguard Worker /// memory usage. This is directly loaded from the dispatch packet Private 398*9880d681SAndroid Build Coastguard Worker /// Segment Byte Size and rounded up to a multiple of DWORD. 399*9880d681SAndroid Build Coastguard Worker /// 400*9880d681SAndroid Build Coastguard Worker /// \todo [Does CP need to round this to >4 byte alignment?] 401*9880d681SAndroid Build Coastguard Worker /// 402*9880d681SAndroid Build Coastguard Worker /// The kernel code must move to SGPRn-3 for use as the FLAT SCRATCH SIZE in 403*9880d681SAndroid Build Coastguard Worker /// flat memory instructions. Having CP load it once avoids loading it at 404*9880d681SAndroid Build Coastguard Worker /// the beginning of every wavefront. 405*9880d681SAndroid Build Coastguard Worker /// 406*9880d681SAndroid Build Coastguard Worker /// For PI: 407*9880d681SAndroid Build Coastguard Worker /// This is the 64 bit base address of the scratch backing memory for 408*9880d681SAndroid Build Coastguard Worker /// allocated by CP for this dispatch. 409*9880d681SAndroid Build Coastguard Worker /// 410*9880d681SAndroid Build Coastguard Worker /// Private Segment Size (enable_sgpr_private_segment_size): 411*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 1. The 32 bit byte size of a single 412*9880d681SAndroid Build Coastguard Worker /// work-item's scratch memory allocation. This is the value from the dispatch 413*9880d681SAndroid Build Coastguard Worker /// packet. Private Segment Byte Size rounded up by CP to a multiple of DWORD. 414*9880d681SAndroid Build Coastguard Worker /// 415*9880d681SAndroid Build Coastguard Worker /// \todo [Does CP need to round this to >4 byte alignment?] 416*9880d681SAndroid Build Coastguard Worker /// 417*9880d681SAndroid Build Coastguard Worker /// Having CP load it once avoids loading it at the beginning of every 418*9880d681SAndroid Build Coastguard Worker /// wavefront. 419*9880d681SAndroid Build Coastguard Worker /// 420*9880d681SAndroid Build Coastguard Worker /// \todo [This will not be used for CI/VI since it is the same value as 421*9880d681SAndroid Build Coastguard Worker /// the second SGPR of Flat Scratch Init. However, it is need for PI which 422*9880d681SAndroid Build Coastguard Worker /// changes meaning of Flat Scratchg Init..] 423*9880d681SAndroid Build Coastguard Worker /// 424*9880d681SAndroid Build Coastguard Worker /// Grid Work-Group Count X (enable_sgpr_grid_workgroup_count_x): 425*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 1. 32 bit count of the number of 426*9880d681SAndroid Build Coastguard Worker /// work-groups in the X dimension for the grid being executed. Computed from 427*9880d681SAndroid Build Coastguard Worker /// the fields in the HsaDispatchPacket as 428*9880d681SAndroid Build Coastguard Worker /// ((gridSize.x+workgroupSize.x-1)/workgroupSize.x). 429*9880d681SAndroid Build Coastguard Worker /// 430*9880d681SAndroid Build Coastguard Worker /// Grid Work-Group Count Y (enable_sgpr_grid_workgroup_count_y): 431*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 1. 32 bit count of the number of 432*9880d681SAndroid Build Coastguard Worker /// work-groups in the Y dimension for the grid being executed. Computed from 433*9880d681SAndroid Build Coastguard Worker /// the fields in the HsaDispatchPacket as 434*9880d681SAndroid Build Coastguard Worker /// ((gridSize.y+workgroupSize.y-1)/workgroupSize.y). 435*9880d681SAndroid Build Coastguard Worker /// 436*9880d681SAndroid Build Coastguard Worker /// Only initialized if <16 previous SGPRs initialized. 437*9880d681SAndroid Build Coastguard Worker /// 438*9880d681SAndroid Build Coastguard Worker /// Grid Work-Group Count Z (enable_sgpr_grid_workgroup_count_z): 439*9880d681SAndroid Build Coastguard Worker /// Number of User SGPR registers: 1. 32 bit count of the number of 440*9880d681SAndroid Build Coastguard Worker /// work-groups in the Z dimension for the grid being executed. Computed 441*9880d681SAndroid Build Coastguard Worker /// from the fields in the HsaDispatchPacket as 442*9880d681SAndroid Build Coastguard Worker /// ((gridSize.z+workgroupSize.z-1)/workgroupSize.z). 443*9880d681SAndroid Build Coastguard Worker /// 444*9880d681SAndroid Build Coastguard Worker /// Only initialized if <16 previous SGPRs initialized. 445*9880d681SAndroid Build Coastguard Worker /// 446*9880d681SAndroid Build Coastguard Worker /// Work-Group Id X (enable_sgpr_workgroup_id_x): 447*9880d681SAndroid Build Coastguard Worker /// Number of System SGPR registers: 1. 32 bit work group id in X dimension 448*9880d681SAndroid Build Coastguard Worker /// of grid for wavefront. Always present. 449*9880d681SAndroid Build Coastguard Worker /// 450*9880d681SAndroid Build Coastguard Worker /// Work-Group Id Y (enable_sgpr_workgroup_id_y): 451*9880d681SAndroid Build Coastguard Worker /// Number of System SGPR registers: 1. 32 bit work group id in Y dimension 452*9880d681SAndroid Build Coastguard Worker /// of grid for wavefront. 453*9880d681SAndroid Build Coastguard Worker /// 454*9880d681SAndroid Build Coastguard Worker /// Work-Group Id Z (enable_sgpr_workgroup_id_z): 455*9880d681SAndroid Build Coastguard Worker /// Number of System SGPR registers: 1. 32 bit work group id in Z dimension 456*9880d681SAndroid Build Coastguard Worker /// of grid for wavefront. If present then Work-group Id Y will also be 457*9880d681SAndroid Build Coastguard Worker /// present 458*9880d681SAndroid Build Coastguard Worker /// 459*9880d681SAndroid Build Coastguard Worker /// Work-Group Info (enable_sgpr_workgroup_info): 460*9880d681SAndroid Build Coastguard Worker /// Number of System SGPR registers: 1. {first_wave, 14'b0000, 461*9880d681SAndroid Build Coastguard Worker /// ordered_append_term[10:0], threadgroup_size_in_waves[5:0]} 462*9880d681SAndroid Build Coastguard Worker /// 463*9880d681SAndroid Build Coastguard Worker /// Private Segment Wave Byte Offset 464*9880d681SAndroid Build Coastguard Worker /// (enable_sgpr_private_segment_wave_byte_offset): 465*9880d681SAndroid Build Coastguard Worker /// Number of System SGPR registers: 1. 32 bit byte offset from base of 466*9880d681SAndroid Build Coastguard Worker /// dispatch scratch base. Must be used as an offset with Private/Spill/Arg 467*9880d681SAndroid Build Coastguard Worker /// segment address when using Scratch Segment Buffer. It must be added to 468*9880d681SAndroid Build Coastguard Worker /// Flat Scratch Offset if setting up FLAT SCRATCH for flat addressing. 469*9880d681SAndroid Build Coastguard Worker /// 470*9880d681SAndroid Build Coastguard Worker /// 471*9880d681SAndroid Build Coastguard Worker /// The order of the VGPR registers is defined, but the Finalizer can specify 472*9880d681SAndroid Build Coastguard Worker /// which ones are actually setup in the amd_kernel_code_t object using the 473*9880d681SAndroid Build Coastguard Worker /// enableVgpr* bit fields. The register numbers used for enabled registers 474*9880d681SAndroid Build Coastguard Worker /// are dense starting at VGPR0: the first enabled register is VGPR0, the next 475*9880d681SAndroid Build Coastguard Worker /// enabled register is VGPR1 etc.; disabled registers do not have an VGPR 476*9880d681SAndroid Build Coastguard Worker /// number. 477*9880d681SAndroid Build Coastguard Worker /// 478*9880d681SAndroid Build Coastguard Worker /// VGPR register initial state is defined as follows: 479*9880d681SAndroid Build Coastguard Worker /// 480*9880d681SAndroid Build Coastguard Worker /// Work-Item Id X (always initialized): 481*9880d681SAndroid Build Coastguard Worker /// Number of registers: 1. 32 bit work item id in X dimension of work-group 482*9880d681SAndroid Build Coastguard Worker /// for wavefront lane. 483*9880d681SAndroid Build Coastguard Worker /// 484*9880d681SAndroid Build Coastguard Worker /// Work-Item Id X (enable_vgpr_workitem_id > 0): 485*9880d681SAndroid Build Coastguard Worker /// Number of registers: 1. 32 bit work item id in Y dimension of work-group 486*9880d681SAndroid Build Coastguard Worker /// for wavefront lane. 487*9880d681SAndroid Build Coastguard Worker /// 488*9880d681SAndroid Build Coastguard Worker /// Work-Item Id X (enable_vgpr_workitem_id > 0): 489*9880d681SAndroid Build Coastguard Worker /// Number of registers: 1. 32 bit work item id in Z dimension of work-group 490*9880d681SAndroid Build Coastguard Worker /// for wavefront lane. 491*9880d681SAndroid Build Coastguard Worker /// 492*9880d681SAndroid Build Coastguard Worker /// 493*9880d681SAndroid Build Coastguard Worker /// The setting of registers is being done by existing GPU hardware as follows: 494*9880d681SAndroid Build Coastguard Worker /// 1) SGPRs before the Work-Group Ids are set by CP using the 16 User Data 495*9880d681SAndroid Build Coastguard Worker /// registers. 496*9880d681SAndroid Build Coastguard Worker /// 2) Work-group Id registers X, Y, Z are set by SPI which supports any 497*9880d681SAndroid Build Coastguard Worker /// combination including none. 498*9880d681SAndroid Build Coastguard Worker /// 3) Scratch Wave Offset is also set by SPI which is why its value cannot 499*9880d681SAndroid Build Coastguard Worker /// be added into the value Flat Scratch Offset which would avoid the 500*9880d681SAndroid Build Coastguard Worker /// Finalizer generated prolog having to do the add. 501*9880d681SAndroid Build Coastguard Worker /// 4) The VGPRs are set by SPI which only supports specifying either (X), 502*9880d681SAndroid Build Coastguard Worker /// (X, Y) or (X, Y, Z). 503*9880d681SAndroid Build Coastguard Worker /// 504*9880d681SAndroid Build Coastguard Worker /// Flat Scratch Dispatch Offset and Flat Scratch Size are adjacent SGRRs so 505*9880d681SAndroid Build Coastguard Worker /// they can be moved as a 64 bit value to the hardware required SGPRn-3 and 506*9880d681SAndroid Build Coastguard Worker /// SGPRn-4 respectively using the Finalizer ?FLAT_SCRATCH? Register. 507*9880d681SAndroid Build Coastguard Worker /// 508*9880d681SAndroid Build Coastguard Worker /// The global segment can be accessed either using flat operations or buffer 509*9880d681SAndroid Build Coastguard Worker /// operations. If buffer operations are used then the Global Buffer used to 510*9880d681SAndroid Build Coastguard Worker /// access HSAIL Global/Readonly/Kernarg (which are combine) segments using a 511*9880d681SAndroid Build Coastguard Worker /// segment address is not passed into the kernel code by CP since its base 512*9880d681SAndroid Build Coastguard Worker /// address is always 0. Instead the Finalizer generates prolog code to 513*9880d681SAndroid Build Coastguard Worker /// initialize 4 SGPRs with a V# that has the following properties, and then 514*9880d681SAndroid Build Coastguard Worker /// uses that in the buffer instructions: 515*9880d681SAndroid Build Coastguard Worker /// - base address of 0 516*9880d681SAndroid Build Coastguard Worker /// - no swizzle 517*9880d681SAndroid Build Coastguard Worker /// - ATC=1 518*9880d681SAndroid Build Coastguard Worker /// - MTYPE set to support memory coherence specified in 519*9880d681SAndroid Build Coastguard Worker /// amd_kernel_code_t.globalMemoryCoherence 520*9880d681SAndroid Build Coastguard Worker /// 521*9880d681SAndroid Build Coastguard Worker /// When the Global Buffer is used to access the Kernarg segment, must add the 522*9880d681SAndroid Build Coastguard Worker /// dispatch packet kernArgPtr to a kernarg segment address before using this V#. 523*9880d681SAndroid Build Coastguard Worker /// Alternatively scalar loads can be used if the kernarg offset is uniform, as 524*9880d681SAndroid Build Coastguard Worker /// the kernarg segment is constant for the duration of the kernel execution. 525*9880d681SAndroid Build Coastguard Worker /// 526*9880d681SAndroid Build Coastguard Worker 527*9880d681SAndroid Build Coastguard Worker typedef struct amd_kernel_code_s { 528*9880d681SAndroid Build Coastguard Worker uint32_t amd_kernel_code_version_major; 529*9880d681SAndroid Build Coastguard Worker uint32_t amd_kernel_code_version_minor; 530*9880d681SAndroid Build Coastguard Worker uint16_t amd_machine_kind; 531*9880d681SAndroid Build Coastguard Worker uint16_t amd_machine_version_major; 532*9880d681SAndroid Build Coastguard Worker uint16_t amd_machine_version_minor; 533*9880d681SAndroid Build Coastguard Worker uint16_t amd_machine_version_stepping; 534*9880d681SAndroid Build Coastguard Worker 535*9880d681SAndroid Build Coastguard Worker /// Byte offset (possibly negative) from start of amd_kernel_code_t 536*9880d681SAndroid Build Coastguard Worker /// object to kernel's entry point instruction. The actual code for 537*9880d681SAndroid Build Coastguard Worker /// the kernel is required to be 256 byte aligned to match hardware 538*9880d681SAndroid Build Coastguard Worker /// requirements (SQ cache line is 16). The code must be position 539*9880d681SAndroid Build Coastguard Worker /// independent code (PIC) for AMD devices to give runtime the 540*9880d681SAndroid Build Coastguard Worker /// option of copying code to discrete GPU memory or APU L2 541*9880d681SAndroid Build Coastguard Worker /// cache. The Finalizer should endeavour to allocate all kernel 542*9880d681SAndroid Build Coastguard Worker /// machine code in contiguous memory pages so that a device 543*9880d681SAndroid Build Coastguard Worker /// pre-fetcher will tend to only pre-fetch Kernel Code objects, 544*9880d681SAndroid Build Coastguard Worker /// improving cache performance. 545*9880d681SAndroid Build Coastguard Worker int64_t kernel_code_entry_byte_offset; 546*9880d681SAndroid Build Coastguard Worker 547*9880d681SAndroid Build Coastguard Worker /// Range of bytes to consider prefetching expressed as an offset 548*9880d681SAndroid Build Coastguard Worker /// and size. The offset is from the start (possibly negative) of 549*9880d681SAndroid Build Coastguard Worker /// amd_kernel_code_t object. Set both to 0 if no prefetch 550*9880d681SAndroid Build Coastguard Worker /// information is available. 551*9880d681SAndroid Build Coastguard Worker int64_t kernel_code_prefetch_byte_offset; 552*9880d681SAndroid Build Coastguard Worker uint64_t kernel_code_prefetch_byte_size; 553*9880d681SAndroid Build Coastguard Worker 554*9880d681SAndroid Build Coastguard Worker /// Number of bytes of scratch backing memory required for full 555*9880d681SAndroid Build Coastguard Worker /// occupancy of target chip. This takes into account the number of 556*9880d681SAndroid Build Coastguard Worker /// bytes of scratch per work-item, the wavefront size, the maximum 557*9880d681SAndroid Build Coastguard Worker /// number of wavefronts per CU, and the number of CUs. This is an 558*9880d681SAndroid Build Coastguard Worker /// upper limit on scratch. If the grid being dispatched is small it 559*9880d681SAndroid Build Coastguard Worker /// may only need less than this. If the kernel uses no scratch, or 560*9880d681SAndroid Build Coastguard Worker /// the Finalizer has not computed this value, it must be 0. 561*9880d681SAndroid Build Coastguard Worker uint64_t max_scratch_backing_memory_byte_size; 562*9880d681SAndroid Build Coastguard Worker 563*9880d681SAndroid Build Coastguard Worker /// Shader program settings for CS. Contains COMPUTE_PGM_RSRC1 and 564*9880d681SAndroid Build Coastguard Worker /// COMPUTE_PGM_RSRC2 registers. 565*9880d681SAndroid Build Coastguard Worker uint64_t compute_pgm_resource_registers; 566*9880d681SAndroid Build Coastguard Worker 567*9880d681SAndroid Build Coastguard Worker /// Code properties. See amd_code_property_mask_t for a full list of 568*9880d681SAndroid Build Coastguard Worker /// properties. 569*9880d681SAndroid Build Coastguard Worker uint32_t code_properties; 570*9880d681SAndroid Build Coastguard Worker 571*9880d681SAndroid Build Coastguard Worker /// The amount of memory required for the combined private, spill 572*9880d681SAndroid Build Coastguard Worker /// and arg segments for a work-item in bytes. If 573*9880d681SAndroid Build Coastguard Worker /// is_dynamic_callstack is 1 then additional space must be added to 574*9880d681SAndroid Build Coastguard Worker /// this value for the call stack. 575*9880d681SAndroid Build Coastguard Worker uint32_t workitem_private_segment_byte_size; 576*9880d681SAndroid Build Coastguard Worker 577*9880d681SAndroid Build Coastguard Worker /// The amount of group segment memory required by a work-group in 578*9880d681SAndroid Build Coastguard Worker /// bytes. This does not include any dynamically allocated group 579*9880d681SAndroid Build Coastguard Worker /// segment memory that may be added when the kernel is 580*9880d681SAndroid Build Coastguard Worker /// dispatched. 581*9880d681SAndroid Build Coastguard Worker uint32_t workgroup_group_segment_byte_size; 582*9880d681SAndroid Build Coastguard Worker 583*9880d681SAndroid Build Coastguard Worker /// Number of byte of GDS required by kernel dispatch. Must be 0 if 584*9880d681SAndroid Build Coastguard Worker /// not using GDS. 585*9880d681SAndroid Build Coastguard Worker uint32_t gds_segment_byte_size; 586*9880d681SAndroid Build Coastguard Worker 587*9880d681SAndroid Build Coastguard Worker /// The size in bytes of the kernarg segment that holds the values 588*9880d681SAndroid Build Coastguard Worker /// of the arguments to the kernel. This could be used by CP to 589*9880d681SAndroid Build Coastguard Worker /// prefetch the kernarg segment pointed to by the dispatch packet. 590*9880d681SAndroid Build Coastguard Worker uint64_t kernarg_segment_byte_size; 591*9880d681SAndroid Build Coastguard Worker 592*9880d681SAndroid Build Coastguard Worker /// Number of fbarrier's used in the kernel and all functions it 593*9880d681SAndroid Build Coastguard Worker /// calls. If the implementation uses group memory to allocate the 594*9880d681SAndroid Build Coastguard Worker /// fbarriers then that amount must already be included in the 595*9880d681SAndroid Build Coastguard Worker /// workgroup_group_segment_byte_size total. 596*9880d681SAndroid Build Coastguard Worker uint32_t workgroup_fbarrier_count; 597*9880d681SAndroid Build Coastguard Worker 598*9880d681SAndroid Build Coastguard Worker /// Number of scalar registers used by a wavefront. This includes 599*9880d681SAndroid Build Coastguard Worker /// the special SGPRs for VCC, Flat Scratch Base, Flat Scratch Size 600*9880d681SAndroid Build Coastguard Worker /// and XNACK (for GFX8 (VI)). It does not include the 16 SGPR added if a 601*9880d681SAndroid Build Coastguard Worker /// trap handler is enabled. Used to set COMPUTE_PGM_RSRC1.SGPRS. 602*9880d681SAndroid Build Coastguard Worker uint16_t wavefront_sgpr_count; 603*9880d681SAndroid Build Coastguard Worker 604*9880d681SAndroid Build Coastguard Worker /// Number of vector registers used by each work-item. Used to set 605*9880d681SAndroid Build Coastguard Worker /// COMPUTE_PGM_RSRC1.VGPRS. 606*9880d681SAndroid Build Coastguard Worker uint16_t workitem_vgpr_count; 607*9880d681SAndroid Build Coastguard Worker 608*9880d681SAndroid Build Coastguard Worker /// If reserved_vgpr_count is 0 then must be 0. Otherwise, this is the 609*9880d681SAndroid Build Coastguard Worker /// first fixed VGPR number reserved. 610*9880d681SAndroid Build Coastguard Worker uint16_t reserved_vgpr_first; 611*9880d681SAndroid Build Coastguard Worker 612*9880d681SAndroid Build Coastguard Worker /// The number of consecutive VGPRs reserved by the client. If 613*9880d681SAndroid Build Coastguard Worker /// is_debug_supported then this count includes VGPRs reserved 614*9880d681SAndroid Build Coastguard Worker /// for debugger use. 615*9880d681SAndroid Build Coastguard Worker uint16_t reserved_vgpr_count; 616*9880d681SAndroid Build Coastguard Worker 617*9880d681SAndroid Build Coastguard Worker /// If reserved_sgpr_count is 0 then must be 0. Otherwise, this is the 618*9880d681SAndroid Build Coastguard Worker /// first fixed SGPR number reserved. 619*9880d681SAndroid Build Coastguard Worker uint16_t reserved_sgpr_first; 620*9880d681SAndroid Build Coastguard Worker 621*9880d681SAndroid Build Coastguard Worker /// The number of consecutive SGPRs reserved by the client. If 622*9880d681SAndroid Build Coastguard Worker /// is_debug_supported then this count includes SGPRs reserved 623*9880d681SAndroid Build Coastguard Worker /// for debugger use. 624*9880d681SAndroid Build Coastguard Worker uint16_t reserved_sgpr_count; 625*9880d681SAndroid Build Coastguard Worker 626*9880d681SAndroid Build Coastguard Worker /// If is_debug_supported is 0 then must be 0. Otherwise, this is the 627*9880d681SAndroid Build Coastguard Worker /// fixed SGPR number used to hold the wave scratch offset for the 628*9880d681SAndroid Build Coastguard Worker /// entire kernel execution, or uint16_t(-1) if the register is not 629*9880d681SAndroid Build Coastguard Worker /// used or not known. 630*9880d681SAndroid Build Coastguard Worker uint16_t debug_wavefront_private_segment_offset_sgpr; 631*9880d681SAndroid Build Coastguard Worker 632*9880d681SAndroid Build Coastguard Worker /// If is_debug_supported is 0 then must be 0. Otherwise, this is the 633*9880d681SAndroid Build Coastguard Worker /// fixed SGPR number of the first of 4 SGPRs used to hold the 634*9880d681SAndroid Build Coastguard Worker /// scratch V# used for the entire kernel execution, or uint16_t(-1) 635*9880d681SAndroid Build Coastguard Worker /// if the registers are not used or not known. 636*9880d681SAndroid Build Coastguard Worker uint16_t debug_private_segment_buffer_sgpr; 637*9880d681SAndroid Build Coastguard Worker 638*9880d681SAndroid Build Coastguard Worker /// The maximum byte alignment of variables used by the kernel in 639*9880d681SAndroid Build Coastguard Worker /// the specified memory segment. Expressed as a power of two. Must 640*9880d681SAndroid Build Coastguard Worker /// be at least HSA_POWERTWO_16. 641*9880d681SAndroid Build Coastguard Worker uint8_t kernarg_segment_alignment; 642*9880d681SAndroid Build Coastguard Worker uint8_t group_segment_alignment; 643*9880d681SAndroid Build Coastguard Worker uint8_t private_segment_alignment; 644*9880d681SAndroid Build Coastguard Worker 645*9880d681SAndroid Build Coastguard Worker /// Wavefront size expressed as a power of two. Must be a power of 2 646*9880d681SAndroid Build Coastguard Worker /// in range 1..64 inclusive. Used to support runtime query that 647*9880d681SAndroid Build Coastguard Worker /// obtains wavefront size, which may be used by application to 648*9880d681SAndroid Build Coastguard Worker /// allocated dynamic group memory and set the dispatch work-group 649*9880d681SAndroid Build Coastguard Worker /// size. 650*9880d681SAndroid Build Coastguard Worker uint8_t wavefront_size; 651*9880d681SAndroid Build Coastguard Worker 652*9880d681SAndroid Build Coastguard Worker int32_t call_convention; 653*9880d681SAndroid Build Coastguard Worker uint8_t reserved3[12]; 654*9880d681SAndroid Build Coastguard Worker uint64_t runtime_loader_kernel_symbol; 655*9880d681SAndroid Build Coastguard Worker uint64_t control_directives[16]; 656*9880d681SAndroid Build Coastguard Worker } amd_kernel_code_t; 657*9880d681SAndroid Build Coastguard Worker 658*9880d681SAndroid Build Coastguard Worker #endif // AMDKERNELCODET_H 659