从std :: deque复制到推力device_vector

时间:2017-04-24 14:16:31

标签: c++ c++11 cuda thrust stddeque

我试图制作一个示例代码,我将其从std::deque复制到thrust::device_vector,但编译器警告calling a __host__ function from a __host__ __device__ function is not allowed(我试图复制粘贴整个错误这里但它超出了问题中人物的限制)。如果需要,我可以发布更多细节。

代码编译成功,但我对这些错误感到非常恼火,因为它们不会像std::liststd::vector那样与其他stl容器一起发生。 我想知道它们为什么会发生,我该如何解决这些警告。

以下是nvcc --version结果:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61

这是我的示例代码

#include <iostream>
#include <algorithm>
#include <deque>
#include <thrust/device_vector.h>

const uint size = 100;

__global__
void hello (int *a) {
  a[threadIdx.x] += threadIdx.x;
}

int main (int argc, const char **argv) {
  std::deque<int> a(size);
  std::fill(a.begin(), a.end(), 1);

  thrust::device_vector<int> a_cuda(a.begin(), a.end());

  dim3 dimBlock(size, 1);
  dim3 dimGrid(1, 1);
  hello<<< dimGrid, dimBlock >>>(thrust::raw_pointer_cast(&a_cuda[0]));

  thrust::copy(a_cuda.begin(), a_cuda.end(), a.begin());

  for (const int i : a) {
    std::cout << i << ' ';
  }

  std::cout << std::endl;

  return EXIT_SUCCESS;
}

以下是我用来编译的命令:

nvcc file.cu -std=c++11 -O3 -o hello

提前致谢

0 个答案:

没有答案
相关问题