POCL: initialize large arrays with a kernel in `zeros` and `ones` #927
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 326 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.346
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #927"
general
weight: 0.35
vchuravy
On a NUMA system, Linux places a page of memory in the domain of the thread that first writes to it. Since #795,
KernelAbstractions.zerosandoneson theCPUback-end allocate a plainArrayand fill it withfill!on the calling thread, so all of the memory ends up in that thread's domain, however many PoCL threads later work on it. KernelAbstractions 0.9 filled these arrays with a kernel, and the NUMA example relied on that.This fills arrays of bits types of at least 1 MiB with a kernel again, so that PoCL's threads touch the pages first. #795 removed the old kernel because it took the element type as a
Type{T}argument, which GPUCompiler can't handle for bits unions likeUnion{Missing, Bool}on Julia 1.13 and earlier. The new kernel takes the value (zero(T)orone(T)) instead, and arrays of bits unions, which aren'tisbitstype, keep the hostfill!regardless. Like before, the arrays are filled whenzerosandonesreturn, since PoCL launches wait for the kernel.Smaller arrays are still filled from the host. Timing the initialization of a fresh
Float32array (allocation and fill, median, excluding the first compilation) on a Ryzen 9950X with one memory domain:| size | 1 thread | 8 threads | 16 threads |
|---|---|---|---|
| 4 KiB | 12.8 | 22.4 | 20.8 |
| 16 KiB | 3.6 | 4.4 | 3.0 |
| 64 KiB | 3.1 | 6.1 | 7.2 |
| 256 KiB | 1.34 | 2.36 | 1.89 |
| 1 MiB | 0.77 | 1.04 | 1.02 |
| 4 MiB | 0.91 | 0.89 | 1.04 |
| 16 MiB | 1.00 | 0.84 | 1.12 |
| 64 MiB | 1.13 | 1.14 | 1.11 |
| 256 MiB | 1.15 | 1.21 | 1.16 |
(time with the kernel divided by time with
fill!; threads set withJULIA_KA_CPU_THREADS, process pinned to 16 cores)Below 1 MiB the launch overhead dominates; from 1 MiB on both are about equally fast, and the largest arrays are bound by memory bandwidth, where the kernel is 10-20% slower on this single-domain machine. That's the price for spreading the pages over the domains of PoCL's threads on a NUMA machine, which I couldn't measure here. With the static scheduling of work-groups in JuliaGPU/pocl#7, a later kernel with as many work-groups runs each of them on the thread that initialized it, so the pages end up near the thread that uses them; this PR doesn't depend on that change.
The NUMA example's remark about
zerosis updated accordingly. Tests:zerosandonesofFloat32,Int8,ComplexF64and a small isbits struct, at just above the threshold, as 1- and 2-D arrays and as one-element arrays, next to the existing bits-union test from #795.