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?

0 Answers0