Complete pump depletion by autoresonant second harmonic generation in a nonuniform medium