proper gradient instead of numerical gradient on GPU