13 #include "../../FaissAssert.h"
14 #include <cuda_runtime.h>
15 #include <cublas_v2.h>
18 namespace faiss {
namespace gpu {
21 int getCurrentDevice();
24 void setCurrentDevice(
int device);
31 void synchronizeAllDevices();
34 const cudaDeviceProp& getDeviceProperties(
int device);
37 const cudaDeviceProp& getCurrentDeviceProperties();
41 int getMaxThreads(
int device);
44 int getMaxThreadsCurrentDevice();
47 size_t getMaxSharedMemPerBlock(
int device);
50 size_t getMaxSharedMemPerBlockCurrentDevice();
54 int getDeviceForAddress(
const void* p);
58 bool getFullUnifiedMemSupport(
int device);
61 bool getFullUnifiedMemSupportCurrentDevice();
80 cublasHandle_t
get() {
return blasHandle_; }
83 cublasHandle_t blasHandle_;
95 inline cudaEvent_t
get() {
return event_; }
111 #define CUDA_VERIFY(X) \
114 FAISS_ASSERT_FMT(err__ == cudaSuccess, "CUDA error %d", (int) err__); \
120 #ifdef FAISS_GPU_SYNC_ERROR
121 #define CUDA_TEST_ERROR() \
123 CUDA_VERIFY(cudaDeviceSynchronize()); \
126 #define CUDA_TEST_ERROR() \
128 CUDA_VERIFY(cudaGetLastError()); \
133 template <
typename L1,
typename L2>
134 void streamWaitBase(
const L1& listWaiting,
const L2& listWaitOn) {
136 std::vector<cudaEvent_t> events;
137 for (
auto& stream : listWaitOn) {
139 CUDA_VERIFY(cudaEventCreateWithFlags(&event, cudaEventDisableTiming));
140 CUDA_VERIFY(cudaEventRecord(event, stream));
141 events.push_back(event);
145 for (
auto& stream : listWaiting) {
146 for (
auto& event : events) {
147 CUDA_VERIFY(cudaStreamWaitEvent(stream, event, 0));
151 for (
auto& event : events) {
152 CUDA_VERIFY(cudaEventDestroy(event));
158 template <
typename L1>
159 void streamWait(
const L1& a,
160 const std::initializer_list<cudaStream_t>& b) {
161 streamWaitBase(a, b);
164 template <
typename L2>
165 void streamWait(
const std::initializer_list<cudaStream_t>& a,
167 streamWaitBase(a, b);
170 inline void streamWait(
const std::initializer_list<cudaStream_t>& a,
171 const std::initializer_list<cudaStream_t>& b) {
172 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.