How to use make_transform_iterator() with counting_iterator<> and execution_policy in Thrust?

江枫思渺然 提交于 2019-12-10 21:21:36

问题


I try to compile this code with MSVS2012, CUDA5.5, Thrust 1.7:

#include <iostream>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/find.h>

#include <thrust/execution_policy.h>

struct is_odd {
  __host__ __device__ bool operator()(uint64_t &x) {
    return x & 1;
  }
};

int main() {
    thrust::counting_iterator<uint64_t> first(0);
    thrust::counting_iterator<uint64_t> last = first + 100;

    auto iter = thrust::find(thrust::device,
                thrust::make_transform_iterator(first, is_odd()),
                thrust::make_transform_iterator(last, is_odd()),
                true);

    int bbb; std::cin >> bbb;
    return 0;
}

and get an error:

Error 1 error : incomplete type is not allowed C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include\thrust\detail\type_traits.h 413 1 HostDevice

If I use host/device_vector instead of counting_iterator then all ok. What's wrong?


回答1:


I changed your functor definition slightly, from this:

struct is_odd {
  __host__ __device__ bool operator()(uint64_t &x) {

to this:

struct is_odd : public thrust::unary_function<uint64_t, bool> {
  __host__ __device__ bool operator()(const uint64_t &x) {

and it compiled for me.



来源:https://stackoverflow.com/questions/21280239/how-to-use-make-transform-iterator-with-counting-iterator-and-execution-poli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!