Я пытаюсь найти элемент float3 в массиве с наибольшим значением x (аналогично в этом примере а>):
// 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);
Однако при компиляции и выполнении я получаю следующую ошибку:
terminate called after throwing an instance of 'thrust::system::system_error'
what(): extrema failed on 2nd step: invalid device function
Aborted (core dumped)
Что я делаю не так?