Array programming

The Metal array type, MtlArray, generally implements the Base array interface and all of its expected methods.

However, there is the special function mtl for transferring an array over to the gpu. For compatibility reasons, it will automatically convert arrays of Float64 to Float32.

Metal.mtlFunction
mtl(A; storage=Private)

storage can be Private (default) or Shared.

Opinionated GPU array adaptor, which may alter the element type T of arrays:

  • For T<:AbstractFloat, it makes a MtlArray{Float32} for performance and compatibility reasons (except for Float16).
  • For T<:Complex{<:AbstractFloat} it makes a MtlArray{ComplexF32}.
  • For other isbitstype(T), it makes a MtlArray{T}.

By contrast, MtlArray(A) never changes the element type.

Uses Adapt.jl to act inside some wrapper structs.

Examples

julia> mtl(ones(3)')
1×3 adjoint(::MtlVector{Float32, Private}) with eltype Float32:
 1.0  1.0  1.0

julia> mtl(zeros(1,3); storage=Shared)
1×3 MtlMatrix{Float32, Shared}:
 0.0  0.0  0.0

julia> mtl(1:3)
1:3

julia> MtlArray(1:3)
3-element MtlVector{Int64, Private}:
 1
 2
 3
source