다음 코드 조각, 추력을 사용하여 CUDA와 코드 사전의 종류를 생성 (CUDA를위한 C++ 템플릿 라이브러리)을 감안할 때 :최적화 CUDA
thrust::device_vector<float> dCodes(codes->begin(), codes->end());
thrust::device_vector<int> dCounts(counts->begin(), counts->end());
thrust::device_vector<int> newCounts(counts->size());
for (int i = 0; i < dCodes.size(); i++) {
float code = dCodes[i];
int count = thrust::count(dCodes.begin(), dCodes.end(), code);
newCounts[i] = dCounts[i] + count;
//Had we already a count in one of the last runs?
if (dCounts[i] > 0) {
newCounts[i]--;
}
//Remove
thrust::detail::normal_iterator<thrust::device_ptr<float> > newEnd = thrust::remove(dCodes.begin()+i+1, dCodes.end(), code);
int dist = thrust::distance(dCodes.begin(), newEnd);
dCodes.resize(dist);
newCounts.resize(dist);
}
codes->resize(dCodes.size());
counts->resize(newCounts.size());
thrust::copy(dCodes.begin(), dCodes.end(), codes->begin());
thrust::copy(newCounts.begin(), newCounts.end(), counts->begin());
문제는 내가 했으므로입니다 CUDA 시각적 프로파일 러를 사용하여 4 바이트의 다중 복사본을 발견했습니다. IMO이
- 루프 카운터에 의해 생성되는 I
- 플로트 코드, INT 카운트 및 DIST
- I에 대한 모든 액세스
(연속 copyin 4 바이트의 g는 재미 없다 ...).
그래서, 이러한 변수는 장치에서 처리되어야한다고 추력을 말하는거야 어떻게? 아니면 이미? 내가 루프에 대한 주위 (또한 slowliness 또 다른 이유가 될 수있는) 호스트 또는 디바이스에서 실행 여부를 확실하지 않다 때문에 추력 :: device_ptr를 사용
는 나를 위해 충분하지 보인다.
내가 필요한 모든 것을 복사하는 추력을 사용하여 완전히 새로운 장치 코드로 해결. –