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

ERROR: LoadError: AssertionError: CGen: variable #2022#v cannot have Any (unresolved) type #64

Closed sarkar1 closed 8 years ago

sarkar1 commented 8 years ago

The following code throws Assertion error. Can't figure out why.

using ParallelAccelerator X=rand(5,3) (n,m)=size(X) theta=zeros(m,1) y=ones(n,1) @acc Jtheta = (1/(2n)) . ((X*theta) .- y) .^ 2 println(Jtheta)

ERROR: LoadError: AssertionError: CGen: variable #2022#v cannot have Any (unresolved) type in from_lambda at /home/akshay/.julia/v0.4/ParallelAccelerator/src/cgen.jl:472 in from_expr at /home/akshay/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2002 in from_root_nonentry at /home/akshay/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2510 in from_worklist at /home/akshay/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2600 in from_root_entry at /home/akshay/.julia/v0.4/ParallelAccelerator/src/cgen.jl:2481 in toCGen at /home/akshay/.julia/v0.4/ParallelAccelerator/src/driver.jl:202 in processFuncCall at /home/akshay/.julia/v0.4/CompilerTools/src/OptFramework.jl:335 in opt_callstrampoline.- at /home/akshay/.julia/v0.4/CompilerTools/src/OptFramework.jl:409 in include at ./boot.jl:261 in include_from_node1 at ./loading.jl:304 in process_options at ./client.jl:280 in _start at ./client.jl:378 while loading /home/akshay/asarkar/Julia_ParallelAccelerator_Study/LinearRegression_PA/test.jl, in expression starting on line 6

KristofferC commented 8 years ago

Firstly, I believe @acc accelerates functions so you need to write Jtheta as a function. Secondly, you are only using a dot in Jtheta, maybe this should be a .*.

This works for me:

using ParallelAccelerator
X=rand(5,3)
(n,m)=size(X)
theta=zeros(m,1)
y=ones(n,1)
@acc Jtheta(n, X, theta, y) = (1/(2n)) .* ((X*theta) .- y) .^ 2
println(Jtheta(n, X, theta, y))
sarkar1 commented 8 years ago

I actually had .* in my code. Problem was that Jtheta was not a function. Thanks KristofferC

lkuper commented 8 years ago

@KristofferC Thanks for your comment. It sounds like this resolves @sarkar1's issue; however, it'd be nice if ParallelAccelerator gave a helpful error message for @acc being in the wrong place. I can open another issue for that.

DrTodd13 commented 8 years ago

So, we say that @acc can occur on expressions containing callsites and in the original code even though it doesn't look like there is a callsite there are in fact several of them (I'm seeing 6) since Julia converts operators into calls in the AST. So, the issue isn't that there aren't any callsites but what those callsites are. When we process a function, we look for calls to .* or .+ to handle specially but in this case we are trying to run our optimizations on the implementations of .* and .+ themselves.

Let's say you did have a function foo you wanted optimized and you did it at a callsite level like:

@acc res = foo(...) .* 7

I think this would still be a problem in that it would try to optimize .* itself.

lkuper commented 8 years ago

@DrTodd13 I didn't know that expressions containing callsites were supported. I thought we only supported @acc on: functions, actual callsites, and begin ... end blocks containing those things.

In fact, the only documented places you can use @acc are on functions or begin ... end blocks of functions. We should probably be more clear about what we support.