Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error transforming a reshaped 0-dimentional GPU array to a CPU array #494

Closed
GiggleLiu opened this issue Oct 15, 2020 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@GiggleLiu
Copy link
Contributor

julia> b = CuArray(zeros())
0-dimensional CuArray{Float64,0}:
0.0

julia> reshape(b, ()) |> Array
ERROR: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
 [1] _empty_reduce_error() at ./reduce.jl:299
 [2] reduce_empty(::typeof(Base.add_sum), ::Type{Union{}}) at ./reduce.jl:319
 [3] reduce_empty(::Base.BottomRF{typeof(Base.add_sum)}, ::Type{Union{}}) at ./reduce.jl:328
 [4] reduce_empty_iter at ./reduce.jl:355 [inlined]
 [5] reduce_empty_iter at ./reduce.jl:354 [inlined]
 [6] foldl_impl(::Base.BottomRF{typeof(Base.add_sum)}, ::NamedTuple{(),Tuple{}}, ::Tuple{}) at ./reduce.jl:49
 [7] mapfoldl_impl(::typeof(identity), ::typeof(Base.add_sum), ::NamedTuple{(),Tuple{}}, ::Tuple{}) at ./reduce.jl:44
 [8] mapfoldl(::Function, ::Function, ::Tuple{}; kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./reduce.jl:160
 [9] mapfoldl at ./reduce.jl:160 [inlined]
 [10] #mapreduce#208 at ./reduce.jl:287 [inlined]
 [11] mapreduce(::Function, ::Function, ::Tuple{}) at ./reduce.jl:287
 [12] sum(::Function, ::Tuple{}) at ./reduce.jl:494
 [13] sum(::Tuple{}) at ./reduce.jl:511
 [14] _memory_offset(::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}, ::Int64) at ./abstractarray.jl:1016
 [15] pointer at /home/ubuntu/.julia/packages/CUDA/gKMm0/src/array.jl:168 [inlined]
 [16] unsafe_copyto!(::Array{Float64,0}, ::Int64, ::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}, ::Int64, ::Int64) at /home/ubuntu/.julia/packages/CUDA/gKMm0/src/array.jl:288
 [17] copyto!(::Array{Float64,0}, ::Int64, ::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}, ::Int64, ::Int64) at /home/ubuntu/.julia/packages/CUDA/gKMm0/src/array.jl:257
 [18] copyto!(::Array{Float64,0}, ::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}) at /home/ubuntu/.julia/packages/CUDA/gKMm0/src/array.jl:261
 [19] copyto_axcheck!(::Array{Float64,0}, ::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}) at ./abstractarray.jl:946
 [20] Array{Float64,0}(::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}) at ./array.jl:562
 [21] Array(::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}) at ./boot.jl:430
 [22] |>(::Base.ReshapedArray{Float64,0,CuArray{Float64,0},Tuple{}}, ::Type{T} where T) at ./operators.jl:834
 [23] top-level scope at REPL[16]:1

I can fix it by dispatching the 0-dimentional reshaped array function, but I think you may know how to fix this issue better.

@GiggleLiu GiggleLiu added the bug Something isn't working label Oct 15, 2020
@maleadt
Copy link
Member

maleadt commented Oct 16, 2020

Issue in Base:

julia> a = zeros()
0-dimensional Array{Float64,0}:
0.0

julia> b = Base.ReshapedArray(a, (), ())
0-dimensional reshape(::Array{Float64,0}, ) with eltype Float64:
0.0

julia> pointer(b, 1)
ERROR: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
 [1] _empty_reduce_error() at ./reduce.jl:299
 [2] reduce_empty(::typeof(Base.add_sum), ::Type{Union{}}) at ./reduce.jl:319
 [3] reduce_empty(::Base.BottomRF{typeof(Base.add_sum)}, ::Type{Union{}}) at ./reduce.jl:328
 [4] reduce_empty_iter at ./reduce.jl:355 [inlined]
 [5] reduce_empty_iter at ./reduce.jl:354 [inlined]
 [6] foldl_impl(::Base.BottomRF{typeof(Base.add_sum)}, ::NamedTuple{(),Tuple{}}, ::Tuple{}) at ./reduce.jl:49
 [7] mapfoldl_impl(::typeof(identity), ::typeof(Base.add_sum), ::NamedTuple{(),Tuple{}}, ::Tuple{}) at ./reduce.jl:44
 [8] mapfoldl(::Function, ::Function, ::Tuple{}; kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./reduce.jl:160
 [9] mapfoldl at ./reduce.jl:160 [inlined]
 [10] #mapreduce#208 at ./reduce.jl:287 [inlined]
 [11] mapreduce(::Function, ::Function, ::Tuple{}) at ./reduce.jl:287
 [12] sum(::Function, ::Tuple{}) at ./reduce.jl:494
 [13] sum(::Tuple{}) at ./reduce.jl:511
 [14] _memory_offset(::Base.ReshapedArray{Float64,0,Array{Float64,0},Tuple{}}, ::Int64) at ./abstractarray.jl:1016
 [15] pointer(::Base.ReshapedArray{Float64,0,Array{Float64,0},Tuple{}}, ::Int64) at ./abstractarray.jl:1009
 [16] top-level scope at REPL[15]:1

I'm considering reverting the SubArray/ReshapedArray/ReinterpretArray change, as it has caused several issues.

@maleadt maleadt closed this as completed Oct 16, 2020
@GiggleLiu
Copy link
Contributor Author

I'm considering reverting the SubArray/ReshapedArray/ReinterpretArray change, as it has caused several issues.

Great, helps a lot to OMEinsum.jl .

@maleadt
Copy link
Member

maleadt commented Oct 16, 2020

Great, helps a lot to OMEinsum.jl .

Could you elaborate? Can't you run into these wrappers with Base arrays too? Array is special-cased to return a regular Array again, but with other inputs you'd still see SubArray/ReinterpretArray/ReshapeArray (and the DenseCuArray etc unions should take care of those).

@GiggleLiu
Copy link
Contributor Author

GiggleLiu commented Oct 16, 2020

Currently, It is mainly about dispatch, output type stability et. al.
My main complaint is the CuArray reshape. Reshape an Array does not give you a ReshapedArray but reshaping a CuArray does. ReshapedArray makes the type unstable in some places. The rest is actually fine.

I have fixed the issue of dispatch in this PR
https://github.com/under-Peter/OMEinsum.jl/pull/100/files

but not yet tested the performance, I will return to this issue after benchmarking (when I have time).

@maleadt
Copy link
Member

maleadt commented Oct 19, 2020

I'm considering reverting the SubArray/ReshapedArray/ReinterpretArray change, as it has caused several issues.

#498, feedback appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants