Launching a kernel with a new signature compiles a lot of signature-independent host code
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- julia
- Domain
- performance
Research direction
Start with hipfunction and _kernel_instances in src/compiler/codegen.jl, then compare the analogous cufunction and cufunction_link patterns in CUDA.jl. Read launch_tuple and pack_arguments in src/runtime/hip-execution.jl and the argument conversion in src/highlevel.jl; validate changes by measuring host-side precompile time for new kernel signatures, including through KernelAbstractions. Done means reducing compilation overhead while accounting for the small per-launch allocation tradeoff.
Written by the indexing model from the issue text.
Description
JuliaGPU/Metal.jl#1014 cut the host-side compilation needed to launch a kernel with a new argument signature by 4-10x on Metal. I checked which of the causes found there also apply to AMDGPU.jl; two do.
These numbers come from a machine without an AMD GPU: they time precompile of a function doing @roc groupsize=64 kern(y, x, a) for a new kernel signature, i.e., host-side inference and code generation only, with the changes below prototyped by redefining the functions. A new signature currently costs ~95 ms (Julia 1.12) / ~101 ms (1.13), and ~79 / ~86 ms through KernelAbstractions.
hipfunction(src/compiler/codegen.jl:275-290) compiles its whole body for every kernel: the lock, device and config lookup,hipfunction_lookup, and the_kernel_instances::Dict{Any,Any}cache (codegen.jl:48), which is keyed by a tuple containingf, so hashing and theDictaccesses are compiled for every kernel too. AHIPKernelis only(f, fun), so that cache can go. Splitting it into a thinhipfunctionthat only doesmethodinstance(F, tt)and constructs theHIPKernel, with the rest in an unspecialized@noinlinefunction (likecufunctionandcufunction_linkin CUDA.jl), brings a new signature from 95 to 61 ms.launch_tuple(fun::HIPFunction, args::Tuple; ...)(src/runtime/hip-execution.jl:125-154) is specialized on the converted arguments, but onlypack_argumentsneeds them (~25 ms exclusive in the inference profile). Packing in a specialized function and launching through a@noinlinefunction taking the parameter pointer brings it from 95 to 68 ms. This gives up theallocamentioned at hip-execution.jl:138-140, i.e., costs a small allocation per launch.
With both changes, a new signature costs 37 / 42 ms, and 40 / 50 ms through KernelAbstractions.
Unrelated, but noticed along the way: @roc converts the arguments once to compute their types (src/highlevel.jl:155) and again when calling the kernel (hip-execution.jl:70).
- Dominant language
- Julia
- Stars
- 346
- Forks
- 81
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 52
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaGPU/AMDGPU.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaGPU/AMDGPU.jl#1040 · 8 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 54/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
All issues in JuliaGPU/AMDGPU.jl
Similar issues
-
View of a view is brokenPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
JuliaPy/pyjuliapkg#102 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
JuliaMath/Polynomials.jl#641 ·