디바이스 펑터 내에서 스러스트와 함께 CURAND를 사용할 수 있습니까? 최소 코드 예제가 될 수 있습니다스러스트 펑터 내에서 CURAND 사용
#include <thrust/device_vector.h>
struct Move
{
Move() {}
using Position = thrust::tuple<double, double>;
__host__ __device__
Position operator()(Position p)
{
thrust::get<0>(p) += 1.0; // use CURAND to add a random N(0,1)
thrust::get<1>(p) += 1.0; // use CURAND to add a random N(0,1)
return p;
}
};
int main()
{
// Create vectors on device
thrust::device_vector<double> p1(10, 0.0);
thrust::device_vector<double> p2(10, 0.0);
// Create zip iterators
auto pBeg = thrust::make_zip_iterator(thrust::make_tuple(p1.begin(), p2.begin()));
auto pEnd = thrust::make_zip_iterator(thrust::make_tuple(p1.end(), p2.end() ));
// Move points in the vectors
thrust::transform(pBeg, pEnd, pBeg, Move());
// Print result (just for debug)
thrust::copy(p1.begin(), p1.end(), std::ostream_iterator<double>(std::cout, "\n"));
thrust::copy(p2.begin(), p2.end(), std::ostream_iterator<double>(std::cout, "\n"));
return 0;
}
연산자 함수 내에서 난수를 생성하는 올바른 방법은 무엇입니까?
여기에 설명 된 cuRAND 장치 API를 사용해야합니다. http://docs.nvidia.com/cuda/curand/device-api-overview.html#device-api-overview –