Some improvements to the CUDA C++ version - #27
Conversation
This uses clearer variables names, and a large number of blocks
|
So, I took inspiration from the paper GROMACS Unplugged: How Power Capping and Frequency Shapes Performance on GPUs where they used a Pi Solver
Frustratingly they don't share the code of their solver, luckily we had a similar existing application, only had to tweak the launch parameters. Some numbers on Cricket (Nvidia A100): C++ (compiled with NVCC 12.6, with $ ./calculate_pi
Calculating PI using:
1000000000 slices
1000 CUDA threads
Obtained value for PI: 3.1415926535897891
Time taken: 0.54366599999999998 secondsafter: $ ./calculate_pi
Calculating PI using:
1099511627776 slices
512 CUDA threads
Obtained value for PI: 3.1415926535897869
Time taken: 3.1384690000000002 secondsNote the 3 orders of magnitude of difference in the number of slices. Similarly, for Julia (v1.12.5, with CUDA.jl v5.9.6), before: $ julia --project pi_cuda.jl
Activating project at `~/repo/pi_examples/julia_cuda_pi_dir`
Warming up...done. [19.527s]
Calculating PI using:
1000000000 slices
64 CUDA threads(s)
Obtained value of PI: 3.1415926515897707
Time taken: 3.561 secondsafter: $ julia --project pi_cuda.jl
Activating project at `~/repo/pi_examples/julia_cuda_pi_dir`
Warming up...done. [18.532s]
Calculating PI using:
1099511627776 slices
512 CUDA threads(s)
Obtained value of PI: 3.141592653589793
Time taken: 3.015 secondsAnd to confirm this is fully compute-bound, here is a roofline model from Nsight Compute of the new Julia implementation: I'm sure this can still be improved, but I'm happy with the current status, seems to be a solid improvement for both implementations. |


Still work in progress, but this version I already get a decent speedup compared to the current version.
CC @qiUip who suggested all the algorithmic improvements.