Code Monkey home page Code Monkey logo

Comments (3)

christiangnrd avatar christiangnrd commented on September 28, 2024 1

Your kernel is constructing a Normal{Float32}(0.f0, 1.f0) object for every state index. On top of being very inefficient, this code will not run on GPU as it creates allocations.

What if you tried:

function kernel(state, dist)
    idx = thread_position_in_grid_1d()
    state[idx] = rand(dist)
    return
end

n = 10
state = Metal.ones(n)
@metal threads=n kernel(state, Normal{Float32}(0f0,1f0))

from metal.jl.

FredericWantiez avatar FredericWantiez commented on September 28, 2024

In the actual code, the distribution depends on the state, something like Normal(state[idx], 1.f0). Tried running your example but that still raises a pgstack error.

julia> @metal threads=n kernel(state, Normal{Float32}(0f0,1f0))
ERROR: InvalidIRError: compiling MethodInstance for kernel(::MtlDeviceVector{Float32, 1}, ::Normal{Float32}) resulted in invalid LLVM IR
Reason: unsupported call to an unknown function (call to julia.get_pgcstack)
Stacktrace:
 [1] randn_unlikely
   @ ~/.julia/juliaup/julia-1.9.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.9/Random/src/normal.jl:81
 [2] multiple call sites
   @ unknown:0

These are the system info:

macOS 14.5.0, Darwin 23.5.0

Toolchain:
- Julia: 1.10.4
- LLVM: 15.0.7

Julia packages:
- Metal.jl: 1.2.0
- LLVMDowngrader_jll: 0.3.0+1

1 device:
- Apple M1 Max (384.000 KiB allocated)

from metal.jl.

maleadt avatar maleadt commented on September 28, 2024

External packages not supporting GPU execution is not a bug in the GPU support package, so it's probably better to file an issue on Distributions.jl for GPU compatibility. If that reveals specific features are needed for that support, you can file them here.

For example, your stack trace seems to show that rand is called by Distributions, which is currently not supported by Metal.jl kernels. If you can confirm that and create a MWE of what's needed, feel free to open a new issue with that information (but know that RNG support in kernels is fairly involved, see e.g. the CUDA.jl implementation, https://github.com/JuliaGPU/CUDA.jl/blob/master/src/device/random.jl).

(For other questions like this, something in GitHub's discussions, or on Discourse or Slack, is probably better suited than filing a bug report.)

from metal.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.