Merak: An Efficient Distributed DNN Training Framework with Automated 3D Parallelism for Giant Foundation Models