Pregunta

I have this:

mykernel<<<....>>>(....,devCols);

    thrust::device_ptr<float> thrust_dev_ptr_Cols(devCols);
    thrust::inclusive_scan( thrust_dev_ptr_Cols , thrust_dev_ptr_Cols  + numbers ,thrust_dev_ptr_Cols);


    float * raw_ptr = (float*) malloc ( numbers   * sizeof(float) );
    thrust::copy(thrust_dev_ptr_Cols , thrust_dev_ptr_Cols + numbers  ,raw_ptr );

    numberCols = *(raw_ptr + (numbers  -1) );

The inclusive scan works fine. I want to copy the result from the inclusive scan to host and use it to compute numberCols which is just a float variable.

I am trying the above but the numberCols results to zero (as I said , the inclusive scan works fine).

--------------EDIT----------------

To anyone who might read this post.

This code runs fine too!

It seems the problem was the presenting of results.

(Thanks to Robert Crovella who "insisted" that this code was ok)

¿Fue útil?

Solución

EDIT: See the comments and the EDIT in the original question! This solution is probably not necessary:

Not (necessarily) an answer, but too long for a comment: I don't see a reason why it should not be possible to simply copy the data from the (raw) pointer to the host with cudaMemcpy:

float* devPtr = thrust::raw_pointer_cast(thrust_dev_ptr_Cols); 
float* hostPtr = (float*)malloc (numbers*sizeof(float));
cudaMemcpy(hostPtr, devPtr, numbers*sizeof(float), cudaMemcpyDeviceToHost);

EDIT: BTW, if devCols is still known at this point, then you could probably use devCols directly instead of the devPtr - this is not obvious from the posted code

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top