RadixSort fails on NVIDIA's OpenCL driver: its default block size of 512 exceeds the reported kernel limit of 256
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- julia
- 領域
- backend, performance
調査の方向性
Start with SortTuning and OpenCLExt to trace how OpenCL GPU devices choose radix_block_size; then inspect the RadixSort cases in test/generic/workspace.jl and the “reduce: block sizes” testset in reduce_dims.jl. Check how MAX_BLOCK_SIZE is set in test/runtests.jl, since it uses the device limit while launches are checked against a kernel limit. Done when the default radix sort fits the kernel limit and the affected OpenCL tests pass.
索引モデルが issue の本文から書いたものです。
説明
With NVIDIA's OpenCL driver, every RadixSort call with the default settings throws before launching anything:
using OpenCL # with NVIDIA's ICD, e.g. OCL_ICD_FILENAMES=libnvidia-opencl.so.1
import AcceleratedKernels as AK
AK.sort!(CLArray(rand(Float32, 1000)); alg=AK.RadixSort())
ERROR: ArgumentError: Work-group size (512, 1, 1) has more than 256 work-items, the maximum for this kernel
SortTuning's default radix_block_size is 512. KernelInterface checks each launch against CL_KERNEL_WORK_GROUP_SIZE, and NVIDIA's driver reports 256 for that. Every length and layout fails the same way (100 and 10^4 elements, dims=1 on 100×3, dims=2 on 3×3000, 32- and 64-bit keys), while RadixSort(block_size=256) sorts correctly. Auto() never picks RadixSort on OpenCL GPUs, so only an explicit alg=AK.RadixSort() runs into this. The test suite hits it in test/generic/workspace.jl (the RadixSort cases) and in the "reduce: block sizes" testset of reduce_dims.jl, which tries block sizes up to MAX_BLOCK_SIZE. For OpenCL that is the device's max_work_group_size (1024), not the kernel's limit.
Nothing launches with an invalid configuration: KernelInterface's check_work_group_size rejects the launch, so the user gets an ArgumentError, not a crash.
Environment: AK main (fdd0a6f, 0.5.11), OpenCL.jl 1.0.0, KernelAbstractions 0.10.4, KernelInterface 0.4.3, spirv2clc_jll 0.2.7, Julia 1.12.7. NVIDIA driver 615.78.08 (OpenCL platform "CUDA 13.4.96"), on an RTX 5080 (Linux 7.2) and an RTX 6000 Ada. The driver lacks cl_khr_il_program, so OpenCL.jl translates the SPIR-V to OpenCL C with spirv2clc.
Triage: the limit is the driver's, and it doesn't depend on the kernel:
- Every kernel reports
CL_KERNEL_WORK_GROUP_SIZE == 256, whileCL_DEVICE_MAX_WORK_GROUP_SIZEis 1024. That includes AK's radix, merge, scan and reduce kernels, a one-line KA copy kernel, and hand-written OpenCL C built directly withcl.Program(source=...), with or without-cl-std. So it isn't spirv2clc output or register pressure. - Even a kernel declared
__attribute__((reqd_work_group_size(1024, 1, 1)))reports 256, whileCL_KERNEL_COMPILE_WORK_GROUP_SIZEsays (1024, 1, 1). The two answers contradict each other. - Launches past the reported limit work. Hand-written kernels at local sizes of 512 and 1024 (one with a barrier and local memory) give correct results, and with KernelInterface's check overridden,
RadixSort(block_size=512)andblock_size=1024sort 100 and 10^6Float32/Int64keys correctly.
So the driver under-reports. Still, the per-kernel value is the only limit OpenCL defines, and nothing tells which larger launches are safe, so AK should stay within it rather than have KernelInterface skip the check.
Other back-ends:
- CUDA: KA compiles a kernel with a static work-group size with that size as its thread limit, so
max_threads_per_blockequals the block size. On the RTX 5080 the radix kernels report 512 atblock_size=512and 1024 at 1024. - Metal and oneAPI: KernelInterface checks the pipeline's
maxTotalThreadsPerThreadgroupor the kernel's maximum group size the same way. Register-heavy kernels can get a lower limit there, butRadixSortat 512 passes the M1 CI. I haven't measured it further.
On every back-end, a too-large block is an ArgumentError before launch. AK never queries a kernel's limit itself: check_block_size only bounds block sizes at 1024.
Suggested fix:
- In OpenCLExt, give GPU devices
SortTuning(radix_block_size=256). OpenCL GPUs have no measured tuning (the comment says so), and 256 is what every other AK kernel algorithm uses by default. A clamp at launch time wouldn't work, because the block size is a compile-time constant of the kernels and sets the size of the workspace's histograms. - In test/runtests.jl, derive OpenCL's
MAX_BLOCK_SIZEfrom a compiled kernel's limit (for example,KI.max_work_group_sizeof a trivial kernel), not from the device'smax_work_group_size. - Optionally, report the constant 256 to NVIDIA, with the
reqd_work_group_sizekernel as the reproducer.
- 主要言語
- Julia
- スター
- 204
- フォーク
- 20
- 平均マージ
- 2日 19時間
- マージ済み PR(30日)
- 41
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaGPU/AcceleratedKernels.jl のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
JuliaGPU/AcceleratedKernels.jl#89 ·
メンテナーはふだん 1 日以内に返信
-
Inference of reductions with a non-concrete `alg` recurses through GPUArrays 12 and never finishesオープン
難易度 5/5 1週間以上 初心者へのやさしさ 8/100
JuliaGPU/AcceleratedKernels.jl#161 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
JuliaGPU/AcceleratedKernels.jl#159 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
JuliaGPU/AcceleratedKernels.jl#156 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
JuliaGPU/AcceleratedKernels.jl#150 ·
メンテナーはふだん 1 日以内に返信
JuliaGPU/AcceleratedKernels.jl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
MagneticResonanceImaging/MRIReco.jl#366 ·
メンテナーはふだん 3 日以内に返信
-
`AdamW` gives `NaN` for zero-gradient entries of `Float16` parameters (epsilon underflows to 0)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
FluxML/Optimisers.jl#253 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
JuliaGraphs/GraphNeuralNetworks.jl#736 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
`poissonians` is not public, unlike `brownians` and `jumps`対応中かも @isaacsas が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
SciML/ModelingToolkit.jl#5389 ·
メンテナーはふだん 2 日以内に返信