diff options
author | Evan Shelhamer <shelhamer@imaginarynumber.net> | 2014-06-29 20:47:40 -0700 |
---|---|---|
committer | Evan Shelhamer <shelhamer@imaginarynumber.net> | 2014-07-17 11:57:09 +0200 |
commit | 41e063f77647a489aaabb26d795e27c8850a816f (patch) | |
tree | a370bcc2a544a9ca56ada75143c2cb5eceed4d8e | |
parent | b6d881d1e7eeb75515e70254fc5168f7854f7c42 (diff) | |
download | caffeonacl-41e063f77647a489aaabb26d795e27c8850a816f.tar.gz caffeonacl-41e063f77647a489aaabb26d795e27c8850a816f.tar.bz2 caffeonacl-41e063f77647a489aaabb26d795e27c8850a816f.zip |
stub out GPU layer methods to crash loudly in CPU-only mode
28 files changed, 140 insertions, 0 deletions
diff --git a/include/caffe/layer.hpp b/include/caffe/layer.hpp index d4d10aaf..31689a4f 100644 --- a/include/caffe/layer.hpp +++ b/include/caffe/layer.hpp @@ -9,6 +9,7 @@ #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/proto/caffe.pb.h" +#include "caffe/util/cpu_only.hpp" using std::string; using std::vector; diff --git a/include/caffe/util/cpu_only.hpp b/include/caffe/util/cpu_only.hpp new file mode 100644 index 00000000..1ae6ec9d --- /dev/null +++ b/include/caffe/util/cpu_only.hpp @@ -0,0 +1,37 @@ +// Copyright 2014 BVLC and contributors. + +#ifndef CAFFE_UTIL_CPU_ONLY_H_ +#define CAFFE_UTIL_CPU_ONLY_H_ + +#include <vector> + +#include "caffe/blob.hpp" +#include "caffe/common.hpp" + +// For CPU-only Caffe, stub out GPU calls as unavailable. +#ifdef CPU_ONLY + +#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; } \ + +#endif // CPU_ONLY +#endif // CAFFE_UTIL_CPU_ONLY_H_ diff --git a/src/caffe/layers/bnll_layer.cpp b/src/caffe/layers/bnll_layer.cpp index 95e6bd87..0e30b8aa 100644 --- a/src/caffe/layers/bnll_layer.cpp +++ b/src/caffe/layers/bnll_layer.cpp @@ -43,6 +43,9 @@ void BNLLLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(BNLLLayer); +#endif INSTANTIATE_CLASS(BNLLLayer); diff --git a/src/caffe/layers/concat_layer.cpp b/src/caffe/layers/concat_layer.cpp index 4c894ddf..dd899a57 100644 --- a/src/caffe/layers/concat_layer.cpp +++ b/src/caffe/layers/concat_layer.cpp @@ -100,6 +100,10 @@ void ConcatLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } // concat_dim_ is guaranteed to be 0 or 1 by SetUp. } +#ifdef CPU_ONLY +STUB_GPU(ConcatLayer); +#endif + INSTANTIATE_CLASS(ConcatLayer); } // namespace caffe diff --git a/src/caffe/layers/conv_layer.cpp b/src/caffe/layers/conv_layer.cpp index d7099e55..e8f08c7e 100644 --- a/src/caffe/layers/conv_layer.cpp +++ b/src/caffe/layers/conv_layer.cpp @@ -187,6 +187,10 @@ void ConvolutionLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(ConvolutionLayer); +#endif + INSTANTIATE_CLASS(ConvolutionLayer); } // namespace caffe diff --git a/src/caffe/layers/data_layer.cpp b/src/caffe/layers/data_layer.cpp index 29c4fec8..e9ec15c5 100644 --- a/src/caffe/layers/data_layer.cpp +++ b/src/caffe/layers/data_layer.cpp @@ -362,6 +362,10 @@ Dtype DataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, return Dtype(0.); } +#ifdef CPU_ONLY +STUB_GPU_FORWARD(DataLayer, Forward); +#endif + INSTANTIATE_CLASS(DataLayer); } // namespace caffe diff --git a/src/caffe/layers/dropout_layer.cpp b/src/caffe/layers/dropout_layer.cpp index a3501bf5..a9372977 100644 --- a/src/caffe/layers/dropout_layer.cpp +++ b/src/caffe/layers/dropout_layer.cpp @@ -65,6 +65,10 @@ void DropoutLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } +#ifdef CPU_ONLY +STUB_GPU(DropoutLayer); +#endif + INSTANTIATE_CLASS(DropoutLayer); diff --git a/src/caffe/layers/eltwise_layer.cpp b/src/caffe/layers/eltwise_layer.cpp index 2c265f66..44bad932 100644 --- a/src/caffe/layers/eltwise_layer.cpp +++ b/src/caffe/layers/eltwise_layer.cpp @@ -94,6 +94,10 @@ void EltwiseLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(EltwiseLayer); +#endif + INSTANTIATE_CLASS(EltwiseLayer); diff --git a/src/caffe/layers/euclidean_loss_layer.cpp b/src/caffe/layers/euclidean_loss_layer.cpp index 2478a514..43e9989f 100644 --- a/src/caffe/layers/euclidean_loss_layer.cpp +++ b/src/caffe/layers/euclidean_loss_layer.cpp @@ -52,6 +52,10 @@ void EuclideanLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(EuclideanLossLayer); +#endif + INSTANTIATE_CLASS(EuclideanLossLayer); } // namespace caffe diff --git a/src/caffe/layers/flatten_layer.cpp b/src/caffe/layers/flatten_layer.cpp index 9494da9a..7e106d26 100644 --- a/src/caffe/layers/flatten_layer.cpp +++ b/src/caffe/layers/flatten_layer.cpp @@ -33,6 +33,10 @@ void FlattenLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, (*bottom)[0]->ShareDiff(*top[0]); } +#ifdef CPU_ONLY +STUB_GPU(FlattenLayer); +#endif + INSTANTIATE_CLASS(FlattenLayer); } // namespace caffe diff --git a/src/caffe/layers/hdf5_data_layer.cpp b/src/caffe/layers/hdf5_data_layer.cpp index 2ba7fa77..81cfdc09 100644 --- a/src/caffe/layers/hdf5_data_layer.cpp +++ b/src/caffe/layers/hdf5_data_layer.cpp @@ -114,6 +114,10 @@ Dtype HDF5DataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, return Dtype(0.); } +#ifdef CPU_ONLY +STUB_GPU_FORWARD(HDF5DataLayer, Forward); +#endif + INSTANTIATE_CLASS(HDF5DataLayer); } // namespace caffe diff --git a/src/caffe/layers/hdf5_output_layer.cpp b/src/caffe/layers/hdf5_output_layer.cpp index 8307ad7c..ffa240f1 100644 --- a/src/caffe/layers/hdf5_output_layer.cpp +++ b/src/caffe/layers/hdf5_output_layer.cpp @@ -69,6 +69,10 @@ void HDF5OutputLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, return; } +#ifdef CPU_ONLY +STUB_GPU(HDF5OutputLayer); +#endif + INSTANTIATE_CLASS(HDF5OutputLayer); } // namespace caffe diff --git a/src/caffe/layers/im2col_layer.cpp b/src/caffe/layers/im2col_layer.cpp index e047dfb8..2c86412b 100644 --- a/src/caffe/layers/im2col_layer.cpp +++ b/src/caffe/layers/im2col_layer.cpp @@ -47,6 +47,10 @@ void Im2colLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(Im2colLayer); +#endif + INSTANTIATE_CLASS(Im2colLayer); } // namespace caffe diff --git a/src/caffe/layers/image_data_layer.cpp b/src/caffe/layers/image_data_layer.cpp index 1f7368e7..9d09d3c4 100644 --- a/src/caffe/layers/image_data_layer.cpp +++ b/src/caffe/layers/image_data_layer.cpp @@ -287,6 +287,10 @@ Dtype ImageDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, return Dtype(0.); } +#ifdef CPU_ONLY +STUB_GPU_FORWARD(ImageDataLayer, Forward); +#endif + INSTANTIATE_CLASS(ImageDataLayer); } // namespace caffe diff --git a/src/caffe/layers/inner_product_layer.cpp b/src/caffe/layers/inner_product_layer.cpp index a92b56a3..4da8578d 100644 --- a/src/caffe/layers/inner_product_layer.cpp +++ b/src/caffe/layers/inner_product_layer.cpp @@ -96,6 +96,10 @@ void InnerProductLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(InnerProductLayer); +#endif + INSTANTIATE_CLASS(InnerProductLayer); } // namespace caffe diff --git a/src/caffe/layers/lrn_layer.cpp b/src/caffe/layers/lrn_layer.cpp index 2bda0430..0e2df2ff 100644 --- a/src/caffe/layers/lrn_layer.cpp +++ b/src/caffe/layers/lrn_layer.cpp @@ -256,6 +256,12 @@ void LRNLayer<Dtype>::WithinChannelBackward( } } +#ifdef CPU_ONLY +STUB_GPU(LRNLayer); +STUB_GPU_FORWARD(LRNLayer, CrossChannelForward); +STUB_GPU_BACKWARD(LRNLayer, CrossChannelBackward); +#endif + INSTANTIATE_CLASS(LRNLayer); diff --git a/src/caffe/layers/pooling_layer.cpp b/src/caffe/layers/pooling_layer.cpp index 9151ff23..d6fef07b 100644 --- a/src/caffe/layers/pooling_layer.cpp +++ b/src/caffe/layers/pooling_layer.cpp @@ -296,6 +296,10 @@ void PoolingLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } +#ifdef CPU_ONLY +STUB_GPU(PoolingLayer); +#endif + INSTANTIATE_CLASS(PoolingLayer); diff --git a/src/caffe/layers/power_layer.cpp b/src/caffe/layers/power_layer.cpp index 5ff33929..4607457a 100644 --- a/src/caffe/layers/power_layer.cpp +++ b/src/caffe/layers/power_layer.cpp @@ -99,6 +99,10 @@ void PowerLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(PowerLayer); +#endif + INSTANTIATE_CLASS(PowerLayer); diff --git a/src/caffe/layers/relu_layer.cpp b/src/caffe/layers/relu_layer.cpp index d7a8509b..6d601744 100644 --- a/src/caffe/layers/relu_layer.cpp +++ b/src/caffe/layers/relu_layer.cpp @@ -38,6 +38,10 @@ void ReLULayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } +#ifdef CPU_ONLY +STUB_GPU(ReLULayer); +#endif + INSTANTIATE_CLASS(ReLULayer); diff --git a/src/caffe/layers/relu_layer.cu b/src/caffe/layers/relu_layer.cu index a5b24afa..2ad68912 100644 --- a/src/caffe/layers/relu_layer.cu +++ b/src/caffe/layers/relu_layer.cu @@ -59,6 +59,7 @@ void ReLULayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top, } } + INSTANTIATE_CLASS(ReLULayer); diff --git a/src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp b/src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp index 8cb830ff..074fa6ce 100644 --- a/src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp +++ b/src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp @@ -68,6 +68,10 @@ void SigmoidCrossEntropyLossLayer<Dtype>::Backward_cpu( } } +#ifdef CPU_ONLY +STUB_GPU(SigmoidCrossEntropyLossLayer); +#endif + INSTANTIATE_CLASS(SigmoidCrossEntropyLossLayer); diff --git a/src/caffe/layers/sigmoid_layer.cpp b/src/caffe/layers/sigmoid_layer.cpp index 50139d86..e25db04c 100644 --- a/src/caffe/layers/sigmoid_layer.cpp +++ b/src/caffe/layers/sigmoid_layer.cpp @@ -42,6 +42,10 @@ void SigmoidLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(SigmoidLayer); +#endif + INSTANTIATE_CLASS(SigmoidLayer); diff --git a/src/caffe/layers/softmax_layer.cpp b/src/caffe/layers/softmax_layer.cpp index 5d60d9df..665cfaec 100644 --- a/src/caffe/layers/softmax_layer.cpp +++ b/src/caffe/layers/softmax_layer.cpp @@ -82,6 +82,10 @@ void SoftmaxLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } +#ifdef CPU_ONLY +STUB_GPU(SoftmaxLayer); +#endif + INSTANTIATE_CLASS(SoftmaxLayer); diff --git a/src/caffe/layers/softmax_loss_layer.cpp b/src/caffe/layers/softmax_loss_layer.cpp index 37c5ebc4..c87270ea 100644 --- a/src/caffe/layers/softmax_loss_layer.cpp +++ b/src/caffe/layers/softmax_loss_layer.cpp @@ -79,6 +79,10 @@ void SoftmaxWithLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } +#ifdef CPU_ONLY +STUB_GPU(SoftmaxWithLossLayer); +#endif + INSTANTIATE_CLASS(SoftmaxWithLossLayer); diff --git a/src/caffe/layers/split_layer.cpp b/src/caffe/layers/split_layer.cpp index 28abd95f..6bae4ef2 100644 --- a/src/caffe/layers/split_layer.cpp +++ b/src/caffe/layers/split_layer.cpp @@ -50,6 +50,10 @@ void SplitLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } +#ifdef CPU_ONLY +STUB_GPU(SplitLayer); +#endif + INSTANTIATE_CLASS(SplitLayer); } // namespace caffe diff --git a/src/caffe/layers/tanh_layer.cpp b/src/caffe/layers/tanh_layer.cpp index 6b5166d5..0a6ec68d 100644 --- a/src/caffe/layers/tanh_layer.cpp +++ b/src/caffe/layers/tanh_layer.cpp @@ -41,6 +41,10 @@ void TanHLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, } } +#ifdef CPU_ONLY +STUB_GPU(TanHLayer); +#endif + INSTANTIATE_CLASS(TanHLayer); } // namespace caffe diff --git a/src/caffe/layers/threshold_layer.cpp b/src/caffe/layers/threshold_layer.cpp index e6ed8a6b..2c8546c9 100644 --- a/src/caffe/layers/threshold_layer.cpp +++ b/src/caffe/layers/threshold_layer.cpp @@ -27,6 +27,10 @@ Dtype ThresholdLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, return Dtype(0); } +#ifdef CPU_ONLY +STUB_GPU_FORWARD(ThresholdLayer, Forward); +#endif + INSTANTIATE_CLASS(ThresholdLayer); } // namespace caffe diff --git a/src/caffe/layers/window_data_layer.cpp b/src/caffe/layers/window_data_layer.cpp index 5dbdff33..51e0dc09 100644 --- a/src/caffe/layers/window_data_layer.cpp +++ b/src/caffe/layers/window_data_layer.cpp @@ -453,6 +453,10 @@ Dtype WindowDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, return Dtype(0.); } +#ifdef CPU_ONLY +STUB_GPU_FORWARD(WindowDataLayer, Forward); +#endif + INSTANTIATE_CLASS(WindowDataLayer); } // namespace caffe |