//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ #ifndef vtk_m_cont_internal_ParallelRadixSortInterface_h #define vtk_m_cont_internal_ParallelRadixSortInterface_h #include #include #include #include namespace vtkm { namespace cont { namespace internal { namespace radix { const size_t MIN_BYTES_FOR_PARALLEL = 400000; const size_t BYTES_FOR_MAX_PARALLELISM = 4000000; struct RadixSortTag { }; struct PSortTag { }; // Detect supported functors for radix sort: template struct is_valid_compare_type : std::integral_constant { }; template struct is_valid_compare_type> : std::integral_constant { }; template struct is_valid_compare_type> : std::integral_constant { }; template <> struct is_valid_compare_type : std::integral_constant { }; template <> struct is_valid_compare_type : std::integral_constant { }; // Convert vtkm::Sort[Less|Greater] to the std:: equivalents: template BComp&& get_std_compare(BComp&& b, T&&) { return std::forward(b); } template std::less get_std_compare(vtkm::SortLess, T&&) { return std::less{}; } template std::greater get_std_compare(vtkm::SortGreater, T&&) { return std::greater{}; } // Determine if radix sort can be used for a given ValueType, StorageType, and // comparison functor. template struct sort_tag_type { using type = PSortTag; }; template struct sort_tag_type { using PrimT = std::is_arithmetic; using LongDT = std::is_same; using BComp = is_valid_compare_type; using type = typename std:: conditional::type; }; template struct sortbykey_tag_type { using type = PSortTag; }; template struct sortbykey_tag_type { using PrimKey = std::is_arithmetic; using PrimValue = std::is_arithmetic; using LongDKey = std::is_same; using BComp = is_valid_compare_type; using type = typename std::conditional::type; }; #define VTKM_INTERNAL_RADIX_SORT_DECLARE(key_type) \ VTKM_CONT_EXPORT void parallel_radix_sort( \ key_type* data, size_t num_elems, const std::greater& comp); \ VTKM_CONT_EXPORT void parallel_radix_sort( \ key_type* data, size_t num_elems, const std::less& comp); \ VTKM_CONT_EXPORT void parallel_radix_sort_key_values( \ key_type* keys, vtkm::Id* vals, size_t num_elems, const std::greater& comp); \ VTKM_CONT_EXPORT void parallel_radix_sort_key_values( \ key_type* keys, vtkm::Id* vals, size_t num_elems, const std::less& comp); // Generate radix sort interfaces for key and key value sorts. #define VTKM_DECLARE_RADIX_SORT() \ VTKM_INTERNAL_RADIX_SORT_DECLARE(short int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned short int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(long int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned long int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(long long int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned long long int) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(unsigned char) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(signed char) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(char) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(char16_t) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(char32_t) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(wchar_t) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(float) \ VTKM_INTERNAL_RADIX_SORT_DECLARE(double) } } } } // end vtkm::cont::internal::radix #endif // vtk_m_cont_internal_ParallelRadixSortInterface_h