Repository navigation
POCL: initialize large arrays with a kernel in zeros and ones - #927
Merged
Merged
Conversation
Since #795, `zeros` and `ones` on the CPU back-end allocate and `fill!` from the calling thread, which first-touches every page and so places all of the memory in that thread's NUMA domain. KernelAbstractions 0.9 filled them with a kernel, and the NUMA example relied on that. Fill arrays of bits types of at least 1 MiB with a kernel again. The kernel takes the value rather than its type: a `Type{T}` argument is what failed for bits unions in #795. Arrays of bits unions, which aren't `isbitstype`, and smaller arrays keep the host `fill!`. The threshold is where the launch stops dominating. Initializing a fresh `Float32` array on a Ryzen 9950X (one memory domain) with 1, 8 or 16 PoCL threads, the kernel takes 1.3 to 22 times as long as `fill!` up to 256 KiB, 0.8 to 1.1 times from 1 to 16 MiB, and 1.1 to 1.2 times from 64 MiB on, where both are bound by memory bandwidth.
Contributor
|
Documentation preview: https://juliagpu.github.io/KernelAbstractions.jl/previews/PR927/ |
Contributor
Benchmark ResultsShow table
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
vchuravy
approved these changes
Oct 26, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #927 +/- ##
==========================================
+ Coverage 83.05% 83.13% +0.07%
==========================================
Files 31 31
Lines 2556 2568 +12
==========================================
+ Hits 2123 2135 +12
Misses 433 433 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:(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.