OSDN Git Service

AMDGPU: Make sram-ecc off by default for Vega20
[android-x86/external-llvm.git] / docs / AMDGPUUsage.rst
1 =============================
2 User Guide for AMDGPU Backend
3 =============================
4
5 .. contents::
6    :local:
7
8 Introduction
9 ============
10
11 The AMDGPU backend provides ISA code generation for AMD GPUs, starting with the
12 R600 family up until the current GCN families. It lives in the
13 ``lib/Target/AMDGPU`` directory.
14
15 LLVM
16 ====
17
18 .. _amdgpu-target-triples:
19
20 Target Triples
21 --------------
22
23 Use the ``clang -target <Architecture>-<Vendor>-<OS>-<Environment>`` option to
24 specify the target triple:
25
26   .. table:: AMDGPU Architectures
27      :name: amdgpu-architecture-table
28
29      ============ ==============================================================
30      Architecture Description
31      ============ ==============================================================
32      ``r600``     AMD GPUs HD2XXX-HD6XXX for graphics and compute shaders.
33      ``amdgcn``   AMD GPUs GCN GFX6 onwards for graphics and compute shaders.
34      ============ ==============================================================
35
36   .. table:: AMDGPU Vendors
37      :name: amdgpu-vendor-table
38
39      ============ ==============================================================
40      Vendor       Description
41      ============ ==============================================================
42      ``amd``      Can be used for all AMD GPU usage.
43      ``mesa3d``   Can be used if the OS is ``mesa3d``.
44      ============ ==============================================================
45
46   .. table:: AMDGPU Operating Systems
47      :name: amdgpu-os-table
48
49      ============== ============================================================
50      OS             Description
51      ============== ============================================================
52      *<empty>*      Defaults to the *unknown* OS.
53      ``amdhsa``     Compute kernels executed on HSA [HSA]_ compatible runtimes
54                     such as AMD's ROCm [AMD-ROCm]_.
55      ``amdpal``     Graphic shaders and compute kernels executed on AMD PAL
56                     runtime.
57      ``mesa3d``     Graphic shaders and compute kernels executed on Mesa 3D
58                     runtime.
59      ============== ============================================================
60
61   .. table:: AMDGPU Environments
62      :name: amdgpu-environment-table
63
64      ============ ==============================================================
65      Environment  Description
66      ============ ==============================================================
67      *<empty>*    Default.
68      ============ ==============================================================
69
70 .. _amdgpu-processors:
71
72 Processors
73 ----------
74
75 Use the ``clang -mcpu <Processor>`` option to specify the AMD GPU processor. The
76 names from both the *Processor* and *Alternative Processor* can be used.
77
78   .. table:: AMDGPU Processors
79      :name: amdgpu-processor-table
80
81      =========== =============== ============ ===== ========== ======= ======================
82      Processor   Alternative     Target       dGPU/ Target     ROCm    Example
83                  Processor       Triple       APU   Features   Support Products
84                                  Architecture       Supported
85                                                     [Default]
86      =========== =============== ============ ===== ========== ======= ======================
87      **Radeon HD 2000/3000 Series (R600)** [AMD-RADEON-HD-2000-3000]_
88      ----------------------------------------------------------------------------------------
89      ``r600``                    ``r600``     dGPU
90      ``r630``                    ``r600``     dGPU
91      ``rs880``                   ``r600``     dGPU
92      ``rv670``                   ``r600``     dGPU
93      **Radeon HD 4000 Series (R700)** [AMD-RADEON-HD-4000]_
94      ----------------------------------------------------------------------------------------
95      ``rv710``                   ``r600``     dGPU
96      ``rv730``                   ``r600``     dGPU
97      ``rv770``                   ``r600``     dGPU
98      **Radeon HD 5000 Series (Evergreen)** [AMD-RADEON-HD-5000]_
99      ----------------------------------------------------------------------------------------
100      ``cedar``                   ``r600``     dGPU
101      ``cypress``                 ``r600``     dGPU
102      ``juniper``                 ``r600``     dGPU
103      ``redwood``                 ``r600``     dGPU
104      ``sumo``                    ``r600``     dGPU
105      **Radeon HD 6000 Series (Northern Islands)** [AMD-RADEON-HD-6000]_
106      ----------------------------------------------------------------------------------------
107      ``barts``                   ``r600``     dGPU
108      ``caicos``                  ``r600``     dGPU
109      ``cayman``                  ``r600``     dGPU
110      ``turks``                   ``r600``     dGPU
111      **GCN GFX6 (Southern Islands (SI))** [AMD-GCN-GFX6]_
112      ----------------------------------------------------------------------------------------
113      ``gfx600``  - ``tahiti``    ``amdgcn``   dGPU
114      ``gfx601``  - ``hainan``    ``amdgcn``   dGPU
115                  - ``oland``
116                  - ``pitcairn``
117                  - ``verde``
118      **GCN GFX7 (Sea Islands (CI))** [AMD-GCN-GFX7]_
119      ----------------------------------------------------------------------------------------
120      ``gfx700``  - ``kaveri``    ``amdgcn``   APU                      - A6-7000
121                                                                        - A6 Pro-7050B
122                                                                        - A8-7100
123                                                                        - A8 Pro-7150B
124                                                                        - A10-7300
125                                                                        - A10 Pro-7350B
126                                                                        - FX-7500
127                                                                        - A8-7200P
128                                                                        - A10-7400P
129                                                                        - FX-7600P
130      ``gfx701``  - ``hawaii``    ``amdgcn``   dGPU             ROCm    - FirePro W8100
131                                                                        - FirePro W9100
132                                                                        - FirePro S9150
133                                                                        - FirePro S9170
134      ``gfx702``                  ``amdgcn``   dGPU             ROCm    - Radeon R9 290
135                                                                        - Radeon R9 290x
136                                                                        - Radeon R390
137                                                                        - Radeon R390x
138      ``gfx703``  - ``kabini``    ``amdgcn``   APU                      - E1-2100
139                  - ``mullins``                                         - E1-2200
140                                                                        - E1-2500
141                                                                        - E2-3000
142                                                                        - E2-3800
143                                                                        - A4-5000
144                                                                        - A4-5100
145                                                                        - A6-5200
146                                                                        - A4 Pro-3340B
147      ``gfx704``  - ``bonaire``   ``amdgcn``   dGPU                     - Radeon HD 7790
148                                                                        - Radeon HD 8770
149                                                                        - R7 260
150                                                                        - R7 260X
151      **GCN GFX8 (Volcanic Islands (VI))** [AMD-GCN-GFX8]_
152      ----------------------------------------------------------------------------------------
153      ``gfx801``  - ``carrizo``   ``amdgcn``   APU   - xnack            - A6-8500P
154                                                       [on]             - Pro A6-8500B
155                                                                        - A8-8600P
156                                                                        - Pro A8-8600B
157                                                                        - FX-8800P
158                                                                        - Pro A12-8800B
159      \                           ``amdgcn``   APU   - xnack    ROCm    - A10-8700P
160                                                       [on]             - Pro A10-8700B
161                                                                        - A10-8780P
162      \                           ``amdgcn``   APU   - xnack            - A10-9600P
163                                                       [on]             - A10-9630P
164                                                                        - A12-9700P
165                                                                        - A12-9730P
166                                                                        - FX-9800P
167                                                                        - FX-9830P
168      \                           ``amdgcn``   APU   - xnack            - E2-9010
169                                                       [on]             - A6-9210
170                                                                        - A9-9410
171      ``gfx802``  - ``iceland``   ``amdgcn``   dGPU  - xnack    ROCm    - FirePro S7150
172                  - ``tonga``                          [off]            - FirePro S7100
173                                                                        - FirePro W7100
174                                                                        - Radeon R285
175                                                                        - Radeon R9 380
176                                                                        - Radeon R9 385
177                                                                        - Mobile FirePro
178                                                                          M7170
179      ``gfx803``  - ``fiji``      ``amdgcn``   dGPU  - xnack    ROCm    - Radeon R9 Nano
180                                                       [off]            - Radeon R9 Fury
181                                                                        - Radeon R9 FuryX
182                                                                        - Radeon Pro Duo
183                                                                        - FirePro S9300x2
184                                                                        - Radeon Instinct MI8
185      \           - ``polaris10`` ``amdgcn``   dGPU  - xnack    ROCm    - Radeon RX 470
186                                                       [off]            - Radeon RX 480
187                                                                        - Radeon Instinct MI6
188      \           - ``polaris11`` ``amdgcn``   dGPU  - xnack    ROCm    - Radeon RX 460
189                                                       [off]
190      ``gfx810``  - ``stoney``    ``amdgcn``   APU   - xnack
191                                                       [on]
192      **GCN GFX9** [AMD-GCN-GFX9]_
193      ----------------------------------------------------------------------------------------
194      ``gfx900``                  ``amdgcn``   dGPU  - xnack    ROCm    - Radeon Vega
195                                                       [off]              Frontier Edition
196                                                                        - Radeon RX Vega 56
197                                                                        - Radeon RX Vega 64
198                                                                        - Radeon RX Vega 64
199                                                                          Liquid
200                                                                        - Radeon Instinct MI25
201      ``gfx902``                  ``amdgcn``   APU   - xnack            - Ryzen 3 2200G
202                                                       [on]             - Ryzen 5 2400G
203      ``gfx904``                  ``amdgcn``   dGPU  - xnack            *TBA*
204                                                       [off]
205                                                                        .. TODO
206                                                                           Add product
207                                                                           names.
208      ``gfx906``                  ``amdgcn``   dGPU  - xnack            - Radeon Instinct MI50
209                                                       [off]            - Radeon Instinct MI60
210      ``gfx909``                  ``amdgcn``   APU   - xnack            *TBA* (Raven Ridge 2)
211                                                       [on]
212                                                                        .. TODO
213                                                                           Add product
214                                                                           names.
215      =========== =============== ============ ===== ========== ======= ======================
216
217 .. _amdgpu-target-features:
218
219 Target Features
220 ---------------
221
222 Target features control how code is generated to support certain
223 processor specific features. Not all target features are supported by
224 all processors. The runtime must ensure that the features supported by
225 the device used to execute the code match the features enabled when
226 generating the code. A mismatch of features may result in incorrect
227 execution, or a reduction in performance.
228
229 The target features supported by each processor, and the default value
230 used if not specified explicitly, is listed in
231 :ref:`amdgpu-processor-table`.
232
233 Use the ``clang -m[no-]<TargetFeature>`` option to specify the AMD GPU
234 target features.
235
236 For example:
237
238 ``-mxnack``
239   Enable the ``xnack`` feature.
240 ``-mno-xnack``
241   Disable the ``xnack`` feature.
242
243   .. table:: AMDGPU Target Features
244      :name: amdgpu-target-feature-table
245
246      =============== ==================================================
247      Target Feature  Description
248      =============== ==================================================
249      -m[no-]xnack    Enable/disable generating code that has
250                      memory clauses that are compatible with
251                      having XNACK replay enabled.
252
253                      This is used for demand paging and page
254                      migration. If XNACK replay is enabled in
255                      the device, then if a page fault occurs
256                      the code may execute incorrectly if the
257                      ``xnack`` feature is not enabled. Executing
258                      code that has the feature enabled on a
259                      device that does not have XNACK replay
260                      enabled will execute correctly, but may
261                      be less performant than code with the
262                      feature disabled.
263      -m[no-]sram-ecc Enable/disable generating code that assumes SRAM
264                      ECC is enabled/disabled.
265      =============== ==================================================
266
267 .. _amdgpu-address-spaces:
268
269 Address Spaces
270 --------------
271
272 The AMDGPU backend uses the following address space mappings.
273
274 The memory space names used in the table, aside from the region memory space, is
275 from the OpenCL standard.
276
277 LLVM Address Space number is used throughout LLVM (for example, in LLVM IR).
278
279   .. table:: Address Space Mapping
280      :name: amdgpu-address-space-mapping-table
281
282      ================== =================================
283      LLVM Address Space Memory Space
284      ================== =================================
285      0                  Generic (Flat)
286      1                  Global
287      2                  Region (GDS)
288      3                  Local (group/LDS)
289      4                  Constant
290      5                  Private (Scratch)
291      6                  Constant 32-bit
292      7                  Buffer Fat Pointer (experimental)
293      ================== =================================
294
295 The buffer fat pointer is an experimental address space that is currently
296 unsupported in the backend. It exposes a non-integral pointer that is in future
297 intended to support the modelling of 128-bit buffer descriptors + a 32-bit
298 offset into the buffer descriptor (in total encapsulating a 160-bit 'pointer'),
299 allowing us to use normal LLVM load/store/atomic operations to model the buffer
300 descriptors used heavily in graphics workloads targeting the backend.
301
302 .. _amdgpu-memory-scopes:
303
304 Memory Scopes
305 -------------
306
307 This section provides LLVM memory synchronization scopes supported by the AMDGPU
308 backend memory model when the target triple OS is ``amdhsa`` (see
309 :ref:`amdgpu-amdhsa-memory-model` and :ref:`amdgpu-target-triples`).
310
311 The memory model supported is based on the HSA memory model [HSA]_ which is
312 based in turn on HRF-indirect with scope inclusion [HRF]_. The happens-before
313 relation is transitive over the synchonizes-with relation independent of scope,
314 and synchonizes-with allows the memory scope instances to be inclusive (see
315 table :ref:`amdgpu-amdhsa-llvm-sync-scopes-table`).
316
317 This is different to the OpenCL [OpenCL]_ memory model which does not have scope
318 inclusion and requires the memory scopes to exactly match. However, this
319 is conservatively correct for OpenCL.
320
321   .. table:: AMDHSA LLVM Sync Scopes
322      :name: amdgpu-amdhsa-llvm-sync-scopes-table
323
324      ======================= ===================================================
325      LLVM Sync Scope         Description
326      ======================= ===================================================
327      *none*                  The default: ``system``.
328
329                              Synchronizes with, and participates in modification
330                              and seq_cst total orderings with, other operations
331                              (except image operations) for all address spaces
332                              (except private, or generic that accesses private)
333                              provided the other operation's sync scope is:
334
335                              - ``system``.
336                              - ``agent`` and executed by a thread on the same
337                                agent.
338                              - ``workgroup`` and executed by a thread in the
339                                same workgroup.
340                              - ``wavefront`` and executed by a thread in the
341                                same wavefront.
342
343      ``agent``               Synchronizes with, and participates in modification
344                              and seq_cst total orderings with, other operations
345                              (except image operations) for all address spaces
346                              (except private, or generic that accesses private)
347                              provided the other operation's sync scope is:
348
349                              - ``system`` or ``agent`` and executed by a thread
350                                on the same agent.
351                              - ``workgroup`` and executed by a thread in the
352                                same workgroup.
353                              - ``wavefront`` and executed by a thread in the
354                                same wavefront.
355
356      ``workgroup``           Synchronizes with, and participates in modification
357                              and seq_cst total orderings with, other operations
358                              (except image operations) for all address spaces
359                              (except private, or generic that accesses private)
360                              provided the other operation's sync scope is:
361
362                              - ``system``, ``agent`` or ``workgroup`` and
363                                executed by a thread in the same workgroup.
364                              - ``wavefront`` and executed by a thread in the
365                                same wavefront.
366
367      ``wavefront``           Synchronizes with, and participates in modification
368                              and seq_cst total orderings with, other operations
369                              (except image operations) for all address spaces
370                              (except private, or generic that accesses private)
371                              provided the other operation's sync scope is:
372
373                              - ``system``, ``agent``, ``workgroup`` or
374                                ``wavefront`` and executed by a thread in the
375                                same wavefront.
376
377      ``singlethread``        Only synchronizes with, and participates in
378                              modification and seq_cst total orderings with,
379                              other operations (except image operations) running
380                              in the same thread for all address spaces (for
381                              example, in signal handlers).
382
383      ``one-as``              Same as ``system`` but only synchronizes with other
384                              operations within the same address space.
385
386      ``agent-one-as``        Same as ``agent`` but only synchronizes with other
387                              operations within the same address space.
388
389      ``workgroup-one-as``    Same as ``workgroup`` but only synchronizes with
390                              other operations within the same address space.
391
392      ``wavefront-one-as``    Same as ``wavefront`` but only synchronizes with
393                              other operations within the same address space.
394
395      ``singlethread-one-as`` Same as ``singlethread`` but only synchronizes with
396                              other operations within the same address space.
397      ======================= ===================================================
398
399 AMDGPU Intrinsics
400 -----------------
401
402 The AMDGPU backend implements the following LLVM IR intrinsics.
403
404 *This section is WIP.*
405
406 .. TODO
407    List AMDGPU intrinsics
408
409 AMDGPU Attributes
410 -----------------
411
412 The AMDGPU backend supports the following LLVM IR attributes.
413
414   .. table:: AMDGPU LLVM IR Attributes
415      :name: amdgpu-llvm-ir-attributes-table
416
417      ======================================= ==========================================================
418      LLVM Attribute                          Description
419      ======================================= ==========================================================
420      "amdgpu-flat-work-group-size"="min,max" Specify the minimum and maximum flat work group sizes that
421                                              will be specified when the kernel is dispatched. Generated
422                                              by the ``amdgpu_flat_work_group_size`` CLANG attribute [CLANG-ATTR]_.
423      "amdgpu-implicitarg-num-bytes"="n"      Number of kernel argument bytes to add to the kernel
424                                              argument block size for the implicit arguments. This
425                                              varies by OS and language (for OpenCL see
426                                              :ref:`opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table`).
427      "amdgpu-max-work-group-size"="n"        Specify the maximum work-group size that will be specifed
428                                              when the kernel is dispatched.
429      "amdgpu-num-sgpr"="n"                   Specifies the number of SGPRs to use. Generated by
430                                              the ``amdgpu_num_sgpr`` CLANG attribute [CLANG-ATTR]_.
431      "amdgpu-num-vgpr"="n"                   Specifies the number of VGPRs to use. Generated by the
432                                              ``amdgpu_num_vgpr`` CLANG attribute [CLANG-ATTR]_.
433      "amdgpu-waves-per-eu"="m,n"             Specify the minimum and maximum number of waves per
434                                              execution unit. Generated by the ``amdgpu_waves_per_eu``
435                                              CLANG attribute [CLANG-ATTR]_.
436      ======================================= ==========================================================
437
438 Code Object
439 ===========
440
441 The AMDGPU backend generates a standard ELF [ELF]_ relocatable code object that
442 can be linked by ``lld`` to produce a standard ELF shared code object which can
443 be loaded and executed on an AMDGPU target.
444
445 Header
446 ------
447
448 The AMDGPU backend uses the following ELF header:
449
450   .. table:: AMDGPU ELF Header
451      :name: amdgpu-elf-header-table
452
453      ========================== ===============================
454      Field                      Value
455      ========================== ===============================
456      ``e_ident[EI_CLASS]``      ``ELFCLASS64``
457      ``e_ident[EI_DATA]``       ``ELFDATA2LSB``
458      ``e_ident[EI_OSABI]``      - ``ELFOSABI_NONE``
459                                 - ``ELFOSABI_AMDGPU_HSA``
460                                 - ``ELFOSABI_AMDGPU_PAL``
461                                 - ``ELFOSABI_AMDGPU_MESA3D``
462      ``e_ident[EI_ABIVERSION]`` - ``ELFABIVERSION_AMDGPU_HSA``
463                                 - ``ELFABIVERSION_AMDGPU_PAL``
464                                 - ``ELFABIVERSION_AMDGPU_MESA3D``
465      ``e_type``                 - ``ET_REL``
466                                 - ``ET_DYN``
467      ``e_machine``              ``EM_AMDGPU``
468      ``e_entry``                0
469      ``e_flags``                See :ref:`amdgpu-elf-header-e_flags-table`
470      ========================== ===============================
471
472 ..
473
474   .. table:: AMDGPU ELF Header Enumeration Values
475      :name: amdgpu-elf-header-enumeration-values-table
476
477      =============================== =====
478      Name                            Value
479      =============================== =====
480      ``EM_AMDGPU``                   224
481      ``ELFOSABI_NONE``               0
482      ``ELFOSABI_AMDGPU_HSA``         64
483      ``ELFOSABI_AMDGPU_PAL``         65
484      ``ELFOSABI_AMDGPU_MESA3D``      66
485      ``ELFABIVERSION_AMDGPU_HSA``    1
486      ``ELFABIVERSION_AMDGPU_PAL``    0
487      ``ELFABIVERSION_AMDGPU_MESA3D`` 0
488      =============================== =====
489
490 ``e_ident[EI_CLASS]``
491   The ELF class is:
492
493   * ``ELFCLASS32`` for ``r600`` architecture.
494
495   * ``ELFCLASS64`` for ``amdgcn`` architecture which only supports 64
496     bit applications.
497
498 ``e_ident[EI_DATA]``
499   All AMDGPU targets use ``ELFDATA2LSB`` for little-endian byte ordering.
500
501 ``e_ident[EI_OSABI]``
502   One of the following AMD GPU architecture specific OS ABIs
503   (see :ref:`amdgpu-os-table`):
504
505   * ``ELFOSABI_NONE`` for *unknown* OS.
506
507   * ``ELFOSABI_AMDGPU_HSA`` for ``amdhsa`` OS.
508
509   * ``ELFOSABI_AMDGPU_PAL`` for ``amdpal`` OS.
510
511   * ``ELFOSABI_AMDGPU_MESA3D`` for ``mesa3D`` OS.
512
513 ``e_ident[EI_ABIVERSION]``
514   The ABI version of the AMD GPU architecture specific OS ABI to which the code
515   object conforms:
516
517   * ``ELFABIVERSION_AMDGPU_HSA`` is used to specify the version of AMD HSA
518     runtime ABI.
519
520   * ``ELFABIVERSION_AMDGPU_PAL`` is used to specify the version of AMD PAL
521     runtime ABI.
522
523   * ``ELFABIVERSION_AMDGPU_MESA3D`` is used to specify the version of AMD MESA
524     3D runtime ABI.
525
526 ``e_type``
527   Can be one of the following values:
528
529
530   ``ET_REL``
531     The type produced by the AMD GPU backend compiler as it is relocatable code
532     object.
533
534   ``ET_DYN``
535     The type produced by the linker as it is a shared code object.
536
537   The AMD HSA runtime loader requires a ``ET_DYN`` code object.
538
539 ``e_machine``
540   The value ``EM_AMDGPU`` is used for the machine for all processors supported
541   by the ``r600`` and ``amdgcn`` architectures (see
542   :ref:`amdgpu-processor-table`). The specific processor is specified in the
543   ``EF_AMDGPU_MACH`` bit field of the ``e_flags`` (see
544   :ref:`amdgpu-elf-header-e_flags-table`).
545
546 ``e_entry``
547   The entry point is 0 as the entry points for individual kernels must be
548   selected in order to invoke them through AQL packets.
549
550 ``e_flags``
551   The AMDGPU backend uses the following ELF header flags:
552
553   .. table:: AMDGPU ELF Header ``e_flags``
554      :name: amdgpu-elf-header-e_flags-table
555
556      ================================= ========== =============================
557      Name                              Value      Description
558      ================================= ========== =============================
559      **AMDGPU Processor Flag**                    See :ref:`amdgpu-processor-table`.
560      -------------------------------------------- -----------------------------
561      ``EF_AMDGPU_MACH``                0x000000ff AMDGPU processor selection
562                                                   mask for
563                                                   ``EF_AMDGPU_MACH_xxx`` values
564                                                   defined in
565                                                   :ref:`amdgpu-ef-amdgpu-mach-table`.
566      ``EF_AMDGPU_XNACK``               0x00000100 Indicates if the ``xnack``
567                                                   target feature is
568                                                   enabled for all code
569                                                   contained in the code object.
570                                                   If the processor
571                                                   does not support the
572                                                   ``xnack`` target
573                                                   feature then must
574                                                   be 0.
575                                                   See
576                                                   :ref:`amdgpu-target-features`.
577      ``EF_AMDGPU_SRAM_ECC``            0x00000200 Indicates if the ``sram-ecc``
578                                                   target feature is
579                                                   enabled for all code
580                                                   contained in the code object.
581                                                   If the processor
582                                                   does not support the
583                                                   ``sram-ecc`` target
584                                                   feature then must
585                                                   be 0.
586                                                   See
587                                                   :ref:`amdgpu-target-features`.
588      ================================= ========== =============================
589
590   .. table:: AMDGPU ``EF_AMDGPU_MACH`` Values
591      :name: amdgpu-ef-amdgpu-mach-table
592
593      ================================= ========== =============================
594      Name                              Value      Description (see
595                                                   :ref:`amdgpu-processor-table`)
596      ================================= ========== =============================
597      ``EF_AMDGPU_MACH_NONE``           0x000      *not specified*
598      ``EF_AMDGPU_MACH_R600_R600``      0x001      ``r600``
599      ``EF_AMDGPU_MACH_R600_R630``      0x002      ``r630``
600      ``EF_AMDGPU_MACH_R600_RS880``     0x003      ``rs880``
601      ``EF_AMDGPU_MACH_R600_RV670``     0x004      ``rv670``
602      ``EF_AMDGPU_MACH_R600_RV710``     0x005      ``rv710``
603      ``EF_AMDGPU_MACH_R600_RV730``     0x006      ``rv730``
604      ``EF_AMDGPU_MACH_R600_RV770``     0x007      ``rv770``
605      ``EF_AMDGPU_MACH_R600_CEDAR``     0x008      ``cedar``
606      ``EF_AMDGPU_MACH_R600_CYPRESS``   0x009      ``cypress``
607      ``EF_AMDGPU_MACH_R600_JUNIPER``   0x00a      ``juniper``
608      ``EF_AMDGPU_MACH_R600_REDWOOD``   0x00b      ``redwood``
609      ``EF_AMDGPU_MACH_R600_SUMO``      0x00c      ``sumo``
610      ``EF_AMDGPU_MACH_R600_BARTS``     0x00d      ``barts``
611      ``EF_AMDGPU_MACH_R600_CAICOS``    0x00e      ``caicos``
612      ``EF_AMDGPU_MACH_R600_CAYMAN``    0x00f      ``cayman``
613      ``EF_AMDGPU_MACH_R600_TURKS``     0x010      ``turks``
614      *reserved*                        0x011 -    Reserved for ``r600``
615                                        0x01f      architecture processors.
616      ``EF_AMDGPU_MACH_AMDGCN_GFX600``  0x020      ``gfx600``
617      ``EF_AMDGPU_MACH_AMDGCN_GFX601``  0x021      ``gfx601``
618      ``EF_AMDGPU_MACH_AMDGCN_GFX700``  0x022      ``gfx700``
619      ``EF_AMDGPU_MACH_AMDGCN_GFX701``  0x023      ``gfx701``
620      ``EF_AMDGPU_MACH_AMDGCN_GFX702``  0x024      ``gfx702``
621      ``EF_AMDGPU_MACH_AMDGCN_GFX703``  0x025      ``gfx703``
622      ``EF_AMDGPU_MACH_AMDGCN_GFX704``  0x026      ``gfx704``
623      *reserved*                        0x027      Reserved.
624      ``EF_AMDGPU_MACH_AMDGCN_GFX801``  0x028      ``gfx801``
625      ``EF_AMDGPU_MACH_AMDGCN_GFX802``  0x029      ``gfx802``
626      ``EF_AMDGPU_MACH_AMDGCN_GFX803``  0x02a      ``gfx803``
627      ``EF_AMDGPU_MACH_AMDGCN_GFX810``  0x02b      ``gfx810``
628      ``EF_AMDGPU_MACH_AMDGCN_GFX900``  0x02c      ``gfx900``
629      ``EF_AMDGPU_MACH_AMDGCN_GFX902``  0x02d      ``gfx902``
630      ``EF_AMDGPU_MACH_AMDGCN_GFX904``  0x02e      ``gfx904``
631      ``EF_AMDGPU_MACH_AMDGCN_GFX906``  0x02f      ``gfx906``
632      *reserved*                        0x030      Reserved.
633      ``EF_AMDGPU_MACH_AMDGCN_GFX909``  0x031      ``gfx909``
634      ================================= ========== =============================
635
636 Sections
637 --------
638
639 An AMDGPU target ELF code object has the standard ELF sections which include:
640
641   .. table:: AMDGPU ELF Sections
642      :name: amdgpu-elf-sections-table
643
644      ================== ================ =================================
645      Name               Type             Attributes
646      ================== ================ =================================
647      ``.bss``           ``SHT_NOBITS``   ``SHF_ALLOC`` + ``SHF_WRITE``
648      ``.data``          ``SHT_PROGBITS`` ``SHF_ALLOC`` + ``SHF_WRITE``
649      ``.debug_``\ *\**  ``SHT_PROGBITS`` *none*
650      ``.dynamic``       ``SHT_DYNAMIC``  ``SHF_ALLOC``
651      ``.dynstr``        ``SHT_PROGBITS`` ``SHF_ALLOC``
652      ``.dynsym``        ``SHT_PROGBITS`` ``SHF_ALLOC``
653      ``.got``           ``SHT_PROGBITS`` ``SHF_ALLOC`` + ``SHF_WRITE``
654      ``.hash``          ``SHT_HASH``     ``SHF_ALLOC``
655      ``.note``          ``SHT_NOTE``     *none*
656      ``.rela``\ *name*  ``SHT_RELA``     *none*
657      ``.rela.dyn``      ``SHT_RELA``     *none*
658      ``.rodata``        ``SHT_PROGBITS`` ``SHF_ALLOC``
659      ``.shstrtab``      ``SHT_STRTAB``   *none*
660      ``.strtab``        ``SHT_STRTAB``   *none*
661      ``.symtab``        ``SHT_SYMTAB``   *none*
662      ``.text``          ``SHT_PROGBITS`` ``SHF_ALLOC`` + ``SHF_EXECINSTR``
663      ================== ================ =================================
664
665 These sections have their standard meanings (see [ELF]_) and are only generated
666 if needed.
667
668 ``.debug``\ *\**
669   The standard DWARF sections. See :ref:`amdgpu-dwarf` for information on the
670   DWARF produced by the AMDGPU backend.
671
672 ``.dynamic``, ``.dynstr``, ``.dynsym``, ``.hash``
673   The standard sections used by a dynamic loader.
674
675 ``.note``
676   See :ref:`amdgpu-note-records` for the note records supported by the AMDGPU
677   backend.
678
679 ``.rela``\ *name*, ``.rela.dyn``
680   For relocatable code objects, *name* is the name of the section that the
681   relocation records apply. For example, ``.rela.text`` is the section name for
682   relocation records associated with the ``.text`` section.
683
684   For linked shared code objects, ``.rela.dyn`` contains all the relocation
685   records from each of the relocatable code object's ``.rela``\ *name* sections.
686
687   See :ref:`amdgpu-relocation-records` for the relocation records supported by
688   the AMDGPU backend.
689
690 ``.text``
691   The executable machine code for the kernels and functions they call. Generated
692   as position independent code. See :ref:`amdgpu-code-conventions` for
693   information on conventions used in the isa generation.
694
695 .. _amdgpu-note-records:
696
697 Note Records
698 ------------
699
700 The AMDGPU backend code object contains ELF note records in the ``.note``
701 section. The set of generated notes and their semantics depend on the code
702 object version; see :ref:`amdgpu-note-records-v2` and
703 :ref:`amdgpu-note-records-v3`.
704
705 As required by ``ELFCLASS32`` and ``ELFCLASS64``, minimal zero byte padding
706 must be generated after the ``name`` field to ensure the ``desc`` field is 4
707 byte aligned. In addition, minimal zero byte padding must be generated to
708 ensure the ``desc`` field size is a multiple of 4 bytes. The ``sh_addralign``
709 field of the ``.note`` section must be at least 4 to indicate at least 8 byte
710 alignment.
711
712 .. _amdgpu-note-records-v2:
713
714 Code Object V2 Note Records (-mattr=-code-object-v3)
715 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
716
717 .. warning:: Code Object V2 is not the default code object version emitted by
718   this version of LLVM. For a description of the notes generated with the
719   default configuration (Code Object V3) see :ref:`amdgpu-note-records-v3`.
720
721 The AMDGPU backend code object uses the following ELF note record in the
722 ``.note`` section when compiling for Code Object V2 (-mattr=-code-object-v3).
723
724 Additional note records may be present, but any which are not documented here
725 are deprecated and should not be used.
726
727   .. table:: AMDGPU Code Object V2 ELF Note Records
728      :name: amdgpu-elf-note-records-table-v2
729
730      ===== ============================== ======================================
731      Name  Type                           Description
732      ===== ============================== ======================================
733      "AMD" ``NT_AMD_AMDGPU_HSA_METADATA`` <metadata null terminated string>
734      ===== ============================== ======================================
735
736 ..
737
738   .. table:: AMDGPU Code Object V2 ELF Note Record Enumeration Values
739      :name: amdgpu-elf-note-record-enumeration-values-table-v2
740
741      ============================== =====
742      Name                           Value
743      ============================== =====
744      *reserved*                       0-9
745      ``NT_AMD_AMDGPU_HSA_METADATA``    10
746      *reserved*                        11
747      ============================== =====
748
749 ``NT_AMD_AMDGPU_HSA_METADATA``
750   Specifies extensible metadata associated with the code objects executed on HSA
751   [HSA]_ compatible runtimes such as AMD's ROCm [AMD-ROCm]_. It is required when
752   the target triple OS is ``amdhsa`` (see :ref:`amdgpu-target-triples`). See
753   :ref:`amdgpu-amdhsa-code-object-metadata-v2` for the syntax of the code
754   object metadata string.
755
756 .. _amdgpu-note-records-v3:
757
758 Code Object V3 Note Records (-mattr=+code-object-v3)
759 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
760
761 The AMDGPU backend code object uses the following ELF note record in the
762 ``.note`` section when compiling for Code Object V3 (-mattr=+code-object-v3).
763
764 Additional note records may be present, but any which are not documented here
765 are deprecated and should not be used.
766
767   .. table:: AMDGPU Code Object V3 ELF Note Records
768      :name: amdgpu-elf-note-records-table-v3
769
770      ======== ============================== ======================================
771      Name     Type                           Description
772      ======== ============================== ======================================
773      "AMDGPU" ``NT_AMDGPU_METADATA``         Metadata in Message Pack [MsgPack]_
774                                              binary format.
775      ======== ============================== ======================================
776
777 ..
778
779   .. table:: AMDGPU Code Object V3 ELF Note Record Enumeration Values
780      :name: amdgpu-elf-note-record-enumeration-values-table-v3
781
782      ============================== =====
783      Name                           Value
784      ============================== =====
785      *reserved*                     0-31
786      ``NT_AMDGPU_METADATA``         32
787      ============================== =====
788
789 ``NT_AMDGPU_METADATA``
790   Specifies extensible metadata associated with an AMDGPU code
791   object. It is encoded as a map in the Message Pack [MsgPack]_ binary
792   data format. See :ref:`amdgpu-amdhsa-code-object-metadata-v3` for the
793   map keys defined for the ``amdhsa`` OS.
794
795 .. _amdgpu-symbols:
796
797 Symbols
798 -------
799
800 Symbols include the following:
801
802   .. table:: AMDGPU ELF Symbols
803      :name: amdgpu-elf-symbols-table
804
805      ===================== ============== ============= ==================
806      Name                  Type           Section       Description
807      ===================== ============== ============= ==================
808      *link-name*           ``STT_OBJECT`` - ``.data``   Global variable
809                                           - ``.rodata``
810                                           - ``.bss``
811      *link-name*\ ``.kd``  ``STT_OBJECT`` - ``.rodata`` Kernel descriptor
812      *link-name*           ``STT_FUNC``   - ``.text``   Kernel entry point
813      ===================== ============== ============= ==================
814
815 Global variable
816   Global variables both used and defined by the compilation unit.
817
818   If the symbol is defined in the compilation unit then it is allocated in the
819   appropriate section according to if it has initialized data or is readonly.
820
821   If the symbol is external then its section is ``STN_UNDEF`` and the loader
822   will resolve relocations using the definition provided by another code object
823   or explicitly defined by the runtime.
824
825   All global symbols, whether defined in the compilation unit or external, are
826   accessed by the machine code indirectly through a GOT table entry. This
827   allows them to be preemptable. The GOT table is only supported when the target
828   triple OS is ``amdhsa`` (see :ref:`amdgpu-target-triples`).
829
830   .. TODO
831      Add description of linked shared object symbols. Seems undefined symbols
832      are marked as STT_NOTYPE.
833
834 Kernel descriptor
835   Every HSA kernel has an associated kernel descriptor. It is the address of the
836   kernel descriptor that is used in the AQL dispatch packet used to invoke the
837   kernel, not the kernel entry point. The layout of the HSA kernel descriptor is
838   defined in :ref:`amdgpu-amdhsa-kernel-descriptor`.
839
840 Kernel entry point
841   Every HSA kernel also has a symbol for its machine code entry point.
842
843 .. _amdgpu-relocation-records:
844
845 Relocation Records
846 ------------------
847
848 AMDGPU backend generates ``Elf64_Rela`` relocation records. Supported
849 relocatable fields are:
850
851 ``word32``
852   This specifies a 32-bit field occupying 4 bytes with arbitrary byte
853   alignment. These values use the same byte order as other word values in the
854   AMD GPU architecture.
855
856 ``word64``
857   This specifies a 64-bit field occupying 8 bytes with arbitrary byte
858   alignment. These values use the same byte order as other word values in the
859   AMD GPU architecture.
860
861 Following notations are used for specifying relocation calculations:
862
863 **A**
864   Represents the addend used to compute the value of the relocatable field.
865
866 **G**
867   Represents the offset into the global offset table at which the relocation
868   entry's symbol will reside during execution.
869
870 **GOT**
871   Represents the address of the global offset table.
872
873 **P**
874   Represents the place (section offset for ``et_rel`` or address for ``et_dyn``)
875   of the storage unit being relocated (computed using ``r_offset``).
876
877 **S**
878   Represents the value of the symbol whose index resides in the relocation
879   entry. Relocations not using this must specify a symbol index of ``STN_UNDEF``.
880
881 **B**
882   Represents the base address of a loaded executable or shared object which is
883   the difference between the ELF address and the actual load address. Relocations
884   using this are only valid in executable or shared objects.
885
886 The following relocation types are supported:
887
888   .. table:: AMDGPU ELF Relocation Records
889      :name: amdgpu-elf-relocation-records-table
890
891      ========================== ======= =====  ==========  ==============================
892      Relocation Type            Kind    Value  Field       Calculation
893      ========================== ======= =====  ==========  ==============================
894      ``R_AMDGPU_NONE``                  0      *none*      *none*
895      ``R_AMDGPU_ABS32_LO``      Static, 1      ``word32``  (S + A) & 0xFFFFFFFF
896                                 Dynamic
897      ``R_AMDGPU_ABS32_HI``      Static, 2      ``word32``  (S + A) >> 32
898                                 Dynamic
899      ``R_AMDGPU_ABS64``         Static, 3      ``word64``  S + A
900                                 Dynamic
901      ``R_AMDGPU_REL32``         Static  4      ``word32``  S + A - P
902      ``R_AMDGPU_REL64``         Static  5      ``word64``  S + A - P
903      ``R_AMDGPU_ABS32``         Static, 6      ``word32``  S + A
904                                 Dynamic
905      ``R_AMDGPU_GOTPCREL``      Static  7      ``word32``  G + GOT + A - P
906      ``R_AMDGPU_GOTPCREL32_LO`` Static  8      ``word32``  (G + GOT + A - P) & 0xFFFFFFFF
907      ``R_AMDGPU_GOTPCREL32_HI`` Static  9      ``word32``  (G + GOT + A - P) >> 32
908      ``R_AMDGPU_REL32_LO``      Static  10     ``word32``  (S + A - P) & 0xFFFFFFFF
909      ``R_AMDGPU_REL32_HI``      Static  11     ``word32``  (S + A - P) >> 32
910      *reserved*                         12
911      ``R_AMDGPU_RELATIVE64``    Dynamic 13     ``word64``  B + A
912      ========================== ======= =====  ==========  ==============================
913
914 ``R_AMDGPU_ABS32_LO`` and ``R_AMDGPU_ABS32_HI`` are only supported by
915 the ``mesa3d`` OS, which does not support ``R_AMDGPU_ABS64``.
916
917 There is no current OS loader support for 32 bit programs and so
918 ``R_AMDGPU_ABS32`` is not used.
919
920 .. _amdgpu-dwarf:
921
922 DWARF
923 -----
924
925 Standard DWARF [DWARF]_ Version 5 sections can be generated. These contain
926 information that maps the code object executable code and data to the source
927 language constructs. It can be used by tools such as debuggers and profilers.
928
929 Address Space Mapping
930 ~~~~~~~~~~~~~~~~~~~~~
931
932 The following address space mapping is used:
933
934   .. table:: AMDGPU DWARF Address Space Mapping
935      :name: amdgpu-dwarf-address-space-mapping-table
936
937      =================== =================
938      DWARF Address Space Memory Space
939      =================== =================
940      1                   Private (Scratch)
941      2                   Local (group/LDS)
942      *omitted*           Global
943      *omitted*           Constant
944      *omitted*           Generic (Flat)
945      *not supported*     Region (GDS)
946      =================== =================
947
948 See :ref:`amdgpu-address-spaces` for information on the memory space terminology
949 used in the table.
950
951 An ``address_class`` attribute is generated on pointer type DIEs to specify the
952 DWARF address space of the value of the pointer when it is in the *private* or
953 *local* address space. Otherwise the attribute is omitted.
954
955 An ``XDEREF`` operation is generated in location list expressions for variables
956 that are allocated in the *private* and *local* address space. Otherwise no
957 ``XDREF`` is omitted.
958
959 Register Mapping
960 ~~~~~~~~~~~~~~~~
961
962 *This section is WIP.*
963
964 .. TODO
965    Define DWARF register enumeration.
966
967    If want to present a wavefront state then should expose vector registers as
968    64 wide (rather than per work-item view that LLVM uses). Either as separate
969    registers, or a 64x4 byte single register. In either case use a new LANE op
970    (akin to XDREF) to select the current lane usage in a location
971    expression. This would also allow scalar register spilling to vector register
972    lanes to be expressed (currently no debug information is being generated for
973    spilling). If choose a wide single register approach then use LANE in
974    conjunction with PIECE operation to select the dword part of the register for
975    the current lane. If the separate register approach then use LANE to select
976    the register.
977
978 Source Text
979 ~~~~~~~~~~~
980
981 Source text for online-compiled programs (e.g. those compiled by the OpenCL
982 runtime) may be embedded into the DWARF v5 line table using the ``clang
983 -gembed-source`` option, described in table :ref:`amdgpu-debug-options`.
984
985 For example:
986
987 ``-gembed-source``
988   Enable the embedded source DWARF v5 extension.
989 ``-gno-embed-source``
990   Disable the embedded source DWARF v5 extension.
991
992   .. table:: AMDGPU Debug Options
993      :name: amdgpu-debug-options
994
995      ==================== ==================================================
996      Debug Flag           Description
997      ==================== ==================================================
998      -g[no-]embed-source  Enable/disable embedding source text in DWARF
999                           debug sections. Useful for environments where
1000                           source cannot be written to disk, such as
1001                           when performing online compilation.
1002      ==================== ==================================================
1003
1004 This option enables one extended content types in the DWARF v5 Line Number
1005 Program Header, which is used to encode embedded source.
1006
1007   .. table:: AMDGPU DWARF Line Number Program Header Extended Content Types
1008      :name: amdgpu-dwarf-extended-content-types
1009
1010      ============================  ======================
1011      Content Type                  Form
1012      ============================  ======================
1013      ``DW_LNCT_LLVM_source``       ``DW_FORM_line_strp``
1014      ============================  ======================
1015
1016 The source field will contain the UTF-8 encoded, null-terminated source text
1017 with ``'\n'`` line endings. When the source field is present, consumers can use
1018 the embedded source instead of attempting to discover the source on disk. When
1019 the source field is absent, consumers can access the file to get the source
1020 text.
1021
1022 The above content type appears in the ``file_name_entry_format`` field of the
1023 line table prologue, and its corresponding value appear in the ``file_names``
1024 field. The current encoding of the content type is documented in table
1025 :ref:`amdgpu-dwarf-extended-content-types-encoding`
1026
1027   .. table:: AMDGPU DWARF Line Number Program Header Extended Content Types Encoding
1028      :name: amdgpu-dwarf-extended-content-types-encoding
1029
1030      ============================  ====================
1031      Content Type                  Value
1032      ============================  ====================
1033      ``DW_LNCT_LLVM_source``       0x2001
1034      ============================  ====================
1035
1036 .. _amdgpu-code-conventions:
1037
1038 Code Conventions
1039 ================
1040
1041 This section provides code conventions used for each supported target triple OS
1042 (see :ref:`amdgpu-target-triples`).
1043
1044 AMDHSA
1045 ------
1046
1047 This section provides code conventions used when the target triple OS is
1048 ``amdhsa`` (see :ref:`amdgpu-target-triples`).
1049
1050 .. _amdgpu-amdhsa-code-object-target-identification:
1051
1052 Code Object Target Identification
1053 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1054
1055 The AMDHSA OS uses the following syntax to specify the code object
1056 target as a single string:
1057
1058   ``<Architecture>-<Vendor>-<OS>-<Environment>-<Processor><Target Features>``
1059
1060 Where:
1061
1062   - ``<Architecture>``, ``<Vendor>``, ``<OS>`` and ``<Environment>``
1063     are the same as the *Target Triple* (see
1064     :ref:`amdgpu-target-triples`).
1065
1066   - ``<Processor>`` is the same as the *Processor* (see
1067     :ref:`amdgpu-processors`).
1068
1069   - ``<Target Features>`` is a list of the enabled *Target Features*
1070     (see :ref:`amdgpu-target-features`), each prefixed by a plus, that
1071     apply to *Processor*. The list must be in the same order as listed
1072     in the table :ref:`amdgpu-target-feature-table`. Note that *Target
1073     Features* must be included in the list if they are enabled even if
1074     that is the default for *Processor*.
1075
1076 For example:
1077
1078   ``"amdgcn-amd-amdhsa--gfx902+xnack"``
1079
1080 .. _amdgpu-amdhsa-code-object-metadata:
1081
1082 Code Object Metadata
1083 ~~~~~~~~~~~~~~~~~~~~
1084
1085 The code object metadata specifies extensible metadata associated with the code
1086 objects executed on HSA [HSA]_ compatible runtimes such as AMD's ROCm
1087 [AMD-ROCm]_. The encoding and semantics of this metadata depends on the code
1088 object version; see :ref:`amdgpu-amdhsa-code-object-metadata-v2` and
1089 :ref:`amdgpu-amdhsa-code-object-metadata-v3`.
1090
1091 Code object metadata is specified in a note record (see
1092 :ref:`amdgpu-note-records`) and is required when the target triple OS is
1093 ``amdhsa`` (see :ref:`amdgpu-target-triples`). It must contain the minimum
1094 information necessary to support the ROCM kernel queries. For example, the
1095 segment sizes needed in a dispatch packet. In addition, a high level language
1096 runtime may require other information to be included. For example, the AMD
1097 OpenCL runtime records kernel argument information.
1098
1099 .. _amdgpu-amdhsa-code-object-metadata-v2:
1100
1101 Code Object V2 Metadata (-mattr=-code-object-v3)
1102 ++++++++++++++++++++++++++++++++++++++++++++++++
1103
1104 .. warning:: Code Object V2 is not the default code object version emitted by
1105   this version of LLVM. For a description of the metadata generated with the
1106   default configuration (Code Object V3) see
1107   :ref:`amdgpu-amdhsa-code-object-metadata-v3`.
1108
1109 Code object V2 metadata is specified by the ``NT_AMD_AMDGPU_METADATA`` note
1110 record (see :ref:`amdgpu-note-records-v2`).
1111
1112 The metadata is specified as a YAML formatted string (see [YAML]_ and
1113 :doc:`YamlIO`).
1114
1115 .. TODO
1116    Is the string null terminated? It probably should not if YAML allows it to
1117    contain null characters, otherwise it should be.
1118
1119 The metadata is represented as a single YAML document comprised of the mapping
1120 defined in table :ref:`amdgpu-amdhsa-code-object-metadata-map-table-v2` and
1121 referenced tables.
1122
1123 For boolean values, the string values of ``false`` and ``true`` are used for
1124 false and true respectively.
1125
1126 Additional information can be added to the mappings. To avoid conflicts, any
1127 non-AMD key names should be prefixed by "*vendor-name*.".
1128
1129   .. table:: AMDHSA Code Object V2 Metadata Map
1130      :name: amdgpu-amdhsa-code-object-metadata-map-table-v2
1131
1132      ========== ============== ========= =======================================
1133      String Key Value Type     Required? Description
1134      ========== ============== ========= =======================================
1135      "Version"  sequence of    Required  - The first integer is the major
1136                 2 integers                 version. Currently 1.
1137                                          - The second integer is the minor
1138                                            version. Currently 0.
1139      "Printf"   sequence of              Each string is encoded information
1140                 strings                  about a printf function call. The
1141                                          encoded information is organized as
1142                                          fields separated by colon (':'):
1143
1144                                          ``ID:N:S[0]:S[1]:...:S[N-1]:FormatString``
1145
1146                                          where:
1147
1148                                          ``ID``
1149                                            A 32 bit integer as a unique id for
1150                                            each printf function call
1151
1152                                          ``N``
1153                                            A 32 bit integer equal to the number
1154                                            of arguments of printf function call
1155                                            minus 1
1156
1157                                          ``S[i]`` (where i = 0, 1, ... , N-1)
1158                                            32 bit integers for the size in bytes
1159                                            of the i-th FormatString argument of
1160                                            the printf function call
1161
1162                                          FormatString
1163                                            The format string passed to the
1164                                            printf function call.
1165      "Kernels"  sequence of    Required  Sequence of the mappings for each
1166                 mapping                  kernel in the code object. See
1167                                          :ref:`amdgpu-amdhsa-code-object-kernel-metadata-map-table-v2`
1168                                          for the definition of the mapping.
1169      ========== ============== ========= =======================================
1170
1171 ..
1172
1173   .. table:: AMDHSA Code Object V2 Kernel Metadata Map
1174      :name: amdgpu-amdhsa-code-object-kernel-metadata-map-table-v2
1175
1176      ================= ============== ========= ================================
1177      String Key        Value Type     Required? Description
1178      ================= ============== ========= ================================
1179      "Name"            string         Required  Source name of the kernel.
1180      "SymbolName"      string         Required  Name of the kernel
1181                                                 descriptor ELF symbol.
1182      "Language"        string                   Source language of the kernel.
1183                                                 Values include:
1184
1185                                                 - "OpenCL C"
1186                                                 - "OpenCL C++"
1187                                                 - "HCC"
1188                                                 - "OpenMP"
1189
1190      "LanguageVersion" sequence of              - The first integer is the major
1191                        2 integers                 version.
1192                                                 - The second integer is the
1193                                                   minor version.
1194      "Attrs"           mapping                  Mapping of kernel attributes.
1195                                                 See
1196                                                 :ref:`amdgpu-amdhsa-code-object-kernel-attribute-metadata-map-table-v2`
1197                                                 for the mapping definition.
1198      "Args"            sequence of              Sequence of mappings of the
1199                        mapping                  kernel arguments. See
1200                                                 :ref:`amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v2`
1201                                                 for the definition of the mapping.
1202      "CodeProps"       mapping                  Mapping of properties related to
1203                                                 the kernel code. See
1204                                                 :ref:`amdgpu-amdhsa-code-object-kernel-code-properties-metadata-map-table-v2`
1205                                                 for the mapping definition.
1206      ================= ============== ========= ================================
1207
1208 ..
1209
1210   .. table:: AMDHSA Code Object V2 Kernel Attribute Metadata Map
1211      :name: amdgpu-amdhsa-code-object-kernel-attribute-metadata-map-table-v2
1212
1213      =================== ============== ========= ==============================
1214      String Key          Value Type     Required? Description
1215      =================== ============== ========= ==============================
1216      "ReqdWorkGroupSize" sequence of              If not 0, 0, 0 then all values
1217                          3 integers               must be >=1 and the dispatch
1218                                                   work-group size X, Y, Z must
1219                                                   correspond to the specified
1220                                                   values. Defaults to 0, 0, 0.
1221
1222                                                   Corresponds to the OpenCL
1223                                                   ``reqd_work_group_size``
1224                                                   attribute.
1225      "WorkGroupSizeHint" sequence of              The dispatch work-group size
1226                          3 integers               X, Y, Z is likely to be the
1227                                                   specified values.
1228
1229                                                   Corresponds to the OpenCL
1230                                                   ``work_group_size_hint``
1231                                                   attribute.
1232      "VecTypeHint"       string                   The name of a scalar or vector
1233                                                   type.
1234
1235                                                   Corresponds to the OpenCL
1236                                                   ``vec_type_hint`` attribute.
1237
1238      "RuntimeHandle"     string                   The external symbol name
1239                                                   associated with a kernel.
1240                                                   OpenCL runtime allocates a
1241                                                   global buffer for the symbol
1242                                                   and saves the kernel's address
1243                                                   to it, which is used for
1244                                                   device side enqueueing. Only
1245                                                   available for device side
1246                                                   enqueued kernels.
1247      =================== ============== ========= ==============================
1248
1249 ..
1250
1251   .. table:: AMDHSA Code Object V2 Kernel Argument Metadata Map
1252      :name: amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v2
1253
1254      ================= ============== ========= ================================
1255      String Key        Value Type     Required? Description
1256      ================= ============== ========= ================================
1257      "Name"            string                   Kernel argument name.
1258      "TypeName"        string                   Kernel argument type name.
1259      "Size"            integer        Required  Kernel argument size in bytes.
1260      "Align"           integer        Required  Kernel argument alignment in
1261                                                 bytes. Must be a power of two.
1262      "ValueKind"       string         Required  Kernel argument kind that
1263                                                 specifies how to set up the
1264                                                 corresponding argument.
1265                                                 Values include:
1266
1267                                                 "ByValue"
1268                                                   The argument is copied
1269                                                   directly into the kernarg.
1270
1271                                                 "GlobalBuffer"
1272                                                   A global address space pointer
1273                                                   to the buffer data is passed
1274                                                   in the kernarg.
1275
1276                                                 "DynamicSharedPointer"
1277                                                   A group address space pointer
1278                                                   to dynamically allocated LDS
1279                                                   is passed in the kernarg.
1280
1281                                                 "Sampler"
1282                                                   A global address space
1283                                                   pointer to a S# is passed in
1284                                                   the kernarg.
1285
1286                                                 "Image"
1287                                                   A global address space
1288                                                   pointer to a T# is passed in
1289                                                   the kernarg.
1290
1291                                                 "Pipe"
1292                                                   A global address space pointer
1293                                                   to an OpenCL pipe is passed in
1294                                                   the kernarg.
1295
1296                                                 "Queue"
1297                                                   A global address space pointer
1298                                                   to an OpenCL device enqueue
1299                                                   queue is passed in the
1300                                                   kernarg.
1301
1302                                                 "HiddenGlobalOffsetX"
1303                                                   The OpenCL grid dispatch
1304                                                   global offset for the X
1305                                                   dimension is passed in the
1306                                                   kernarg.
1307
1308                                                 "HiddenGlobalOffsetY"
1309                                                   The OpenCL grid dispatch
1310                                                   global offset for the Y
1311                                                   dimension is passed in the
1312                                                   kernarg.
1313
1314                                                 "HiddenGlobalOffsetZ"
1315                                                   The OpenCL grid dispatch
1316                                                   global offset for the Z
1317                                                   dimension is passed in the
1318                                                   kernarg.
1319
1320                                                 "HiddenNone"
1321                                                   An argument that is not used
1322                                                   by the kernel. Space needs to
1323                                                   be left for it, but it does
1324                                                   not need to be set up.
1325
1326                                                 "HiddenPrintfBuffer"
1327                                                   A global address space pointer
1328                                                   to the runtime printf buffer
1329                                                   is passed in kernarg.
1330
1331                                                 "HiddenDefaultQueue"
1332                                                   A global address space pointer
1333                                                   to the OpenCL device enqueue
1334                                                   queue that should be used by
1335                                                   the kernel by default is
1336                                                   passed in the kernarg.
1337
1338                                                 "HiddenCompletionAction"
1339                                                   A global address space pointer
1340                                                   to help link enqueued kernels into
1341                                                   the ancestor tree for determining
1342                                                   when the parent kernel has finished.
1343
1344      "ValueType"       string         Required  Kernel argument value type. Only
1345                                                 present if "ValueKind" is
1346                                                 "ByValue". For vector data
1347                                                 types, the value is for the
1348                                                 element type. Values include:
1349
1350                                                 - "Struct"
1351                                                 - "I8"
1352                                                 - "U8"
1353                                                 - "I16"
1354                                                 - "U16"
1355                                                 - "F16"
1356                                                 - "I32"
1357                                                 - "U32"
1358                                                 - "F32"
1359                                                 - "I64"
1360                                                 - "U64"
1361                                                 - "F64"
1362
1363                                                 .. TODO
1364                                                    How can it be determined if a
1365                                                    vector type, and what size
1366                                                    vector?
1367      "PointeeAlign"    integer                  Alignment in bytes of pointee
1368                                                 type for pointer type kernel
1369                                                 argument. Must be a power
1370                                                 of 2. Only present if
1371                                                 "ValueKind" is
1372                                                 "DynamicSharedPointer".
1373      "AddrSpaceQual"   string                   Kernel argument address space
1374                                                 qualifier. Only present if
1375                                                 "ValueKind" is "GlobalBuffer" or
1376                                                 "DynamicSharedPointer". Values
1377                                                 are:
1378
1379                                                 - "Private"
1380                                                 - "Global"
1381                                                 - "Constant"
1382                                                 - "Local"
1383                                                 - "Generic"
1384                                                 - "Region"
1385
1386                                                 .. TODO
1387                                                    Is GlobalBuffer only Global
1388                                                    or Constant? Is
1389                                                    DynamicSharedPointer always
1390                                                    Local? Can HCC allow Generic?
1391                                                    How can Private or Region
1392                                                    ever happen?
1393      "AccQual"         string                   Kernel argument access
1394                                                 qualifier. Only present if
1395                                                 "ValueKind" is "Image" or
1396                                                 "Pipe". Values
1397                                                 are:
1398
1399                                                 - "ReadOnly"
1400                                                 - "WriteOnly"
1401                                                 - "ReadWrite"
1402
1403                                                 .. TODO
1404                                                    Does this apply to
1405                                                    GlobalBuffer?
1406      "ActualAccQual"   string                   The actual memory accesses
1407                                                 performed by the kernel on the
1408                                                 kernel argument. Only present if
1409                                                 "ValueKind" is "GlobalBuffer",
1410                                                 "Image", or "Pipe". This may be
1411                                                 more restrictive than indicated
1412                                                 by "AccQual" to reflect what the
1413                                                 kernel actual does. If not
1414                                                 present then the runtime must
1415                                                 assume what is implied by
1416                                                 "AccQual" and "IsConst". Values
1417                                                 are:
1418
1419                                                 - "ReadOnly"
1420                                                 - "WriteOnly"
1421                                                 - "ReadWrite"
1422
1423      "IsConst"         boolean                  Indicates if the kernel argument
1424                                                 is const qualified. Only present
1425                                                 if "ValueKind" is
1426                                                 "GlobalBuffer".
1427
1428      "IsRestrict"      boolean                  Indicates if the kernel argument
1429                                                 is restrict qualified. Only
1430                                                 present if "ValueKind" is
1431                                                 "GlobalBuffer".
1432
1433      "IsVolatile"      boolean                  Indicates if the kernel argument
1434                                                 is volatile qualified. Only
1435                                                 present if "ValueKind" is
1436                                                 "GlobalBuffer".
1437
1438      "IsPipe"          boolean                  Indicates if the kernel argument
1439                                                 is pipe qualified. Only present
1440                                                 if "ValueKind" is "Pipe".
1441
1442                                                 .. TODO
1443                                                    Can GlobalBuffer be pipe
1444                                                    qualified?
1445      ================= ============== ========= ================================
1446
1447 ..
1448
1449   .. table:: AMDHSA Code Object V2 Kernel Code Properties Metadata Map
1450      :name: amdgpu-amdhsa-code-object-kernel-code-properties-metadata-map-table-v2
1451
1452      ============================ ============== ========= =====================
1453      String Key                   Value Type     Required? Description
1454      ============================ ============== ========= =====================
1455      "KernargSegmentSize"         integer        Required  The size in bytes of
1456                                                            the kernarg segment
1457                                                            that holds the values
1458                                                            of the arguments to
1459                                                            the kernel.
1460      "GroupSegmentFixedSize"      integer        Required  The amount of group
1461                                                            segment memory
1462                                                            required by a
1463                                                            work-group in
1464                                                            bytes. This does not
1465                                                            include any
1466                                                            dynamically allocated
1467                                                            group segment memory
1468                                                            that may be added
1469                                                            when the kernel is
1470                                                            dispatched.
1471      "PrivateSegmentFixedSize"    integer        Required  The amount of fixed
1472                                                            private address space
1473                                                            memory required for a
1474                                                            work-item in
1475                                                            bytes. If the kernel
1476                                                            uses a dynamic call
1477                                                            stack then additional
1478                                                            space must be added
1479                                                            to this value for the
1480                                                            call stack.
1481      "KernargSegmentAlign"        integer        Required  The maximum byte
1482                                                            alignment of
1483                                                            arguments in the
1484                                                            kernarg segment. Must
1485                                                            be a power of 2.
1486      "WavefrontSize"              integer        Required  Wavefront size. Must
1487                                                            be a power of 2.
1488      "NumSGPRs"                   integer        Required  Number of scalar
1489                                                            registers used by a
1490                                                            wavefront for
1491                                                            GFX6-GFX9. This
1492                                                            includes the special
1493                                                            SGPRs for VCC, Flat
1494                                                            Scratch (GFX7-GFX9)
1495                                                            and XNACK (for
1496                                                            GFX8-GFX9). It does
1497                                                            not include the 16
1498                                                            SGPR added if a trap
1499                                                            handler is
1500                                                            enabled. It is not
1501                                                            rounded up to the
1502                                                            allocation
1503                                                            granularity.
1504      "NumVGPRs"                   integer        Required  Number of vector
1505                                                            registers used by
1506                                                            each work-item for
1507                                                            GFX6-GFX9
1508      "MaxFlatWorkGroupSize"       integer        Required  Maximum flat
1509                                                            work-group size
1510                                                            supported by the
1511                                                            kernel in work-items.
1512                                                            Must be >=1 and
1513                                                            consistent with
1514                                                            ReqdWorkGroupSize if
1515                                                            not 0, 0, 0.
1516      "NumSpilledSGPRs"            integer                  Number of stores from
1517                                                            a scalar register to
1518                                                            a register allocator
1519                                                            created spill
1520                                                            location.
1521      "NumSpilledVGPRs"            integer                  Number of stores from
1522                                                            a vector register to
1523                                                            a register allocator
1524                                                            created spill
1525                                                            location.
1526      ============================ ============== ========= =====================
1527
1528 .. _amdgpu-amdhsa-code-object-metadata-v3:
1529
1530 Code Object V3 Metadata (-mattr=+code-object-v3)
1531 ++++++++++++++++++++++++++++++++++++++++++++++++
1532
1533 Code object V3 metadata is specified by the ``NT_AMDGPU_METADATA`` note record
1534 (see :ref:`amdgpu-note-records-v3`).
1535
1536 The metadata is represented as Message Pack formatted binary data (see
1537 [MsgPack]_). The top level is a Message Pack map that includes the
1538 keys defined in table
1539 :ref:`amdgpu-amdhsa-code-object-metadata-map-table-v3` and referenced
1540 tables.
1541
1542 Additional information can be added to the maps. To avoid conflicts,
1543 any key names should be prefixed by "*vendor-name*." where
1544 ``vendor-name`` can be the the name of the vendor and specific vendor
1545 tool that generates the information. The prefix is abbreviated to
1546 simply "." when it appears within a map that has been added by the
1547 same *vendor-name*.
1548
1549   .. table:: AMDHSA Code Object V3 Metadata Map
1550      :name: amdgpu-amdhsa-code-object-metadata-map-table-v3
1551
1552      ================= ============== ========= =======================================
1553      String Key        Value Type     Required? Description
1554      ================= ============== ========= =======================================
1555      "amdhsa.version"  sequence of    Required  - The first integer is the major
1556                        2 integers                 version. Currently 1.
1557                                                 - The second integer is the minor
1558                                                   version. Currently 0.
1559      "amdhsa.printf"   sequence of              Each string is encoded information
1560                        strings                  about a printf function call. The
1561                                                 encoded information is organized as
1562                                                 fields separated by colon (':'):
1563
1564                                                 ``ID:N:S[0]:S[1]:...:S[N-1]:FormatString``
1565
1566                                                 where:
1567
1568                                                 ``ID``
1569                                                   A 32 bit integer as a unique id for
1570                                                   each printf function call
1571
1572                                                 ``N``
1573                                                   A 32 bit integer equal to the number
1574                                                   of arguments of printf function call
1575                                                   minus 1
1576
1577                                                 ``S[i]`` (where i = 0, 1, ... , N-1)
1578                                                   32 bit integers for the size in bytes
1579                                                   of the i-th FormatString argument of
1580                                                   the printf function call
1581
1582                                                 FormatString
1583                                                   The format string passed to the
1584                                                   printf function call.
1585      "amdhsa.kernels"  sequence of    Required  Sequence of the maps for each
1586                        map                      kernel in the code object. See
1587                                                 :ref:`amdgpu-amdhsa-code-object-kernel-metadata-map-table-v3`
1588                                                 for the definition of the keys included
1589                                                 in that map.
1590      ================= ============== ========= =======================================
1591
1592 ..
1593
1594   .. table:: AMDHSA Code Object V3 Kernel Metadata Map
1595      :name: amdgpu-amdhsa-code-object-kernel-metadata-map-table-v3
1596
1597      =================================== ============== ========= ================================
1598      String Key                          Value Type     Required? Description
1599      =================================== ============== ========= ================================
1600      ".name"                             string         Required  Source name of the kernel.
1601      ".symbol"                           string         Required  Name of the kernel
1602                                                                   descriptor ELF symbol.
1603      ".language"                         string                   Source language of the kernel.
1604                                                                   Values include:
1605
1606                                                                   - "OpenCL C"
1607                                                                   - "OpenCL C++"
1608                                                                   - "HCC"
1609                                                                   - "HIP"
1610                                                                   - "OpenMP"
1611                                                                   - "Assembler"
1612
1613      ".language_version"                 sequence of              - The first integer is the major
1614                                          2 integers                 version.
1615                                                                   - The second integer is the
1616                                                                     minor version.
1617      ".args"                             sequence of              Sequence of maps of the
1618                                          map                      kernel arguments. See
1619                                                                   :ref:`amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v3`
1620                                                                   for the definition of the keys
1621                                                                   included in that map.
1622      ".reqd_workgroup_size"              sequence of              If not 0, 0, 0 then all values
1623                                          3 integers               must be >=1 and the dispatch
1624                                                                   work-group size X, Y, Z must
1625                                                                   correspond to the specified
1626                                                                   values. Defaults to 0, 0, 0.
1627
1628                                                                   Corresponds to the OpenCL
1629                                                                   ``reqd_work_group_size``
1630                                                                   attribute.
1631      ".workgroup_size_hint"              sequence of              The dispatch work-group size
1632                                          3 integers               X, Y, Z is likely to be the
1633                                                                   specified values.
1634
1635                                                                   Corresponds to the OpenCL
1636                                                                   ``work_group_size_hint``
1637                                                                   attribute.
1638      ".vec_type_hint"                    string                   The name of a scalar or vector
1639                                                                   type.
1640
1641                                                                   Corresponds to the OpenCL
1642                                                                   ``vec_type_hint`` attribute.
1643
1644      ".device_enqueue_symbol"            string                   The external symbol name
1645                                                                   associated with a kernel.
1646                                                                   OpenCL runtime allocates a
1647                                                                   global buffer for the symbol
1648                                                                   and saves the kernel's address
1649                                                                   to it, which is used for
1650                                                                   device side enqueueing. Only
1651                                                                   available for device side
1652                                                                   enqueued kernels.
1653      ".kernarg_segment_size"             integer        Required  The size in bytes of
1654                                                                   the kernarg segment
1655                                                                   that holds the values
1656                                                                   of the arguments to
1657                                                                   the kernel.
1658      ".group_segment_fixed_size"         integer        Required  The amount of group
1659                                                                   segment memory
1660                                                                   required by a
1661                                                                   work-group in
1662                                                                   bytes. This does not
1663                                                                   include any
1664                                                                   dynamically allocated
1665                                                                   group segment memory
1666                                                                   that may be added
1667                                                                   when the kernel is
1668                                                                   dispatched.
1669      ".private_segment_fixed_size"       integer        Required  The amount of fixed
1670                                                                   private address space
1671                                                                   memory required for a
1672                                                                   work-item in
1673                                                                   bytes. If the kernel
1674                                                                   uses a dynamic call
1675                                                                   stack then additional
1676                                                                   space must be added
1677                                                                   to this value for the
1678                                                                   call stack.
1679      ".kernarg_segment_align"            integer        Required  The maximum byte
1680                                                                   alignment of
1681                                                                   arguments in the
1682                                                                   kernarg segment. Must
1683                                                                   be a power of 2.
1684      ".wavefront_size"                   integer        Required  Wavefront size. Must
1685                                                                   be a power of 2.
1686      ".sgpr_count"                       integer        Required  Number of scalar
1687                                                                   registers required by a
1688                                                                   wavefront for
1689                                                                   GFX6-GFX9. A register
1690                                                                   is required if it is
1691                                                                   used explicitly, or
1692                                                                   if a higher numbered
1693                                                                   register is used
1694                                                                   explicitly. This
1695                                                                   includes the special
1696                                                                   SGPRs for VCC, Flat
1697                                                                   Scratch (GFX7-GFX9)
1698                                                                   and XNACK (for
1699                                                                   GFX8-GFX9). It does
1700                                                                   not include the 16
1701                                                                   SGPR added if a trap
1702                                                                   handler is
1703                                                                   enabled. It is not
1704                                                                   rounded up to the
1705                                                                   allocation
1706                                                                   granularity.
1707      ".vgpr_count"                       integer        Required  Number of vector
1708                                                                   registers required by
1709                                                                   each work-item for
1710                                                                   GFX6-GFX9. A register
1711                                                                   is required if it is
1712                                                                   used explicitly, or
1713                                                                   if a higher numbered
1714                                                                   register is used
1715                                                                   explicitly.
1716      ".max_flat_workgroup_size"          integer        Required  Maximum flat
1717                                                                   work-group size
1718                                                                   supported by the
1719                                                                   kernel in work-items.
1720                                                                   Must be >=1 and
1721                                                                   consistent with
1722                                                                   ReqdWorkGroupSize if
1723                                                                   not 0, 0, 0.
1724      ".sgpr_spill_count"                 integer                  Number of stores from
1725                                                                   a scalar register to
1726                                                                   a register allocator
1727                                                                   created spill
1728                                                                   location.
1729      ".vgpr_spill_count"                 integer                  Number of stores from
1730                                                                   a vector register to
1731                                                                   a register allocator
1732                                                                   created spill
1733                                                                   location.
1734      =================================== ============== ========= ================================
1735
1736 ..
1737
1738   .. table:: AMDHSA Code Object V3 Kernel Argument Metadata Map
1739      :name: amdgpu-amdhsa-code-object-kernel-argument-metadata-map-table-v3
1740
1741      ====================== ============== ========= ================================
1742      String Key             Value Type     Required? Description
1743      ====================== ============== ========= ================================
1744      ".name"                string                   Kernel argument name.
1745      ".type_name"           string                   Kernel argument type name.
1746      ".size"                integer        Required  Kernel argument size in bytes.
1747      ".offset"              integer        Required  Kernel argument offset in
1748                                                      bytes. The offset must be a
1749                                                      multiple of the alignment
1750                                                      required by the argument.
1751      ".value_kind"          string         Required  Kernel argument kind that
1752                                                      specifies how to set up the
1753                                                      corresponding argument.
1754                                                      Values include:
1755
1756                                                      "by_value"
1757                                                        The argument is copied
1758                                                        directly into the kernarg.
1759
1760                                                      "global_buffer"
1761                                                        A global address space pointer
1762                                                        to the buffer data is passed
1763                                                        in the kernarg.
1764
1765                                                      "dynamic_shared_pointer"
1766                                                        A group address space pointer
1767                                                        to dynamically allocated LDS
1768                                                        is passed in the kernarg.
1769
1770                                                      "sampler"
1771                                                        A global address space
1772                                                        pointer to a S# is passed in
1773                                                        the kernarg.
1774
1775                                                      "image"
1776                                                        A global address space
1777                                                        pointer to a T# is passed in
1778                                                        the kernarg.
1779
1780                                                      "pipe"
1781                                                        A global address space pointer
1782                                                        to an OpenCL pipe is passed in
1783                                                        the kernarg.
1784
1785                                                      "queue"
1786                                                        A global address space pointer
1787                                                        to an OpenCL device enqueue
1788                                                        queue is passed in the
1789                                                        kernarg.
1790
1791                                                      "hidden_global_offset_x"
1792                                                        The OpenCL grid dispatch
1793                                                        global offset for the X
1794                                                        dimension is passed in the
1795                                                        kernarg.
1796
1797                                                      "hidden_global_offset_y"
1798                                                        The OpenCL grid dispatch
1799                                                        global offset for the Y
1800                                                        dimension is passed in the
1801                                                        kernarg.
1802
1803                                                      "hidden_global_offset_z"
1804                                                        The OpenCL grid dispatch
1805                                                        global offset for the Z
1806                                                        dimension is passed in the
1807                                                        kernarg.
1808
1809                                                      "hidden_none"
1810                                                        An argument that is not used
1811                                                        by the kernel. Space needs to
1812                                                        be left for it, but it does
1813                                                        not need to be set up.
1814
1815                                                      "hidden_printf_buffer"
1816                                                        A global address space pointer
1817                                                        to the runtime printf buffer
1818                                                        is passed in kernarg.
1819
1820                                                      "hidden_default_queue"
1821                                                        A global address space pointer
1822                                                        to the OpenCL device enqueue
1823                                                        queue that should be used by
1824                                                        the kernel by default is
1825                                                        passed in the kernarg.
1826
1827                                                      "hidden_completion_action"
1828                                                        A global address space pointer
1829                                                        to help link enqueued kernels into
1830                                                        the ancestor tree for determining
1831                                                        when the parent kernel has finished.
1832
1833      ".value_type"          string         Required  Kernel argument value type. Only
1834                                                      present if ".value_kind" is
1835                                                      "by_value". For vector data
1836                                                      types, the value is for the
1837                                                      element type. Values include:
1838
1839                                                      - "struct"
1840                                                      - "i8"
1841                                                      - "u8"
1842                                                      - "i16"
1843                                                      - "u16"
1844                                                      - "f16"
1845                                                      - "i32"
1846                                                      - "u32"
1847                                                      - "f32"
1848                                                      - "i64"
1849                                                      - "u64"
1850                                                      - "f64"
1851
1852                                                      .. TODO
1853                                                         How can it be determined if a
1854                                                         vector type, and what size
1855                                                         vector?
1856      ".pointee_align"       integer                  Alignment in bytes of pointee
1857                                                      type for pointer type kernel
1858                                                      argument. Must be a power
1859                                                      of 2. Only present if
1860                                                      ".value_kind" is
1861                                                      "dynamic_shared_pointer".
1862      ".address_space"       string                   Kernel argument address space
1863                                                      qualifier. Only present if
1864                                                      ".value_kind" is "global_buffer" or
1865                                                      "dynamic_shared_pointer". Values
1866                                                      are:
1867
1868                                                      - "private"
1869                                                      - "global"
1870                                                      - "constant"
1871                                                      - "local"
1872                                                      - "generic"
1873                                                      - "region"
1874
1875                                                      .. TODO
1876                                                         Is "global_buffer" only "global"
1877                                                         or "constant"? Is
1878                                                         "dynamic_shared_pointer" always
1879                                                         "local"? Can HCC allow "generic"?
1880                                                         How can "private" or "region"
1881                                                         ever happen?
1882      ".access"              string                   Kernel argument access
1883                                                      qualifier. Only present if
1884                                                      ".value_kind" is "image" or
1885                                                      "pipe". Values
1886                                                      are:
1887
1888                                                      - "read_only"
1889                                                      - "write_only"
1890                                                      - "read_write"
1891
1892                                                      .. TODO
1893                                                         Does this apply to
1894                                                         "global_buffer"?
1895      ".actual_access"       string                   The actual memory accesses
1896                                                      performed by the kernel on the
1897                                                      kernel argument. Only present if
1898                                                      ".value_kind" is "global_buffer",
1899                                                      "image", or "pipe". This may be
1900                                                      more restrictive than indicated
1901                                                      by ".access" to reflect what the
1902                                                      kernel actual does. If not
1903                                                      present then the runtime must
1904                                                      assume what is implied by
1905                                                      ".access" and ".is_const"      . Values
1906                                                      are:
1907
1908                                                      - "read_only"
1909                                                      - "write_only"
1910                                                      - "read_write"
1911
1912      ".is_const"            boolean                  Indicates if the kernel argument
1913                                                      is const qualified. Only present
1914                                                      if ".value_kind" is
1915                                                      "global_buffer".
1916
1917      ".is_restrict"         boolean                  Indicates if the kernel argument
1918                                                      is restrict qualified. Only
1919                                                      present if ".value_kind" is
1920                                                      "global_buffer".
1921
1922      ".is_volatile"         boolean                  Indicates if the kernel argument
1923                                                      is volatile qualified. Only
1924                                                      present if ".value_kind" is
1925                                                      "global_buffer".
1926
1927      ".is_pipe"             boolean                  Indicates if the kernel argument
1928                                                      is pipe qualified. Only present
1929                                                      if ".value_kind" is "pipe".
1930
1931                                                      .. TODO
1932                                                         Can "global_buffer" be pipe
1933                                                         qualified?
1934      ====================== ============== ========= ================================
1935
1936 ..
1937
1938 Kernel Dispatch
1939 ~~~~~~~~~~~~~~~
1940
1941 The HSA architected queuing language (AQL) defines a user space memory interface
1942 that can be used to control the dispatch of kernels, in an agent independent
1943 way. An agent can have zero or more AQL queues created for it using the ROCm
1944 runtime, in which AQL packets (all of which are 64 bytes) can be placed. See the
1945 *HSA Platform System Architecture Specification* [HSA]_ for the AQL queue
1946 mechanics and packet layouts.
1947
1948 The packet processor of a kernel agent is responsible for detecting and
1949 dispatching HSA kernels from the AQL queues associated with it. For AMD GPUs the
1950 packet processor is implemented by the hardware command processor (CP),
1951 asynchronous dispatch controller (ADC) and shader processor input controller
1952 (SPI).
1953
1954 The ROCm runtime can be used to allocate an AQL queue object. It uses the kernel
1955 mode driver to initialize and register the AQL queue with CP.
1956
1957 To dispatch a kernel the following actions are performed. This can occur in the
1958 CPU host program, or from an HSA kernel executing on a GPU.
1959
1960 1. A pointer to an AQL queue for the kernel agent on which the kernel is to be
1961    executed is obtained.
1962 2. A pointer to the kernel descriptor (see
1963    :ref:`amdgpu-amdhsa-kernel-descriptor`) of the kernel to execute is
1964    obtained. It must be for a kernel that is contained in a code object that that
1965    was loaded by the ROCm runtime on the kernel agent with which the AQL queue is
1966    associated.
1967 3. Space is allocated for the kernel arguments using the ROCm runtime allocator
1968    for a memory region with the kernarg property for the kernel agent that will
1969    execute the kernel. It must be at least 16 byte aligned.
1970 4. Kernel argument values are assigned to the kernel argument memory
1971    allocation. The layout is defined in the *HSA Programmer's Language Reference*
1972    [HSA]_. For AMDGPU the kernel execution directly accesses the kernel argument
1973    memory in the same way constant memory is accessed. (Note that the HSA
1974    specification allows an implementation to copy the kernel argument contents to
1975    another location that is accessed by the kernel.)
1976 5. An AQL kernel dispatch packet is created on the AQL queue. The ROCm runtime
1977    api uses 64 bit atomic operations to reserve space in the AQL queue for the
1978    packet. The packet must be set up, and the final write must use an atomic
1979    store release to set the packet kind to ensure the packet contents are
1980    visible to the kernel agent. AQL defines a doorbell signal mechanism to
1981    notify the kernel agent that the AQL queue has been updated. These rules, and
1982    the layout of the AQL queue and kernel dispatch packet is defined in the *HSA
1983    System Architecture Specification* [HSA]_.
1984 6. A kernel dispatch packet includes information about the actual dispatch,
1985    such as grid and work-group size, together with information from the code
1986    object about the kernel, such as segment sizes. The ROCm runtime queries on
1987    the kernel symbol can be used to obtain the code object values which are
1988    recorded in the :ref:`amdgpu-amdhsa-code-object-metadata`.
1989 7. CP executes micro-code and is responsible for detecting and setting up the
1990    GPU to execute the wavefronts of a kernel dispatch.
1991 8. CP ensures that when the a wavefront starts executing the kernel machine
1992    code, the scalar general purpose registers (SGPR) and vector general purpose
1993    registers (VGPR) are set up as required by the machine code. The required
1994    setup is defined in the :ref:`amdgpu-amdhsa-kernel-descriptor`. The initial
1995    register state is defined in
1996    :ref:`amdgpu-amdhsa-initial-kernel-execution-state`.
1997 9. The prolog of the kernel machine code (see
1998    :ref:`amdgpu-amdhsa-kernel-prolog`) sets up the machine state as necessary
1999    before continuing executing the machine code that corresponds to the kernel.
2000 10. When the kernel dispatch has completed execution, CP signals the completion
2001     signal specified in the kernel dispatch packet if not 0.
2002
2003 .. _amdgpu-amdhsa-memory-spaces:
2004
2005 Memory Spaces
2006 ~~~~~~~~~~~~~
2007
2008 The memory space properties are:
2009
2010   .. table:: AMDHSA Memory Spaces
2011      :name: amdgpu-amdhsa-memory-spaces-table
2012
2013      ================= =========== ======== ======= ==================
2014      Memory Space Name HSA Segment Hardware Address NULL Value
2015                        Name        Name     Size
2016      ================= =========== ======== ======= ==================
2017      Private           private     scratch  32      0x00000000
2018      Local             group       LDS      32      0xFFFFFFFF
2019      Global            global      global   64      0x0000000000000000
2020      Constant          constant    *same as 64      0x0000000000000000
2021                                    global*
2022      Generic           flat        flat     64      0x0000000000000000
2023      Region            N/A         GDS      32      *not implemented
2024                                                     for AMDHSA*
2025      ================= =========== ======== ======= ==================
2026
2027 The global and constant memory spaces both use global virtual addresses, which
2028 are the same virtual address space used by the CPU. However, some virtual
2029 addresses may only be accessible to the CPU, some only accessible by the GPU,
2030 and some by both.
2031
2032 Using the constant memory space indicates that the data will not change during
2033 the execution of the kernel. This allows scalar read instructions to be
2034 used. The vector and scalar L1 caches are invalidated of volatile data before
2035 each kernel dispatch execution to allow constant memory to change values between
2036 kernel dispatches.
2037
2038 The local memory space uses the hardware Local Data Store (LDS) which is
2039 automatically allocated when the hardware creates work-groups of wavefronts, and
2040 freed when all the wavefronts of a work-group have terminated. The data store
2041 (DS) instructions can be used to access it.
2042
2043 The private memory space uses the hardware scratch memory support. If the kernel
2044 uses scratch, then the hardware allocates memory that is accessed using
2045 wavefront lane dword (4 byte) interleaving. The mapping used from private
2046 address to physical address is:
2047
2048   ``wavefront-scratch-base +
2049   (private-address * wavefront-size * 4) +
2050   (wavefront-lane-id * 4)``
2051
2052 There are different ways that the wavefront scratch base address is determined
2053 by a wavefront (see :ref:`amdgpu-amdhsa-initial-kernel-execution-state`). This
2054 memory can be accessed in an interleaved manner using buffer instruction with
2055 the scratch buffer descriptor and per wavefront scratch offset, by the scratch
2056 instructions, or by flat instructions. If each lane of a wavefront accesses the
2057 same private address, the interleaving results in adjacent dwords being accessed
2058 and hence requires fewer cache lines to be fetched. Multi-dword access is not
2059 supported except by flat and scratch instructions in GFX9.
2060
2061 The generic address space uses the hardware flat address support available in
2062 GFX7-GFX9. This uses two fixed ranges of virtual addresses (the private and
2063 local appertures), that are outside the range of addressible global memory, to
2064 map from a flat address to a private or local address.
2065
2066 FLAT instructions can take a flat address and access global, private (scratch)
2067 and group (LDS) memory depending in if the address is within one of the
2068 apperture ranges. Flat access to scratch requires hardware aperture setup and
2069 setup in the kernel prologue (see :ref:`amdgpu-amdhsa-flat-scratch`). Flat
2070 access to LDS requires hardware aperture setup and M0 (GFX7-GFX8) register setup
2071 (see :ref:`amdgpu-amdhsa-m0`).
2072
2073 To convert between a segment address and a flat address the base address of the
2074 appertures address can be used. For GFX7-GFX8 these are available in the
2075 :ref:`amdgpu-amdhsa-hsa-aql-queue` the address of which can be obtained with
2076 Queue Ptr SGPR (see :ref:`amdgpu-amdhsa-initial-kernel-execution-state`). For
2077 GFX9 the appature base addresses are directly available as inline constant
2078 registers ``SRC_SHARED_BASE/LIMIT`` and ``SRC_PRIVATE_BASE/LIMIT``. In 64 bit
2079 address mode the apperture sizes are 2^32 bytes and the base is aligned to 2^32
2080 which makes it easier to convert from flat to segment or segment to flat.
2081
2082 Image and Samplers
2083 ~~~~~~~~~~~~~~~~~~
2084
2085 Image and sample handles created by the ROCm runtime are 64 bit addresses of a
2086 hardware 32 byte V# and 48 byte S# object respectively. In order to support the
2087 HSA ``query_sampler`` operations two extra dwords are used to store the HSA BRIG
2088 enumeration values for the queries that are not trivially deducible from the S#
2089 representation.
2090
2091 HSA Signals
2092 ~~~~~~~~~~~
2093
2094 HSA signal handles created by the ROCm runtime are 64 bit addresses of a
2095 structure allocated in memory accessible from both the CPU and GPU. The
2096 structure is defined by the ROCm runtime and subject to change between releases
2097 (see [AMD-ROCm-github]_).
2098
2099 .. _amdgpu-amdhsa-hsa-aql-queue:
2100
2101 HSA AQL Queue
2102 ~~~~~~~~~~~~~
2103
2104 The HSA AQL queue structure is defined by the ROCm runtime and subject to change
2105 between releases (see [AMD-ROCm-github]_). For some processors it contains
2106 fields needed to implement certain language features such as the flat address
2107 aperture bases. It also contains fields used by CP such as managing the
2108 allocation of scratch memory.
2109
2110 .. _amdgpu-amdhsa-kernel-descriptor:
2111
2112 Kernel Descriptor
2113 ~~~~~~~~~~~~~~~~~
2114
2115 A kernel descriptor consists of the information needed by CP to initiate the
2116 execution of a kernel, including the entry point address of the machine code
2117 that implements the kernel.
2118
2119 Kernel Descriptor for GFX6-GFX9
2120 +++++++++++++++++++++++++++++++
2121
2122 CP microcode requires the Kernel descriptor to be allocated on 64 byte
2123 alignment.
2124
2125   .. table:: Kernel Descriptor for GFX6-GFX9
2126      :name: amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table
2127
2128      ======= ======= =============================== ============================
2129      Bits    Size    Field Name                      Description
2130      ======= ======= =============================== ============================
2131      31:0    4 bytes GROUP_SEGMENT_FIXED_SIZE        The amount of fixed local
2132                                                      address space memory
2133                                                      required for a work-group
2134                                                      in bytes. This does not
2135                                                      include any dynamically
2136                                                      allocated local address
2137                                                      space memory that may be
2138                                                      added when the kernel is
2139                                                      dispatched.
2140      63:32   4 bytes PRIVATE_SEGMENT_FIXED_SIZE      The amount of fixed
2141                                                      private address space
2142                                                      memory required for a
2143                                                      work-item in bytes. If
2144                                                      is_dynamic_callstack is 1
2145                                                      then additional space must
2146                                                      be added to this value for
2147                                                      the call stack.
2148      127:64  8 bytes                                 Reserved, must be 0.
2149      191:128 8 bytes KERNEL_CODE_ENTRY_BYTE_OFFSET   Byte offset (possibly
2150                                                      negative) from base
2151                                                      address of kernel
2152                                                      descriptor to kernel's
2153                                                      entry point instruction
2154                                                      which must be 256 byte
2155                                                      aligned.
2156      383:192 24                                      Reserved, must be 0.
2157              bytes
2158      415:384 4 bytes COMPUTE_PGM_RSRC1               Compute Shader (CS)
2159                                                      program settings used by
2160                                                      CP to set up
2161                                                      ``COMPUTE_PGM_RSRC1``
2162                                                      configuration
2163                                                      register. See
2164                                                      :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
2165      447:416 4 bytes COMPUTE_PGM_RSRC2               Compute Shader (CS)
2166                                                      program settings used by
2167                                                      CP to set up
2168                                                      ``COMPUTE_PGM_RSRC2``
2169                                                      configuration
2170                                                      register. See
2171                                                      :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
2172      448     1 bit   ENABLE_SGPR_PRIVATE_SEGMENT     Enable the setup of the
2173                      _BUFFER                         SGPR user data registers
2174                                                      (see
2175                                                      :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
2176
2177                                                      The total number of SGPR
2178                                                      user data registers
2179                                                      requested must not exceed
2180                                                      16 and match value in
2181                                                      ``compute_pgm_rsrc2.user_sgpr.user_sgpr_count``.
2182                                                      Any requests beyond 16
2183                                                      will be ignored.
2184      449     1 bit   ENABLE_SGPR_DISPATCH_PTR        *see above*
2185      450     1 bit   ENABLE_SGPR_QUEUE_PTR           *see above*
2186      451     1 bit   ENABLE_SGPR_KERNARG_SEGMENT_PTR *see above*
2187      452     1 bit   ENABLE_SGPR_DISPATCH_ID         *see above*
2188      453     1 bit   ENABLE_SGPR_FLAT_SCRATCH_INIT   *see above*
2189      454     1 bit   ENABLE_SGPR_PRIVATE_SEGMENT     *see above*
2190                      _SIZE
2191      455     1 bit                                   Reserved, must be 0.
2192      511:456 8 bytes                                 Reserved, must be 0.
2193      512     **Total size 64 bytes.**
2194      ======= ====================================================================
2195
2196 ..
2197
2198   .. table:: compute_pgm_rsrc1 for GFX6-GFX9
2199      :name: amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table
2200
2201      ======= ======= =============================== ===========================================================================
2202      Bits    Size    Field Name                      Description
2203      ======= ======= =============================== ===========================================================================
2204      5:0     6 bits  GRANULATED_WORKITEM_VGPR_COUNT  Number of vector register
2205                                                      blocks used by each work-item;
2206                                                      granularity is device
2207                                                      specific:
2208
2209                                                      GFX6-GFX9
2210                                                        - vgprs_used 0..256
2211                                                        - max(0, ceil(vgprs_used / 4) - 1)
2212
2213                                                      Where vgprs_used is defined
2214                                                      as the highest VGPR number
2215                                                      explicitly referenced plus
2216                                                      one.
2217
2218                                                      Used by CP to set up
2219                                                      ``COMPUTE_PGM_RSRC1.VGPRS``.
2220
2221                                                      The
2222                                                      :ref:`amdgpu-assembler`
2223                                                      calculates this
2224                                                      automatically for the
2225                                                      selected processor from
2226                                                      values provided to the
2227                                                      `.amdhsa_kernel` directive
2228                                                      by the
2229                                                      `.amdhsa_next_free_vgpr`
2230                                                      nested directive (see
2231                                                      :ref:`amdhsa-kernel-directives-table`).
2232      9:6     4 bits  GRANULATED_WAVEFRONT_SGPR_COUNT Number of scalar register
2233                                                      blocks used by a wavefront;
2234                                                      granularity is device
2235                                                      specific:
2236
2237                                                      GFX6-GFX8
2238                                                        - sgprs_used 0..112
2239                                                        - max(0, ceil(sgprs_used / 8) - 1)
2240                                                      GFX9
2241                                                        - sgprs_used 0..112
2242                                                        - 2 * max(0, ceil(sgprs_used / 16) - 1)
2243
2244                                                      Where sgprs_used is
2245                                                      defined as the highest
2246                                                      SGPR number explicitly
2247                                                      referenced plus one, plus
2248                                                      a target-specific number
2249                                                      of additional special
2250                                                      SGPRs for VCC,
2251                                                      FLAT_SCRATCH (GFX7+) and
2252                                                      XNACK_MASK (GFX8+), and
2253                                                      any additional
2254                                                      target-specific
2255                                                      limitations. It does not
2256                                                      include the 16 SGPRs added
2257                                                      if a trap handler is
2258                                                      enabled.
2259
2260                                                      The target-specific
2261                                                      limitations and special
2262                                                      SGPR layout are defined in
2263                                                      the hardware
2264                                                      documentation, which can
2265                                                      be found in the
2266                                                      :ref:`amdgpu-processors`
2267                                                      table.
2268
2269                                                      Used by CP to set up
2270                                                      ``COMPUTE_PGM_RSRC1.SGPRS``.
2271
2272                                                      The
2273                                                      :ref:`amdgpu-assembler`
2274                                                      calculates this
2275                                                      automatically for the
2276                                                      selected processor from
2277                                                      values provided to the
2278                                                      `.amdhsa_kernel` directive
2279                                                      by the
2280                                                      `.amdhsa_next_free_sgpr`
2281                                                      and `.amdhsa_reserve_*`
2282                                                      nested directives (see
2283                                                      :ref:`amdhsa-kernel-directives-table`).
2284      11:10   2 bits  PRIORITY                        Must be 0.
2285
2286                                                      Start executing wavefront
2287                                                      at the specified priority.
2288
2289                                                      CP is responsible for
2290                                                      filling in
2291                                                      ``COMPUTE_PGM_RSRC1.PRIORITY``.
2292      13:12   2 bits  FLOAT_ROUND_MODE_32             Wavefront starts execution
2293                                                      with specified rounding
2294                                                      mode for single (32
2295                                                      bit) floating point
2296                                                      precision floating point
2297                                                      operations.
2298
2299                                                      Floating point rounding
2300                                                      mode values are defined in
2301                                                      :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
2302
2303                                                      Used by CP to set up
2304                                                      ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
2305      15:14   2 bits  FLOAT_ROUND_MODE_16_64          Wavefront starts execution
2306                                                      with specified rounding
2307                                                      denorm mode for half/double (16
2308                                                      and 64 bit) floating point
2309                                                      precision floating point
2310                                                      operations.
2311
2312                                                      Floating point rounding
2313                                                      mode values are defined in
2314                                                      :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
2315
2316                                                      Used by CP to set up
2317                                                      ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
2318      17:16   2 bits  FLOAT_DENORM_MODE_32            Wavefront starts execution
2319                                                      with specified denorm mode
2320                                                      for single (32
2321                                                      bit)  floating point
2322                                                      precision floating point
2323                                                      operations.
2324
2325                                                      Floating point denorm mode
2326                                                      values are defined in
2327                                                      :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
2328
2329                                                      Used by CP to set up
2330                                                      ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
2331      19:18   2 bits  FLOAT_DENORM_MODE_16_64         Wavefront starts execution
2332                                                      with specified denorm mode
2333                                                      for half/double (16
2334                                                      and 64 bit) floating point
2335                                                      precision floating point
2336                                                      operations.
2337
2338                                                      Floating point denorm mode
2339                                                      values are defined in
2340                                                      :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
2341
2342                                                      Used by CP to set up
2343                                                      ``COMPUTE_PGM_RSRC1.FLOAT_MODE``.
2344      20      1 bit   PRIV                            Must be 0.
2345
2346                                                      Start executing wavefront
2347                                                      in privilege trap handler
2348                                                      mode.
2349
2350                                                      CP is responsible for
2351                                                      filling in
2352                                                      ``COMPUTE_PGM_RSRC1.PRIV``.
2353      21      1 bit   ENABLE_DX10_CLAMP               Wavefront starts execution
2354                                                      with DX10 clamp mode
2355                                                      enabled. Used by the vector
2356                                                      ALU to force DX10 style
2357                                                      treatment of NaN's (when
2358                                                      set, clamp NaN to zero,
2359                                                      otherwise pass NaN
2360                                                      through).
2361
2362                                                      Used by CP to set up
2363                                                      ``COMPUTE_PGM_RSRC1.DX10_CLAMP``.
2364      22      1 bit   DEBUG_MODE                      Must be 0.
2365
2366                                                      Start executing wavefront
2367                                                      in single step mode.
2368
2369                                                      CP is responsible for
2370                                                      filling in
2371                                                      ``COMPUTE_PGM_RSRC1.DEBUG_MODE``.
2372      23      1 bit   ENABLE_IEEE_MODE                Wavefront starts execution
2373                                                      with IEEE mode
2374                                                      enabled. Floating point
2375                                                      opcodes that support
2376                                                      exception flag gathering
2377                                                      will quiet and propagate
2378                                                      signaling-NaN inputs per
2379                                                      IEEE 754-2008. Min_dx10 and
2380                                                      max_dx10 become IEEE
2381                                                      754-2008 compliant due to
2382                                                      signaling-NaN propagation
2383                                                      and quieting.
2384
2385                                                      Used by CP to set up
2386                                                      ``COMPUTE_PGM_RSRC1.IEEE_MODE``.
2387      24      1 bit   BULKY                           Must be 0.
2388
2389                                                      Only one work-group allowed
2390                                                      to execute on a compute
2391                                                      unit.
2392
2393                                                      CP is responsible for
2394                                                      filling in
2395                                                      ``COMPUTE_PGM_RSRC1.BULKY``.
2396      25      1 bit   CDBG_USER                       Must be 0.
2397
2398                                                      Flag that can be used to
2399                                                      control debugging code.
2400
2401                                                      CP is responsible for
2402                                                      filling in
2403                                                      ``COMPUTE_PGM_RSRC1.CDBG_USER``.
2404      26      1 bit   FP16_OVFL                       GFX6-GFX8
2405                                                        Reserved, must be 0.
2406                                                      GFX9
2407                                                        Wavefront starts execution
2408                                                        with specified fp16 overflow
2409                                                        mode.
2410
2411                                                        - If 0, fp16 overflow generates
2412                                                          +/-INF values.
2413                                                        - If 1, fp16 overflow that is the
2414                                                          result of an +/-INF input value
2415                                                          or divide by 0 produces a +/-INF,
2416                                                          otherwise clamps computed
2417                                                          overflow to +/-MAX_FP16 as
2418                                                          appropriate.
2419
2420                                                        Used by CP to set up
2421                                                        ``COMPUTE_PGM_RSRC1.FP16_OVFL``.
2422      31:27   5 bits                                  Reserved, must be 0.
2423      32      **Total size 4 bytes**
2424      ======= ===================================================================================================================
2425
2426 ..
2427
2428   .. table:: compute_pgm_rsrc2 for GFX6-GFX9
2429      :name: amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table
2430
2431      ======= ======= =============================== ===========================================================================
2432      Bits    Size    Field Name                      Description
2433      ======= ======= =============================== ===========================================================================
2434      0       1 bit   ENABLE_SGPR_PRIVATE_SEGMENT     Enable the setup of the
2435                      _WAVEFRONT_OFFSET               SGPR wavefront scratch offset
2436                                                      system register (see
2437                                                      :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
2438
2439                                                      Used by CP to set up
2440                                                      ``COMPUTE_PGM_RSRC2.SCRATCH_EN``.
2441      5:1     5 bits  USER_SGPR_COUNT                 The total number of SGPR
2442                                                      user data registers
2443                                                      requested. This number must
2444                                                      match the number of user
2445                                                      data registers enabled.
2446
2447                                                      Used by CP to set up
2448                                                      ``COMPUTE_PGM_RSRC2.USER_SGPR``.
2449      6       1 bit   ENABLE_TRAP_HANDLER             Must be 0.
2450
2451                                                      This bit represents
2452                                                      ``COMPUTE_PGM_RSRC2.TRAP_PRESENT``,
2453                                                      which is set by the CP if
2454                                                      the runtime has installed a
2455                                                      trap handler.
2456      7       1 bit   ENABLE_SGPR_WORKGROUP_ID_X      Enable the setup of the
2457                                                      system SGPR register for
2458                                                      the work-group id in the X
2459                                                      dimension (see
2460                                                      :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
2461
2462                                                      Used by CP to set up
2463                                                      ``COMPUTE_PGM_RSRC2.TGID_X_EN``.
2464      8       1 bit   ENABLE_SGPR_WORKGROUP_ID_Y      Enable the setup of the
2465                                                      system SGPR register for
2466                                                      the work-group id in the Y
2467                                                      dimension (see
2468                                                      :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
2469
2470                                                      Used by CP to set up
2471                                                      ``COMPUTE_PGM_RSRC2.TGID_Y_EN``.
2472      9       1 bit   ENABLE_SGPR_WORKGROUP_ID_Z      Enable the setup of the
2473                                                      system SGPR register for
2474                                                      the work-group id in the Z
2475                                                      dimension (see
2476                                                      :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
2477
2478                                                      Used by CP to set up
2479                                                      ``COMPUTE_PGM_RSRC2.TGID_Z_EN``.
2480      10      1 bit   ENABLE_SGPR_WORKGROUP_INFO      Enable the setup of the
2481                                                      system SGPR register for
2482                                                      work-group information (see
2483                                                      :ref:`amdgpu-amdhsa-initial-kernel-execution-state`).
2484
2485                                                      Used by CP to set up
2486                                                      ``COMPUTE_PGM_RSRC2.TGID_SIZE_EN``.
2487      12:11   2 bits  ENABLE_VGPR_WORKITEM_ID         Enable the setup of the
2488                                                      VGPR system registers used
2489                                                      for the work-item ID.
2490                                                      :ref:`amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table`
2491                                                      defines the values.
2492
2493                                                      Used by CP to set up
2494                                                      ``COMPUTE_PGM_RSRC2.TIDIG_CMP_CNT``.
2495      13      1 bit   ENABLE_EXCEPTION_ADDRESS_WATCH  Must be 0.
2496
2497                                                      Wavefront starts execution
2498                                                      with address watch
2499                                                      exceptions enabled which
2500                                                      are generated when L1 has
2501                                                      witnessed a thread access
2502                                                      an *address of
2503                                                      interest*.
2504
2505                                                      CP is responsible for
2506                                                      filling in the address
2507                                                      watch bit in
2508                                                      ``COMPUTE_PGM_RSRC2.EXCP_EN_MSB``
2509                                                      according to what the
2510                                                      runtime requests.
2511      14      1 bit   ENABLE_EXCEPTION_MEMORY         Must be 0.
2512
2513                                                      Wavefront starts execution
2514                                                      with memory violation
2515                                                      exceptions exceptions
2516                                                      enabled which are generated
2517                                                      when a memory violation has
2518                                                      occurred for this wavefront from
2519                                                      L1 or LDS
2520                                                      (write-to-read-only-memory,
2521                                                      mis-aligned atomic, LDS
2522                                                      address out of range,
2523                                                      illegal address, etc.).
2524
2525                                                      CP sets the memory
2526                                                      violation bit in
2527                                                      ``COMPUTE_PGM_RSRC2.EXCP_EN_MSB``
2528                                                      according to what the
2529                                                      runtime requests.
2530      23:15   9 bits  GRANULATED_LDS_SIZE             Must be 0.
2531
2532                                                      CP uses the rounded value
2533                                                      from the dispatch packet,
2534                                                      not this value, as the
2535                                                      dispatch may contain
2536                                                      dynamically allocated group
2537                                                      segment memory. CP writes
2538                                                      directly to
2539                                                      ``COMPUTE_PGM_RSRC2.LDS_SIZE``.
2540
2541                                                      Amount of group segment
2542                                                      (LDS) to allocate for each
2543                                                      work-group. Granularity is
2544                                                      device specific:
2545
2546                                                      GFX6:
2547                                                        roundup(lds-size / (64 * 4))
2548                                                      GFX7-GFX9:
2549                                                        roundup(lds-size / (128 * 4))
2550
2551      24      1 bit   ENABLE_EXCEPTION_IEEE_754_FP    Wavefront starts execution
2552                      _INVALID_OPERATION              with specified exceptions
2553                                                      enabled.
2554
2555                                                      Used by CP to set up
2556                                                      ``COMPUTE_PGM_RSRC2.EXCP_EN``
2557                                                      (set from bits 0..6).
2558
2559                                                      IEEE 754 FP Invalid
2560                                                      Operation
2561      25      1 bit   ENABLE_EXCEPTION_FP_DENORMAL    FP Denormal one or more
2562                      _SOURCE                         input operands is a
2563                                                      denormal number
2564      26      1 bit   ENABLE_EXCEPTION_IEEE_754_FP    IEEE 754 FP Division by
2565                      _DIVISION_BY_ZERO               Zero
2566      27      1 bit   ENABLE_EXCEPTION_IEEE_754_FP    IEEE 754 FP FP Overflow
2567                      _OVERFLOW
2568      28      1 bit   ENABLE_EXCEPTION_IEEE_754_FP    IEEE 754 FP Underflow
2569                      _UNDERFLOW
2570      29      1 bit   ENABLE_EXCEPTION_IEEE_754_FP    IEEE 754 FP Inexact
2571                      _INEXACT
2572      30      1 bit   ENABLE_EXCEPTION_INT_DIVIDE_BY  Integer Division by Zero
2573                      _ZERO                           (rcp_iflag_f32 instruction
2574                                                      only)
2575      31      1 bit                                   Reserved, must be 0.
2576      32      **Total size 4 bytes.**
2577      ======= ===================================================================================================================
2578
2579 ..
2580
2581   .. table:: Floating Point Rounding Mode Enumeration Values
2582      :name: amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table
2583
2584      ====================================== ===== ==============================
2585      Enumeration Name                       Value Description
2586      ====================================== ===== ==============================
2587      FLOAT_ROUND_MODE_NEAR_EVEN             0     Round Ties To Even
2588      FLOAT_ROUND_MODE_PLUS_INFINITY         1     Round Toward +infinity
2589      FLOAT_ROUND_MODE_MINUS_INFINITY        2     Round Toward -infinity
2590      FLOAT_ROUND_MODE_ZERO                  3     Round Toward 0
2591      ====================================== ===== ==============================
2592
2593 ..
2594
2595   .. table:: Floating Point Denorm Mode Enumeration Values
2596      :name: amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table
2597
2598      ====================================== ===== ==============================
2599      Enumeration Name                       Value Description
2600      ====================================== ===== ==============================
2601      FLOAT_DENORM_MODE_FLUSH_SRC_DST        0     Flush Source and Destination
2602                                                   Denorms
2603      FLOAT_DENORM_MODE_FLUSH_DST            1     Flush Output Denorms
2604      FLOAT_DENORM_MODE_FLUSH_SRC            2     Flush Source Denorms
2605      FLOAT_DENORM_MODE_FLUSH_NONE           3     No Flush
2606      ====================================== ===== ==============================
2607
2608 ..
2609
2610   .. table:: System VGPR Work-Item ID Enumeration Values
2611      :name: amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table
2612
2613      ======================================== ===== ============================
2614      Enumeration Name                         Value Description
2615      ======================================== ===== ============================
2616      SYSTEM_VGPR_WORKITEM_ID_X                0     Set work-item X dimension
2617                                                     ID.
2618      SYSTEM_VGPR_WORKITEM_ID_X_Y              1     Set work-item X and Y
2619                                                     dimensions ID.
2620      SYSTEM_VGPR_WORKITEM_ID_X_Y_Z            2     Set work-item X, Y and Z
2621                                                     dimensions ID.
2622      SYSTEM_VGPR_WORKITEM_ID_UNDEFINED        3     Undefined.
2623      ======================================== ===== ============================
2624
2625 .. _amdgpu-amdhsa-initial-kernel-execution-state:
2626
2627 Initial Kernel Execution State
2628 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2629
2630 This section defines the register state that will be set up by the packet
2631 processor prior to the start of execution of every wavefront. This is limited by
2632 the constraints of the hardware controllers of CP/ADC/SPI.
2633
2634 The order of the SGPR registers is defined, but the compiler can specify which
2635 ones are actually setup in the kernel descriptor using the ``enable_sgpr_*`` bit
2636 fields (see :ref:`amdgpu-amdhsa-kernel-descriptor`). The register numbers used
2637 for enabled registers are dense starting at SGPR0: the first enabled register is
2638 SGPR0, the next enabled register is SGPR1 etc.; disabled registers do not have
2639 an SGPR number.
2640
2641 The initial SGPRs comprise up to 16 User SRGPs that are set by CP and apply to
2642 all wavefronts of the grid. It is possible to specify more than 16 User SGPRs using
2643 the ``enable_sgpr_*`` bit fields, in which case only the first 16 are actually
2644 initialized. These are then immediately followed by the System SGPRs that are
2645 set up by ADC/SPI and can have different values for each wavefront of the grid
2646 dispatch.
2647
2648 SGPR register initial state is defined in
2649 :ref:`amdgpu-amdhsa-sgpr-register-set-up-order-table`.
2650
2651   .. table:: SGPR Register Set Up Order
2652      :name: amdgpu-amdhsa-sgpr-register-set-up-order-table
2653
2654      ========== ========================== ====== ==============================
2655      SGPR Order Name                       Number Description
2656                 (kernel descriptor enable  of
2657                 field)                     SGPRs
2658      ========== ========================== ====== ==============================
2659      First      Private Segment Buffer     4      V# that can be used, together
2660                 (enable_sgpr_private              with Scratch Wavefront Offset
2661                 _segment_buffer)                  as an offset, to access the
2662                                                   private memory space using a
2663                                                   segment address.
2664
2665                                                   CP uses the value provided by
2666                                                   the runtime.
2667      then       Dispatch Ptr               2      64 bit address of AQL dispatch
2668                 (enable_sgpr_dispatch_ptr)        packet for kernel dispatch
2669                                                   actually executing.
2670      then       Queue Ptr                  2      64 bit address of amd_queue_t
2671                 (enable_sgpr_queue_ptr)           object for AQL queue on which
2672                                                   the dispatch packet was
2673                                                   queued.
2674      then       Kernarg Segment Ptr        2      64 bit address of Kernarg
2675                 (enable_sgpr_kernarg              segment. This is directly
2676                 _segment_ptr)                     copied from the
2677                                                   kernarg_address in the kernel
2678                                                   dispatch packet.
2679
2680                                                   Having CP load it once avoids
2681                                                   loading it at the beginning of
2682                                                   every wavefront.
2683      then       Dispatch Id                2      64 bit Dispatch ID of the
2684                 (enable_sgpr_dispatch_id)         dispatch packet being
2685                                                   executed.
2686      then       Flat Scratch Init          2      This is 2 SGPRs:
2687                 (enable_sgpr_flat_scratch
2688                 _init)                            GFX6
2689                                                     Not supported.
2690                                                   GFX7-GFX8
2691                                                     The first SGPR is a 32 bit
2692                                                     byte offset from
2693                                                     ``SH_HIDDEN_PRIVATE_BASE_VIMID``
2694                                                     to per SPI base of memory
2695                                                     for scratch for the queue
2696                                                     executing the kernel
2697                                                     dispatch. CP obtains this
2698                                                     from the runtime. (The
2699                                                     Scratch Segment Buffer base
2700                                                     address is
2701                                                     ``SH_HIDDEN_PRIVATE_BASE_VIMID``
2702                                                     plus this offset.) The value
2703                                                     of Scratch Wavefront Offset must
2704                                                     be added to this offset by
2705                                                     the kernel machine code,
2706                                                     right shifted by 8, and
2707                                                     moved to the FLAT_SCRATCH_HI
2708                                                     SGPR register.
2709                                                     FLAT_SCRATCH_HI corresponds
2710                                                     to SGPRn-4 on GFX7, and
2711                                                     SGPRn-6 on GFX8 (where SGPRn
2712                                                     is the highest numbered SGPR
2713                                                     allocated to the wavefront).
2714                                                     FLAT_SCRATCH_HI is
2715                                                     multiplied by 256 (as it is
2716                                                     in units of 256 bytes) and
2717                                                     added to
2718                                                     ``SH_HIDDEN_PRIVATE_BASE_VIMID``
2719                                                     to calculate the per wavefront
2720                                                     FLAT SCRATCH BASE in flat
2721                                                     memory instructions that
2722                                                     access the scratch
2723                                                     apperture.
2724
2725                                                     The second SGPR is 32 bit
2726                                                     byte size of a single
2727                                                     work-item's scratch memory
2728                                                     usage. CP obtains this from
2729                                                     the runtime, and it is
2730                                                     always a multiple of DWORD.
2731                                                     CP checks that the value in
2732                                                     the kernel dispatch packet
2733                                                     Private Segment Byte Size is
2734                                                     not larger, and requests the
2735                                                     runtime to increase the
2736                                                     queue's scratch size if
2737                                                     necessary. The kernel code
2738                                                     must move it to
2739                                                     FLAT_SCRATCH_LO which is
2740                                                     SGPRn-3 on GFX7 and SGPRn-5
2741                                                     on GFX8. FLAT_SCRATCH_LO is
2742                                                     used as the FLAT SCRATCH
2743                                                     SIZE in flat memory
2744                                                     instructions. Having CP load
2745                                                     it once avoids loading it at
2746                                                     the beginning of every
2747                                                     wavefront.
2748                                                   GFX9
2749                                                     This is the
2750                                                     64 bit base address of the
2751                                                     per SPI scratch backing
2752                                                     memory managed by SPI for
2753                                                     the queue executing the
2754                                                     kernel dispatch. CP obtains
2755                                                     this from the runtime (and
2756                                                     divides it if there are
2757                                                     multiple Shader Arrays each
2758                                                     with its own SPI). The value
2759                                                     of Scratch Wavefront Offset must
2760                                                     be added by the kernel
2761                                                     machine code and the result
2762                                                     moved to the FLAT_SCRATCH
2763                                                     SGPR which is SGPRn-6 and
2764                                                     SGPRn-5. It is used as the
2765                                                     FLAT SCRATCH BASE in flat
2766                                                     memory instructions.
2767      then       Private Segment Size       1      The 32 bit byte size of a
2768                                                   (enable_sgpr_private single
2769                                                   work-item's
2770                                                   scratch_segment_size) memory
2771                                                   allocation. This is the
2772                                                   value from the kernel
2773                                                   dispatch packet Private
2774                                                   Segment Byte Size rounded up
2775                                                   by CP to a multiple of
2776                                                   DWORD.
2777
2778                                                   Having CP load it once avoids
2779                                                   loading it at the beginning of
2780                                                   every wavefront.
2781
2782                                                   This is not used for
2783                                                   GFX7-GFX8 since it is the same
2784                                                   value as the second SGPR of
2785                                                   Flat Scratch Init. However, it
2786                                                   may be needed for GFX9 which
2787                                                   changes the meaning of the
2788                                                   Flat Scratch Init value.
2789      then       Grid Work-Group Count X    1      32 bit count of the number of
2790                 (enable_sgpr_grid                 work-groups in the X dimension
2791                 _workgroup_count_X)               for the grid being
2792                                                   executed. Computed from the
2793                                                   fields in the kernel dispatch
2794                                                   packet as ((grid_size.x +
2795                                                   workgroup_size.x - 1) /
2796                                                   workgroup_size.x).
2797      then       Grid Work-Group Count Y    1      32 bit count of the number of
2798                 (enable_sgpr_grid                 work-groups in the Y dimension
2799                 _workgroup_count_Y &&             for the grid being
2800                 less than 16 previous             executed. Computed from the
2801                 SGPRs)                            fields in the kernel dispatch
2802                                                   packet as ((grid_size.y +
2803                                                   workgroup_size.y - 1) /
2804                                                   workgroupSize.y).
2805
2806                                                   Only initialized if <16
2807                                                   previous SGPRs initialized.
2808      then       Grid Work-Group Count Z    1      32 bit count of the number of
2809                 (enable_sgpr_grid                 work-groups in the Z dimension
2810                 _workgroup_count_Z &&             for the grid being
2811                 less than 16 previous             executed. Computed from the
2812                 SGPRs)                            fields in the kernel dispatch
2813                                                   packet as ((grid_size.z +
2814                                                   workgroup_size.z - 1) /
2815                                                   workgroupSize.z).
2816
2817                                                   Only initialized if <16
2818                                                   previous SGPRs initialized.
2819      then       Work-Group Id X            1      32 bit work-group id in X
2820                 (enable_sgpr_workgroup_id         dimension of grid for
2821                 _X)                               wavefront.
2822      then       Work-Group Id Y            1      32 bit work-group id in Y
2823                 (enable_sgpr_workgroup_id         dimension of grid for
2824                 _Y)                               wavefront.
2825      then       Work-Group Id Z            1      32 bit work-group id in Z
2826                 (enable_sgpr_workgroup_id         dimension of grid for
2827                 _Z)                               wavefront.
2828      then       Work-Group Info            1      {first_wavefront, 14'b0000,
2829                 (enable_sgpr_workgroup            ordered_append_term[10:0],
2830                 _info)                            threadgroup_size_in_wavefronts[5:0]}
2831      then       Scratch Wavefront Offset   1      32 bit byte offset from base
2832                 (enable_sgpr_private              of scratch base of queue
2833                 _segment_wavefront_offset)        executing the kernel
2834                                                   dispatch. Must be used as an
2835                                                   offset with Private
2836                                                   segment address when using
2837                                                   Scratch Segment Buffer. It
2838                                                   must be used to set up FLAT
2839                                                   SCRATCH for flat addressing
2840                                                   (see
2841                                                   :ref:`amdgpu-amdhsa-flat-scratch`).
2842      ========== ========================== ====== ==============================
2843
2844 The order of the VGPR registers is defined, but the compiler can specify which
2845 ones are actually setup in the kernel descriptor using the ``enable_vgpr*`` bit
2846 fields (see :ref:`amdgpu-amdhsa-kernel-descriptor`). The register numbers used
2847 for enabled registers are dense starting at VGPR0: the first enabled register is
2848 VGPR0, the next enabled register is VGPR1 etc.; disabled registers do not have a
2849 VGPR number.
2850
2851 VGPR register initial state is defined in
2852 :ref:`amdgpu-amdhsa-vgpr-register-set-up-order-table`.
2853
2854   .. table:: VGPR Register Set Up Order
2855      :name: amdgpu-amdhsa-vgpr-register-set-up-order-table
2856
2857      ========== ========================== ====== ==============================
2858      VGPR Order Name                       Number Description
2859                 (kernel descriptor enable  of
2860                 field)                     VGPRs
2861      ========== ========================== ====== ==============================
2862      First      Work-Item Id X             1      32 bit work item id in X
2863                 (Always initialized)              dimension of work-group for
2864                                                   wavefront lane.
2865      then       Work-Item Id Y             1      32 bit work item id in Y
2866                 (enable_vgpr_workitem_id          dimension of work-group for
2867                 > 0)                              wavefront lane.
2868      then       Work-Item Id Z             1      32 bit work item id in Z
2869                 (enable_vgpr_workitem_id          dimension of work-group for
2870                 > 1)                              wavefront lane.
2871      ========== ========================== ====== ==============================
2872
2873 The setting of registers is done by GPU CP/ADC/SPI hardware as follows:
2874
2875 1. SGPRs before the Work-Group Ids are set by CP using the 16 User Data
2876    registers.
2877 2. Work-group Id registers X, Y, Z are set by ADC which supports any
2878    combination including none.
2879 3. Scratch Wavefront Offset is set by SPI in a per wavefront basis which is why
2880    its value cannot included with the flat scratch init value which is per queue.
2881 4. The VGPRs are set by SPI which only supports specifying either (X), (X, Y)
2882    or (X, Y, Z).
2883
2884 Flat Scratch register pair are adjacent SGRRs so they can be moved as a 64 bit
2885 value to the hardware required SGPRn-3 and SGPRn-4 respectively.
2886
2887 The global segment can be accessed either using buffer instructions (GFX6 which
2888 has V# 64 bit address support), flat instructions (GFX7-GFX9), or global
2889 instructions (GFX9).
2890
2891 If buffer operations are used then the compiler can generate a V# with the
2892 following properties:
2893
2894 * base address of 0
2895 * no swizzle
2896 * ATC: 1 if IOMMU present (such as APU)
2897 * ptr64: 1
2898 * MTYPE set to support memory coherence that matches the runtime (such as CC for
2899   APU and NC for dGPU).
2900
2901 .. _amdgpu-amdhsa-kernel-prolog:
2902
2903 Kernel Prolog
2904 ~~~~~~~~~~~~~
2905
2906 .. _amdgpu-amdhsa-m0:
2907
2908 M0
2909 ++
2910
2911 GFX6-GFX8
2912   The M0 register must be initialized with a value at least the total LDS size
2913   if the kernel may access LDS via DS or flat operations. Total LDS size is
2914   available in dispatch packet. For M0, it is also possible to use maximum
2915   possible value of LDS for given target (0x7FFF for GFX6 and 0xFFFF for
2916   GFX7-GFX8).
2917 GFX9
2918   The M0 register is not used for range checking LDS accesses and so does not
2919   need to be initialized in the prolog.
2920
2921 .. _amdgpu-amdhsa-flat-scratch:
2922
2923 Flat Scratch
2924 ++++++++++++
2925
2926 If the kernel may use flat operations to access scratch memory, the prolog code
2927 must set up FLAT_SCRATCH register pair (FLAT_SCRATCH_LO/FLAT_SCRATCH_HI which
2928 are in SGPRn-4/SGPRn-3). Initialization uses Flat Scratch Init and Scratch Wavefront
2929 Offset SGPR registers (see :ref:`amdgpu-amdhsa-initial-kernel-execution-state`):
2930
2931 GFX6
2932   Flat scratch is not supported.
2933
2934 GFX7-GFX8
2935   1. The low word of Flat Scratch Init is 32 bit byte offset from
2936      ``SH_HIDDEN_PRIVATE_BASE_VIMID`` to the base of scratch backing memory
2937      being managed by SPI for the queue executing the kernel dispatch. This is
2938      the same value used in the Scratch Segment Buffer V# base address. The
2939      prolog must add the value of Scratch Wavefront Offset to get the wavefront's byte
2940      scratch backing memory offset from ``SH_HIDDEN_PRIVATE_BASE_VIMID``. Since
2941      FLAT_SCRATCH_LO is in units of 256 bytes, the offset must be right shifted
2942      by 8 before moving into FLAT_SCRATCH_LO.
2943   2. The second word of Flat Scratch Init is 32 bit byte size of a single
2944      work-items scratch memory usage. This is directly loaded from the kernel
2945      dispatch packet Private Segment Byte Size and rounded up to a multiple of
2946      DWORD. Having CP load it once avoids loading it at the beginning of every
2947      wavefront. The prolog must move it to FLAT_SCRATCH_LO for use as FLAT SCRATCH
2948      SIZE.
2949
2950 GFX9
2951   The Flat Scratch Init is the 64 bit address of the base of scratch backing
2952   memory being managed by SPI for the queue executing the kernel dispatch. The
2953   prolog must add the value of Scratch Wavefront Offset and moved to the FLAT_SCRATCH
2954   pair for use as the flat scratch base in flat memory instructions.
2955
2956 .. _amdgpu-amdhsa-memory-model:
2957
2958 Memory Model
2959 ~~~~~~~~~~~~
2960
2961 This section describes the mapping of LLVM memory model onto AMDGPU machine code
2962 (see :ref:`memmodel`). *The implementation is WIP.*
2963
2964 .. TODO
2965    Update when implementation complete.
2966
2967 The AMDGPU backend supports the memory synchronization scopes specified in
2968 :ref:`amdgpu-memory-scopes`.
2969
2970 The code sequences used to implement the memory model are defined in table
2971 :ref:`amdgpu-amdhsa-memory-model-code-sequences-gfx6-gfx9-table`.
2972
2973 The sequences specify the order of instructions that a single thread must
2974 execute. The ``s_waitcnt`` and ``buffer_wbinvl1_vol`` are defined with respect
2975 to other memory instructions executed by the same thread. This allows them to be
2976 moved earlier or later which can allow them to be combined with other instances
2977 of the same instruction, or hoisted/sunk out of loops to improve
2978 performance. Only the instructions related to the memory model are given;
2979 additional ``s_waitcnt`` instructions are required to ensure registers are
2980 defined before being used. These may be able to be combined with the memory
2981 model ``s_waitcnt`` instructions as described above.
2982
2983 The AMDGPU backend supports the following memory models:
2984
2985   HSA Memory Model [HSA]_
2986     The HSA memory model uses a single happens-before relation for all address
2987     spaces (see :ref:`amdgpu-address-spaces`).
2988   OpenCL Memory Model [OpenCL]_
2989     The OpenCL memory model which has separate happens-before relations for the
2990     global and local address spaces. Only a fence specifying both global and
2991     local address space, and seq_cst instructions join the relationships. Since
2992     the LLVM ``memfence`` instruction does not allow an address space to be
2993     specified the OpenCL fence has to convervatively assume both local and
2994     global address space was specified. However, optimizations can often be
2995     done to eliminate the additional ``s_waitcnt`` instructions when there are
2996     no intervening memory instructions which access the corresponding address
2997     space. The code sequences in the table indicate what can be omitted for the
2998     OpenCL memory. The target triple environment is used to determine if the
2999     source language is OpenCL (see :ref:`amdgpu-opencl`).
3000
3001 ``ds/flat_load/store/atomic`` instructions to local memory are termed LDS
3002 operations.
3003
3004 ``buffer/global/flat_load/store/atomic`` instructions to global memory are
3005 termed vector memory operations.
3006
3007 For GFX6-GFX9:
3008
3009 * Each agent has multiple compute units (CU).
3010 * Each CU has multiple SIMDs that execute wavefronts.
3011 * The wavefronts for a single work-group are executed in the same CU but may be
3012   executed by different SIMDs.
3013 * Each CU has a single LDS memory shared by the wavefronts of the work-groups
3014   executing on it.
3015 * All LDS operations of a CU are performed as wavefront wide operations in a
3016   global order and involve no caching. Completion is reported to a wavefront in
3017   execution order.
3018 * The LDS memory has multiple request queues shared by the SIMDs of a
3019   CU. Therefore, the LDS operations performed by different wavefronts of a work-group
3020   can be reordered relative to each other, which can result in reordering the
3021   visibility of vector memory operations with respect to LDS operations of other
3022   wavefronts in the same work-group. A ``s_waitcnt lgkmcnt(0)`` is required to
3023   ensure synchronization between LDS operations and vector memory operations
3024   between wavefronts of a work-group, but not between operations performed by the
3025   same wavefront.
3026 * The vector memory operations are performed as wavefront wide operations and
3027   completion is reported to a wavefront in execution order. The exception is
3028   that for GFX7-GFX9 ``flat_load/store/atomic`` instructions can report out of
3029   vector memory order if they access LDS memory, and out of LDS operation order
3030   if they access global memory.
3031 * The vector memory operations access a single vector L1 cache shared by all
3032   SIMDs a CU. Therefore, no special action is required for coherence between the
3033   lanes of a single wavefront, or for coherence between wavefronts in the same
3034   work-group. A ``buffer_wbinvl1_vol`` is required for coherence between wavefronts
3035   executing in different work-groups as they may be executing on different CUs.
3036 * The scalar memory operations access a scalar L1 cache shared by all wavefronts
3037   on a group of CUs. The scalar and vector L1 caches are not coherent. However,
3038   scalar operations are used in a restricted way so do not impact the memory
3039   model. See :ref:`amdgpu-amdhsa-memory-spaces`.
3040 * The vector and scalar memory operations use an L2 cache shared by all CUs on
3041   the same agent.
3042 * The L2 cache has independent channels to service disjoint ranges of virtual
3043   addresses.
3044 * Each CU has a separate request queue per channel. Therefore, the vector and
3045   scalar memory operations performed by wavefronts executing in different work-groups
3046   (which may be executing on different CUs) of an agent can be reordered
3047   relative to each other. A ``s_waitcnt vmcnt(0)`` is required to ensure
3048   synchronization between vector memory operations of different CUs. It ensures a
3049   previous vector memory operation has completed before executing a subsequent
3050   vector memory or LDS operation and so can be used to meet the requirements of
3051   acquire and release.
3052 * The L2 cache can be kept coherent with other agents on some targets, or ranges
3053   of virtual addresses can be set up to bypass it to ensure system coherence.
3054
3055 Private address space uses ``buffer_load/store`` using the scratch V# (GFX6-GFX8),
3056 or ``scratch_load/store`` (GFX9). Since only a single thread is accessing the
3057 memory, atomic memory orderings are not meaningful and all accesses are treated
3058 as non-atomic.
3059
3060 Constant address space uses ``buffer/global_load`` instructions (or equivalent
3061 scalar memory instructions). Since the constant address space contents do not
3062 change during the execution of a kernel dispatch it is not legal to perform
3063 stores, and atomic memory orderings are not meaningful and all access are
3064 treated as non-atomic.
3065
3066 A memory synchronization scope wider than work-group is not meaningful for the
3067 group (LDS) address space and is treated as work-group.
3068
3069 The memory model does not support the region address space which is treated as
3070 non-atomic.
3071
3072 Acquire memory ordering is not meaningful on store atomic instructions and is
3073 treated as non-atomic.
3074
3075 Release memory ordering is not meaningful on load atomic instructions and is
3076 treated a non-atomic.
3077
3078 Acquire-release memory ordering is not meaningful on load or store atomic
3079 instructions and is treated as acquire and release respectively.
3080
3081 AMDGPU backend only uses scalar memory operations to access memory that is
3082 proven to not change during the execution of the kernel dispatch. This includes
3083 constant address space and global address space for program scope const
3084 variables. Therefore the kernel machine code does not have to maintain the
3085 scalar L1 cache to ensure it is coherent with the vector L1 cache. The scalar
3086 and vector L1 caches are invalidated between kernel dispatches by CP since
3087 constant address space data may change between kernel dispatch executions. See
3088 :ref:`amdgpu-amdhsa-memory-spaces`.
3089
3090 The one execption is if scalar writes are used to spill SGPR registers. In this
3091 case the AMDGPU backend ensures the memory location used to spill is never
3092 accessed by vector memory operations at the same time. If scalar writes are used
3093 then a ``s_dcache_wb`` is inserted before the ``s_endpgm`` and before a function
3094 return since the locations may be used for vector memory instructions by a
3095 future wavefront that uses the same scratch area, or a function call that creates a
3096 frame at the same address, respectively. There is no need for a ``s_dcache_inv``
3097 as all scalar writes are write-before-read in the same thread.
3098
3099 Scratch backing memory (which is used for the private address space)
3100 is accessed with MTYPE NC_NV (non-coherenent non-volatile). Since the private
3101 address space is only accessed by a single thread, and is always
3102 write-before-read, there is never a need to invalidate these entries from the L1
3103 cache. Hence all cache invalidates are done as ``*_vol`` to only invalidate the
3104 volatile cache lines.
3105
3106 On dGPU the kernarg backing memory is accessed as UC (uncached) to avoid needing
3107 to invalidate the L2 cache. This also causes it to be treated as
3108 non-volatile and so is not invalidated by ``*_vol``. On APU it is accessed as CC
3109 (cache coherent) and so the L2 cache will coherent with the CPU and other
3110 agents.
3111
3112   .. table:: AMDHSA Memory Model Code Sequences GFX6-GFX9
3113      :name: amdgpu-amdhsa-memory-model-code-sequences-gfx6-gfx9-table
3114
3115      ============ ============ ============== ========== ===============================
3116      LLVM Instr   LLVM Memory  LLVM Memory    AMDGPU     AMDGPU Machine Code
3117                   Ordering     Sync Scope     Address
3118                                               Space
3119      ============ ============ ============== ========== ===============================
3120      **Non-Atomic**
3121      -----------------------------------------------------------------------------------
3122      load         *none*       *none*         - global   - !volatile & !nontemporal
3123                                               - generic
3124                                               - private    1. buffer/global/flat_load
3125                                               - constant
3126                                                          - volatile & !nontemporal
3127
3128                                                            1. buffer/global/flat_load
3129                                                               glc=1
3130
3131                                                          - nontemporal
3132
3133                                                            1. buffer/global/flat_load
3134                                                               glc=1 slc=1
3135
3136      load         *none*       *none*         - local    1. ds_load
3137      store        *none*       *none*         - global   - !nontemporal
3138                                               - generic
3139                                               - private    1. buffer/global/flat_store
3140                                               - constant
3141                                                          - nontemporal
3142
3143                                                            1. buffer/global/flat_stote
3144                                                               glc=1 slc=1
3145
3146      store        *none*       *none*         - local    1. ds_store
3147      **Unordered Atomic**
3148      -----------------------------------------------------------------------------------
3149      load atomic  unordered    *any*          *any*      *Same as non-atomic*.
3150      store atomic unordered    *any*          *any*      *Same as non-atomic*.
3151      atomicrmw    unordered    *any*          *any*      *Same as monotonic
3152                                                          atomic*.
3153      **Monotonic Atomic**
3154      -----------------------------------------------------------------------------------
3155      load atomic  monotonic    - singlethread - global   1. buffer/global/flat_load
3156                                - wavefront    - generic
3157                                - workgroup
3158      load atomic  monotonic    - singlethread - local    1. ds_load
3159                                - wavefront
3160                                - workgroup
3161      load atomic  monotonic    - agent        - global   1. buffer/global/flat_load
3162                                - system       - generic     glc=1
3163      store atomic monotonic    - singlethread - global   1. buffer/global/flat_store
3164                                - wavefront    - generic
3165                                - workgroup
3166                                - agent
3167                                - system
3168      store atomic monotonic    - singlethread - local    1. ds_store
3169                                - wavefront
3170                                - workgroup
3171      atomicrmw    monotonic    - singlethread - global   1. buffer/global/flat_atomic
3172                                - wavefront    - generic
3173                                - workgroup
3174                                - agent
3175                                - system
3176      atomicrmw    monotonic    - singlethread - local    1. ds_atomic
3177                                - wavefront
3178                                - workgroup
3179      **Acquire Atomic**
3180      -----------------------------------------------------------------------------------
3181      load atomic  acquire      - singlethread - global   1. buffer/global/ds/flat_load
3182                                - wavefront    - local
3183                                               - generic
3184      load atomic  acquire      - workgroup    - global   1. buffer/global/flat_load
3185      load atomic  acquire      - workgroup    - local    1. ds_load
3186                                                          2. s_waitcnt lgkmcnt(0)
3187
3188                                                            - If OpenCL, omit.
3189                                                            - Must happen before
3190                                                              any following
3191                                                              global/generic
3192                                                              load/load
3193                                                              atomic/store/store
3194                                                              atomic/atomicrmw.
3195                                                            - Ensures any
3196                                                              following global
3197                                                              data read is no
3198                                                              older than the load
3199                                                              atomic value being
3200                                                              acquired.
3201      load atomic  acquire      - workgroup    - generic  1. flat_load
3202                                                          2. s_waitcnt lgkmcnt(0)
3203
3204                                                            - If OpenCL, omit.
3205                                                            - Must happen before
3206                                                              any following
3207                                                              global/generic
3208                                                              load/load
3209                                                              atomic/store/store
3210                                                              atomic/atomicrmw.
3211                                                            - Ensures any
3212                                                              following global
3213                                                              data read is no
3214                                                              older than the load
3215                                                              atomic value being
3216                                                              acquired.
3217      load atomic  acquire      - agent        - global   1. buffer/global/flat_load
3218                                - system                     glc=1
3219                                                          2. s_waitcnt vmcnt(0)
3220
3221                                                            - Must happen before
3222                                                              following
3223                                                              buffer_wbinvl1_vol.
3224                                                            - Ensures the load
3225                                                              has completed
3226                                                              before invalidating
3227                                                              the cache.
3228
3229                                                          3. buffer_wbinvl1_vol
3230
3231                                                            - Must happen before
3232                                                              any following
3233                                                              global/generic
3234                                                              load/load
3235                                                              atomic/atomicrmw.
3236                                                            - Ensures that
3237                                                              following
3238                                                              loads will not see
3239                                                              stale global data.
3240
3241      load atomic  acquire      - agent        - generic  1. flat_load glc=1
3242                                - system                  2. s_waitcnt vmcnt(0) &
3243                                                             lgkmcnt(0)
3244
3245                                                            - If OpenCL omit
3246                                                              lgkmcnt(0).
3247                                                            - Must happen before
3248                                                              following
3249                                                              buffer_wbinvl1_vol.
3250                                                            - Ensures the flat_load
3251                                                              has completed
3252                                                              before invalidating
3253                                                              the cache.
3254
3255                                                          3. buffer_wbinvl1_vol
3256
3257                                                            - Must happen before
3258                                                              any following
3259                                                              global/generic
3260                                                              load/load
3261                                                              atomic/atomicrmw.
3262                                                            - Ensures that
3263                                                              following loads
3264                                                              will not see stale
3265                                                              global data.
3266
3267      atomicrmw    acquire      - singlethread - global   1. buffer/global/ds/flat_atomic
3268                                - wavefront    - local
3269                                               - generic
3270      atomicrmw    acquire      - workgroup    - global   1. buffer/global/flat_atomic
3271      atomicrmw    acquire      - workgroup    - local    1. ds_atomic
3272                                                          2. waitcnt lgkmcnt(0)
3273
3274                                                            - If OpenCL, omit.
3275                                                            - Must happen before
3276                                                              any following
3277                                                              global/generic
3278                                                              load/load
3279                                                              atomic/store/store
3280                                                              atomic/atomicrmw.
3281                                                            - Ensures any
3282                                                              following global
3283                                                              data read is no
3284                                                              older than the
3285                                                              atomicrmw value
3286                                                              being acquired.
3287
3288      atomicrmw    acquire      - workgroup    - generic  1. flat_atomic
3289                                                          2. waitcnt lgkmcnt(0)
3290
3291                                                            - If OpenCL, omit.
3292                                                            - Must happen before
3293                                                              any following
3294                                                              global/generic
3295                                                              load/load
3296                                                              atomic/store/store
3297                                                              atomic/atomicrmw.
3298                                                            - Ensures any
3299                                                              following global
3300                                                              data read is no
3301                                                              older than the
3302                                                              atomicrmw value
3303                                                              being acquired.
3304
3305      atomicrmw    acquire      - agent        - global   1. buffer/global/flat_atomic
3306                                - system                  2. s_waitcnt vmcnt(0)
3307
3308                                                            - Must happen before
3309                                                              following
3310                                                              buffer_wbinvl1_vol.
3311                                                            - Ensures the
3312                                                              atomicrmw has
3313                                                              completed before
3314                                                              invalidating the
3315                                                              cache.
3316
3317                                                          3. buffer_wbinvl1_vol
3318
3319                                                            - Must happen before
3320                                                              any following
3321                                                              global/generic
3322                                                              load/load
3323                                                              atomic/atomicrmw.
3324                                                            - Ensures that
3325                                                              following loads
3326                                                              will not see stale
3327                                                              global data.
3328
3329      atomicrmw    acquire      - agent        - generic  1. flat_atomic
3330                                - system                  2. s_waitcnt vmcnt(0) &
3331                                                             lgkmcnt(0)
3332
3333                                                            - If OpenCL, omit
3334                                                              lgkmcnt(0).
3335                                                            - Must happen before
3336                                                              following
3337                                                              buffer_wbinvl1_vol.
3338                                                            - Ensures the
3339                                                              atomicrmw has
3340                                                              completed before
3341                                                              invalidating the
3342                                                              cache.
3343
3344                                                          3. buffer_wbinvl1_vol
3345
3346                                                            - Must happen before
3347                                                              any following
3348                                                              global/generic
3349                                                              load/load
3350                                                              atomic/atomicrmw.
3351                                                            - Ensures that
3352                                                              following loads
3353                                                              will not see stale
3354                                                              global data.
3355
3356      fence        acquire      - singlethread *none*     *none*
3357                                - wavefront
3358      fence        acquire      - workgroup    *none*     1. s_waitcnt lgkmcnt(0)
3359
3360                                                            - If OpenCL and
3361                                                              address space is
3362                                                              not generic, omit.
3363                                                            - However, since LLVM
3364                                                              currently has no
3365                                                              address space on
3366                                                              the fence need to
3367                                                              conservatively
3368                                                              always generate. If
3369                                                              fence had an
3370                                                              address space then
3371                                                              set to address
3372                                                              space of OpenCL
3373                                                              fence flag, or to
3374                                                              generic if both
3375                                                              local and global
3376                                                              flags are
3377                                                              specified.
3378                                                            - Must happen after
3379                                                              any preceding
3380                                                              local/generic load
3381                                                              atomic/atomicrmw
3382                                                              with an equal or
3383                                                              wider sync scope
3384                                                              and memory ordering
3385                                                              stronger than
3386                                                              unordered (this is
3387                                                              termed the
3388                                                              fence-paired-atomic).
3389                                                            - Must happen before
3390                                                              any following
3391                                                              global/generic
3392                                                              load/load
3393                                                              atomic/store/store
3394                                                              atomic/atomicrmw.
3395                                                            - Ensures any
3396                                                              following global
3397                                                              data read is no
3398                                                              older than the
3399                                                              value read by the
3400                                                              fence-paired-atomic.
3401
3402      fence        acquire      - agent        *none*     1. s_waitcnt lgkmcnt(0) &
3403                                - system                     vmcnt(0)
3404
3405                                                            - If OpenCL and
3406                                                              address space is
3407                                                              not generic, omit
3408                                                              lgkmcnt(0).
3409                                                            - However, since LLVM
3410                                                              currently has no
3411                                                              address space on
3412                                                              the fence need to
3413                                                              conservatively
3414                                                              always generate
3415                                                              (see comment for
3416                                                              previous fence).
3417                                                            - Could be split into
3418                                                              separate s_waitcnt
3419                                                              vmcnt(0) and
3420                                                              s_waitcnt
3421                                                              lgkmcnt(0) to allow
3422                                                              them to be
3423                                                              independently moved
3424                                                              according to the
3425                                                              following rules.
3426                                                            - s_waitcnt vmcnt(0)
3427                                                              must happen after
3428                                                              any preceding
3429                                                              global/generic load
3430                                                              atomic/atomicrmw
3431                                                              with an equal or
3432                                                              wider sync scope
3433                                                              and memory ordering
3434                                                              stronger than
3435                                                              unordered (this is
3436                                                              termed the
3437                                                              fence-paired-atomic).
3438                                                            - s_waitcnt lgkmcnt(0)
3439                                                              must happen after
3440                                                              any preceding
3441                                                              local/generic load
3442                                                              atomic/atomicrmw
3443                                                              with an equal or
3444                                                              wider sync scope
3445                                                              and memory ordering
3446                                                              stronger than
3447                                                              unordered (this is
3448                                                              termed the
3449                                                              fence-paired-atomic).
3450                                                            - Must happen before
3451                                                              the following
3452                                                              buffer_wbinvl1_vol.
3453                                                            - Ensures that the
3454                                                              fence-paired atomic
3455                                                              has completed
3456                                                              before invalidating
3457                                                              the
3458                                                              cache. Therefore
3459                                                              any following
3460                                                              locations read must
3461                                                              be no older than
3462                                                              the value read by
3463                                                              the
3464                                                              fence-paired-atomic.
3465
3466                                                          2. buffer_wbinvl1_vol
3467
3468                                                            - Must happen before any
3469                                                              following global/generic
3470                                                              load/load
3471                                                              atomic/store/store
3472                                                              atomic/atomicrmw.
3473                                                            - Ensures that
3474                                                              following loads
3475                                                              will not see stale
3476                                                              global data.
3477
3478      **Release Atomic**
3479      -----------------------------------------------------------------------------------
3480      store atomic release      - singlethread - global   1. buffer/global/ds/flat_store
3481                                - wavefront    - local
3482                                               - generic
3483      store atomic release      - workgroup    - global   1. s_waitcnt lgkmcnt(0)
3484
3485                                                            - If OpenCL, omit.
3486                                                            - Must happen after
3487                                                              any preceding
3488                                                              local/generic
3489                                                              load/store/load
3490                                                              atomic/store
3491                                                              atomic/atomicrmw.
3492                                                            - Must happen before
3493                                                              the following
3494                                                              store.
3495                                                            - Ensures that all
3496                                                              memory operations
3497                                                              to local have
3498                                                              completed before
3499                                                              performing the
3500                                                              store that is being
3501                                                              released.
3502
3503                                                          2. buffer/global/flat_store
3504      store atomic release      - workgroup    - local    1. ds_store
3505      store atomic release      - workgroup    - generic  1. s_waitcnt lgkmcnt(0)
3506
3507                                                            - If OpenCL, omit.
3508                                                            - Must happen after
3509                                                              any preceding
3510                                                              local/generic
3511                                                              load/store/load
3512                                                              atomic/store
3513                                                              atomic/atomicrmw.
3514                                                            - Must happen before
3515                                                              the following
3516                                                              store.
3517                                                            - Ensures that all
3518                                                              memory operations
3519                                                              to local have
3520                                                              completed before
3521                                                              performing the
3522                                                              store that is being
3523                                                              released.
3524
3525                                                          2. flat_store
3526      store atomic release      - agent        - global   1. s_waitcnt lgkmcnt(0) &
3527                                - system       - generic     vmcnt(0)
3528
3529                                                            - If OpenCL, omit
3530                                                              lgkmcnt(0).
3531                                                            - Could be split into
3532                                                              separate s_waitcnt
3533                                                              vmcnt(0) and
3534                                                              s_waitcnt
3535                                                              lgkmcnt(0) to allow
3536                                                              them to be
3537                                                              independently moved
3538                                                              according to the
3539                                                              following rules.
3540                                                            - s_waitcnt vmcnt(0)
3541                                                              must happen after
3542                                                              any preceding
3543                                                              global/generic
3544                                                              load/store/load
3545                                                              atomic/store
3546                                                              atomic/atomicrmw.
3547                                                            - s_waitcnt lgkmcnt(0)
3548                                                              must happen after
3549                                                              any preceding
3550                                                              local/generic
3551                                                              load/store/load
3552                                                              atomic/store
3553                                                              atomic/atomicrmw.
3554                                                            - Must happen before
3555                                                              the following
3556                                                              store.
3557                                                            - Ensures that all
3558                                                              memory operations
3559                                                              to memory have
3560                                                              completed before
3561                                                              performing the
3562                                                              store that is being
3563                                                              released.
3564
3565                                                          2. buffer/global/ds/flat_store
3566      atomicrmw    release      - singlethread - global   1. buffer/global/ds/flat_atomic
3567                                - wavefront    - local
3568                                               - generic
3569      atomicrmw    release      - workgroup    - global   1. s_waitcnt lgkmcnt(0)
3570
3571                                                            - If OpenCL, omit.
3572                                                            - Must happen after
3573                                                              any preceding
3574                                                              local/generic
3575                                                              load/store/load
3576                                                              atomic/store
3577                                                              atomic/atomicrmw.
3578                                                            - Must happen before
3579                                                              the following
3580                                                              atomicrmw.
3581                                                            - Ensures that all
3582                                                              memory operations
3583                                                              to local have
3584                                                              completed before
3585                                                              performing the
3586                                                              atomicrmw that is
3587                                                              being released.
3588
3589                                                          2. buffer/global/flat_atomic
3590      atomicrmw    release      - workgroup    - local    1. ds_atomic
3591      atomicrmw    release      - workgroup    - generic  1. s_waitcnt lgkmcnt(0)
3592
3593                                                            - If OpenCL, omit.
3594                                                            - Must happen after
3595                                                              any preceding
3596                                                              local/generic
3597                                                              load/store/load
3598                                                              atomic/store
3599                                                              atomic/atomicrmw.
3600                                                            - Must happen before
3601                                                              the following
3602                                                              atomicrmw.
3603                                                            - Ensures that all
3604                                                              memory operations
3605                                                              to local have
3606                                                              completed before
3607                                                              performing the
3608                                                              atomicrmw that is
3609                                                              being released.
3610
3611                                                          2. flat_atomic
3612      atomicrmw    release      - agent        - global   1. s_waitcnt lgkmcnt(0) &
3613                                - system       - generic     vmcnt(0)
3614
3615                                                            - If OpenCL, omit
3616                                                              lgkmcnt(0).
3617                                                            - Could be split into
3618                                                              separate s_waitcnt
3619                                                              vmcnt(0) and
3620                                                              s_waitcnt
3621                                                              lgkmcnt(0) to allow
3622                                                              them to be
3623                                                              independently moved
3624                                                              according to the
3625                                                              following rules.
3626                                                            - s_waitcnt vmcnt(0)
3627                                                              must happen after
3628                                                              any preceding
3629                                                              global/generic
3630                                                              load/store/load
3631                                                              atomic/store
3632                                                              atomic/atomicrmw.
3633                                                            - s_waitcnt lgkmcnt(0)
3634                                                              must happen after
3635                                                              any preceding
3636                                                              local/generic
3637                                                              load/store/load
3638                                                              atomic/store
3639                                                              atomic/atomicrmw.
3640                                                            - Must happen before
3641                                                              the following
3642                                                              atomicrmw.
3643                                                            - Ensures that all
3644                                                              memory operations
3645                                                              to global and local
3646                                                              have completed
3647                                                              before performing
3648                                                              the atomicrmw that
3649                                                              is being released.
3650
3651                                                          2. buffer/global/ds/flat_atomic
3652      fence        release      - singlethread *none*     *none*
3653                                - wavefront
3654      fence        release      - workgroup    *none*     1. s_waitcnt lgkmcnt(0)
3655
3656                                                            - If OpenCL and
3657                                                              address space is
3658                                                              not generic, omit.
3659                                                            - However, since LLVM
3660                                                              currently has no
3661                                                              address space on
3662                                                              the fence need to
3663                                                              conservatively
3664                                                              always generate. If
3665                                                              fence had an
3666                                                              address space then
3667                                                              set to address
3668                                                              space of OpenCL
3669                                                              fence flag, or to
3670                                                              generic if both
3671                                                              local and global
3672                                                              flags are
3673                                                              specified.
3674                                                            - Must happen after
3675                                                              any preceding
3676                                                              local/generic
3677                                                              load/load
3678                                                              atomic/store/store
3679                                                              atomic/atomicrmw.
3680                                                            - Must happen before
3681                                                              any following store
3682                                                              atomic/atomicrmw
3683                                                              with an equal or
3684                                                              wider sync scope
3685                                                              and memory ordering
3686                                                              stronger than
3687                                                              unordered (this is
3688                                                              termed the
3689                                                              fence-paired-atomic).
3690                                                            - Ensures that all
3691                                                              memory operations
3692                                                              to local have
3693                                                              completed before
3694                                                              performing the
3695                                                              following
3696                                                              fence-paired-atomic.
3697
3698      fence        release      - agent        *none*     1. s_waitcnt lgkmcnt(0) &
3699                                - system                     vmcnt(0)
3700
3701                                                            - If OpenCL and
3702                                                              address space is
3703                                                              not generic, omit
3704                                                              lgkmcnt(0).
3705                                                            - If OpenCL and
3706                                                              address space is
3707                                                              local, omit
3708                                                              vmcnt(0).
3709                                                            - However, since LLVM
3710                                                              currently has no
3711                                                              address space on
3712                                                              the fence need to
3713                                                              conservatively
3714                                                              always generate. If
3715                                                              fence had an
3716                                                              address space then
3717                                                              set to address
3718                                                              space of OpenCL
3719                                                              fence flag, or to
3720                                                              generic if both
3721                                                              local and global
3722                                                              flags are
3723                                                              specified.
3724                                                            - Could be split into
3725                                                              separate s_waitcnt
3726                                                              vmcnt(0) and
3727                                                              s_waitcnt
3728                                                              lgkmcnt(0) to allow
3729                                                              them to be
3730                                                              independently moved
3731                                                              according to the
3732                                                              following rules.
3733                                                            - s_waitcnt vmcnt(0)
3734                                                              must happen after
3735                                                              any preceding
3736                                                              global/generic
3737                                                              load/store/load
3738                                                              atomic/store
3739                                                              atomic/atomicrmw.
3740                                                            - s_waitcnt lgkmcnt(0)
3741                                                              must happen after
3742                                                              any preceding
3743                                                              local/generic
3744                                                              load/store/load
3745                                                              atomic/store
3746                                                              atomic/atomicrmw.
3747                                                            - Must happen before
3748                                                              any following store
3749                                                              atomic/atomicrmw
3750                                                              with an equal or
3751                                                              wider sync scope
3752                                                              and memory ordering
3753                                                              stronger than
3754                                                              unordered (this is
3755                                                              termed the
3756                                                              fence-paired-atomic).
3757                                                            - Ensures that all
3758                                                              memory operations
3759                                                              have
3760                                                              completed before
3761                                                              performing the
3762                                                              following
3763                                                              fence-paired-atomic.
3764
3765      **Acquire-Release Atomic**
3766      -----------------------------------------------------------------------------------
3767      atomicrmw    acq_rel      - singlethread - global   1. buffer/global/ds/flat_atomic
3768                                - wavefront    - local
3769                                               - generic
3770      atomicrmw    acq_rel      - workgroup    - global   1. s_waitcnt lgkmcnt(0)
3771
3772                                                            - If OpenCL, omit.
3773                                                            - Must happen after
3774                                                              any preceding
3775                                                              local/generic
3776                                                              load/store/load
3777                                                              atomic/store
3778                                                              atomic/atomicrmw.
3779                                                            - Must happen before
3780                                                              the following
3781                                                              atomicrmw.
3782                                                            - Ensures that all
3783                                                              memory operations
3784                                                              to local have
3785                                                              completed before
3786                                                              performing the
3787                                                              atomicrmw that is
3788                                                              being released.
3789
3790                                                          2. buffer/global/flat_atomic
3791      atomicrmw    acq_rel      - workgroup    - local    1. ds_atomic
3792                                                          2. s_waitcnt lgkmcnt(0)
3793
3794                                                            - If OpenCL, omit.
3795                                                            - Must happen before
3796                                                              any following
3797                                                              global/generic
3798                                                              load/load
3799                                                              atomic/store/store
3800                                                              atomic/atomicrmw.
3801                                                            - Ensures any
3802                                                              following global
3803                                                              data read is no
3804                                                              older than the load
3805                                                              atomic value being
3806                                                              acquired.
3807
3808      atomicrmw    acq_rel      - workgroup    - generic  1. s_waitcnt lgkmcnt(0)
3809
3810                                                            - If OpenCL, omit.
3811                                                            - Must happen after
3812                                                              any preceding
3813                                                              local/generic
3814                                                              load/store/load
3815                                                              atomic/store
3816                                                              atomic/atomicrmw.
3817                                                            - Must happen before
3818                                                              the following
3819                                                              atomicrmw.
3820                                                            - Ensures that all
3821                                                              memory operations
3822                                                              to local have
3823                                                              completed before
3824                                                              performing the
3825                                                              atomicrmw that is
3826                                                              being released.
3827
3828                                                          2. flat_atomic
3829                                                          3. s_waitcnt lgkmcnt(0)
3830
3831                                                            - If OpenCL, omit.
3832                                                            - Must happen before
3833                                                              any following
3834                                                              global/generic
3835                                                              load/load
3836                                                              atomic/store/store
3837                                                              atomic/atomicrmw.
3838                                                            - Ensures any
3839                                                              following global
3840                                                              data read is no
3841                                                              older than the load
3842                                                              atomic value being
3843                                                              acquired.
3844
3845      atomicrmw    acq_rel      - agent        - global   1. s_waitcnt lgkmcnt(0) &
3846                                - system                     vmcnt(0)
3847
3848                                                            - If OpenCL, omit
3849                                                              lgkmcnt(0).
3850                                                            - Could be split into
3851                                                              separate s_waitcnt
3852                                                              vmcnt(0) and
3853                                                              s_waitcnt
3854                                                              lgkmcnt(0) to allow
3855                                                              them to be
3856                                                              independently moved
3857                                                              according to the
3858                                                              following rules.
3859                                                            - s_waitcnt vmcnt(0)
3860                                                              must happen after
3861                                                              any preceding
3862                                                              global/generic
3863                                                              load/store/load
3864                                                              atomic/store
3865                                                              atomic/atomicrmw.
3866                                                            - s_waitcnt lgkmcnt(0)
3867                                                              must happen after
3868                                                              any preceding
3869                                                              local/generic
3870                                                              load/store/load
3871                                                              atomic/store
3872                                                              atomic/atomicrmw.
3873                                                            - Must happen before
3874                                                              the following
3875                                                              atomicrmw.
3876                                                            - Ensures that all
3877                                                              memory operations
3878                                                              to global have
3879                                                              completed before
3880                                                              performing the
3881                                                              atomicrmw that is
3882                                                              being released.
3883
3884                                                          2. buffer/global/flat_atomic
3885                                                          3. s_waitcnt vmcnt(0)
3886
3887                                                            - Must happen before
3888                                                              following
3889                                                              buffer_wbinvl1_vol.
3890                                                            - Ensures the
3891                                                              atomicrmw has
3892                                                              completed before
3893                                                              invalidating the
3894                                                              cache.
3895
3896                                                          4. buffer_wbinvl1_vol
3897
3898                                                            - Must happen before
3899                                                              any following
3900                                                              global/generic
3901                                                              load/load
3902                                                              atomic/atomicrmw.
3903                                                            - Ensures that
3904                                                              following loads
3905                                                              will not see stale
3906                                                              global data.
3907
3908      atomicrmw    acq_rel      - agent        - generic  1. s_waitcnt lgkmcnt(0) &
3909                                - system                     vmcnt(0)
3910
3911                                                            - If OpenCL, omit
3912                                                              lgkmcnt(0).
3913                                                            - Could be split into
3914                                                              separate s_waitcnt
3915                                                              vmcnt(0) and
3916                                                              s_waitcnt
3917                                                              lgkmcnt(0) to allow
3918                                                              them to be
3919                                                              independently moved
3920                                                              according to the
3921                                                              following rules.
3922                                                            - s_waitcnt vmcnt(0)
3923                                                              must happen after
3924                                                              any preceding
3925                                                              global/generic
3926                                                              load/store/load
3927                                                              atomic/store
3928                                                              atomic/atomicrmw.
3929                                                            - s_waitcnt lgkmcnt(0)
3930                                                              must happen after
3931                                                              any preceding
3932                                                              local/generic
3933                                                              load/store/load
3934                                                              atomic/store
3935                                                              atomic/atomicrmw.
3936                                                            - Must happen before
3937                                                              the following
3938                                                              atomicrmw.
3939                                                            - Ensures that all
3940                                                              memory operations
3941                                                              to global have
3942                                                              completed before
3943                                                              performing the
3944                                                              atomicrmw that is
3945                                                              being released.
3946
3947                                                          2. flat_atomic
3948                                                          3. s_waitcnt vmcnt(0) &
3949                                                             lgkmcnt(0)
3950
3951                                                            - If OpenCL, omit
3952                                                              lgkmcnt(0).
3953                                                            - Must happen before
3954                                                              following
3955                                                              buffer_wbinvl1_vol.
3956                                                            - Ensures the
3957                                                              atomicrmw has
3958                                                              completed before
3959                                                              invalidating the
3960                                                              cache.
3961
3962                                                          4. buffer_wbinvl1_vol
3963
3964                                                            - Must happen before
3965                                                              any following
3966                                                              global/generic
3967                                                              load/load
3968                                                              atomic/atomicrmw.
3969                                                            - Ensures that
3970                                                              following loads
3971                                                              will not see stale
3972                                                              global data.
3973
3974      fence        acq_rel      - singlethread *none*     *none*
3975                                - wavefront
3976      fence        acq_rel      - workgroup    *none*     1. s_waitcnt lgkmcnt(0)
3977
3978                                                            - If OpenCL and
3979                                                              address space is
3980                                                              not generic, omit.
3981                                                            - However,
3982                                                              since LLVM
3983                                                              currently has no
3984                                                              address space on
3985                                                              the fence need to
3986                                                              conservatively
3987                                                              always generate
3988                                                              (see comment for
3989                                                              previous fence).
3990                                                            - Must happen after
3991                                                              any preceding
3992                                                              local/generic
3993                                                              load/load
3994                                                              atomic/store/store
3995                                                              atomic/atomicrmw.
3996                                                            - Must happen before
3997                                                              any following
3998                                                              global/generic
3999                                                              load/load
4000                                                              atomic/store/store
4001                                                              atomic/atomicrmw.
4002                                                            - Ensures that all
4003                                                              memory operations
4004                                                              to local have
4005                                                              completed before
4006                                                              performing any
4007                                                              following global
4008                                                              memory operations.
4009                                                            - Ensures that the
4010                                                              preceding
4011                                                              local/generic load
4012                                                              atomic/atomicrmw
4013                                                              with an equal or
4014                                                              wider sync scope
4015                                                              and memory ordering
4016                                                              stronger than
4017                                                              unordered (this is
4018                                                              termed the
4019                                                              acquire-fence-paired-atomic
4020                                                              ) has completed
4021                                                              before following
4022                                                              global memory
4023                                                              operations. This
4024                                                              satisfies the
4025                                                              requirements of
4026                                                              acquire.
4027                                                            - Ensures that all
4028                                                              previous memory
4029                                                              operations have
4030                                                              completed before a
4031                                                              following
4032                                                              local/generic store
4033                                                              atomic/atomicrmw
4034                                                              with an equal or
4035                                                              wider sync scope
4036                                                              and memory ordering
4037                                                              stronger than
4038                                                              unordered (this is
4039                                                              termed the
4040                                                              release-fence-paired-atomic
4041                                                              ). This satisfies the
4042                                                              requirements of
4043                                                              release.
4044
4045      fence        acq_rel      - agent        *none*     1. s_waitcnt lgkmcnt(0) &
4046                                - system                     vmcnt(0)
4047
4048                                                            - If OpenCL and
4049                                                              address space is
4050                                                              not generic, omit
4051                                                              lgkmcnt(0).
4052                                                            - However, since LLVM
4053                                                              currently has no
4054                                                              address space on
4055                                                              the fence need to
4056                                                              conservatively
4057                                                              always generate
4058                                                              (see comment for
4059                                                              previous fence).
4060                                                            - Could be split into
4061                                                              separate s_waitcnt
4062                                                              vmcnt(0) and
4063                                                              s_waitcnt
4064                                                              lgkmcnt(0) to allow
4065                                                              them to be
4066                                                              independently moved
4067                                                              according to the
4068                                                              following rules.
4069                                                            - s_waitcnt vmcnt(0)
4070                                                              must happen after
4071                                                              any preceding
4072                                                              global/generic
4073                                                              load/store/load
4074                                                              atomic/store
4075                                                              atomic/atomicrmw.
4076                                                            - s_waitcnt lgkmcnt(0)
4077                                                              must happen after
4078                                                              any preceding
4079                                                              local/generic
4080                                                              load/store/load
4081                                                              atomic/store
4082                                                              atomic/atomicrmw.
4083                                                            - Must happen before
4084                                                              the following
4085                                                              buffer_wbinvl1_vol.
4086                                                            - Ensures that the
4087                                                              preceding
4088                                                              global/local/generic
4089                                                              load
4090                                                              atomic/atomicrmw
4091                                                              with an equal or
4092                                                              wider sync scope
4093                                                              and memory ordering
4094                                                              stronger than
4095                                                              unordered (this is
4096                                                              termed the
4097                                                              acquire-fence-paired-atomic
4098                                                              ) has completed
4099                                                              before invalidating
4100                                                              the cache. This
4101                                                              satisfies the
4102                                                              requirements of
4103                                                              acquire.
4104                                                            - Ensures that all
4105                                                              previous memory
4106                                                              operations have
4107                                                              completed before a
4108                                                              following
4109                                                              global/local/generic
4110                                                              store
4111                                                              atomic/atomicrmw
4112                                                              with an equal or
4113                                                              wider sync scope
4114                                                              and memory ordering
4115                                                              stronger than
4116                                                              unordered (this is
4117                                                              termed the
4118                                                              release-fence-paired-atomic
4119                                                              ). This satisfies the
4120                                                              requirements of
4121                                                              release.
4122
4123                                                          2. buffer_wbinvl1_vol
4124
4125                                                            - Must happen before
4126                                                              any following
4127                                                              global/generic
4128                                                              load/load
4129                                                              atomic/store/store
4130                                                              atomic/atomicrmw.
4131                                                            - Ensures that
4132                                                              following loads
4133                                                              will not see stale
4134                                                              global data. This
4135                                                              satisfies the
4136                                                              requirements of
4137                                                              acquire.
4138
4139      **Sequential Consistent Atomic**
4140      -----------------------------------------------------------------------------------
4141      load atomic  seq_cst      - singlethread - global   *Same as corresponding
4142                                - wavefront    - local    load atomic acquire,
4143                                               - generic  except must generated
4144                                                          all instructions even
4145                                                          for OpenCL.*
4146      load atomic  seq_cst      - workgroup    - global   1. s_waitcnt lgkmcnt(0)
4147                                               - generic
4148                                                            - Must
4149                                                              happen after
4150                                                              preceding
4151                                                              global/generic load
4152                                                              atomic/store
4153                                                              atomic/atomicrmw
4154                                                              with memory
4155                                                              ordering of seq_cst
4156                                                              and with equal or
4157                                                              wider sync scope.
4158                                                              (Note that seq_cst
4159                                                              fences have their
4160                                                              own s_waitcnt
4161                                                              lgkmcnt(0) and so do
4162                                                              not need to be
4163                                                              considered.)
4164                                                            - Ensures any
4165                                                              preceding
4166                                                              sequential
4167                                                              consistent local
4168                                                              memory instructions
4169                                                              have completed
4170                                                              before executing
4171                                                              this sequentially
4172                                                              consistent
4173                                                              instruction. This
4174                                                              prevents reordering
4175                                                              a seq_cst store
4176                                                              followed by a
4177                                                              seq_cst load. (Note
4178                                                              that seq_cst is
4179                                                              stronger than
4180                                                              acquire/release as
4181                                                              the reordering of
4182                                                              load acquire
4183                                                              followed by a store
4184                                                              release is
4185                                                              prevented by the
4186                                                              waitcnt of
4187                                                              the release, but
4188                                                              there is nothing
4189                                                              preventing a store
4190                                                              release followed by
4191                                                              load acquire from
4192                                                              competing out of
4193                                                              order.)
4194
4195                                                          2. *Following
4196                                                             instructions same as
4197                                                             corresponding load
4198                                                             atomic acquire,
4199                                                             except must generated
4200                                                             all instructions even
4201                                                             for OpenCL.*
4202      load atomic  seq_cst      - workgroup    - local    *Same as corresponding
4203                                                          load atomic acquire,
4204                                                          except must generated
4205                                                          all instructions even
4206                                                          for OpenCL.*
4207      load atomic  seq_cst      - agent        - global   1. s_waitcnt lgkmcnt(0) &
4208                                - system       - generic     vmcnt(0)
4209
4210                                                            - Could be split into
4211                                                              separate s_waitcnt
4212                                                              vmcnt(0)
4213                                                              and s_waitcnt
4214                                                              lgkmcnt(0) to allow
4215                                                              them to be
4216                                                              independently moved
4217                                                              according to the
4218                                                              following rules.
4219                                                            - waitcnt lgkmcnt(0)
4220                                                              must happen after
4221                                                              preceding
4222                                                              global/generic load
4223                                                              atomic/store
4224                                                              atomic/atomicrmw
4225                                                              with memory
4226                                                              ordering of seq_cst
4227                                                              and with equal or
4228                                                              wider sync scope.
4229                                                              (Note that seq_cst
4230                                                              fences have their
4231                                                              own s_waitcnt
4232                                                              lgkmcnt(0) and so do
4233                                                              not need to be
4234                                                              considered.)
4235                                                            - waitcnt vmcnt(0)
4236                                                              must happen after
4237                                                              preceding
4238                                                              global/generic load
4239                                                              atomic/store
4240                                                              atomic/atomicrmw
4241                                                              with memory
4242                                                              ordering of seq_cst
4243                                                              and with equal or
4244                                                              wider sync scope.
4245                                                              (Note that seq_cst
4246                                                              fences have their
4247                                                              own s_waitcnt
4248                                                              vmcnt(0) and so do
4249                                                              not need to be
4250                                                              considered.)
4251                                                            - Ensures any
4252                                                              preceding
4253                                                              sequential
4254                                                              consistent global
4255                                                              memory instructions
4256                                                              have completed
4257                                                              before executing
4258                                                              this sequentially
4259                                                              consistent
4260                                                              instruction. This
4261                                                              prevents reordering
4262                                                              a seq_cst store
4263                                                              followed by a
4264                                                              seq_cst load. (Note
4265                                                              that seq_cst is
4266                                                              stronger than
4267                                                              acquire/release as
4268                                                              the reordering of
4269                                                              load acquire
4270                                                              followed by a store
4271                                                              release is
4272                                                              prevented by the
4273                                                              waitcnt of
4274                                                              the release, but
4275                                                              there is nothing
4276                                                              preventing a store
4277                                                              release followed by
4278                                                              load acquire from
4279                                                              competing out of
4280                                                              order.)
4281
4282                                                          2. *Following
4283                                                             instructions same as
4284                                                             corresponding load
4285                                                             atomic acquire,
4286                                                             except must generated
4287                                                             all instructions even
4288                                                             for OpenCL.*
4289      store atomic seq_cst      - singlethread - global   *Same as corresponding
4290                                - wavefront    - local    store atomic release,
4291                                - workgroup    - generic  except must generated
4292                                                          all instructions even
4293                                                          for OpenCL.*
4294      store atomic seq_cst      - agent        - global   *Same as corresponding
4295                                - system       - generic  store atomic release,
4296                                                          except must generated
4297                                                          all instructions even
4298                                                          for OpenCL.*
4299      atomicrmw    seq_cst      - singlethread - global   *Same as corresponding
4300                                - wavefront    - local    atomicrmw acq_rel,
4301                                - workgroup    - generic  except must generated
4302                                                          all instructions even
4303                                                          for OpenCL.*
4304      atomicrmw    seq_cst      - agent        - global   *Same as corresponding
4305                                - system       - generic  atomicrmw acq_rel,
4306                                                          except must generated
4307                                                          all instructions even
4308                                                          for OpenCL.*
4309      fence        seq_cst      - singlethread *none*     *Same as corresponding
4310                                - wavefront               fence acq_rel,
4311                                - workgroup               except must generated
4312                                - agent                   all instructions even
4313                                - system                  for OpenCL.*
4314      ============ ============ ============== ========== ===============================
4315
4316 The memory order also adds the single thread optimization constrains defined in
4317 table
4318 :ref:`amdgpu-amdhsa-memory-model-single-thread-optimization-constraints-gfx6-gfx9-table`.
4319
4320   .. table:: AMDHSA Memory Model Single Thread Optimization Constraints GFX6-GFX9
4321      :name: amdgpu-amdhsa-memory-model-single-thread-optimization-constraints-gfx6-gfx9-table
4322
4323      ============ ==============================================================
4324      LLVM Memory  Optimization Constraints
4325      Ordering
4326      ============ ==============================================================
4327      unordered    *none*
4328      monotonic    *none*
4329      acquire      - If a load atomic/atomicrmw then no following load/load
4330                     atomic/store/ store atomic/atomicrmw/fence instruction can
4331                     be moved before the acquire.
4332                   - If a fence then same as load atomic, plus no preceding
4333                     associated fence-paired-atomic can be moved after the fence.
4334      release      - If a store atomic/atomicrmw then no preceding load/load
4335                     atomic/store/ store atomic/atomicrmw/fence instruction can
4336                     be moved after the release.
4337                   - If a fence then same as store atomic, plus no following
4338                     associated fence-paired-atomic can be moved before the
4339                     fence.
4340      acq_rel      Same constraints as both acquire and release.
4341      seq_cst      - If a load atomic then same constraints as acquire, plus no
4342                     preceding sequentially consistent load atomic/store
4343                     atomic/atomicrmw/fence instruction can be moved after the
4344                     seq_cst.
4345                   - If a store atomic then the same constraints as release, plus
4346                     no following sequentially consistent load atomic/store
4347                     atomic/atomicrmw/fence instruction can be moved before the
4348                     seq_cst.
4349                   - If an atomicrmw/fence then same constraints as acq_rel.
4350      ============ ==============================================================
4351
4352 Trap Handler ABI
4353 ~~~~~~~~~~~~~~~~
4354
4355 For code objects generated by AMDGPU backend for HSA [HSA]_ compatible runtimes
4356 (such as ROCm [AMD-ROCm]_), the runtime installs a trap handler that supports
4357 the ``s_trap`` instruction with the following usage:
4358
4359   .. table:: AMDGPU Trap Handler for AMDHSA OS
4360      :name: amdgpu-trap-handler-for-amdhsa-os-table
4361
4362      =================== =============== =============== =======================
4363      Usage               Code Sequence   Trap Handler    Description
4364                                          Inputs
4365      =================== =============== =============== =======================
4366      reserved            ``s_trap 0x00``                 Reserved by hardware.
4367      ``debugtrap(arg)``  ``s_trap 0x01`` ``SGPR0-1``:    Reserved for HSA
4368                                            ``queue_ptr`` ``debugtrap``
4369                                          ``VGPR0``:      intrinsic (not
4370                                            ``arg``       implemented).
4371      ``llvm.trap``       ``s_trap 0x02`` ``SGPR0-1``:    Causes dispatch to be
4372                                            ``queue_ptr`` terminated and its
4373                                                          associated queue put
4374                                                          into the error state.
4375      ``llvm.debugtrap``  ``s_trap 0x03``                 - If debugger not
4376                                                            installed then
4377                                                            behaves as a
4378                                                            no-operation. The
4379                                                            trap handler is
4380                                                            entered and
4381                                                            immediately returns
4382                                                            to continue
4383                                                            execution of the
4384                                                            wavefront.
4385                                                          - If the debugger is
4386                                                            installed, causes
4387                                                            the debug trap to be
4388                                                            reported by the
4389                                                            debugger and the
4390                                                            wavefront is put in
4391                                                            the halt state until
4392                                                            resumed by the
4393                                                            debugger.
4394      reserved            ``s_trap 0x04``                 Reserved.
4395      reserved            ``s_trap 0x05``                 Reserved.
4396      reserved            ``s_trap 0x06``                 Reserved.
4397      debugger breakpoint ``s_trap 0x07``                 Reserved for debugger
4398                                                          breakpoints.
4399      reserved            ``s_trap 0x08``                 Reserved.
4400      reserved            ``s_trap 0xfe``                 Reserved.
4401      reserved            ``s_trap 0xff``                 Reserved.
4402      =================== =============== =============== =======================
4403
4404 AMDPAL
4405 ------
4406
4407 This section provides code conventions used when the target triple OS is
4408 ``amdpal`` (see :ref:`amdgpu-target-triples`) for passing runtime parameters
4409 from the application/runtime to each invocation of a hardware shader. These
4410 parameters include both generic, application-controlled parameters called
4411 *user data* as well as system-generated parameters that are a product of the
4412 draw or dispatch execution.
4413
4414 User Data
4415 ~~~~~~~~~
4416
4417 Each hardware stage has a set of 32-bit *user data registers* which can be
4418 written from a command buffer and then loaded into SGPRs when waves are launched
4419 via a subsequent dispatch or draw operation. This is the way most arguments are
4420 passed from the application/runtime to a hardware shader.
4421
4422 Compute User Data
4423 ~~~~~~~~~~~~~~~~~
4424
4425 Compute shader user data mappings are simpler than graphics shaders, and have a
4426 fixed mapping.
4427
4428 Note that there are always 10 available *user data entries* in registers -
4429 entries beyond that limit must be fetched from memory (via the spill table
4430 pointer) by the shader.
4431
4432   .. table:: PAL Compute Shader User Data Registers
4433      :name: pal-compute-user-data-registers
4434
4435      ============= ================================
4436      User Register Description
4437      ============= ================================
4438      0             Global Internal Table (32-bit pointer)
4439      1             Per-Shader Internal Table (32-bit pointer)
4440      2 - 11        Application-Controlled User Data (10 32-bit values)
4441      12            Spill Table (32-bit pointer)
4442      13 - 14       Thread Group Count (64-bit pointer)
4443      15            GDS Range
4444      ============= ================================
4445
4446 Graphics User Data
4447 ~~~~~~~~~~~~~~~~~~
4448
4449 Graphics pipelines support a much more flexible user data mapping:
4450
4451   .. table:: PAL Graphics Shader User Data Registers
4452      :name: pal-graphics-user-data-registers
4453
4454      ============= ================================
4455      User Register Description
4456      ============= ================================
4457      0             Global Internal Table (32-bit pointer)
4458      +             Per-Shader Internal Table (32-bit pointer)
4459      + 1-15        Application Controlled User Data
4460                    (1-15 Contiguous 32-bit Values in Registers)
4461      +             Spill Table (32-bit pointer)
4462      +             Draw Index (First Stage Only)
4463      +             Vertex Offset (First Stage Only)
4464      +             Instance Offset (First Stage Only)
4465      ============= ================================
4466
4467   The placement of the global internal table remains fixed in the first *user
4468   data SGPR register*. Otherwise all parameters are optional, and can be mapped
4469   to any desired *user data SGPR register*, with the following regstrictions:
4470
4471   * Draw Index, Vertex Offset, and Instance Offset can only be used by the first
4472     activehardware stage in a graphics pipeline (i.e. where the API vertex
4473     shader runs).
4474
4475   * Application-controlled user data must be mapped into a contiguous range of
4476     user data registers.
4477
4478   * The application-controlled user data range supports compaction remapping, so
4479     only *entries* that are actually consumed by the shader must be assigned to
4480     corresponding *registers*. Note that in order to support an efficient runtime
4481     implementation, the remapping must pack *registers* in the same order as
4482     *entries*, with unused *entries* removed.
4483
4484 .. _pal_global_internal_table:
4485
4486 Global Internal Table
4487 ~~~~~~~~~~~~~~~~~~~~~
4488
4489 The global internal table is a table of *shader resource descriptors* (SRDs) that
4490 define how certain engine-wide, runtime-managed resources should be accessed
4491 from a shader. The majority of these resources have HW-defined formats, and it
4492 is up to the compiler to write/read data as required by the target hardware.
4493
4494 The following table illustrates the required format:
4495
4496   .. table:: PAL Global Internal Table
4497      :name: pal-git-table
4498
4499      ============= ================================
4500      Offset        Description
4501      ============= ================================
4502      0-3           Graphics Scratch SRD
4503      4-7           Compute Scratch SRD
4504      8-11          ES/GS Ring Output SRD
4505      12-15         ES/GS Ring Input SRD
4506      16-19         GS/VS Ring Output #0
4507      20-23         GS/VS Ring Output #1
4508      24-27         GS/VS Ring Output #2
4509      28-31         GS/VS Ring Output #3
4510      32-35         GS/VS Ring Input SRD
4511      36-39         Tessellation Factor Buffer SRD
4512      40-43         Off-Chip LDS Buffer SRD
4513      44-47         Off-Chip Param Cache Buffer SRD
4514      48-51         Sample Position Buffer SRD
4515      52            vaRange::ShadowDescriptorTable High Bits
4516      ============= ================================
4517
4518   The pointer to the global internal table passed to the shader as user data
4519   is a 32-bit pointer. The top 32 bits should be assumed to be the same as
4520   the top 32 bits of the pipeline, so the shader may use the program
4521   counter's top 32 bits.
4522
4523 Unspecified OS
4524 --------------
4525
4526 This section provides code conventions used when the target triple OS is
4527 empty (see :ref:`amdgpu-target-triples`).
4528
4529 Trap Handler ABI
4530 ~~~~~~~~~~~~~~~~
4531
4532 For code objects generated by AMDGPU backend for non-amdhsa OS, the runtime does
4533 not install a trap handler. The ``llvm.trap`` and ``llvm.debugtrap``
4534 instructions are handled as follows:
4535
4536   .. table:: AMDGPU Trap Handler for Non-AMDHSA OS
4537      :name: amdgpu-trap-handler-for-non-amdhsa-os-table
4538
4539      =============== =============== ===========================================
4540      Usage           Code Sequence   Description
4541      =============== =============== ===========================================
4542      llvm.trap       s_endpgm        Causes wavefront to be terminated.
4543      llvm.debugtrap  *none*          Compiler warning given that there is no
4544                                      trap handler installed.
4545      =============== =============== ===========================================
4546
4547 Source Languages
4548 ================
4549
4550 .. _amdgpu-opencl:
4551
4552 OpenCL
4553 ------
4554
4555 When the language is OpenCL the following differences occur:
4556
4557 1. The OpenCL memory model is used (see :ref:`amdgpu-amdhsa-memory-model`).
4558 2. The AMDGPU backend appends additional arguments to the kernel's explicit
4559    arguments for the AMDHSA OS (see
4560    :ref:`opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table`).
4561 3. Additional metadata is generated
4562    (see :ref:`amdgpu-amdhsa-code-object-metadata`).
4563
4564   .. table:: OpenCL kernel implicit arguments appended for AMDHSA OS
4565      :name: opencl-kernel-implicit-arguments-appended-for-amdhsa-os-table
4566
4567      ======== ==== ========= ===========================================
4568      Position Byte Byte      Description
4569               Size Alignment
4570      ======== ==== ========= ===========================================
4571      1        8    8         OpenCL Global Offset X
4572      2        8    8         OpenCL Global Offset Y
4573      3        8    8         OpenCL Global Offset Z
4574      4        8    8         OpenCL address of printf buffer
4575      5        8    8         OpenCL address of virtual queue used by
4576                              enqueue_kernel.
4577      6        8    8         OpenCL address of AqlWrap struct used by
4578                              enqueue_kernel.
4579      ======== ==== ========= ===========================================
4580
4581 .. _amdgpu-hcc:
4582
4583 HCC
4584 ---
4585
4586 When the language is HCC the following differences occur:
4587
4588 1. The HSA memory model is used (see :ref:`amdgpu-amdhsa-memory-model`).
4589
4590 .. _amdgpu-assembler:
4591
4592 Assembler
4593 ---------
4594
4595 AMDGPU backend has LLVM-MC based assembler which is currently in development.
4596 It supports AMDGCN GFX6-GFX9.
4597
4598 This section describes general syntax for instructions and operands.
4599
4600 Instructions
4601 ~~~~~~~~~~~~
4602
4603 .. toctree::
4604    :hidden:
4605
4606    AMDGPU/AMDGPUAsmGFX7
4607    AMDGPU/AMDGPUAsmGFX8
4608    AMDGPU/AMDGPUAsmGFX9
4609    AMDGPUModifierSyntax
4610    AMDGPUOperandSyntax
4611    AMDGPUInstructionSyntax
4612    AMDGPUInstructionNotation
4613
4614 An instruction has the following :doc:`syntax<AMDGPUInstructionSyntax>`:
4615
4616     ``<``\ *opcode*\ ``>    <``\ *operand0*\ ``>, <``\ *operand1*\ ``>,...    <``\ *modifier0*\ ``> <``\ *modifier1*\ ``>...``
4617
4618 :doc:`Operands<AMDGPUOperandSyntax>` are normally comma-separated while
4619 :doc:`modifiers<AMDGPUModifierSyntax>` are space-separated.
4620
4621 The order of *operands* and *modifiers* is fixed.
4622 Most *modifiers* are optional and may be omitted.
4623
4624 See detailed instruction syntax description for :doc:`GFX7<AMDGPU/AMDGPUAsmGFX7>`,
4625 :doc:`GFX8<AMDGPU/AMDGPUAsmGFX8>` and :doc:`GFX9<AMDGPU/AMDGPUAsmGFX9>`.
4626
4627 Note that features under development are not included in this description.
4628
4629 For more information about instructions, their semantics and supported combinations of
4630 operands, refer to one of instruction set architecture manuals
4631 [AMD-GCN-GFX6]_, [AMD-GCN-GFX7]_, [AMD-GCN-GFX8]_ and [AMD-GCN-GFX9]_.
4632
4633 Operands
4634 ~~~~~~~~
4635
4636 Detailed description of operands may be found :doc:`here<AMDGPUOperandSyntax>`.
4637
4638 Modifiers
4639 ~~~~~~~~~
4640
4641 Detailed description of modifiers may be found :doc:`here<AMDGPUModifierSyntax>`.
4642
4643 Instruction Examples
4644 ~~~~~~~~~~~~~~~~~~~~
4645
4646 DS
4647 ++
4648
4649 .. code-block:: nasm
4650
4651   ds_add_u32 v2, v4 offset:16
4652   ds_write_src2_b64 v2 offset0:4 offset1:8
4653   ds_cmpst_f32 v2, v4, v6
4654   ds_min_rtn_f64 v[8:9], v2, v[4:5]
4655
4656
4657 For full list of supported instructions, refer to "LDS/GDS instructions" in ISA Manual.
4658
4659 FLAT
4660 ++++
4661
4662 .. code-block:: nasm
4663
4664   flat_load_dword v1, v[3:4]
4665   flat_store_dwordx3 v[3:4], v[5:7]
4666   flat_atomic_swap v1, v[3:4], v5 glc
4667   flat_atomic_cmpswap v1, v[3:4], v[5:6] glc slc
4668   flat_atomic_fmax_x2 v[1:2], v[3:4], v[5:6] glc
4669
4670 For full list of supported instructions, refer to "FLAT instructions" in ISA Manual.
4671
4672 MUBUF
4673 +++++
4674
4675 .. code-block:: nasm
4676
4677   buffer_load_dword v1, off, s[4:7], s1
4678   buffer_store_dwordx4 v[1:4], v2, ttmp[4:7], s1 offen offset:4 glc tfe
4679   buffer_store_format_xy v[1:2], off, s[4:7], s1
4680   buffer_wbinvl1
4681   buffer_atomic_inc v1, v2, s[8:11], s4 idxen offset:4 slc
4682
4683 For full list of supported instructions, refer to "MUBUF Instructions" in ISA Manual.
4684
4685 SMRD/SMEM
4686 +++++++++
4687
4688 .. code-block:: nasm
4689
4690   s_load_dword s1, s[2:3], 0xfc
4691   s_load_dwordx8 s[8:15], s[2:3], s4
4692   s_load_dwordx16 s[88:103], s[2:3], s4
4693   s_dcache_inv_vol
4694   s_memtime s[4:5]
4695
4696 For full list of supported instructions, refer to "Scalar Memory Operations" in ISA Manual.
4697
4698 SOP1
4699 ++++
4700
4701 .. code-block:: nasm
4702
4703   s_mov_b32 s1, s2
4704   s_mov_b64 s[0:1], 0x80000000
4705   s_cmov_b32 s1, 200
4706   s_wqm_b64 s[2:3], s[4:5]
4707   s_bcnt0_i32_b64 s1, s[2:3]
4708   s_swappc_b64 s[2:3], s[4:5]
4709   s_cbranch_join s[4:5]
4710
4711 For full list of supported instructions, refer to "SOP1 Instructions" in ISA Manual.
4712
4713 SOP2
4714 ++++
4715
4716 .. code-block:: nasm
4717
4718   s_add_u32 s1, s2, s3
4719   s_and_b64 s[2:3], s[4:5], s[6:7]
4720   s_cselect_b32 s1, s2, s3
4721   s_andn2_b32 s2, s4, s6
4722   s_lshr_b64 s[2:3], s[4:5], s6
4723   s_ashr_i32 s2, s4, s6
4724   s_bfm_b64 s[2:3], s4, s6
4725   s_bfe_i64 s[2:3], s[4:5], s6
4726   s_cbranch_g_fork s[4:5], s[6:7]
4727
4728 For full list of supported instructions, refer to "SOP2 Instructions" in ISA Manual.
4729
4730 SOPC
4731 ++++
4732
4733 .. code-block:: nasm
4734
4735   s_cmp_eq_i32 s1, s2
4736   s_bitcmp1_b32 s1, s2
4737   s_bitcmp0_b64 s[2:3], s4
4738   s_setvskip s3, s5
4739
4740 For full list of supported instructions, refer to "SOPC Instructions" in ISA Manual.
4741
4742 SOPP
4743 ++++
4744
4745 .. code-block:: nasm
4746
4747   s_barrier
4748   s_nop 2
4749   s_endpgm
4750   s_waitcnt 0 ; Wait for all counters to be 0
4751   s_waitcnt vmcnt(0) & expcnt(0) & lgkmcnt(0) ; Equivalent to above
4752   s_waitcnt vmcnt(1) ; Wait for vmcnt counter to be 1.
4753   s_sethalt 9
4754   s_sleep 10
4755   s_sendmsg 0x1
4756   s_sendmsg sendmsg(MSG_INTERRUPT)
4757   s_trap 1
4758
4759 For full list of supported instructions, refer to "SOPP Instructions" in ISA Manual.
4760
4761 Unless otherwise mentioned, little verification is performed on the operands
4762 of SOPP Instructions, so it is up to the programmer to be familiar with the
4763 range or acceptable values.
4764
4765 VALU
4766 ++++
4767
4768 For vector ALU instruction opcodes (VOP1, VOP2, VOP3, VOPC, VOP_DPP, VOP_SDWA),
4769 the assembler will automatically use optimal encoding based on its operands.
4770 To force specific encoding, one can add a suffix to the opcode of the instruction:
4771
4772 * _e32 for 32-bit VOP1/VOP2/VOPC
4773 * _e64 for 64-bit VOP3
4774 * _dpp for VOP_DPP
4775 * _sdwa for VOP_SDWA
4776
4777 VOP1/VOP2/VOP3/VOPC examples:
4778
4779 .. code-block:: nasm
4780
4781   v_mov_b32 v1, v2
4782   v_mov_b32_e32 v1, v2
4783   v_nop
4784   v_cvt_f64_i32_e32 v[1:2], v2
4785   v_floor_f32_e32 v1, v2
4786   v_bfrev_b32_e32 v1, v2
4787   v_add_f32_e32 v1, v2, v3
4788   v_mul_i32_i24_e64 v1, v2, 3
4789   v_mul_i32_i24_e32 v1, -3, v3
4790   v_mul_i32_i24_e32 v1, -100, v3
4791   v_addc_u32 v1, s[0:1], v2, v3, s[2:3]
4792   v_max_f16_e32 v1, v2, v3
4793
4794 VOP_DPP examples:
4795
4796 .. code-block:: nasm
4797
4798   v_mov_b32 v0, v0 quad_perm:[0,2,1,1]
4799   v_sin_f32 v0, v0 row_shl:1 row_mask:0xa bank_mask:0x1 bound_ctrl:0
4800   v_mov_b32 v0, v0 wave_shl:1
4801   v_mov_b32 v0, v0 row_mirror
4802   v_mov_b32 v0, v0 row_bcast:31
4803   v_mov_b32 v0, v0 quad_perm:[1,3,0,1] row_mask:0xa bank_mask:0x1 bound_ctrl:0
4804   v_add_f32 v0, v0, |v0| row_shl:1 row_mask:0xa bank_mask:0x1 bound_ctrl:0
4805   v_max_f16 v1, v2, v3 row_shl:1 row_mask:0xa bank_mask:0x1 bound_ctrl:0
4806
4807 VOP_SDWA examples:
4808
4809 .. code-block:: nasm
4810
4811   v_mov_b32 v1, v2 dst_sel:BYTE_0 dst_unused:UNUSED_PRESERVE src0_sel:DWORD
4812   v_min_u32 v200, v200, v1 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:BYTE_1 src1_sel:DWORD
4813   v_sin_f32 v0, v0 dst_unused:UNUSED_PAD src0_sel:WORD_1
4814   v_fract_f32 v0, |v0| dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1
4815   v_cmpx_le_u32 vcc, v1, v2 src0_sel:BYTE_2 src1_sel:WORD_0
4816
4817 For full list of supported instructions, refer to "Vector ALU instructions".
4818
4819 .. TODO
4820    Remove once we switch to code object v3 by default.
4821
4822 .. _amdgpu-amdhsa-assembler-predefined-symbols-v2:
4823
4824 Code Object V2 Predefined Symbols (-mattr=-code-object-v3)
4825 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4826
4827 .. warning:: Code Object V2 is not the default code object version emitted by
4828   this version of LLVM. For a description of the predefined symbols available
4829   with the default configuration (Code Object V3) see
4830   :ref:`amdgpu-amdhsa-assembler-predefined-symbols-v3`.
4831
4832 The AMDGPU assembler defines and updates some symbols automatically. These
4833 symbols do not affect code generation.
4834
4835 .option.machine_version_major
4836 +++++++++++++++++++++++++++++
4837
4838 Set to the GFX major generation number of the target being assembled for. For
4839 example, when assembling for a "GFX9" target this will be set to the integer
4840 value "9". The possible GFX major generation numbers are presented in
4841 :ref:`amdgpu-processors`.
4842
4843 .option.machine_version_minor
4844 +++++++++++++++++++++++++++++
4845
4846 Set to the GFX minor generation number of the target being assembled for. For
4847 example, when assembling for a "GFX810" target this will be set to the integer
4848 value "1". The possible GFX minor generation numbers are presented in
4849 :ref:`amdgpu-processors`.
4850
4851 .option.machine_version_stepping
4852 ++++++++++++++++++++++++++++++++
4853
4854 Set to the GFX stepping generation number of the target being assembled for.
4855 For example, when assembling for a "GFX704" target this will be set to the
4856 integer value "4". The possible GFX stepping generation numbers are presented
4857 in :ref:`amdgpu-processors`.
4858
4859 .kernel.vgpr_count
4860 ++++++++++++++++++
4861
4862 Set to zero each time a
4863 :ref:`amdgpu-amdhsa-assembler-directive-amdgpu_hsa_kernel` directive is
4864 encountered. At each instruction, if the current value of this symbol is less
4865 than or equal to the maximum VPGR number explicitly referenced within that
4866 instruction then the symbol value is updated to equal that VGPR number plus
4867 one.
4868
4869 .kernel.sgpr_count
4870 ++++++++++++++++++
4871
4872 Set to zero each time a
4873 :ref:`amdgpu-amdhsa-assembler-directive-amdgpu_hsa_kernel` directive is
4874 encountered. At each instruction, if the current value of this symbol is less
4875 than or equal to the maximum VPGR number explicitly referenced within that
4876 instruction then the symbol value is updated to equal that SGPR number plus
4877 one.
4878
4879 .. _amdgpu-amdhsa-assembler-directives-v2:
4880
4881 Code Object V2 Directives (-mattr=-code-object-v3)
4882 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4883
4884 .. warning:: Code Object V2 is not the default code object version emitted by
4885   this version of LLVM. For a description of the directives supported with
4886   the default configuration (Code Object V3) see
4887   :ref:`amdgpu-amdhsa-assembler-directives-v3`.
4888
4889 AMDGPU ABI defines auxiliary data in output code object. In assembly source,
4890 one can specify them with assembler directives.
4891
4892 .hsa_code_object_version major, minor
4893 +++++++++++++++++++++++++++++++++++++
4894
4895 *major* and *minor* are integers that specify the version of the HSA code
4896 object that will be generated by the assembler.
4897
4898 .hsa_code_object_isa [major, minor, stepping, vendor, arch]
4899 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4900
4901
4902 *major*, *minor*, and *stepping* are all integers that describe the instruction
4903 set architecture (ISA) version of the assembly program.
4904
4905 *vendor* and *arch* are quoted strings.  *vendor* should always be equal to
4906 "AMD" and *arch* should always be equal to "AMDGPU".
4907
4908 By default, the assembler will derive the ISA version, *vendor*, and *arch*
4909 from the value of the -mcpu option that is passed to the assembler.
4910
4911 .. _amdgpu-amdhsa-assembler-directive-amdgpu_hsa_kernel:
4912
4913 .amdgpu_hsa_kernel (name)
4914 +++++++++++++++++++++++++
4915
4916 This directives specifies that the symbol with given name is a kernel entry point
4917 (label) and the object should contain corresponding symbol of type STT_AMDGPU_HSA_KERNEL.
4918
4919 .amd_kernel_code_t
4920 ++++++++++++++++++
4921
4922 This directive marks the beginning of a list of key / value pairs that are used
4923 to specify the amd_kernel_code_t object that will be emitted by the assembler.
4924 The list must be terminated by the *.end_amd_kernel_code_t* directive.  For
4925 any amd_kernel_code_t values that are unspecified a default value will be
4926 used.  The default value for all keys is 0, with the following exceptions:
4927
4928 - *kernel_code_version_major* defaults to 1.
4929 - *machine_kind* defaults to 1.
4930 - *machine_version_major*, *machine_version_minor*, and
4931   *machine_version_stepping* are derived from the value of the -mcpu option
4932   that is passed to the assembler.
4933 - *kernel_code_entry_byte_offset* defaults to 256.
4934 - *wavefront_size* defaults to 6.
4935 - *kernarg_segment_alignment*, *group_segment_alignment*, and
4936   *private_segment_alignment* default to 4. Note that alignments are specified
4937   as a power of 2, so a value of **n** means an alignment of 2^ **n**.
4938
4939 The *.amd_kernel_code_t* directive must be placed immediately after the
4940 function label and before any instructions.
4941
4942 For a full list of amd_kernel_code_t keys, refer to AMDGPU ABI document,
4943 comments in lib/Target/AMDGPU/AmdKernelCodeT.h and test/CodeGen/AMDGPU/hsa.s.
4944
4945 .. _amdgpu-amdhsa-assembler-example-v2:
4946
4947 Code Object V2 Example Source Code (-mattr=-code-object-v3)
4948 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4949
4950 .. warning:: Code Object V2 is not the default code object version emitted by
4951   this version of LLVM. For a description of the directives supported with
4952   the default configuration (Code Object V3) see
4953   :ref:`amdgpu-amdhsa-assembler-example-v3`.
4954
4955 Here is an example of a minimal assembly source file, defining one HSA kernel:
4956
4957 .. code-block:: none
4958
4959    .hsa_code_object_version 1,0
4960    .hsa_code_object_isa
4961
4962    .hsatext
4963    .globl  hello_world
4964    .p2align 8
4965    .amdgpu_hsa_kernel hello_world
4966
4967    hello_world:
4968
4969       .amd_kernel_code_t
4970          enable_sgpr_kernarg_segment_ptr = 1
4971          is_ptr64 = 1
4972          compute_pgm_rsrc1_vgprs = 0
4973          compute_pgm_rsrc1_sgprs = 0
4974          compute_pgm_rsrc2_user_sgpr = 2
4975          kernarg_segment_byte_size = 8
4976          wavefront_sgpr_count = 2
4977          workitem_vgpr_count = 3
4978      .end_amd_kernel_code_t
4979
4980      s_load_dwordx2 s[0:1], s[0:1] 0x0
4981      v_mov_b32 v0, 3.14159
4982      s_waitcnt lgkmcnt(0)
4983      v_mov_b32 v1, s0
4984      v_mov_b32 v2, s1
4985      flat_store_dword v[1:2], v0
4986      s_endpgm
4987    .Lfunc_end0:
4988         .size   hello_world, .Lfunc_end0-hello_world
4989
4990 .. _amdgpu-amdhsa-assembler-predefined-symbols-v3:
4991
4992 Code Object V3 Predefined Symbols (-mattr=+code-object-v3)
4993 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4994
4995 The AMDGPU assembler defines and updates some symbols automatically. These
4996 symbols do not affect code generation.
4997
4998 .amdgcn.gfx_generation_number
4999 +++++++++++++++++++++++++++++
5000
5001 Set to the GFX major generation number of the target being assembled for. For
5002 example, when assembling for a "GFX9" target this will be set to the integer
5003 value "9". The possible GFX major generation numbers are presented in
5004 :ref:`amdgpu-processors`.
5005
5006 .amdgcn.gfx_generation_minor
5007 ++++++++++++++++++++++++++++
5008
5009 Set to the GFX minor generation number of the target being assembled for. For
5010 example, when assembling for a "GFX810" target this will be set to the integer
5011 value "1". The possible GFX minor generation numbers are presented in
5012 :ref:`amdgpu-processors`.
5013
5014 .amdgcn.gfx_generation_stepping
5015 +++++++++++++++++++++++++++++++
5016
5017 Set to the GFX stepping generation number of the target being assembled for.
5018 For example, when assembling for a "GFX704" target this will be set to the
5019 integer value "4". The possible GFX stepping generation numbers are presented
5020 in :ref:`amdgpu-processors`.
5021
5022 .amdgcn.next_free_vgpr
5023 ++++++++++++++++++++++
5024
5025 Set to zero before assembly begins. At each instruction, if the current value
5026 of this symbol is less than or equal to the maximum VGPR number explicitly
5027 referenced within that instruction then the symbol value is updated to equal
5028 that VGPR number plus one.
5029
5030 May be used to set the `.amdhsa_next_free_vpgr` directive in
5031 :ref:`amdhsa-kernel-directives-table`.
5032
5033 May be set at any time, e.g. manually set to zero at the start of each kernel.
5034
5035 .amdgcn.next_free_sgpr
5036 ++++++++++++++++++++++
5037
5038 Set to zero before assembly begins. At each instruction, if the current value
5039 of this symbol is less than or equal the maximum SGPR number explicitly
5040 referenced within that instruction then the symbol value is updated to equal
5041 that SGPR number plus one.
5042
5043 May be used to set the `.amdhsa_next_free_spgr` directive in
5044 :ref:`amdhsa-kernel-directives-table`.
5045
5046 May be set at any time, e.g. manually set to zero at the start of each kernel.
5047
5048 .. _amdgpu-amdhsa-assembler-directives-v3:
5049
5050 Code Object V3 Directives (-mattr=+code-object-v3)
5051 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5052
5053 Directives which begin with ``.amdgcn`` are valid for all ``amdgcn``
5054 architecture processors, and are not OS-specific. Directives which begin with
5055 ``.amdhsa`` are specific to ``amdgcn`` architecture processors when the
5056 ``amdhsa`` OS is specified. See :ref:`amdgpu-target-triples` and
5057 :ref:`amdgpu-processors`.
5058
5059 .amdgcn_target <target>
5060 +++++++++++++++++++++++
5061
5062 Optional directive which declares the target supported by the containing
5063 assembler source file. Valid values are described in
5064 :ref:`amdgpu-amdhsa-code-object-target-identification`. Used by the assembler
5065 to validate command-line options such as ``-triple``, ``-mcpu``, and those
5066 which specify target features.
5067
5068 .amdhsa_kernel <name>
5069 +++++++++++++++++++++
5070
5071 Creates a correctly aligned AMDHSA kernel descriptor and a symbol,
5072 ``<name>.kd``, in the current location of the current section. Only valid when
5073 the OS is ``amdhsa``. ``<name>`` must be a symbol that labels the first
5074 instruction to execute, and does not need to be previously defined.
5075
5076 Marks the beginning of a list of directives used to generate the bytes of a
5077 kernel descriptor, as described in :ref:`amdgpu-amdhsa-kernel-descriptor`.
5078 Directives which may appear in this list are described in
5079 :ref:`amdhsa-kernel-directives-table`. Directives may appear in any order, must
5080 be valid for the target being assembled for, and cannot be repeated. Directives
5081 support the range of values specified by the field they reference in
5082 :ref:`amdgpu-amdhsa-kernel-descriptor`. If a directive is not specified, it is
5083 assumed to have its default value, unless it is marked as "Required", in which
5084 case it is an error to omit the directive. This list of directives is
5085 terminated by an ``.end_amdhsa_kernel`` directive.
5086
5087   .. table:: AMDHSA Kernel Assembler Directives
5088      :name: amdhsa-kernel-directives-table
5089
5090      ======================================================== ================ ============ ===================
5091      Directive                                                Default          Supported On Description
5092      ======================================================== ================ ============ ===================
5093      ``.amdhsa_group_segment_fixed_size``                     0                GFX6-GFX9    Controls GROUP_SEGMENT_FIXED_SIZE in
5094                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5095      ``.amdhsa_private_segment_fixed_size``                   0                GFX6-GFX9    Controls PRIVATE_SEGMENT_FIXED_SIZE in
5096                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5097      ``.amdhsa_user_sgpr_private_segment_buffer``             0                GFX6-GFX9    Controls ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER in
5098                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5099      ``.amdhsa_user_sgpr_dispatch_ptr``                       0                GFX6-GFX9    Controls ENABLE_SGPR_DISPATCH_PTR in
5100                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5101      ``.amdhsa_user_sgpr_queue_ptr``                          0                GFX6-GFX9    Controls ENABLE_SGPR_QUEUE_PTR in
5102                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5103      ``.amdhsa_user_sgpr_kernarg_segment_ptr``                0                GFX6-GFX9    Controls ENABLE_SGPR_KERNARG_SEGMENT_PTR in
5104                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5105      ``.amdhsa_user_sgpr_dispatch_id``                        0                GFX6-GFX9    Controls ENABLE_SGPR_DISPATCH_ID in
5106                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5107      ``.amdhsa_user_sgpr_flat_scratch_init``                  0                GFX6-GFX9    Controls ENABLE_SGPR_FLAT_SCRATCH_INIT in
5108                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5109      ``.amdhsa_user_sgpr_private_segment_size``               0                GFX6-GFX9    Controls ENABLE_SGPR_PRIVATE_SEGMENT_SIZE in
5110                                                                                             :ref:`amdgpu-amdhsa-kernel-descriptor-gfx6-gfx9-table`.
5111      ``.amdhsa_system_sgpr_private_segment_wavefront_offset`` 0                GFX6-GFX9    Controls ENABLE_SGPR_PRIVATE_SEGMENT_WAVEFRONT_OFFSET in
5112                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5113      ``.amdhsa_system_sgpr_workgroup_id_x``                   1                GFX6-GFX9    Controls ENABLE_SGPR_WORKGROUP_ID_X in
5114                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5115      ``.amdhsa_system_sgpr_workgroup_id_y``                   0                GFX6-GFX9    Controls ENABLE_SGPR_WORKGROUP_ID_Y in
5116                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5117      ``.amdhsa_system_sgpr_workgroup_id_z``                   0                GFX6-GFX9    Controls ENABLE_SGPR_WORKGROUP_ID_Z in
5118                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5119      ``.amdhsa_system_sgpr_workgroup_info``                   0                GFX6-GFX9    Controls ENABLE_SGPR_WORKGROUP_INFO in
5120                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5121      ``.amdhsa_system_vgpr_workitem_id``                      0                GFX6-GFX9    Controls ENABLE_VGPR_WORKITEM_ID in
5122                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5123                                                                                             Possible values are defined in
5124                                                                                             :ref:`amdgpu-amdhsa-system-vgpr-work-item-id-enumeration-values-table`.
5125      ``.amdhsa_next_free_vgpr``                               Required         GFX6-GFX9    Maximum VGPR number explicitly referenced, plus one.
5126                                                                                             Used to calculate GRANULATED_WORKITEM_VGPR_COUNT in
5127                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5128      ``.amdhsa_next_free_sgpr``                               Required         GFX6-GFX9    Maximum SGPR number explicitly referenced, plus one.
5129                                                                                             Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
5130                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5131      ``.amdhsa_reserve_vcc``                                  1                GFX6-GFX9    Whether the kernel may use the special VCC SGPR.
5132                                                                                             Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
5133                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5134      ``.amdhsa_reserve_flat_scratch``                         1                GFX7-GFX9    Whether the kernel may use flat instructions to access
5135                                                                                             scratch memory. Used to calculate
5136                                                                                             GRANULATED_WAVEFRONT_SGPR_COUNT in
5137                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5138      ``.amdhsa_reserve_xnack_mask``                           Target           GFX8-GFX9    Whether the kernel may trigger XNACK replay.
5139                                                               Feature                       Used to calculate GRANULATED_WAVEFRONT_SGPR_COUNT in
5140                                                               Specific                      :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5141                                                               (+xnack)
5142      ``.amdhsa_float_round_mode_32``                          0                GFX6-GFX9    Controls FLOAT_ROUND_MODE_32 in
5143                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5144                                                                                             Possible values are defined in
5145                                                                                             :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
5146      ``.amdhsa_float_round_mode_16_64``                       0                GFX6-GFX9    Controls FLOAT_ROUND_MODE_16_64 in
5147                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5148                                                                                             Possible values are defined in
5149                                                                                             :ref:`amdgpu-amdhsa-floating-point-rounding-mode-enumeration-values-table`.
5150      ``.amdhsa_float_denorm_mode_32``                         0                GFX6-GFX9    Controls FLOAT_DENORM_MODE_32 in
5151                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5152                                                                                             Possible values are defined in
5153                                                                                             :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
5154      ``.amdhsa_float_denorm_mode_16_64``                      3                GFX6-GFX9    Controls FLOAT_DENORM_MODE_16_64 in
5155                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5156                                                                                             Possible values are defined in
5157                                                                                             :ref:`amdgpu-amdhsa-floating-point-denorm-mode-enumeration-values-table`.
5158      ``.amdhsa_dx10_clamp``                                   1                GFX6-GFX9    Controls ENABLE_DX10_CLAMP in
5159                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5160      ``.amdhsa_ieee_mode``                                    1                GFX6-GFX9    Controls ENABLE_IEEE_MODE in
5161                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5162      ``.amdhsa_fp16_overflow``                                0                GFX9         Controls FP16_OVFL in
5163                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc1-gfx6-gfx9-table`.
5164      ``.amdhsa_exception_fp_ieee_invalid_op``                 0                GFX6-GFX9    Controls ENABLE_EXCEPTION_IEEE_754_FP_INVALID_OPERATION in
5165                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5166      ``.amdhsa_exception_fp_denorm_src``                      0                GFX6-GFX9    Controls ENABLE_EXCEPTION_FP_DENORMAL_SOURCE in
5167                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5168      ``.amdhsa_exception_fp_ieee_div_zero``                   0                GFX6-GFX9    Controls ENABLE_EXCEPTION_IEEE_754_FP_DIVISION_BY_ZERO in
5169                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5170      ``.amdhsa_exception_fp_ieee_overflow``                   0                GFX6-GFX9    Controls ENABLE_EXCEPTION_IEEE_754_FP_OVERFLOW in
5171                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5172      ``.amdhsa_exception_fp_ieee_underflow``                  0                GFX6-GFX9    Controls ENABLE_EXCEPTION_IEEE_754_FP_UNDERFLOW in
5173                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5174      ``.amdhsa_exception_fp_ieee_inexact``                    0                GFX6-GFX9    Controls ENABLE_EXCEPTION_IEEE_754_FP_INEXACT in
5175                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5176      ``.amdhsa_exception_int_div_zero``                       0                GFX6-GFX9    Controls ENABLE_EXCEPTION_INT_DIVIDE_BY_ZERO in
5177                                                                                             :ref:`amdgpu-amdhsa-compute_pgm_rsrc2-gfx6-gfx9-table`.
5178      ======================================================== ================ ============ ===================
5179
5180 .amdgpu_metadata
5181 ++++++++++++++++
5182
5183 Optional directive which declares the contents of the ``NT_AMDGPU_METADATA``
5184 note record (see :ref:`amdgpu-elf-note-records-table-v3`).
5185
5186 The contents must be in the [YAML]_ markup format, with the same structure and
5187 semantics described in :ref:`amdgpu-amdhsa-code-object-metadata-v3`.
5188
5189 This directive is terminated by an ``.end_amdgpu_metadata`` directive.
5190
5191 .. _amdgpu-amdhsa-assembler-example-v3:
5192
5193 Code Object V3 Example Source Code (-mattr=+code-object-v3)
5194 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5195
5196 Here is an example of a minimal assembly source file, defining one HSA kernel:
5197
5198 .. code-block:: none
5199
5200   .amdgcn_target "amdgcn-amd-amdhsa--gfx900+xnack" // optional
5201
5202   .text
5203   .globl hello_world
5204   .p2align 8
5205   .type hello_world,@function
5206   hello_world:
5207     s_load_dwordx2 s[0:1], s[0:1] 0x0
5208     v_mov_b32 v0, 3.14159
5209     s_waitcnt lgkmcnt(0)
5210     v_mov_b32 v1, s0
5211     v_mov_b32 v2, s1
5212     flat_store_dword v[1:2], v0
5213     s_endpgm
5214   .Lfunc_end0:
5215     .size   hello_world, .Lfunc_end0-hello_world
5216
5217   .rodata
5218   .p2align 6
5219   .amdhsa_kernel hello_world
5220     .amdhsa_user_sgpr_kernarg_segment_ptr 1
5221     .amdhsa_next_free_vgpr .amdgcn.next_free_vgpr
5222     .amdhsa_next_free_sgpr .amdgcn.next_free_sgpr
5223   .end_amdhsa_kernel
5224
5225   .amdgpu_metadata
5226   ---
5227   amdhsa.version:
5228     - 1
5229     - 0
5230   amdhsa.kernels:
5231     - .name: hello_world
5232       .symbol: hello_world.kd
5233       .kernarg_segment_size: 48
5234       .group_segment_fixed_size: 0
5235       .private_segment_fixed_size: 0
5236       .kernarg_segment_align: 4
5237       .wavefront_size: 64
5238       .sgpr_count: 2
5239       .vgpr_count: 3
5240       .max_flat_workgroup_size: 256
5241   ...
5242   .end_amdgpu_metadata
5243
5244 Additional Documentation
5245 ========================
5246
5247 .. [AMD-RADEON-HD-2000-3000] `AMD R6xx shader ISA <http://developer.amd.com/wordpress/media/2012/10/R600_Instruction_Set_Architecture.pdf>`__
5248 .. [AMD-RADEON-HD-4000] `AMD R7xx shader ISA <http://developer.amd.com/wordpress/media/2012/10/R700-Family_Instruction_Set_Architecture.pdf>`__
5249 .. [AMD-RADEON-HD-5000] `AMD Evergreen shader ISA <http://developer.amd.com/wordpress/media/2012/10/AMD_Evergreen-Family_Instruction_Set_Architecture.pdf>`__
5250 .. [AMD-RADEON-HD-6000] `AMD Cayman/Trinity shader ISA <http://developer.amd.com/wordpress/media/2012/10/AMD_HD_6900_Series_Instruction_Set_Architecture.pdf>`__
5251 .. [AMD-GCN-GFX6] `AMD Southern Islands Series ISA <http://developer.amd.com/wordpress/media/2012/12/AMD_Southern_Islands_Instruction_Set_Architecture.pdf>`__
5252 .. [AMD-GCN-GFX7] `AMD Sea Islands Series ISA <http://developer.amd.com/wordpress/media/2013/07/AMD_Sea_Islands_Instruction_Set_Architecture.pdf>`_
5253 .. [AMD-GCN-GFX8] `AMD GCN3 Instruction Set Architecture <http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/12/AMD_GCN3_Instruction_Set_Architecture_rev1.1.pdf>`__
5254 .. [AMD-GCN-GFX9] `AMD "Vega" Instruction Set Architecture <http://developer.amd.com/wordpress/media/2013/12/Vega_Shader_ISA_28July2017.pdf>`__
5255 .. [AMD-ROCm] `ROCm: Open Platform for Development, Discovery and Education Around GPU Computing <http://gpuopen.com/compute-product/rocm/>`__
5256 .. [AMD-ROCm-github] `ROCm github <http://github.com/RadeonOpenCompute>`__
5257 .. [HSA] `Heterogeneous System Architecture (HSA) Foundation <http://www.hsafoundation.com/>`__
5258 .. [ELF] `Executable and Linkable Format (ELF) <http://www.sco.com/developers/gabi/>`__
5259 .. [DWARF] `DWARF Debugging Information Format <http://dwarfstd.org/>`__
5260 .. [YAML] `YAML Ain't Markup Language (YAML™) Version 1.2 <http://www.yaml.org/spec/1.2/spec.html>`__
5261 .. [MsgPack] `Message Pack <http://www.msgpack.org/>`__
5262 .. [OpenCL] `The OpenCL Specification Version 2.0 <http://www.khronos.org/registry/cl/specs/opencl-2.0.pdf>`__
5263 .. [HRF] `Heterogeneous-race-free Memory Models <http://benedictgaster.org/wp-content/uploads/2014/01/asplos269-FINAL.pdf>`__
5264 .. [CLANG-ATTR] `Attributes in Clang <http://clang.llvm.org/docs/AttributeReference.html>`__