summaryrefslogtreecommitdiff
path: root/include/caffe/util/device_alternate.hpp
diff options
context:
space:
mode:
authorEvan Shelhamer <shelhamer@imaginarynumber.net>2014-07-15 15:56:36 +0200
committerEvan Shelhamer <shelhamer@imaginarynumber.net>2014-07-17 11:57:47 +0200
commite52d91ea331dfd1430384808db272926561b116f (patch)
tree34704ca094edd1cee6b812e0a2a7c2fec9947995 /include/caffe/util/device_alternate.hpp
parentb882c3b4707eeb072a04490c6f36bd7c4deb03df (diff)
downloadcaffeonacl-e52d91ea331dfd1430384808db272926561b116f.tar.gz
caffeonacl-e52d91ea331dfd1430384808db272926561b116f.tar.bz2
caffeonacl-e52d91ea331dfd1430384808db272926561b116f.zip
collect CUDA includes and calls, separate from CPU-only mode, leave out
- collect CUDA includes in device_alternate.hpp - add guards for CUDA code - move GPU code into cu from cpp - make CUDA includes and libraries conditional in Makefile - drop CUDA dependency from travis-ci build
Diffstat (limited to 'include/caffe/util/device_alternate.hpp')
-rw-r--r--include/caffe/util/device_alternate.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/caffe/util/device_alternate.hpp b/include/caffe/util/device_alternate.hpp
new file mode 100644
index 00000000..abee4f57
--- /dev/null
+++ b/include/caffe/util/device_alternate.hpp
@@ -0,0 +1,44 @@
+// Copyright 2014 BVLC and contributors.
+
+#ifndef CAFFE_UTIL_DEVICE_ALTERNATE_H_
+#define CAFFE_UTIL_DEVICE_ALTERNATE_H_
+
+#ifdef CPU_ONLY // CPU-only Caffe.
+
+#include <vector>
+
+// Stub out GPU calls as unavailable.
+
+#define NO_GPU LOG(FATAL) << "CPU-only Mode"
+
+#define STUB_GPU(classname) \
+template <typename Dtype> \
+Dtype classname<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom, \
+ vector<Blob<Dtype>*>* top) { NO_GPU; } \
+template <typename Dtype> \
+void classname<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top, \
+ const vector<bool>& propagate_down, \
+ vector<Blob<Dtype>*>* bottom) { NO_GPU; } \
+
+#define STUB_GPU_FORWARD(classname, funcname) \
+template <typename Dtype> \
+Dtype classname<Dtype>::funcname##_##gpu(const vector<Blob<Dtype>*>& bottom, \
+ 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, \
+ vector<Blob<Dtype>*>* bottom) { NO_GPU; } \
+
+#else // Normal GPU + CPU Caffe.
+
+#include <cublas_v2.h>
+#include <cuda.h>
+#include <cuda_runtime.h>
+#include <curand.h>
+#include <driver_types.h> // cuda driver types
+
+#endif // CPU_ONLY
+
+#endif // CAFFE_UTIL_DEVICE_ALTERNATE_H_