| | #ifndef CAFFE_UTIL_DEVICE_ALTERNATE_H_ |
| | #define CAFFE_UTIL_DEVICE_ALTERNATE_H_ |
| |
|
| | #ifdef CPU_ONLY |
| |
|
| | #include <vector> |
| |
|
| | |
| |
|
| | #define NO_GPU LOG(FATAL) << "Cannot use GPU in CPU-only Caffe: check mode." |
| |
|
| | #define STUB_GPU(classname) \ |
| | template <typename Dtype> \ |
| | void classname<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom, \ |
| | const vector<Blob<Dtype>*>& top) { NO_GPU; } \ |
| | template <typename Dtype> \ |
| | void classname<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top, \ |
| | const vector<bool>& propagate_down, \ |
| | const vector<Blob<Dtype>*>& bottom) { NO_GPU; } \ |
| | |
| | #define STUB_GPU_FORWARD(classname, funcname) \ |
| | template <typename Dtype> \ |
| | void classname<Dtype>::funcname##_##gpu(const vector<Blob<Dtype>*>& bottom, \ |
| | const vector<Blob<Dtype>*>& top) { NO_GPU; } \ |
| | |
| | #define STUB_GPU_BACKWARD(classname, funcname) \ |
| | template <typename Dtype> \ |
| | void classname<Dtype>::funcname##_##gpu(const vector<Blob<Dtype>*>& top, \ |
| | const vector<bool>& propagate_down, \ |
| | const vector<Blob<Dtype>*>& bottom) { NO_GPU; } \ |
| | |
| | #else |
| |
|
| | #include <cublas_v2.h> |
| | #include <cuda.h> |
| | #include <cuda_runtime.h> |
| | #include <curand.h> |
| | #include <driver_types.h> |
| | #ifdef USE_CUDNN |
| | #include "caffe/util/cudnn.hpp" |
| | #endif |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | #define CUDA_CHECK(condition) \ |
| | \ |
| | do { \ |
| | cudaError_t error = condition; \ |
| | CHECK_EQ(error, cudaSuccess) << " " << cudaGetErrorString(error); \ |
| | } while (0) |
| |
|
| | #define CUBLAS_CHECK(condition) \ |
| | do { \ |
| | cublasStatus_t status = condition; \ |
| | CHECK_EQ(status, CUBLAS_STATUS_SUCCESS) << " " \ |
| | << caffe::cublasGetErrorString(status); \ |
| | } while (0) |
| |
|
| | #define CURAND_CHECK(condition) \ |
| | do { \ |
| | curandStatus_t status = condition; \ |
| | CHECK_EQ(status, CURAND_STATUS_SUCCESS) << " " \ |
| | << caffe::curandGetErrorString(status); \ |
| | } while (0) |
| |
|
| | |
| | #define CUDA_KERNEL_LOOP(i, n) \ |
| | for (int i = blockIdx.x * blockDim.x + threadIdx.x; \ |
| | i < (n); \ |
| | i += blockDim.x * gridDim.x) |
| |
|
| | |
| | #define CUDA_POST_KERNEL_CHECK CUDA_CHECK(cudaPeekAtLastError()) |
| |
|
| | namespace caffe { |
| |
|
| | |
| | const char* cublasGetErrorString(cublasStatus_t error); |
| | const char* curandGetErrorString(curandStatus_t error); |
| |
|
| | |
| | const int CAFFE_CUDA_NUM_THREADS = 512; |
| |
|
| | |
| | inline int CAFFE_GET_BLOCKS(const int N) { |
| | return (N + CAFFE_CUDA_NUM_THREADS - 1) / CAFFE_CUDA_NUM_THREADS; |
| | } |
| |
|
| | } |
| |
|
| | #endif |
| |
|
| | #endif |
| |
|