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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ function parse_input(expr, store)
unique!(store.leftind)
store.sharedind = unique!(setdiff(store.sharedind, store.notfree))
store.rightind = unique!(setdiff(store.rightind, store.notfree))
union!(store.unsaferight, store.shiftedind)
any(==(:_), vcat(store.leftind, store.rightind)) && throw("can't use _ as an index name")

unique!(store.outpre) # kill mutiple assertions, and evaluate any f(A) only once
Expand Down
4 changes: 2 additions & 2 deletions test/cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Tullio, Test
using CUDA, KernelAbstractions
CUDA.allowscalar(false)
using Tracker
using Tracker, ForwardDiff
@tullio grad=Base

# matmul
Expand All @@ -17,14 +17,14 @@ A = rand(3,40); B = rand(40,500);
@test Ξ”A β‰ˆ ones(3,500) * B'
@test cu(Ξ”A) β‰ˆ Tracker.gradient((A,B) -> sum(mul(A, B)), cu(A), cu(B))[1]

#=
# shifts
@tullio D[i,j] := A[i,j+k] k in 0:10
@test axes(D) == (1:3, 1:30)
@tullio cD[i,j] := cu(A)[i,j+k] k in 0:10
@test cD isa CuArray
@test cD β‰ˆ cu(D)

#=
# ranges
@tullio E[i,j] := A[i,j+k-1] + (-1:0.5:1)[k]
@test axes(E) == (1:3, 1:36)
Expand Down