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

Typed rand() fails #96

Closed ehsantn closed 8 years ago

ehsantn commented 8 years ago
using ParallelAccelerator
@acc ff(n) = 2*rand(Float32,n)
ff(4)

Gives this error:

ERROR: MethodError: `convert` has no method matching convert(::Type{Union{DataType,GlobalRef,QuoteNode}}, ::SymbolNode)
This may have arisen from a call to the constructor Union{DataType,GlobalRef,QuoteNode}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  call{T}(::Type{T}, ::Any)
  convert{T}(::Type{T}, ::T)
 in translate_call_alloc at /home/etotoni/.julia/v0.4/ParallelAccelerator/src/domain-ir.jl:1355
 in translate_call_symbol at /home/etotoni/.julia/v0.4/ParallelAccelerator/src/domain-ir.jl:1468

If I comment out the type annotation line:

ERROR: LoadError: MethodError: `getElemTypeFromAllocExp` has no method matching getElemTypeFromAllocExp(::SymbolNode)
 in translate_call_alloc at /home/etotoni/.julia/v0.4/ParallelAccelerator/src/domain-ir.jl:1356
 in translate_call_symbol at /home/etotoni/.julia/v0.4/ParallelAccelerator/src/domain-ir.jl:1468
 in translate_call_globalref at /home/etotoni/.julia/v0.4/ParallelAccelerator/src/domain-ir.jl:2177

Seems like it cannot recognize the rand() with type annotation since there is not handled ParallelAccelerator.API.rand in DomainIR debug output.

ninegua commented 8 years ago

Commit 96886dc6507c5cea110ea46c4f33c5b15b1bdf45 solves the problem for Julia 0.5, which has to do with passing constants (type, globalref) to inner function.

Commit e1da90f solves the problem for Julia 0.4 by creating a method for rand(Float32,...) in API.Lib. This is because somehow Julia 0.4 refuses to inline the method for rand(T::DataType, ...), but Julia 0.5 can.