-
-
Notifications
You must be signed in to change notification settings - Fork 83
really slow reduce over single dimension #362
Comments
A quick workaround for this would be something like: import Base.minimum
function minimum(x::CuArray{T}; dims=1:ndims(x)) where {T}
mx = fill!(similar(x, T, Base.reduced_indices(x, dims)), typemax(T))
Base._mapreducedim!(identity, min, mx, x)
end This reduces the time from 1s to 0.002s for the MWE on my machine. This works, because The scalar |
Yeah sure that would be a good workaround for now. |
#362: specialise reduce, minimum and maximum for CuArrays
Any ideas on how to backpropagate through Base.findmax(x::CuArray{T}; dims=:) where {T} = reduce(x, init=(typemin(T),1), dims=dims) do ((a,ai),(b,bi))
a > b ? (a,ai) : (b,bi)
end without any luck |
@baggepinnen: have a look at |
Thanks! In my context I managed to get around the problem by creating a binary mask, but am looking forward to seeing progress on #304 in general. |
reduce
(as well asmaximum
,minimum
but notsum
...) is really slow on CuArrays when the reduction happens over a single dimension, a tuple of dimensions however, is a lot faster (multiple orders of magnitude).When I set
allowscalar
tofalse
,reduce
,maximum
andminium
fail.To Reproduce
The Minimal Working Example (MWE) for this bug:
On my machine, with
dims=2
it takes 8.80s while it only takes 0.01s with dims=(2, 1)After disallowing scalar indexing, the code above throws
scalar getindex is disallowed
Environment details
Details on Julia:
The text was updated successfully, but these errors were encountered: