Skip to content

Commit ec2613c

Browse files
committed
hsa docs
kernel dispatch added hsa lb moved to More Acronyms
1 parent 369fd46 commit ec2613c

File tree

7 files changed

+88
-2
lines changed

7 files changed

+88
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RS64 = RISCV/RV64I + a few custom instructions! Load (at least MEC) with offset
3232

3333
## Architechture Diagram
3434

35-
![](/docs/arch1.jpg)
35+
![](/docs/img/arch1.jpg)
3636

3737
- 1x 5nm GCD (graphics compute die)
3838
- 6x 6nm MCD (memory cache die)
@@ -133,6 +133,7 @@ HSAKMT_DEBUG_LEVEL=7 # user space debugging
133133
- EOP: End Of Pipe/Pipeline
134134
- SRBM: System Register Bus Manager
135135
- GRBM: Graphics Register Bus Manager
136+
- [HSA](/docs/HSA.md) = Heterogeneous System Architecture
136137

137138
## Listing IP blocks
138139

docs/CU.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
It's where compute happens
44

5-
![](/docs/big_compute-unit-pair.jpg)
5+
![](/docs/img/big_compute-unit-pair.jpg)
66

77
7900XTX has 96 compute units (48 work-group processors)
88

docs/HSA.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# HSA stands for Heterogeneous System Architecture
2+
3+
[HSA](https://en.wikipedia.org/wiki/Heterogeneous_System_Architecture) is a cross-vendor set of specifications that allow for the integration of central processing units and graphics processors on the same bus, with shared memory and tasks.
4+
5+
Idea of HSA is to reduce communication latency between CPUs, GPUs and to make it easier to offload calculations to the GPU
6+
![](/docs/img/gpu_with_hsa.png)
7+
8+
HSA defines a unified virtual address space for compute.
9+
10+
Usually GPU and CPU have their own memory, HSA requires them to share page tables, to exchange data by sharing pointers. Needs to be supported by HSA specific [memory management units](https://web.archive.org/web/20140328140823/http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/hsa10.pdf)
11+
12+
HSA should support both GPUs and CPUs and high-level languages.
13+
14+
The CPU's [MMU](https://en.wikipedia.org/wiki/Memory_management_unit) and the GPU's [IOMMU](https://en.wikipedia.org/wiki/IOMMU) must both comply with HSA hardware specifications.
15+
![](/docs/img/mmu_iommu.png)
16+
17+
Some of the HSA-specific features implemented in the hardware need to be supported by the operating system kernel and specific device drivers.
18+
19+
`amdkfd` supports heterogeneous queuing (HQ), which aims to simplify the distribution of computational jobs among multiple CPUs and GPUs from the programmer's perspective. Support for heterogeneous memory management (HMM), suited only for graphics hardware featuring version 2 of the AMD's IOMMU,
20+
21+
22+
## Graphics Core Next (GCN)
23+
24+
HSA kernel driver resides in the directory `/drivers/gpu/hsa`, while the DRM graphics device drivers reside in `/drivers/gpu/drm`
25+
26+
Hardware schedulers are used to perform scheduling and offload the assignment of compute queues to the ACEs from the driver to hardware, by buffering these queues until there is at least one empty queue in at least one ACE. This causes the HWS to immediately assign buffered queues to the ACEs until all queues are full or there are no more queues to safely assign
27+
28+
Part of the scheduling work performed includes prioritized queues which allow critical tasks to run at a higher priority than other tasks without requiring the lower priority tasks to be preempted to run the high priority task, therefore allowing the tasks to run concurrently with the high priority tasks scheduled to hog the GPU as much as possible while letting other tasks use the resources that the high priority tasks are not using. These are essentially Asynchronous Compute Engines that lack dispatch controllers. They were first introduced in the fourth generation [GCN](https://en.wikipedia.org/wiki/Graphics_Core_Next) microarchitectur
29+
30+
## Kernel dispatch
31+
32+
[Dispatching a kernel](https://llvm.org/docs/AMDGPUUsage.html#kernel-dispatch) can be done from a CPU hosted program or from an HSA kernel executing on a GPU
33+
* Get pointer to AQL queue
34+
* Get pointer to the kernel [descriptor](https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-kernel-descriptor), kernel must be part of code loaded by an HSA runtime, where the AQL queue is associated
35+
* Space is allocated, atleast 16-byte aligned, for the kernel arguments
36+
* Kernel arguments values are asssigned to allocated memory, according to [HSA](https://llvm.org/docs/AMDGPUUsage.html#hsa). For AMDGPU kernel execution has direct access to kernel arguments memory
37+
* An AQL kernel dispatch packet is created on the AQL queue. 64-bit atomic operationss is used to reserve space in the AQL queue
38+
- Final write must use an atomic store release to set the packet kind
39+
- AQL defines a doorbell signal mechanism, to notify kernel agent that AQL has been updated.[For more info](https://llvm.org/docs/AMDGPUUsage.html#hsa)
40+
* A kernel dispatch contains information about the actual dispatch and information about the kernel. The HSA runtime can be used tofind values recorded in the [Code Object Metadata](https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-code-object-metadata)
41+
* CP executes micro-code and is responsible for detecting and setting up the GPU to execute wavefronts of a kernel dispatch
42+
* CP ensures SGRP and VGRP is setup as required by the machine code. See [Kernel Descriptor](https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-kernel-descriptor) and [Initial Kernel Execution State](https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-initial-kernel-execution-state)
43+
- SGRP = Scalar General Purpose Registers
44+
- VGRP = Vector General Purpose Registers
45+
* [Kernel Prolog](https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-kernel-prolog) initialized by the compiler from instructions in the Initial Kernel Execution State via the Kernel descriptor
46+
* When execution is complete, CP signals completion specified in the kernel dispatch packet, if not 0.
47+
48+
## HSA Signals
49+
50+
HSA Signal handles, are 64-bit addresses of a structure allocated in memory. Accessible both from CPU and GPU
51+
52+
## HSA AQL Queue
53+
54+
The HSA AQL queue structure, is defined by an HSA compatible runtime
55+
56+
## Example HSA kernel in assembler
57+
58+
GFX900 HSA kernel in [asm](https://llvm.org/docs/AMDGPUUsage.html#code-object-v3-and-above-example-source-code)
59+
60+
## HSA IB
61+
```
62+
bob@melee:~/dev/7900xtx/crash$ sudo umr -go 0 -di 0@0x7fff00b4ad00 0xc 6
63+
[WARNING]: Unknown ASIC [amd744c] should be added to pci.did to get proper name
64+
Decoding IB at 0@0x7fff00b4ad00 from 0@0x0 of 0 words (type 0)
65+
[0@0x7fff00b4ad00 + 0x0000] [ 0x00000002] Opcode 0x2 [HSA_KERNEL_DISPATCH] (32 words, type: 0, hdr: 0x2)
66+
[0@0x7fff00b4ad00 + 0x0002] [ 0x0000] |---> setup_dimensions=0
67+
[0@0x7fff00b4ad00 + 0x0004] [ 0x1aa0] |---> workgroup_size_x=6816
68+
[0@0x7fff00b4ad00 + 0x0006] [ 0x0040] |---> workgroup_size_y=64
69+
[0@0x7fff00b4ad00 + 0x0008] [ 0x7fff] |---> workgroup_size_z=32767
70+
[0@0x7fff00b4ad00 + 0x000a] [ 0x0000] |---> reserved0=0
71+
[0@0x7fff00b4ad00 + 0x000c] [ 0x00000000] |---> grid_size_x=0
72+
[0@0x7fff00b4ad00 + 0x0010] [ 0xdeadbeef] |---> grid_size_y=3735928559
73+
[0@0x7fff00b4ad00 + 0x0014] [ 0x00000000] |---> grid_size_z=0
74+
[0@0x7fff00b4ad00 + 0x0018] [ 0x00000000] |---> private_segment_size=0
75+
[0@0x7fff00b4ad00 + 0x001c] [ 0x00000000] |---> group_segment_size=0
76+
[0@0x7fff00b4ad00 + 0x0020] [0x0000000000000000] |---> kernel_object=0x0
77+
[0@0x7fff00b4ad00 + 0x0028] [0x0000000000000000] |---> kernarg_address=0x0
78+
[0@0x7fff00b4ad00 + 0x0030] [0x0000000000000000] |---> reserved2=0x0
79+
[0@0x7fff00b4ad00 + 0x0038] [0x0000000000000000] |---> completion_signal=0x0
80+
[0@0x7fff00b4ad00 + 0x0040] [ 0x00000000] Opcode 0x0 [HSA_VENDOR_SPECIFIC] (1 words, type: 0, hdr: 0x0)
81+
[0@0x7fff00b4ad00 + 0x0042] [ 0x00000000] Opcode 0x0 [HSA_VENDOR_SPECIFIC] (1 words, type: 0, hdr: 0x0)
82+
[0@0x7fff00b4ad00 + 0x0044] [ 0x00000000] Opcode 0x0 [HSA_VENDOR_SPECIFIC] (1 words, type: 0, hdr: 0x0)
83+
[0@0x7fff00b4ad00 + 0x0046] [ 0x00000000] Opcode 0x0 [HSA_VENDOR_SPECIFIC] (1 words, type: 0, hdr: 0x0)
84+
Done decoding IB
85+
```
File renamed without changes.
File renamed without changes.

docs/img/gpu_with_hsa.png

27.9 KB
Loading

docs/img/mmu_iommu.png

46.6 KB
Loading

0 commit comments

Comments
 (0)