Skip to content

More LoopVectorization tests & checks #57

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

Merged
merged 40 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4b91f76
only load Dual overloads with LV 0.8
Dec 12, 2020
65449e1
tweak tests of onlyone(Mask ,...)
Dec 12, 2020
0714e64
tweak
Dec 12, 2020
877903f
gradient fiddling
Dec 12, 2020
fa7d3a7
turn on some more gradient tests
Dec 12, 2020
0f7cb66
make testsets
Dec 12, 2020
93f3ce5
convolutions...
Dec 13, 2020
d11c3c3
turn grad=Dual tests on 1.4 back on
Dec 13, 2020
05d4180
tweaks
Dec 13, 2020
68f2e73
skip 3 tests
Dec 13, 2020
0be01bd
oops
Dec 13, 2020
9d1d51e
oops
Dec 13, 2020
ba2b151
tidy up runtests after bad rebase
Dec 17, 2020
61a9194
skip some tests on nightly
Dec 19, 2020
abbacee
restore LV testing on nightly
Dec 20, 2020
87358aa
try 6 threads
Dec 20, 2020
0c1227b
padding conditional store, without else clause
Dec 21, 2020
21dda72
VectorizationBase 0.14
Dec 21, 2020
2762a4f
widen signature of allzero(seen::Vec{N,Int}))
Dec 21, 2020
1e86d2e
Zygote 0.6
Dec 21, 2020
440b838
disable avx for min/max grad
Dec 21, 2020
e6d5151
readme
Dec 21, 2020
d3d688f
disable avx in min/max grad, correctly & visibly
Dec 21, 2020
90bb1ba
versions
Dec 22, 2020
4a96e91
VectorizationBase 0.14.8
Dec 24, 2020
cedff62
restore Base.last hack for old LV
Dec 24, 2020
f8cc7d7
skip two
Dec 24, 2020
4dd82ac
update compat bounds
Jan 21, 2021
a68c11b
re-enable zygote on 1.6
Jan 21, 2021
5819089
disable anyone / onlyone, vectorised min/max grad already disabled
Jan 21, 2021
8178df7
add some space
Jan 21, 2021
3840437
add some links
Jan 21, 2021
f15efed
one more skip
Jan 21, 2021
7536064
skip Zygote on nightly
Jan 21, 2021
e911775
bump
Jan 21, 2021
fd16709
bump
Jan 22, 2021
f6a60d7
stop CI early on multi-threaded group-3
mcabbott Jan 22, 2021
e4b8c9d
stop CI early on multi-threaded group-3, take II
mcabbott Jan 22, 2021
80f2f9f
trivial commit
Jan 23, 2021
09b60f1
disable LV grad checks on CI completely
Jan 23, 2021
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
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
JULIA_NUM_THREADS: "1"
JULIA_NUM_THREADS: "6"
# SECRET_CODECOV_TOKEN: "..."

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-julia-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
tags: '*'
jobs:
test-julia-nightly:
name: NIGHTLY/t-${{ matrix.threads }}/group-${{ matrix.group }}/${{ github.event_name }}/${{ matrix.arch }}+${{ matrix.os }}
name: NIGHTLY -t${{ matrix.threads }} / group-${{ matrix.group }} / ${{ github.event_name }} / ${{ matrix.os }}+${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -24,7 +24,7 @@ jobs:
- ubuntu-latest
threads:
- '1'
- '2'
- '6'
version:
- 'nightly'
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
tags: '*'
jobs:
test:
name: v${{ matrix.version }}/t-${{ matrix.threads }}/group-${{ matrix.group }}/${{ github.event_name }}/${{ matrix.arch }}+${{ matrix.os }}
name: v${{ matrix.version }} -t${{ matrix.threads }} / group-${{ matrix.group }} / ${{ github.event_name }} / ${{ matrix.os }}+${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -24,7 +24,7 @@ jobs:
- ubuntu-latest
threads:
- '1'
- '2'
- '6' # t>2 might be ignored on Julia <= 1.5
version:
- '1.4'
- '1' # automatically expands to the latest stable 1.x release of Julia
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ CUDA = "1, 2"
DiffRules = "1"
FillArrays = "0.10"
ForwardDiff = "0.10"
KernelAbstractions = "0.4"
LoopVectorization = "0.8.26, 0.9.7"
KernelAbstractions = "0.5.2"
LoopVectorization = "0.8.26, 0.9.20"
NamedDims = "0.2"
OffsetArrays = "1"
Requires = "1"
TensorOperations = "3"
Tracker = "0.2"
VectorizationBase = "0.12.33, 0.13.10"
Zygote = "0.5"
VectorizationBase = "0.12.33, 0.15.7"
Zygote = "0.6"
julia = "1.3"

[extras]
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ using Tullio
A = [abs2(i - 11) for i in 1:21]

# Downsample -- range of i is that allowed by both terms:
@tullio D[i] := (A[2i] + A[2i+1])/2 # 1:10 == intersect(1:10, 0:10)
@tullio B[i] := (A[2i] + A[2i+1])/2 # 1:10 == intersect(1:10, 0:10)

# Shifts -- range of i calculated in terms of that given for j:
@tullio M[i,j] := A[i+j-1] (j in 1:15) # i in 1:7
Expand Down Expand Up @@ -129,6 +129,9 @@ fft(S) ≈ @tullio F[k] := S[x] * exp(-im*pi/8 * (k-1) * x) (k ∈ axes(S,1))
@tullio (*) P[i] := A[i+k] (k in 0:2) # product
@tullio (max) X[i,_] := D[i,j] # maximum(D, dims=2), almost

min1(x,y) = ifelse(first(x) < first(y), x, y); # findmin(D, dims=1), almost:
@tullio (min1) Ts[j+_] := (D[i,j], (i,j)) init=(typemax(Int), (0,0))

# Access to fields & arrays -- this uses j ∈ eachindex(first(N).c)
N = [(a=i, b=i^2, c=fill(i^3,3)) for i in 1:10]
@tullio T[i,j] := (N[i].a // 1, N[i].c[j])
Expand Down Expand Up @@ -449,7 +452,7 @@ Front-end near-lookalikes:

* [Einsum.jl](https://github.com/ahwillia/Einsum.jl) makes simple loops. See [tests/einsum.jl](https://github.com/mcabbott/Tullio.jl/blob/master/test/einsum.jl) where `using Tullio: @einsum` is an almost-seamless replacement.

* [TensorOperations.jl](https://github.com/Jutho/TensorOperations.jl) and [OMEinsum.jl](https://github.com/under-Peter/OMEinsum.jl) identify patterns on which they can call various basic operations.
* [TensorOperations.jl](https://github.com/Jutho/TensorOperations.jl) and [OMEinsum.jl](https://github.com/under-Peter/OMEinsum.jl) identify patterns on which they can call various basic operations. [TensorRules.jl](https://github.com/ho-oto/TensorRules.jl) makes `@tensor` differentiable; see also [TensorGrad.jl](https://github.com/mcabbott/TensorGrad.jl) and [TensorTrack.jl](https://github.com/mcabbott/TensorTrack.jl) for earlier attempts.

* [TensorCast.jl](https://github.com/mcabbott/TensorCast.jl) expresses everything as Julia array operations, broadcasting and reduction. (OMEinsum.jl also treats some cases as a special lazy broadcast-reduction.)

Expand Down
20 changes: 9 additions & 11 deletions src/eval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,27 @@ using Requires
using .LoopVectorization
if isdefined(LoopVectorization, :SVec) # version 0.8, for Julia ⩽1.5
using .LoopVectorization.VectorizationBase: SVec, Mask, prevpow2
@require ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" begin
# Dual numbers + svec, not needed on version 0.9
include("grad/avxdual.jl")
end
else # version 0.9, supports Julia 1.6
using .LoopVectorization.VectorizationBase: Vec, Mask, prevpow2
SVec{N,T} = Vec{N,T}
end

#=
# Functions needed for safe vectorised max gradient
@inline Tullio.onlyone(cond::Bool, seen::SVec) = cond && allzero(seen)

@inline Tullio.onlyone(cond::Mask{W}) where {W} = Mask{W}(prevpow2(cond.u))
@inline Tullio.onlyone(cond::Mask, seen::Union{Int,SVec}) =
Tullio.allzero(seen) ? Tullio.onlyone(cond) : zero(cond)

@inline allzero(seen::Int) = iszero(seen)
@inline allzero(seen::SVec{N,Int}) where {N} = iszero((!iszero(seen)).u)

# @inline Tullio.anyone(cond::Mask) = cond != zero(cond)
@inline Tullio.anyone(cond::Mask) = cond.u != zero(cond).u # for v0.9
@inline allzero(seen::Integer) = iszero(seen)
@inline allzero(seen::SVec) = iszero((!iszero(seen)).u)

@require ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" begin
# Dual numbers + svec, should live in PaddedMatricesForwardDiff?
# (And where would the conditional loading go, still here?)
include("grad/avxdual.jl")
end
@inline Tullio.anyone(cond::Mask) = !iszero(cond.u)
=#
end

#========== CuArrays ==========#
Expand Down
4 changes: 2 additions & 2 deletions src/forward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function insert_forward_gradient(axislist, store)

defineepsilons, readepsilons = [], []
for (d, (Aepsilon, Aex)) in enumerate(epsilondict)
basis = [i==d ? :(one($TYP)) : :(zero($TYP)) for i in 1:length(epsilondict)]
push!(defineepsilons, :($Aepsilon = ForwardDiff.Dual(zero($TYP), ($(basis...),))))
basis = [i==d ? :($one($TYP)) : :($zero($TYP)) for i in 1:length(epsilondict)]
push!(defineepsilons, :($Aepsilon = ForwardDiff.Dual($zero($TYP), ($(basis...),))))
push!(readepsilons, :($Aex = $Aex + ForwardDiff.partials($ZED, $d) * $dZ[$(store.leftraw...)]))
end

Expand Down
18 changes: 10 additions & 8 deletions src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ padmodclamp_replace(s, store, inside=false) = s
padmodclamp_replace(ex::Expr, store, inside=false) =
if ex.head == :(=) && @capture_(ex.args[1], A_[inds__])
# This tricky case is 𝛥A[pad(i,2)] = 𝛥A[pad(i,2)] + ...
Aex, fun = padmodclamp_pair(A, inds, store)
Aex, fun = padmodclamp_pair(A, inds, store, true)
right = if fun != identity
padmodclamp_replace(ex.args[2], store, true)
else
Expand All @@ -481,7 +481,7 @@ padmodclamp_replace(ex::Expr, store, inside=false) =
Expr(ex.head, args...)
end

padmodclamp_pair(A, inds, store) = begin
padmodclamp_pair(A, inds, store, assign=false) = begin
nopadif = []
inds4 = map(enumerate(inds)) do (d,ex)
isexpr(ex, :call) || return ex
Expand All @@ -494,7 +494,8 @@ padmodclamp_pair(A, inds, store) = begin
elseif ex.args[1] == :pad && length(ex.args) >= 2
i = ex.args[2]
if !all(==(0), ex.args[3:end]) || length(ex.args) == 2
push!(nopadif, :($i ∈ $axes($A,$d)))
# push!(nopadif, :($i >= first(axes($A,$d))), :($i <= last(axes($A,$d)))) # allows avx
push!(nopadif, :($i >= first(axes($A,$d))), :($i <= Base.last(axes($A,$d)))) # allows avx... but LV 0.8, Julia 1.4, needs Base?
end
return i
end
Expand All @@ -508,8 +509,10 @@ padmodclamp_pair(A, inds, store) = begin
for c2 in nopadif[2:end]
cond = :($cond & $c2)
end
if store.padkeyword == TYP # default
ex -> :($cond ? $ex : $zero($eltype($A)))
if assign # for gradients, this wraps 𝛥A[pad(i,2)] = 𝛥A[pad(i,2)] + ...
ex -> :($cond && $ex)
elseif store.padkeyword == TYP # default, pad with zero
ex -> :($cond ? $ex : zero(eltype($A)))
else
ex -> :($cond ? $ex : $convert($eltype($A), $(store.padkeyword)))
end
Expand Down Expand Up @@ -1070,16 +1073,15 @@ function make_many_actors(act!, args, ex1, outer::Vector, ex3, inner::Vector, ex
safe = if act! == ACT!
isempty(store.unsafeleft)
else # working on ∇act!
isempty(store.unsaferight) &&
store.redfun == :+ && # Disable @avx for min/max grad, #53
store.grad != :Dual # and for use with ForwardDiff
isempty(store.unsaferight)
end

if safe && store.avx != false && isdefined(store.mod, :LoopVectorization)
unroll = store.avx == true ? 0 : store.avx # unroll=0 is the default setting
info1 = store.verbose>0 ? :(@info "running LoopVectorization actor $($note)" maxlog=3 _id=$(hash(store))) : nothing
check1 = store.verbose>0 ? :(LoopVectorization.check_args($(store.arrays...)) || @error "rejected by LoopVectorization's check_args! $($note)" maxlog=3 _id=$(hash(store))) : nothing
try
act! == ACT! || store.redfun == :+ || throw("use of LoopVectorization for min/max gradients is disabled")
lex = if isnothing(exloopfinal)
quote

Expand Down
Loading