推力集差异无法通过不允许从__host__ __device__函数调用__host__函数进行编译 [英] thrust set difference fails to compile with calling a __host__ function from a __host__ __device__ function is not allowed

查看:148
本文介绍了推力集差异无法通过不允许从__host__ __device__函数调用__host__函数进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两套A& B之20分别为10个整数。 B是A的子集。我需要找到B的互补集。我使用推力::: set_difference来找到集合差异,但是它无法通过以下消息进行编译: warning:从中调用__host__函数不允许使用__host__ __device__函数

I have a two sets A & B of 20 & 10 integers respectively. B is a subset of A. I need to find the complimentary set of B. I use thrust::set_difference to find the set difference, However it fails to compile with message: warning: calling a __host__ function from a __host__ __device__ function is not allowed

我的代码如下。我不知道为什么这个简单的代码无法编译。

My code is as below. I dont know why this simple code fails to compile.

#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个错误​​:

My compilation error is huge. I found the 8 errors in them which i list below:

    /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_vectors。

While using thrust::set_difference the arguments are iterators and not the device_vectors. the last argument to the set_difference has to be complimentary_set.begin() instead of complimentary_set.

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

the entire correct statement now reads:

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

这篇关于推力集差异无法通过不允许从__host__ __device__函数调用__host__函数进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆