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 cudaDeviceProp& getDeviceProperties(
int device);
38 int getMaxThreads(
int device);
41 int getMaxThreadsCurrentDevice();
44 size_t getMaxSharedMemPerBlock(
int device);
47 size_t getMaxSharedMemPerBlockCurrentDevice();
51 int getDeviceForAddress(
const void* p);
55 bool getFullUnifiedMemSupport(
int device);
58 bool getFullUnifiedMemSupportCurrentDevice();
77 cublasHandle_t
get() {
return blasHandle_; }
80 cublasHandle_t blasHandle_;
92 inline cudaEvent_t
get() {
return event_; }
108 #define CUDA_VERIFY(X) \
111 FAISS_ASSERT_FMT(err__ == cudaSuccess, "CUDA error %d", (int) err__); \
117 #ifdef FAISS_GPU_SYNC_ERROR
118 #define CUDA_TEST_ERROR() \
120 CUDA_VERIFY(cudaDeviceSynchronize()); \
123 #define CUDA_TEST_ERROR() \
125 CUDA_VERIFY(cudaGetLastError()); \
130 template <
typename L1,
typename L2>
131 void streamWaitBase(
const L1& listWaiting,
const L2& listWaitOn) {
133 std::vector<cudaEvent_t> events;
134 for (
auto& stream : listWaitOn) {
136 CUDA_VERIFY(cudaEventCreateWithFlags(&event, cudaEventDisableTiming));
137 CUDA_VERIFY(cudaEventRecord(event, stream));
138 events.push_back(event);
142 for (
auto& stream : listWaiting) {
143 for (
auto& event : events) {
144 CUDA_VERIFY(cudaStreamWaitEvent(stream, event, 0));
148 for (
auto& event : events) {
149 CUDA_VERIFY(cudaEventDestroy(event));
155 template <
typename L1>
156 void streamWait(
const L1& a,
157 const std::initializer_list<cudaStream_t>& b) {
158 streamWaitBase(a, b);
161 template <
typename L2>
162 void streamWait(
const std::initializer_list<cudaStream_t>& a,
164 streamWaitBase(a, b);
167 inline void streamWait(
const std::initializer_list<cudaStream_t>& a,
168 const std::initializer_list<cudaStream_t>& b) {
169 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.