Metal.jl icon indicating copy to clipboard operation
Metal.jl copied to clipboard

Base.unsafe_convert is ambiguous

Open mcabbott opened this issue 3 years ago • 0 comments

julia> Base.unsafe_convert(Ptr{Float32}, MtlArray(rand(Float32, 5)))
ERROR: MethodError: unsafe_convert(::Type{Ptr{Float32}}, ::MtlArray{Float32, 1}) is ambiguous.

Candidates:
  unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where T
    @ Base pointer.jl:67
  unsafe_convert(::Type{Ptr{S}}, a::AbstractArray{T}) where {S, T}
    @ Base pointer.jl:66
  unsafe_convert(::Type{<:Ptr}, x::MtlArray)
    @ Metal ~/.julia/packages/Metal/OGOSN/src/array.jl:128

Possible fix, define
  unsafe_convert(::Type{Ptr{T}}, ::MtlArray{T}) where T

Stacktrace:
 [1] top-level scope
   @ REPL[39]:1
 [2] top-level scope
   @ ~/.julia/packages/Metal/OGOSN/src/initialization.jl:25

(jl_764Pyi) pkg> st Metal
Status `/private/var/folders/yq/4p2zwd614y59gszh7y9ypyhh0000gn/T/jl_764Pyi/Project.toml`
  [dde4c033] Metal v0.1.1

I'm not sure whether this should or should not work. But I expected something like either of these two:

julia> using JLArrays  # Pkg.add(url="https://github.com/JuliaGPU/GPUArrays.jl.git", subdir="lib/JLArrays") for now

julia> Base.unsafe_convert(Ptr{Float32}, jl(rand(Float32, 5)))
Ptr{Float32} @0x0000000159404e00

julia> using CUDA

julia> Base.unsafe_convert(Ptr{Float32}, cu(rand(Float32, 5)))
ERROR: ArgumentError: cannot take the CPU address of a CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}
Stacktrace:
 [1] unsafe_convert(#unused#::Type{Ptr{Float32}}, x::CuArray{Float32, 1, CUDA.Mem.DeviceBuffer})
   @ CUDA ~/.julia/packages/CUDA/tTK8Y/src/array.jl:319

mcabbott avatar Jul 18 '22 17:07 mcabbott