You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an application where I need to compute pairwise distances between vectors that are part of a larger MtlArray (Gaussian processes; kernel methods). The implementation that finally gets called uses SubArrays (it is designed for CPU work). Since there is no * method for MtlArrays and a view of a MtlArray, Julia dispatches to the CPU implementation of multiplication and is breaking.
Where should this kind of support be added? If this question has a complicated answer, how can I go about working around this? Thanks a bunch in advance!
using Metal
x =MtlArray(rand(Float32, 1, 1))
# 1×1 MtlArray{Float32, 2}:# 0.7656045
subarray =view(x, :, :)
# 1×1 view(::MtlArray{Float32, 2}, :, :) with eltype Float32:# 0.7656045
x * x
# 1×1 MtlArray{Float32, 2}:# 0.5861502
x * subarray
# ERROR: MethodError: unsafe_convert(::Type{Ptr{Float32}}, ::MtlArray{Float32, 2}) is ambiguous. Candidates:# unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where T in Base at pointer.jl:67# unsafe_convert(::Type{Ptr{S}}, a::AbstractArray{T}) where {S, T} in Base at pointer.jl:66# unsafe_convert(::Type{<:Ptr}, x::MtlArray) in Metal at /Users/me/.julia/packages/Metal/OGOSN/src/array.jl:128# Possible fix, define# unsafe_convert(::Type{Ptr{T}}, ::MtlArray{T}) where T# Stacktrace:# [1] gemm!(transA::Char, transB::Char, alpha::Float32, A::MtlArray{Float32, 2}, B::SubArray{Float32, 2, MtlArray{Float32, 2}, Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, beta::Float32, C::MtlArray{Float32, 2})# @ LinearAlgebra.BLAS ~/.julia/juliaup/julia-1.8.0+0.x64/share/julia/stdlib/v1.8/LinearAlgebra/src/blas.jl:1514# [2] gemm_wrapper!(C::MtlArray{Float32, 2}, tA::Char, tB::Char, A::MtlArray{Float32, 2}, B::SubArray{Float32, 2, MtlArray{Float32, 2}, Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, _add::LinearAlgebra.MulAddMul{true, true, Bool, Bool})# @ LinearAlgebra ~/.julia/juliaup/julia-1.8.0+0.x64/share/julia/stdlib/v1.8/LinearAlgebra/src/matmul.jl:674# [3] mul!# @ ~/.julia/juliaup/julia-1.8.0+0.x64/share/julia/stdlib/v1.8/LinearAlgebra/src/matmul.jl:161 [inlined]# [4] mul!# @ ~/.julia/juliaup/julia-1.8.0+0.x64/share/julia/stdlib/v1.8/LinearAlgebra/src/matmul.jl:276 [inlined]# [5] *(A::MtlArray{Float32, 2}, B::SubArray{Float32, 2, MtlArray{Float32, 2}, Tuple{Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true})# @ LinearAlgebra ~/.julia/juliaup/julia-1.8.0+0.x64/share/julia/stdlib/v1.8/LinearAlgebra/src/matmul.jl:148# [6] top-level scope# @ REPL[30]:1# [7] macro expansion# @ ~/.julia/packages/CUDA/DfvRa/src/initialization.jl:52 [inlined]# [8] top-level scope# @ ~/.julia/packages/Metal/OGOSN/src/initialization.jl:25
The text was updated successfully, but these errors were encountered:
In CUDA.jl, we represent contiguous SubArrays of a CuArray as another CuArray; that would probably be the easiest way to fix this (as it makes it easy to reuse functionality without having to add additional methods).
I have an application where I need to compute pairwise distances between vectors that are part of a larger
MtlArray
(Gaussian processes; kernel methods). The implementation that finally gets called usesSubArrays
(it is designed for CPU work). Since there is no*
method forMtlArray
s and a view of aMtlArray
, Julia dispatches to the CPU implementation of multiplication and is breaking.Where should this kind of support be added? If this question has a complicated answer, how can I go about working around this? Thanks a bunch in advance!
The text was updated successfully, but these errors were encountered: