compiler-errors - 推力集差异无法通过不允许从__host__ __device__函数调用__host__函数进行编译

标签 compiler-errors cuda set thrust

我分别有两组A和B,分别为20和10个整数。 B是A的子集。我需要找到B的互补集。我使用推力:: set_difference来找到集差,但是它无法通过消息编译:warning: calling a __host__ function from a __host__ __device__ function is not allowed
我的代码如下。我不知道为什么这个简单的代码无法编译。

#include <thrust/sequence.h>
#include <thrust/execution_policy.h>
#include <thrust/set_operations.h>
#include <thrust/device_vector.h>


        thrust::device_vector<int> find_complimentary_set(thrust::device_vector<int> A, thrust::device_vector<int> B)
        {

        thrust::sort(thrust::device, A.begin(), A.end());
        thrust::sort(thrust::device, B.begin(), B.end());

        int N=A.size()-B.size();
        thrust::device_vector<int> complimentary_set(N);

        **// the following line causes the compilation error**
        thrust::set_difference(thrust::device, A.begin(), A.end(), B.begin(), B.end(), complimentary_set);

        return complimentary_set;

        }
            int main(int argc, char * argv[])
            {
            int N=20;
            thrust::device_vector<int> A(N);
            thrust::sequence(thrust::device, A.begin(), A.end(),0); 

            thrust::device_vector<int> B(10);
            B[0]=2;B[1]=4;B[2]=8;B[3]=10;B[4]=11;B[5]=13;B[6]=15;B[7]=17;B[8]=19;B[9]=6;

            find_complimentary_set(A, B);

            return 0;
            }

我的编译错误很大。我发现其中列出了8个错误:
    /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/detail/set_operation.inl(517): error: no operator "+" matches these operands
                operand types are: thrust::device_vector<int, thrust::device_malloc_allocator<int>> + thrust::reference<signed long, thrust::pointer<signed long, thrust::system::cuda::detail::par_t, thrust::use_default, thrust::use_default>, thrust::use_default>

    /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/detail/set_operation.inl(648): error: no operator "+" matches these operands
                operand types are: thrust::device_vector<int, thrust::device_malloc_allocator<int>> + signed long

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(64): error: no operator "*" matches these operands
            operand types are: * thrust::device_vector<int, thrust::device_malloc_allocator<int>>

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(66): error: no operator "++" matches these operands
            operand types are: ++ thrust::device_vector<int, thrust::device_malloc_allocator<int>>

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/iterator/iterator_traits.h(49): error: class "thrust::device_vector<int, thrust::device_malloc_allocator<int>>" has no member "iterator_category"

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(106): error: no operator "++" matches these operands
            operand types are: ++ thrust::device_vector<int, thrust::device_malloc_allocator<int>>

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(76): error: no operator "*" matches these operands
            operand types are: * thrust::device_vector<int, thrust::device_malloc_allocator<int>>

最佳答案

当使用推力:: set_difference时,参数是迭代器,而不是device_vector。 set_difference的最后一个参数必须是complementary_set.begin(),而不是complementary_set。

整个正确的语句现在显示为:

thrust::set_difference(thrust::device, A.begin(), A.end(), B.begin(), B.end(), complimentary_set.begin());

关于compiler-errors - 推力集差异无法通过不允许从__host__ __device__函数调用__host__函数进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53689844/

相关文章:

java - java.util.Set 中的重复元素

java - 简单的退出按钮不起作用

c++ - g++ 编译错误

excel - Excel VBA : Automated Excel Backup Stopped Working due to “Compile Error: Cannot find file or library”

c++ - 自动为 C++ 函数添加函数前缀

c++ - 通过引用设置构造函数复制?

linux - arduino IDE找不到库

python - 在 Celery celery worker 中使用 Theano 共享变量时出现 RuntimeError

c++ - CUDA 凸包程序在大输入时崩溃

position - 在子弹物理学中重新定位刚体