Checkmate: Breaking the Memory Wall with Optimal Tensor Rematerialization