Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark all shifted indices unsafe in gradients #86

Merged
merged 2 commits into from
Mar 19, 2021
Merged

Mark all shifted indices unsafe in gradients #86

merged 2 commits into from
Mar 19, 2021

Conversation

mcabbott
Copy link
Owner

This should fix #85

Here the crucial part is tuple(), tuple(𝒶𝓍i, 𝒶𝓍j): the first set of indices are safe to multi-thread, the second are not, so this will be done sequentially:

julia> using Tullio

julia> reg(x) = @tullio res = sqrt(abs2(x[i, j] - x[i+1, j]) +abs2(x[i, j] - x[i, j+1])) verbose=2
...
┌ Info: <<<<< Gradient maker functionverbosetidy(ex_make) =quotelocal function ∇ℳ𝒶𝓀ℯ(𝛥ℛ::𝒯, ℛ, x) where 𝒯
│                local 𝛥x = fill!(similar(x, Base.promote_type(eltype(x), 𝒯)), 0)
│                local 𝒶𝓍j = intersect((axes)(x, 2), (axes)(x, 2), (axes)(x, 2), (axes)(x, 2) .- 1)
│                local 𝒶𝓍i = intersect((axes)(x, 1), (axes)(x, 1) .- 1, (axes)(x, 1), (axes)(x, 1))
│                (Tullio.∇threader)(∇𝒜𝒸𝓉!, (Tullio.storage_type)(𝛥x, x), tuple(𝛥x, (Tullio.OneBox)(𝛥ℛ), ℛ, x), tuple(), tuple(𝒶𝓍i, 𝒶𝓍j), 8457)
│                return (𝛥x,)
│            endend
...
┌ Warning: using KernelAbstractions with no outer indices, this will be slow
└ @ Tullio ~/.julia/dev/Tullio/src/macro.jl:1139

This also affects convolutions like @tullio a[i] := b[i-k] * c[k], which won't multi-thread at all.

Should add a test, perhaps to GPU set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential for race conditions with shifted indices
1 participant