12 #include "../../FaissAssert.h"
13 #include <cuda_runtime.h>
14 #include <cublas_v2.h>
17 namespace faiss {
namespace gpu {
20 int getCurrentDevice();
23 void setCurrentDevice(
int device);
30 void synchronizeAllDevices();
33 const cudaDeviceProp& getDeviceProperties(
int device);
36 const cudaDeviceProp& getCurrentDeviceProperties();
40 int getMaxThreads(
int device);
43 int getMaxThreadsCurrentDevice();
46 size_t getMaxSharedMemPerBlock(
int device);
49 size_t getMaxSharedMemPerBlockCurrentDevice();
53 int getDeviceForAddress(
const void* p);
57 bool getFullUnifiedMemSupport(
int device);
60 bool getFullUnifiedMemSupportCurrentDevice();
79 cublasHandle_t
get() {
return blasHandle_; }
82 cublasHandle_t blasHandle_;
94 inline cudaEvent_t
get() {
return event_; }
110 #define CUDA_VERIFY(X) \
113 FAISS_ASSERT_FMT(err__ == cudaSuccess, "CUDA error %d", (int) err__); \
119 #ifdef FAISS_GPU_SYNC_ERROR
120 #define CUDA_TEST_ERROR() \
122 CUDA_VERIFY(cudaDeviceSynchronize()); \
125 #define CUDA_TEST_ERROR() \
127 CUDA_VERIFY(cudaGetLastError()); \
132 template <
typename L1,
typename L2>
133 void streamWaitBase(
const L1& listWaiting,
const L2& listWaitOn) {
135 std::vector<cudaEvent_t> events;
136 for (
auto& stream : listWaitOn) {
138 CUDA_VERIFY(cudaEventCreateWithFlags(&event, cudaEventDisableTiming));
139 CUDA_VERIFY(cudaEventRecord(event, stream));
140 events.push_back(event);
144 for (
auto& stream : listWaiting) {
145 for (
auto& event : events) {
146 CUDA_VERIFY(cudaStreamWaitEvent(stream, event, 0));
150 for (
auto& event : events) {
151 CUDA_VERIFY(cudaEventDestroy(event));
157 template <
typename L1>
158 void streamWait(
const L1& a,
159 const std::initializer_list<cudaStream_t>& b) {
160 streamWaitBase(a, b);
163 template <
typename L2>
164 void streamWait(
const std::initializer_list<cudaStream_t>& a,
166 streamWaitBase(a, b);
169 inline void streamWait(
const std::initializer_list<cudaStream_t>& a,
170 const std::initializer_list<cudaStream_t>& b) {
171 streamWaitBase(a, b);
void cpuWaitOnEvent()
Have the CPU wait for the completion of this event.
void streamWaitOnEvent(cudaStream_t stream)
Wait on this event in this stream.
CudaEvent(cudaStream_t stream)
Creates an event and records it in this stream.
RAII object to manage a cublasHandle_t.