0
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/scan.h>
#include <thrust/execution_policy.h>
#include <iostream>
#include <thrust/transform.h>
struct text_functor {
text_functor() {}
__host__ __device__ int operator()(const char t) const {
if (t == '\n') return 0;
return 1;
}
};
void CountPosition1(const char *text, int *pos, int text_size)
{
thrust::transform(text, text + text_size, pos, text_functor());
}
int main() {
char s[4] = {'a', 'a', '\n', 'a'};
int r[4] = {0};
int *k;
cudaMalloc((void**) &k, sizeof(int) * 4);
CountPosition1(s, k, 4);
}
thrust :: transform에서 호스트 반복자와 디바이스 반복자 k를 섞습니다. 세그먼트 화 오류가 발생합니다. CountPosition1
에서 인수 k를 r로 변경하면 프로그램이 올바르게됩니다. 추력 함수의 모든 반복기가 동일한 소스 (호스트 또는 두 장치 모두)에 있어야합니까? 아니면이 코드에서 잘못된 점이 있습니까?스러스트 반복자 믹스 사용법
"text"와 "pos"에 모든 원시 포인터를 적용하더라도 세그먼트 결함이 발생합니다. 인수로 원시 포인터를 받아 들일 수 있습니까? device_pointer_cast를 사용하는 것이 더 좋습니까? –
원시 ** 기기 ** 포인터가 아닙니다. [this] (http://stackoverflow.com/questions/25242790/simple-sorting-using-thrust-not-working)을 읽어보십시오. 당신은 또한 아마도 내 대답에 링크 된 전체 추력 빠른 시작 가이드를 읽어야합니다. –
메시지'0x0000000000403acd in thrust :: detail :: unary_transform_functor :: operator() > (이 = 0x7fffffffe6ef, t = ...) /usr/local/cuda/bin/..//에서 thrust :: get <1> (t) = f (thrust :: get <0> (t)); 포함/추력/세부 사항/internal_functional.h : 322 ' –