IntelLabs / ParallelAccelerator.jl

The ParallelAccelerator package, part of the High Performance Scripting project at Intel Labs
BSD 2-Clause "Simplified" License
294 stars 32 forks source link

array broadcast rules in PA #139

Open ehsantn opened 7 years ago

ehsantn commented 7 years ago

Array equivalence analysis treats all arrays in element-wise expressions as having equivalent shape. However, dimensions with size 1 can be broadcast. The example below gives incorrect result instead of throwing an error.

One solution is to specialize to array size dimensions having 1; it will be part of the type in some sort semantically. We could also mention this limitation in documentation and live with it.

using ParallelAccelerator
ParallelAccelerator.ParallelIR.set_debug_level(3)

@acc function btest(A,B,C)
    D1 = A.+B
    D2 = B.+C
    D1.+D2
end

A = ones(2,2)
B = ones(1,2)
C = ones(3,1)

println(btest(A,B,C))
[4.0 3.0; 4.0 1.0]
ninegua commented 7 years ago

This was partly discussed in #35

In short, we do not support Julia's semantics of broadcast, and personally I don't think we can. We should amend our documentation to reflect this.