不允许通过从__host__ __device__函数调用__host__函数来编译推力集差异

问题描述 投票:-1回答:1

我有两组A和B分别为20和10整数。 B是A的子集。我需要找到B的互补集。我使用thrust :: 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>>
compiler-errors cuda set thrust
1个回答
1
投票

使用thrust :: set_difference时,参数是迭代器而不是device_vectors。 set_difference的最后一个参数必须是complementary_set.begin()而不是complimentary_set。

现在整个正确的陈述如下:

thrust::set_difference(thrust::device, A.begin(), A.end(), B.begin(), B.end(), complimentary_set.begin());
© www.soinside.com 2019 - 2024. All rights reserved.