Energy-efficient On-chip Deep Neural Network (DNN) Inference and Training with Emerging Non-volatile Memory Technologies