2017-02-22 23:26:44 +01:00
|
|
|
/**
|
2019-05-28 16:17:22 +02:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-02-22 23:26:44 +01:00
|
|
|
*
|
2019-05-28 16:17:22 +02:00
|
|
|
* This source code is licensed under the MIT license found in the
|
2017-02-22 23:26:44 +01:00
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-09-20 18:59:10 +02:00
|
|
|
#include <faiss/gpu/utils/DeviceTensor.cuh>
|
|
|
|
#include <faiss/gpu/utils/Float16.cuh>
|
2017-02-22 23:26:44 +01:00
|
|
|
|
|
|
|
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,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool vectorsRowMajor,
|
2017-02-22 23:26:44 +01: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,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool queriesRowMajor,
|
2017-02-22 23:26:44 +01:00
|
|
|
int k,
|
|
|
|
Tensor<float, 2, true>& outDistances,
|
|
|
|
Tensor<int, 2, true>& outIndices,
|
|
|
|
// Do we care about `outDistances`? If not, we can
|
|
|
|
// take shortcuts.
|
2017-11-22 05:11:28 -08:00
|
|
|
bool ignoreOutDistances = false);
|
2017-02-22 23:26:44 +01: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,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool vectorsRowMajor,
|
2017-02-22 23:26:44 +01:00
|
|
|
Tensor<float, 2, true>& queries,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool queriesRowMajor,
|
2017-02-22 23:26:44 +01:00
|
|
|
int k,
|
|
|
|
Tensor<float, 2, true>& outDistances,
|
2017-11-22 05:11:28 -08:00
|
|
|
Tensor<int, 2, true>& outIndices);
|
2017-02-22 23:26:44 +01:00
|
|
|
|
|
|
|
void runIPDistance(GpuResources* resources,
|
|
|
|
Tensor<half, 2, true>& vectors,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool vectorsRowMajor,
|
2017-02-22 23:26:44 +01:00
|
|
|
Tensor<half, 2, true>& queries,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool queriesRowMajor,
|
2017-02-22 23:26:44 +01:00
|
|
|
int k,
|
|
|
|
Tensor<half, 2, true>& outDistances,
|
|
|
|
Tensor<int, 2, true>& outIndices,
|
2017-11-22 05:11:28 -08:00
|
|
|
bool useHgemm);
|
2017-02-22 23:26:44 +01:00
|
|
|
|
|
|
|
void runL2Distance(GpuResources* resources,
|
|
|
|
Tensor<half, 2, true>& vectors,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool vectorsRowMajor,
|
2017-02-22 23:26:44 +01:00
|
|
|
Tensor<half, 1, true>* vectorNorms,
|
|
|
|
Tensor<half, 2, true>& queries,
|
2019-05-28 16:17:22 +02:00
|
|
|
bool queriesRowMajor,
|
2017-02-22 23:26:44 +01:00
|
|
|
int k,
|
|
|
|
Tensor<half, 2, true>& outDistances,
|
|
|
|
Tensor<int, 2, true>& outIndices,
|
2017-06-21 06:54:28 -07:00
|
|
|
bool useHgemm,
|
2017-11-22 05:11:28 -08:00
|
|
|
bool ignoreOutDistances = false);
|
2017-02-22 23:26:44 +01:00
|
|
|
|
|
|
|
} } // namespace
|