#include #include #include #include #include #include #include #include #ifdef THRUST_TEST_DEVICE_SIDE struct set_difference_kernel { template __device__ void operator()(ExecutionPolicy exec, Input1 a, Input2 b, Output result) const { const auto end = thrust::set_difference(exec, a.begin(), a.end(), b.begin(), b.end(), result.begin()); TEST_ASSERT_DEVICE(end == result.end()); } }; template void TestSetDifferenceDevice(ExecutionPolicy exec) { const auto device = test_runtime::current_test_device(); cuda::stream stream{device}; auto a = cuda::make_device_buffer(stream, device, cuda::std::initializer_list{0, 2, 4, 5}); auto b = cuda::make_device_buffer(stream, device, cuda::std::initializer_list{0, 3, 3, 4, 6}); auto result = cuda::make_device_buffer(stream, device, 2, cuda::no_init); cuda::launch(stream, test_runtime::single_thread_config(), set_difference_kernel{}, exec, a, b, result); stream.sync(); test_runtime::assert_equal(stream, result, {2, 5}); } void TestSetDifferenceDeviceSeq() { TestSetDifferenceDevice(thrust::seq); } DECLARE_UNITTEST(TestSetDifferenceDeviceSeq); void TestSetDifferenceDeviceDevice() { TestSetDifferenceDevice(thrust::device); } DECLARE_UNITTEST(TestSetDifferenceDeviceDevice); #endif void TestSetDifferenceCudaStreams() { const auto device = test_runtime::current_test_device(); cuda::stream stream{device}; auto a = cuda::make_device_buffer(stream, device, cuda::std::initializer_list{0, 2, 4, 5}); auto b = cuda::make_device_buffer(stream, device, cuda::std::initializer_list{0, 3, 3, 4, 6}); auto result = cuda::make_device_buffer(stream, device, 2, cuda::no_init); auto end = thrust::set_difference(thrust::cuda::par.on(stream.get()), a.begin(), a.end(), b.begin(), b.end(), result.begin()); ASSERT_EQUAL_QUIET(result.end(), end); test_runtime::assert_equal(stream, result, {2, 5}); } DECLARE_UNITTEST(TestSetDifferenceCudaStreams);