1

I'm trying to make a sample code where I copy from a std::deque to a thrust::device_vector but the compiler warns calling a __host__ function from a __host__ __device__ function is not allowed (I tried to copy-paste the entire error here but it is beyond the limit of characters in questions). I can post more details if needed.

The code compiles successfully, but I'm really annoyed by these errors as they do not happen with other stl containers as std::list and std::vector. I want to know why they are happening and how do I fix these warning.

Here is the nvcc --version result:

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

Here is my sample code

#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;
}

And here is the command I'm using to compile:

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

Thanks in advance

Marco
  • 827
  • 6
  • 18
  • So what's your question, and what would you like us to do about? – talonmies Apr 24 '17 at 15:15
  • As I said, I'm annoyed with the error output and I want to know why this is happening / how to fix it (just edited to add these two last parts, thanks for pointing it out) – Marco Apr 24 '17 at 15:19
  • 1
    Well, you only said you were annoyed. You didn't actually ask any sort of question. I think you should be posting this as a bug report to the thrust developers, not asking about it here. It is obvious that there is something broken in the thrust copy constructor which is emitting code when it probably shouldn't (it also does it with thrust::host_vector copy construction with a std::deque as the source) – talonmies Apr 24 '17 at 15:25
  • I thought it was a problem on my code or even a limitation when copying using deques. I will keep it open to see if someone knows what is happening and I will file a bug report on thrust. Thanks – Marco Apr 24 '17 at 16:08
  • 2
    As a workaround, if you copy to a `std::vector` first, you can go from there – Robert Crovella Apr 24 '17 at 16:31

0 Answers0