-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
module SemiTest | ||
using Test | ||
using Trixi | ||
using TrixiEnzyme | ||
|
||
# %% | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module UpwindTest | ||
using Test | ||
using TrixiEnzyme | ||
using TrixiEnzyme: upwind! | ||
using ForwardDiff | ||
|
||
x = -1:0.005:1 | ||
batch_size = 2 | ||
jacobian_enzyme_forward(TrixiEnzyme.upwind!, x, N=batch_size) | ||
|
||
Δt₁ = @elapsed J1 = jacobian_enzyme_forward(TrixiEnzyme.upwind!, x) | ||
|
||
Δt₂ = @elapsed begin | ||
u = zeros(length(x)) | ||
du = zeros(length(x)) | ||
cfg = ForwardDiff.JacobianConfig(nothing, du, u) | ||
uEltype = eltype(cfg) | ||
nan_uEltype=convert(uEltype, NaN) | ||
numerical_flux=fill(nan_uEltype, length(u)) | ||
|
||
J2 = ForwardDiff.jacobian(du, u, cfg) do du_ode, u_ode | ||
upwind!(du_ode, u_ode, (;v=1.0, numerical_flux)); | ||
end; | ||
|
||
end; # 0.326764 seconds (1.09 M allocations: 75.013 MiB, 7.28% gc time, 99.87% compilation time) | ||
|
||
@test J1 = J2 | ||
|
||
@info "Compare the time consumed by Enzyme.jl Δt and ForwardDiff.jl..." | ||
println("Enzyme: ", Δt₁) | ||
println("ForwardDiff: ", Δt₂) | ||
|
||
end |