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

resize!, append! not defined #277

Closed
mtfishman opened this issue Jan 26, 2024 · 1 comment · Fixed by #279
Closed

resize!, append! not defined #277

mtfishman opened this issue Jan 26, 2024 · 1 comment · Fixed by #279
Labels
good first issue Good for newcomers

Comments

@mtfishman
Copy link
Contributor

I didn't see an issue for this. I see that resize! isn't defined for MtlVector:

julia> using Metal

julia> v = mtl(randn(10))
10-element MtlVector{Float32, Metal.MTL.MTLResourceStorageModePrivate}:
  0.7318981
  1.1954936
 -0.34666944
 -1.3239378
  0.2817273
  0.04914088
 -0.017454434
  0.076685436
  1.2588097
  0.7811673

julia> resize!(v, 12)
ERROR: MethodError: no method matching resize!(::MtlVector{Float32, Metal.MTL.MTLResourceStorageModePrivate}, ::Int64)

Closest candidates are:
  resize!(::SparseArrays.ReadOnly, ::Any)
   @ SparseArrays ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/SparseArrays/src/readonly.jl:33
  resize!(::SparseArrays.UMFPACK.UmfpackWS, ::Any, ::Bool; expand_only)
   @ SparseArrays ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/SparseArrays/src/solvers/umfpack.jl:214
  resize!(::BitVector, ::Integer)
   @ Base bitarray.jl:814
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[8]:1
 [2] top-level scope
   @ ~/.julia/packages/Metal/lnkVP/src/initialization.jl:57

which means functions that rely on it like append! don't work:

julia> append!(v, mtl([1, 2, 3]))
ERROR: MethodError: no method matching resize!(::MtlVector{Float32, Metal.MTL.MTLResourceStorageModePrivate}, ::Int64)

Closest candidates are:
  resize!(::SparseArrays.ReadOnly, ::Any)
   @ SparseArrays ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/SparseArrays/src/readonly.jl:33
  resize!(::SparseArrays.UMFPACK.UmfpackWS, ::Any, ::Bool; expand_only)
   @ SparseArrays ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/SparseArrays/src/solvers/umfpack.jl:214
  resize!(::BitVector, ::Integer)
   @ Base bitarray.jl:814
  ...

Stacktrace:
 [1] _append!(a::MtlVector{…}, ::Base.HasShape{…}, iter::MtlVector{…})
   @ Base ./array.jl:1196
 [2] append!(a::MtlVector{…}, iter::MtlVector{…})
   @ Base ./array.jl:1187
 [3] top-level scope
   @ REPL[9]:1
 [4] top-level scope
   @ ~/.julia/packages/Metal/lnkVP/src/initialization.jl:57
Some type information was truncated. Use `show(err)` to see complete types.

This causes issues for generic in-place code that relies on resize!/append! to be defined for AbstractVector.

Version information:

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores

(Metal.jl) pkg> st
Status `~/Simons Foundation Dropbox/Matthew Fishman/Documents/workdir/temp_julia_project/Metal.jl/Project.toml`
  [dde4c033] Metal v0.5.1

Please let me know if there is a simple workaround or low level definition I could use, and if so I'm happy to make a PR.

@maleadt
Copy link
Member

maleadt commented Jan 29, 2024

With the current design, there's no easy way to implement resize or append efficiently, so you could copy the CUDA.jl impl: https://github.com/JuliaGPU/CUDA.jl/blob/1ea0a8bd64b0d79174082fcd43682e2881ba6f77/src/array.jl#L864-L902

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants