Gravity has nothing (directly) to do with acceleration of cosmic rays. You need vert strong magnetic or electric fields, preferably in shock fronts.
https://en.m.wikipedia.org/wiki/Fermi_acceleration
Directly, I say, because the objects that are extreme enough to produce such environments are indeed essentially fueled by gravitation energy: supermassive black holes at the centers of galaxies, super nova explosions, colliding neutron stars, ...
https://www.researchgate.net/figure/A-modern-adaption-of-the...