ggeo
1
Hello , I saw in a piece of code this:
std::vector< unsigned int > myarray( mysize );
std::fill( myarray.begin(), myarray.end(), 0 );
And when I tried to do:
unsigned int * devmyarray;
cudaMalloc( (void**) &devmyarray, mysize sizeof(unsigned int) )
cudaMemcpy( devmyarray , myarray , mysize sizeof(unsigned int), cudaMemcpyHostToDevice )
it throws:
no suitable conversion function from "std::vector<unsigned int, std::allocator<unsigned int>>" to "const void *" exists
Unlike ordinary C arrays, the name of a std::vector is not a pointer to its first element.
instead of this:
cudaMemcpy( devmyarray , myarray , mysize sizeof(unsigned int), cudaMemcpyHostToDevice )
(note that I’m just reproducing the junk code you put in your question above. This line won’t compile.)
try this:
cudaMemcpy( devmyarray ,&(myarray[0]) , mysize*sizeof(unsigned int), cudaMemcpyHostToDevice );
or this:
cudaMemcpy( devmyarray , myarray.data() , mysize*sizeof(unsigned int), cudaMemcpyHostToDevice );
This has nothing to do with CUDA, by the way.
ggeo
3
Ok , thank you very much for your help txbob.
( I am not used at all to vectors ,I didn’t know)