Ivan Tanasic said that Saving and restoring the context is performed by a microprogrammed trap routine. But I don’t know how to do it.
anasic I, Gelado I, Cabezas J, et al. Enabling preemptive multiprogramming on GPUs[C]//2014 ACM/IEEE 41st International Symposium on Computer Architecture (ISCA). IEEE, 2014: 193-204.