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

Support `end` keyword in Julia array indices #98

Closed lkuper closed 8 years ago

lkuper commented 8 years ago

Julia lets you use end to represent the last index in a dimension. Right now (under Julia 0.5), code that uses end in this way fails in liveness with the following error:

ERROR: LoadError: UndefVarError: end not defined
 in typeOfOpr(::GlobalRef, ::CompilerTools.LambdaHandling.LambdaVarInfo) at /home/lkuper/.julia/v0.5/CompilerTools/src/liveness.jl:664
DrTodd13 commented 8 years ago

I fixed this problem in Liveness but domain IR doesn't parallelize the result.

"a[3:4].+1" converts to:

((ParallelAccelerator.API.getindex)(a,$(Expr(:new, UnitRange{Int64}, 3, :((Base.select_value)((Base.sle_int)(3,4)::Bool,4,(Base.box)(Int64,(Base.sub_int)(3,1)))::Int64))))::Array{Int64,1} .+ 1)::Array{Int64,1}

and will parallelize but

"a[3:end].+1" converts to:

(ParallelAccelerator.API.getindex)(a,(MiscTest.colon)(3,MiscTest.end)) .+ 1

and this isn't converted to mmap by domain IR.

@ninegua

ninegua commented 8 years ago

The solution is not to have the end keyword at all. Ranges involving end is only a syntactic sugar, and they are converted to proper size expression once Julia expression is processed by the macro pass. The reason that it is left dangling here is that ParallelAccelerator translates all ref expression head (at macro level) to getindex, and didn't take care of end symbol that may appear inside a ref expression. A patch is needed for src/api-capture.jl to fix this.

DrTodd13 commented 8 years ago

Fixed in 437e892.

timholy commented 8 years ago

There's also EndpointRanges.