2

I have the following code snippet

uint64_t myvec[] = {1,2,3,4,5}; int main(void) { uint64_t* dev; cudaMalloc(&dev, 5*sizeof(uint64_t)); cudaMemcpy(dev,myvec,sizeof(uint64_t)*5,cudaMemcpyHostToDevice); uint64_t* min_iter = thrust::min_element(thrust::device, dev, dev+5); return 0; } 

This code crashes with a segfault because of min_element on device.

But this code seems to be working if i perform it on host

uint64_t* min_iter = thrust::min_element(thrust::host, myvec, myvec+5); 

I don't know what's wrong. I am using cuda 7.5. Is this a bug?

1
  • 3
    This seems to be a bug: github.com/thrust/thrust/issues/776. You can work around it with this: uint64_t* min_iter = thrust::min_element(thrust::device, thrust::device_pointer_cast(dev), thrust::device_pointer_cast(dev+5)).get(); Commented Apr 13, 2016 at 20:37

1 Answer 1

2

This has been confirmed as a bug in Thrust. In comments, it was suggested that this:

uint64_t* min_iter = thrust::min_element(thrust::device, thrust::device_pointer_cast(dev), thrust::device_pointer_cast(dev+5)).get(); 

would work around the problem.

There now appears to be a patch which has been added to the current Thrust development branch to address this problem.

[This answer has been mostly assembled from comments and added as a community wiki entry to get this question off the unanswered question list for the CUDA tag].

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.