xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDKernelCodeT.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric //===-- AMDGPUKernelCodeT.h - Print AMDGPU assembly code ---------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file AMDKernelCodeT.h
90b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
100b57cec5SDimitry Andric 
110b57cec5SDimitry Andric #ifndef AMDKERNELCODET_H
120b57cec5SDimitry Andric #define AMDKERNELCODET_H
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include <cstdint>
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric //---------------------------------------------------------------------------//
170b57cec5SDimitry Andric // AMD Kernel Code, and its dependencies                                     //
180b57cec5SDimitry Andric //---------------------------------------------------------------------------//
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric typedef uint8_t hsa_powertwo8_t;
210b57cec5SDimitry Andric typedef uint32_t hsa_ext_code_kind_t;
220b57cec5SDimitry Andric typedef uint8_t hsa_ext_brig_profile8_t;
230b57cec5SDimitry Andric typedef uint8_t hsa_ext_brig_machine_model8_t;
240b57cec5SDimitry Andric typedef uint64_t hsa_ext_control_directive_present64_t;
250b57cec5SDimitry Andric typedef uint16_t hsa_ext_exception_kind16_t;
260b57cec5SDimitry Andric typedef uint32_t hsa_ext_code_kind32_t;
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric typedef struct hsa_dim3_s {
290b57cec5SDimitry Andric   uint32_t x;
300b57cec5SDimitry Andric   uint32_t y;
310b57cec5SDimitry Andric   uint32_t z;
320b57cec5SDimitry Andric } hsa_dim3_t;
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric /// The version of the amd_*_code_t struct. Minor versions must be
350b57cec5SDimitry Andric /// backward compatible.
360b57cec5SDimitry Andric typedef uint32_t amd_code_version32_t;
370b57cec5SDimitry Andric enum amd_code_version_t {
380b57cec5SDimitry Andric   AMD_CODE_VERSION_MAJOR = 0,
390b57cec5SDimitry Andric   AMD_CODE_VERSION_MINOR = 1
400b57cec5SDimitry Andric };
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric // Sets val bits for specified mask in specified dst packed instance.
430b57cec5SDimitry Andric #define AMD_HSA_BITS_SET(dst, mask, val)                                       \
440b57cec5SDimitry Andric   dst &= (~(1 << mask ## _SHIFT) & ~mask);                                     \
450b57cec5SDimitry Andric   dst |= (((val) << mask ## _SHIFT) & mask)
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric // Gets bits for specified mask from specified src packed instance.
480b57cec5SDimitry Andric #define AMD_HSA_BITS_GET(src, mask)                                            \
490b57cec5SDimitry Andric   ((src & mask) >> mask ## _SHIFT)                                             \
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric /// The values used to define the number of bytes to use for the
520b57cec5SDimitry Andric /// swizzle element size.
530b57cec5SDimitry Andric enum amd_element_byte_size_t {
540b57cec5SDimitry Andric   AMD_ELEMENT_2_BYTES = 0,
550b57cec5SDimitry Andric   AMD_ELEMENT_4_BYTES = 1,
560b57cec5SDimitry Andric   AMD_ELEMENT_8_BYTES = 2,
570b57cec5SDimitry Andric   AMD_ELEMENT_16_BYTES = 3
580b57cec5SDimitry Andric };
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric /// Shader program settings for CS. Contains COMPUTE_PGM_RSRC1 and
610b57cec5SDimitry Andric /// COMPUTE_PGM_RSRC2 registers.
620b57cec5SDimitry Andric typedef uint64_t amd_compute_pgm_resource_register64_t;
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric /// Every amd_*_code_t has the following properties, which are composed of
650b57cec5SDimitry Andric /// a number of bit fields. Every bit field has a mask (AMD_CODE_PROPERTY_*),
660b57cec5SDimitry Andric /// bit width (AMD_CODE_PROPERTY_*_WIDTH, and bit shift amount
670b57cec5SDimitry Andric /// (AMD_CODE_PROPERTY_*_SHIFT) for convenient access. Unused bits must be 0.
680b57cec5SDimitry Andric ///
690b57cec5SDimitry Andric /// (Note that bit fields cannot be used as their layout is
700b57cec5SDimitry Andric /// implementation defined in the C standard and so cannot be used to
710b57cec5SDimitry Andric /// specify an ABI)
720b57cec5SDimitry Andric typedef uint32_t amd_code_property32_t;
730b57cec5SDimitry Andric enum amd_code_property_mask_t {
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric   /// Enable the setup of the SGPR user data registers
760b57cec5SDimitry Andric   /// (AMD_CODE_PROPERTY_ENABLE_SGPR_*), see documentation of amd_kernel_code_t
770b57cec5SDimitry Andric   /// for initial register state.
780b57cec5SDimitry Andric   ///
790b57cec5SDimitry Andric   /// The total number of SGPRuser data registers requested must not
800b57cec5SDimitry Andric   /// exceed 16. Any requests beyond 16 will be ignored.
810b57cec5SDimitry Andric   ///
820b57cec5SDimitry Andric   /// Used to set COMPUTE_PGM_RSRC2.USER_SGPR (set to total count of
830b57cec5SDimitry Andric   /// SGPR user data registers enabled up to 16).
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER_SHIFT = 0,
860b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER_WIDTH = 1,
870b57cec5SDimitry Andric   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,
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR_SHIFT = 1,
900b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR_WIDTH = 1,
910b57cec5SDimitry Andric   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,
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR_SHIFT = 2,
940b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR_WIDTH = 1,
950b57cec5SDimitry Andric   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,
960b57cec5SDimitry Andric 
970b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR_SHIFT = 3,
980b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR_WIDTH = 1,
990b57cec5SDimitry Andric   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,
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID_SHIFT = 4,
1020b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID_WIDTH = 1,
1030b57cec5SDimitry Andric   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,
1040b57cec5SDimitry Andric 
1050b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT_SHIFT = 5,
1060b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT_WIDTH = 1,
1070b57cec5SDimitry Andric   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,
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE_SHIFT = 6,
1100b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_SIZE_WIDTH = 1,
1110b57cec5SDimitry Andric   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,
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X_SHIFT = 7,
1140b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X_WIDTH = 1,
1150b57cec5SDimitry Andric   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,
1160b57cec5SDimitry Andric 
1170b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y_SHIFT = 8,
1180b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y_WIDTH = 1,
1190b57cec5SDimitry Andric   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,
1200b57cec5SDimitry Andric 
1210b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z_SHIFT = 9,
1220b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z_WIDTH = 1,
1230b57cec5SDimitry Andric   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,
1240b57cec5SDimitry Andric 
1250b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32_SHIFT = 10,
1260b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32_WIDTH = 1,
1270b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32 = ((1 << AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32_WIDTH) - 1) << AMD_CODE_PROPERTY_ENABLE_WAVEFRONT_SIZE32_SHIFT,
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric   AMD_CODE_PROPERTY_RESERVED1_SHIFT = 11,
1300b57cec5SDimitry Andric   AMD_CODE_PROPERTY_RESERVED1_WIDTH = 5,
1310b57cec5SDimitry Andric   AMD_CODE_PROPERTY_RESERVED1 = ((1 << AMD_CODE_PROPERTY_RESERVED1_WIDTH) - 1) << AMD_CODE_PROPERTY_RESERVED1_SHIFT,
1320b57cec5SDimitry Andric 
1330b57cec5SDimitry Andric   /// Control wave ID base counter for GDS ordered-append. Used to set
1340b57cec5SDimitry Andric   /// COMPUTE_DISPATCH_INITIATOR.ORDERED_APPEND_ENBL. (Not sure if
1350b57cec5SDimitry Andric   /// ORDERED_APPEND_MODE also needs to be settable)
1360b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_ORDERED_APPEND_GDS_SHIFT = 16,
1370b57cec5SDimitry Andric   AMD_CODE_PROPERTY_ENABLE_ORDERED_APPEND_GDS_WIDTH = 1,
1380b57cec5SDimitry Andric   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,
1390b57cec5SDimitry Andric 
1400b57cec5SDimitry Andric   /// The interleave (swizzle) element size in bytes required by the
1410b57cec5SDimitry Andric   /// code for private memory. This must be 2, 4, 8 or 16. This value
1420b57cec5SDimitry Andric   /// is provided to the finalizer when it is invoked and is recorded
1430b57cec5SDimitry Andric   /// here. The hardware will interleave the memory requests of each
1440b57cec5SDimitry Andric   /// lane of a wavefront by this element size to ensure each
145*81ad6265SDimitry Andric   /// work-item gets a distinct memory location. Therefore, the
1460b57cec5SDimitry Andric   /// finalizer ensures that all load and store operations done to
1470b57cec5SDimitry Andric   /// private memory do not exceed this size. For example, if the
1480b57cec5SDimitry Andric   /// element size is 4 (32-bits or dword) and a 64-bit value must be
1490b57cec5SDimitry Andric   /// loaded, the finalizer will generate two 32-bit loads. This
1500b57cec5SDimitry Andric   /// ensures that the interleaving will get the work-item
1510b57cec5SDimitry Andric   /// specific dword for both halves of the 64-bit value. If it just
1520b57cec5SDimitry Andric   /// did a 64-bit load then it would get one dword which belonged to
1530b57cec5SDimitry Andric   /// its own work-item, but the second dword would belong to the
1540b57cec5SDimitry Andric   /// adjacent lane work-item since the interleaving is in dwords.
1550b57cec5SDimitry Andric   ///
1560b57cec5SDimitry Andric   /// The value used must match the value that the runtime configures
1570b57cec5SDimitry Andric   /// the GPU flat scratch (SH_STATIC_MEM_CONFIG.ELEMENT_SIZE). This
1580b57cec5SDimitry Andric   /// is generally DWORD.
1590b57cec5SDimitry Andric   ///
1600b57cec5SDimitry Andric   /// uSE VALUES FROM THE AMD_ELEMENT_BYTE_SIZE_T ENUM.
1610b57cec5SDimitry Andric   AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_SHIFT = 17,
1620b57cec5SDimitry Andric   AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_WIDTH = 2,
1630b57cec5SDimitry Andric   AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE = ((1 << AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_WIDTH) - 1) << AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE_SHIFT,
1640b57cec5SDimitry Andric 
1650b57cec5SDimitry Andric   /// Are global memory addresses 64 bits. Must match
1660b57cec5SDimitry Andric   /// amd_kernel_code_t.hsail_machine_model ==
1670b57cec5SDimitry Andric   /// HSA_MACHINE_LARGE. Must also match
1680b57cec5SDimitry Andric   /// SH_MEM_CONFIG.PTR32 (GFX6 (SI)/GFX7 (CI)),
1690b57cec5SDimitry Andric   /// SH_MEM_CONFIG.ADDRESS_MODE (GFX8 (VI)+).
1700b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_PTR64_SHIFT = 19,
1710b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_PTR64_WIDTH = 1,
1720b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_PTR64 = ((1 << AMD_CODE_PROPERTY_IS_PTR64_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_PTR64_SHIFT,
1730b57cec5SDimitry Andric 
1740b57cec5SDimitry Andric   /// Indicate if the generated ISA is using a dynamically sized call
1750b57cec5SDimitry Andric   /// stack. This can happen if calls are implemented using a call
1760b57cec5SDimitry Andric   /// stack and recursion, alloca or calls to indirect functions are
1770b57cec5SDimitry Andric   /// present. In these cases the Finalizer cannot compute the total
1780b57cec5SDimitry Andric   /// private segment size at compile time. In this case the
1790b57cec5SDimitry Andric   /// workitem_private_segment_byte_size only specifies the statically
1800b57cec5SDimitry Andric   /// know private segment size, and additional space must be added
1810b57cec5SDimitry Andric   /// for the call stack.
1820b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_SHIFT = 20,
1830b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_WIDTH = 1,
1840b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK = ((1 << AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_DYNAMIC_CALLSTACK_SHIFT,
1850b57cec5SDimitry Andric 
1860b57cec5SDimitry Andric   /// Indicate if code generated has support for debugging.
1870b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_SHIFT = 21,
1880b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_WIDTH = 1,
1890b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED = ((1 << AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED_SHIFT,
1900b57cec5SDimitry Andric 
1910b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_SHIFT = 22,
1920b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_WIDTH = 1,
1930b57cec5SDimitry Andric   AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED = ((1 << AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_WIDTH) - 1) << AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED_SHIFT,
1940b57cec5SDimitry Andric 
1950b57cec5SDimitry Andric   AMD_CODE_PROPERTY_RESERVED2_SHIFT = 23,
1960b57cec5SDimitry Andric   AMD_CODE_PROPERTY_RESERVED2_WIDTH = 9,
1970b57cec5SDimitry Andric   AMD_CODE_PROPERTY_RESERVED2 = ((1 << AMD_CODE_PROPERTY_RESERVED2_WIDTH) - 1) << AMD_CODE_PROPERTY_RESERVED2_SHIFT
1980b57cec5SDimitry Andric };
1990b57cec5SDimitry Andric 
2000b57cec5SDimitry Andric /// The hsa_ext_control_directives_t specifies the values for the HSAIL
2010b57cec5SDimitry Andric /// control directives. These control how the finalizer generates code. This
2020b57cec5SDimitry Andric /// struct is used both as an argument to hsaFinalizeKernel to specify values for
2030b57cec5SDimitry Andric /// the control directives, and is used in HsaKernelCode to record the values of
2040b57cec5SDimitry Andric /// the control directives that the finalize used when generating the code which
2050b57cec5SDimitry Andric /// either came from the finalizer argument or explicit HSAIL control
2060b57cec5SDimitry Andric /// directives. See the definition of the control directives in HSA Programmer's
2070b57cec5SDimitry Andric /// Reference Manual which also defines how the values specified as finalizer
2080b57cec5SDimitry Andric /// arguments have to agree with the control directives in the HSAIL code.
2090b57cec5SDimitry Andric typedef struct hsa_ext_control_directives_s {
2100b57cec5SDimitry Andric   /// This is a bit set indicating which control directives have been
2110b57cec5SDimitry Andric   /// specified. If the value is 0 then there are no control directives specified
2120b57cec5SDimitry Andric   /// and the rest of the fields can be ignored. The bits are accessed using the
2130b57cec5SDimitry Andric   /// hsa_ext_control_directives_present_mask_t. Any control directive that is not
2140b57cec5SDimitry Andric   /// enabled in this bit set must have the value of all 0s.
2150b57cec5SDimitry Andric   hsa_ext_control_directive_present64_t enabled_control_directives;
2160b57cec5SDimitry Andric 
2170b57cec5SDimitry Andric   /// If enableBreakExceptions is not enabled then must be 0, otherwise must be
2180b57cec5SDimitry Andric   /// non-0 and specifies the set of HSAIL exceptions that must have the BREAK
2190b57cec5SDimitry Andric   /// policy enabled. If this set is not empty then the generated code may have
2200b57cec5SDimitry Andric   /// lower performance than if the set is empty. If the kernel being finalized
2210b57cec5SDimitry Andric   /// has any enablebreakexceptions control directives, then the values specified
2220b57cec5SDimitry Andric   /// by this argument are unioned with the values in these control
2230b57cec5SDimitry Andric   /// directives. If any of the functions the kernel calls have an
2240b57cec5SDimitry Andric   /// enablebreakexceptions control directive, then they must be equal or a
2250b57cec5SDimitry Andric   /// subset of, this union.
2260b57cec5SDimitry Andric   hsa_ext_exception_kind16_t enable_break_exceptions;
2270b57cec5SDimitry Andric 
2280b57cec5SDimitry Andric   /// If enableDetectExceptions is not enabled then must be 0, otherwise must be
2290b57cec5SDimitry Andric   /// non-0 and specifies the set of HSAIL exceptions that must have the DETECT
2300b57cec5SDimitry Andric   /// policy enabled. If this set is not empty then the generated code may have
2310b57cec5SDimitry Andric   /// lower performance than if the set is empty. However, an implementation
2320b57cec5SDimitry Andric   /// should endeavour to make the performance impact small. If the kernel being
2330b57cec5SDimitry Andric   /// finalized has any enabledetectexceptions control directives, then the
2340b57cec5SDimitry Andric   /// values specified by this argument are unioned with the values in these
2350b57cec5SDimitry Andric   /// control directives. If any of the functions the kernel calls have an
2360b57cec5SDimitry Andric   /// enabledetectexceptions control directive, then they must be equal or a
2370b57cec5SDimitry Andric   /// subset of, this union.
2380b57cec5SDimitry Andric   hsa_ext_exception_kind16_t enable_detect_exceptions;
2390b57cec5SDimitry Andric 
2400b57cec5SDimitry Andric   /// If maxDynamicGroupSize is not enabled then must be 0, and any amount of
2410b57cec5SDimitry Andric   /// dynamic group segment can be allocated for a dispatch, otherwise the value
2420b57cec5SDimitry Andric   /// specifies the maximum number of bytes of dynamic group segment that can be
2430b57cec5SDimitry Andric   /// allocated for a dispatch. If the kernel being finalized has any
2440b57cec5SDimitry Andric   /// maxdynamicsize control directives, then the values must be the same, and
2450b57cec5SDimitry Andric   /// must be the same as this argument if it is enabled. This value can be used
2460b57cec5SDimitry Andric   /// by the finalizer to determine the maximum number of bytes of group memory
2470b57cec5SDimitry Andric   /// used by each work-group by adding this value to the group memory required
2480b57cec5SDimitry Andric   /// for all group segment variables used by the kernel and all functions it
2490b57cec5SDimitry Andric   /// calls, and group memory used to implement other HSAIL features such as
2500b57cec5SDimitry Andric   /// fbarriers and the detect exception operations. This can allow the finalizer
2510b57cec5SDimitry Andric   /// to determine the expected number of work-groups that can be executed by a
2520b57cec5SDimitry Andric   /// compute unit and allow more resources to be allocated to the work-items if
2530b57cec5SDimitry Andric   /// it is known that fewer work-groups can be executed due to group memory
2540b57cec5SDimitry Andric   /// limitations.
2550b57cec5SDimitry Andric   uint32_t max_dynamic_group_size;
2560b57cec5SDimitry Andric 
2570b57cec5SDimitry Andric   /// If maxFlatGridSize is not enabled then must be 0, otherwise must be greater
2580b57cec5SDimitry Andric   /// than 0. See HSA Programmer's Reference Manual description of
2590b57cec5SDimitry Andric   /// maxflatgridsize control directive.
2600b57cec5SDimitry Andric   uint32_t max_flat_grid_size;
2610b57cec5SDimitry Andric 
2620b57cec5SDimitry Andric   /// If maxFlatWorkgroupSize is not enabled then must be 0, otherwise must be
2630b57cec5SDimitry Andric   /// greater than 0. See HSA Programmer's Reference Manual description of
2640b57cec5SDimitry Andric   /// maxflatworkgroupsize control directive.
2650b57cec5SDimitry Andric   uint32_t max_flat_workgroup_size;
2660b57cec5SDimitry Andric 
2670b57cec5SDimitry Andric   /// If requestedWorkgroupsPerCu is not enabled then must be 0, and the
2680b57cec5SDimitry Andric   /// finalizer is free to generate ISA that may result in any number of
2690b57cec5SDimitry Andric   /// work-groups executing on a single compute unit. Otherwise, the finalizer
2700b57cec5SDimitry Andric   /// should attempt to generate ISA that will allow the specified number of
2710b57cec5SDimitry Andric   /// work-groups to execute on a single compute unit. This is only a hint and
2720b57cec5SDimitry Andric   /// can be ignored by the finalizer. If the kernel being finalized, or any of
2730b57cec5SDimitry Andric   /// the functions it calls, has a requested control directive, then the values
2740b57cec5SDimitry Andric   /// must be the same. This can be used to determine the number of resources
2750b57cec5SDimitry Andric   /// that should be allocated to a single work-group and work-item. For example,
2760b57cec5SDimitry Andric   /// a low value may allow more resources to be allocated, resulting in higher
2770b57cec5SDimitry Andric   /// per work-item performance, as it is known there will never be more than the
2780b57cec5SDimitry Andric   /// specified number of work-groups actually executing on the compute
2790b57cec5SDimitry Andric   /// unit. Conversely, a high value may allocate fewer resources, resulting in
2800b57cec5SDimitry Andric   /// lower per work-item performance, which is offset by the fact it allows more
2810b57cec5SDimitry Andric   /// work-groups to actually execute on the compute unit.
2820b57cec5SDimitry Andric   uint32_t requested_workgroups_per_cu;
2830b57cec5SDimitry Andric 
2840b57cec5SDimitry Andric   /// If not enabled then all elements for Dim3 must be 0, otherwise every
2850b57cec5SDimitry Andric   /// element must be greater than 0. See HSA Programmer's Reference Manual
2860b57cec5SDimitry Andric   /// description of requiredgridsize control directive.
2870b57cec5SDimitry Andric   hsa_dim3_t required_grid_size;
2880b57cec5SDimitry Andric 
2890b57cec5SDimitry Andric   /// If requiredWorkgroupSize is not enabled then all elements for Dim3 must be
2900b57cec5SDimitry Andric   /// 0, and the produced code can be dispatched with any legal work-group range
2910b57cec5SDimitry Andric   /// consistent with the dispatch dimensions. Otherwise, the code produced must
2920b57cec5SDimitry Andric   /// always be dispatched with the specified work-group range. No element of the
2930b57cec5SDimitry Andric   /// specified range must be 0. It must be consistent with required_dimensions
2940b57cec5SDimitry Andric   /// and max_flat_workgroup_size. If the kernel being finalized, or any of the
2950b57cec5SDimitry Andric   /// functions it calls, has a requiredworkgroupsize control directive, then the
2960b57cec5SDimitry Andric   /// values must be the same. Specifying a value can allow the finalizer to
2970b57cec5SDimitry Andric   /// optimize work-group id operations, and if the number of work-items in the
2980b57cec5SDimitry Andric   /// work-group is less than the WAVESIZE then barrier operations can be
2990b57cec5SDimitry Andric   /// optimized to just a memory fence.
3000b57cec5SDimitry Andric   hsa_dim3_t required_workgroup_size;
3010b57cec5SDimitry Andric 
3020b57cec5SDimitry Andric   /// If requiredDim is not enabled then must be 0 and the produced kernel code
3030b57cec5SDimitry Andric   /// can be dispatched with 1, 2 or 3 dimensions. If enabled then the value is
3040b57cec5SDimitry Andric   /// 1..3 and the code produced must only be dispatched with a dimension that
3050b57cec5SDimitry Andric   /// matches. Other values are illegal. If the kernel being finalized, or any of
3060b57cec5SDimitry Andric   /// the functions it calls, has a requireddimsize control directive, then the
3070b57cec5SDimitry Andric   /// values must be the same. This can be used to optimize the code generated to
3080b57cec5SDimitry Andric   /// compute the absolute and flat work-group and work-item id, and the dim
3090b57cec5SDimitry Andric   /// HSAIL operations.
3100b57cec5SDimitry Andric   uint8_t required_dim;
3110b57cec5SDimitry Andric 
3120b57cec5SDimitry Andric   /// Reserved. Must be 0.
3130b57cec5SDimitry Andric   uint8_t reserved[75];
3140b57cec5SDimitry Andric } hsa_ext_control_directives_t;
3150b57cec5SDimitry Andric 
3160b57cec5SDimitry Andric /// AMD Kernel Code Object (amd_kernel_code_t). GPU CP uses the AMD Kernel
3170b57cec5SDimitry Andric /// Code Object to set up the hardware to execute the kernel dispatch.
3180b57cec5SDimitry Andric ///
3190b57cec5SDimitry Andric /// Initial Kernel Register State.
3200b57cec5SDimitry Andric ///
3210b57cec5SDimitry Andric /// Initial kernel register state will be set up by CP/SPI prior to the start
3220b57cec5SDimitry Andric /// of execution of every wavefront. This is limited by the constraints of the
3230b57cec5SDimitry Andric /// current hardware.
3240b57cec5SDimitry Andric ///
3250b57cec5SDimitry Andric /// The order of the SGPR registers is defined, but the Finalizer can specify
3260b57cec5SDimitry Andric /// which ones are actually setup in the amd_kernel_code_t object using the
3270b57cec5SDimitry Andric /// enable_sgpr_* bit fields. The register numbers used for enabled registers
3280b57cec5SDimitry Andric /// are dense starting at SGPR0: the first enabled register is SGPR0, the next
3290b57cec5SDimitry Andric /// enabled register is SGPR1 etc.; disabled registers do not have an SGPR
3300b57cec5SDimitry Andric /// number.
3310b57cec5SDimitry Andric ///
3320b57cec5SDimitry Andric /// The initial SGPRs comprise up to 16 User SRGPs that are set up by CP and
3330b57cec5SDimitry Andric /// apply to all waves of the grid. It is possible to specify more than 16 User
3340b57cec5SDimitry Andric /// SGPRs using the enable_sgpr_* bit fields, in which case only the first 16
3350b57cec5SDimitry Andric /// are actually initialized. These are then immediately followed by the System
3360b57cec5SDimitry Andric /// SGPRs that are set up by ADC/SPI and can have different values for each wave
3370b57cec5SDimitry Andric /// of the grid dispatch.
3380b57cec5SDimitry Andric ///
3390b57cec5SDimitry Andric /// SGPR register initial state is defined as follows:
3400b57cec5SDimitry Andric ///
3410b57cec5SDimitry Andric /// Private Segment Buffer (enable_sgpr_private_segment_buffer):
3420b57cec5SDimitry Andric ///   Number of User SGPR registers: 4. V# that can be used, together with
3430b57cec5SDimitry Andric ///   Scratch Wave Offset as an offset, to access the Private/Spill/Arg
3440b57cec5SDimitry Andric ///   segments using a segment address. It must be set as follows:
3450b57cec5SDimitry Andric ///     - Base address: of the scratch memory area used by the dispatch. It
3460b57cec5SDimitry Andric ///       does not include the scratch wave offset. It will be the per process
3470b57cec5SDimitry Andric ///       SH_HIDDEN_PRIVATE_BASE_VMID plus any offset from this dispatch (for
3480b57cec5SDimitry Andric ///       example there may be a per pipe offset, or per AQL Queue offset).
3490b57cec5SDimitry Andric ///     - Stride + data_format: Element Size * Index Stride (???)
3500b57cec5SDimitry Andric ///     - Cache swizzle: ???
3510b57cec5SDimitry Andric ///     - Swizzle enable: SH_STATIC_MEM_CONFIG.SWIZZLE_ENABLE (must be 1 for
3520b57cec5SDimitry Andric ///       scratch)
3530b57cec5SDimitry Andric ///     - Num records: Flat Scratch Work Item Size / Element Size (???)
3540b57cec5SDimitry Andric ///     - Dst_sel_*: ???
3550b57cec5SDimitry Andric ///     - Num_format: ???
3560b57cec5SDimitry Andric ///     - Element_size: SH_STATIC_MEM_CONFIG.ELEMENT_SIZE (will be DWORD, must
3570b57cec5SDimitry Andric ///       agree with amd_kernel_code_t.privateElementSize)
3580b57cec5SDimitry Andric ///     - Index_stride: SH_STATIC_MEM_CONFIG.INDEX_STRIDE (will be 64 as must
3590b57cec5SDimitry Andric ///       be number of wavefront lanes for scratch, must agree with
3600b57cec5SDimitry Andric ///       amd_kernel_code_t.wavefrontSize)
3610b57cec5SDimitry Andric ///     - Add tid enable: 1
3620b57cec5SDimitry Andric ///     - ATC: from SH_MEM_CONFIG.PRIVATE_ATC,
3630b57cec5SDimitry Andric ///     - Hash_enable: ???
3640b57cec5SDimitry Andric ///     - Heap: ???
3650b57cec5SDimitry Andric ///     - Mtype: from SH_STATIC_MEM_CONFIG.PRIVATE_MTYPE
3660b57cec5SDimitry Andric ///     - Type: 0 (a buffer) (???)
3670b57cec5SDimitry Andric ///
3680b57cec5SDimitry Andric /// Dispatch Ptr (enable_sgpr_dispatch_ptr):
3690b57cec5SDimitry Andric ///   Number of User SGPR registers: 2. 64 bit address of AQL dispatch packet
3700b57cec5SDimitry Andric ///   for kernel actually executing.
3710b57cec5SDimitry Andric ///
3720b57cec5SDimitry Andric /// Queue Ptr (enable_sgpr_queue_ptr):
3730b57cec5SDimitry Andric ///   Number of User SGPR registers: 2. 64 bit address of AmdQueue object for
3740b57cec5SDimitry Andric ///   AQL queue on which the dispatch packet was queued.
3750b57cec5SDimitry Andric ///
3760b57cec5SDimitry Andric /// Kernarg Segment Ptr (enable_sgpr_kernarg_segment_ptr):
3770b57cec5SDimitry Andric ///   Number of User SGPR registers: 2. 64 bit address of Kernarg segment. This
3780b57cec5SDimitry Andric ///   is directly copied from the kernargPtr in the dispatch packet. Having CP
3790b57cec5SDimitry Andric ///   load it once avoids loading it at the beginning of every wavefront.
3800b57cec5SDimitry Andric ///
3810b57cec5SDimitry Andric /// Dispatch Id (enable_sgpr_dispatch_id):
3820b57cec5SDimitry Andric ///   Number of User SGPR registers: 2. 64 bit Dispatch ID of the dispatch
3830b57cec5SDimitry Andric ///   packet being executed.
3840b57cec5SDimitry Andric ///
3850b57cec5SDimitry Andric /// Flat Scratch Init (enable_sgpr_flat_scratch_init):
3860b57cec5SDimitry Andric ///   Number of User SGPR registers: 2. This is 2 SGPRs.
3870b57cec5SDimitry Andric ///
3880b57cec5SDimitry Andric ///   For CI/VI:
3890b57cec5SDimitry Andric ///     The first SGPR is a 32 bit byte offset from SH_MEM_HIDDEN_PRIVATE_BASE
3900b57cec5SDimitry Andric ///     to base of memory for scratch for this dispatch. This is the same offset
3910b57cec5SDimitry Andric ///     used in computing the Scratch Segment Buffer base address. The value of
3920b57cec5SDimitry Andric ///     Scratch Wave Offset must be added by the kernel code and moved to
3930b57cec5SDimitry Andric ///     SGPRn-4 for use as the FLAT SCRATCH BASE in flat memory instructions.
3940b57cec5SDimitry Andric ///
3950b57cec5SDimitry Andric ///     The second SGPR is 32 bit byte size of a single work-item's scratch
3960b57cec5SDimitry Andric ///     memory usage. This is directly loaded from the dispatch packet Private
3970b57cec5SDimitry Andric ///     Segment Byte Size and rounded up to a multiple of DWORD.
3980b57cec5SDimitry Andric ///
3990b57cec5SDimitry Andric ///     \todo [Does CP need to round this to >4 byte alignment?]
4000b57cec5SDimitry Andric ///
4010b57cec5SDimitry Andric ///     The kernel code must move to SGPRn-3 for use as the FLAT SCRATCH SIZE in
4020b57cec5SDimitry Andric ///     flat memory instructions. Having CP load it once avoids loading it at
4030b57cec5SDimitry Andric ///     the beginning of every wavefront.
4040b57cec5SDimitry Andric ///
4050b57cec5SDimitry Andric ///   For PI:
4060b57cec5SDimitry Andric ///     This is the 64 bit base address of the scratch backing memory for
4070b57cec5SDimitry Andric ///     allocated by CP for this dispatch.
4080b57cec5SDimitry Andric ///
4090b57cec5SDimitry Andric /// Private Segment Size (enable_sgpr_private_segment_size):
4100b57cec5SDimitry Andric ///   Number of User SGPR registers: 1. The 32 bit byte size of a single
4110b57cec5SDimitry Andric ///   work-item's scratch memory allocation. This is the value from the dispatch
4120b57cec5SDimitry Andric ///   packet. Private Segment Byte Size rounded up by CP to a multiple of DWORD.
4130b57cec5SDimitry Andric ///
4140b57cec5SDimitry Andric ///   \todo [Does CP need to round this to >4 byte alignment?]
4150b57cec5SDimitry Andric ///
4160b57cec5SDimitry Andric ///   Having CP load it once avoids loading it at the beginning of every
4170b57cec5SDimitry Andric ///   wavefront.
4180b57cec5SDimitry Andric ///
4190b57cec5SDimitry Andric ///   \todo [This will not be used for CI/VI since it is the same value as
4200b57cec5SDimitry Andric ///   the second SGPR of Flat Scratch Init. However, it is need for PI which
4210b57cec5SDimitry Andric ///   changes meaning of Flat Scratchg Init..]
4220b57cec5SDimitry Andric ///
4230b57cec5SDimitry Andric /// Grid Work-Group Count X (enable_sgpr_grid_workgroup_count_x):
4240b57cec5SDimitry Andric ///   Number of User SGPR registers: 1. 32 bit count of the number of
4250b57cec5SDimitry Andric ///   work-groups in the X dimension for the grid being executed. Computed from
4260b57cec5SDimitry Andric ///   the fields in the HsaDispatchPacket as
4270b57cec5SDimitry Andric ///   ((gridSize.x+workgroupSize.x-1)/workgroupSize.x).
4280b57cec5SDimitry Andric ///
4290b57cec5SDimitry Andric /// Grid Work-Group Count Y (enable_sgpr_grid_workgroup_count_y):
4300b57cec5SDimitry Andric ///   Number of User SGPR registers: 1. 32 bit count of the number of
4310b57cec5SDimitry Andric ///   work-groups in the Y dimension for the grid being executed. Computed from
4320b57cec5SDimitry Andric ///   the fields in the HsaDispatchPacket as
4330b57cec5SDimitry Andric ///   ((gridSize.y+workgroupSize.y-1)/workgroupSize.y).
4340b57cec5SDimitry Andric ///
4350b57cec5SDimitry Andric ///   Only initialized if <16 previous SGPRs initialized.
4360b57cec5SDimitry Andric ///
4370b57cec5SDimitry Andric /// Grid Work-Group Count Z (enable_sgpr_grid_workgroup_count_z):
4380b57cec5SDimitry Andric ///   Number of User SGPR registers: 1. 32 bit count of the number of
4390b57cec5SDimitry Andric ///   work-groups in the Z dimension for the grid being executed. Computed
4400b57cec5SDimitry Andric ///   from the fields in the HsaDispatchPacket as
4410b57cec5SDimitry Andric ///   ((gridSize.z+workgroupSize.z-1)/workgroupSize.z).
4420b57cec5SDimitry Andric ///
4430b57cec5SDimitry Andric ///   Only initialized if <16 previous SGPRs initialized.
4440b57cec5SDimitry Andric ///
4450b57cec5SDimitry Andric /// Work-Group Id X (enable_sgpr_workgroup_id_x):
4460b57cec5SDimitry Andric ///   Number of System SGPR registers: 1. 32 bit work group id in X dimension
4470b57cec5SDimitry Andric ///   of grid for wavefront. Always present.
4480b57cec5SDimitry Andric ///
4490b57cec5SDimitry Andric /// Work-Group Id Y (enable_sgpr_workgroup_id_y):
4500b57cec5SDimitry Andric ///   Number of System SGPR registers: 1. 32 bit work group id in Y dimension
4510b57cec5SDimitry Andric ///   of grid for wavefront.
4520b57cec5SDimitry Andric ///
4530b57cec5SDimitry Andric /// Work-Group Id Z (enable_sgpr_workgroup_id_z):
4540b57cec5SDimitry Andric ///   Number of System SGPR registers: 1. 32 bit work group id in Z dimension
4550b57cec5SDimitry Andric ///   of grid for wavefront. If present then Work-group Id Y will also be
4560b57cec5SDimitry Andric ///   present
4570b57cec5SDimitry Andric ///
4580b57cec5SDimitry Andric /// Work-Group Info (enable_sgpr_workgroup_info):
4590b57cec5SDimitry Andric ///   Number of System SGPR registers: 1. {first_wave, 14'b0000,
4600b57cec5SDimitry Andric ///   ordered_append_term[10:0], threadgroup_size_in_waves[5:0]}
4610b57cec5SDimitry Andric ///
4620b57cec5SDimitry Andric /// Private Segment Wave Byte Offset
4630b57cec5SDimitry Andric /// (enable_sgpr_private_segment_wave_byte_offset):
4640b57cec5SDimitry Andric ///   Number of System SGPR registers: 1. 32 bit byte offset from base of
4650b57cec5SDimitry Andric ///   dispatch scratch base. Must be used as an offset with Private/Spill/Arg
4660b57cec5SDimitry Andric ///   segment address when using Scratch Segment Buffer. It must be added to
4670b57cec5SDimitry Andric ///   Flat Scratch Offset if setting up FLAT SCRATCH for flat addressing.
4680b57cec5SDimitry Andric ///
4690b57cec5SDimitry Andric ///
4700b57cec5SDimitry Andric /// The order of the VGPR registers is defined, but the Finalizer can specify
4710b57cec5SDimitry Andric /// which ones are actually setup in the amd_kernel_code_t object using the
4720b57cec5SDimitry Andric /// enableVgpr*  bit fields. The register numbers used for enabled registers
4730b57cec5SDimitry Andric /// are dense starting at VGPR0: the first enabled register is VGPR0, the next
4740b57cec5SDimitry Andric /// enabled register is VGPR1 etc.; disabled registers do not have an VGPR
4750b57cec5SDimitry Andric /// number.
4760b57cec5SDimitry Andric ///
4770b57cec5SDimitry Andric /// VGPR register initial state is defined as follows:
4780b57cec5SDimitry Andric ///
4790b57cec5SDimitry Andric /// Work-Item Id X (always initialized):
4800b57cec5SDimitry Andric ///   Number of registers: 1. 32 bit work item id in X dimension of work-group
4810b57cec5SDimitry Andric ///   for wavefront lane.
4820b57cec5SDimitry Andric ///
4830b57cec5SDimitry Andric /// Work-Item Id X (enable_vgpr_workitem_id > 0):
4840b57cec5SDimitry Andric ///   Number of registers: 1. 32 bit work item id in Y dimension of work-group
4850b57cec5SDimitry Andric ///   for wavefront lane.
4860b57cec5SDimitry Andric ///
4870b57cec5SDimitry Andric /// Work-Item Id X (enable_vgpr_workitem_id > 0):
4880b57cec5SDimitry Andric ///   Number of registers: 1. 32 bit work item id in Z dimension of work-group
4890b57cec5SDimitry Andric ///   for wavefront lane.
4900b57cec5SDimitry Andric ///
4910b57cec5SDimitry Andric ///
4920b57cec5SDimitry Andric /// The setting of registers is being done by existing GPU hardware as follows:
4930b57cec5SDimitry Andric ///   1) SGPRs before the Work-Group Ids are set by CP using the 16 User Data
4940b57cec5SDimitry Andric ///      registers.
4950b57cec5SDimitry Andric ///   2) Work-group Id registers X, Y, Z are set by SPI which supports any
4960b57cec5SDimitry Andric ///      combination including none.
4970b57cec5SDimitry Andric ///   3) Scratch Wave Offset is also set by SPI which is why its value cannot
4980b57cec5SDimitry Andric ///      be added into the value Flat Scratch Offset which would avoid the
4990b57cec5SDimitry Andric ///      Finalizer generated prolog having to do the add.
5000b57cec5SDimitry Andric ///   4) The VGPRs are set by SPI which only supports specifying either (X),
5010b57cec5SDimitry Andric ///      (X, Y) or (X, Y, Z).
5020b57cec5SDimitry Andric ///
5030b57cec5SDimitry Andric /// Flat Scratch Dispatch Offset and Flat Scratch Size are adjacent SGRRs so
5040b57cec5SDimitry Andric /// they can be moved as a 64 bit value to the hardware required SGPRn-3 and
5050b57cec5SDimitry Andric /// SGPRn-4 respectively using the Finalizer ?FLAT_SCRATCH? Register.
5060b57cec5SDimitry Andric ///
5070b57cec5SDimitry Andric /// The global segment can be accessed either using flat operations or buffer
5080b57cec5SDimitry Andric /// operations. If buffer operations are used then the Global Buffer used to
5090b57cec5SDimitry Andric /// access HSAIL Global/Readonly/Kernarg (which are combine) segments using a
5100b57cec5SDimitry Andric /// segment address is not passed into the kernel code by CP since its base
5110b57cec5SDimitry Andric /// address is always 0. Instead the Finalizer generates prolog code to
5120b57cec5SDimitry Andric /// initialize 4 SGPRs with a V# that has the following properties, and then
5130b57cec5SDimitry Andric /// uses that in the buffer instructions:
5140b57cec5SDimitry Andric ///   - base address of 0
5150b57cec5SDimitry Andric ///   - no swizzle
5160b57cec5SDimitry Andric ///   - ATC=1
5170b57cec5SDimitry Andric ///   - MTYPE set to support memory coherence specified in
5180b57cec5SDimitry Andric ///     amd_kernel_code_t.globalMemoryCoherence
5190b57cec5SDimitry Andric ///
5200b57cec5SDimitry Andric /// When the Global Buffer is used to access the Kernarg segment, must add the
5210b57cec5SDimitry Andric /// dispatch packet kernArgPtr to a kernarg segment address before using this V#.
5220b57cec5SDimitry Andric /// Alternatively scalar loads can be used if the kernarg offset is uniform, as
5230b57cec5SDimitry Andric /// the kernarg segment is constant for the duration of the kernel execution.
5240b57cec5SDimitry Andric ///
5250b57cec5SDimitry Andric 
526e8d8bef9SDimitry Andric struct amd_kernel_code_t {
5270b57cec5SDimitry Andric   uint32_t amd_kernel_code_version_major;
5280b57cec5SDimitry Andric   uint32_t amd_kernel_code_version_minor;
5290b57cec5SDimitry Andric   uint16_t amd_machine_kind;
5300b57cec5SDimitry Andric   uint16_t amd_machine_version_major;
5310b57cec5SDimitry Andric   uint16_t amd_machine_version_minor;
5320b57cec5SDimitry Andric   uint16_t amd_machine_version_stepping;
5330b57cec5SDimitry Andric 
5340b57cec5SDimitry Andric   /// Byte offset (possibly negative) from start of amd_kernel_code_t
5350b57cec5SDimitry Andric   /// object to kernel's entry point instruction. The actual code for
5360b57cec5SDimitry Andric   /// the kernel is required to be 256 byte aligned to match hardware
5370b57cec5SDimitry Andric   /// requirements (SQ cache line is 16). The code must be position
5380b57cec5SDimitry Andric   /// independent code (PIC) for AMD devices to give runtime the
5390b57cec5SDimitry Andric   /// option of copying code to discrete GPU memory or APU L2
5400b57cec5SDimitry Andric   /// cache. The Finalizer should endeavour to allocate all kernel
5410b57cec5SDimitry Andric   /// machine code in contiguous memory pages so that a device
5420b57cec5SDimitry Andric   /// pre-fetcher will tend to only pre-fetch Kernel Code objects,
5430b57cec5SDimitry Andric   /// improving cache performance.
5440b57cec5SDimitry Andric   int64_t kernel_code_entry_byte_offset;
5450b57cec5SDimitry Andric 
5460b57cec5SDimitry Andric   /// Range of bytes to consider prefetching expressed as an offset
5470b57cec5SDimitry Andric   /// and size. The offset is from the start (possibly negative) of
5480b57cec5SDimitry Andric   /// amd_kernel_code_t object. Set both to 0 if no prefetch
5490b57cec5SDimitry Andric   /// information is available.
5500b57cec5SDimitry Andric   int64_t kernel_code_prefetch_byte_offset;
5510b57cec5SDimitry Andric   uint64_t kernel_code_prefetch_byte_size;
5520b57cec5SDimitry Andric 
5530b57cec5SDimitry Andric   /// Reserved. Must be 0.
5540b57cec5SDimitry Andric   uint64_t reserved0;
5550b57cec5SDimitry Andric 
5560b57cec5SDimitry Andric   /// Shader program settings for CS. Contains COMPUTE_PGM_RSRC1 and
5570b57cec5SDimitry Andric   /// COMPUTE_PGM_RSRC2 registers.
5580b57cec5SDimitry Andric   uint64_t compute_pgm_resource_registers;
5590b57cec5SDimitry Andric 
5600b57cec5SDimitry Andric   /// Code properties. See amd_code_property_mask_t for a full list of
5610b57cec5SDimitry Andric   /// properties.
5620b57cec5SDimitry Andric   uint32_t code_properties;
5630b57cec5SDimitry Andric 
5640b57cec5SDimitry Andric   /// The amount of memory required for the combined private, spill
5650b57cec5SDimitry Andric   /// and arg segments for a work-item in bytes. If
5660b57cec5SDimitry Andric   /// is_dynamic_callstack is 1 then additional space must be added to
5670b57cec5SDimitry Andric   /// this value for the call stack.
5680b57cec5SDimitry Andric   uint32_t workitem_private_segment_byte_size;
5690b57cec5SDimitry Andric 
5700b57cec5SDimitry Andric   /// The amount of group segment memory required by a work-group in
5710b57cec5SDimitry Andric   /// bytes. This does not include any dynamically allocated group
5720b57cec5SDimitry Andric   /// segment memory that may be added when the kernel is
5730b57cec5SDimitry Andric   /// dispatched.
5740b57cec5SDimitry Andric   uint32_t workgroup_group_segment_byte_size;
5750b57cec5SDimitry Andric 
5760b57cec5SDimitry Andric   /// Number of byte of GDS required by kernel dispatch. Must be 0 if
5770b57cec5SDimitry Andric   /// not using GDS.
5780b57cec5SDimitry Andric   uint32_t gds_segment_byte_size;
5790b57cec5SDimitry Andric 
5800b57cec5SDimitry Andric   /// The size in bytes of the kernarg segment that holds the values
5810b57cec5SDimitry Andric   /// of the arguments to the kernel. This could be used by CP to
5820b57cec5SDimitry Andric   /// prefetch the kernarg segment pointed to by the dispatch packet.
5830b57cec5SDimitry Andric   uint64_t kernarg_segment_byte_size;
5840b57cec5SDimitry Andric 
5850b57cec5SDimitry Andric   /// Number of fbarrier's used in the kernel and all functions it
5860b57cec5SDimitry Andric   /// calls. If the implementation uses group memory to allocate the
5870b57cec5SDimitry Andric   /// fbarriers then that amount must already be included in the
5880b57cec5SDimitry Andric   /// workgroup_group_segment_byte_size total.
5890b57cec5SDimitry Andric   uint32_t workgroup_fbarrier_count;
5900b57cec5SDimitry Andric 
5910b57cec5SDimitry Andric   /// Number of scalar registers used by a wavefront. This includes
5920b57cec5SDimitry Andric   /// the special SGPRs for VCC, Flat Scratch Base, Flat Scratch Size
5930b57cec5SDimitry Andric   /// and XNACK (for GFX8 (VI)). It does not include the 16 SGPR added if a
5940b57cec5SDimitry Andric   /// trap handler is enabled. Used to set COMPUTE_PGM_RSRC1.SGPRS.
5950b57cec5SDimitry Andric   uint16_t wavefront_sgpr_count;
5960b57cec5SDimitry Andric 
5970b57cec5SDimitry Andric   /// Number of vector registers used by each work-item. Used to set
5980b57cec5SDimitry Andric   /// COMPUTE_PGM_RSRC1.VGPRS.
5990b57cec5SDimitry Andric   uint16_t workitem_vgpr_count;
6000b57cec5SDimitry Andric 
6010b57cec5SDimitry Andric   /// If reserved_vgpr_count is 0 then must be 0. Otherwise, this is the
6020b57cec5SDimitry Andric   /// first fixed VGPR number reserved.
6030b57cec5SDimitry Andric   uint16_t reserved_vgpr_first;
6040b57cec5SDimitry Andric 
6050b57cec5SDimitry Andric   /// The number of consecutive VGPRs reserved by the client. If
6060b57cec5SDimitry Andric   /// is_debug_supported then this count includes VGPRs reserved
6070b57cec5SDimitry Andric   /// for debugger use.
6080b57cec5SDimitry Andric   uint16_t reserved_vgpr_count;
6090b57cec5SDimitry Andric 
6100b57cec5SDimitry Andric   /// If reserved_sgpr_count is 0 then must be 0. Otherwise, this is the
6110b57cec5SDimitry Andric   /// first fixed SGPR number reserved.
6120b57cec5SDimitry Andric   uint16_t reserved_sgpr_first;
6130b57cec5SDimitry Andric 
6140b57cec5SDimitry Andric   /// The number of consecutive SGPRs reserved by the client. If
6150b57cec5SDimitry Andric   /// is_debug_supported then this count includes SGPRs reserved
6160b57cec5SDimitry Andric   /// for debugger use.
6170b57cec5SDimitry Andric   uint16_t reserved_sgpr_count;
6180b57cec5SDimitry Andric 
6190b57cec5SDimitry Andric   /// If is_debug_supported is 0 then must be 0. Otherwise, this is the
6200b57cec5SDimitry Andric   /// fixed SGPR number used to hold the wave scratch offset for the
6210b57cec5SDimitry Andric   /// entire kernel execution, or uint16_t(-1) if the register is not
6220b57cec5SDimitry Andric   /// used or not known.
6230b57cec5SDimitry Andric   uint16_t debug_wavefront_private_segment_offset_sgpr;
6240b57cec5SDimitry Andric 
6250b57cec5SDimitry Andric   /// If is_debug_supported is 0 then must be 0. Otherwise, this is the
6260b57cec5SDimitry Andric   /// fixed SGPR number of the first of 4 SGPRs used to hold the
6270b57cec5SDimitry Andric   /// scratch V# used for the entire kernel execution, or uint16_t(-1)
6280b57cec5SDimitry Andric   /// if the registers are not used or not known.
6290b57cec5SDimitry Andric   uint16_t debug_private_segment_buffer_sgpr;
6300b57cec5SDimitry Andric 
6310b57cec5SDimitry Andric   /// The maximum byte alignment of variables used by the kernel in
6320b57cec5SDimitry Andric   /// the specified memory segment. Expressed as a power of two. Must
6330b57cec5SDimitry Andric   /// be at least HSA_POWERTWO_16.
6340b57cec5SDimitry Andric   uint8_t kernarg_segment_alignment;
6350b57cec5SDimitry Andric   uint8_t group_segment_alignment;
6360b57cec5SDimitry Andric   uint8_t private_segment_alignment;
6370b57cec5SDimitry Andric 
6380b57cec5SDimitry Andric   /// Wavefront size expressed as a power of two. Must be a power of 2
6390b57cec5SDimitry Andric   /// in range 1..64 inclusive. Used to support runtime query that
6400b57cec5SDimitry Andric   /// obtains wavefront size, which may be used by application to
6410b57cec5SDimitry Andric   /// allocated dynamic group memory and set the dispatch work-group
6420b57cec5SDimitry Andric   /// size.
6430b57cec5SDimitry Andric   uint8_t wavefront_size;
6440b57cec5SDimitry Andric 
6450b57cec5SDimitry Andric   int32_t call_convention;
6460b57cec5SDimitry Andric   uint8_t reserved3[12];
6470b57cec5SDimitry Andric   uint64_t runtime_loader_kernel_symbol;
6480b57cec5SDimitry Andric   uint64_t control_directives[16];
649e8d8bef9SDimitry Andric };
6500b57cec5SDimitry Andric 
6510b57cec5SDimitry Andric #endif // AMDKERNELCODET_H
652