-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mapreduce assumes commutative op #484
Comments
I just implemented a I suspect |
How can we fix this without, essentially, serializing the reduction? When reducing a 1D vector in parallel, aren't we always going to be reordering operations? Changing the order to something
EDIT: whoops, I'm a dummy, |
Interestingly the
Which makes sense as the current Can this be considered a replacement pending the associativity fix ? Even modifying the expression to |
Ha, that's funny. Yes, it's probably worth doing so awaiting a better implementation. |
We need to use |
Describe the bug
It looks like CUDA.jl's
mapreduce
assumes commutativity ofop
here:CUDA.jl/src/mapreduce.jl
Lines 67 to 73 in bc2d5f4
and here
CUDA.jl/src/mapreduce.jl
Lines 114 to 121 in bc2d5f4
To reproduce
As a result, the result of
mapreduce
differs from the CPU version even ifop
is exactly associative. For example, we can't implementfindmax
that returns the first maximum element and the location usingmapreduce
:Reading
Base.reduce
, my expectation has been thatreduce(op, xs)
andmapreduce(f, op, xs)
require only the associativity ofop
and not commutativity. It would be nice ifmapreduce
implementations on GPU also only assume associativity ofop
. If it's difficult to implement, I think it'd be reasonable to mention this in the docstring.Manifest.toml
Expected behavior
I expect
naive_findmax(xs::CuArray) == naive_findmax(Array(xs))
.Version info
Details on Julia:
Details on CUDA:
Additional context
I wonder if you can iterate using
d <<= 1
instead ofd >>= 1
to recover theBase
-compatibility.The text was updated successfully, but these errors were encountered: