dneprdroid / primenumbers-metal Goto Github PK
View Code? Open in Web Editor NEWSearch prime numbers via Metal GPU API and compare its performance to CPU.
Search prime numbers via Metal GPU API and compare its performance to CPU.
Alex, I found your interesting Metal implementation of prime number generation through Reddit.
I've cloned and run it and it works well until the number of primes gets large when the test you have included to compare CPU and GPU prime-generation generates an error.
The first error is for a false prime generated by the GPU (the false primes are all generated by the GPU). This is the claim that 17884441 is prime when in fact it it 4229^2. Subsequently all numbers that are the squares of primes are falsely identified as primes.
The problem comes from the upper bound at about line 33 in your gpuTest/computePrimeNumbers.metal file where the last number is not tested; hence when the only divisor of a number is its prime square-root, it seems to be a prime but isn't.
This fixes it just by adding 2 to force the top number to be tested:
for (UIntType i = 3; i <= sqrt((FloatType)num) + 2; i+=2)
I notice that you also use a different Type in the CPU version with Double rather than FloatType so maybe that would also work but I haven't checked.
Hope this is helpful.
Incidentally, my MacBook generates primes up to 1,000,000,000 on its AMD Radeon 5500M GPU in about 10 secs; the CPU takes forever (or maybe hangs) and I haven't run it to completion with that many primes.
The code doesn't seem to exit smoothly, but that's another matter.
pudepiedj
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.