Skip to content

Metal support #7

@lazarusA

Description

@lazarusA

just guessing now, but I think the current failure is due to the random number generator.

possible related issues:

doing

using GPUArrays
using Metal
GArray = MtlArray; # for Apple hardware
rng = GPUArrays.default_rng(GArray);
rand(rng,1)

fails:

ERROR: MethodError: no method matching rng_native_52(::GPUArrays.RNG)
The function `rng_native_52` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  rng_native_52(::Random.MersenneTwister)
   @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/RNGs.jl:444
  rng_native_52(::Random.RandomDevice)
   @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/RNGs.jl:36
  rng_native_52(::Random.TaskLocalRNG)
   @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Xoshiro.jl:230

and doing directly Metal.rand

using GLMakie
Metal.rand(Vec2f)
ERROR: MethodError: no method matching Random.Sampler(::Type{GPUArrays.RNG}, ::Random.SamplerType{UInt32}, ::Val{1})
This error has been manually thrown, explicitly, so the method may exist but be intentionally marked as unimplemented.

Closest candidates are:
  Random.Sampler(::Type{<:Random.AbstractRNG}, ::Random.Sampler, ::Union{Val{1}, Val{Inf}})
   @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:147
  Random.Sampler(::Type{<:Random.AbstractRNG}, ::Any, ::Union{Val{1}, Val{Inf}})
   @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:183
  Random.Sampler(::Type{<:Random.AbstractRNG}, ::BitSet, ::Union{Val{1}, Val{Inf}})
   @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/generation.jl:488
  ...

Stacktrace:
  [1] Random.Sampler(T::Type{GPUArrays.RNG}, sp::Random.SamplerType{UInt32}, r::Val{1})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:147
  [2] Random.Sampler(rng::GPUArrays.RNG, x::Random.SamplerType{UInt32}, r::Val{1})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:141
  [3] rand(rng::GPUArrays.RNG, X::Random.SamplerType{UInt32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:255
  [4] rand(rng::GPUArrays.RNG, ::Type{UInt32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:258
  [5] rand(r::GPUArrays.RNG, ::Random.SamplerTrivial{Random.UInt23Raw{UInt32}, UInt32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/generation.jl:112
  [6] rand(rng::GPUArrays.RNG, X::Random.UInt23Raw{UInt32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:255
  [7] rand(r::GPUArrays.RNG, ::Random.SamplerTrivial{Random.UInt23{UInt32}, UInt32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/generation.jl:124
  [8] rand(rng::GPUArrays.RNG, X::Random.UInt23{UInt32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:255
  [9] rand(r::GPUArrays.RNG, ::Random.SamplerTrivial{Random.CloseOpen01{Float32}, Float32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/generation.jl:29
 [10] rand(rng::GPUArrays.RNG, ::Type{Float32})
    @ Random ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:258
 [11] macro expansion
    @ ~/.julia/packages/StaticArrays/DsPgf/src/arraymath.jl:77 [inlined]
 [12] _rand
    @ ~/.julia/packages/StaticArrays/DsPgf/src/arraymath.jl:62 [inlined]
 [13] rand
    @ ~/.julia/packages/StaticArrays/DsPgf/src/arraymath.jl:60 [inlined]
 [14] rand!
    @ ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:273 [inlined]
 [15] rand!
    @ ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:269 [inlined]
 [16] rand
    @ ~/.julia/packages/StaticArrays/DsPgf/src/arraymath.jl:59 [inlined]
 [17] rand
    @ ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/Random/src/Random.jl:293 [inlined]
 [18] rand!(rng::GPUArrays.RNG, A::MtlVector{Vec{2, Float32}, Metal.SharedStorage})
    @ GPUArrays ~/.julia/packages/GPUArrays/w335n/src/host/random.jl:115
 [19] rand(::Type, ::Int64; storage::Type)
    @ Metal ~/.julia/packages/Metal/av3If/src/random.jl:40
 [20] rand(T::Type; storage::Type)
    @ Metal ~/.julia/packages/Metal/av3If/src/random.jl:52
 [21] top-level scope
    @ REPL[4]:1

which is / could be used for example in

function sample_light(bvh, ctx, width, height, camera_pos, focal_length, aspect, x, y, sky_color)
    jitter = rand(Vec2f)
....
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions