diff --git a/Project.toml b/Project.toml index bdf5201..5dea779 100644 --- a/Project.toml +++ b/Project.toml @@ -4,5 +4,6 @@ CFTime = "179af706-886a-5703-950a-314cd64e0468" ClimaOcean = "0376089a-ecfe-4b0e-a64f-9c555d74d754" Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09" OrthogonalSphericalShellGrids = "c2be9673-fb75-4747-82dc-aa2bb9f4aed0" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reactant = "3c362404-f566-11ee-1572-e11a4b42c853" Reactant_jll = "0192cb87-2b54-54ad-80e0-3be72ad8a3c0" diff --git a/oceananigans-dynamical-core/super_simple_simulation.jl b/oceananigans-dynamical-core/super_simple_simulation.jl index 839bc53..e2c4700 100644 --- a/oceananigans-dynamical-core/super_simple_simulation.jl +++ b/oceananigans-dynamical-core/super_simple_simulation.jl @@ -2,36 +2,50 @@ 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) # 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() 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ᵢ) # 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) @@ -39,16 +53,19 @@ pop!(r_simulation.callbacks, :nan_checker) 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)