Hi,
I can’t work out what function thrust::reduce needs for scoring my objects.
I think I might need to change just one or two lines, but I don’t see how.
I’d appreciate your insights.
// Needs fixing - but how?
Thanks,
Paul
class scored_orientation_t {
public:
__device__ scored_orientation_t(float score_in, int idx_in) : score(score_in), idx(idx_in) {}
int idx;
float score;
__device__ bool operator<(const scored_orientation_t &o) const {
return (score < o.score);
}
__device__ bool operator>(const scored_orientation_t &o) const {
return (score > o.score);
}
};
an array of which holds the scores of various orientations.
I want to find the orientation parameters (currently merely idx) with the maximum score
unsigned int N_trials = 10000;
scored_orientation_t *scored_orientations_p;
cudaMalloc(&scored_orientations_p, N_trials * sizeof(scored_orientation_t));
// .. code to set the scores here ..
// wrap raw pointer with a device_ptr
thrust::device_ptr<scored_orientation_t> dev_ptr(scored_orientations_p);
// Needs fixing - but how?
thrust::device_ptr<scored_orientation_t> best_via_thrust = thrust::reduce(dev_ptr, dev_ptr + N_trials, 0, thrust::max_element<scored_orientation_t>());