| 1 |
/* |
| 2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 |
* |
| 4 |
* This source code is licensed under the MIT license found in the |
| 5 |
* LICENSE file in the root directory of this source tree. |
| 6 |
*/ |
| 7 |
|
| 8 |
// -*- c++ -*- |
| 9 |
|
| 10 |
#include "GpuResources_c.h" |
| 11 |
#include <faiss/gpu/GpuResources.h> |
| 12 |
#include "macros_impl.h" |
| 13 |
|
| 14 |
using faiss::gpu::GpuResources; |
| 15 |
using faiss::gpu::GpuResourcesProvider; |
| 16 |
|
| 17 |
DEFINE_DESTRUCTOR(GpuResources) |
| 18 |
|
| 19 |
int faiss_GpuResources_initializeForDevice(FaissGpuResources* res, int device) { |
| 20 |
try { |
| 21 |
reinterpret_cast<GpuResources*>(res)->initializeForDevice(device); |
| 22 |
} |
| 23 |
CATCH_AND_HANDLE |
| 24 |
} |
| 25 |
|
| 26 |
int faiss_GpuResources_getBlasHandle( |
| 27 |
FaissGpuResources* res, |
| 28 |
int device, |
| 29 |
cublasHandle_t* out) { |
| 30 |
try { |
| 31 |
auto o = reinterpret_cast<GpuResources*>(res)->getBlasHandle(device); |
| 32 |
*out = o; |
| 33 |
} |
| 34 |
CATCH_AND_HANDLE |
| 35 |
} |
| 36 |
|
| 37 |
int faiss_GpuResources_getDefaultStream( |
| 38 |
FaissGpuResources* res, |
| 39 |
int device, |
| 40 |
cudaStream_t* out) { |
| 41 |
try { |
| 42 |
auto o = reinterpret_cast<GpuResources*>(res)->getDefaultStream(device); |
| 43 |
*out = o; |
| 44 |
} |
| 45 |
CATCH_AND_HANDLE |
| 46 |
} |
| 47 |
|
| 48 |
int faiss_GpuResources_getPinnedMemory( |
| 49 |
FaissGpuResources* res, |
| 50 |
void** p_buffer, |
| 51 |
size_t* p_size) { |
| 52 |
try { |
| 53 |
auto o = reinterpret_cast<GpuResources*>(res)->getPinnedMemory(); |
| 54 |
*p_buffer = o.first; |
| 55 |
*p_size = o.second; |
| 56 |
} |
| 57 |
CATCH_AND_HANDLE |
| 58 |
} |
| 59 |
|
| 60 |
int faiss_GpuResources_getAsyncCopyStream( |
| 61 |
FaissGpuResources* res, |
| 62 |
int device, |
| 63 |
cudaStream_t* out) { |
| 64 |
try { |
| 65 |
auto o = reinterpret_cast<GpuResources*>(res)->getAsyncCopyStream( |
| 66 |
device); |
| 67 |
*out = o; |
| 68 |
} |
| 69 |
CATCH_AND_HANDLE |
| 70 |
} |
| 71 |
|
| 72 |
int faiss_GpuResources_getBlasHandleCurrentDevice( |
| 73 |
FaissGpuResources* res, |
| 74 |
cublasHandle_t* out) { |
| 75 |
try { |
| 76 |
auto o = reinterpret_cast<GpuResources*>(res) |
| 77 |
->getBlasHandleCurrentDevice(); |
| 78 |
*out = o; |
| 79 |
} |
| 80 |
CATCH_AND_HANDLE |
| 81 |
} |
| 82 |
|
| 83 |
int faiss_GpuResources_getDefaultStreamCurrentDevice( |
| 84 |
FaissGpuResources* res, |
| 85 |
cudaStream_t* out) { |
| 86 |
try { |
| 87 |
auto o = reinterpret_cast<GpuResources*>(res) |
| 88 |
->getDefaultStreamCurrentDevice(); |
| 89 |
*out = o; |
| 90 |
} |
| 91 |
CATCH_AND_HANDLE |
| 92 |
} |
| 93 |
|
| 94 |
int faiss_GpuResources_syncDefaultStream(FaissGpuResources* res, int device) { |
| 95 |
try { |
| 96 |
reinterpret_cast<GpuResources*>(res)->syncDefaultStream(device); |
| 97 |
} |
| 98 |
CATCH_AND_HANDLE |
| 99 |
} |
| 100 |
|
| 101 |
int faiss_GpuResources_syncDefaultStreamCurrentDevice(FaissGpuResources* res) { |
| 102 |
try { |
| 103 |
reinterpret_cast<GpuResources*>(res)->syncDefaultStreamCurrentDevice(); |
| 104 |
} |
| 105 |
CATCH_AND_HANDLE |
| 106 |
} |
| 107 |
|
| 108 |
int faiss_GpuResources_getAsyncCopyStreamCurrentDevice( |
| 109 |
FaissGpuResources* res, |
| 110 |
cudaStream_t* out) { |
| 111 |
try { |
| 112 |
auto o = reinterpret_cast<GpuResources*>(res) |
| 113 |
->getAsyncCopyStreamCurrentDevice(); |
| 114 |
*out = o; |
| 115 |
} |
| 116 |
CATCH_AND_HANDLE |
| 117 |
} |
| 118 |
|
| 119 |
DEFINE_DESTRUCTOR(GpuResourcesProvider) |
| 120 |
|
| 121 |
int faiss_GpuResourcesProvider_getResources( |
| 122 |
FaissGpuResourcesProvider* res, |
| 123 |
FaissGpuResources** out) { |
| 124 |
try { |
| 125 |
auto o = reinterpret_cast<GpuResourcesProvider*>(res)->getResources(); |
| 126 |
*out = reinterpret_cast<FaissGpuResources*>(o.get()); |
| 127 |
} |
| 128 |
CATCH_AND_HANDLE |
| 129 |
} |