2017-02-23 06:26:44 +08:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-07-30 15:18:45 +08:00
|
|
|
* This source code is licensed under the BSD+Patents license found in the
|
2017-02-23 06:26:44 +08:00
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../utils/DeviceTensor.cuh"
|
|
|
|
#include "../utils/Float16.cuh"
|
|
|
|
|
|
|
|
namespace faiss { namespace gpu {
|
|
|
|
|
|
|
|
class GpuResources;
|
|
|
|
|
|
|
|
/// Calculates brute-force L2 distance between `vectors` and
|
|
|
|
/// `queries`, returning the k closest results seen
|
|
|
|
void runL2Distance(GpuResources* resources,
|
|
|
|
Tensor<float, 2, true>& vectors,
|
2017-03-21 01:48:35 +08:00
|
|
|
Tensor<float, 2, true>* vectorsTransposed,
|
2017-02-23 06:26:44 +08:00
|
|
|
// can be optionally pre-computed; nullptr if we
|
|
|
|
// have to compute it upon the call
|
|
|
|
Tensor<float, 1, true>* vectorNorms,
|
|
|
|
Tensor<float, 2, true>& queries,
|
|
|
|
int k,
|
|
|
|
Tensor<float, 2, true>& outDistances,
|
|
|
|
Tensor<int, 2, true>& outIndices,
|
|
|
|
// Do we care about `outDistances`? If not, we can
|
|
|
|
// take shortcuts.
|
|
|
|
bool ignoreOutDistances = false,
|
|
|
|
// Hint to use a different sized tile for
|
|
|
|
// multi-streaming the queries. If <= 0, we use the
|
2017-04-06 19:33:41 +08:00
|
|
|
// default
|
|
|
|
int tileSizeOverride = -1);
|
2017-02-23 06:26:44 +08:00
|
|
|
|
|
|
|
/// Calculates brute-force inner product distance between `vectors`
|
|
|
|
/// and `queries`, returning the k closest results seen
|
|
|
|
void runIPDistance(GpuResources* resources,
|
|
|
|
Tensor<float, 2, true>& vectors,
|
2017-03-21 01:48:35 +08:00
|
|
|
Tensor<float, 2, true>* vectorsTransposed,
|
2017-02-23 06:26:44 +08:00
|
|
|
Tensor<float, 2, true>& queries,
|
|
|
|
int k,
|
|
|
|
Tensor<float, 2, true>& outDistances,
|
|
|
|
Tensor<int, 2, true>& outIndices,
|
|
|
|
// Hint to use a different sized tile for
|
|
|
|
// multi-streaming the queries. If <= 0, we use the
|
2017-04-06 19:33:41 +08:00
|
|
|
// default
|
|
|
|
int tileSizeOverride = -1);
|
2017-02-23 06:26:44 +08:00
|
|
|
|
|
|
|
#ifdef FAISS_USE_FLOAT16
|
|
|
|
void runIPDistance(GpuResources* resources,
|
|
|
|
Tensor<half, 2, true>& vectors,
|
2017-03-21 01:48:35 +08:00
|
|
|
Tensor<half, 2, true>* vectorsTransposed,
|
2017-02-23 06:26:44 +08:00
|
|
|
Tensor<half, 2, true>& queries,
|
|
|
|
int k,
|
|
|
|
Tensor<half, 2, true>& outDistances,
|
|
|
|
Tensor<int, 2, true>& outIndices,
|
2017-06-21 21:54:28 +08:00
|
|
|
bool useHgemm,
|
2017-04-06 19:33:41 +08:00
|
|
|
int tileSizeOverride = -1);
|
2017-02-23 06:26:44 +08:00
|
|
|
|
|
|
|
void runL2Distance(GpuResources* resources,
|
|
|
|
Tensor<half, 2, true>& vectors,
|
2017-03-21 01:48:35 +08:00
|
|
|
Tensor<half, 2, true>* vectorsTransposed,
|
2017-02-23 06:26:44 +08:00
|
|
|
Tensor<half, 1, true>* vectorNorms,
|
|
|
|
Tensor<half, 2, true>& queries,
|
|
|
|
int k,
|
|
|
|
Tensor<half, 2, true>& outDistances,
|
|
|
|
Tensor<int, 2, true>& outIndices,
|
2017-06-21 21:54:28 +08:00
|
|
|
bool useHgemm,
|
2017-02-23 06:26:44 +08:00
|
|
|
bool ignoreOutDistances = false,
|
2017-04-06 19:33:41 +08:00
|
|
|
int tileSizeOverride = -1);
|
2017-02-23 06:26:44 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
} } // namespace
|