/** * 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 "GpuAutoTune_c.h" #include #include #include #include #include #include #include "GpuClonerOptions_c.h" #include "macros_impl.h" using faiss::Index; using faiss::gpu::GpuClonerOptions; using faiss::gpu::GpuMultipleClonerOptions; using faiss::gpu::GpuResourcesProvider; int faiss_index_gpu_to_cpu(const FaissIndex* gpu_index, FaissIndex** p_out) { try { auto cpu_index = faiss::gpu::index_gpu_to_cpu( reinterpret_cast(gpu_index)); *p_out = reinterpret_cast(cpu_index); } CATCH_AND_HANDLE } /// converts any CPU index that can be converted to GPU int faiss_index_cpu_to_gpu( FaissGpuResourcesProvider* provider, int device, const FaissIndex* index, FaissGpuIndex** p_out) { try { auto res = reinterpret_cast(provider); auto gpu_index = faiss::gpu::index_cpu_to_gpu( res, device, reinterpret_cast(index)); *p_out = reinterpret_cast(gpu_index); } CATCH_AND_HANDLE } int faiss_index_cpu_to_gpu_with_options( FaissGpuResourcesProvider* provider, int device, const FaissIndex* index, const FaissGpuClonerOptions* options, FaissGpuIndex** p_out) { try { auto res = reinterpret_cast(provider); auto gpu_index = faiss::gpu::index_cpu_to_gpu( res, device, reinterpret_cast(index), reinterpret_cast(options)); *p_out = reinterpret_cast(gpu_index); } CATCH_AND_HANDLE } int faiss_index_cpu_to_gpu_multiple( FaissGpuResourcesProvider* const* providers_vec, const int* devices, size_t devices_size, const FaissIndex* index, FaissGpuIndex** p_out) { try { std::vector res(devices_size); for (auto i = 0u; i < devices_size; ++i) { res[i] = reinterpret_cast(providers_vec[i]); } std::vector dev(devices, devices + devices_size); auto gpu_index = faiss::gpu::index_cpu_to_gpu_multiple( res, dev, reinterpret_cast(index)); *p_out = reinterpret_cast(gpu_index); } CATCH_AND_HANDLE } int faiss_index_cpu_to_gpu_multiple_with_options( FaissGpuResourcesProvider** providers_vec, size_t providers_vec_size, int* devices, size_t devices_size, const FaissIndex* index, const FaissGpuMultipleClonerOptions* options, FaissGpuIndex** p_out) { try { std::vector res(providers_vec_size); for (auto i = 0u; i < providers_vec_size; ++i) { res[i] = reinterpret_cast(providers_vec[i]); } std::vector dev(devices, devices + devices_size); auto gpu_index = faiss::gpu::index_cpu_to_gpu_multiple( res, dev, reinterpret_cast(index), reinterpret_cast(options)); *p_out = reinterpret_cast(gpu_index); } CATCH_AND_HANDLE }