Skip to content

UnsafeStridedView Type Problem #30

Open
@JaredCrean2

Description

@JaredCrean2

I switched from manually inlining code within a for loop to using ArrayViews, and I discovered that when the array used to create the view is the field of a type, then there is a significant slowdown, and @code_warntype show an abstract type. Here is a minimal example

using ArrayViews

type mytype{T}
  arr::Array{T, 4}
end

function func1(q::AbstractArray)
# do some work
  tmp = q.*q
  return nothing
end



function runtest(obj)
(tmp, tmp, nnodes, numel) = size(obj.arr)

for i=1:numel
  for j=1:nnodes
    for k=1:2
      q_vals = unsafe_view(obj.arr, k, :, j, i)
      func1(q_vals)
     end
  end
end

end

function runtest2(obj)
(tmp, tmp, nnodes, numel) = size(obj.arr)

q_vals = zeros(2)
for i=1:numel
  for j=1:nnodes
    for k=1:2
      q_vals[1] = obj.arr[k, 1, j, i]
      q_vals[2] = obj.arr[k, 2, j, i]
      func1(q_vals)
     end
  end
end

end

# run the test
big_array = rand(2,2, 3, 50000)
obj = mytype{Float64}(big_array)

runtest(obj)
@time runtest(obj)

runtest2(obj)
@time runtest2(obj)

The output is

   1.083 seconds      (9291 k allocations: 407 MB, 4.21% gc time)
   312.813 milliseconds (3000 k allocations: 110 MB, 3.02% gc time)

The concerning line from @code_warntype runtest(obj) is:

      q_vals = call(UnsafeStridedView,GenSym(13),(GlobalRef(ArrayViews,:roffset))(GenSym(13),k::Int64,GenSym(12),j::Int64,i::Int64)::Int64,##shp#1550::Tuple{Int64,Int64},ArrayViews.ContRank{0},(GlobalRef(ArrayViews,:_vstrides))(strides(GenSym(13))::Tuple{Vararg{Int64}},1,k::Int64,GenSym(12),j::Int64,i::Int64)::Tuple{Int64,Int64})::ArrayViews.UnsafeStridedView{Float64,2,0} # line 22:

Something gets turned into a ::Tuple{Vararg{Int64}}, although I can't tell exactly what (I'm new to looking at partially compiled code). Do you think this could be the cause of the performance loss?

I'm using ArrayViews version 0.6.2 and Julia Version 0.4.0-dev+5149, Commit 317a4d1* (2015-06-01 18:58 UTC).

Thanks in advance,
Jared Crean

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions