You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to this, I ran into a problem (or at least inconvenience) when defining local anonymous functions inside kernels:
@kernel function foo(v)
bar = x -> begin y = 2*x; return y end
ID = @index(Global)
v[ID] = bar(v[ID])
end
Is not allowed by KernelAbstractions and tells me that I can't use return inside a kernel, even though this return clearly doesn't return from the kernel. This problem is fixed if I use instead:
@kernel function foo(v)
bar = x -> begin y = 2*x; y end
ID = @index(Global)
v[ID] = bar(v[ID])
end
Fixed by #556, which removed the check: return and return nothing are accepted in 0.10, including early returns and return inside closures defined in the kernel.
@kernelfunctionf!(A)
i =@index(Global)
bar = x ->begin y =2x; return y end
i >2&&return
A[i] =bar(i)
returnnothingend
Activity
vchuravy commentedon Dec 18, 2023
KernelAbstractions will politly ignore those and insert a
return nothingfor you.But yes we could explicitly allow
returnorreturn nothingpxl-th commentedon Jan 9, 2024
Closed by #446.
AntonReinhard commentedon Oct 22, 2025
Related to this, I ran into a problem (or at least inconvenience) when defining local anonymous functions inside kernels:
Is not allowed by KernelAbstractions and tells me that I can't use
returninside a kernel, even though this return clearly doesn't return from the kernel. This problem is fixed if I use instead:Which is valid, compiles, and runs as expected.
szabo137 commentedon Oct 22, 2025
+1 on that
maleadt commentedon Oct 19, 2026
Fixed by #556, which removed the check:
returnandreturn nothingare accepted in 0.10, including early returns andreturninside closures defined in the kernel.