0

I'm trying to find the float3 element in an array with the highest x value (similar to this example):

// Find the variable with the max_x value // Binary predicate struct comp_float3_x{ __host__ __device__ bool operator()(const float3& lhs, const float3& rhs){ return lhs.x < rhs.x; } }; /*initialize*/ size_t n = 8; float3 *data = cudaMallocManaged(...); /*set random values*/ /*find the max x element*/ thrust::device_ptr<float3> d_ptr = thrust::device_pointer_cast(data); thrust::device_ptr<float3> it_ptr = thrust::max_element(thrust::device, d_ptr, d_ptr + n, comp_float3_x()); float3 result; cudaMemcpy(&result, it_ptr.get(), sizeof(float3), cudaMemcpyDeviceToHost); printf("%f, %f, %f", result.x, result.y, result.z); 

However when compiling and executed, I get the following error:

terminate called after throwing an instance of 'thrust::system::system_error' what(): extrema failed on 2nd step: invalid device function Aborted (core dumped) 

What am I doing wrong?

2
  • 1
    you may be compiling for a GPU architecture that does not match the GPU you are actually running on. Commented Apr 21, 2020 at 20:06
  • Wow, can't believe it was such an easy fix. Thank you, that solved it. Commented Apr 21, 2020 at 20:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.