Closed spaarmann closed 11 months ago
I suspected this might be my fault, but the following change makes it fail also on v0.22.6. (Just reporting this in case it's useful for pinpointing the problem.)
entry problem [n] (arr: *[n]i64) : [n]i64 =
let arr2 = copy arr
in reduce_by_index arr (+) 0 (iota n) arr2
A prettier workaround for you would be to copy first, I think.
entry problem [n] (arr: *[n]i64) : [n]i64 =
reduce_by_index (copy arr) (+) 0 (iota n) arr
I'm OK with blaming Nikolaj if no one else volunteers.
This code
produces the following output when compiled with
futhark cuda
orfuthark opencl
:futhark c
works fine.Tested on a recent nightly (
0.26.0 (prerelease), git: 07fa0b447debb1501c3bc9593a4f0975685bc8eb
) as well as 0.25.9.I originally came across this working on the 2nd weekly assignment for DPP'23, the example above is what I reduced it to. Cosmin proposed in the lab that the
copy
was incorrectly eliminated by some optimization and suggested using something likemap (+ (opaque 0)) arr
instead ofcopy arr
as a workaround, which does work.