From 726bb09108b5aba6635099750fd4a0a12591e221 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Wed, 25 Jan 2023 13:52:30 -0700 Subject: [PATCH] Fix floating point exception in Kokkos sort THe current version of sort in Kokkos does not check whether the array is of size 0, and that messes up its bin calculation. If the size of the array is less than 2, skip the sort since the order cannot change. --- vtkm/cont/kokkos/internal/DeviceAdapterAlgorithmKokkos.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vtkm/cont/kokkos/internal/DeviceAdapterAlgorithmKokkos.h b/vtkm/cont/kokkos/internal/DeviceAdapterAlgorithmKokkos.h index 5a8ca9283..78e93c7a3 100644 --- a/vtkm/cont/kokkos/internal/DeviceAdapterAlgorithmKokkos.h +++ b/vtkm/cont/kokkos/internal/DeviceAdapterAlgorithmKokkos.h @@ -726,6 +726,13 @@ private: template VTKM_CONT static void SortImpl(vtkm::cont::ArrayHandle& values, vtkm::SortLess, std::true_type) { + // In Kokkos 3.7, we have noticed some errors when sorting with zero-length arrays (which + // should do nothing). There is no check, and the bin size computation gets messed up. + if (values.GetNumberOfValues() <= 1) + { + return; + } + vtkm::cont::Token token; auto portal = values.PrepareForInPlace(vtkm::cont::DeviceAdapterTagKokkos{}, token); kokkos::internal::KokkosViewExec view(portal.GetArray(), portal.GetNumberOfValues());