在将CUDA程序与Thrust链接时,未解析的外部符号

时间:2014-05-15 05:19:20

标签: c++ cuda thrust

我使用一些Thrust库函数创建了一个简单的程序,但在模板化函数上收到链接错误 Unresolved external symbol 。我用的是VS2010。

这是我的代码。

func.cuh

#pragma once

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>

struct F1 {
    template <typename Tuple> 
    __host__ __device__ 
    void operator()(Tuple arg) {        
        thrust::get<1>(arg) = (-1) * thrust::get<0>(arg);
    } 
};

struct F2 {
    template <typename Tuple>   
    __host__ __device__     
    void operator()(Tuple arg) { 
        thrust::get<1>(arg) = thrust::get<0>(arg) + 1.0;
    } 
};

template <typename Functor> thrust::host_vector<double> evalFunc(Functor func, thrust::host_vector<double> point) {
    size_t space_dim = point.size();

    thrust::device_vector<double> dev_point(space_dim);
    thrust::device_vector<double> dev_result(space_dim);
    thrust::host_vector<double> result(space_dim);

    dev_point = point;
    thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(dev_point.begin(), dev_result.begin())),
                     thrust::make_zip_iterator(thrust::make_tuple(dev_point.end(), dev_result.end())),
                     func);     
    result = dev_result;

    return result; 
}

operations.h

#pragma once

thrust::host_vector<double> computeFunction(thrust::device_vector<double> v);

operations.cu

#include "operations.h"
#include "func.cuh"

thrust::host_vector<double> computeFunction(HostVector v) {
    return evalFunc(F1(), v);
}

的main.cpp

#include <thrust/host_vector.h>
#include "operations.h"

int main(void) {
    ...
    // some code that creates and fills the vector v 
    ...

    thrust::host_vector<double> r = computeFunction(v);

    return EXIT_SUCCESS;
}

所有文件都已成功编译,但在链接

期间出错
error LNK2019: unresolved external symbol "class thrust::host_vector<double,class std::allocator<double> > __cdecl computeFunction(class thrust::device_vector<double,class thrust::device_malloc_allocator<double> >)" (?computeFunction@@YA?AV?$host_vector@NV?$allocator@N@std@@@thrust@@V?$device_vector@NV?$device_malloc_allocator@N@thrust@@@2@@Z) referenced in function main

为什么呢?

1 个答案:

答案 0 :(得分:1)

问题解决了!这是我的错 - 在computeFunction的定义及其实现中不同的参数类型。