NVidia CUDA / Thrustを学習するために、簡単なプログラムを作成しようとしています。私は完全な初心者です。私がやろうとしているのは、カスタム述語でfind_ifを使用することです。今のところ私の述語はすべてに対してtrueを返すだけなので、すべての入力を取得しようとしています。最終的に文字列を検索し、ファンクターを文字列Xで初期化してから、GPUが一致するすべての文字列を見つけられるようにします。
ここでいくつかの点で混乱しています。
文字列へのポインタでいっぱいのdevice_vectorを埋めてから、MemCmp述語に対して実行しようとしています。
まず、device_vectorは文字列をメインメモリからGPUメモリにコピーすることを「知っている」のでしょうか、それともポインタ値をコピーするだけでしょうか。
次に、「count = d_inputVector.end()--iter;」の行で これは、find_ifの結果であるイテレータ内のアイテムの数である12を返します。これは間違っていませんか?iterを試してみると、d_inputVector.begin()はゼロを返し、どこにも到達しません。
最後に、私の小さなプログラムの結果を得る私の方法は正しいですか?私はthrust::copyを使用してメモリをhost_vectorにコピーしますか?結果を表示するには、最後のようなループで十分ですか?
どんな提案でも大歓迎です。ありがとう、
mj
struct MemCmp
{
__host__ __device__
bool operator()(char *data)
{
bool rv = false;
rv = true;
return rv;
}
};
....
// I initialize a device_vector and then copy pointers from main memory into the device_vector.
thrust::device_vector<char*> d_inputVector( itemCount );
for( int i=0; i<itemCount; i++ ){
d_inputVector[i] = inputData[i];
}
thrust::device_vector<char*>::iterator iter;
iter = thrust::find_if( d_inputVector.begin(), d_inputVector.end(), MemCmp() );
// this is the count that I think is wrong.
count = d_inputVector.end() - iter;
thrust::host_vector<char*> results( count );
thrust::copy( d_inputVector.begin(), iter, results.begin() );
for( thrust::host_vector<char *>::iterator it = results.begin(); it != results.end(); it++ ){
char* foo = *it;
}