Skip to content

Commit

Permalink
Conditionally add AllocCheck in 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Dec 5, 2023
1 parent 69aaa0b commit 2b67d66
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
9 changes: 4 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ Enzyme = "0.11"
FiniteDiff = "2.8.1"
ForwardDiff = "0.10"
Graphs = "1"
LinearAlgebra = "1.6"
LinearAlgebra = "<0.0.1, 1"
PackageExtensionCompat = "1"
Random = "1.6"
Random = "<0.0.1, 1"
Reexport = "1"
SciMLOperators = "0.3.7"
Setfield = "1"
SparseArrays = "1.6"
SparseArrays = "<0.0.1, 1"
StaticArrayInterface = "1.3"
StaticArrays = "1"
Symbolics = "5.5"
Expand All @@ -62,7 +62,6 @@ Zygote = "0.6"
julia = "1.6"

[extras]
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
Expand All @@ -76,4 +75,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Test", "BandedMatrices", "BlockBandedMatrices", "Enzyme", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Symbolics", "Zygote", "StaticArrays", "AllocCheck"]
test = ["Test", "BandedMatrices", "BlockBandedMatrices", "Enzyme", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Symbolics", "Zygote", "StaticArrays"]
2 changes: 2 additions & 0 deletions test/allocs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const GROUP = get(ENV, "GROUP", "All")
const is_APPVEYOR = (Sys.iswindows() && haskey(ENV, "APPVEYOR"))
const is_TRAVIS = haskey(ENV, "TRAVIS")

function activate_gpu_env()
Pkg.activate("gpu")
function activate_env(env)
Pkg.activate(env)
Pkg.develop(PackageSpec(path = dirname(@__DIR__)))
Pkg.instantiate()
end
Expand Down Expand Up @@ -42,6 +42,7 @@ if GROUP == "Core" || GROUP == "All"
end

if GROUP == "InterfaceI" || GROUP == "All"
VERSION v"1.9" && activate_env("allocs")
@time @safetestset "Jac Vecs and Hes Vecs" begin
include("test_jaches_products.jl")
end
Expand All @@ -54,7 +55,7 @@ if GROUP == "InterfaceI" || GROUP == "All"
end

if GROUP == "GPU"
activate_gpu_env()
activate_env("gpu")
@time @safetestset "GPU AD" begin
include("test_gpu_ad.jl")
end
Expand Down
42 changes: 23 additions & 19 deletions test/test_sparse_jacobian.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Sparse Jacobian tests
using AllocCheck, SparseDiffTools,
using SparseDiffTools,
Symbolics, ForwardDiff, LinearAlgebra, SparseArrays, Zygote, Enzyme, Test, StaticArrays

@views function fdiff(y, x) # in-place
Expand Down Expand Up @@ -164,28 +164,32 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa
end
end

# Testing that the non-sparse jacobian's are non-allocating.
fvcat(x) = vcat(x, x)
@static if VERSION v"1.9"
using AllocCheck

x_sa = @SVector randn(Float32, 10);
# Testing that the non-sparse jacobian's are non-allocating.
fvcat(x) = vcat(x, x)

J_true_sa = ForwardDiff.jacobian(fvcat, x_sa)
x_sa = @SVector randn(Float32, 10);

@check_allocs function __sparse_jacobian_no_allocs(ad, sd, f::F, x) where {F}
return sparse_jacobian(ad, sd, f, x)
end
J_true_sa = ForwardDiff.jacobian(fvcat, x_sa)

@testset "Static Arrays" begin
@testset "No Allocations: $(difftype)" for difftype in (AutoSparseForwardDiff(),
AutoForwardDiff())
J = __sparse_jacobian_no_allocs(difftype, NoSparsityDetection(), fvcat, x_sa)
@test J J_true_sa
@check_allocs function __sparse_jacobian_no_allocs(ad, sd, f::F, x) where {F}
return sparse_jacobian(ad, sd, f, x)
end

@testset "Other Backends: $(difftype)" for difftype in (AutoSparseZygote(),
AutoZygote(), AutoSparseEnzyme(), AutoEnzyme(), AutoSparseFiniteDiff(),
AutoFiniteDiff())
J = sparse_jacobian(difftype, NoSparsityDetection(), fvcat, x_sa)
@test J J_true_sa
@testset "Static Arrays" begin
@testset "No Allocations: $(difftype)" for difftype in (AutoSparseForwardDiff(),
AutoForwardDiff())
J = __sparse_jacobian_no_allocs(difftype, NoSparsityDetection(), fvcat, x_sa)
@test J J_true_sa
end

@testset "Other Backends: $(difftype)" for difftype in (AutoSparseZygote(),
AutoZygote(), AutoSparseEnzyme(), AutoEnzyme(), AutoSparseFiniteDiff(),
AutoFiniteDiff())
J = sparse_jacobian(difftype, NoSparsityDetection(), fvcat, x_sa)
@test J J_true_sa
end
end
end
end

0 comments on commit 2b67d66

Please sign in to comment.