From 3e87989172adb588673ccf48681785355faabc61 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Mon, 21 Aug 2017 12:52:41 -0400 Subject: [PATCH] Use propagate_inbounds instead of inline (#101) Currently the benchmarks are relying on inlining bugs to propagate boundscheck elision but the bug will be fixed with linear IR. Ref https://github.com/JuliaLang/julia/issues/18261 This is affecting https://github.com/JuliaLang/julia/pull/23240 --- src/array/indexing.jl | 36 +++++++++++++++++------------------- src/array/sumindex.jl | 36 ++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/array/indexing.jl b/src/array/indexing.jl index 04e05fec..a40d5db2 100644 --- a/src/array/indexing.jl +++ b/src/array/indexing.jl @@ -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 @@ -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 - diff --git a/src/array/sumindex.jl b/src/array/sumindex.jl index b35e2408..929a9544 100644 --- a/src/array/sumindex.jl +++ b/src/array/sumindex.jl @@ -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) @@ -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-"