Exercises
In the Case Study we found that the hand-written
mc_random_walk_kernel!kernel was slower than the fused broadcast version,mc_random_walk_fused!. Rewrite the kernel so that it matches (or beats) the fused version, benchmarking both aftersynchronize(get_backend(y_gpu))and checking that the two still produce statistically equivalent results. Hints: pre-generate all normal deviates in a device array and have each kernel invocation consume them; it is also worth sweeping KernelAbstractions workgroup sizes rather than assuming that is optimal.Take some of your existing code and port it to the GPU using the inbuilt array operations, then write a custom
KernelAbstractions.@kernelfor the more complicated operations. Verify correctness by comparing against the CPU result withisapprox, and benchmark both versions aftersynchronize(get_backend(array))to check that moving to the GPU was actually worthwhile once the host-to-device copies are counted.