Refactor stable_sort_each_copy to take a Context parameter and to dynamically allocate smem.