CUDA和Thrust库:使用.cuh .cu和.cpp文件以及-std = c ++ 0x时出现问题

ksm*_*001 2 parallel-processing cuda gpu-programming thrust c++11

我想要一个.cuh文件,我可以在其中声明内核函数和宿主函数.这些函数的实现将在.cu文件中进行.实施将包括使用Thrust库.

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();
Run Code Online (Sandbox Code Playgroud)

myFunctions.cu

#include "myFunctions.cuh"

__host__ void show(){
   std::cout<<"test"<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)

main.cpp

#include "myFunctions.cuh"

int main(void){

    show();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我通过这样做编译:

nvcc myFunctions.cu main.cpp -O3
Run Code Online (Sandbox Code Playgroud)

然后键入以运行可执行文件 ./a.out

test文本将被打印出来.

但是,如果我决定-std=c++0x使用以下命令包含:

nvcc myFunctions.cu main.cpp -O3 --compiler-options "-std=c++0x"
Run Code Online (Sandbox Code Playgroud)

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

/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
Run Code Online (Sandbox Code Playgroud)

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

先感谢您

Rob*_*lla 5

如果您查看此特定答案,您将看到用户正在使用您正在使用的相同开关编译一个空的虚拟应用程序,并获得一些完全相同的错误.如果将该开关的使用限制为编译.cpp文件,则可能会有更好的结果:

myFunctions.h:

void show();
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

main.cpp中:

#include "myFunctions.h"

int main(void){

    show();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

建立:

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
Run Code Online (Sandbox Code Playgroud)