@@ -5,13 +5,15 @@ import Interpolations as Intp
5
5
import ClimaCore
6
6
import ClimaCore. Fields: Adapt
7
7
import ClimaCore. Fields: ClimaComms
8
+ import ClimaCore. Fields: zeros
8
9
9
10
import ClimaUtilities. Regridders
10
11
11
12
struct InterpolationsRegridder{
12
13
SPACE <: ClimaCore.Spaces.AbstractSpace ,
13
14
FIELD <: ClimaCore.Fields.Field ,
14
15
BC,
16
+ GITP,
15
17
} <: Regridders.AbstractRegridder
16
18
17
19
""" ClimaCore.Space where the output Field will be defined"""
@@ -22,6 +24,10 @@ struct InterpolationsRegridder{
22
24
23
25
""" Tuple of extrapolation conditions as accepted by Interpolations.jl"""
24
26
extrapolation_bc:: BC
27
+
28
+ # This is needed because Adapt moves from CPU to GPU and allocates new memory
29
+ """ Preallocated area of memory where to store the GPU interpolant (if needed)"""
30
+ _gpuitp:: GITP
25
31
end
26
32
27
33
# Note, we swap Lat and Long! This is because according to the CF conventions longitude
@@ -69,7 +75,12 @@ function Regridders.InterpolationsRegridder(
69
75
end
70
76
end
71
77
72
- return InterpolationsRegridder (target_space, coordinates, extrapolation_bc)
78
+ return InterpolationsRegridder (
79
+ target_space,
80
+ coordinates,
81
+ extrapolation_bc,
82
+ zeros (target_space),
83
+ )
73
84
end
74
85
75
86
"""
@@ -90,7 +101,8 @@ function Regridders.regrid(regridder::InterpolationsRegridder, data, dimensions)
90
101
)
91
102
92
103
# Move it to GPU (if needed)
93
- gpuitp = Adapt. adapt (ClimaComms. array_type (regridder. target_space), itp)
104
+ itp. _gpuitp .=
105
+ Adapt. adapt (ClimaComms. array_type (regridder. target_space), itp)
94
106
95
107
return map (regridder. coordinates) do coord
96
108
gpuitp (totuple (coord)... )
0 commit comments