Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Capture reshape() in API, avoid inlining
Browse files Browse the repository at this point in the history
reshape() calls are sometimes inlined by Julia resuling
in errors. They are now captured here but arguments are
changed to tuple as before.
  • Loading branch information
Ehsan Totoni committed Feb 7, 2017
1 parent 1c8f71b commit 9bac479
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
48 changes: 28 additions & 20 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
Copyright (c) 2015, Intel Corporation
All rights reserved.
Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
=#

Expand All @@ -30,31 +30,40 @@ import Base: call

eval(x) = Core.eval(API, x)

@noinline function setindex!{T}(A::DenseArray{T}, args...)
@noinline function setindex!{T}(A::DenseArray{T}, args...)
Base.setindex!(A, args...)
end

@inline function setindex!(A, args...)
@inline function setindex!(A, args...)
Base.setindex!(A, args...)
end

@noinline function getindex{T}(A::DenseArray{T}, args...)
@noinline function getindex{T}(A::DenseArray{T}, args...)
Base.getindex(A, args...)
end

@inline function getindex{T}(A::Type{T}, X...)
T[ X[i] for i=1:length(X) ]
end

@inline function getindex(A, args...)
@inline function getindex(A, args...)
Base.getindex(A, args...)
end

@noinline function reshape{T}(A::DenseArray{T}, args)
Base.reshape(A, args...)
end

# inline reshape to version with dims as tuple for easier handling in compiler
@inline function reshape{T}(A::DenseArray{T}, args...)
reshape(A, args)
end

# Unary operators/functions
const unary_map_operators = Symbol[
:-, :+, :acos, :acosh, :angle, :asin, :asinh, :atan, :atanh, :cbrt,
:cis, :cos, :cosh, :exp10, :exp2, :exp, :expm1, :lgamma,
:log10, :log1p, :log2, :log, :sin, :sinh, :sqrt, :tan, :tanh,
:log10, :log1p, :log2, :log, :sin, :sinh, :sqrt, :tan, :tanh,
:abs, :erf, :isnan]

const reduce_operators = Symbol[:sum, :prod, :minimum, :maximum, :any, :all]
Expand All @@ -65,7 +74,7 @@ const unary_operators = vcat(unary_map_operators, reduce_operators, Symbol[:copy
const comparison_map_operators = Symbol[ :.>, :.<, :.<=, :.>=, :.== ]

const binary_map_operators = vcat(comparison_map_operators, Symbol[ :*, :/,
:-, :+, :.+, :.-, :.*, :./, :.\, :.%, :.<<, :.>>, :.^,
:-, :+, :.+, :.-, :.*, :./, :.\, :.%, :.<<, :.>>, :.^,
:div, :mod, :rem, :&, :|, :$, :min, :max])

const binary_operators = binary_map_operators
Expand Down Expand Up @@ -272,8 +281,8 @@ end
Base.broadcast(f, a...)
end

operators = Set(vcat(unary_operators, binary_operators,
Symbol[:map, :map!, :reduce, :broadcast, :setindex!, :getindex]))
operators = Set(vcat(unary_operators, binary_operators,
Symbol[:map, :map!, :reduce, :broadcast, :setindex!, :getindex, :reshape]))

for opr in operators
@eval export $opr
Expand All @@ -294,7 +303,7 @@ macro par(args...)
if !isa(loop,Expr) || !is(loop.head,:for)
error("malformed @par loop")
end
if !isa(loop.args[1], Expr)
if !isa(loop.args[1], Expr)
error("maltformed for loop")
end
for i = 1:na-1
Expand Down Expand Up @@ -341,4 +350,3 @@ enableLib()
include("api-capture.jl")

end

2 changes: 1 addition & 1 deletion src/cgen-pattern-match.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ end

function pattern_match_call_reshape(fun, inp::Any, shape::RHSVar, linfo)
res = ""
if isBaseFunc(fun, :reshape)
if isBaseFunc(fun, :reshape) || fun==GlobalRef(ParallelAccelerator.API,:reshape)
typ = getSymType(shape, linfo)
if istupletyp(typ)
dim = length(typ.parameters)
Expand Down
2 changes: 1 addition & 1 deletion src/parallel-ir-simplify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ function create_equivalence_classes_assignment(lhs, rhs::Expr, state)
else
throw(string("arraysize AST node didn't have 2 or 3 arguments."))
end
elseif isBaseFunc(fun, :reshape)
elseif isBaseFunc(fun, :reshape) || fun==GlobalRef(ParallelAccelerator.API,:reshape)
# rhs.args[2] is the array to be reshaped, lhs is the result, rhs.args[3] is a tuple with new shape
if haskey(state.tuple_table, args[2])
@dprintln(3,"reshape tuple found in tuple_table = ", state.tuple_table[args[2]])
Expand Down

0 comments on commit 9bac479

Please sign in to comment.