-
Notifications
You must be signed in to change notification settings - Fork 118
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
[BUG] Imperfect shape query propagation in the presence of dead code #471
Comments
Another example of similar behaviour, except now there is no dead code, but there is a more complicated scalar expression to reason about. let a = use (fromList (Z :. (1 :: Int)) [(1::Float,2::Float)])
b = map fst a
in generate (I1 (let I1 n1 = shape b ; I1 n2 = shape a in min n1 n2))
(\(I1 i) -> b ! I1 i) This
whereas an optimal fusion result would have been Notable is that if |
Two more programs that produce (somewhat) unexpected results: zipWith (+)
(zipWith (\x y -> x * 2 * y) a a)
(map (\x -> x * x) a) which
which could have been Program 2: zipWith (+) a (map (\x -> x) a) which
which could have been I'm just collecting these for future reference at this point. |
Description
The fusion pipeline tries to express array shape queries in expressions (with the
shape
primitive) in terms of shapes of argument arrays if not doing so would prevent fusion. However, the algorithm seems to miss certain cases; the case I ran into involves a shape query of an array that is not used anywhere outside of that shape query (and is thus dead code).Steps to reproduce
Consider the following code:
The only difference between these two programs is the argument to
shape
. Note thata8
anda9
have the same shape by definition ofmap
.The first program
show
s to:The second program
show
s to:The first program exhibits suboptimal fusion, even though it is equivalent to the second.
Expected behaviour
Both programs should fuse to the same result, eliminating all
map
calls.Your environment
accelerate-1.3.0.0
on Hackage, or commit162a779f
.The text was updated successfully, but these errors were encountered: