ホストには、整数のベクトルのベクトルで実装されたギザギザの配列があります。
デバイスでジャグ配列を設定するために、int のポインターへのポインターを割り当てることから始めました。
int ** adjlist; // host pointer
int ** d_adjlist; // device pointer
いくつかの用語を明確にするために、ポインターの配列をadjlist
「ベース」と呼び、ポインターの配列をadjlist[i]
「歯」と呼んでいます。
// this is the width of the base
const int ens_size = 12;
// allocate the base on the device
cutilSafeCall( cudaMalloc( (void***)&d_adjlist, ens_size*sizeof(int*) ) );
// to store the contents of base on host (I can't cudaMalloc the teeth directly, as that would require dereferencing a pointer to device memory)
adjlist = static_cast<int**>( malloc( ens_size*sizeof(int*) ) );
// copy the contents of base from the device to the host
cutilSafeCall( cudaMemcpy( adjlist, d_adjlist, ens_size*sizeof(int*), cudaMemcpyDeviceToHost) );
これですべて正常に動作し、ベースが完成しました。冒頭で述べたベクトルの元のベクトルは に格納されていnets[i]->adjlist
ます。次に、次のループで歯を割り当てます。
int N = 6;
int numNets = 2;
for(int i=0; i < numNets; ++i)
{
for(int j=0; j < N; ++j)
{
k = nets[i]->adjlist[j].size();
// allocate the "teeth" of the adjacency list
cutilSafeCall( cudaMalloc( (void**)&(adjlist[N*i+j]), k ) );
}
}
ベクトルのベクトルからデバイス上の歯に歯をコピーしようとすると、私の問題が発生します。コードは次のとおりです。
// this holds the tooth to be copied to the device
int h_adjlist[Kmax]; // k <= Kmax
for(int i=0; i < numNets; ++i)
{
for(int j=0; j < N; ++j)
{
k = nets[i]->adjlist[j].size();
// copy the adjacency list of the (Ni+j)-th node
copy( nets[i]->adjlist[j].begin(), nets[i]->adjlist[j].end(), h_adjlist );
cutilSafeCall( cudaMemcpy( adjlist[N*i+j],
h_adjlist,
sizeof(int)*k,
cudaMemcpyHostToDevice ) );
}
}
コードを実行しようとすると、次Runtime API error: invalid argument.
の行でエラーが発生します。
cudaMemcpyHostToDevice ) );
少なくとも、cudaSafeCall
関数がエラーが発生したと言う行です。
これが無効な引数としてフラグ付けされているのはなぜですか? または、それが他の引数である場合、どの引数ですか?