Skip to content

Commit

Permalink
Use propagate_inbounds instead of inline (#101)
Browse files Browse the repository at this point in the history
Currently the benchmarks are relying on inlining bugs to propagate boundscheck elision
but the bug will be fixed with linear IR.

Ref JuliaLang/julia#18261
This is affecting JuliaLang/julia#23240
  • Loading branch information
yuyichao authored and ararslan committed Aug 21, 2017
1 parent fc99b9a commit 3e87989
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
36 changes: 17 additions & 19 deletions src/array/indexing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function perf_hdindexing{T}(u_i::AbstractArray{T, 6}, u_ip1::AbstractArray{T, 6})
d1min = 3
d1max = size(u_i, 5) - 2
Expand Down Expand Up @@ -35,80 +34,79 @@ function kernel5{T}(idx, u_i::AbstractArray{T,6}, u_ip1::AbstractArray{T,6})
d3 = idx[3]
d4 = idx[4]
d5 = idx[5]

delta_12 = 0.5
delta_22 = 0.5
delta_32 = 0.5
delta_42 = 0.5
delta_52 = 0.5

u11_1 = (1/12)*u_i[ d1 - 2, d2, d3, d4, d5, 1] +
(-2/3)*u_i[ d1 - 1, d2, d3, d4, d5, 1] +
(0)*u_i[ d1 , d2, d3, d4, d5, 1] +
(2/3)*u_i[ d1 + 1, d2, d3, d4, d5, 1] +
(-1/12)*u_i[ d1 + 2, d2, d3, d4, d5, 1]

u22_1 = (1/12)*u_i[ d1, d2 - 2, d3, d4, d5, 1] +
(-2/3)*u_i[ d1, d2 - 1, d3, d4, d5, 1] +
(0)*u_i[ d1, d2 , d3, d4, d5, 1] +
(2/3)*u_i[ d1, d2 + 1, d3, d4, d5, 1] +
(-1/12)*u_i[ d1, d2 + 2, d3, d4, d5, 1]

u33_1 = (1/12)*u_i[ d1, d2, d3 - 2, d4, d5, 1] +
(-2/3)*u_i[ d1, d2, d3 - 1, d4, d5, 1] +
(0)*u_i[ d1, d2, d3 , d4, d5, 1] +
(2/3)*u_i[ d1, d2, d3 + 1, d4, d5, 1] +
(-1/12)*u_i[ d1, d2, d3 + 2, d4, d5, 1]

u44_1 = (1/12)*u_i[ d1, d2, d3, d4 - 2, d5, 1] +
(-2/3)*u_i[ d1, d2, d3, d4 - 1, d5, 1] +
(0)*u_i[ d1, d2, d3, d4 , d5, 1] +
(2/3)*u_i[ d1, d2, d3, d4 + 1, d5, 1] +
(-1/12)*u_i[ d1, d2, d3, d4 + 2, d5, 1]

u55_1 = (1/12)*u_i[ d1, d2, d3, d4, d5 - 2, 1] +
(-2/3)*u_i[ d1, d2, d3, d4, d5 - 1, 1] +
(0)*u_i[ d1, d2, d3, d4, d5 , 1] +
(2/3)*u_i[ d1, d2, d3, d4, d5 + 1, 1] +
(-1/12)*u_i[ d1, d2, d3, d4, d5 + 2, 1]
u_ip1[ d1, d2, d3, d4, d5, 2] = delta_12*u11_1 + delta_22*u22_1 + delta_32*u33_1 +

u_ip1[ d1, d2, d3, d4, d5, 2] = delta_12*u11_1 + delta_22*u22_1 + delta_32*u33_1 +
delta_42*u44_1 + delta_52*u55_1

u11_2 = (1/12)*u_i[ d1 - 2, d2, d3, d4, d5, 2] +
(-2/3)*u_i[ d1 - 1, d2, d3, d4, d5, 2] +
(0)*u_i[ d1 , d2, d3, d4, d5, 2] +
(2/3)*u_i[ d1 + 1, d2, d3, d4, d5, 2] +
(-1/12)*u_i[ d1 + 2, d2, d3, d4, d5, 2]

u22_2 = (1/12)*u_i[ d1, d2 - 2, d3, d4, d5, 2] +
(-2/3)*u_i[ d1, d2 - 1, d3, d4, d5, 2] +
(0)*u_i[ d1, d2 , d3, d4, d5, 2] +
(2/3)*u_i[ d1, d2 + 1, d3, d4, d5, 2] +
(-1/12)*u_i[ d1, d2 + 2, d3, d4, d5, 2]

u33_2 = (1/12)*u_i[ d1, d2, d3 - 2, d4, d5, 2] +
(-2/3)*u_i[ d1, d2, d3 - 1, d4, d5, 2] +
(0)*u_i[ d1, d2, d3 , d4, d5, 2] +
(2/3)*u_i[ d1, d2, d3 + 1, d4, d5, 2] +
(-1/12)*u_i[ d1, d2, d3 + 2, d4, d5, 2]

u44_2 = (1/12)*u_i[ d1, d2, d3, d4 - 2, d5, 2] +
(-2/3)*u_i[ d1, d2, d3, d4 - 1, d5, 2] +
(0)*u_i[ d1, d2, d3, d4 , d5, 2] +
(2/3)*u_i[ d1, d2, d3, d4 + 1, d5, 2] +
(-1/12)*u_i[ d1, d2, d3, d4 + 2, d5, 2]

u55_2 = (1/12)*u_i[ d1, d2, d3, d4, d5 - 2, 2] +
(-2/3)*u_i[ d1, d2, d3, d4, d5 - 1, 2] +
(0)*u_i[ d1, d2, d3, d4, d5 , 2] +
(2/3)*u_i[ d1, d2, d3, d4, d5 + 1, 2] +
(-1/12)*u_i[ d1, d2, d3, d4, d5 + 2, 2]
u_ip1[ d1, d2, d3, d4, d5, 1] = delta_12*u11_2 + delta_22*u22_2 + delta_32*u33_2 +

u_ip1[ d1, d2, d3, d4, d5, 1] = delta_12*u11_2 + delta_22*u22_2 + delta_32*u33_2 +
delta_42*u44_2 + delta_52*u55_2


return nothing
end

36 changes: 18 additions & 18 deletions src/array/sumindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ end

ArrayStrides1(A::Array) = ArrayStrides1(A, size(A,1))

@inline Base.setindex!(A::ArrayLSLS, v, I::Int...) = A.data[I...] = v
Base.@propagate_inbounds Base.setindex!(A::ArrayLSLS, v, I::Int...) = A.data[I...] = v

@inline Base.unsafe_setindex!(A::ArrayLSLS, v, I::Int...) = Base.unsafe_setindex!(A.data, v, I...)
Base.@propagate_inbounds Base.unsafe_setindex!(A::ArrayLSLS, v, I::Int...) = Base.unsafe_setindex!(A.data, v, I...)

Base.first(A::ArrayLSLS) = first(A.data)

Expand All @@ -258,27 +258,27 @@ Base.size(A::MyArray) = size(A.data)
@inline Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Int,Int}) = ArrayLSLS(similar(A.data, T, (dims[1]+1,dims[2]+1)))
@inline Base.similar{T}(A::ArrayLSLS, ::Type{T}, dims::Tuple{Vararg{Int}}) = ArrayLSLS(similar(A.data, T, map(n->n+1, dims)))

@inline Base.getindex(A::ArrayLF, i::Int) = getindex(A.data, i)
@inline Base.getindex{T}(A::ArrayLS{T,2}, i::Int, j::Int) = getindex(A.data, i, j)
@inline Base.getindex{T}(A::ArrayLS{T,3}, i::Int, j::Int, k::Int) = getindex(A.data, i, j, k)
@inline Base.getindex{T}(A::ArrayLSLS{T,2}, i::Int, j::Int) = getindex(A.data, i, j)
@inline Base.unsafe_getindex(A::ArrayLF, indx::Int) = Base.unsafe_getindex(A.data, indx)
@inline Base.unsafe_getindex{T}(A::ArrayLS{T,2}, i::Int, j::Int) = Base.unsafe_getindex(A.data, i, j)
@inline Base.unsafe_getindex{T}(A::ArrayLS{T,3}, i::Int, j::Int, k::Int) = Base.unsafe_getindex(A.data, i, j, k)
@inline Base.unsafe_getindex{T}(A::ArrayLSLS{T,2}, i::Int, j::Int) = Base.unsafe_getindex(A.data, i, j)
Base.@propagate_inbounds Base.getindex(A::ArrayLF, i::Int) = getindex(A.data, i)
Base.@propagate_inbounds Base.getindex{T}(A::ArrayLS{T,2}, i::Int, j::Int) = getindex(A.data, i, j)
Base.@propagate_inbounds Base.getindex{T}(A::ArrayLS{T,3}, i::Int, j::Int, k::Int) = getindex(A.data, i, j, k)
Base.@propagate_inbounds Base.getindex{T}(A::ArrayLSLS{T,2}, i::Int, j::Int) = getindex(A.data, i, j)
Base.@propagate_inbounds Base.unsafe_getindex(A::ArrayLF, indx::Int) = Base.unsafe_getindex(A.data, indx)
Base.@propagate_inbounds Base.unsafe_getindex{T}(A::ArrayLS{T,2}, i::Int, j::Int) = Base.unsafe_getindex(A.data, i, j)
Base.@propagate_inbounds Base.unsafe_getindex{T}(A::ArrayLS{T,3}, i::Int, j::Int, k::Int) = Base.unsafe_getindex(A.data, i, j, k)
Base.@propagate_inbounds Base.unsafe_getindex{T}(A::ArrayLSLS{T,2}, i::Int, j::Int) = Base.unsafe_getindex(A.data, i, j)

@inline Base.getindex{T}(A::ArrayStrides{T,2}, i::Real, j::Real) = getindex(A.data, 1+A.strides[1]*(i-1)+A.strides[2]*(j-1))
@inline Base.getindex(A::ArrayStrides1, i::Real, j::Real) = getindex(A.data, i + A.stride1*(j-1))
@inline Base.unsafe_getindex{T}(A::ArrayStrides{T,2}, i::Real, j::Real) = Base.unsafe_getindex(A.data, 1+A.strides[1]*(i-1)+A.strides[2]*(j-1))
@inline Base.unsafe_getindex(A::ArrayStrides1, i::Real, j::Real) = Base.unsafe_getindex(A.data, i + A.stride1*(j-1))
Base.@propagate_inbounds Base.getindex{T}(A::ArrayStrides{T,2}, i::Real, j::Real) = getindex(A.data, 1+A.strides[1]*(i-1)+A.strides[2]*(j-1))
Base.@propagate_inbounds Base.getindex(A::ArrayStrides1, i::Real, j::Real) = getindex(A.data, i + A.stride1*(j-1))
Base.@propagate_inbounds Base.unsafe_getindex{T}(A::ArrayStrides{T,2}, i::Real, j::Real) = Base.unsafe_getindex(A.data, 1+A.strides[1]*(i-1)+A.strides[2]*(j-1))
Base.@propagate_inbounds Base.unsafe_getindex(A::ArrayStrides1, i::Real, j::Real) = Base.unsafe_getindex(A.data, i + A.stride1*(j-1))

@compat Base.IndexStyle(::Type{<:ArrayLF}) = IndexLinear()

if !applicable(Base.unsafe_getindex, [1 2], 1:1, 2)
@inline Base.unsafe_getindex(A::Array, I...) = @inbounds return A[I...]
@inline Base.unsafe_getindex(A::MyArray, I...) = @inbounds return A[I...]
@inline Base.unsafe_getindex(A::SubArray, I...) = @inbounds return A[I...]
@inline Base.unsafe_getindex(A::BitArray, I1::BitArray, I2::Int) = Base.unsafe_getindex(A, Base.to_index(I1), I2)
Base.@propagate_inbounds Base.unsafe_getindex(A::Array, I...) = @inbounds return A[I...]
Base.@propagate_inbounds Base.unsafe_getindex(A::MyArray, I...) = @inbounds return A[I...]
Base.@propagate_inbounds Base.unsafe_getindex(A::SubArray, I...) = @inbounds return A[I...]
Base.@propagate_inbounds Base.unsafe_getindex(A::BitArray, I1::BitArray, I2::Int) = Base.unsafe_getindex(A, Base.to_index(I1), I2)
end
# Add support for views with CartesianIndex in a comparable method to how indexing works
if v"0.5-" < VERSION < v"0.6-"
Expand Down

0 comments on commit 3e87989

Please sign in to comment.