| 1 |
|
| 2 |
Hardware docs |
| 3 |
============= |
| 4 |
|
| 5 |
Command buffers |
| 6 |
--------------- |
| 7 |
|
| 8 |
Command format |
| 9 |
^^^^^^^^^^^^^^ |
| 10 |
|
| 11 |
Each command sent to the GPU contains a method and some data. Method names are |
| 12 |
documented in corresponding header files copied from NVIDIA, eg. the fermi |
| 13 |
graphics methods are in src/nouveau/headers/nvidia/classes/cl9097.h |
| 14 |
|
| 15 |
P_IMMD |
| 16 |
"""""" |
| 17 |
|
| 18 |
A lot of the time, you will want to issue a single method with its data, which |
| 19 |
can be done with P_IMMD:: |
| 20 |
|
| 21 |
P_IMMD(p, NV9097, WAIT_FOR_IDLE, 0); |
| 22 |
|
| 23 |
P_IMMD will emit either a single `immediate-data method`_, which takes a single |
| 24 |
word, or a pair of words that's equivalent to P_MTHD + the provided data. Code |
| 25 |
must count P_IMMD as possibly 2 words as a result. |
| 26 |
|
| 27 |
.. _immediate-data method: https://github.com/NVIDIA/open-gpu-doc/blob/87ba53e0c385285a3aa304b864dccb975a9a0dd4/manuals/turing/tu104/dev_ram.ref.txt#L1214 |
| 28 |
|
| 29 |
P_MTHD |
| 30 |
"""""" |
| 31 |
|
| 32 |
`P_MTHD`_ is a convenient way to execute multiple consecutive methods without |
| 33 |
repeating the method header. For example, the code:: |
| 34 |
|
| 35 |
P_MTHD(p, NV9097, SET_REPORT_SEMAPHORE_A); |
| 36 |
P_NV9097_SET_REPORT_SEMAPHORE_A(p, addr >> 32); |
| 37 |
P_NV9097_SET_REPORT_SEMAPHORE_B(p, addr); |
| 38 |
P_NV9097_SET_REPORT_SEMAPHORE_C(p, value); |
| 39 |
|
| 40 |
generates four words - one word for the method header (defaulting to 1INC) and |
| 41 |
then the next three words for data. 1INC will automatically increment the method |
| 42 |
id by one word for each data value, which is why the example can advance from |
| 43 |
SET_REPORT_SEMAPHORE_A to B to C. |
| 44 |
|
| 45 |
.. _P_MTHD: https://github.com/NVIDIA/open-gpu-doc/blob/87ba53e0c385285a3aa304b864dccb975a9a0dd4/manuals/turing/tu104/dev_ram.ref.txt#L1042 |
| 46 |
|
| 47 |
P_0INC |
| 48 |
"""""" |
| 49 |
|
| 50 |
`0INC`_ will issue the same method repeatedly for each following data word. |
| 51 |
|
| 52 |
.. _0INC: https://github.com/NVIDIA/open-gpu-doc/blob/87ba53e0c385285a3aa304b864dccb975a9a0dd4/manuals/turing/tu104/dev_ram.ref.txt#L1096 |
| 53 |
|
| 54 |
P_1INC |
| 55 |
"""""" |
| 56 |
|
| 57 |
`1INC`_ will increment after one word and then issue the following method |
| 58 |
repeatedly. For example, the code:: |
| 59 |
|
| 60 |
P_1INC(p, NV9097, CALL_MME_MACRO(NVK_MME_SET_PRIV_REG)); |
| 61 |
P_INLINE_DATA(p, 0); |
| 62 |
P_INLINE_DATA(p, BITFIELD_BIT(3)); |
| 63 |
|
| 64 |
issues one NV9097_CALL_MME_MACRO command, then increments the method and issues |
| 65 |
two NV9097_CALL_MME_DATA commands. |
| 66 |
|
| 67 |
.. _1INC: https://github.com/NVIDIA/open-gpu-doc/blob/87ba53e0c385285a3aa304b864dccb975a9a0dd4/manuals/turing/tu104/dev_ram.ref.txt#L1149 |
| 68 |
|
| 69 |
Execution barriers |
| 70 |
^^^^^^^^^^^^^^^^^^ |
| 71 |
|
| 72 |
Commands within a command buffer can be synchronized in a few different ways. |
| 73 |
|
| 74 |
* Explicit WFI - Idles all engines before executing the next command eg. via |
| 75 |
`NVA16F_WFI` or `NV9097_WAIT_FOR_IDLE` |
| 76 |
* Semaphores - Delay execution based on values in a memory location. See |
| 77 |
`open-gpu-doc on semaphores`_ |
| 78 |
* A subchannel switch - Causes the hardware to execute an implied WFI |
| 79 |
|
| 80 |
.. _open-gpu-doc on semaphores: https://github.com/NVIDIA/open-gpu-doc/blob/master/manuals/turing/tu104/dev_pbdma.ref.txt#L3231 |
| 81 |
|
| 82 |
Subchannel switches |
| 83 |
""""""""""""""""""" |
| 84 |
|
| 85 |
A subchannel switch occurs when the hardware receives a command for a different |
| 86 |
subchannel than the one that it's currently executing. For example, if the |
| 87 |
hardware is currently executing commands on the 3D engine (`SUBC_NV9097 == 0`), a |
| 88 |
command executed on the compute engine (`SUBC_NV90C0 == 1`) will cause a |
| 89 |
subchannel switch. Host methods (class \*6F) are an exception to this - they can |
| 90 |
be issued to any subchannel and will not trigger a subchannel switch |
| 91 |
[#fhostsubcswitch]_ [#foverlapnvk]_. |
| 92 |
|
| 93 |
Subchannel switches act the same way that an explicit WFI does - they fully idle |
| 94 |
the channel before issuing commands to the next engine [#fnsight]_ |
| 95 |
[#foverlapnvk]_. |
| 96 |
|
| 97 |
This works the same on Blackwell. Some NVIDIA documentation contradicts this: |
| 98 |
"On NVIDIA Blackwell Architecture GPUs and newer, subchannel switches do not |
| 99 |
occur between 3D and compute workloads"[#fnsight]_. This documentation appears |
| 100 |
to be wrong or inapplicable for some reason - tests do not reproduce this |
| 101 |
behavior [#foverlapnvk]_ [#foverlapprop]_, and the blob does not change its |
| 102 |
event implementation for blackwell [#feventprop]_. |
| 103 |
|
| 104 |
|
| 105 |
.. [#fnsight] https://docs.nvidia.com/nsight-graphics/UserGuide/index.html#subchannel-switch-overlay |
| 106 |
.. [#foverlapnvk] Based on reverse engineering by running |
| 107 |
https://gitlab.freedesktop.org/mhenning/re/-/tree/main/vk_test_overlap_exec |
| 108 |
under nvk, possibly with alterations to the way nvk generates commands for |
| 109 |
pipeline barriers. |
| 110 |
.. [#foverlapprop] By running |
| 111 |
https://gitlab.freedesktop.org/mhenning/re/-/tree/main/vk_test_overlap_exec |
| 112 |
under the proprietary driver and examining the main output (eg. execution |
| 113 |
overlaps without pipeline barriers) |
| 114 |
.. [#feventprop] For example, the event commands generated here only wait on a |
| 115 |
single engine |
| 116 |
https://gitlab.freedesktop.org/mhenning/re/-/blob/6ce8c860da65fbf2ab26d124d25f907dea2cf33a/vk_event/blackwell.out#L20612-20793 |
| 117 |
.. [#fhostsubcswitch] https://github.com/NVIDIA/open-gpu-doc/blob/87ba53e0c385285a3aa304b864dccb975a9a0dd4/manuals/turing/tu104/dev_ram.ref.txt#L1009 |
| 118 |
|
| 119 |
Copy engine |
| 120 |
^^^^^^^^^^^ |
| 121 |
|
| 122 |
The copy engine's `PIPELINED` mode allows a new transfer to start before the |
| 123 |
previous transfer finishes, while `NON_PIPELINED` acts as an execution barrier |
| 124 |
between the current copy and the previous one [#fpipelined]_. |
| 125 |
|
| 126 |
.. [#fpipelined] https://github.com/NVIDIA/open-gpu-kernel-modules/blob/2b436058a616676ec888ef3814d1db6b2220f2eb/src/common/sdk/nvidia/inc/ctrl/ctrl0050.h#L75-L83 |