在.cpp中编译thrust出现的错误解决

4 篇文章 0 订阅
新建CUDA工程,新建thrustTest.cpp,键入如下代码:
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
#include <thrust/copy.h>
#include <thrust/fill.h>
#include <thrust/replace.h>
#include <thrust/functional.h>
#include <thrust/sequence.h>
#include <thrust/transform.h>

void thrustTest()
{
    {
        // allocate three device_vectors with 10 elements
        thrust::device_vector<int> X(10);
        thrust::device_vector<int> Y(10);
        thrust::device_vector<int> Z(10);

        // initialize X to 0,1,2,3, ....
        thrust::sequence(X.begin(), X.end());
        // compute Y = -X
        thrust::transform(X.begin(), X.end(), Y.begin(), thrust::negate<int>());
        // fill Z with twos
        thrust::fill(Z.begin(), Z.end(), 2);
        // compute Y = X mod 2
       // thrust::transform(X.begin(), X.end(), Z.begin(), Y.begin(), thrust::modulus<int>());
    }
}
编译会出现如下错误:
../for_each.inl(96) : error C2027: use of undefined type 'thrust::detail::STATIC_ASSERTION_FAILURE<x>'

解决办法:

右键thrustTest.cpp,选择属性,在“常规”->“项类型”里选择 CUDA C/C++,确定,再重新编译即可。

需要注意的是,使用CUDA C/C++来编译的话,有些代码可能会编译不通过,例如我在thrustTest.cpp里添加Eigen库的调用,就编译不通过,解决办法是将cuda相关的代码与其他代码文件上分离。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值