#include // Disabled on MSVC && NVCC < 11.1 for GH issue #1098. #if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && defined(__CUDACC__) #if (__CUDACC_VER_MAJOR__ < 11) || (__CUDACC_VER_MAJOR__ == 11 && __CUDACC_VER_MINOR__ < 1) #define THRUST_BUG_1098_ACTIVE #endif // NVCC version check #endif // MSVC + NVCC check #if THRUST_CPP_DIALECT >= 2014 && !defined(THRUST_BUG_1098_ACTIVE) #include #include #include #include enum wait_policy { wait_for_futures , do_not_wait_for_futures }; template struct custom_greater { __host__ __device__ bool operator()(T rhs, T lhs) const { return lhs > rhs; } }; #define DEFINE_SORT_INVOKER(name, ...) \ template \ struct name \ { \ template < \ typename ForwardIt, typename Sentinel \ > \ __host__ \ static void sync( \ ForwardIt&& first, Sentinel&& last \ ) \ { \ ::thrust::sort( \ THRUST_FWD(first), THRUST_FWD(last) \ ); \ } \ \ template < \ typename ForwardIt, typename Sentinel \ > \ __host__ \ static auto async( \ ForwardIt&& first, Sentinel&& last \ ) \ THRUST_RETURNS( \ ::thrust::async::sort( \ __VA_ARGS__ \ THRUST_PP_COMMA_IF(THRUST_PP_ARITY(__VA_ARGS__)) \ THRUST_FWD(first), THRUST_FWD(last) \ ) \ ) \ }; \ /**/ DEFINE_SORT_INVOKER( sort_invoker ); DEFINE_SORT_INVOKER( sort_invoker_device, thrust::device ); #define DEFINE_SORT_OP_INVOKER(name, op, ...) \ template \ struct name \ { \ template < \ typename ForwardIt, typename Sentinel \ > \ __host__ \ static void sync( \ ForwardIt&& first, Sentinel&& last \ ) \ { \ ::thrust::sort( \ THRUST_FWD(first), THRUST_FWD(last), op{} \ ); \ } \ \ template < \ typename ForwardIt, typename Sentinel \ > \ __host__ \ static auto async( \ ForwardIt&& first, Sentinel&& last \ ) \ THRUST_RETURNS( \ ::thrust::async::sort( \ __VA_ARGS__ \ THRUST_PP_COMMA_IF(THRUST_PP_ARITY(__VA_ARGS__)) \ THRUST_FWD(first), THRUST_FWD(last), op{} \ ) \ ) \ }; \ /**/ DEFINE_SORT_OP_INVOKER( sort_invoker_less, thrust::less ); DEFINE_SORT_OP_INVOKER( sort_invoker_less_device, thrust::less, thrust::device ); DEFINE_SORT_OP_INVOKER( sort_invoker_greater, thrust::greater ); DEFINE_SORT_OP_INVOKER( sort_invoker_greater_device, thrust::greater, thrust::device ); DEFINE_SORT_OP_INVOKER( sort_invoker_custom_greater, custom_greater ); DEFINE_SORT_OP_INVOKER( sort_invoker_custom_greater_device, custom_greater, thrust::device ); #undef DEFINE_SORT_INVOKER #undef DEFINE_SORT_OP_INVOKER /////////////////////////////////////////////////////////////////////////////// template