-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MPSMatrixRandom
#321
Add MPSMatrixRandom
#321
Conversation
The quality of random numbers produced by GPUArrays' RNG is probably lower though, so I would consider just using the one from MPS. |
4fa8052
to
b203523
Compare
A few comments.
|
So you're just reinterpreting Float32-generated random numbers as integers? That doesn't seem valid. Naively I would try to map the generated [0, 1) numbers to the integer's range, but that may still result in a biased output. I'm no RNG expert, but you could try it out and comparing a histogram to
What is the problem? Doesn't it have a way to seed the generator (e.g. https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixrandomphilox/3242872-initwithdevice?language=objc)?
I would just fall back to the GPUArrays RNG in those cases. CUDA.jl similarly tries to CURAND when possible, and falls back to the native generator in other cases. |
The default rng generator generates random UInt32 values so it's reinterpreting those as whatever Integer value was determined. Just took a look at histograms for all Integer datatypes and they all seem to be equivalent to the CPU versions. They also seem to be much better than the GPUArrays.
I'm not sure how to tie it in with I've marked this as a draft because the seeding test is currently marked as broken and I don't want to forget to fix it. |
4e7abb1
to
e5657f7
Compare
That's not surprising :-) FYI, if you really want to make sure the RNG is good, you can use https://github.com/JuliaRandom/RNGTest.jl. CUDA.jl's native RNG passes those, but it took a while to get there. |
40e640e
to
9f55467
Compare
This is now ready for final review. |
9f55467
to
16da0c0
Compare
Added some API functions that I missed. I won't squash anymore until it's been reviewed to make things less confusing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
This comment was marked as outdated.
This comment was marked as outdated.
d76ec2e
to
5a995b2
Compare
0b5f039
to
d48c7da
Compare
9b07eaa
to
84911a9
Compare
test/random.jl
Outdated
@@ -11,6 +11,7 @@ const OOPLACE_TUPLES = [[(Metal.rand, rand, T) for T in RAND_TYPES]; | |||
@testset "random" begin | |||
# in-place | |||
@testset "in-place" begin | |||
Metal.seed!(123) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the global RNG need seeding if you're using an explicit RNG object below?
See #329 |
7ca3dcf
to
a72992b
Compare
a72992b
to
fe8189f
Compare
…izes that are not divisible by 4
fe8189f
to
69f73ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, hadn't seen the request for review.
test/random.jl
Outdated
# Seed the default generators to work around value of 0 being | ||
# randomly generated in the size 1 Int8 Array test in 1.11 | ||
Metal.seed!(123) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still too fishy for me. Do we have an issue open about it? Removing the seeding doesn't make the tests fail here...
Interesting failure; seems unrelated to this PR though. I've restarted the job. EDIT: that's weird; the EDIT 2: I think JuliaGPU/GPUCompiler.jl#623 will fix this. |
Once the unrelated failure is resolved, this should be ready to merge. The only thing left is that at the moment the docs mention that this is available starting with Metal 2.0, which I wrote when I thought #392 would cause a major version bump, but this doesn't have any breaking changes so it should probably be 1.4 instead. |
Great stuff, thanks for keeping at it! We should include this in a blog post when releasing the next version of Metal.jl; I'll ping you when I get to that. |
Thanks for taking the time to review this over and over! |
Adds https://developer.apple.com/documentation/metalperformanceshaders/mpsmatrixrandom?language=objc and the other "MPSMatrixRandom" classes.