-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use new ReactantState
architecture in super_simple_simulation.jl
#12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,53 +2,70 @@ using Oceananigans | |
using Reactant | ||
using Libdl | ||
using Reactant_jll | ||
using Random | ||
|
||
Reactant.Ops.DEBUG_MODE[] = true | ||
ENV["JULIA_DEBUG"] = "Reactant_jll" | ||
@show Reactant_jll.cuDriverGetVersion(dlopen("libcuda.so")) | ||
# ENV["JULIA_DEBUG"] = "Reactant_jll" | ||
# @show Reactant_jll.cuDriverGetVersion(dlopen("libcuda.so")) | ||
|
||
arch = GPU() # CPU() to run on CPU | ||
# Try to automatically guess whether we have a GPU available | ||
arch = isempty(find_library(["libcuda.so.1", "libcuda.so"])) ? CPU() : GPU() | ||
r_arch = Oceananigans.ReactantState() | ||
Nx, Ny, Nz = (360, 120, 100) # number of cells | ||
|
||
grid = LatitudeLongitudeGrid(arch, size=(Nx, Ny, Nz), halo=(7, 7, 7), | ||
longitude=(0, 360), latitude=(-60, 60), z=(-1000, 0)) | ||
r_grid = LatitudeLongitudeGrid(r_arch, size=(Nx, Ny, Nz), halo=(7, 7, 7), | ||
longitude=(0, 360), latitude=(-60, 60), z=(-1000, 0)) | ||
|
||
FT = Float64 | ||
t = ConcreteRNumber(zero(FT)) | ||
iter = ConcreteRNumber(0) | ||
stage = ConcreteRNumber(0) | ||
last_Δt = ConcreteRNumber(zero(FT)) | ||
last_stage_Δt = ConcreteRNumber(zero(FT)) | ||
r_clock = Clock(; time=t, iteration=iter, stage, last_Δt, last_stage_Δt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @glwagner to be clear, with CliMA/Oceananigans.jl#4096 how would I modify this? So that I can test it quickly locally There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with that PR you won't need this anymore because it will happen by default. (But you can still override the default if you want) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CliMA/Oceananigans.jl#4096 basically just wraps this code into a default so that we retain existing behavior but also extend when using a ReactantState architecture |
||
|
||
# One of the implest configurations we might consider: | ||
model = HydrostaticFreeSurfaceModel(; grid, momentum_advection=WENO()) | ||
r_model = HydrostaticFreeSurfaceModel(; grid=r_grid, clock=r_clock, momentum_advection=WENO()) | ||
|
||
@assert model.free_surface isa SplitExplicitFreeSurface | ||
@assert r_model.free_surface isa SplitExplicitFreeSurface | ||
|
||
Random.seed!(123) | ||
uᵢ(x, y, z) = randn() | ||
giordano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
set!(model, u=uᵢ, v=uᵢ) | ||
|
||
# First form a Reactant model | ||
r_model = Reactant.to_rarray(model) | ||
Random.seed!(123) | ||
set!(r_model, u=uᵢ, v=uᵢ) | ||
giordano marked this conversation as resolved.
Show resolved
Hide resolved
giordano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# What we normally do: | ||
@info "--> Running simulation with stock Oceananigans" | ||
simulation = Simulation(model, Δt=60, stop_iteration=2) | ||
run!(simulation) | ||
|
||
#using CUDA | ||
#CUDA.@device_code dir="cudajl" run!(simulation) | ||
|
||
# What we want to do with Reactant: | ||
@info "--> Running simulation with Reactant" | ||
r_simulation = Simulation(r_model, Δt=60, stop_iteration=2) | ||
pop!(r_simulation.callbacks, :nan_checker) | ||
# @show @code_hlo optimize=:before_kernel run!(r_simulation) | ||
|
||
r_run! = @compile sync = true run!(r_simulation) | ||
r_run!(r_simulation) | ||
|
||
@info "--> Re-running simulation with stock Oceananigans (with profiler)" | ||
Reactant.with_profiler("./notrace4/") do | ||
run!(simulation) | ||
end | ||
|
||
@info "--> Re-running simulation with Reactant (with profiler)" | ||
Reactant.with_profiler("./retrace4/") do | ||
r_run!(r_simulation) | ||
end | ||
|
||
using BenchmarkTools | ||
|
||
@btime run!(simulation) | ||
@btime r_run!(r_simulation) | ||
|
||
@info "--> Benchmark stock Oceananigans" | ||
@btime run!($simulation) | ||
@info "--> Benchmark Reactant" | ||
@btime r_run!($r_simulation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you also want to set the Reactant default to cpu vs gpu based on this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Reactant does it automatically already.