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

Default type Float32 on GPU #266

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CuFourierFlows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
plan_flows_fft(a::CuArray, args...; flags=nothing, kwargs...) = plan_fft(a, args...; kwargs...)
plan_flows_rfft(a::CuArray, args...; flags=nothing, kwargs...) = plan_rfft(a, args...; kwargs...)

OneDGrid(dev::GPU, args...; kwargs...) = OneDGrid(args...; ArrayType=CuArray, kwargs...)
TwoDGrid(dev::GPU, args...; kwargs...) = TwoDGrid(args...; ArrayType=CuArray, kwargs...)
ThreeDGrid(dev::GPU, args...; kwargs...) = ThreeDGrid(args...; ArrayType=CuArray, kwargs...)
OneDGrid(dev::GPU, args...; kwargs...) = OneDGrid(args...; ArrayType=CuArray, T=Float32, kwargs...)
TwoDGrid(dev::GPU, args...; kwargs...) = TwoDGrid(args...; ArrayType=CuArray, T=Float32, kwargs...)
ThreeDGrid(dev::GPU, args...; kwargs...) = ThreeDGrid(args...; ArrayType=CuArray, T=Float32, kwargs...)

function Base.zeros(::GPU, T, dims)
a = CuArray{T}(undef, dims...)
Expand Down
19 changes: 15 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ using LinearAlgebra: mul!, ldiv!, norm
devices = (CPU(),)
@has_cuda devices = (CPU(), GPU())

const rtol_fft = 1e-12
const rtol_output = 1e-12
const rtol_utils = 1e-13
const rtol_timesteppers = 1e-12
Expand All @@ -39,6 +38,8 @@ include("createffttestfunctions.jl")

for dev in devices

global const rtol_fft = dev==CPU() ? 1e-12 : 1e-6

@info "testing on " * string(typeof(dev))

@time @testset "Grid tests" begin
Expand Down Expand Up @@ -107,9 +108,19 @@ for dev in devices
@test testtypedthreedgrid(dev, nx, Lx, ny, Ly, nz, Lz; T=T)

# Test show() methods
@test repr(g₁) == "OneDimensionalGrid\n ├─────────── Device: "*FourierFlows.griddevice(g₁)*"\n ├──────── FloatType: Float64\n ├────────── size Lx: 6.283185307179586\n ├──── resolution nx: 6\n ├── grid spacing dx: 1.0471975511965976\n └─────────── domain: x ∈ [-3.141592653589793, 2.094395102393195]"
@test repr(g₂) == "TwoDimensionalGrid\n ├───────────────── Device: "*FourierFlows.griddevice(g₂)*"\n ├────────────── FloatType: Float64\n ├────────── size (Lx, Ly): (6.283185307179586, 12.566370614359172)\n ├──── resolution (nx, ny): (6, 8)\n ├── grid spacing (dx, dy): (1.0471975511965976, 1.5707963267948966)\n └───────────────── domain: x ∈ [-3.141592653589793, 2.094395102393195]\n y ∈ [-6.283185307179586, 4.71238898038469]"
@test repr(g₃) == "ThreeDimensionalGrid\n ├───────────────────── Device: "*FourierFlows.griddevice(g₃)*"\n ├────────────────── FloatType: Float64\n ├────────── size (Lx, Ly, Lz): (6.283185307179586, 12.566370614359172, 12.566370614359172)\n ├──── resolution (nx, ny, nz): (6, 8, 10)\n ├── grid spacing (dx, dy, dz): (1.0471975511965976, 1.5707963267948966, 0.3)\n └──────────────────── domain: x ∈ [-3.141592653589793, 2.094395102393195]\n y ∈ [-6.283185307179586, 4.71238898038469]\n z ∈ [-1.5, 1.2]"
if dev==CPU()
FT = "Float64"

@test repr(g₁) == "OneDimensionalGrid\n ├─────────── Device: "*FourierFlows.griddevice(g₁)*"\n ├──────── FloatType: "*FT*"\n ├────────── size Lx: 6.283185307179586\n ├──── resolution nx: 6\n ├── grid spacing dx: 1.0471975511965976\n └─────────── domain: x ∈ [-3.141592653589793, 2.094395102393195]"
@test repr(g₂) == "TwoDimensionalGrid\n ├───────────────── Device: "*FourierFlows.griddevice(g₂)*"\n ├────────────── FloatType: "*FT*"\n ├────────── size (Lx, Ly): (6.283185307179586, 12.566370614359172)\n ├──── resolution (nx, ny): (6, 8)\n ├── grid spacing (dx, dy): (1.0471975511965976, 1.5707963267948966)\n └───────────────── domain: x ∈ [-3.141592653589793, 2.094395102393195]\n y ∈ [-6.283185307179586, 4.71238898038469]"
@test repr(g₃) == "ThreeDimensionalGrid\n ├───────────────────── Device: "*FourierFlows.griddevice(g₃)*"\n ├────────────────── FloatType: "*FT*"\n ├────────── size (Lx, Ly, Lz): (6.283185307179586, 12.566370614359172, 12.566370614359172)\n ├──── resolution (nx, ny, nz): (6, 8, 10)\n ├── grid spacing (dx, dy, dz): (1.0471975511965976, 1.5707963267948966, 0.3)\n └──────────────────── domain: x ∈ [-3.141592653589793, 2.094395102393195]\n y ∈ [-6.283185307179586, 4.71238898038469]\n z ∈ [-1.5, 1.2]"
else
FT = "Float32"

@test repr(g₁) == "OneDimensionalGrid\n ├─────────── Device: "*FourierFlows.griddevice(g₁)*"\n ├──────── FloatType: "*FT*"\n ├────────── size Lx: 6.2831855\n ├──── resolution nx: 6\n ├── grid spacing dx: 1.0471976\n └─────────── domain: x ∈ [-3.1415927, 2.0943952]"
@test repr(g₂) == "TwoDimensionalGrid\n ├───────────────── Device: "*FourierFlows.griddevice(g₂)*"\n ├────────────── FloatType: "*FT*"\n ├────────── size (Lx, Ly): (6.2831855f0, 12.566371f0)\n ├──── resolution (nx, ny): (6, 8)\n ├── grid spacing (dx, dy): (1.0471976f0, 1.5707964f0)\n └───────────────── domain: x ∈ [-3.1415927, 2.0943952]\n y ∈ [-6.2831855, 4.712389]"
@test repr(g₃) == "ThreeDimensionalGrid\n ├───────────────────── Device: "*FourierFlows.griddevice(g₃)*"\n ├────────────────── FloatType: "*FT*"\n ├────────── size (Lx, Ly, Lz): (6.2831855f0, 12.566371f0, 12.566371f0)\n ├──── resolution (nx, ny, nz): (6, 8, 10)\n ├── grid spacing (dx, dy, dz): (1.0471976f0, 1.5707964f0, 0.3f0)\n └──────────────────── domain: x ∈ [-3.1415927, 2.0943952]\n y ∈ [-6.2831855, 4.712389]\n z ∈ [-1.5, 1.2]"
end
end

@time @testset "FFT tests" begin
Expand Down