Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions aten/src/ATen/native/cuda/SortStable.cu
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ void launch_stable_sort_kernel(
return;
}

int64_t numel_or_intmax =
std::min(numel, static_cast<int64_t>(std::numeric_limits<int>::max()));
const int64_t intmax = static_cast<int64_t>(std::numeric_limits<int>::max());
// On ROCm, std::min -> ::min did not work as expected on when input values >= 2147483648
int64_t numel_or_intmax = numel < intmax ? numel : intmax;
int64_t nsort = self.size(dim);
int64_t nbatch = (numel_or_intmax / nsort) * nsort;
TORCH_CHECK(nbatch > 0, "Cannot sort dimension of length ", nsort);
Expand All @@ -238,7 +239,8 @@ void launch_stable_sort_kernel(
scalar_t* values_ptr = values.mutable_data_ptr<scalar_t>();
int64_t remaining = numel;
while (remaining > 0) {
int64_t n = std::min(remaining, nbatch);
// On ROCm, std::min -> ::min did not work as expected on when input values >= 2147483648
int64_t n = remaining < nbatch ? remaining : nbatch;
int64_t nsegments = n / nsort;

if (nsegments == 1 ||
Expand Down
2 changes: 1 addition & 1 deletion test/test_sort_and_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_stable_sort(self, device, dtype):
)

@onlyCUDA
@dtypes(torch.uint8)
@dtypes(torch.float16)
@largeTensorTest("200GB") # Unfortunately 80GB A100 is not large enough
def test_sort_large(self, device, dtype):
t0 = torch.randperm(8192, device=device).to(dtype)
Expand Down