Cavity nonlinear optics with a cold atom ensemble on an atom chip : all-optical latching, modulation, and amplification