Gpu non contiguous copies sorted

(A pull request into another pull request...)

This implements the sorting of dimensions by stride that Zalman suggested on #348. This should improve locality for sparse copies that need this sorting, and it simplifies the logic for folding contiguous dimensions.