問題は、Cudaカーネルでクラス「ベクトル」を使用する方法はありますか? 試してみると、次のエラーが表示されます。
error : calling a host function("std::vector<int, std::allocator<int> > ::push_back") from a __device__/__global__ function not allowed
グローバルセクションでベクトルを使用する方法はありますか? 私は最近、次のことを試しました:
- 新しい Cuda プロジェクトを作成する
- プロジェクトのプロパティに移動します
- Cuda C/C++ を開く
- デバイスに移動
- 「コード生成」の値を次の値に変更します: compute_20,sm_20
........その後、Cudaカーネルでprintf標準ライブラリ関数を使用できるようになりました。
vector
カーネル コードで printf がサポートされている方法で、標準ライブラリ クラスを使用する方法はありますか? これは、カーネル コードで printf を使用する例です。
// this code only to count the 3s in an array using Cuda
//private_count is an array to hold every thread's result separately
__global__ void countKernel(int *a, int length, int* private_count)
{
printf("%d\n",threadIdx.x); //it's print the thread id and it's working
// vector<int> y;
//y.push_back(0); is there a possibility to do this?
unsigned int offset = threadIdx.x * length;
int i = offset;
for( ; i < offset + length; i++)
{
if(a[i] == 3)
{
private_count[threadIdx.x]++;
printf("%d ",a[i]);
}
}
}