Commit 395d2ce6 authored by huchen's avatar huchen
Browse files

init the faiss for rocm

parent 5ded39f5
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c -*-
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "../AutoTune_c.h"
#include "../Index_c.h"
#include "../error_c.h"
#include "../index_factory_c.h"
#include "DeviceUtils_c.h"
#include "GpuAutoTune_c.h"
#include "StandardGpuResources_c.h"
#define FAISS_TRY(C) \
{ \
if (C) { \
fprintf(stderr, "%s", faiss_get_last_error()); \
exit(-1); \
} \
}
double drand() {
return (double)rand() / (double)RAND_MAX;
}
int main() {
time_t seed = time(NULL);
srand(seed);
int gpus = -1;
FAISS_TRY(faiss_get_num_gpus(&gpus));
printf("%d GPU devices are available\n", gpus);
printf("Generating some data...\n");
int d = 128; // dimension
int nb = 100000; // database size
int nq = 10000; // nb of queries
float* xb = malloc(d * nb * sizeof(float));
float* xq = malloc(d * nq * sizeof(float));
for (int i = 0; i < nb; i++) {
for (int j = 0; j < d; j++)
xb[d * i + j] = drand();
xb[d * i] += i / 1000.;
}
for (int i = 0; i < nq; i++) {
for (int j = 0; j < d; j++)
xq[d * i + j] = drand();
xq[d * i] += i / 1000.;
}
printf("Loading standard GPU resources...\n");
FaissStandardGpuResources* gpu_res = NULL;
FAISS_TRY(faiss_StandardGpuResources_new(&gpu_res));
printf("Building an index...\n");
FaissIndex* cpu_index = NULL;
FAISS_TRY(faiss_index_factory(
&cpu_index, d, "Flat", METRIC_L2)); // use factory to create index
printf("Moving index to the GPU...\n");
FaissGpuIndex* index = NULL;
FaissGpuClonerOptions* options = NULL;
FAISS_TRY(faiss_GpuClonerOptions_new(&options));
FAISS_TRY(faiss_index_cpu_to_gpu_with_options(
gpu_res, 0, cpu_index, options, &index));
printf("is_trained = %s\n",
faiss_Index_is_trained(index) ? "true" : "false");
FAISS_TRY(faiss_Index_add(index, nb, xb)); // add vectors to the index
printf("ntotal = %ld\n", faiss_Index_ntotal(index));
printf("Searching...\n");
int k = 5;
{ // sanity check: search 5 first vectors of xb
idx_t* I = malloc(k * 5 * sizeof(idx_t));
float* D = malloc(k * 5 * sizeof(float));
FAISS_TRY(faiss_Index_search(index, 5, xb, k, D, I));
printf("I=\n");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < k; j++)
printf("%5ld (d=%2.3f) ", I[i * k + j], D[i * k + j]);
printf("\n");
}
free(I);
free(D);
}
{ // search xq
idx_t* I = malloc(k * nq * sizeof(idx_t));
float* D = malloc(k * nq * sizeof(float));
FAISS_TRY(faiss_Index_search(index, 5, xb, k, D, I));
printf("I=\n");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < k; j++)
printf("%5ld (d=%2.3f) ", I[i * k + j], D[i * k + j]);
printf("\n");
}
free(I);
free(D);
}
printf("Freeing index...\n");
faiss_Index_free(index);
printf("Freeing GPU resources...\n");
faiss_GpuResources_free(gpu_res);
faiss_GpuClonerOptions_free(options);
printf("Done.\n");
return 0;
}
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-
#ifndef GPU_MACROS_IMPL_H
#define GPU_MACROS_IMPL_H
#include "../macros_impl.h"
#undef DEFINE_GETTER
#define DEFINE_GETTER(clazz, ty, name) \
ty faiss_##clazz##_##name(const Faiss##clazz* obj) { \
return static_cast<ty>( \
reinterpret_cast<const faiss::gpu::clazz*>(obj)->name); \
}
#undef DEFINE_SETTER
#define DEFINE_SETTER(clazz, ty, name) \
void faiss_##clazz##_set_##name(Faiss##clazz* obj, ty val) { \
reinterpret_cast<faiss::gpu::clazz*>(obj)->name = val; \
}
#undef DEFINE_SETTER_STATIC
#define DEFINE_SETTER_STATIC(clazz, ty_to, ty_from, name) \
void faiss_##clazz##_set_##name(Faiss##clazz* obj, ty_from val) { \
reinterpret_cast<faiss::gpu::clazz*>(obj)->name = \
static_cast<ty_to>(val); \
}
#undef DEFINE_DESTRUCTOR
#define DEFINE_DESTRUCTOR(clazz) \
void faiss_##clazz##_free(Faiss##clazz* obj) { \
delete reinterpret_cast<faiss::gpu::clazz*>(obj); \
}
#endif
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-
#include "AuxIndexStructures_c.h"
#include <faiss/impl/AuxIndexStructures.h>
#include <iostream>
#include "../macros_impl.h"
using faiss::BufferList;
using faiss::DistanceComputer;
using faiss::IDSelector;
using faiss::IDSelectorBatch;
using faiss::IDSelectorRange;
using faiss::RangeQueryResult;
using faiss::RangeSearchPartialResult;
using faiss::RangeSearchResult;
DEFINE_GETTER(RangeSearchResult, size_t, nq)
int faiss_RangeSearchResult_new(FaissRangeSearchResult** p_rsr, idx_t nq) {
try {
*p_rsr = reinterpret_cast<FaissRangeSearchResult*>(
new RangeSearchResult(nq));
return 0;
}
CATCH_AND_HANDLE
}
int faiss_RangeSearchResult_new_with(
FaissRangeSearchResult** p_rsr,
idx_t nq,
int alloc_lims) {
try {
*p_rsr = reinterpret_cast<FaissRangeSearchResult*>(
new RangeSearchResult(nq, static_cast<bool>(alloc_lims)));
return 0;
}
CATCH_AND_HANDLE
}
/// called when lims contains the nb of elements result entries
/// for each query
int faiss_RangeSearchResult_do_allocation(FaissRangeSearchResult* rsr) {
try {
reinterpret_cast<RangeSearchResult*>(rsr)->do_allocation();
return 0;
}
CATCH_AND_HANDLE
}
DEFINE_DESTRUCTOR(RangeSearchResult)
/// getter for buffer_size
DEFINE_GETTER(RangeSearchResult, size_t, buffer_size)
/// getter for lims: size (nq + 1)
void faiss_RangeSearchResult_lims(FaissRangeSearchResult* rsr, size_t** lims) {
*lims = reinterpret_cast<RangeSearchResult*>(rsr)->lims;
}
/// getter for labels and respective distances (not sorted):
/// result for query i is labels[lims[i]:lims[i+1]]
void faiss_RangeSearchResult_labels(
FaissRangeSearchResult* rsr,
idx_t** labels,
float** distances) {
auto sr = reinterpret_cast<RangeSearchResult*>(rsr);
*labels = sr->labels;
*distances = sr->distances;
}
DEFINE_DESTRUCTOR(IDSelector)
int faiss_IDSelector_is_member(const FaissIDSelector* sel, idx_t id) {
return reinterpret_cast<const IDSelector*>(sel)->is_member(id);
}
DEFINE_DESTRUCTOR(IDSelectorRange)
DEFINE_GETTER(IDSelectorRange, idx_t, imin)
DEFINE_GETTER(IDSelectorRange, idx_t, imax)
int faiss_IDSelectorRange_new(
FaissIDSelectorRange** p_sel,
idx_t imin,
idx_t imax) {
try {
*p_sel = reinterpret_cast<FaissIDSelectorRange*>(
new IDSelectorRange(imin, imax));
return 0;
}
CATCH_AND_HANDLE
}
DEFINE_GETTER(IDSelectorBatch, int, nbits)
DEFINE_GETTER(IDSelectorBatch, idx_t, mask)
int faiss_IDSelectorBatch_new(
FaissIDSelectorBatch** p_sel,
size_t n,
const idx_t* indices) {
try {
*p_sel = reinterpret_cast<FaissIDSelectorBatch*>(
new IDSelectorBatch(n, indices));
return 0;
}
CATCH_AND_HANDLE
}
// Below are structures used only by Index implementations
DEFINE_DESTRUCTOR(BufferList)
DEFINE_GETTER(BufferList, size_t, buffer_size)
DEFINE_GETTER(BufferList, size_t, wp)
int faiss_BufferList_append_buffer(FaissBufferList* bl) {
try {
reinterpret_cast<BufferList*>(bl)->append_buffer();
return 0;
}
CATCH_AND_HANDLE
}
int faiss_BufferList_new(FaissBufferList** p_bl, size_t buffer_size) {
try {
*p_bl = reinterpret_cast<FaissBufferList*>(new BufferList(buffer_size));
return 0;
}
CATCH_AND_HANDLE
}
int faiss_BufferList_add(FaissBufferList* bl, idx_t id, float dis) {
try {
reinterpret_cast<BufferList*>(bl)->add(id, dis);
return 0;
}
CATCH_AND_HANDLE
}
/// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
/// tables dest_ids, dest_dis
int faiss_BufferList_copy_range(
FaissBufferList* bl,
size_t ofs,
size_t n,
idx_t* dest_ids,
float* dest_dis) {
try {
reinterpret_cast<BufferList*>(bl)->copy_range(
ofs, n, dest_ids, dest_dis);
return 0;
}
CATCH_AND_HANDLE
}
DEFINE_GETTER(RangeQueryResult, idx_t, qno)
DEFINE_GETTER(RangeQueryResult, size_t, nres)
DEFINE_GETTER_PERMISSIVE(RangeQueryResult, FaissRangeSearchPartialResult*, pres)
int faiss_RangeQueryResult_add(FaissRangeQueryResult* qr, float dis, idx_t id) {
try {
reinterpret_cast<RangeQueryResult*>(qr)->add(dis, id);
return 0;
}
CATCH_AND_HANDLE
}
DEFINE_GETTER_PERMISSIVE(RangeSearchPartialResult, FaissRangeSearchResult*, res)
int faiss_RangeSearchPartialResult_new(
FaissRangeSearchPartialResult** p_res,
FaissRangeSearchResult* res_in) {
try {
*p_res = reinterpret_cast<FaissRangeSearchPartialResult*>(
new RangeSearchPartialResult(
reinterpret_cast<RangeSearchResult*>(res_in)));
return 0;
}
CATCH_AND_HANDLE
}
int faiss_RangeSearchPartialResult_finalize(
FaissRangeSearchPartialResult* res) {
try {
reinterpret_cast<RangeSearchPartialResult*>(res)->finalize();
return 0;
}
CATCH_AND_HANDLE
}
/// called by range_search before do_allocation
int faiss_RangeSearchPartialResult_set_lims(
FaissRangeSearchPartialResult* res) {
try {
reinterpret_cast<RangeSearchPartialResult*>(res)->set_lims();
return 0;
}
CATCH_AND_HANDLE
}
int faiss_RangeSearchPartialResult_new_result(
FaissRangeSearchPartialResult* res,
idx_t qno,
FaissRangeQueryResult** qr) {
try {
auto q = &reinterpret_cast<RangeSearchPartialResult*>(res)->new_result(
qno);
if (qr) {
*qr = reinterpret_cast<FaissRangeQueryResult*>(&q);
}
return 0;
}
CATCH_AND_HANDLE
}
DEFINE_DESTRUCTOR(DistanceComputer)
int faiss_DistanceComputer_set_query(
FaissDistanceComputer* dc,
const float* x) {
try {
reinterpret_cast<DistanceComputer*>(dc)->set_query(x);
return 0;
}
CATCH_AND_HANDLE
}
int faiss_DistanceComputer_vector_to_query_dis(
FaissDistanceComputer* dc,
idx_t i,
float* qd) {
try {
*qd = reinterpret_cast<DistanceComputer*>(dc)->operator()(i);
return 0;
}
CATCH_AND_HANDLE
}
int faiss_DistanceComputer_symmetric_dis(
FaissDistanceComputer* dc,
idx_t i,
idx_t j,
float* vd) {
try {
*vd = reinterpret_cast<DistanceComputer*>(dc)->symmetric_dis(i, j);
return 0;
}
CATCH_AND_HANDLE
}
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c -*-
#ifndef FAISS_AUX_INDEX_STRUCTURES_C_H
#define FAISS_AUX_INDEX_STRUCTURES_C_H
#include "../Index_c.h"
#include "../faiss_c.h"
#ifdef __cplusplus
extern "C" {
#endif
FAISS_DECLARE_CLASS(RangeSearchResult)
FAISS_DECLARE_GETTER(RangeSearchResult, size_t, nq)
int faiss_RangeSearchResult_new(FaissRangeSearchResult** p_rsr, idx_t nq);
int faiss_RangeSearchResult_new_with(
FaissRangeSearchResult** p_rsr,
idx_t nq,
int alloc_lims);
/// called when lims contains the nb of elements result entries
/// for each query
int faiss_RangeSearchResult_do_allocation(FaissRangeSearchResult* rsr);
FAISS_DECLARE_DESTRUCTOR(RangeSearchResult)
/// getter for buffer_size
FAISS_DECLARE_GETTER(RangeSearchResult, size_t, buffer_size)
/// getter for lims: size (nq + 1)
void faiss_RangeSearchResult_lims(FaissRangeSearchResult* rsr, size_t** lims);
/// getter for labels and respective distances (not sorted):
/// result for query i is labels[lims[i]:lims[i+1]]
void faiss_RangeSearchResult_labels(
FaissRangeSearchResult* rsr,
idx_t** labels,
float** distances);
/** Encapsulates a set of ids to remove. */
FAISS_DECLARE_CLASS(IDSelector)
FAISS_DECLARE_DESTRUCTOR(IDSelector)
int faiss_IDSelector_is_member(const FaissIDSelector* sel, idx_t id);
/** remove ids between [imni, imax) */
FAISS_DECLARE_CLASS(IDSelectorRange)
FAISS_DECLARE_DESTRUCTOR(IDSelectorRange)
FAISS_DECLARE_GETTER(IDSelectorRange, idx_t, imin)
FAISS_DECLARE_GETTER(IDSelectorRange, idx_t, imax)
int faiss_IDSelectorRange_new(
FaissIDSelectorRange** p_sel,
idx_t imin,
idx_t imax);
/** Remove ids from a set. Repetitions of ids in the indices set
* passed to the constructor does not hurt performance. The hash
* function used for the bloom filter and GCC's implementation of
* unordered_set are just the least significant bits of the id. This
* works fine for random ids or ids in sequences but will produce many
* hash collisions if lsb's are always the same */
FAISS_DECLARE_CLASS(IDSelectorBatch)
FAISS_DECLARE_GETTER(IDSelectorBatch, int, nbits)
FAISS_DECLARE_GETTER(IDSelectorBatch, idx_t, mask)
int faiss_IDSelectorBatch_new(
FaissIDSelectorBatch** p_sel,
size_t n,
const idx_t* indices);
// Below are structures used only by Index implementations
/** List of temporary buffers used to store results before they are
* copied to the RangeSearchResult object. */
FAISS_DECLARE_CLASS(BufferList)
FAISS_DECLARE_DESTRUCTOR(BufferList)
FAISS_DECLARE_GETTER(BufferList, size_t, buffer_size)
FAISS_DECLARE_GETTER(BufferList, size_t, wp)
typedef struct FaissBuffer {
idx_t* ids;
float* dis;
} FaissBuffer;
int faiss_BufferList_append_buffer(FaissBufferList* bl);
int faiss_BufferList_new(FaissBufferList** p_bl, size_t buffer_size);
int faiss_BufferList_add(FaissBufferList* bl, idx_t id, float dis);
/// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
/// tables dest_ids, dest_dis
int faiss_BufferList_copy_range(
FaissBufferList* bl,
size_t ofs,
size_t n,
idx_t* dest_ids,
float* dest_dis);
/// the entries in the buffers are split per query
FAISS_DECLARE_CLASS(RangeSearchPartialResult)
/// result structure for a single query
FAISS_DECLARE_CLASS(RangeQueryResult)
FAISS_DECLARE_GETTER(RangeQueryResult, idx_t, qno)
FAISS_DECLARE_GETTER(RangeQueryResult, size_t, nres)
FAISS_DECLARE_GETTER(RangeQueryResult, FaissRangeSearchPartialResult*, pres)
int faiss_RangeQueryResult_add(FaissRangeQueryResult* qr, float dis, idx_t id);
FAISS_DECLARE_GETTER(RangeSearchPartialResult, FaissRangeSearchResult*, res)
int faiss_RangeSearchPartialResult_new(
FaissRangeSearchPartialResult** p_res,
FaissRangeSearchResult* res_in);
int faiss_RangeSearchPartialResult_finalize(FaissRangeSearchPartialResult* res);
/// called by range_search before do_allocation
int faiss_RangeSearchPartialResult_set_lims(FaissRangeSearchPartialResult* res);
int faiss_RangeSearchPartialResult_new_result(
FaissRangeSearchPartialResult* res,
idx_t qno,
FaissRangeQueryResult** qr);
FAISS_DECLARE_CLASS(DistanceComputer)
/// called before computing distances
int faiss_DistanceComputer_set_query(FaissDistanceComputer* dc, const float* x);
/**
* Compute distance of vector i to current query.
* This function corresponds to the function call operator:
* DistanceComputer::operator()
*/
int faiss_DistanceComputer_vector_to_query_dis(
FaissDistanceComputer* dc,
idx_t i,
float* qd);
/// compute distance between two stored vectors
int faiss_DistanceComputer_symmetric_dis(
FaissDistanceComputer* dc,
idx_t i,
idx_t j,
float* vd);
FAISS_DECLARE_DESTRUCTOR(DistanceComputer)
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-
#include "index_factory_c.h"
#include <faiss/index_factory.h>
#include <cstring>
#include "macros_impl.h"
using faiss::Index;
/** Build and index with the sequence of processing steps described in
* the string.
*/
int faiss_index_factory(
FaissIndex** p_index,
int d,
const char* description,
FaissMetricType metric) {
try {
*p_index = reinterpret_cast<FaissIndex*>(faiss::index_factory(
d, description, static_cast<faiss::MetricType>(metric)));
}
CATCH_AND_HANDLE
}
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c -*-
#ifndef FAISS_INDEX_FACTORY_C_H
#define FAISS_INDEX_FACTORY_C_H
#include "Index_c.h"
#include "faiss_c.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Build and index with the sequence of processing steps described in
* the string.
*/
int faiss_index_factory(
FaissIndex** p_index,
int d,
const char* description,
FaissMetricType metric);
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved
// -*- c++ -*-
// I/O code for indexes
#include "index_io_c.h"
#include <faiss/index_io.h>
#include "macros_impl.h"
using faiss::Index;
int faiss_write_index(const FaissIndex* idx, FILE* f) {
try {
faiss::write_index(reinterpret_cast<const Index*>(idx), f);
}
CATCH_AND_HANDLE
}
int faiss_write_index_fname(const FaissIndex* idx, const char* fname) {
try {
faiss::write_index(reinterpret_cast<const Index*>(idx), fname);
}
CATCH_AND_HANDLE
}
int faiss_read_index(FILE* f, int io_flags, FaissIndex** p_out) {
try {
auto out = faiss::read_index(f, io_flags);
*p_out = reinterpret_cast<FaissIndex*>(out);
}
CATCH_AND_HANDLE
}
int faiss_read_index_fname(
const char* fname,
int io_flags,
FaissIndex** p_out) {
try {
auto out = faiss::read_index(fname, io_flags);
*p_out = reinterpret_cast<FaissIndex*>(out);
}
CATCH_AND_HANDLE
}
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved
// -*- c++ -*-
// I/O code for indexes
#ifndef FAISS_INDEX_IO_C_H
#define FAISS_INDEX_IO_C_H
#include <stdio.h>
#include "Index_c.h"
#include "faiss_c.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Write index to a file.
* This is equivalent to `faiss::write_index` when a file descriptor is
* provided.
*/
int faiss_write_index(const FaissIndex* idx, FILE* f);
/** Write index to a file.
* This is equivalent to `faiss::write_index` when a file path is provided.
*/
int faiss_write_index_fname(const FaissIndex* idx, const char* fname);
#define FAISS_IO_FLAG_MMAP 1
#define FAISS_IO_FLAG_READ_ONLY 2
/** Read index from a file.
* This is equivalent to `faiss:read_index` when a file descriptor is given.
*/
int faiss_read_index(FILE* f, int io_flags, FaissIndex** p_out);
/** Read index from a file.
* This is equivalent to `faiss:read_index` when a file path is given.
*/
int faiss_read_index_fname(const char* fname, int io_flags, FaissIndex** p_out);
#ifdef __cplusplus
}
#endif
#endif
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-
/// Utility macros for the C wrapper implementation.
#ifndef MACROS_IMPL_H
#define MACROS_IMPL_H
#include <faiss/impl/FaissException.h>
#include <iostream>
#include <stdexcept>
#include "error_impl.h"
#include "faiss_c.h"
#ifdef NDEBUG
#define CATCH_AND_HANDLE \
catch (faiss::FaissException & e) { \
faiss_last_exception = std::make_exception_ptr(e); \
return -2; \
} \
catch (std::exception & e) { \
faiss_last_exception = std::make_exception_ptr(e); \
return -4; \
} \
catch (...) { \
faiss_last_exception = \
std::make_exception_ptr(std::runtime_error("Unknown error")); \
return -1; \
} \
return 0;
#else
#define CATCH_AND_HANDLE \
catch (faiss::FaissException & e) { \
std::cerr << e.what() << '\n'; \
faiss_last_exception = std::make_exception_ptr(e); \
return -2; \
} \
catch (std::exception & e) { \
std::cerr << e.what() << '\n'; \
faiss_last_exception = std::make_exception_ptr(e); \
return -4; \
} \
catch (...) { \
std::cerr << "Unrecognized exception!\n"; \
faiss_last_exception = \
std::make_exception_ptr(std::runtime_error("Unknown error")); \
return -1; \
} \
return 0;
#endif
#define DEFINE_GETTER(clazz, ty, name) \
ty faiss_##clazz##_##name(const Faiss##clazz* obj) { \
return static_cast<ty>( \
reinterpret_cast<const faiss::clazz*>(obj)->name); \
}
#define DEFINE_GETTER_SUBCLASS(clazz, parent, ty, name) \
ty faiss_##clazz##_##name(const Faiss##clazz* obj) { \
return static_cast<ty>( \
reinterpret_cast<const faiss::parent::clazz*>(obj)->name); \
}
#define DEFINE_GETTER_PERMISSIVE(clazz, ty, name) \
ty faiss_##clazz##_##name(const Faiss##clazz* obj) { \
return (ty)(reinterpret_cast<const faiss::clazz*>(obj)->name); \
}
#define DEFINE_GETTER_SUBCLASS_PERMISSIVE(clazz, parent, ty, name) \
ty faiss_##clazz##_##name(const Faiss##clazz* obj) { \
return (ty)(reinterpret_cast<const faiss::parent::clazz*>(obj)->name); \
}
#define DEFINE_SETTER(clazz, ty, name) \
void faiss_##clazz##_set_##name(Faiss##clazz* obj, ty val) { \
reinterpret_cast<faiss::clazz*>(obj)->name = val; \
}
#define DEFINE_SETTER_STATIC(clazz, ty_to, ty_from, name) \
void faiss_##clazz##_set_##name(Faiss##clazz* obj, ty_from val) { \
reinterpret_cast<faiss::clazz*>(obj)->name = static_cast<ty_to>(val); \
}
#define DEFINE_DESTRUCTOR(clazz) \
void faiss_##clazz##_free(Faiss##clazz* obj) { \
delete reinterpret_cast<faiss::clazz*>(obj); \
}
#define DEFINE_INDEX_DOWNCAST(clazz) \
Faiss##clazz* faiss_##clazz##_cast(FaissIndex* index) { \
return reinterpret_cast<Faiss##clazz*>(dynamic_cast<faiss::clazz*>( \
reinterpret_cast<faiss::Index*>(index))); \
}
#endif
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-
#include "distances_c.h"
#include <faiss/utils/distances.h>
#include <cstdio>
void faiss_pairwise_L2sqr(
int64_t d,
int64_t nq,
const float* xq,
int64_t nb,
const float* xb,
float* dis,
int64_t ldq,
int64_t ldb,
int64_t ldd) {
faiss::pairwise_L2sqr(d, nq, xq, nb, xb, dis, ldq, ldb, ldd);
}
void faiss_pairwise_L2sqr_with_defaults(
int64_t d,
int64_t nq,
const float* xq,
int64_t nb,
const float* xb,
float* dis) {
faiss::pairwise_L2sqr(d, nq, xq, nb, xb, dis);
}
void faiss_fvec_inner_products_ny(
float* ip,
const float* x,
const float* y,
size_t d,
size_t ny) {
faiss::fvec_inner_products_ny(ip, x, y, d, ny);
}
void faiss_fvec_L2sqr_ny(
float* dis,
const float* x,
const float* y,
size_t d,
size_t ny) {
faiss::fvec_L2sqr_ny(dis, x, y, d, ny);
}
float faiss_fvec_norm_L2sqr(const float* x, size_t d) {
return faiss::fvec_norm_L2sqr(x, d);
}
void faiss_fvec_norms_L2(float* norms, const float* x, size_t d, size_t nx) {
faiss::fvec_norms_L2(norms, x, d, nx);
}
void faiss_fvec_norms_L2sqr(float* norms, const float* x, size_t d, size_t nx) {
faiss::fvec_norms_L2sqr(norms, x, d, nx);
}
void faiss_fvec_renorm_L2(size_t d, size_t nx, float* x) {
faiss::fvec_renorm_L2(d, nx, x);
}
void faiss_set_distance_compute_blas_threshold(int value) {
faiss::distance_compute_blas_threshold = value;
}
int faiss_get_distance_compute_blas_threshold() {
return faiss::distance_compute_blas_threshold;
}
void faiss_set_distance_compute_blas_query_bs(int value) {
faiss::distance_compute_blas_query_bs = value;
}
int faiss_get_distance_compute_blas_query_bs() {
return faiss::distance_compute_blas_query_bs;
}
void faiss_set_distance_compute_blas_database_bs(int value) {
faiss::distance_compute_blas_database_bs = value;
}
int faiss_get_distance_compute_blas_database_bs() {
return faiss::distance_compute_blas_database_bs;
}
void faiss_set_distance_compute_min_k_reservoir(int value) {
faiss::distance_compute_min_k_reservoir = value;
}
int faiss_get_distance_compute_min_k_reservoir() {
return faiss::distance_compute_min_k_reservoir;
}
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c -*-
#ifndef FAISS_DISTANCES_C_H
#define FAISS_DISTANCES_C_H
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/*********************************************************
* Optimized distance/norm/inner prod computations
*********************************************************/
/// Compute pairwise distances between sets of vectors
void faiss_pairwise_L2sqr(
int64_t d,
int64_t nq,
const float* xq,
int64_t nb,
const float* xb,
float* dis,
int64_t ldq,
int64_t ldb,
int64_t ldd);
/// Compute pairwise distances between sets of vectors
/// arguments from "faiss_pairwise_L2sqr"
/// ldq equal -1 by default
/// ldb equal -1 by default
/// ldd equal -1 by default
void faiss_pairwise_L2sqr_with_defaults(
int64_t d,
int64_t nq,
const float* xq,
int64_t nb,
const float* xb,
float* dis);
/// compute the inner product between nx vectors x and one y
void faiss_fvec_inner_products_ny(
float* ip, /* output inner product */
const float* x,
const float* y,
size_t d,
size_t ny);
/// compute ny square L2 distance between x and a set of contiguous y vectors
void faiss_fvec_L2sqr_ny(
float* dis,
const float* x,
const float* y,
size_t d,
size_t ny);
/// squared norm of a vector
float faiss_fvec_norm_L2sqr(const float* x, size_t d);
/// compute the L2 norms for a set of vectors
void faiss_fvec_norms_L2(float* norms, const float* x, size_t d, size_t nx);
/// same as fvec_norms_L2, but computes squared norms
void faiss_fvec_norms_L2sqr(float* norms, const float* x, size_t d, size_t nx);
/// L2-renormalize a set of vector. Nothing done if the vector is 0-normed
void faiss_fvec_renorm_L2(size_t d, size_t nx, float* x);
/// Setter of threshold value on nx above which we switch to BLAS to compute
/// distances
void faiss_set_distance_compute_blas_threshold(int value);
/// Getter of threshold value on nx above which we switch to BLAS to compute
/// distances
int faiss_get_distance_compute_blas_threshold();
/// Setter of block sizes value for BLAS distance computations
void faiss_set_distance_compute_blas_query_bs(int value);
/// Getter of block sizes value for BLAS distance computations
int faiss_get_distance_compute_blas_query_bs();
/// Setter of block sizes value for BLAS distance computations
void faiss_set_distance_compute_blas_database_bs(int value);
/// Getter of block sizes value for BLAS distance computations
int faiss_get_distance_compute_blas_database_bs();
/// Setter of number of results we switch to a reservoir to collect results
/// rather than a heap
void faiss_set_distance_compute_min_k_reservoir(int value);
/// Getter of number of results we switch to a reservoir to collect results
/// rather than a heap
int faiss_get_distance_compute_min_k_reservoir();
#ifdef __cplusplus
}
#endif
#endif
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# Adapted from CMake's FindBLAS module.
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindMKL
--------
Find Intel MKL library.
Input Variables
^^^^^^^^^^^^^^^
The following variables may be set to influence this module's behavior:
``BLA_STATIC``
if ``ON`` use static linkage
``BLA_VENDOR``
If set, checks only the specified vendor, if not set checks all the
possibilities. List of vendors valid in this module:
* ``Intel10_32`` (intel mkl v10 32 bit)
* ``Intel10_64lp`` (intel mkl v10+ 64 bit, threaded code, lp64 model)
* ``Intel10_64lp_seq`` (intel mkl v10+ 64 bit, sequential code, lp64 model)
* ``Intel10_64ilp`` (intel mkl v10+ 64 bit, threaded code, ilp64 model)
* ``Intel10_64ilp_seq`` (intel mkl v10+ 64 bit, sequential code, ilp64 model)
* ``Intel10_64_dyn`` (intel mkl v10+ 64 bit, single dynamic library)
* ``Intel`` (obsolete versions of mkl 32 and 64 bit)
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
``MKL_FOUND``
library implementing the BLAS interface is found
``MKL_LIBRARIES``
uncached list of libraries (using full path name) to link against
to use MKL (may be empty if compiler implicitly links MKL)
.. note::
C or CXX must be enabled to use Intel Math Kernel Library (MKL).
For example, to use Intel MKL libraries and/or Intel compiler:
.. code-block:: cmake
set(BLA_VENDOR Intel10_64lp)
find_package(MKL)
Hints
^^^^^
Set the ``MKLROOT`` environment variable to a directory that contains an MKL
installation, or add the directory to the dynamic library loader environment
variable for your platform (``LIB``, ``DYLD_LIBRARY_PATH`` or
``LD_LIBRARY_PATH``).
#]=======================================================================]
include(CheckFunctionExists)
include(CMakePushCheckState)
include(FindPackageHandleStandardArgs)
cmake_push_check_state()
set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(BLA_STATIC)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
else()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# for ubuntu's libblas3gf and liblapack3gf packages
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
endif()
endif()
macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _threadlibs _addlibdir _subdirs)
# This macro checks for the existence of the combination of fortran libraries
# given by _list. If the combination is found, this macro checks (using the
# Check_Fortran_Function_Exists macro) whether can link against that library
# combination using the name of a routine given by _name using the linker
# flags given by _flags. If the combination of libraries is found and passes
# the link test, LIBRARIES is set to the list of complete library paths that
# have been found. Otherwise, LIBRARIES is set to FALSE.
# N.B. _prefix is the prefix applied to the names of all cached variables that
# are generated internally and marked advanced by this macro.
# _addlibdir is a list of additional search paths. _subdirs is a list of path
# suffixes to be used by find_library().
set(_libraries_work TRUE)
set(${LIBRARIES})
set(_combined_name)
set(_extaddlibdir "${_addlibdir}")
if(WIN32)
list(APPEND _extaddlibdir ENV LIB)
elseif(APPLE)
list(APPEND _extaddlibdir ENV DYLD_LIBRARY_PATH)
else()
list(APPEND _extaddlibdir ENV LD_LIBRARY_PATH)
endif()
list(APPEND _extaddlibdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
foreach(_library ${_list})
if(_library MATCHES "^-Wl,--(start|end)-group$")
# Respect linker flags like --start/end-group (required by MKL)
set(${LIBRARIES} ${${LIBRARIES}} "${_library}")
else()
set(_combined_name ${_combined_name}_${_library})
if(NOT "${_threadlibs}" STREQUAL "")
set(_combined_name ${_combined_name}_threadlibs)
endif()
if(_libraries_work)
find_library(${_prefix}_${_library}_LIBRARY
NAMES ${_library}
PATHS ${_extaddlibdir}
PATH_SUFFIXES ${_subdirs}
)
#message("DEBUG: find_library(${_library}) got ${${_prefix}_${_library}_LIBRARY}")
mark_as_advanced(${_prefix}_${_library}_LIBRARY)
set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
endif()
endif()
endforeach()
if(_libraries_work)
# Test this combination of libraries.
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threadlibs})
#message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
if(CMAKE_Fortran_COMPILER_LOADED)
check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
else()
check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
endif()
set(CMAKE_REQUIRED_LIBRARIES)
set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
endif()
if(_libraries_work)
if("${_list}" STREQUAL "")
set(${LIBRARIES} "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
else()
set(${LIBRARIES} ${${LIBRARIES}} ${_threadlibs})
endif()
else()
set(${LIBRARIES} FALSE)
endif()
#message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
endmacro()
set(MKL_LIBRARIES)
if(NOT $ENV{BLA_VENDOR} STREQUAL "")
set(BLA_VENDOR $ENV{BLA_VENDOR})
else()
if(NOT BLA_VENDOR)
set(BLA_VENDOR "All")
endif()
endif()
if(BLA_VENDOR_THREADING)
set(BLAS_mkl_THREADING ${BLA_VENDOR_THREADING})
else()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(BLAS_mkl_THREADING "gnu")
else()
set(BLAS_mkl_THREADING "intel")
endif()
endif()
if(CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
# System-specific settings
if(WIN32)
if(BLA_STATIC)
set(BLAS_mkl_DLL_SUFFIX "")
else()
set(BLAS_mkl_DLL_SUFFIX "_dll")
endif()
else()
if(BLA_STATIC)
set(BLAS_mkl_START_GROUP "-Wl,--start-group")
set(BLAS_mkl_END_GROUP "-Wl,--end-group")
else()
set(BLAS_mkl_START_GROUP "")
set(BLAS_mkl_END_GROUP "")
endif()
if(BLAS_mkl_THREADING STREQUAL "gnu")
set(BLAS_mkl_OMP "gomp")
else()
set(BLAS_mkl_OMP "iomp5")
endif()
set(BLAS_mkl_LM "-lm")
set(BLAS_mkl_LDL "-ldl")
endif()
if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
find_package(Threads)
else()
find_package(Threads REQUIRED)
endif()
set(BLAS_mkl_INTFACE "intel")
if(BLA_VENDOR MATCHES "_64ilp")
set(BLAS_mkl_ILP_MODE "ilp64")
else()
set(BLAS_mkl_ILP_MODE "lp64")
endif()
set(BLAS_SEARCH_LIBS "")
set(BLAS_mkl_SEARCH_SYMBOL sgemm)
set(_LIBRARIES MKL_LIBRARIES)
if(WIN32)
# Find the main file (32-bit or 64-bit)
set(BLAS_SEARCH_LIBS_WIN_MAIN "")
if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
"mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
endif()
if(BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
"mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
endif()
# Add threading/sequential libs
set(BLAS_SEARCH_LIBS_WIN_THREAD "")
if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
# old version
list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
"libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
# mkl >= 10.3
list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
"libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
endif()
if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
"mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
endif()
# Cartesian product of the above
foreach(MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
foreach(THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
list(APPEND BLAS_SEARCH_LIBS
"${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
endforeach()
endforeach()
else()
if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
# old version
list(APPEND BLAS_SEARCH_LIBS
"mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
# mkl >= 10.3
list(APPEND BLAS_SEARCH_LIBS
"${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
endif()
if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
# old version
list(APPEND BLAS_SEARCH_LIBS
"mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
# mkl >= 10.3
list(APPEND BLAS_SEARCH_LIBS
"${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
endif()
if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
list(APPEND BLAS_SEARCH_LIBS
"${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core ${BLAS_mkl_END_GROUP}")
endif()
#older vesions of intel mkl libs
if(BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
list(APPEND BLAS_SEARCH_LIBS
"mkl")
list(APPEND BLAS_SEARCH_LIBS
"mkl_ia32")
list(APPEND BLAS_SEARCH_LIBS
"mkl_em64t")
endif()
endif()
if(BLA_VENDOR MATCHES "^Intel10_64_dyn$" OR BLA_VENDOR STREQUAL "All")
# mkl >= 10.3 with single dynamic library
list(APPEND BLAS_SEARCH_LIBS
"mkl_rt")
endif()
# MKL uses a multitude of partially platform-specific subdirectories:
if(BLA_VENDOR STREQUAL "Intel10_32")
set(BLAS_mkl_ARCH_NAME "ia32")
else()
set(BLAS_mkl_ARCH_NAME "intel64")
endif()
if(WIN32)
set(BLAS_mkl_OS_NAME "win")
elseif(APPLE)
set(BLAS_mkl_OS_NAME "mac")
else()
set(BLAS_mkl_OS_NAME "lin")
endif()
if(DEFINED ENV{MKLROOT})
file(TO_CMAKE_PATH "$ENV{MKLROOT}" BLAS_mkl_MKLROOT)
# If MKLROOT points to the subdirectory 'mkl', use the parent directory instead
# so we can better detect other relevant libraries in 'compiler' or 'tbb':
get_filename_component(BLAS_mkl_MKLROOT_LAST_DIR "${BLAS_mkl_MKLROOT}" NAME)
if(BLAS_mkl_MKLROOT_LAST_DIR STREQUAL "mkl")
get_filename_component(BLAS_mkl_MKLROOT "${BLAS_mkl_MKLROOT}" DIRECTORY)
endif()
endif()
set(BLAS_mkl_LIB_PATH_SUFFIXES
"compiler/lib" "compiler/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
"mkl/lib" "mkl/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
"lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}")
foreach(IT ${BLAS_SEARCH_LIBS})
string(REPLACE " " ";" SEARCH_LIBS ${IT})
if(NOT ${_LIBRARIES})
check_blas_libraries(
${_LIBRARIES}
BLAS
${BLAS_mkl_SEARCH_SYMBOL}
""
"${SEARCH_LIBS}"
"${CMAKE_THREAD_LIBS_INIT};${BLAS_mkl_LM};${BLAS_mkl_LDL}"
"${BLAS_mkl_MKLROOT}"
"${BLAS_mkl_LIB_PATH_SUFFIXES}"
)
endif()
endforeach()
unset(BLAS_mkl_ILP_MODE)
unset(BLAS_mkl_INTFACE)
unset(BLAS_mkl_THREADING)
unset(BLAS_mkl_OMP)
unset(BLAS_mkl_DLL_SUFFIX)
unset(BLAS_mkl_LM)
unset(BLAS_mkl_LDL)
unset(BLAS_mkl_MKLROOT)
unset(BLAS_mkl_MKLROOT_LAST_DIR)
unset(BLAS_mkl_ARCH_NAME)
unset(BLAS_mkl_OS_NAME)
unset(BLAS_mkl_LIB_PATH_SUFFIXES)
endif()
find_package_handle_standard_args(MKL REQUIRED_VARS MKL_LIBRARIES)
cmake_pop_check_state()
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
include("${CMAKE_CURRENT_LIST_DIR}/faiss-targets.cmake")
cd build;
export CPLUS_INCLUDE_PATH=/opt/dtk-21.04/include:/opt/dtk-21.04:/opencl/include
export LD_LIBRARY_PATH=/home/huchen/intel-compiler-2017.5.239/mkl/lib/intel64_lin/:$LD_LIBRARY_PATH
export PATH=/home/huchen/FAISS/swig-4.0.2-build/bin/:$PATH
export CPLUS_INCLUDE_PATH=/opt/dtk-21.04/hiprand/include/:/opt/dtk-21.04/rocrand/include:$CPLUS_INCLUDE_PATH
CXX=hipcc CC=hipcc cmake3 -DFAISS_ENABLE_GPU=ON -DFAISS_OPT_LEVEL=sse4 -DBUILD_SHARED_LIBS=ON -DCMAKE_MODULE_PATH=${ROCM_PATH}/hip/cmake/ -DMKL_LIBRARIES=/home/huchen/intel-compiler-2017.5.239/mkl/lib/intel64_lin/ ..
make -j faiss VERBOSE=1 > hc_faiss.log 2>&1
cd -
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
FROM nvidia/cuda:10.2-devel-ubuntu18.04
RUN apt-get update && apt-get install -y wget git
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
bash Miniconda3-latest-Linux-x86_64.sh -b -p ~/miniconda3
ENV PATH="/root/miniconda3/condabin:${PATH}"
RUN conda install conda-build
COPY ./ faiss
WORKDIR /faiss/conda
RUN conda build faiss --no-anaconda-upload -c pytorch
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
FROM nvidia/cuda:10.2-devel-centos8
RUN yum install -y wget git libcublas-devel-10-2
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
bash Miniconda3-latest-Linux-x86_64.sh -b -p ~/miniconda3
ENV PATH="/root/miniconda3/condabin:${PATH}"
RUN conda install -y -q conda-build anaconda-client
RUN conda config --set anaconda_upload yes
COPY ./ faiss
WORKDIR /faiss/conda
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
FROM nvidia/cuda:11.3.1-devel-centos8
RUN yum install -y wget git libcublas-devel-11-3
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
bash Miniconda3-latest-Linux-x86_64.sh -b -p ~/miniconda3
ENV PATH="/root/miniconda3/condabin:${PATH}"
RUN conda install -y -q conda-build anaconda-client
RUN conda config --set anaconda_upload yes
COPY ./ faiss
WORKDIR /faiss/conda
CONDA_BUILD_SYSROOT:
- /opt/MacOSX10.9.sdk # [osx]
python:
- 3.6
- 3.7
- 3.8
#!/bin/sh
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -e
# Build libfaiss.so/libfaiss_avx2.so.
cmake -B _build \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_TESTING=OFF \
-DFAISS_OPT_LEVEL=avx2 \
-DFAISS_ENABLE_GPU=ON \
-DCMAKE_CUDA_ARCHITECTURES="${CUDA_ARCHS}" \
-DFAISS_ENABLE_PYTHON=OFF \
-DBLA_VENDOR=Intel10_64lp \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_BUILD_TYPE=Release .
make -C _build -j $CPU_COUNT faiss faiss_avx2
cmake --install _build --prefix $PREFIX
cmake --install _build --prefix _libfaiss_stage/
#!/bin/sh
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -e
# Build swigfaiss.so/swigfaiss_avx2.so.
cmake -B _build_python_${PY_VER} \
-Dfaiss_ROOT=_libfaiss_stage/ \
-DFAISS_OPT_LEVEL=avx2 \
-DFAISS_ENABLE_GPU=ON \
-DCMAKE_BUILD_TYPE=Release \
-DPython_EXECUTABLE=$PYTHON \
faiss/python
make -C _build_python_${PY_VER} -j $CPU_COUNT swigfaiss swigfaiss_avx2
# Build actual python module.
cd _build_python_${PY_VER}/
$PYTHON setup.py install --single-version-externally-managed --record=record.txt --prefix=$PREFIX
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment