내가 CUDA 추력을 사용하여 파일 내에서 보고서 실행의 발생을 생산하는 "실행 길이 인코더를"구축을 위해 노력하고 실행 길이 인코딩. 이 "보고서"를 사용하여 나중에 런타임 길이 인코딩 단계를 수행합니다.CUDA 추력 - 실행 지수
입력 서열
inputSequence = [a, a, b, c, a, a, a];
의 출력 시퀀스 :
runChar = [a, a];
runCount = [2, 3];
runPosition = [0, 4];
출력은 2의 실행 위치 0에서 시작하는 그리고 3의 실행이 위치에서 시작있어 desribes 4.
아래에 설명 된 추력 런 길이 인코더 예제는 두 개의 배열을 출력합니다. 하나는 출력 char 용이고 다른 하나는 길이 용입니다.
2 개 미만의 실행은 제외되고 각 실행이 발생하는 위치도 출력되도록 수정하고 싶습니다. 이미 표시된 것을 구축
// input data on the host
const char data[] = "aaabbbbbcddeeeeeeeeeff";
const size_t N = (sizeof(data)/sizeof(char)) - 1;
// copy input data to the device
thrust::device_vector<char> input(data, data + N);
// allocate storage for output data and run lengths
thrust::device_vector<char> output(N);
thrust::device_vector<int> lengths(N);
// print the initial data
std::cout << "input data:" << std::endl;
thrust::copy(input.begin(), input.end(), std::ostream_iterator<char>(std::cout, ""));
std::cout << std::endl << std::endl;
// compute run lengths
size_t num_runs = thrust::reduce_by_key
(input.begin(), input.end(), // input key sequence
thrust::constant_iterator<int>(1), // input value sequence
output.begin(), // output key sequence
lengths.begin() // output value sequence
).first - output.begin(); // compute the output size
// print the output
std::cout << "run-length encoded output:" << std::endl;
for(size_t i = 0; i < num_runs; i++)
std::cout << "(" << output[i] << "," << lengths[i] << ")";
std::cout << std::endl;
return 0;