Could you check the memory usage in nvidia-smi and see, if the GPU is used by other processes or if some dead processes are filling it up?
I’m not sure, if there is a simple way of changing gcc in your current setup.
The cleanest way would probably still be to use docker, since you can just wipe it in the worst case.