Mercurial > repos > public > sbplib_julia
changeset 1886:9ce6d939dfae allocation_testing
Start experimenting with allocation testing
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 07 Apr 2022 07:37:02 +0200 |
parents | 03f65ef8adb9 |
children | 24590890e124 |
files | test/Manifest.toml test/Project.toml test/SbpOperators/allocations_test.jl |
diffstat | 3 files changed, 310 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/test/Manifest.toml Thu Apr 07 07:30:00 2022 +0200 +++ b/test/Manifest.toml Thu Apr 07 07:37:02 2022 +0200 @@ -12,6 +12,12 @@ [[deps.Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +[[deps.BenchmarkTools]] +deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"] +git-tree-sha1 = "4c10eee4af024676200bc7752e536f858c6b8f93" +uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +version = "1.3.1" + [[deps.ChainRulesCore]] deps = ["Compat", "LinearAlgebra", "SparseArrays"] git-tree-sha1 = "9950387274246d08af38f6eef8cb5480862a435f" @@ -93,6 +99,12 @@ uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" version = "1.4.1" +[[deps.JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.3" + [[deps.LibCURL]] deps = ["LibCURL_jll", "MozillaCACerts_jll"] uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" @@ -161,6 +173,12 @@ uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" version = "0.5.5+0" +[[deps.Parsers]] +deps = ["Dates"] +git-tree-sha1 = "621f4f3b4977325b9128d5fae7a8b4829a0c2222" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.2.4" + [[deps.Pkg]] deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -175,6 +193,10 @@ deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" +[[deps.Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + [[deps.REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
--- a/test/Project.toml Thu Apr 07 07:30:00 2022 +0200 +++ b/test/Project.toml Thu Apr 07 07:37:02 2022 +0200 @@ -1,4 +1,5 @@ [deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" Glob = "c27321d9-0574-5035-807b-f59d2c89b15c" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/SbpOperators/allocations_test.jl Thu Apr 07 07:37:02 2022 +0200 @@ -0,0 +1,287 @@ +using Test +using BenchmarkTools + +using Sbplib.Grids +using Sbplib.SbpOperators + +using Sbplib.LazyTensors +using Sbplib.RegionIndices + +@testset "Allocations" begin + stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml", order=4) + + @testset "1D" begin + g₁ = EquidistantGrid(15, 0.,1.) + + H = inner_product(g₁, stencil_set) + H⁻¹ = inverse_inner_product(g₁, stencil_set) + D₂ = second_derivative(g₁, stencil_set, 1) + + eₗ = boundary_restriction(g₁, stencil_set, CartesianBoundary{1,Lower}()) + eᵣ = boundary_restriction(g₁, stencil_set, CartesianBoundary{1,Upper}()) + + dₗ = normal_derivative(g₁, stencil_set, CartesianBoundary{1,Lower}()) + dᵣ = normal_derivative(g₁, stencil_set, CartesianBoundary{1,Upper}()) + + + + @testset "Derivative operator" begin + v = rand(size(g₁)...) + @test (@ballocated LazyTensors.apply($D₂, $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($D₂, $v, 6)) == 0 + @test (@ballocated LazyTensors.apply($D₂, $v, 15)) == 0 + end + + @testset "inner_product operator" begin + v = rand(size(g₁)...) + + @test (@ballocated LazyTensors.apply($H, $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 6)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 15)) == 0 + + @test (@ballocated LazyTensors.apply($(H∘H), $v, 5)) == 0 + end + + @testset "inverse_inner_product operator" begin + v = rand(size(g₁)...) + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15)) == 0 + end + + @testset "boundary operators" begin + v = rand(size(g₁)...) + @test (@ballocated LazyTensors.apply($eₗ, $v)) == 0 + @test (@ballocated LazyTensors.apply($eᵣ, $v)) == 0 + @test (@ballocated LazyTensors.apply($dₗ, $v)) == 0 + @test (@ballocated LazyTensors.apply($dᵣ, $v)) == 0 + end + + @testset "boundary operator transposes" begin + v = fill(1.) + @test (@ballocated LazyTensors.apply($eₗ', $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($eₗ', $v, 7)) == 0 + @test (@ballocated LazyTensors.apply($eₗ', $v, 15)) == 0 + + @test (@ballocated LazyTensors.apply($eᵣ', $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($eᵣ', $v, 7)) == 0 + @test (@ballocated LazyTensors.apply($eᵣ', $v, 15)) == 0 + + @test (@ballocated LazyTensors.apply($dₗ', $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($dₗ', $v, 7)) == 0 + @test (@ballocated LazyTensors.apply($dₗ', $v, 15)) == 0 + + @test (@ballocated LazyTensors.apply($dᵣ', $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($dᵣ', $v, 7)) == 0 + @test (@ballocated LazyTensors.apply($dᵣ', $v, 15)) == 0 + end + + @testset "sat terms" begin + v = rand(size(g₁)...) + neumannSATₗ = H⁻¹∘eₗ'∘dₗ + neumannSATᵣ = H⁻¹∘eᵣ'∘dᵣ + + + @test (@ballocated LazyTensors.apply($neumannSATₗ, $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSATₗ, $v, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSATₗ, $v, 15)) == 0 + + @test (@ballocated LazyTensors.apply($neumannSATᵣ, $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSATᵣ, $v, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSATᵣ, $v, 15)) == 0 + end + end + + + @testset "2D" begin + g₂ = EquidistantGrid((15,15), (0.,0.),(1.,1.)) + + H = inner_product(g₂, stencil_set) + H⁻¹ = inverse_inner_product(g₂, stencil_set) + D₂x = second_derivative(g₂, stencil_set, 1) + D₂y = second_derivative(g₂, stencil_set, 2) + + e₁ₗ = boundary_restriction(g₂, stencil_set, CartesianBoundary{1,Lower}()) + e₁ᵤ = boundary_restriction(g₂, stencil_set, CartesianBoundary{1,Upper}()) + e₂ₗ = boundary_restriction(g₂, stencil_set, CartesianBoundary{2,Lower}()) + e₂ᵤ = boundary_restriction(g₂, stencil_set, CartesianBoundary{2,Upper}()) + + d₁ₗ = normal_derivative(g₂, stencil_set, CartesianBoundary{1,Lower}()) + d₁ᵤ = normal_derivative(g₂, stencil_set, CartesianBoundary{1,Upper}()) + d₂ₗ = normal_derivative(g₂, stencil_set, CartesianBoundary{2,Lower}()) + d₂ᵤ = normal_derivative(g₂, stencil_set, CartesianBoundary{2,Upper}()) + + H₁ₗ = inner_product(boundary_grid(g₂, CartesianBoundary{1,Lower}()), stencil_set) + H₁ᵤ = inner_product(boundary_grid(g₂, CartesianBoundary{1,Upper}()), stencil_set) + H₂ₗ = inner_product(boundary_grid(g₂, CartesianBoundary{2,Lower}()), stencil_set) + H₂ᵤ = inner_product(boundary_grid(g₂, CartesianBoundary{2,Upper}()), stencil_set) + + + @testset "Derivative operator" begin + v = rand(size(g₂)...) + @test (@ballocated LazyTensors.apply($D₂x, $v, 1, 7)) == 0 + @test (@ballocated LazyTensors.apply($D₂x, $v, 6, 7)) == 0 + @test (@ballocated LazyTensors.apply($D₂x, $v, 15, 7)) == 0 + + @test (@ballocated LazyTensors.apply($D₂y, $v, 7, 1)) == 0 + @test (@ballocated LazyTensors.apply($D₂y, $v, 7, 6)) == 0 + @test (@ballocated LazyTensors.apply($D₂y, $v, 7, 15)) == 0 + + @test (@ballocated LazyTensors.apply($(D₂x∘D₂y), $v, 1, 1)) == 0 + @test (@ballocated LazyTensors.apply($(D₂x∘D₂y), $v, 7, 6)) == 0 + @test (@ballocated LazyTensors.apply($(D₂x∘D₂y), $v, 15, 15)) == 0 + end + + @testset "inner_product operator" begin + v = rand(size(g₂)...) + @test (@ballocated LazyTensors.apply($H, $v, 1, 1)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 1, 6)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 1, 15)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 6, 1)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 6, 6)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 6, 15)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 15, 1)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 15, 6)) == 0 + @test (@ballocated LazyTensors.apply($H, $v, 15, 15)) == 0 + + + @test (@ballocated LazyTensors.apply($(H∘H), $v, 5, 5)) == 0 + end + + @testset "inverse_inner_product operator" begin + v = rand(size(g₂)...) + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1, 1)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1, 6)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 1, 15)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6, 1)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6, 6)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 6, 15)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15, 1)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15, 6)) == 0 + @test (@ballocated LazyTensors.apply($H⁻¹, $v, 15, 15)) == 0 + end + + @testset "boundary operators" begin + v = rand(size(g₂)...) + @test (@ballocated LazyTensors.apply($e₁ₗ, $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($e₁ᵤ, $v, 5)) == 0 + @test (@ballocated LazyTensors.apply($e₂ₗ, $v, 15)) == 0 + @test (@ballocated LazyTensors.apply($e₂ᵤ, $v, 3)) == 0 + + @test (@ballocated LazyTensors.apply($d₁ₗ, $v, 5)) == 0 + @test (@ballocated LazyTensors.apply($d₁ᵤ, $v, 15)) == 0 + @test (@ballocated LazyTensors.apply($d₂ₗ, $v, 1)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ, $v, 5)) == 0 + end + + @testset "boundary operator transposes" begin + v = rand(first(size(g₂))) + + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 1, 1)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 1, 6)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 1, 15)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 6, 1)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 6, 6)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 6, 15)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 15, 1)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 15, 6)) == 0 + @test (@ballocated LazyTensors.apply($e₁ₗ', $v, 15, 15)) == 0 + + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 1, 1)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 1, 6)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 1, 15)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 6, 1)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 6, 6)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 6, 15)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 15, 1)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 15, 6)) == 0 + @test (@ballocated LazyTensors.apply($d₂ᵤ', $v, 15, 15)) == 0 + end + + @testset "sat terms" begin + v = rand(size(g₂)...) + u = rand(size(g₂)[1]) + # neumannSAT₁ₗ = H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ + # neumannSAT₂ᵤ = H⁻¹∘e₂ᵤ'∘H₂ᵤ∘d₂ᵤ + + neumannSAT₁ₗ = e₁ₗ'∘d₁ₗ + neumannSAT₂ᵤ = e₂ᵤ'∘d₂ᵤ + + # indices = [1,6,15] + indices = [1] + + @testset for i ∈ indices + @testset for j ∈ indices + @test (@ballocated LazyTensors.apply($(e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(d₁ₗ'∘e₁ₗ), $v, $i, $j)) == 0 + + @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 + @test_broken (@ballocated LazyTensors.apply($(e₁ₗ'∘H₁ₗ∘d₁ₗ∘H⁻¹), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 + @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(H⁻¹∘D₂x), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(H⁻¹∘D₂y), $v, $i, $j)) == 0 + @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘D₂x∘D₂y), $v, $i, $j)) == 0 + @test_broken (@ballocated LazyTensors.apply($(D₂x∘e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 + @test_broken (@ballocated LazyTensors.apply($(D₂y∘e₁ₗ'∘H₁ₗ∘d₁ₗ), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(D₂x∘e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(D₂y∘e₁ₗ'∘d₁ₗ), $v, $i, $j)) == 0 + + @test (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'), $u, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(e₁ₗ'∘H₁ₗ), $u, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ), $v, $i)) == 0 + + @test_broken (@ballocated LazyTensors.apply($(H⁻¹∘e₁ₗ'∘H₁ₗ), $u, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(H₁ₗ∘e₁ₗ∘H⁻¹), $v, $i)) == 0 + @test (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ∘H⁻¹), $v, $i)) == 0 + + @test_broken (@ballocated LazyTensors.apply($(e₁ₗ'∘e₁ₗ∘e₁ₗ'∘e₁ₗ), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(e₁ₗ'∘e₁ₗ∘e₁ₗ'), $u, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(e₁ₗ∘e₁ₗ'∘e₁ₗ), $v, $i)) == 0 + @test (@ballocated LazyTensors.apply($(e₁ₗ'∘e₁ₗ), $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(e₁ₗ∘e₁ₗ'), $u, $i)) == 0 + + + @test (@ballocated LazyTensors.apply($H, $v, $i, $j)) == 0 + @test (@ballocated LazyTensors.apply($(H∘H), $v, $i, $j)) == 0 + @test_broken (@ballocated LazyTensors.apply($(H∘H∘H), $v, $i, $j)) == 0 + @test_broken (@ballocated LazyTensors.apply($(H∘H∘H∘H), $v, $i, $j)) == 0 + end + @test (@ballocated LazyTensors.apply($(e₁ₗ∘d₁ₗ'), $u, $i)) == 0 + @test (@ballocated LazyTensors.apply($(d₁ₗ∘e₁ₗ'), $u, $i)) == 0 + + @test (@ballocated LazyTensors.apply($(e₁ₗ∘H∘d₁ₗ'), $u, $i)) == 0 + @test (@ballocated LazyTensors.apply($(d₁ₗ∘H∘e₁ₗ'), $u, $i)) == 0 + + @test (@ballocated LazyTensors.apply($(H₁ₗ∘e₁ₗ∘d₁ₗ'), $u, $i)) == 0 + @test (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ∘e₁ₗ'), $u, $i)) == 0 + + @test_broken (@ballocated LazyTensors.apply($(H₁ₗ∘e₁ₗ∘H∘d₁ₗ'), $u, $i)) == 0 + @test_broken (@ballocated LazyTensors.apply($(H₁ₗ∘d₁ₗ∘H∘e₁ₗ'), $u, $i)) == 0 + + @test_broken (@ballocated LazyTensors.apply($(e₁ₗ∘H∘d₁ₗ'∘H₁ₗ), $u, $i)) == 0 + @test_broken (@ballocated LazyTensors.apply($(d₁ₗ∘H∘e₁ₗ'∘H₁ₗ), $u, $i)) == 0 + end + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 1, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 1, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 1, 15)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 6, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 6, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 6, 15)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 15, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 15, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₁ₗ, $v, 15, 15)) == 0 + + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 1, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 1, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 1, 15)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 6, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 6, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 6, 15)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 15, 1)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 15, 6)) == 0 + @test (@ballocated LazyTensors.apply($neumannSAT₂ᵤ, $v, 15, 15)) == 0 + end + + end +end