Thrust を使用して値の配列の最小値と最大値を削減しようとしていますが、行き詰まっているようです。フロートの配列が与えられた場合、最小値と最大値を 1 回のパスで減らしたいのですが、スラストの reduce メソッドを使用すると、代わりにすべてのテンプレート コンパイル エラーの母 (または少なくともおばさん) が得られます。
私の元のコードには、削減したい 2 つの float4 配列にまたがる 5 つの値のリストが含まれていますが、この短い例に要約しました。
struct ReduceMinMax {
__host__ __device__
float2 operator()(float lhs, float rhs) {
return make_float2(Min(lhs, rhs), Max(lhs, rhs));
}
};
int main(int argc, char *argv[]){
thrust::device_vector<float> hat(4);
hat[0] = 3;
hat[1] = 5;
hat[2] = 6;
hat[3] = 1;
ReduceMinMax binary_op_of_dooooom;
thrust::reduce(hat.begin(), hat.end(), 4.0f, binary_op_of_dooooom);
}
代わりに2つの削減に分割すると、もちろん機能します。私の質問は次のとおりです。スラストを使用して1回のパスで最小値と最大値の両方を減らすことは可能ですか? そうでない場合、上記の削減を達成する最も効率的な方法は何ですか? 変換イテレータは役に立ちますか (もしそうなら、リダクションはワンパスリダクションになりますか?)
いくつかの追加情報: 私は Thrust 1.5 (CUDA 4.2.7 で提供) を使用しています。私の実際のコードは、reduce だけでなく reduce_by_key を使用しています。この質問を書いているときに transform_reduce を見つけましたが、キーは考慮されていません。