2

.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();

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

これらのエラーは何を意味し、どうすれば回避できますか?

前もって感謝します

4

1 に答える 1

5

この特定の回答を見ると、ユーザーが使用しているのと同じスイッチで空のダミーアプリをコンパイルしていて、まったく同じエラーが発生していることがわかります。そのスイッチの使用を .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;
}

main.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
于 2013-04-22T15:46:22.887 に答える