我有一個使用推力目前正常在單GPU工作的一個CUDA C++代碼。我現在想修改它爲多GPU。我有一個主機功能,其中包括一些Thrust調用,用於對設備陣列進行排序,複製和計算差異等。我想要使用每個GPU同時在自己的(獨立)陣列集上運行這個Thrust調用序列。我讀過Thrust函數的返回值是同步的,但我可以使用OpenMP讓每個主機線程調用一個在獨立GPU上運行的函數(使用Thrust調用)?多GPU CUDA推力
例如(在瀏覽器編碼):
#pragma omp parallel for
for (int dev=0; dev<Ndev; dev++){
cudaSetDevice(dev);
runthrustfunctions(dev);
}
void runthrustfunctions(int dev){
/*lots of Thrust functions running on device arrays stored on corresponding GPU*/
//for example this is just a few of the lines"
thrust::device_ptr<double> pos_ptr = thrust::device_pointer_cast(particle[dev].pos);
thrust::device_ptr<int> list_ptr = thrust::device_pointer_cast(particle[dev].list);
thrust::sequence(list_ptr,list_ptr+length);
thrust::sort_by_key(pos_ptr, pos_ptr+length,list_ptr);
thrust::device_vector<double> temp(length);
thrust::gather(list_ptr,list_ptr+length,pos_ptr,temp.begin());
thrust::copy(temp.begin(), temp.end(), pos_ptr);
}`
我認爲還需要結構 「顆粒[0]」 將被存儲在GPU 0,粒子[1]上GPU 1等,我的猜測是不可能的。一個選項可能是針對每個GPU情況使用「開關」和單獨的代碼。
我想知道這是否是一個正確的做法,或者有更好的辦法嗎? 感謝
爲什麼你需要設置不同的主機線程的設備?你可以使用一個簡單的例子:[多GPU使用CUDA Thrust](http://stackoverflow.com/questions/16885971/multi-gpu-usage-with-cuda-thrust)? – JackOLantern
推測是一種解決某些推力操作阻塞主機線程的方法。 –