Skip to content

Commit 64c9e59

Browse files
Fix allocations with pow (#2308)
1 parent 4a4261e commit 64c9e59

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Fields/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ end
313313
Base.Broadcast.broadcasted(
314314
::typeof(Base.literal_pow),
315315
::typeof(^),
316-
f::Field,
316+
f::Union{Field, Base.Broadcast.Broadcasted{<:AbstractFieldStyle}},
317317
::Val{n},
318318
) where {n} = Base.Broadcast.broadcasted(x -> Base.literal_pow(^, x, Val(n)), f)
319319

test/Fields/unit_field.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ function pow_n(f)
147147
@. f.x = f.x^2
148148
return nothing
149149
end
150+
function pow_n_bc(f)
151+
@. f.x = (f.x * 2)^2
152+
return nothing
153+
end
150154
@testset "Broadcasting with ^n" begin
151155
FT = Float32
152156
device = ClimaComms.CPUSingleThreaded() # fill is broken on gpu
@@ -160,6 +164,13 @@ end
160164
else
161165
@test p_allocated == 0 broken = (device isa ClimaComms.CUDADevice)
162166
end
167+
pow_n_bc(f) # Compile first
168+
p_allocated = @allocated pow_n_bc(f)
169+
if space isa Spaces.SpectralElementSpace1D
170+
@test p_allocated == 0
171+
else
172+
@test p_allocated == 0 broken = (device isa ClimaComms.CUDADevice)
173+
end
163174
end
164175
end
165176

0 commit comments

Comments
 (0)