The perturbative QCD gradient flow to three loops