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

Simple test breaks with error #23

Closed ranjanan closed 8 years ago

ranjanan commented 8 years ago

I wanted to conduct a simple test:

@acc function test()
    #a = rand(10^3)
    #a = randperm(10)
    a = [1,2,3,4,5,6,7,8,9,10]
    @time a .* a
end

On all three declarations of a I get the following error message:

ERROR: ArgumentError: reducing over an empty collection is not allowed
 in mapfoldl at reduce.jl:58
 in from_ccall at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:852
 in from_builtins at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:999
 in from_inlineable at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1188
 in resolveCallTarget at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1331
 in from_call at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1519
 in from_expr at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1942
 in from_assignment at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:592
 in from_expr at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1942
 in from_exprs at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:444
 in from_expr at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1942
 in from_lambda at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:420
 in from_expr at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1942
 in from_root at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2296
 in from_root at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2263
 in toCGen at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/driver.jl:172
 in processFuncCall at /Users/ranjan/.julia/v0.4/CompilerTools/src/OptFramework.jl:338
 in test at /Users/ranjan/.julia/v0.4/CompilerTools/src/OptFramework.jl:400

I noticed that doing the same thing using anonymous functions work though.

@acc f = x -> x.* x
f(rand(10))

However, suppose I run test() and get the error, and then I go back to the anonymous function:

f(rand(10))

I get the following error:

ERROR: KeyError: Array{Float64,1} not found
 in to_j2c_array at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/j2c-array.jl:118
 in ___j2c_proxy at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/driver.jl:276
 in opt_calls_trampoline_.* at /Users/ranjan/.julia/v0.4/CompilerTools/src/OptFramework.jl:419
 in anonymous at none:1

versioninfo:

Julia Version 0.4.1
Commit cbe1bee* (2015-11-08 10:33 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Am i doing something incorrectly?

ranjanan commented 8 years ago

It looks like the @time is causing the problem. If I remove it, test() works.

DrTodd13 commented 8 years ago

Yes, that is what I was going to suggest. You can time the call to the function rather than putting @time inside the optimized function. We will take a look at what @time is doing inside the function though. It may be something we could easily support but the error did look like the C code generation part and there are somethings there that we will probably never support. The native threading path will probably handle such cases when it is ready with the next official release of Julia that has native threading.

----- Original Message -----

From: "Ranjan Anantharaman" notifications@github.com To: "IntelLabs/ParallelAccelerator.jl" ParallelAccelerator.jl@noreply.github.com Sent: Thursday, December 3, 2015 7:25:12 AM Subject: Re: [ParallelAccelerator.jl] Simple test breaks with error (#23)

It looks like the @time is causing the problem.

— Reply to this email directly or view it on GitHub .

ranjanan commented 8 years ago

I see. I also got a different error while using arrays of arrays:

@acc function test2()
    a = Array(Vector{Int}, 10)
    for i = 1:size(a,1)
        a[i] = [1,2,3]
    end
    a .* 5
end

The message is:

ERROR: AssertionError: CGen: variables cannot have Any (unresolved) type
 in from_lambda at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:408
 in from_expr at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:1942
 in from_root at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2296
 in from_root at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2263
 in toCGen at /Users/ranjan/.julia/v0.4/ParallelAccelerator/src/driver.jl:172
 in processFuncCall at /Users/ranjan/.julia/v0.4/CompilerTools/src/OptFramework.jl:338
 in test2 at /Users/ranjan/.julia/v0.4/CompilerTools/src/OptFramework.jl:400
DrTodd13 commented 8 years ago

Sorry for the delay. I was able to look into this today. Both of your examples come down to "we don't support that in CGen." At the moment we have only the C code generation path and that path comes with restrictions. In that path, we don't support printing (or IO in general) and everything has to have a known type (in other words, we don't support Any).

In your last example, in standard Julia, "a .* 5" results in something with type Array{Any,1}. It isn't Array{Vector{Int},1} * Int = Array{Vector{Int}, 1} like you might expect.

map(y -> y .* 5, a) produces the right type but we don't parallelize that. [x .* 5 for x in a] also produces Array{Any,1} but in this case ParallelAccelerator augments Julia's type inference and corrects this to the correct Array{Vector{Int},1}. So, I suggest trying the comprehension syntax.

It would be nice if we did a better job of indicating where the Any type is coming from. It manifests currently on some internal variable we introduce that isn't in the original source so it would be quite meaningless to the user. We'd probably have to do it with line numbers but we currently just throw line numbers away.

If you are satisfied then please close the ticket. Thanks.

ranjanan commented 8 years ago

Thanks Todd.