Skip to content
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

Simulation tips may be a little misleading #3594

Open
glwagner opened this issue May 9, 2024 · 3 comments
Open

Simulation tips may be a little misleading #3594

glwagner opened this issue May 9, 2024 · 3 comments
Labels
documentation 📜 The sacred scrolls

Comments

@glwagner
Copy link
Member

glwagner commented May 9, 2024

The Simulation tips section of the docs probably needs updating. For example it says

For example, if can be difficult to just view a CuArray since Julia needs to access its elements to do that. Consider the example below:

This example is contrived though; the problem is that the show method for OffsetArrays has scalar indexing. But the show method for CuArray works fine, so

julia> using Oceananigans

julia> grid = RectilinearGrid(GPU(), size=(1, 1, 1), extent=(1, 1, 1), halo=(1, 1, 1))
1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on GPU with 1×1×1 halo
├── Periodic x  [0.0, 1.0)  regularly spaced with Δx=1.0
├── Periodic y  [0.0, 1.0)  regularly spaced with Δy=1.0
└── Bounded  z  [-1.0, 0.0] regularly spaced with Δz=1.0

julia> c = CenterField(grid)
1×1×1 Field{Center, Center, Center} on RectilinearGrid on GPU
├── grid: 1×1×1 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on GPU with 1×1×1 halo
├── boundary conditions: FieldBoundaryConditions
│   └── west: Periodic, east: Periodic, south: Periodic, north: Periodic, bottom: ZeroFlux, top: ZeroFlux, immersed: ZeroFlux
└── data: 3×3×3 OffsetArray(::CUDA.CuArray{Float64, 3, CUDA.Mem.DeviceBuffer}, 0:2, 0:2, 0:2) with eltype Float64 with indices 0:2×0:2×0:2
    └── max=0.0, min=0.0, mean=0.0

julia> c.data.parent
3×3×3 CUDA.CuArray{Float64, 3, CUDA.Mem.DeviceBuffer}:
[:, :, 1] =
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

[:, :, 2] =
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

[:, :, 3] =
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

The example also creates a model which is probably overkill, a Field would do.

Also, the example uses

julia> adapt(Array, model.velocities.u.data)

To show an array on CPU. But we have a built-in method on_archiecture(CPU(), field) that would probably be better to use, since its more flexible and also generalizes to distributed architectures, etc...

@glwagner glwagner added the documentation 📜 The sacred scrolls label May 9, 2024
@navidcy
Copy link
Collaborator

navidcy commented Aug 17, 2024

I also just noticed that this statement:

```julia
T₀ = 20 # ᵒC
surface_temperature(x, y, t) = T₀ * sin(2π / 86400 * t)
T_bcs = FieldBoundaryConditions(bottom = GradientBoundaryCondition(surface_temperature))
```
will throw an error if run on the GPU (and will run more slowly than it should on the CPU).

is wrong since the above code does not error. I believe the error will pop up down the line, when we try to pass this boundary condition to a model that uses a grid that lives on the GPU.

@glwagner
Copy link
Member Author

right!

@glwagner
Copy link
Member Author

Why don't we try to doctest / example this since we run docs on GPU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 📜 The sacred scrolls
Projects
None yet
Development

No branches or pull requests

2 participants