Repository navigation
Commit 01743fb
committed
GPU: make the kernel entry-point signature work on Metal
MSL has no by-value kernel parameters: every one must carry an attribute naming
a buffer or a builtin. It also has no ambient work-item builtins, so the grid
dimensions arrive as attributes on the entry point too.
GPUCA_KRNLGPU_DEF therefore gets two hooks, GPUCA_KRNL_SECTOR_ARG and
GPUCA_KRNL_GRID_ARGS, which the Metal source fills in with a buffer and the four
grid attributes. Both default to what the signature had, so CUDA, HIP and OpenCL
generate exactly the same entry point as before.
The attributes are named after the nBlocks, nThreads, iBlock and iThread that
Thread() already takes, so the get_*() helpers resolve at the entry point and in
everything it calls. Metal still needs its own definitions of them because the
host ones assume one thread per block: get_local_id() is 0 and get_local_size()
is 1 there.
The generated arguments need an attribute too, each with a distinct buffer index,
and the preprocessor cannot supply one: the kernel list splices arguments as a
flat comma-separated list, and __COUNTER__ is monotonic across the translation
unit rather than per kernel. o2_gpu_add_kernel already walks the arguments in
pairs, so it emits the index there. Declarations go through GPUPtr1(idx, type,
name) for pointers and GPUArg1(idx, type, name) for scalars, which each backend
defines as it needs. Indices start at 3, after gpu_mem, the constant memory and
the sector; the sector itself is nothing special, it just lives in the fixed part
of the macro rather than in the generated list.
Metal masks pointers as a 64-bit address exactly as OpenCL does, and for the same
reason: GPUTRDTrackerKernels takes a GPUTRDTrackerGPU*, and a pointer to a
derived class is not a valid kernel argument type there either. Binding POD
pointers directly would have worked but would not have covered that case, so both
go the same way. On the way back in, GPUPtr2 casts through device before handing
the pointer to Thread(): the kernel's own buffers are device memory, but the
Thread() entry points take the pointer unannotated, which in MSL means generic.
Generated entry points are byte-identical for CUDA, HIP and OpenCL. Kernel list
diagnostics: 408 to 0, and the translation unit 1108 to 881.1 parent 7518d76 commit 01743fb
5 files changed
Lines changed: 52 additions & 11 deletions
File tree
- GPU
- Common
- GPUTracking
- Base
- metal
- Definitions
- cmake
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
280 | 290 | | |
281 | 291 | | |
282 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
66 | 75 | | |
67 | | - | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
73 | 83 | | |
74 | 84 | | |
75 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
25 | 29 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
32 | 41 | | |
33 | | - | |
| 42 | + | |
34 | 43 | | |
| 44 | + | |
35 | 45 | | |
36 | 46 | | |
37 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
58 | 60 | | |
59 | | - | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | | - | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
0 commit comments