Cross-layer Designs against Non-ideal Effects in ReRAM-based Processing-in-Memory System