질문 : Cuda 커널에서 "vector"클래스를 사용하는 방법이 있습니까? 시도 할 때 다음과 같은 오류가 나타납니다 :CUDA 장치 코드에서 std :: vector 사용
error : calling a host function("std::vector<int, std::allocator<int> > ::push_back") from a __device__/__global__ function not allowed
그래서 전역 섹션에서 벡터를 사용하는 방법은 무엇입니까? 는 최근 다음을 시도 :
- 개방 CUDA는 C/C++
- 는
- 변화를 장치에 코드 "의 값을 이동
- 프로젝트의 속성으로 이동 새로운 CUDA는 프로젝트를 생성 생성 "이이 값으로 설정됩니다 : compute_20, sm_20
....... 그 후 나는 내 Cuda 커널의 printf 표준 라이브러리 함수.
printf가 커널 코드에서 지원되는 방식에 표준 라이브러리 클래스 vector
을 사용하는 방법이 있습니까?
// this code only to count the 3s in an array using Cuda
//private_count is an array to hold every thread's result separately
__global__ void countKernel(int *a, int length, int* private_count)
{
printf("%d\n",threadIdx.x); //it's print the thread id and it's working
// vector<int> y;
//y.push_back(0); is there a possibility to do this?
unsigned int offset = threadIdx.x * length;
int i = offset;
for(; i < offset + length; i++)
{
if(a[i] == 3)
{
private_count[threadIdx.x]++;
printf("%d ",a[i]);
}
}
}
+1 완벽하게 합법적 인 질문 (확실하지. 불행히도 대답은 현재이다. – harrism