/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the CC-by-NC 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 "MathOperators.cuh" #include "WarpShuffles.cuh" namespace faiss { namespace gpu { /// A simple pair type for CUDA device usage template struct Pair { constexpr __device__ inline Pair() { } constexpr __device__ inline Pair(K key, V value) : k(key), v(value) { } __device__ inline bool operator==(const Pair& rhs) const { return Math::eq(k, rhs.k) && Math::eq(v, rhs.v); } __device__ inline bool operator!=(const Pair& rhs) const { return !operator==(rhs); } __device__ inline bool operator<(const Pair& rhs) const { return Math::lt(k, rhs.k) || (Math::eq(k, rhs.k) && Math::lt(v, rhs.v)); } __device__ inline bool operator>(const Pair& rhs) const { return Math::gt(k, rhs.k) || (Math::eq(k, rhs.k) && Math::gt(v, rhs.v)); } K k; V v; }; template inline __device__ Pair shfl_up(const Pair& pair, unsigned int delta, int width = kWarpSize) { return Pair(shfl_up(pair.k, delta, width), shfl_up(pair.v, delta, width)); } template inline __device__ Pair shfl_xor(const Pair& pair, int laneMask, int width = kWarpSize) { return Pair(shfl_xor(pair.k, laneMask, width), shfl_xor(pair.v, laneMask, width)); } } } // namespace