Skip to content
Merged
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
14 changes: 14 additions & 0 deletions src/operators/convolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,20 @@ const _DeviceReadyConvolution = Convolution{
<:_DeviceKernel, Direct,
}
_device_ready(::_DeviceReadyConvolution) = true
# Names what keeps a convolution from the rule on device arrays. A device
# call runs the direct method whatever was asked, so `FFTMethod()` there
# takes plain AD and says so.
function _device_whys(c::Convolution{K, M}) where {K, M}
out = String[]
M === Direct || push!(
out,
"the method, $(nameof(M))(), has no rule on device arrays: " *
"pass Direct(), the method a device call runs"
)
_device_ready(Convolution(c.kernel)) ||
push!(out, "the kernel, a $(nameof(K)), has no rule on device arrays")
return out
end

# Whether each output of kernel `c` is one dot of its weights with the
# window it reads, so an output can run on its own.
Expand Down
5 changes: 5 additions & 0 deletions test/registry/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const DEVICE_PLAIN = Set(
"Convolution lag contributions of a kernel from a calendar hazard (call 2)",
"Recurrence routes, dense and sparse",
"Recurrence routes in a buffer deeper than the kernels",
# A device call runs the direct method whatever was asked, so these
# `FFTMethod()` scenarios keep plain AD there and say why.
"Convolution long kernel by the transform",
"Convolution wide-range series by the transform",
"Convolution epidemic curve by the transform",
]
)
# These refuse a device with the message given.
Expand Down
16 changes: 16 additions & 0 deletions test/unit/device_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,22 @@ end
@test (@inferred route(op, args)) === Val(:rule)
steps = TimeVarying([1 => pmf, 15 => reverse(pmf)])
@test !CR._device_ready(Convolution(steps))
# A device call runs the direct method, so an `FFTMethod()` convolution
# there keeps plain AD and is named by its method, once; a change-point
# kernel is named by its kernel.
fft = Convolution(JLArray(pmf); method = CR.FFTMethod())
fargs = (JLArray(inputs(S)), true, nothing, nothing, 1, nothing)
@test (@inferred route(fft, fargs)) === Val(:plain)
@test CR._stopped_whys(fft, fargs...) == [
"the method, FFTMethod(), has no rule on device arrays: " *
"pass Direct(), the method a device call runs",
]
@test_logs (:info, r"Convolution gradients use plain AD.*FFTMethod") (
CR._note_stopped(fft, fargs...)
)
@test_logs CR._note_stopped(fft, fargs...)
@test CR._stopped_whys(Convolution(steps), fargs...) ==
["the kernel, a TimeVarying, has no rule on device arrays"]
# Numbers other than IEEE floats keep plain AD.
xq, cq = JLArray(fill(1 // 2, S, T)), Convolution(JLArray(fill(1 // 5, L)))
@test route(cq, (xq, true, nothing, nothing, 1, nothing)) === Val(:plain)
Expand Down
Loading