You need to do something similar for the number of threads, but cap it to 512, as otherwise it won't work on all GPU.

If you see a speed difference with the cap, we can detect the GPU and make this max a dynamic number when this fct is in an op.