Учитывая большой массив значений A, которые преобразуются в массив B, поэтому B = Transform (A).Когда A и B имеют разные типы, и преобразование Transform () достаточно дорого, а размер данных B больше, чем A. Но результаты также должны быть отфильтрованы на основе предиката Keep (B).
Есть ли достойный способ сделать это, не выписывая сначала массив B, а затем обрезая записи B, которые нужно сохранить?
Я начал в толчке попробовать:
typedef int A;
struct B { int a, b, c; };
struct FTransform : thrust::unary_function<A, B>
{
__device__ B operator()(A a) const { return B{ a, a, a }; }
};
struct FKeep : thrust::unary_function<B, bool>
{
__device__ bool operator()(B b) const { return (b.a & 1) == 0; }
};
thrust::device_vector<B> outputs(8);
thrust::device_vector<A> inputs(8);
std::generate(inputs.begin(), inputs.end(), rand);
auto first = thrust::make_transform_iterator(inputs.begin(), FTransform());
auto last = thrust::make_transform_iterator(inputs.end(), FTransform());
auto end = thrust::copy_if(first, last, outputs, FKeep());
Однакоэто дает ошибки компиляции (Cuda 9.2):
thrust/iterator/iterator_traits.h(49): error : class "thrust::device_vector<B, thrust::device_malloc_allocator<B>>" has no member "iterator_category"
thrust/detail/copy_if.inl(78): error : incomplete type is not allowed
thrust/detail/copy_if.inl(80): error : no instance of overloaded function "select_system" matches the argument list
thrust/detail/copy_if.inl(80): error : no instance of overloaded function "thrust::copy_if" matches the argument list