Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Missing constructor CuArray{Float32,4}(::UndefInitializer, ::Tuple{Int64,Int64,Int64}) #408

Closed
baggepinnen opened this issue Sep 3, 2019 · 3 comments
Labels

Comments

@baggepinnen
Copy link
Contributor

The following throws an error

using Flux, CuArrays
julia> Z = gpu(Conv((3,3), 1=>1))(gpu(randn(5,5,1,1)))
Tracked 3×3×1×1 CuArray{Float32,4}:
[:, :, 1, 1] =
  1.85926   -4.03764  -1.79426
  0.348474  -3.98205  -1.1394 
 -0.766892  -1.29553  -1.96865

julia> Z = mapslices(Z, dims=(1,2,4)) do Zs
           Zs
       end
ERROR: MethodError: no method matching CuArray{Float32,4}(::UndefInitializer, ::Tuple{Int64,Int64,Int64})
Closest candidates are:
  CuArray{Float32,4}(::UndefInitializer, ::Tuple{Vararg{Int64,N}}) where {T, N} at /home/fredrikb/.julia/packages/CuArrays/wXQp8/src/array.jl:38
  CuArray{Float32,4}(::CUDAdrv.Mem.Buffer, ::Tuple{Vararg{Int64,N}}; offset, own) where {T, N} at /home/fredrikb/.julia/packages/CuArrays/wXQp8/src/array.jl:11
  CuArray{Float32,4}(::UndefInitializer, ::Integer...) where {T, N} at /home/fredrikb/.julia/packages/CuArrays/wXQp8/src/array.jl:42
  ...
Stacktrace:
 [1] similar(::Type{CuArray{Float32,4}}, ::Tuple{Int64,Int64,Int64}) at ./abstractarray.jl:672
 [2] convert(::Type{CuArray{Float32,4}}, ::Array{Float32,3}) at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/construction.jl:80
 [3] convert(::Type{CuArray{Float32,4}}, ::TrackedArray{…,CuArray{Float32,3}}) at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/construction.jl:71
 [4] gpu_convert at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/indexing.jl:119 [inlined]
 [5] _unsafe_setindex!(::IndexLinear, ::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Vararg{Union{Real, AbstractArray},N} where N) at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/indexing.jl:131
 [6] _setindex!(::IndexLinear, ::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Base.OneTo{Int64}, ::Vararg{Union{Real, AbstractArray},N} where N) at ./multidimensional.jl:712
 [7] setindex!(::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Base.OneTo{Int64}, ::Int64, ::Vararg{Any,N} where N) at ./abstractarray.jl:1074
 [8] concatenate_setindex!(::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Vararg{Any,N} where N) at ./abstractarray.jl:2060
 [9] #mapslices#109(::Tuple{Int64,Int64,Int64}, ::typeof(mapslices), ::getfield(Main, Symbol("##21#22")), ::TrackedArray{…,CuArray{Float32,4}}) at ./abstractarray.jl:2026
 [10] (::getfield(Base, Symbol("#kw##mapslices")))(::NamedTuple{(:dims,),Tuple{Tuple{Int64,Int64,Int64}}}, ::typeof(mapslices), ::Function, ::TrackedArray{…,CuArray{Float32,4}}) at ./none:0
 [11] top-level scope at none:0

Naively defining the suggested method does not help

julia> CuArray{T,N}(::UndefInitializer, dims::Tuple) where {T,N} =
         CuArray{T,N}(alloc(prod(dims)*sizeof(T)), dims...)

julia> Z = mapslices(Z, dims=(1,2,4)) do Zs
           Zs
       end
ERROR: MethodError: no method matching CuArray{Float32,4}(::CUDAdrv.Mem.DeviceBuffer, ::Int64, ::Int64, ::Int64)
Closest candidates are:
  CuArray{Float32,4}(::UndefInitializer, ::Integer...) where {T, N} at /home/fredrikb/.julia/packages/CuArrays/wXQp8/src/array.jl:42
  CuArray{Float32,4}(::Function, ::Any...) where {T, N} at /home/fredrikb/.julia/packages/CuArrays/wXQp8/src/array.jl:56
  CuArray{Float32,4}(::UniformScaling, ::Integer, ::Integer) at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/construction.jl:34
  ...
Stacktrace:
 [1] CuArray{Float32,4}(::UndefInitializer, ::Tuple{Int64,Int64,Int64}) at /home/fredrikb/arl/megafauna/explore.jl:248
 [2] similar(::Type{CuArray{Float32,4}}, ::Tuple{Int64,Int64,Int64}) at ./abstractarray.jl:672
 [3] convert(::Type{CuArray{Float32,4}}, ::Array{Float32,3}) at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/construction.jl:80
 [4] convert(::Type{CuArray{Float32,4}}, ::TrackedArray{…,CuArray{Float32,3}}) at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/construction.jl:71
 [5] gpu_convert at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/indexing.jl:119 [inlined]
 [6] _unsafe_setindex!(::IndexLinear, ::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Vararg{Union{Real, AbstractArray},N} where N) at /home/fredrikb/.julia/packages/GPUArrays/J4c3Q/src/indexing.jl:131
 [7] _setindex!(::IndexLinear, ::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Base.OneTo{Int64}, ::Vararg{Union{Real, AbstractArray},N} where N) at ./multidimensional.jl:712
 [8] setindex!(::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Base.OneTo{Int64}, ::Int64, ::Vararg{Any,N} where N) at ./abstractarray.jl:1074
 [9] concatenate_setindex!(::CuArray{Float32,4}, ::TrackedArray{…,CuArray{Float32,3}}, ::Base.OneTo{Int64}, ::Vararg{Any,N} where N) at ./abstractarray.jl:2060
 [10] #mapslices#109(::Tuple{Int64,Int64,Int64}, ::typeof(mapslices), ::getfield(Main, Symbol("##31#32")), ::TrackedArray{…,CuArray{Float32,4}}) at ./abstractarray.jl:2026
 [11] (::getfield(Base, Symbol("#kw##mapslices")))(::NamedTuple{(:dims,),Tuple{Tuple{Int64,Int64,Int64}}}, ::typeof(mapslices), ::Function, ::TrackedArray{…,CuArray{Float32,4}}) at ./none:0
 [12] top-level scope at none:0

Details on Julia:

julia> versioninfo()
Julia Version 1.3.0-alpha.0
Commit 6c11e7c2c4 (2019-07-23 01:46 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 6

(v1.3) pkg> st
    Status `~/.julia/environments/v1.3/Project.toml`
  [c52e3926] Atom v0.9.1
  [70b36510] AutomaticDocstrings v0.1.1 [`~/.julia/dev/AutomaticDocstrings`]
  [aae01518] BandedMatrices v0.10.1
  [07f847a3] BasisFunctionExpansions v1.0.1
  [6e4b80f9] BenchmarkTools v0.4.2
  [5d742f6a] CSVFiles v0.15.0
  [3895d2a7] CUDAapi v1.1.0
  [8f4d0f93] Conda v1.3.0
  [3abffc1c] ControlSystemIdentification v0.1.5 [`~/.julia/dev/ControlSystemIdentification`]
  [a6e380b2] ControlSystems v0.5.3 [`~/.julia/dev/ControlSystems`]
  [3a865a2d] CuArrays v1.2.1
  [717857b8] DSP v0.6.0
  [a93c6f00] DataFrames v0.19.2
  [864edb3b] DataStructures v0.17.0
  [9cd584b6] DifferentialDynamicProgramming v0.4.0 [`~/.julia/dev/DifferentialDynamicProgramming`]
  [09c11fbc] DiskDataProviders v0.1.0 [`~/.julia/dev/DiskDataProviders`]
  [7a1cc6ca] FFTW v0.3.0
  [5789e2e9] FileIO v1.0.7
  [587475ba] Flux v0.9.0 [`~/.julia/dev/Flux`]
  [f6369f11] ForwardDiff v0.10.3
  [28b8d3ca] GR v0.41.0
  [f67ccb44] HDF5 v0.12.2
  [cd3eb016] HTTP v0.8.5
  [7073ff75] IJulia v1.19.0
  [6a3955dd] ImageFiltering v0.6.5
  [6218d12a] ImageMagick v0.7.5
  [916415d5] Images v0.18.0
  [d0351b0e] InspectDR v0.3.6
  [e5e0dc1b] Juno v0.7.2
  [1902f260] Knet v1.2.4
  [26dcc766] LPVSpectral v0.1.2
  [82ba68a1] LazyWAVFiles v0.1.0 [`~/.julia/dev/LazyWAVFiles`]
  [98b081ad] Literate v2.0.3
  [43172d54] LiterateWeave v0.1.0 [`~/.julia/dev/LiterateWeave`]
  [33e6dc65] MKL v0.0.0 #master (https://github.com/JuliaComputing/MKL.jl)
  [f0e99cf1] MLBase v0.8.0
  [cc2ba9b6] MLDataUtils v0.5.0
  [0987c9cc] MonteCarloMeasurements v0.4.0 [`~/.julia/dev/MonteCarloMeasurements`]
  [6f286f6a] MultivariateStats v0.6.0
  [872c559c] NNlib v0.6.0
  [1dea7af3] OrdinaryDiffEq v5.14.0
  [58dd65bb] Plotly v0.2.0
  [f0f68f2c] PlotlyJS v0.12.5
  [91a5bcdd] Plots v0.26.2
  [438e738f] PyCall v1.91.2
  [d330b81b] PyPlot v2.8.1
  [a75dfa10] Robotlib v0.3.2+ [`~/.julia/dev/Robotlib`]
  [90137ffa] StaticArrays v0.11.0
  [2913bbd2] StatsBase v0.30.0
  [f3b207a7] StatsPlots v0.10.2
  [bd369af6] Tables v0.2.11
  [5e47fb64] TestImages v0.5.1
  [b8865327] UnicodePlots v1.1.0
  [8149f6b0] WAV v1.0.2
  [44d3d7a6] Weave v0.9.1
  [cd998857] Yota v0.1.3+ [`~/.julia/dev/Yota`]
  [e88e6eb3] Zygote v0.3.4 [`~/.julia/dev/Zygote`]
  [700de1a5] ZygoteRules v0.1.0 [`~/.julia/dev/ZygoteRules`]
@baggepinnen baggepinnen added the bug label Sep 3, 2019
@maleadt
Copy link
Member

maleadt commented Sep 3, 2019

There is a dimension mismatch in these calls (4-dim CuArray, 3-dim indices), and these calls do not work with Array either:

julia> Array{Float32,4}(undef, (1,2,3))
ERROR: MethodError: no method matching Array{Float32,4}(::UndefInitializer, ::Tuple{Int64,Int64,Int64})

julia> similar(Array{Float32,4}, (1,2,3))
ERROR: MethodError: no method matching Array{Float32,4}(::UndefInitializer, ::Tuple{Int64,Int64,Int64})

julia> convert(Array{Float32,4}, Array{Float32,3}(undef, (1,2,3)))
ERROR: MethodError: no method matching Array{Float32,4}(::Array{Float32,3})

So not a missing constructor or method. The call to mapslices also works with pure CuArray:

julia> Z = CuArray{Float32,4}(undef, (5,5,1,1))
5×5×1×1 CuArray{Float32,4}:
[:, :, 1, 1] =
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0

julia> Z = mapslices(Z, dims=(1,2,4)) do Zs
                  Zs
              end
5×5×1×1 CuArray{Float32,4}:
[:, :, 1, 1] =
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0

So this looks like an issue with TrackedArray instead?

@baggepinnen
Copy link
Contributor Author

Ah sorry, my bad. I'll open an issue on tracker instead!

@baggepinnen
Copy link
Contributor Author

Ref: FluxML/Tracker.jl#45

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants