在Nsight Eclipse中链接错误

时间:2015-08-11 11:25:47

标签: c++ cuda nsight

我正在尝试使用Nsight Eclipse Edition编译这个简单的类示例:

testclass.h

#include <vector>

#ifndef TESTCLASS_H_
#define TESTCLASS_H_

class testclass {
public:
__host__ __device__ testclass(int);
__host__ __device__ virtual ~testclass();
std::vector<int> intvec;

};

testclass.cu

#include "testclass.h"

testclass::testclass(int dim):
intvec(dim){}

testclass::~testclass(){}

main.cu

#include <stdio.h>
#include <stdlib.h>
#include "testclass.h"

__host__ __device__ unsigned int bitreverse(unsigned int number) {

number = ((0xf0f0f0f0 & number) >> 4) | ((0x0f0f0f0f & number) << 4);
number = ((0xcccccccc & number) >> 2) | ((0x33333333 & number) << 2);
number = ((0xaaaaaaaa & number) >> 1) | ((0x55555555 & number) << 1);

return number;
}

__global__ void bitreverse(void *data) {
testclass test(5);
unsigned int *idata = (unsigned int*) data;
idata[threadIdx.x] = bitreverse(idata[threadIdx.x]);
}

int main(void) 
{
testclass t(2);
void *d = NULL;
int i;
unsigned int idata[WORK_SIZE], odata[WORK_SIZE];

for (i = 0; i < WORK_SIZE; i++)
    idata[i] = (unsigned int) i;

CUDA_CHECK_RETURN(cudaMalloc((void**) &d, sizeof(int) * WORK_SIZE));
CUDA_CHECK_RETURN(
        cudaMemcpy(d, idata, sizeof(int) * WORK_SIZE, cudaMemcpyHostToDevice));

bitreverse<<<1, WORK_SIZE, WORK_SIZE * sizeof(int)>>>(d);

CUDA_CHECK_RETURN(cudaThreadSynchronize()); 
CUDA_CHECK_RETURN(cudaGetLastError());
CUDA_CHECK_RETURN(cudaMemcpy(odata, d, sizeof(int) * WORK_SIZE, cudaMemcpyDeviceToHost));

for (i = 0; i < WORK_SIZE; i++)
    printf("Input value: %u, device output: %u, host output: %u\n",
            idata[i], odata[i], bitreverse(idata[i]));

CUDA_CHECK_RETURN(cudaFree((void*) d));
CUDA_CHECK_RETURN(cudaDeviceReset());

return 0;
}

尝试编译我收到错误:

Unresolved extern function '_ZN9testclassC1Ei'

如果我在bitreverse内核函数中删除了test(5)的声明,则不会发生错误。在链接设备代码期间,这似乎是一个错误。

有人知道如何在Nsight eclipse中解决这个问题吗?

0 个答案:

没有答案