2013-06-09 2 views
2

다음 코드에는 CPU 또는 GPU에서 실행될 수있는 정보가 없습니다. 나는 "reduce"연산이 어디에서 실행되는지 궁금합니다. 추력 : 알고리즘 호출이 실행되는 위치를 직접 제어하는 ​​방법은 무엇입니까?

#include <thrust/iterator/counting_iterator.h> 
... 
// create iterators 
thrust::counting_iterator<int> first(10); 
thrust::counting_iterator<int> last = first + 3; 

first[0] // returns 10 
first[1] // returns 11 
first[100] // returns 110 

// sum of [first, last) 
thrust::reduce(first, last); // returns 33 (i.e. 10 + 11 + 12) 

또한

데이터 추력 :: host_vector 정의하더라도
thrust::transform_reduce(
    thrust::counting_iterator<unsigned int>(0), 
    thrust::counting_iterator<unsigned int>(N), 
    MyOperation(data), 0 ,thrust::plus<unsigned int>()) 

이 기능은 GPU (파일 이름의 .cpp 끝나는 때문에 컴파일러는 관련 에러를 범)에서 실행하려고. CPU에서 코드를 실행하려면 어떻게해야합니까? 또는 동일한 작업을 수행하는 또 다른 방법을 찾아야합니까? counting_iterator를 사용하지 않습니까?

+0

내가이 페이지 http://code.google.com/p/thrust/wiki/DirectSystemAccess에 설명하지만, 컴파일러가 retag.h 파일을 찾을 수 없습니다로 counting_iterator 태그를 재지 시도,도 OMP/memory.h 파일 .. – phoad

답변

4

기본적으로 이와 같은 알고리즘 호출은 기기 백엔드 (즉, 사례의 GPU)에서 실행됩니다.

#include <thrust/execution_policy.h> 

... 

thrust::reduce(thrust::host, first, last); 

... 

thrust::transform_reduce(thrust::host, 
         first, 
         last, 
         MyOperation(data), 
         0, 
         thrust::plus<unsigned int>()); 

는 1.6 추력 사용하는 경우 : 당신은 추력 1.7 이상을 사용하는 경우

는 호스트 (즉, CPU)에서 실행하는 알고리즘 호출을 강제로 thrust::host 실행 정책을 사용 , 기존 반복자 드래그하는 retag하여 호스트로 호출 목표를 재설정 할 수 있습니다 : 당신은 추력 전 1.6의 이전 버전을 사용하는 경우

#include <thrust/iterator/retag.h> 

... 

thrust::reduce(thrust::retag<thrust::host_system_tag>(first), 
       thrust::retag<thrust::host_system_tag>(last)); 

... 

thrust::transform_reduce(thrust::retag<thrust::host_system_tag>(first), 
         thrust::retag<thrust::host_system_tag>(last), 
         MyOperation(data), 
         0, 
         thrust::plus<unsigned int>()); 

를 템플릿으로 counting_iteratorhost_space_tag를 전달해야 매개 변수 :

thrust::reduce(thrust::counting_iterator<unsigned int, thrust::host_space_tag>(0), 
       thrust::counting_iterator<unsigned int, thrust::host_space_tag>(N)); 
+0

환상적. 이에 관한 도움 문서가 있습니까? 나는 NVIDIA의 psg 서버를 사용하고 compile하는 동안 execution_policy.h를 찾을 수 없다 :(그래서 내 문제를 해결하지 못했지만 솔루션 인 것 같다. 내가 컴파일 할 때 약간의 에러가 생기기 때문에 나는 cuda_13 태그로 컴파일한다. cuda_20 태그. – phoad

+1

추력 1.7은 아직 공개적으로 공개되지 않은 CUDA 5.5와 함께 제공됩니다. 그 동안 Github에서 얻을 수 있습니다. 다음은 몇 가지 문서입니다. https://github.com/thrust/thrust/wiki/Direct-System -Access –

+0

NVIDIA 서버에서 Thrust 1.5를 사용할 수 있습니다.이 버전에는 아무런 해결책이 없다고 생각합니까? 이미 Thrust 1.5가 있으므로 추력의 로컬 복사본을 사용하고 강제로 사용해야합니까? – phoad

관련 문제