2013-04-22 24 views
2

我想要一个.cuh文件,我可以在其中声明内核函数和主机函数。这些功能的实现将在.cu文件中进行。该实施将包括使用Thrust库。CUDA和Thrust library:将.cuh .cu和.cpp文件与-std = C++一起使用时遇到问题0x

main.cpp文件中,我想使用.cu文件中的实现。所以我们可以说,我们有这样的事情:

myFunctions.cuh

#include <thrust/sort.h> 
#include <thrust/device_vector.h> 
#include <thrust/remove.h> 
#include <thrust/host_vector.h> 
#include <iostream> 

__host__ void show(); 

myFunctions.cu

#include "myFunctions.cuh" 

__host__ void show(){ 
    std::cout<<"test"<<std::endl; 
} 

main.cpp

#include "myFunctions.cuh" 

int main(void){ 

    show(); 

    return 0; 
} 

如果我做这个编译

nvcc myFunctions.cu main.cpp -O3 

然后键入./a.out

test文本将被打印运行可执行文件。

但是,如果我决定通过使用下面的命令包括-std=c++0x

nvcc myFunctions.cu main.cpp -O3 --compiler-options "-std=c++0x" 

我得到了很多错误,其中一些如下:

/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: identifier "nullptr" is undefined 

/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: expected a ";" 

/usr/include/c++/4.6/bits/exception_ptr.h(93): error: incomplete type is not allowed 

/usr/include/c++/4.6/bits/exception_ptr.h(93): error: expected a ";" 

/usr/include/c++/4.6/bits/exception_ptr.h(112): error: expected a ")" 

/usr/include/c++/4.6/bits/exception_ptr.h(114): error: expected a ">" 

/usr/include/c++/4.6/bits/exception_ptr.h(114): error: identifier "__o" is undefined 

做这些错误意味着什么,我该如何避免它们?

预先感谢您

+1

您可能对[此SO问题]感兴趣(http://stackoverflow.com/questions/12073828/c-version-supported-by-cuda-5-0),它是答案。可能最简单的解决方案是限制你使用的实际需要C++ 0x功能的东西到.cpp文件 – 2013-04-22 14:55:09

+0

我认为C++ 11比C++ 0x更新,这就是为什么它不被支持。但是,我仍然想在.cpp文件中使用C++ 0x,这可能吗?谢谢。如果你想要,你可以做出答案,以便我可以接受。 – ksm001 2013-04-22 15:24:01

回答

5

如果你看一下this specific answer,你会看到用户正在编制一个空的虚拟应用程序与您正在使用,并得到了一些确切的同样的错误的同一交换机。如果限制开关来编译.cpp文件的使用情况,你可能会有更好的效果:

myFunctions.h:

void show(); 

myFunctions.cu:

#include <thrust/sort.h> 
#include <thrust/device_vector.h> 
#include <thrust/remove.h> 
#include <thrust/host_vector.h> 
#include <thrust/sequence.h> 
#include <iostream> 

#include "myFunctions.h" 

void show(){ 
    thrust::device_vector<int> my_ints(10); 
    thrust::sequence(my_ints.begin(), my_ints.end()); 
    std::cout<<"my_ints[9] = "<< my_ints[9] << std::endl; 
} 

为主。 CPP:

#include "myFunctions.h" 

int main(void){ 

    show(); 

    return 0; 
} 

编译:

g++ -c -std=c++0x main.cpp 
nvcc -arch=sm_20 -c myFunctions.cu 
g++ -L/usr/local/cuda/lib64 -lcudart -o test main.o myFunctions.o 
+0

非常感谢你! – ksm001 2013-04-22 18:25:17

相关问题