Repository navigation
Look up kernel metadata by dispatch on the kernel - #236
Conversation
`@parallel <kernelcall>` reads the kernel's metadata (nb_parallel_indices, memopt) at launch. The metadata function had a mangled name derived from the callee expression, so it was only found when the kernel was called by its own name: calls through a struct field (`@parallel s.f(A)`) or a function argument (`g(f, A) = @parallel f(A)`) failed with a FieldError or UndefVarError. The metadata is now an additional method of the kernel function itself, `kernel(::ParallelStencil.KernelMetadata, args...)`, so any callee expression evaluating to the kernel finds it by dispatch, in whatever scope the kernel is defined. The method is defined after the kernel, as KernelAbstractions defines its kernel constructors only if the kernel name is not yet bound. Fixes omlins#234 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@luraess Why does it not trigger now the GPU CI? |
Ah, I forgot, CSCS CI cannot run from forks. So to have it running one would need to rebase on a branch from PS's main. |
|
@albert-de-montserrat : thanks for the PR! There are unit tests that are looking for the old metadata functions (e.g. with |
omlins
left a comment
There was a problem hiding this comment.
There are unit tests that are looking for the old metadata functions (e.g. with ###META.) - this needs to be adapted in order to verify that the new metadata methods were created instead
|
Unit tests are passing now :) |
Since v0.16.1,
@parallel <kernelcall>reads the kernel's metadata (nb_parallel_indices,memopt) at launch. The name of the metadata function was derived from the callee expression, so the lookup only works when the kernel is called by its own name. Calling a kernel through a struct field or a function argument fails:Change
The metadata is now stored as an additional method of the kernel function itself,
and the call site emits
callee(ParallelStencil.KernelMetadata(), args...). Any callee expression that evaluates to the kernel (f,Mod.f,s.f, a function argument) thus finds the metadata by dispatch, in whatever scope the kernel is defined (includingletblocks and function bodies). This also covers module-qualified calls (#224) and replaces the special case added for them in #225. The lookup still returns a constant module, so withconstmetadatamemoptandnb_parallel_indicesremain constant-folded.The metadata method is defined after the kernel, as KernelAbstractions'
@kerneldefines the kernel constructors only if the kernel name is not yet bound.test/runtests.jl: the stderr filter for metadata method-overwrite warnings is updated to the new method signature.Tests
test/test_parallel.jl("6. metadata"):@metadataand@parallelcalled through a NamedTuple field and through a function argument.mainand gives the correct result with this change.Pkg.test()passes locally (Julia 1.13, macOS aarch64) with Threads, Polyester, KernelAbstractions (CPU) and Metal. CUDA and AMDGPU were not tested locally.Fixes #234
🤖 Generated with Claude Code