Skip to content

Commit 22ad48d

Browse files
committed
Switch assert with @allocated == 0 for Dense path and keep the 5-arg mul!.
1 parent 4f8b266 commit 22ad48d

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/perform_step/low_order.jl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,13 @@ end
104104
# By linearity: 0.5*(gtmp1+gtmp2)*W.dW == 0.5*(gtmp2*W.dW) + 0.5*(gtmp1*W.dW).
105105
# Avoid forming (gtmp1 + gtmp2), which would allocate a temporary SparseMatrixCSC.
106106
# Use 5-arg mul! to accumulate directly into the cached vector (allocation-free).
107-
_eh_accum_stage2!(nrtmp, gtmp2, W.dW)
107+
mul!(nrtmp, gtmp2, W.dW, convert(eltype(nrtmp), 0.5), convert(eltype(nrtmp), 0.5))
108108
end
109109

110110
dto2 = dt / 2
111111
@.. u = uprev + dto2 * (ftmp1 + ftmp2) + nrtmp
112112
end
113113

114-
@inline function _eh_accum_stage2!(y, g2, dW)
115-
mul!(y, g2, dW, convert(eltype(y), 0.5), convert(eltype(y), 0.5))
116-
return nothing
117-
end
118-
119-
@inline function _eh_accum_stage2!(
120-
y::StridedVector{T},
121-
g2::StridedMatrix{T},
122-
dW::StridedVector{T}
123-
) where {T <: LinearAlgebra.BlasFloat}
124-
LinearAlgebra.BLAS.gemv!('N', T(0.5), g2, dW, T(0.5), y)
125-
return nothing
126-
end
127-
128114
@muladd function perform_step!(integrator, cache::RandomEMConstantCache)
129115
@unpack t, dt, uprev, u, W, p, f = integrator
130116
u = uprev .+ dt .* integrator.f(uprev, p, t, W.curW)

test/nondiag_noise_eulerheun_test.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ using DiffEqBase: @..
9494
integ = init(prob, EulerHeun(); dt = 0.01, adaptive = false, save_on = false)
9595

9696
cache = integ.cache
97-
allocs = AllocCheck.check_allocs(
98-
StochasticDiffEq.perform_step!, (typeof(integ), typeof(cache))
99-
)
100-
@test isempty(allocs)
97+
98+
# Dense+BLAS: assert with `@allocated == 0` (not `check_allocs`).
99+
# `check_allocs` flags throw-only branches in LinearAlgebra’s generic gemv!/mul!,
100+
# while the BLAS hot path is allocation-free at runtime. We keep `check_allocs`
101+
# for the sparse/non-diagonal tests.
102+
StochasticDiffEq.perform_step!(integ, cache) # warm-up
103+
@test @allocated(StochasticDiffEq.perform_step!(integ, cache)) == 0
101104
end
102105

103106
make_integrator_dense(16)

0 commit comments

Comments
 (0)