#include #include #include #include template __global__ void partition_point_kernel(ExecutionPolicy exec, Iterator1 first, Iterator1 last, Predicate pred, Iterator2 result) { *result = thrust::partition_point(exec, first, last, pred); } template struct is_even { __host__ __device__ bool operator()(T x) const { return ((int) x % 2) == 0; } }; template void TestPartitionPointDevice(ExecutionPolicy exec) { size_t n = 1000; thrust::device_vector v = unittest::random_integers(n); typedef typename thrust::device_vector::iterator iterator; iterator ref = thrust::stable_partition(v.begin(), v.end(), is_even()); thrust::device_vector result(1); partition_point_kernel<<<1,1>>>(exec, v.begin(), v.end(), is_even(), result.begin()); cudaError_t const err = cudaDeviceSynchronize(); ASSERT_EQUAL(cudaSuccess, err); ASSERT_EQUAL(ref - v.begin(), (iterator)result[0] - v.begin()); } void TestPartitionPointDeviceSeq() { TestPartitionPointDevice(thrust::seq); } DECLARE_UNITTEST(TestPartitionPointDeviceSeq); void TestPartitionPointDeviceDevice() { TestPartitionPointDevice(thrust::device); } DECLARE_UNITTEST(TestPartitionPointDeviceDevice); void TestPartitionPointCudaStreams() { typedef thrust::device_vector Vector; typedef Vector::value_type T; typedef Vector::iterator Iterator; Vector v(4); v[0] = 1; v[1] = 1; v[2] = 1; v[3] = 0; Iterator first = v.begin(); Iterator last = v.begin() + 4; Iterator ref = first + 3; cudaStream_t s; cudaStreamCreate(&s); ASSERT_EQUAL_QUIET(ref, thrust::partition_point(thrust::cuda::par.on(s), first, last, thrust::identity())); last = v.begin() + 3; ref = last; ASSERT_EQUAL_QUIET(ref, thrust::partition_point(thrust::cuda::par.on(s), first, last, thrust::identity())); cudaStreamDestroy(s); } DECLARE_UNITTEST(TestPartitionPointCudaStreams);