/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD+Patents license found in the * LICENSE file in the root directory of this source tree. */ // Copyright 2004-present Facebook. All Rights Reserved. #pragma once #include #include "Limits.cuh" #include "MathOperators.cuh" #include "Pair.cuh" namespace faiss { namespace gpu { template struct Sum { __device__ inline T operator()(T a, T b) const { return Math::add(a, b); } inline __device__ T identity() const { return Math::zero(); } }; template struct Min { __device__ inline T operator()(T a, T b) const { return Math::lt(a, b) ? a : b; } inline __device__ T identity() const { return Limits::getMax(); } }; template struct Max { __device__ inline T operator()(T a, T b) const { return Math::gt(a, b) ? a : b; } inline __device__ T identity() const { return Limits::getMin(); } }; /// Used for producing segmented prefix scans; the value of the Pair /// denotes the start of a new segment for the scan template struct SegmentedReduce { inline __device__ SegmentedReduce(const ReduceOp& o) : op(o) { } __device__ inline Pair operator()(const Pair& a, const Pair& b) const { return Pair(b.v ? b.k : op(a.k, b.k), a.v || b.v); } inline __device__ Pair identity() const { return Pair(op.identity(), false); } ReduceOp op; }; } } // namespace